blob: ff93437caf979375f286aa09d61e1d266a36eb28 [file] [log] [blame]
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001*builtin.txt* For Vim version 9.0. Last change: 2022 Nov 09
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}
84byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr}
85byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr}
86call({func}, {arglist} [, {dict}])
87 any call {func} with arguments {arglist}
88ceil({expr}) Float round {expr} up
89ch_canread({handle}) Number check if there is something to read
90ch_close({handle}) none close {handle}
91ch_close_in({handle}) none close in part of {handle}
92ch_evalexpr({handle}, {expr} [, {options}])
93 any evaluate {expr} on JSON {handle}
94ch_evalraw({handle}, {string} [, {options}])
95 any evaluate {string} on raw {handle}
96ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
97ch_getjob({channel}) Job get the Job of {channel}
98ch_info({handle}) String info about channel {handle}
99ch_log({msg} [, {handle}]) none write {msg} in the channel log file
100ch_logfile({fname} [, {mode}]) none start logging channel activity
101ch_open({address} [, {options}])
102 Channel open a channel to {address}
103ch_read({handle} [, {options}]) String read from {handle}
104ch_readblob({handle} [, {options}])
105 Blob read Blob from {handle}
106ch_readraw({handle} [, {options}])
107 String read raw from {handle}
108ch_sendexpr({handle}, {expr} [, {options}])
109 any send {expr} over JSON {handle}
110ch_sendraw({handle}, {expr} [, {options}])
111 any send {expr} over raw {handle}
112ch_setoptions({handle}, {options})
113 none set options for {handle}
114ch_status({handle} [, {options}])
115 String status of channel {handle}
116changenr() Number current change number
117char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
118charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000119charcol({expr} [, {winid}]) Number column number of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000120charidx({string}, {idx} [, {countcc}])
121 Number char index of byte {idx} in {string}
122chdir({dir}) String change current working directory
123cindent({lnum}) Number C indent for line {lnum}
124clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000125col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000126complete({startcol}, {matches}) none set Insert mode completion
127complete_add({expr}) Number add completion match
128complete_check() Number check for key typed during completion
129complete_info([{what}]) Dict get current completion information
130confirm({msg} [, {choices} [, {default} [, {type}]]])
131 Number number of choice picked by user
132copy({expr}) any make a shallow copy of {expr}
133cos({expr}) Float cosine of {expr}
134cosh({expr}) Float hyperbolic cosine of {expr}
135count({comp}, {expr} [, {ic} [, {start}]])
136 Number count how many {expr} are in {comp}
137cscope_connection([{num}, {dbpath} [, {prepend}]])
138 Number checks existence of cscope connection
139cursor({lnum}, {col} [, {off}])
140 Number move cursor to {lnum}, {col}, {off}
141cursor({list}) Number move cursor to position in {list}
142debugbreak({pid}) Number interrupt process being debugged
143deepcopy({expr} [, {noref}]) any make a full copy of {expr}
144delete({fname} [, {flags}]) Number delete the file or directory {fname}
145deletebufline({buf}, {first} [, {last}])
146 Number delete lines from buffer {buf}
147did_filetype() Number |TRUE| if FileType autocmd event used
148diff_filler({lnum}) Number diff filler lines about {lnum}
149diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
150digraph_get({chars}) String get the |digraph| of {chars}
151digraph_getlist([{listall}]) List get all |digraph|s
152digraph_set({chars}, {digraph}) Boolean register |digraph|
153digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
154echoraw({expr}) none output {expr} as-is
155empty({expr}) Number |TRUE| if {expr} is empty
156environ() Dict return environment variables
157escape({string}, {chars}) String escape {chars} in {string} with '\'
158eval({string}) any evaluate {string} into its value
159eventhandler() Number |TRUE| if inside an event handler
160executable({expr}) Number 1 if executable {expr} exists
161execute({command}) String execute {command} and get the output
162exepath({expr}) String full path of the command {expr}
163exists({expr}) Number |TRUE| if {expr} exists
164exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
165exp({expr}) Float exponential of {expr}
166expand({expr} [, {nosuf} [, {list}]])
167 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100168expandcmd({string} [, {options}])
169 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000170extend({expr1}, {expr2} [, {expr3}])
171 List/Dict insert items of {expr2} into {expr1}
172extendnew({expr1}, {expr2} [, {expr3}])
173 List/Dict like |extend()| but creates a new
174 List or Dictionary
175feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
176filereadable({file}) Number |TRUE| if {file} is a readable file
177filewritable({file}) Number |TRUE| if {file} is a writable file
178filter({expr1}, {expr2}) List/Dict/Blob/String
179 remove items from {expr1} where
180 {expr2} is 0
181finddir({name} [, {path} [, {count}]])
182 String find directory {name} in {path}
183findfile({name} [, {path} [, {count}]])
184 String find file {name} in {path}
185flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
186flattennew({list} [, {maxdepth}])
187 List flatten a copy of {list}
188float2nr({expr}) Number convert Float {expr} to a Number
189floor({expr}) Float round {expr} down
190fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
191fnameescape({fname}) String escape special characters in {fname}
192fnamemodify({fname}, {mods}) String modify file name
193foldclosed({lnum}) Number first line of fold at {lnum} if closed
194foldclosedend({lnum}) Number last line of fold at {lnum} if closed
195foldlevel({lnum}) Number fold level at {lnum}
196foldtext() String line displayed for closed fold
197foldtextresult({lnum}) String text for closed fold at {lnum}
198foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100199fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000200funcref({name} [, {arglist}] [, {dict}])
201 Funcref reference to function {name}
202function({name} [, {arglist}] [, {dict}])
203 Funcref named reference to function {name}
204garbagecollect([{atexit}]) none free memory, breaking cyclic references
205get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
206get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
207get({func}, {what}) any get property of funcref/partial {func}
208getbufinfo([{buf}]) List information about buffers
209getbufline({buf}, {lnum} [, {end}])
210 List lines {lnum} to {end} of buffer {buf}
211getbufvar({buf}, {varname} [, {def}])
212 any variable {varname} in buffer {buf}
213getchangelist([{buf}]) List list of change list items
214getchar([expr]) Number or String
215 get one character from the user
216getcharmod() Number modifiers for the last typed character
217getcharpos({expr}) List position of cursor, mark, etc.
218getcharsearch() Dict last character search
219getcharstr([expr]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100220getcmdcompltype() String return the type of the current
221 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000222getcmdline() String return the current command-line
223getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100224getcmdscreenpos() Number return cursor screen position in
225 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getcmdtype() String return current command-line type
227getcmdwintype() String return current command-line window type
228getcompletion({pat}, {type} [, {filtered}])
229 List list of cmdline completion matches
230getcurpos([{winnr}]) List position of the cursor
231getcursorcharpos([{winnr}]) List character position of the cursor
232getcwd([{winnr} [, {tabnr}]]) String get the current working directory
233getenv({name}) String return environment variable
234getfontname([{name}]) String name of font being used
235getfperm({fname}) String file permissions of file {fname}
236getfsize({fname}) Number size in bytes of file {fname}
237getftime({fname}) Number last modification time of file
238getftype({fname}) String description of type of file {fname}
239getimstatus() Number |TRUE| if the IME status is active
240getjumplist([{winnr} [, {tabnr}]])
241 List list of jump list items
242getline({lnum}) String line {lnum} of current buffer
243getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
244getloclist({nr}) List list of location list items
245getloclist({nr}, {what}) Dict get specific location list properties
246getmarklist([{buf}]) List list of global/local marks
247getmatches([{win}]) List list of current matches
248getmousepos() Dict last known mouse position
249getpid() Number process ID of Vim
250getpos({expr}) List position of cursor, mark, etc.
251getqflist() List list of quickfix items
252getqflist({what}) Dict get specific quickfix list properties
253getreg([{regname} [, 1 [, {list}]]])
254 String or List contents of a register
255getreginfo([{regname}]) Dict information about a register
256getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100257getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000258gettabinfo([{expr}]) List list of tab pages
259gettabvar({nr}, {varname} [, {def}])
260 any variable {varname} in tab {nr} or {def}
261gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
262 any {name} in {winnr} in tab page {tabnr}
263gettagstack([{nr}]) Dict get the tag stack of window {nr}
264gettext({text}) String lookup translation of {text}
265getwininfo([{winid}]) List list of info about each window
266getwinpos([{timeout}]) List X and Y coord in pixels of the Vim window
267getwinposx() Number X coord in pixels of the Vim window
268getwinposy() Number Y coord in pixels of the Vim window
269getwinvar({nr}, {varname} [, {def}])
270 any variable {varname} in window {nr}
271glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
272 any expand file wildcards in {expr}
273glob2regpat({expr}) String convert a glob pat into a search pat
274globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
275 String do glob({expr}) for all dirs in {path}
276has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
277has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
278haslocaldir([{winnr} [, {tabnr}]])
279 Number |TRUE| if the window executed |:lcd|
280 or |:tcd|
281hasmapto({what} [, {mode} [, {abbr}]])
282 Number |TRUE| if mapping to {what} exists
283histadd({history}, {item}) Number add an item to a history
284histdel({history} [, {item}]) Number remove an item from a history
285histget({history} [, {index}]) String get the item {index} from a history
286histnr({history}) Number highest index of a history
287hlID({name}) Number syntax ID of highlight group {name}
288hlexists({name}) Number |TRUE| if highlight group {name} exists
289hlget([{name} [, {resolve}]]) List get highlight group attributes
290hlset({list}) Number set highlight group attributes
291hostname() String name of the machine Vim is running on
292iconv({expr}, {from}, {to}) String convert encoding of {expr}
293indent({lnum}) Number indent of line {lnum}
294index({object}, {expr} [, {start} [, {ic}]])
295 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100296indexof({object}, {expr} [, {opts}]])
297 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000298input({prompt} [, {text} [, {completion}]])
299 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100300inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000301 String like input() but in a GUI dialog
302inputlist({textlist}) Number let the user pick from a choice list
303inputrestore() Number restore typeahead
304inputsave() Number save and clear typeahead
305inputsecret({prompt} [, {text}]) String like input() but hiding the text
306insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
307interrupt() none interrupt script execution
308invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100309isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000310isdirectory({directory}) Number |TRUE| if {directory} is a directory
311isinf({expr}) Number determine if {expr} is infinity value
312 (positive or negative)
313islocked({expr}) Number |TRUE| if {expr} is locked
314isnan({expr}) Number |TRUE| if {expr} is NaN
315items({dict}) List key-value pairs in {dict}
316job_getchannel({job}) Channel get the channel handle for {job}
317job_info([{job}]) Dict get information about {job}
318job_setoptions({job}, {options}) none set options for {job}
319job_start({command} [, {options}])
320 Job start a job
321job_status({job}) String get the status of {job}
322job_stop({job} [, {how}]) Number stop {job}
323join({list} [, {sep}]) String join {list} items into one String
324js_decode({string}) any decode JS style JSON
325js_encode({expr}) String encode JS style JSON
326json_decode({string}) any decode JSON
327json_encode({expr}) String encode JSON
328keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100329keytrans({string}) String translate internal keycodes to a form
330 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000331len({expr}) Number the length of {expr}
332libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
333libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
334line({expr} [, {winid}]) Number line nr of cursor, last line or mark
335line2byte({lnum}) Number byte count of line {lnum}
336lispindent({lnum}) Number Lisp indent for line {lnum}
337list2blob({list}) Blob turn {list} of numbers into a Blob
338list2str({list} [, {utf8}]) String turn {list} of numbers into a String
339listener_add({callback} [, {buf}])
340 Number add a callback to listen to changes
341listener_flush([{buf}]) none invoke listener callbacks
342listener_remove({id}) none remove a listener callback
343localtime() Number current time
344log({expr}) Float natural logarithm (base e) of {expr}
345log10({expr}) Float logarithm of Float {expr} to base 10
346luaeval({expr} [, {expr}]) any evaluate |Lua| expression
347map({expr1}, {expr2}) List/Dict/Blob/String
348 change each item in {expr1} to {expr2}
349maparg({name} [, {mode} [, {abbr} [, {dict}]]])
350 String or Dict
351 rhs of mapping {name} in mode {mode}
352mapcheck({name} [, {mode} [, {abbr}]])
353 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100354maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000355mapnew({expr1}, {expr2}) List/Dict/Blob/String
356 like |map()| but creates a new List or
357 Dictionary
358mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
359match({expr}, {pat} [, {start} [, {count}]])
360 Number position where {pat} matches in {expr}
361matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
362 Number highlight {pattern} with {group}
363matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
364 Number highlight positions with {group}
365matcharg({nr}) List arguments of |:match|
366matchdelete({id} [, {win}]) Number delete match identified by {id}
367matchend({expr}, {pat} [, {start} [, {count}]])
368 Number position where {pat} ends in {expr}
369matchfuzzy({list}, {str} [, {dict}])
370 List fuzzy match {str} in {list}
371matchfuzzypos({list}, {str} [, {dict}])
372 List fuzzy match {str} in {list}
373matchlist({expr}, {pat} [, {start} [, {count}]])
374 List match and submatches of {pat} in {expr}
375matchstr({expr}, {pat} [, {start} [, {count}]])
376 String {count}'th match of {pat} in {expr}
377matchstrpos({expr}, {pat} [, {start} [, {count}]])
378 List {count}'th match of {pat} in {expr}
379max({expr}) Number maximum value of items in {expr}
380menu_info({name} [, {mode}]) Dict get menu item information
381min({expr}) Number minimum value of items in {expr}
382mkdir({name} [, {path} [, {prot}]])
383 Number create directory {name}
384mode([expr]) String current editing mode
385mzeval({expr}) any evaluate |MzScheme| expression
386nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
387nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
388or({expr}, {expr}) Number bitwise OR
389pathshorten({expr} [, {len}]) String shorten directory names in a path
390perleval({expr}) any evaluate |Perl| expression
391popup_atcursor({what}, {options}) Number create popup window near the cursor
392popup_beval({what}, {options}) Number create popup window for 'ballooneval'
393popup_clear() none close all popup windows
394popup_close({id} [, {result}]) none close popup window {id}
395popup_create({what}, {options}) Number create a popup window
396popup_dialog({what}, {options}) Number create a popup window used as a dialog
397popup_filter_menu({id}, {key}) Number filter for a menu popup window
398popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100399popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000400popup_findinfo() Number get window ID of info popup window
401popup_findpreview() Number get window ID of preview popup window
402popup_getoptions({id}) Dict get options of popup window {id}
403popup_getpos({id}) Dict get position of popup window {id}
404popup_hide({id}) none hide popup menu {id}
405popup_list() List get a list of window IDs of all popups
406popup_locate({row}, {col}) Number get window ID of popup at position
407popup_menu({what}, {options}) Number create a popup window used as a menu
408popup_move({id}, {options}) none set position of popup window {id}
409popup_notification({what}, {options})
410 Number create a notification popup window
411popup_setoptions({id}, {options})
412 none set options for popup window {id}
413popup_settext({id}, {text}) none set the text of popup window {id}
414popup_show({id}) none unhide popup window {id}
415pow({x}, {y}) Float {x} to the power of {y}
416prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
417printf({fmt}, {expr1}...) String format text
418prompt_getprompt({buf}) String get prompt text
419prompt_setcallback({buf}, {expr}) none set prompt callback function
420prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
421prompt_setprompt({buf}, {text}) none set prompt text
422prop_add({lnum}, {col}, {props}) none add one text property
423prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
424 none add multiple text properties
425prop_clear({lnum} [, {lnum-end} [, {props}]])
426 none remove all text properties
427prop_find({props} [, {direction}])
428 Dict search for a text property
429prop_list({lnum} [, {props}]) List text properties in {lnum}
430prop_remove({props} [, {lnum} [, {lnum-end}]])
431 Number remove a text property
432prop_type_add({name}, {props}) none define a new property type
433prop_type_change({name}, {props})
434 none change an existing property type
435prop_type_delete({name} [, {props}])
436 none delete a property type
437prop_type_get({name} [, {props}])
438 Dict get property type values
439prop_type_list([{props}]) List get list of property types
440pum_getpos() Dict position and size of pum if visible
441pumvisible() Number whether popup menu is visible
442py3eval({expr}) any evaluate |python3| expression
443pyeval({expr}) any evaluate |Python| expression
444pyxeval({expr}) any evaluate |python_x| expression
445rand([{expr}]) Number get pseudo-random number
446range({expr} [, {max} [, {stride}]])
447 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100448readblob({fname} [, {offset} [, {size}]])
449 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000450readdir({dir} [, {expr} [, {dict}]])
451 List file names in {dir} selected by {expr}
452readdirex({dir} [, {expr} [, {dict}]])
453 List file info in {dir} selected by {expr}
454readfile({fname} [, {type} [, {max}]])
455 List get list of lines from file {fname}
456reduce({object}, {func} [, {initial}])
457 any reduce {object} using {func}
458reg_executing() String get the executing register name
459reg_recording() String get the recording register name
460reltime([{start} [, {end}]]) List get time value
461reltimefloat({time}) Float turn the time value into a Float
462reltimestr({time}) String turn time value into a String
463remote_expr({server}, {string} [, {idvar} [, {timeout}]])
464 String send expression
465remote_foreground({server}) Number bring Vim server to the foreground
466remote_peek({serverid} [, {retvar}])
467 Number check for reply string
468remote_read({serverid} [, {timeout}])
469 String read reply string
470remote_send({server}, {string} [, {idvar}])
471 String send key sequence
472remote_startserver({name}) none become server {name}
473remove({list}, {idx} [, {end}]) any/List
474 remove items {idx}-{end} from {list}
475remove({blob}, {idx} [, {end}]) Number/Blob
476 remove bytes {idx}-{end} from {blob}
477remove({dict}, {key}) any remove entry {key} from {dict}
478rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100479repeat({expr}, {count}) List/Blob/String
480 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000481resolve({filename}) String get filename a shortcut points to
482reverse({list}) List reverse {list} in-place
483round({expr}) Float round off {expr}
484rubyeval({expr}) any evaluate |Ruby| expression
485screenattr({row}, {col}) Number attribute at screen position
486screenchar({row}, {col}) Number character at screen position
487screenchars({row}, {col}) List List of characters at screen position
488screencol() Number current cursor column
489screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
490screenrow() Number current cursor row
491screenstring({row}, {col}) String characters at screen position
492search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
493 Number search for {pattern}
494searchcount([{options}]) Dict get or update search stats
495searchdecl({name} [, {global} [, {thisblock}]])
496 Number search for variable declaration
497searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
498 Number search for other end of start/end pair
499searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
500 List search for other end of start/end pair
501searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
502 List search for {pattern}
503server2client({clientid}, {string})
504 Number send reply string
505serverlist() String get a list of available servers
506setbufline({expr}, {lnum}, {text})
507 Number set line {lnum} to {text} in buffer
508 {expr}
509setbufvar({buf}, {varname}, {val})
510 none set {varname} in buffer {buf} to {val}
511setcellwidths({list}) none set character cell width overrides
512setcharpos({expr}, {list}) Number set the {expr} position to {list}
513setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100514setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000515setcmdpos({pos}) Number set cursor position in command-line
516setcursorcharpos({list}) Number move cursor to position in {list}
517setenv({name}, {val}) none set environment variable
518setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
519setline({lnum}, {line}) Number set line {lnum} to {line}
520setloclist({nr}, {list} [, {action}])
521 Number modify location list using {list}
522setloclist({nr}, {list}, {action}, {what})
523 Number modify specific location list props
524setmatches({list} [, {win}]) Number restore a list of matches
525setpos({expr}, {list}) Number set the {expr} position to {list}
526setqflist({list} [, {action}]) Number modify quickfix list using {list}
527setqflist({list}, {action}, {what})
528 Number modify specific quickfix list props
529setreg({n}, {v} [, {opt}]) Number set register to value and type
530settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
531settabwinvar({tabnr}, {winnr}, {varname}, {val})
532 none set {varname} in window {winnr} in tab
533 page {tabnr} to {val}
534settagstack({nr}, {dict} [, {action}])
535 Number modify tag stack using {dict}
536setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
537sha256({string}) String SHA256 checksum of {string}
538shellescape({string} [, {special}])
539 String escape {string} for use as shell
540 command argument
541shiftwidth([{col}]) Number effective value of 'shiftwidth'
542sign_define({name} [, {dict}]) Number define or update a sign
543sign_define({list}) List define or update a list of signs
544sign_getdefined([{name}]) List get a list of defined signs
545sign_getplaced([{buf} [, {dict}]])
546 List get a list of placed signs
547sign_jump({id}, {group}, {buf})
548 Number jump to a sign
549sign_place({id}, {group}, {name}, {buf} [, {dict}])
550 Number place a sign
551sign_placelist({list}) List place a list of signs
552sign_undefine([{name}]) Number undefine a sign
553sign_undefine({list}) List undefine a list of signs
554sign_unplace({group} [, {dict}])
555 Number unplace a sign
556sign_unplacelist({list}) List unplace a list of signs
557simplify({filename}) String simplify filename as much as possible
558sin({expr}) Float sine of {expr}
559sinh({expr}) Float hyperbolic sine of {expr}
560slice({expr}, {start} [, {end}]) String, List or Blob
561 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000562sort({list} [, {how} [, {dict}]])
563 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000564sound_clear() none stop playing all sounds
565sound_playevent({name} [, {callback}])
566 Number play an event sound
567sound_playfile({path} [, {callback}])
568 Number play sound file {path}
569sound_stop({id}) none stop playing sound {id}
570soundfold({word}) String sound-fold {word}
571spellbadword() String badly spelled word at cursor
572spellsuggest({word} [, {max} [, {capital}]])
573 List spelling suggestions
574split({expr} [, {pat} [, {keepempty}]])
575 List make |List| from {pat} separated {expr}
576sqrt({expr}) Float square root of {expr}
577srand([{expr}]) List get seed for |rand()|
578state([{what}]) String current state of Vim
579str2float({expr} [, {quoted}]) Float convert String to Float
580str2list({expr} [, {utf8}]) List convert each character of {expr} to
581 ASCII/UTF-8 value
582str2nr({expr} [, {base} [, {quoted}]])
583 Number convert String to Number
584strcharlen({expr}) Number character length of the String {expr}
585strcharpart({str}, {start} [, {len} [, {skipcc}]])
586 String {len} characters of {str} at
587 character {start}
588strchars({expr} [, {skipcc}]) Number character count of the String {expr}
589strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
590strftime({format} [, {time}]) String format time with a specified format
591strgetchar({str}, {index}) Number get char {index} from {str}
592stridx({haystack}, {needle} [, {start}])
593 Number index of {needle} in {haystack}
594string({expr}) String String representation of {expr} value
595strlen({expr}) Number length of the String {expr}
596strpart({str}, {start} [, {len} [, {chars}]])
597 String {len} bytes/chars of {str} at
598 byte {start}
599strptime({format}, {timestring})
600 Number Convert {timestring} to unix timestamp
601strridx({haystack}, {needle} [, {start}])
602 Number last index of {needle} in {haystack}
603strtrans({expr}) String translate string to make it printable
604strwidth({expr}) Number display cell length of the String {expr}
605submatch({nr} [, {list}]) String or List
606 specific match in ":s" or substitute()
607substitute({expr}, {pat}, {sub}, {flags})
608 String all {pat} in {expr} replaced with {sub}
609swapinfo({fname}) Dict information about swap file {fname}
610swapname({buf}) String swap file of buffer {buf}
611synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
612synIDattr({synID}, {what} [, {mode}])
613 String attribute {what} of syntax ID {synID}
614synIDtrans({synID}) Number translated syntax ID of {synID}
615synconcealed({lnum}, {col}) List info about concealing
616synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
617system({expr} [, {input}]) String output of shell command/filter {expr}
618systemlist({expr} [, {input}]) List output of shell command/filter {expr}
619tabpagebuflist([{arg}]) List list of buffer numbers in tab page
620tabpagenr([{arg}]) Number number of current or last tab page
621tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
622tagfiles() List tags files used
623taglist({expr} [, {filename}]) List list of tags matching {expr}
624tan({expr}) Float tangent of {expr}
625tanh({expr}) Float hyperbolic tangent of {expr}
626tempname() String name for a temporary file
627term_dumpdiff({filename}, {filename} [, {options}])
628 Number display difference between two dumps
629term_dumpload({filename} [, {options}])
630 Number displaying a screen dump
631term_dumpwrite({buf}, {filename} [, {options}])
632 none dump terminal window contents
633term_getaltscreen({buf}) Number get the alternate screen flag
634term_getansicolors({buf}) List get ANSI palette in GUI color mode
635term_getattr({attr}, {what}) Number get the value of attribute {what}
636term_getcursor({buf}) List get the cursor position of a terminal
637term_getjob({buf}) Job get the job associated with a terminal
638term_getline({buf}, {row}) String get a line of text from a terminal
639term_getscrolled({buf}) Number get the scroll count of a terminal
640term_getsize({buf}) List get the size of a terminal
641term_getstatus({buf}) String get the status of a terminal
642term_gettitle({buf}) String get the title of a terminal
643term_gettty({buf}, [{input}]) String get the tty name of a terminal
644term_list() List get the list of terminal buffers
645term_scrape({buf}, {row}) List get row of a terminal screen
646term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
647term_setansicolors({buf}, {colors})
648 none set ANSI palette in GUI color mode
649term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
650term_setkill({buf}, {how}) none set signal to stop job in terminal
651term_setrestore({buf}, {command}) none set command to restore terminal
652term_setsize({buf}, {rows}, {cols})
653 none set the size of a terminal
654term_start({cmd} [, {options}]) Number open a terminal window and run a job
655term_wait({buf} [, {time}]) Number wait for screen to be updated
656terminalprops() Dict properties of the terminal
657test_alloc_fail({id}, {countdown}, {repeat})
658 none make memory allocation fail
659test_autochdir() none enable 'autochdir' during startup
660test_feedinput({string}) none add key sequence to input buffer
661test_garbagecollect_now() none free memory right now for testing
662test_garbagecollect_soon() none free memory soon for testing
663test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000664test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000665test_ignore_error({expr}) none ignore a specific error
666test_null_blob() Blob null value for testing
667test_null_channel() Channel null value for testing
668test_null_dict() Dict null value for testing
669test_null_function() Funcref null value for testing
670test_null_job() Job null value for testing
671test_null_list() List null value for testing
672test_null_partial() Funcref null value for testing
673test_null_string() String null value for testing
674test_option_not_set({name}) none reset flag indicating option was set
675test_override({expr}, {val}) none test with Vim internal overrides
676test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000677test_setmouse({row}, {col}) none set the mouse position for testing
678test_settime({expr}) none set current time for testing
679test_srand_seed([seed]) none set seed for testing srand()
680test_unknown() any unknown value for testing
681test_void() any void value for testing
682timer_info([{id}]) List information about timers
683timer_pause({id}, {pause}) none pause or unpause a timer
684timer_start({time}, {callback} [, {options}])
685 Number create a timer
686timer_stop({timer}) none stop a timer
687timer_stopall() none stop all timers
688tolower({expr}) String the String {expr} switched to lowercase
689toupper({expr}) String the String {expr} switched to uppercase
690tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
691 to chars in {tostr}
692trim({text} [, {mask} [, {dir}]])
693 String trim characters in {mask} from {text}
694trunc({expr}) Float truncate Float {expr}
695type({expr}) Number type of value {expr}
696typename({expr}) String representation of the type of {expr}
697undofile({name}) String undo file name for {name}
698undotree() List undo file tree
699uniq({list} [, {func} [, {dict}]])
700 List remove adjacent duplicates from a list
701values({dict}) List values in {dict}
LemonBoy0f7a3e12022-05-26 12:10:37 +0100702virtcol({expr} [, {list}]) Number or List
703 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100704virtcol2col({winid}, {lnum}, {col})
705 Number byte index of a character on screen
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000706visualmode([expr]) String last visual mode used
707wildmenumode() Number whether 'wildmenu' mode is active
708win_execute({id}, {command} [, {silent}])
709 String execute {command} in window {id}
710win_findbuf({bufnr}) List find windows containing {bufnr}
711win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
712win_gettype([{nr}]) String type of window {nr}
713win_gotoid({expr}) Number go to window with ID {expr}
714win_id2tabwin({expr}) List get tab and window nr from window ID
715win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000716win_move_separator({nr}) Number move window vertical separator
717win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000718win_screenpos({nr}) List get screen position of window {nr}
719win_splitmove({nr}, {target} [, {options}])
720 Number move window {nr} to split of {target}
721winbufnr({nr}) Number buffer number of window {nr}
722wincol() Number window column of the cursor
723windowsversion() String MS-Windows OS version
724winheight({nr}) Number height of window {nr}
725winlayout([{tabnr}]) List layout of windows in tab {tabnr}
726winline() Number window line of the cursor
727winnr([{expr}]) Number number of current window
728winrestcmd() String returns command to restore window sizes
729winrestview({dict}) none restore view of current window
730winsaveview() Dict save view of current window
731winwidth({nr}) Number width of window {nr}
732wordcount() Dict get byte/char/word statistics
733writefile({object}, {fname} [, {flags}])
734 Number write |Blob| or |List| of lines to file
735xor({expr}, {expr}) Number bitwise XOR
736
737==============================================================================
7382. Details *builtin-function-details*
739
740Not all functions are here, some have been moved to a help file covering the
741specific functionality.
742
743abs({expr}) *abs()*
744 Return the absolute value of {expr}. When {expr} evaluates to
745 a |Float| abs() returns a |Float|. When {expr} can be
746 converted to a |Number| abs() returns a |Number|. Otherwise
747 abs() gives an error message and returns -1.
748 Examples: >
749 echo abs(1.456)
750< 1.456 >
751 echo abs(-5.456)
752< 5.456 >
753 echo abs(-4)
754< 4
755
756 Can also be used as a |method|: >
757 Compute()->abs()
758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000759
760acos({expr}) *acos()*
761 Return the arc cosine of {expr} measured in radians, as a
762 |Float| in the range of [0, pi].
763 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100764 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000765 Examples: >
766 :echo acos(0)
767< 1.570796 >
768 :echo acos(-0.5)
769< 2.094395
770
771 Can also be used as a |method|: >
772 Compute()->acos()
773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000774
775add({object}, {expr}) *add()*
776 Append the item {expr} to |List| or |Blob| {object}. Returns
777 the resulting |List| or |Blob|. Examples: >
778 :let alist = add([1, 2, 3], item)
779 :call add(mylist, "woodstock")
780< Note that when {expr} is a |List| it is appended as a single
781 item. Use |extend()| to concatenate |Lists|.
782 When {object} is a |Blob| then {expr} must be a number.
783 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100784 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000785
786 Can also be used as a |method|: >
787 mylist->add(val1)->add(val2)
788
789
790and({expr}, {expr}) *and()*
791 Bitwise AND on the two arguments. The arguments are converted
792 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100793 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000794 Example: >
795 :let flag = and(bits, 0x80)
796< Can also be used as a |method|: >
797 :let flag = bits->and(0x80)
798
799
800append({lnum}, {text}) *append()*
801 When {text} is a |List|: Append each item of the |List| as a
802 text line below line {lnum} in the current buffer.
803 Otherwise append {text} as one text line below line {lnum} in
804 the current buffer.
805 Any type of item is accepted and converted to a String.
806 {lnum} can be zero to insert a line before the first one.
807 {lnum} is used like with |getline()|.
808 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000809 0 for success. When {text} is an empty list zero is returned,
810 no matter the value of {lnum}.
811 In |Vim9| script an invalid argument or negative number
812 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000813 :let failed = append(line('$'), "# THE END")
814 :let failed = append(0, ["Chapter 1", "the beginning"])
815
816< Can also be used as a |method| after a List, the base is
817 passed as the second argument: >
818 mylist->append(lnum)
819
820
821appendbufline({buf}, {lnum}, {text}) *appendbufline()*
822 Like |append()| but append the text in buffer {buf}.
823
824 This function works only for loaded buffers. First call
825 |bufload()| if needed.
826
827 For the use of {buf}, see |bufname()|.
828
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000829 {lnum} is the line number to append below. Note that using
830 |line()| would use the current buffer, not the one appending
831 to. Use "$" to append at the end of the buffer. Other string
832 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000833
834 On success 0 is returned, on failure 1 is returned.
835 In |Vim9| script an error is given for an invalid {lnum}.
836
837 If {buf} is not a valid buffer or {lnum} is not valid, an
838 error message is given. Example: >
839 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000840< However, when {text} is an empty list then no error is given
841 for an invalid {lnum}, since {lnum} isn't actually used.
842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000843 Can also be used as a |method| after a List, the base is
844 passed as the second argument: >
845 mylist->appendbufline(buf, lnum)
846
847
848argc([{winid}]) *argc()*
849 The result is the number of files in the argument list. See
850 |arglist|.
851 If {winid} is not supplied, the argument list of the current
852 window is used.
853 If {winid} is -1, the global argument list is used.
854 Otherwise {winid} specifies the window of which the argument
855 list is used: either the window number or the window ID.
856 Returns -1 if the {winid} argument is invalid.
857
858 *argidx()*
859argidx() The result is the current index in the argument list. 0 is
860 the first file. argc() - 1 is the last one. See |arglist|.
861
862 *arglistid()*
863arglistid([{winnr} [, {tabnr}]])
864 Return the argument list ID. This is a number which
865 identifies the argument list being used. Zero is used for the
866 global argument list. See |arglist|.
867 Returns -1 if the arguments are invalid.
868
869 Without arguments use the current window.
870 With {winnr} only use this window in the current tab page.
871 With {winnr} and {tabnr} use the window in the specified tab
872 page.
873 {winnr} can be the window number or the |window-ID|.
874
875 *argv()*
876argv([{nr} [, {winid}]])
877 The result is the {nr}th file in the argument list. See
878 |arglist|. "argv(0)" is the first one. Example: >
879 :let i = 0
880 :while i < argc()
881 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000882 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000883 : let i = i + 1
884 :endwhile
885< Without the {nr} argument, or when {nr} is -1, a |List| with
886 the whole |arglist| is returned.
887
888 The {winid} argument specifies the window ID, see |argc()|.
889 For the Vim command line arguments see |v:argv|.
890
Bram Moolenaar016188f2022-06-06 20:52:59 +0100891 Returns an empty string if {nr}th argument is not present in
892 the argument list. Returns an empty List if the {winid}
893 argument is invalid.
894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895asin({expr}) *asin()*
896 Return the arc sine of {expr} measured in radians, as a |Float|
897 in the range of [-pi/2, pi/2].
898 {expr} must evaluate to a |Float| or a |Number| in the range
899 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100900 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
901 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000902 Examples: >
903 :echo asin(0.8)
904< 0.927295 >
905 :echo asin(-0.5)
906< -0.523599
907
908 Can also be used as a |method|: >
909 Compute()->asin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910
911
912assert_ functions are documented here: |assert-functions-details|
913
914
915
916atan({expr}) *atan()*
917 Return the principal value of the arc tangent of {expr}, in
918 the range [-pi/2, +pi/2] radians, as a |Float|.
919 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100920 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000921 Examples: >
922 :echo atan(100)
923< 1.560797 >
924 :echo atan(-4.01)
925< -1.326405
926
927 Can also be used as a |method|: >
928 Compute()->atan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000929
930
931atan2({expr1}, {expr2}) *atan2()*
932 Return the arc tangent of {expr1} / {expr2}, measured in
933 radians, as a |Float| in the range [-pi, pi].
934 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100935 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
936 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000937 Examples: >
938 :echo atan2(-1, 1)
939< -0.785398 >
940 :echo atan2(1, -1)
941< 2.356194
942
943 Can also be used as a |method|: >
944 Compute()->atan2(1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000945
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100946
947autocmd_add({acmds}) *autocmd_add()*
948 Adds a List of autocmds and autocmd groups.
949
950 The {acmds} argument is a List where each item is a Dict with
951 the following optional items:
952 bufnr buffer number to add a buffer-local autocmd.
953 If this item is specified, then the "pattern"
954 item is ignored.
955 cmd Ex command to execute for this autocmd event
956 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100957 This can be either a String with a single
958 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100959 group autocmd group name. Refer to |autocmd-groups|.
960 If this group doesn't exist then it is
961 created. If not specified or empty, then the
962 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100963 nested boolean flag, set to v:true to add a nested
964 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100965 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100966 which executes only once. Refer to
967 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100968 pattern autocmd pattern string. Refer to
969 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +0100970 present, then this item is ignored. This can
971 be a String with a single pattern or a List of
972 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +0100973 replace boolean flag, set to v:true to remove all the
974 commands associated with the specified autocmd
975 event and group and add the {cmd}. This is
976 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +0100977 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100978
979 Returns v:true on success and v:false on failure.
980 Examples: >
981 " Create a buffer-local autocmd for buffer 5
982 let acmd = {}
983 let acmd.group = 'MyGroup'
984 let acmd.event = 'BufEnter'
985 let acmd.bufnr = 5
986 let acmd.cmd = 'call BufEnterFunc()'
987 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000988<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +0100989 Can also be used as a |method|: >
990 GetAutocmdList()->autocmd_add()
991<
992autocmd_delete({acmds}) *autocmd_delete()*
993 Deletes a List of autocmds and autocmd groups.
994
995 The {acmds} argument is a List where each item is a Dict with
996 the following optional items:
997 bufnr buffer number to delete a buffer-local autocmd.
998 If this item is specified, then the "pattern"
999 item is ignored.
1000 cmd Ex command for this autocmd event
1001 event autocmd event name. Refer to |autocmd-events|.
1002 If '*' then all the autocmd events in this
1003 group are deleted.
1004 group autocmd group name. Refer to |autocmd-groups|.
1005 If not specified or empty, then the default
1006 group is used.
1007 nested set to v:true for a nested autocmd.
1008 Refer to |autocmd-nested|.
1009 once set to v:true for an autocmd which executes
1010 only once. Refer to |autocmd-once|.
1011 pattern autocmd pattern string. Refer to
1012 |autocmd-patterns|. If "bufnr" item is
1013 present, then this item is ignored.
1014
1015 If only {group} is specified in a {acmds} entry and {event},
1016 {pattern} and {cmd} are not specified, then that autocmd group
1017 is deleted.
1018
Bram Moolenaar016188f2022-06-06 20:52:59 +01001019 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001020 Examples: >
1021 " :autocmd! BufLeave *.vim
1022 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1023 call autocmd_delete([acmd]})
1024 " :autocmd! MyGroup1 BufLeave
1025 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1026 call autocmd_delete([acmd])
1027 " :autocmd! MyGroup2 BufEnter *.c
1028 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1029 \ pattern: '*.c'}
1030 " :autocmd! MyGroup2 * *.c
1031 let acmd = #{group: 'MyGroup2', event: '*',
1032 \ pattern: '*.c'}
1033 call autocmd_delete([acmd])
1034 " :autocmd! MyGroup3
1035 let acmd = #{group: 'MyGroup3'}
1036 call autocmd_delete([acmd])
1037<
1038 Can also be used as a |method|: >
1039 GetAutocmdList()->autocmd_delete()
1040
1041autocmd_get([{opts}]) *autocmd_get()*
1042 Returns a |List| of autocmds. If {opts} is not supplied, then
1043 returns the autocmds for all the events in all the groups.
1044
1045 The optional {opts} Dict argument supports the following
1046 items:
1047 group Autocmd group name. If specified, returns only
1048 the autocmds defined in this group. If the
1049 specified group doesn't exist, results in an
1050 error message. If set to an empty string,
1051 then the default autocmd group is used.
1052 event Autocmd event name. If specified, returns only
1053 the autocmds defined for this event. If set
1054 to "*", then returns autocmds for all the
1055 events. If the specified event doesn't exist,
1056 results in an error message.
1057 pattern Autocmd pattern. If specified, returns only
1058 the autocmds defined for this pattern.
1059 A combination of the above three times can be supplied in
1060 {opts}.
1061
1062 Each Dict in the returned List contains the following items:
1063 bufnr For buffer-local autocmds, buffer number where
1064 the autocmd is defined.
1065 cmd Command executed for this autocmd.
1066 event Autocmd event name.
1067 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001068 nested Boolean flag, set to v:true for a nested
1069 autocmd. See |autocmd-nested|.
1070 once Boolean flag, set to v:true, if the autocmd
1071 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001072 pattern Autocmd pattern. For a buffer-local
1073 autocmd, this will be of the form "<buffer=n>".
1074 If there are multiple commands for an autocmd event in a
1075 group, then separate items are returned for each command.
1076
Bram Moolenaar016188f2022-06-06 20:52:59 +01001077 Returns an empty List if an autocmd with the specified group
1078 or event or pattern is not found.
1079
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001080 Examples: >
1081 " :autocmd MyGroup
1082 echo autocmd_get(#{group: 'Mygroup'})
1083 " :autocmd G BufUnload
1084 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1085 " :autocmd G * *.ts
1086 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1087 echo autocmd_get(acmd)
1088 " :autocmd Syntax
1089 echo autocmd_get(#{event: 'Syntax'})
1090 " :autocmd G BufEnter *.ts
1091 let acmd = #{group: 'G', event: 'BufEnter',
1092 \ pattern: '*.ts'}
1093 echo autocmd_get(acmd)
1094<
1095 Can also be used as a |method|: >
1096 Getopts()->autocmd_get()
1097<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001098balloon_gettext() *balloon_gettext()*
1099 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001100 not used for the List. Returns an empty string if balloon
1101 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001102
1103balloon_show({expr}) *balloon_show()*
1104 Show {expr} inside the balloon. For the GUI {expr} is used as
1105 a string. For a terminal {expr} can be a list, which contains
1106 the lines of the balloon. If {expr} is not a list it will be
1107 split with |balloon_split()|.
1108 If {expr} is an empty string any existing balloon is removed.
1109
1110 Example: >
1111 func GetBalloonContent()
1112 " ... initiate getting the content
1113 return ''
1114 endfunc
1115 set balloonexpr=GetBalloonContent()
1116
1117 func BalloonCallback(result)
1118 call balloon_show(a:result)
1119 endfunc
1120< Can also be used as a |method|: >
1121 GetText()->balloon_show()
1122<
1123 The intended use is that fetching the content of the balloon
1124 is initiated from 'balloonexpr'. It will invoke an
1125 asynchronous method, in which a callback invokes
1126 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001127 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001128
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001129 When showing a balloon is not possible then nothing happens,
1130 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001131 {only available when compiled with the |+balloon_eval| or
1132 |+balloon_eval_term| feature}
1133
1134balloon_split({msg}) *balloon_split()*
1135 Split String {msg} into lines to be displayed in a balloon.
1136 The splits are made for the current window size and optimize
1137 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001138 Returns a |List| with the split lines. Returns an empty List
1139 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001140 Can also be used as a |method|: >
1141 GetText()->balloon_split()->balloon_show()
1142
1143< {only available when compiled with the |+balloon_eval_term|
1144 feature}
1145
1146blob2list({blob}) *blob2list()*
1147 Return a List containing the number value of each byte in Blob
1148 {blob}. Examples: >
1149 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1150 blob2list(0z) returns []
1151< Returns an empty List on error. |list2blob()| does the
1152 opposite.
1153
1154 Can also be used as a |method|: >
1155 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001156<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001157 *browse()*
1158browse({save}, {title}, {initdir}, {default})
1159 Put up a file requester. This only works when "has("browse")"
1160 returns |TRUE| (only in some GUI versions).
1161 The input fields are:
1162 {save} when |TRUE|, select file to write
1163 {title} title for the requester
1164 {initdir} directory to start browsing in
1165 {default} default file name
1166 An empty string is returned when the "Cancel" button is hit,
1167 something went wrong, or browsing is not possible.
1168
1169 *browsedir()*
1170browsedir({title}, {initdir})
1171 Put up a directory requester. This only works when
1172 "has("browse")" returns |TRUE| (only in some GUI versions).
1173 On systems where a directory browser is not supported a file
1174 browser is used. In that case: select a file in the directory
1175 to be used.
1176 The input fields are:
1177 {title} title for the requester
1178 {initdir} directory to start browsing in
1179 When the "Cancel" button is hit, something went wrong, or
1180 browsing is not possible, an empty string is returned.
1181
1182bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001183 Add a buffer to the buffer list with name {name} (must be a
1184 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001185 If a buffer for file {name} already exists, return that buffer
1186 number. Otherwise return the buffer number of the newly
1187 created buffer. When {name} is an empty string then a new
1188 buffer is always created.
1189 The buffer will not have 'buflisted' set and not be loaded
1190 yet. To add some text to the buffer use this: >
1191 let bufnr = bufadd('someName')
1192 call bufload(bufnr)
1193 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001194< Returns 0 on error.
1195 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001196 let bufnr = 'somename'->bufadd()
1197
1198bufexists({buf}) *bufexists()*
1199 The result is a Number, which is |TRUE| if a buffer called
1200 {buf} exists.
1201 If the {buf} argument is a number, buffer numbers are used.
1202 Number zero is the alternate buffer for the current window.
1203
1204 If the {buf} argument is a string it must match a buffer name
1205 exactly. The name can be:
1206 - Relative to the current directory.
1207 - A full path.
1208 - The name of a buffer with 'buftype' set to "nofile".
1209 - A URL name.
1210 Unlisted buffers will be found.
1211 Note that help files are listed by their short name in the
1212 output of |:buffers|, but bufexists() requires using their
1213 long name to be able to find them.
1214 bufexists() may report a buffer exists, but to use the name
1215 with a |:buffer| command you may need to use |expand()|. Esp
1216 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1217 Use "bufexists(0)" to test for the existence of an alternate
1218 file name.
1219
1220 Can also be used as a |method|: >
1221 let exists = 'somename'->bufexists()
1222<
1223 Obsolete name: buffer_exists(). *buffer_exists()*
1224
1225buflisted({buf}) *buflisted()*
1226 The result is a Number, which is |TRUE| if a buffer called
1227 {buf} exists and is listed (has the 'buflisted' option set).
1228 The {buf} argument is used like with |bufexists()|.
1229
1230 Can also be used as a |method|: >
1231 let listed = 'somename'->buflisted()
1232
1233bufload({buf}) *bufload()*
1234 Ensure the buffer {buf} is loaded. When the buffer name
1235 refers to an existing file then the file is read. Otherwise
1236 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001237 then there is no change. If the buffer is not related to a
1238 file the no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001239 If there is an existing swap file for the file of the buffer,
1240 there will be no dialog, the buffer will be loaded anyway.
1241 The {buf} argument is used like with |bufexists()|.
1242
1243 Can also be used as a |method|: >
1244 eval 'somename'->bufload()
1245
1246bufloaded({buf}) *bufloaded()*
1247 The result is a Number, which is |TRUE| if a buffer called
1248 {buf} exists and is loaded (shown in a window or hidden).
1249 The {buf} argument is used like with |bufexists()|.
1250
1251 Can also be used as a |method|: >
1252 let loaded = 'somename'->bufloaded()
1253
1254bufname([{buf}]) *bufname()*
1255 The result is the name of a buffer. Mostly as it is displayed
1256 by the `:ls` command, but not using special names such as
1257 "[No Name]".
1258 If {buf} is omitted the current buffer is used.
1259 If {buf} is a Number, that buffer number's name is given.
1260 Number zero is the alternate buffer for the current window.
1261 If {buf} is a String, it is used as a |file-pattern| to match
1262 with the buffer names. This is always done like 'magic' is
1263 set and 'cpoptions' is empty. When there is more than one
1264 match an empty string is returned.
1265 "" or "%" can be used for the current buffer, "#" for the
1266 alternate buffer.
1267 A full match is preferred, otherwise a match at the start, end
1268 or middle of the buffer name is accepted. If you only want a
1269 full match then put "^" at the start and "$" at the end of the
1270 pattern.
1271 Listed buffers are found first. If there is a single match
1272 with a listed buffer, that one is returned. Next unlisted
1273 buffers are searched for.
1274 If the {buf} is a String, but you want to use it as a buffer
1275 number, force it to be a Number by adding zero to it: >
1276 :echo bufname("3" + 0)
1277< Can also be used as a |method|: >
1278 echo bufnr->bufname()
1279
1280< If the buffer doesn't exist, or doesn't have a name, an empty
1281 string is returned. >
1282 bufname("#") alternate buffer name
1283 bufname(3) name of buffer 3
1284 bufname("%") name of current buffer
1285 bufname("file2") name of buffer where "file2" matches.
1286< *buffer_name()*
1287 Obsolete name: buffer_name().
1288
1289 *bufnr()*
1290bufnr([{buf} [, {create}]])
1291 The result is the number of a buffer, as it is displayed by
1292 the `:ls` command. For the use of {buf}, see |bufname()|
1293 above.
1294
1295 If the buffer doesn't exist, -1 is returned. Or, if the
1296 {create} argument is present and TRUE, a new, unlisted,
1297 buffer is created and its number is returned. Example: >
1298 let newbuf = bufnr('Scratch001', 1)
1299< Using an empty name uses the current buffer. To create a new
1300 buffer with an empty name use |bufadd()|.
1301
1302 bufnr("$") is the last buffer: >
1303 :let last_buffer = bufnr("$")
1304< The result is a Number, which is the highest buffer number
1305 of existing buffers. Note that not all buffers with a smaller
1306 number necessarily exist, because ":bwipeout" may have removed
1307 them. Use bufexists() to test for the existence of a buffer.
1308
1309 Can also be used as a |method|: >
1310 echo bufref->bufnr()
1311<
1312 Obsolete name: buffer_number(). *buffer_number()*
1313 *last_buffer_nr()*
1314 Obsolete name for bufnr("$"): last_buffer_nr().
1315
1316bufwinid({buf}) *bufwinid()*
1317 The result is a Number, which is the |window-ID| of the first
1318 window associated with buffer {buf}. For the use of {buf},
1319 see |bufname()| above. If buffer {buf} doesn't exist or
1320 there is no such window, -1 is returned. Example: >
1321
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001322 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001323<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001324 Only deals with the current tab page. See |win_findbuf()| for
1325 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001326
1327 Can also be used as a |method|: >
1328 FindBuffer()->bufwinid()
1329
1330bufwinnr({buf}) *bufwinnr()*
1331 Like |bufwinid()| but return the window number instead of the
1332 |window-ID|.
1333 If buffer {buf} doesn't exist or there is no such window, -1
1334 is returned. Example: >
1335
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001336 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001337
1338< The number can be used with |CTRL-W_w| and ":wincmd w"
1339 |:wincmd|.
1340
1341 Can also be used as a |method|: >
1342 FindBuffer()->bufwinnr()
1343
1344byte2line({byte}) *byte2line()*
1345 Return the line number that contains the character at byte
1346 count {byte} in the current buffer. This includes the
1347 end-of-line character, depending on the 'fileformat' option
1348 for the current buffer. The first character has byte count
1349 one.
1350 Also see |line2byte()|, |go| and |:goto|.
1351
Bram Moolenaar016188f2022-06-06 20:52:59 +01001352 Returns -1 if the {byte} value is invalid.
1353
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001354 Can also be used as a |method|: >
1355 GetOffset()->byte2line()
1356
1357< {not available when compiled without the |+byte_offset|
1358 feature}
1359
1360byteidx({expr}, {nr}) *byteidx()*
1361 Return byte index of the {nr}'th character in the String
1362 {expr}. Use zero for the first character, it then returns
1363 zero.
1364 If there are no multibyte characters the returned value is
1365 equal to {nr}.
1366 Composing characters are not counted separately, their byte
1367 length is added to the preceding base character. See
1368 |byteidxcomp()| below for counting composing characters
1369 separately.
1370 Example : >
1371 echo matchstr(str, ".", byteidx(str, 3))
1372< will display the fourth character. Another way to do the
1373 same: >
1374 let s = strpart(str, byteidx(str, 3))
1375 echo strpart(s, 0, byteidx(s, 1))
1376< Also see |strgetchar()| and |strcharpart()|.
1377
1378 If there are less than {nr} characters -1 is returned.
1379 If there are exactly {nr} characters the length of the string
1380 in bytes is returned.
1381
1382 Can also be used as a |method|: >
1383 GetName()->byteidx(idx)
1384
1385byteidxcomp({expr}, {nr}) *byteidxcomp()*
1386 Like byteidx(), except that a composing character is counted
1387 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001388 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001389 echo byteidx(s, 1)
1390 echo byteidxcomp(s, 1)
1391 echo byteidxcomp(s, 2)
1392< The first and third echo result in 3 ('e' plus composing
1393 character is 3 bytes), the second echo results in 1 ('e' is
1394 one byte).
1395 Only works differently from byteidx() when 'encoding' is set
1396 to a Unicode encoding.
1397
1398 Can also be used as a |method|: >
1399 GetName()->byteidxcomp(idx)
1400
1401call({func}, {arglist} [, {dict}]) *call()* *E699*
1402 Call function {func} with the items in |List| {arglist} as
1403 arguments.
1404 {func} can either be a |Funcref| or the name of a function.
1405 a:firstline and a:lastline are set to the cursor line.
1406 Returns the return value of the called function.
1407 {dict} is for functions with the "dict" attribute. It will be
1408 used to set the local variable "self". |Dictionary-function|
1409
1410 Can also be used as a |method|: >
1411 GetFunc()->call([arg, arg], dict)
1412
1413ceil({expr}) *ceil()*
1414 Return the smallest integral value greater than or equal to
1415 {expr} as a |Float| (round up).
1416 {expr} must evaluate to a |Float| or a |Number|.
1417 Examples: >
1418 echo ceil(1.456)
1419< 2.0 >
1420 echo ceil(-5.456)
1421< -5.0 >
1422 echo ceil(4.0)
1423< 4.0
1424
Bram Moolenaar016188f2022-06-06 20:52:59 +01001425 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001427 Can also be used as a |method|: >
1428 Compute()->ceil()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001429
1430
1431ch_ functions are documented here: |channel-functions-details|
1432
1433
1434changenr() *changenr()*
1435 Return the number of the most recent change. This is the same
1436 number as what is displayed with |:undolist| and can be used
1437 with the |:undo| command.
1438 When a change was made it is the number of that change. After
1439 redo it is the number of the redone change. After undo it is
1440 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001441 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442
1443char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001444 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001445 Examples: >
1446 char2nr(" ") returns 32
1447 char2nr("ABC") returns 65
1448< When {utf8} is omitted or zero, the current 'encoding' is used.
1449 Example for "utf-8": >
1450 char2nr("á") returns 225
1451 char2nr("á"[0]) returns 195
1452< When {utf8} is TRUE, always treat as UTF-8 characters.
1453 A combining character is a separate character.
1454 |nr2char()| does the opposite.
1455 To turn a string into a list of character numbers: >
1456 let str = "ABC"
1457 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1458< Result: [65, 66, 67]
1459
Bram Moolenaar016188f2022-06-06 20:52:59 +01001460 Returns 0 if {string} is not a |String|.
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462 Can also be used as a |method|: >
1463 GetChar()->char2nr()
1464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001465charclass({string}) *charclass()*
1466 Return the character class of the first character in {string}.
1467 The character class is one of:
1468 0 blank
1469 1 punctuation
1470 2 word character
1471 3 emoji
1472 other specific Unicode class
1473 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001474 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001475
1476
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001477charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001478 Same as |col()| but returns the character index of the column
1479 position given with {expr} instead of the byte position.
1480
1481 Example:
1482 With the cursor on '세' in line 5 with text "여보세요": >
1483 charcol('.') returns 3
1484 col('.') returns 7
1485
1486< Can also be used as a |method|: >
1487 GetPos()->col()
1488<
1489 *charidx()*
1490charidx({string}, {idx} [, {countcc}])
1491 Return the character index of the byte at {idx} in {string}.
1492 The index of the first character is zero.
1493 If there are no multibyte characters the returned value is
1494 equal to {idx}.
1495 When {countcc} is omitted or |FALSE|, then composing characters
1496 are not counted separately, their byte length is
1497 added to the preceding base character.
1498 When {countcc} is |TRUE|, then composing characters are
1499 counted as separate characters.
1500 Returns -1 if the arguments are invalid or if {idx} is greater
1501 than the index of the last byte in {string}. An error is
1502 given if the first argument is not a string, the second
1503 argument is not a number or when the third argument is present
1504 and is not zero or one.
1505 See |byteidx()| and |byteidxcomp()| for getting the byte index
1506 from the character index.
1507 Examples: >
1508 echo charidx('áb́ć', 3) returns 1
1509 echo charidx('áb́ć', 6, 1) returns 4
1510 echo charidx('áb́ć', 16) returns -1
1511<
1512 Can also be used as a |method|: >
1513 GetName()->charidx(idx)
1514
1515chdir({dir}) *chdir()*
1516 Change the current working directory to {dir}. The scope of
1517 the directory change depends on the directory of the current
1518 window:
1519 - If the current window has a window-local directory
1520 (|:lcd|), then changes the window local directory.
1521 - Otherwise, if the current tabpage has a local
1522 directory (|:tcd|) then changes the tabpage local
1523 directory.
1524 - Otherwise, changes the global directory.
1525 {dir} must be a String.
1526 If successful, returns the previous working directory. Pass
1527 this to another chdir() to restore the directory.
1528 On failure, returns an empty string.
1529
1530 Example: >
1531 let save_dir = chdir(newdir)
1532 if save_dir != ""
1533 " ... do some work
1534 call chdir(save_dir)
1535 endif
1536
1537< Can also be used as a |method|: >
1538 GetDir()->chdir()
1539<
1540cindent({lnum}) *cindent()*
1541 Get the amount of indent for line {lnum} according the C
1542 indenting rules, as with 'cindent'.
1543 The indent is counted in spaces, the value of 'tabstop' is
1544 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001545 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001546 See |C-indenting|.
1547
1548 Can also be used as a |method|: >
1549 GetLnum()->cindent()
1550
1551clearmatches([{win}]) *clearmatches()*
1552 Clears all matches previously defined for the current window
1553 by |matchadd()| and the |:match| commands.
1554 If {win} is specified, use the window with this number or
1555 window ID instead of the current window.
1556
1557 Can also be used as a |method|: >
1558 GetWin()->clearmatches()
1559<
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001560col({expr} [, {winid}) *col()*
1561 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001562 position given with {expr}. The accepted positions are:
1563 . the cursor position
1564 $ the end of the cursor line (the result is the
1565 number of bytes in the cursor line plus one)
1566 'x position of mark x (if the mark is not set, 0 is
1567 returned)
1568 v In Visual mode: the start of the Visual area (the
1569 cursor is the end). When not in Visual mode
1570 returns the cursor position. Differs from |'<| in
1571 that it's updated right away.
1572 Additionally {expr} can be [lnum, col]: a |List| with the line
1573 and column number. Most useful when the column is "$", to get
1574 the last column of a specific line. When "lnum" or "col" is
1575 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001576 With the optional {winid} argument the values are obtained for
1577 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001578 To get the line number use |line()|. To get both use
1579 |getpos()|.
1580 For the screen column position use |virtcol()|. For the
1581 character position use |charcol()|.
1582 Note that only marks in the current file can be used.
1583 Examples: >
1584 col(".") column of cursor
1585 col("$") length of cursor line plus one
1586 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001587 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001588< The first column is 1. Returns 0 if {expr} is invalid or when
1589 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001590 For an uppercase mark the column may actually be in another
1591 buffer.
1592 For the cursor position, when 'virtualedit' is active, the
1593 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001594 line. Also, when using a <Cmd> mapping the cursor isn't
1595 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001596 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001597
1598< Can also be used as a |method|: >
1599 GetPos()->col()
1600<
1601
1602complete({startcol}, {matches}) *complete()* *E785*
1603 Set the matches for Insert mode completion.
1604 Can only be used in Insert mode. You need to use a mapping
1605 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1606 or with an expression mapping.
1607 {startcol} is the byte offset in the line where the completed
1608 text start. The text up to the cursor is the original text
1609 that will be replaced by the matches. Use col('.') for an
1610 empty string. "col('.') - 1" will replace one character by a
1611 match.
1612 {matches} must be a |List|. Each |List| item is one match.
1613 See |complete-items| for the kind of items that are possible.
1614 "longest" in 'completeopt' is ignored.
1615 Note that the after calling this function you need to avoid
1616 inserting anything that would cause completion to stop.
1617 The match can be selected with CTRL-N and CTRL-P as usual with
1618 Insert mode completion. The popup menu will appear if
1619 specified, see |ins-completion-menu|.
1620 Example: >
1621 inoremap <F5> <C-R>=ListMonths()<CR>
1622
1623 func! ListMonths()
1624 call complete(col('.'), ['January', 'February', 'March',
1625 \ 'April', 'May', 'June', 'July', 'August', 'September',
1626 \ 'October', 'November', 'December'])
1627 return ''
1628 endfunc
1629< This isn't very useful, but it shows how it works. Note that
1630 an empty string is returned to avoid a zero being inserted.
1631
1632 Can also be used as a |method|, the base is passed as the
1633 second argument: >
1634 GetMatches()->complete(col('.'))
1635
1636complete_add({expr}) *complete_add()*
1637 Add {expr} to the list of matches. Only to be used by the
1638 function specified with the 'completefunc' option.
1639 Returns 0 for failure (empty string or out of memory),
1640 1 when the match was added, 2 when the match was already in
1641 the list.
1642 See |complete-functions| for an explanation of {expr}. It is
1643 the same as one item in the list that 'omnifunc' would return.
1644
1645 Can also be used as a |method|: >
1646 GetMoreMatches()->complete_add()
1647
1648complete_check() *complete_check()*
1649 Check for a key typed while looking for completion matches.
1650 This is to be used when looking for matches takes some time.
1651 Returns |TRUE| when searching for matches is to be aborted,
1652 zero otherwise.
1653 Only to be used by the function specified with the
1654 'completefunc' option.
1655
1656
1657complete_info([{what}]) *complete_info()*
1658 Returns a |Dictionary| with information about Insert mode
1659 completion. See |ins-completion|.
1660 The items are:
1661 mode Current completion mode name string.
1662 See |complete_info_mode| for the values.
1663 pum_visible |TRUE| if popup menu is visible.
1664 See |pumvisible()|.
1665 items List of completion matches. Each item is a
1666 dictionary containing the entries "word",
1667 "abbr", "menu", "kind", "info" and "user_data".
1668 See |complete-items|.
1669 selected Selected item index. First index is zero.
1670 Index is -1 if no item is selected (showing
1671 typed text only, or the last completion after
1672 no item is selected when using the <Up> or
1673 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001674 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001675
1676 *complete_info_mode*
1677 mode values are:
1678 "" Not in completion mode
1679 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1680 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1681 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1682 |i_CTRL-X_CTRL-Y|
1683 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1684 "files" File names |i_CTRL-X_CTRL-F|
1685 "tags" Tags |i_CTRL-X_CTRL-]|
1686 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1687 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1688 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1689 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1690 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1691 "function" User defined completion |i_CTRL-X_CTRL-U|
1692 "omni" Omni completion |i_CTRL-X_CTRL-O|
1693 "spell" Spelling suggestions |i_CTRL-X_s|
1694 "eval" |complete()| completion
1695 "unknown" Other internal modes
1696
1697 If the optional {what} list argument is supplied, then only
1698 the items listed in {what} are returned. Unsupported items in
1699 {what} are silently ignored.
1700
1701 To get the position and size of the popup menu, see
1702 |pum_getpos()|. It's also available in |v:event| during the
1703 |CompleteChanged| event.
1704
Bram Moolenaar016188f2022-06-06 20:52:59 +01001705 Returns an empty |Dictionary| on error.
1706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001707 Examples: >
1708 " Get all items
1709 call complete_info()
1710 " Get only 'mode'
1711 call complete_info(['mode'])
1712 " Get only 'mode' and 'pum_visible'
1713 call complete_info(['mode', 'pum_visible'])
1714
1715< Can also be used as a |method|: >
1716 GetItems()->complete_info()
1717<
1718 *confirm()*
1719confirm({msg} [, {choices} [, {default} [, {type}]]])
1720 confirm() offers the user a dialog, from which a choice can be
1721 made. It returns the number of the choice. For the first
1722 choice this is 1.
1723 Note: confirm() is only supported when compiled with dialog
1724 support, see |+dialog_con| and |+dialog_gui|.
1725
1726 {msg} is displayed in a |dialog| with {choices} as the
1727 alternatives. When {choices} is missing or empty, "&OK" is
1728 used (and translated).
1729 {msg} is a String, use '\n' to include a newline. Only on
1730 some systems the string is wrapped when it doesn't fit.
1731
1732 {choices} is a String, with the individual choices separated
1733 by '\n', e.g. >
1734 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1735< The letter after the '&' is the shortcut key for that choice.
1736 Thus you can type 'c' to select "Cancel". The shortcut does
1737 not need to be the first letter: >
1738 confirm("file has been modified", "&Save\nSave &All")
1739< For the console, the first letter of each choice is used as
1740 the default shortcut key. Case is ignored.
1741
1742 The optional {default} argument is the number of the choice
1743 that is made if the user hits <CR>. Use 1 to make the first
1744 choice the default one. Use 0 to not set a default. If
1745 {default} is omitted, 1 is used.
1746
1747 The optional {type} String argument gives the type of dialog.
1748 This is only used for the icon of the GTK, Mac, Motif and
1749 Win32 GUI. It can be one of these values: "Error",
1750 "Question", "Info", "Warning" or "Generic". Only the first
1751 character is relevant. When {type} is omitted, "Generic" is
1752 used.
1753
1754 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1755 or another valid interrupt key, confirm() returns 0.
1756
1757 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001758 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001759 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001760 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001761 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001762 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001763 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001764 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001765 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001766 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001767< In a GUI dialog, buttons are used. The layout of the buttons
1768 depends on the 'v' flag in 'guioptions'. If it is included,
1769 the buttons are always put vertically. Otherwise, confirm()
1770 tries to put the buttons in one horizontal line. If they
1771 don't fit, a vertical layout is used anyway. For some systems
1772 the horizontal layout is always used.
1773
1774 Can also be used as a |method|in: >
1775 BuildMessage()->confirm("&Yes\n&No")
1776<
1777 *copy()*
1778copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
1779 different from using {expr} directly.
1780 When {expr} is a |List| a shallow copy is created. This means
1781 that the original |List| can be changed without changing the
1782 copy, and vice versa. But the items are identical, thus
1783 changing an item changes the contents of both |Lists|.
1784 A |Dictionary| is copied in a similar way as a |List|.
1785 Also see |deepcopy()|.
1786 Can also be used as a |method|: >
1787 mylist->copy()
1788
1789cos({expr}) *cos()*
1790 Return the cosine of {expr}, measured in radians, as a |Float|.
1791 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001792 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001793 Examples: >
1794 :echo cos(100)
1795< 0.862319 >
1796 :echo cos(-4.01)
1797< -0.646043
1798
1799 Can also be used as a |method|: >
1800 Compute()->cos()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001801
1802
1803cosh({expr}) *cosh()*
1804 Return the hyperbolic cosine of {expr} as a |Float| in the range
1805 [1, inf].
1806 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001807 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001808 Examples: >
1809 :echo cosh(0.5)
1810< 1.127626 >
1811 :echo cosh(-0.5)
1812< -1.127626
1813
1814 Can also be used as a |method|: >
1815 Compute()->cosh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001816
1817
1818count({comp}, {expr} [, {ic} [, {start}]]) *count()*
1819 Return the number of times an item with value {expr} appears
1820 in |String|, |List| or |Dictionary| {comp}.
1821
1822 If {start} is given then start with the item with this index.
1823 {start} can only be used with a |List|.
1824
1825 When {ic} is given and it's |TRUE| then case is ignored.
1826
1827 When {comp} is a string then the number of not overlapping
1828 occurrences of {expr} is returned. Zero is returned when
1829 {expr} is an empty string.
1830
1831 Can also be used as a |method|: >
1832 mylist->count(val)
1833<
1834 *cscope_connection()*
1835cscope_connection([{num} , {dbpath} [, {prepend}]])
1836 Checks for the existence of a |cscope| connection. If no
1837 parameters are specified, then the function returns:
1838 0, if cscope was not available (not compiled in), or
1839 if there are no cscope connections;
1840 1, if there is at least one cscope connection.
1841
1842 If parameters are specified, then the value of {num}
1843 determines how existence of a cscope connection is checked:
1844
1845 {num} Description of existence check
1846 ----- ------------------------------
1847 0 Same as no parameters (e.g., "cscope_connection()").
1848 1 Ignore {prepend}, and use partial string matches for
1849 {dbpath}.
1850 2 Ignore {prepend}, and use exact string matches for
1851 {dbpath}.
1852 3 Use {prepend}, use partial string matches for both
1853 {dbpath} and {prepend}.
1854 4 Use {prepend}, use exact string matches for both
1855 {dbpath} and {prepend}.
1856
1857 Note: All string comparisons are case sensitive!
1858
1859 Examples. Suppose we had the following (from ":cs show"): >
1860
1861 # pid database name prepend path
1862 0 27664 cscope.out /usr/local
1863<
1864 Invocation Return Val ~
1865 ---------- ---------- >
1866 cscope_connection() 1
1867 cscope_connection(1, "out") 1
1868 cscope_connection(2, "out") 0
1869 cscope_connection(3, "out") 0
1870 cscope_connection(3, "out", "local") 1
1871 cscope_connection(4, "out") 0
1872 cscope_connection(4, "out", "local") 0
1873 cscope_connection(4, "cscope.out", "/usr/local") 1
1874<
1875cursor({lnum}, {col} [, {off}]) *cursor()*
1876cursor({list})
1877 Positions the cursor at the column (byte count) {col} in the
1878 line {lnum}. The first column is one.
1879
1880 When there is one argument {list} this is used as a |List|
1881 with two, three or four item:
1882 [{lnum}, {col}]
1883 [{lnum}, {col}, {off}]
1884 [{lnum}, {col}, {off}, {curswant}]
1885 This is like the return value of |getpos()| or |getcurpos()|,
1886 but without the first item.
1887
1888 To position the cursor using the character count, use
1889 |setcursorcharpos()|.
1890
1891 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01001892 {lnum} is used like with |getline()|, except that if {lnum} is
1893 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001894 If {lnum} is greater than the number of lines in the buffer,
1895 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001896 If {col} is greater than the number of bytes in the line,
1897 the cursor will be positioned at the last character in the
1898 line.
1899 If {col} is zero, the cursor will stay in the current column.
1900 If {curswant} is given it is used to set the preferred column
1901 for vertical movement. Otherwise {col} is used.
1902
1903 When 'virtualedit' is used {off} specifies the offset in
1904 screen columns from the start of the character. E.g., a
1905 position within a <Tab> or after the last character.
1906 Returns 0 when the position could be set, -1 otherwise.
1907
1908 Can also be used as a |method|: >
1909 GetCursorPos()->cursor()
1910
1911debugbreak({pid}) *debugbreak()*
1912 Specifically used to interrupt a program being debugged. It
1913 will cause process {pid} to get a SIGTRAP. Behavior for other
1914 processes is undefined. See |terminal-debugger|.
1915 {only available on MS-Windows}
1916
Bram Moolenaar016188f2022-06-06 20:52:59 +01001917 Returns |TRUE| if successfully interrupted the program.
1918 Otherwise returns |FALSE|.
1919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001920 Can also be used as a |method|: >
1921 GetPid()->debugbreak()
1922
1923deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
1924 Make a copy of {expr}. For Numbers and Strings this isn't
1925 different from using {expr} directly.
1926 When {expr} is a |List| a full copy is created. This means
1927 that the original |List| can be changed without changing the
1928 copy, and vice versa. When an item is a |List| or
1929 |Dictionary|, a copy for it is made, recursively. Thus
1930 changing an item in the copy does not change the contents of
1931 the original |List|.
1932 A |Dictionary| is copied in a similar way as a |List|.
1933
1934 When {noref} is omitted or zero a contained |List| or
1935 |Dictionary| is only copied once. All references point to
1936 this single copy. With {noref} set to 1 every occurrence of a
1937 |List| or |Dictionary| results in a new copy. This also means
1938 that a cyclic reference causes deepcopy() to fail.
1939 *E724*
1940 Nesting is possible up to 100 levels. When there is an item
1941 that refers back to a higher level making a deep copy with
1942 {noref} set to 1 will fail.
1943 Also see |copy()|.
1944
1945 Can also be used as a |method|: >
1946 GetObject()->deepcopy()
1947
1948delete({fname} [, {flags}]) *delete()*
1949 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01001950 name {fname}.
1951
1952 This also works when {fname} is a symbolic link. The symbolic
1953 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954
1955 When {flags} is "d": Deletes the directory by the name
1956 {fname}. This fails when directory {fname} is not empty.
1957
1958 When {flags} is "rf": Deletes the directory by the name
1959 {fname} and everything in it, recursively. BE CAREFUL!
1960 Note: on MS-Windows it is not possible to delete a directory
1961 that is being used.
1962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001963 The result is a Number, which is 0/false if the delete
1964 operation was successful and -1/true when the deletion failed
1965 or partly failed.
1966
1967 Use |remove()| to delete an item from a |List|.
1968 To delete a line from the buffer use |:delete| or
1969 |deletebufline()|.
1970
1971 Can also be used as a |method|: >
1972 GetName()->delete()
1973
1974deletebufline({buf}, {first} [, {last}]) *deletebufline()*
1975 Delete lines {first} to {last} (inclusive) from buffer {buf}.
1976 If {last} is omitted then delete line {first} only.
1977 On success 0 is returned, on failure 1 is returned.
1978
1979 This function works only for loaded buffers. First call
1980 |bufload()| if needed.
1981
1982 For the use of {buf}, see |bufname()| above.
1983
1984 {first} and {last} are used like with |getline()|. Note that
1985 when using |line()| this refers to the current buffer. Use "$"
1986 to refer to the last line in buffer {buf}.
1987
1988 Can also be used as a |method|: >
1989 GetBuffer()->deletebufline(1)
1990<
1991 *did_filetype()*
1992did_filetype() Returns |TRUE| when autocommands are being executed and the
1993 FileType event has been triggered at least once. Can be used
1994 to avoid triggering the FileType event again in the scripts
1995 that detect the file type. |FileType|
1996 Returns |FALSE| when `:setf FALLBACK` was used.
1997 When editing another file, the counter is reset, thus this
1998 really checks if the FileType event has been triggered for the
1999 current buffer. This allows an autocommand that starts
2000 editing another buffer to set 'filetype' and load a syntax
2001 file.
2002
2003diff_filler({lnum}) *diff_filler()*
2004 Returns the number of filler lines above line {lnum}.
2005 These are the lines that were inserted at this point in
2006 another diff'ed window. These filler lines are shown in the
2007 display but don't exist in the buffer.
2008 {lnum} is used like with |getline()|. Thus "." is the current
2009 line, "'m" mark m, etc.
2010 Returns 0 if the current window is not in diff mode.
2011
2012 Can also be used as a |method|: >
2013 GetLnum()->diff_filler()
2014
2015diff_hlID({lnum}, {col}) *diff_hlID()*
2016 Returns the highlight ID for diff mode at line {lnum} column
2017 {col} (byte index). When the current line does not have a
2018 diff change zero is returned.
2019 {lnum} is used like with |getline()|. Thus "." is the current
2020 line, "'m" mark m, etc.
2021 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2022 line.
2023 The highlight ID can be used with |synIDattr()| to obtain
2024 syntax information about the highlighting.
2025
2026 Can also be used as a |method|: >
2027 GetLnum()->diff_hlID(col)
2028<
2029
2030digraph_get({chars}) *digraph_get()* *E1214*
2031 Return the digraph of {chars}. This should be a string with
2032 exactly two characters. If {chars} are not just two
2033 characters, or the digraph of {chars} does not exist, an error
2034 is given and an empty string is returned.
2035
2036 The character will be converted from Unicode to 'encoding'
2037 when needed. This does require the conversion to be
2038 available, it might fail.
2039
2040 Also see |digraph_getlist()|.
2041
2042 Examples: >
2043 " Get a built-in digraph
2044 :echo digraph_get('00') " Returns '∞'
2045
2046 " Get a user-defined digraph
2047 :call digraph_set('aa', 'あ')
2048 :echo digraph_get('aa') " Returns 'あ'
2049<
2050 Can also be used as a |method|: >
2051 GetChars()->digraph_get()
2052<
2053 This function works only when compiled with the |+digraphs|
2054 feature. If this feature is disabled, this function will
2055 display an error message.
2056
2057
2058digraph_getlist([{listall}]) *digraph_getlist()*
2059 Return a list of digraphs. If the {listall} argument is given
2060 and it is TRUE, return all digraphs, including the default
2061 digraphs. Otherwise, return only user-defined digraphs.
2062
2063 The characters will be converted from Unicode to 'encoding'
2064 when needed. This does require the conservation to be
2065 available, it might fail.
2066
2067 Also see |digraph_get()|.
2068
2069 Examples: >
2070 " Get user-defined digraphs
2071 :echo digraph_getlist()
2072
2073 " Get all the digraphs, including default digraphs
2074 :echo digraph_getlist(1)
2075<
2076 Can also be used as a |method|: >
2077 GetNumber()->digraph_getlist()
2078<
2079 This function works only when compiled with the |+digraphs|
2080 feature. If this feature is disabled, this function will
2081 display an error message.
2082
2083
Bram Moolenaara2baa732022-02-04 16:09:54 +00002084digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002085 Add digraph {chars} to the list. {chars} must be a string
2086 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002087 encoded character. *E1215*
2088 Be careful, composing characters are NOT ignored. This
2089 function is similar to |:digraphs| command, but useful to add
2090 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002091
2092 The function result is v:true if |digraph| is registered. If
2093 this fails an error message is given and v:false is returned.
2094
2095 If you want to define multiple digraphs at once, you can use
2096 |digraph_setlist()|.
2097
2098 Example: >
2099 call digraph_set(' ', 'あ')
2100<
2101 Can be used as a |method|: >
2102 GetString()->digraph_set('あ')
2103<
2104 This function works only when compiled with the |+digraphs|
2105 feature. If this feature is disabled, this function will
2106 display an error message.
2107
2108
2109digraph_setlist({digraphlist}) *digraph_setlist()*
2110 Similar to |digraph_set()| but this function can add multiple
2111 digraphs at once. {digraphlist} is a list composed of lists,
2112 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002113 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002114 Example: >
2115 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2116<
2117 It is similar to the following: >
2118 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2119 call digraph_set(chars, digraph)
2120 endfor
2121< Except that the function returns after the first error,
2122 following digraphs will not be added.
2123
2124 Can be used as a |method|: >
2125 GetList()->digraph_setlist()
2126<
2127 This function works only when compiled with the |+digraphs|
2128 feature. If this feature is disabled, this function will
2129 display an error message.
2130
2131
2132echoraw({string}) *echoraw()*
2133 Output {string} as-is, including unprintable characters.
2134 This can be used to output a terminal code. For example, to
2135 disable modifyOtherKeys: >
2136 call echoraw(&t_TE)
2137< and to enable it again: >
2138 call echoraw(&t_TI)
2139< Use with care, you can mess up the terminal this way.
2140
2141
2142empty({expr}) *empty()*
2143 Return the Number 1 if {expr} is empty, zero otherwise.
2144 - A |List| or |Dictionary| is empty when it does not have any
2145 items.
2146 - A |String| is empty when its length is zero.
2147 - A |Number| and |Float| are empty when their value is zero.
2148 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2149 - A |Job| is empty when it failed to start.
2150 - A |Channel| is empty when it is closed.
2151 - A |Blob| is empty when its length is zero.
2152
2153 For a long |List| this is much faster than comparing the
2154 length with zero.
2155
2156 Can also be used as a |method|: >
2157 mylist->empty()
2158
2159environ() *environ()*
2160 Return all of environment variables as dictionary. You can
2161 check if an environment variable exists like this: >
2162 :echo has_key(environ(), 'HOME')
2163< Note that the variable name may be CamelCase; to ignore case
2164 use this: >
2165 :echo index(keys(environ()), 'HOME', 0, 1) != -1
2166
2167escape({string}, {chars}) *escape()*
2168 Escape the characters in {chars} that occur in {string} with a
2169 backslash. Example: >
2170 :echo escape('c:\program files\vim', ' \')
2171< results in: >
2172 c:\\program\ files\\vim
2173< Also see |shellescape()| and |fnameescape()|.
2174
2175 Can also be used as a |method|: >
2176 GetText()->escape(' \')
2177<
2178 *eval()*
2179eval({string}) Evaluate {string} and return the result. Especially useful to
2180 turn the result of |string()| back into the original value.
2181 This works for Numbers, Floats, Strings, Blobs and composites
2182 of them. Also works for |Funcref|s that refer to existing
2183 functions.
2184
2185 Can also be used as a |method|: >
2186 argv->join()->eval()
2187
2188eventhandler() *eventhandler()*
2189 Returns 1 when inside an event handler. That is that Vim got
2190 interrupted while waiting for the user to type a character,
2191 e.g., when dropping a file on Vim. This means interactive
2192 commands cannot be used. Otherwise zero is returned.
2193
2194executable({expr}) *executable()*
2195 This function checks if an executable with the name {expr}
2196 exists. {expr} must be the name of the program without any
2197 arguments.
2198 executable() uses the value of $PATH and/or the normal
2199 searchpath for programs. *PATHEXT*
2200 On MS-Windows the ".exe", ".bat", etc. can optionally be
2201 included. Then the extensions in $PATHEXT are tried. Thus if
2202 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2203 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2204 by itself can be used in $PATHEXT to try using the name
2205 without an extension. When 'shell' looks like a Unix shell,
2206 then the name is also tried without adding an extension.
2207 On MS-Windows it only checks if the file exists and is not a
2208 directory, not if it's really executable.
2209 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002210 normally found. Since this directory is added to $PATH it
2211 should also work to execute it |win32-PATH|. This can be
2212 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2213 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002214 The result is a Number:
2215 1 exists
2216 0 does not exist
2217 -1 not implemented on this system
2218 |exepath()| can be used to get the full path of an executable.
2219
2220 Can also be used as a |method|: >
2221 GetCommand()->executable()
2222
2223execute({command} [, {silent}]) *execute()*
2224 Execute an Ex command or commands and return the output as a
2225 string.
2226 {command} can be a string or a List. In case of a List the
2227 lines are executed one by one.
2228 This is equivalent to: >
2229 redir => var
2230 {command}
2231 redir END
2232<
2233 The optional {silent} argument can have these values:
2234 "" no `:silent` used
2235 "silent" `:silent` used
2236 "silent!" `:silent!` used
2237 The default is "silent". Note that with "silent!", unlike
2238 `:redir`, error messages are dropped. When using an external
2239 command the screen may be messed up, use `system()` instead.
2240 *E930*
2241 It is not possible to use `:redir` anywhere in {command}.
2242
2243 To get a list of lines use |split()| on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002244 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002245
2246< To execute a command in another window than the current one
2247 use `win_execute()`.
2248
2249 When used recursively the output of the recursive call is not
2250 included in the output of the higher level call.
2251
2252 Can also be used as a |method|: >
2253 GetCommand()->execute()
2254
2255exepath({expr}) *exepath()*
2256 If {expr} is an executable and is either an absolute path, a
2257 relative path or found in $PATH, return the full path.
2258 Note that the current directory is used when {expr} starts
2259 with "./", which may be a problem for Vim: >
2260 echo exepath(v:progpath)
2261< If {expr} cannot be found in $PATH or is not executable then
2262 an empty string is returned.
2263
2264 Can also be used as a |method|: >
2265 GetCommand()->exepath()
2266<
2267 *exists()*
2268exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined,
2269 zero otherwise.
2270
2271 Note: In a compiled |:def| function the evaluation is done at
2272 runtime. Use `exists_compiled()` to evaluate the expression
2273 at compile time.
2274
2275 For checking for a supported feature use |has()|.
2276 For checking if a file exists use |filereadable()|.
2277
2278 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002279 varname internal variable (see
2280 dict.key |internal-variables|). Also works
2281 list[i] for |curly-braces-names|, |Dictionary|
2282 import.Func entries, |List| items, imported
Bram Moolenaar944697a2022-02-20 19:48:20 +00002283 items, etc.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002284 Does not work for local variables in a
2285 compiled `:def` function.
Bram Moolenaar944697a2022-02-20 19:48:20 +00002286 Also works for a function in |Vim9|
2287 script, since it can be used as a
2288 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002289 Beware that evaluating an index may
2290 cause an error message for an invalid
2291 expression. E.g.: >
2292 :let l = [1, 2, 3]
2293 :echo exists("l[5]")
2294< 0 >
2295 :echo exists("l[xx]")
2296< E121: Undefined variable: xx
2297 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002298 &option-name Vim option (only checks if it exists,
2299 not if it really works)
2300 +option-name Vim option that works.
2301 $ENVNAME environment variable (could also be
2302 done by comparing with an empty
2303 string)
2304 *funcname built-in function (see |functions|)
2305 or user defined function (see
2306 |user-functions|) that is implemented.
2307 Also works for a variable that is a
2308 Funcref.
2309 ?funcname built-in function that could be
2310 implemented; to be used to check if
2311 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002312 :cmdname Ex command: built-in command, user
2313 command or command modifier |:command|.
2314 Returns:
2315 1 for match with start of a command
2316 2 full match with a command
2317 3 matches several user commands
2318 To check for a supported command
2319 always check the return value to be 2.
2320 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002321 :3match The |:3match| command (but you
2322 probably should not use it, it is
2323 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002324 #event autocommand defined for this event
2325 #event#pattern autocommand defined for this event and
2326 pattern (the pattern is taken
2327 literally and compared to the
2328 autocommand patterns character by
2329 character)
2330 #group autocommand group exists
2331 #group#event autocommand defined for this group and
2332 event.
2333 #group#event#pattern
2334 autocommand defined for this group,
2335 event and pattern.
2336 ##event autocommand for this event is
2337 supported.
2338
2339 Examples: >
2340 exists("&shortname")
2341 exists("$HOSTNAME")
2342 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002343 exists("*s:MyFunc") " only for legacy script
2344 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002345 exists("bufcount")
2346 exists(":Make")
2347 exists("#CursorHold")
2348 exists("#BufReadPre#*.gz")
2349 exists("#filetypeindent")
2350 exists("#filetypeindent#FileType")
2351 exists("#filetypeindent#FileType#*")
2352 exists("##ColorScheme")
2353< There must be no space between the symbol (&/$/*/#) and the
2354 name.
2355 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002356 a few cases this is ignored. That may become stricter in the
2357 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002358 Working example: >
2359 exists(":make")
2360< NOT working example: >
2361 exists(":make install")
2362
2363< Note that the argument must be a string, not the name of the
2364 variable itself. For example: >
2365 exists(bufcount)
2366< This doesn't check for existence of the "bufcount" variable,
2367 but gets the value of "bufcount", and checks if that exists.
2368
2369 Can also be used as a |method|: >
2370 Varname()->exists()
2371<
2372
2373exists_compiled({expr}) *exists_compiled()*
2374 Like `exists()` but evaluated at compile time. This is useful
2375 to skip a block where a function is used that would otherwise
2376 give an error: >
2377 if exists_compiled('*ThatFunction')
2378 ThatFunction('works')
2379 endif
2380< If `exists()` were used then a compilation error would be
2381 given if ThatFunction() is not defined.
2382
2383 {expr} must be a literal string. *E1232*
2384 Can only be used in a |:def| function. *E1233*
2385 This does not work to check for arguments or local variables.
2386
2387
2388exp({expr}) *exp()*
2389 Return the exponential of {expr} as a |Float| in the range
2390 [0, inf].
2391 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002392 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002393 Examples: >
2394 :echo exp(2)
2395< 7.389056 >
2396 :echo exp(-1)
2397< 0.367879
2398
2399 Can also be used as a |method|: >
2400 Compute()->exp()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002401
2402
2403expand({string} [, {nosuf} [, {list}]]) *expand()*
2404 Expand wildcards and the following special keywords in
2405 {string}. 'wildignorecase' applies.
2406
2407 If {list} is given and it is |TRUE|, a List will be returned.
2408 Otherwise the result is a String and when there are several
2409 matches, they are separated by <NL> characters. [Note: in
2410 version 5.0 a space was used, which caused problems when a
2411 file name contains a space]
2412
2413 If the expansion fails, the result is an empty string. A name
2414 for a non-existing file is not included, unless {string} does
2415 not start with '%', '#' or '<', see below.
2416
2417 When {string} starts with '%', '#' or '<', the expansion is
2418 done like for the |cmdline-special| variables with their
2419 associated modifiers. Here is a short overview:
2420
2421 % current file name
2422 # alternate file name
2423 #n alternate file name n
2424 <cfile> file name under the cursor
2425 <afile> autocmd file name
2426 <abuf> autocmd buffer number (as a String!)
2427 <amatch> autocmd matched name
2428 <cexpr> C expression under the cursor
2429 <sfile> sourced script file or function name
2430 <slnum> sourced script line number or function
2431 line number
2432 <sflnum> script file line number, also when in
2433 a function
2434 <SID> "<SNR>123_" where "123" is the
2435 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002436 <script> sourced script file, or script file
2437 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438 <stack> call stack
2439 <cword> word under the cursor
2440 <cWORD> WORD under the cursor
2441 <client> the {clientid} of the last received
2442 message |server2client()|
2443 Modifiers:
2444 :p expand to full path
2445 :h head (last path component removed)
2446 :t tail (last path component only)
2447 :r root (one extension removed)
2448 :e extension only
2449
2450 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002451 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002452< Note that when expanding a string that starts with '%', '#' or
2453 '<', any following text is ignored. This does NOT work: >
2454 :let doesntwork = expand("%:h.bak")
2455< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002456 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002457< Also note that expanding "<cfile>" and others only returns the
2458 referenced file name without further expansion. If "<cfile>"
2459 is "~/.cshrc", you need to do another expand() to have the
2460 "~/" expanded into the path of the home directory: >
2461 :echo expand(expand("<cfile>"))
2462<
2463 There cannot be white space between the variables and the
2464 following modifier. The |fnamemodify()| function can be used
2465 to modify normal file names.
2466
2467 When using '%' or '#', and the current or alternate file name
2468 is not defined, an empty string is used. Using "%:p" in a
2469 buffer with no name, results in the current directory, with a
2470 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002471 When 'verbose' is set then expanding '%', '#' and <> items
2472 will result in an error message if the argument cannot be
2473 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002474
2475 When {string} does not start with '%', '#' or '<', it is
2476 expanded like a file name is expanded on the command line.
2477 'suffixes' and 'wildignore' are used, unless the optional
2478 {nosuf} argument is given and it is |TRUE|.
2479 Names for non-existing files are included. The "**" item can
2480 be used to search in a directory tree. For example, to find
2481 all "README" files in the current directory and below: >
2482 :echo expand("**/README")
2483<
2484 expand() can also be used to expand variables and environment
2485 variables that are only known in a shell. But this can be
2486 slow, because a shell may be used to do the expansion. See
2487 |expr-env-expand|.
2488 The expanded variable is still handled like a list of file
2489 names. When an environment variable cannot be expanded, it is
2490 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2491 "$FOOBAR".
2492
2493 See |glob()| for finding existing files. See |system()| for
2494 getting the raw output of an external command.
2495
2496 Can also be used as a |method|: >
2497 Getpattern()->expand()
2498
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002499expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002500 Expand special items in String {string} like what is done for
2501 an Ex command such as `:edit`. This expands special keywords,
2502 like with |expand()|, and environment variables, anywhere in
2503 {string}. "~user" and "~/path" are only expanded at the
2504 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002505
2506 The following items are supported in the {options} Dict
2507 argument:
2508 errmsg If set to TRUE, error messages are displayed
2509 if an error is encountered during expansion.
2510 By default, error messages are not displayed.
2511
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002512 Returns the expanded string. If an error is encountered
2513 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002514
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002515 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002516 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002517 make /path/runtime/doc/builtin.o
2518 :echo expandcmd('make %<.o', {'errmsg': v:true})
2519<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002520 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521 GetCommand()->expandcmd()
2522<
2523extend({expr1}, {expr2} [, {expr3}]) *extend()*
2524 {expr1} and {expr2} must be both |Lists| or both
2525 |Dictionaries|.
2526
2527 If they are |Lists|: Append {expr2} to {expr1}.
2528 If {expr3} is given insert the items of {expr2} before the
2529 item with index {expr3} in {expr1}. When {expr3} is zero
2530 insert before the first item. When {expr3} is equal to
2531 len({expr1}) then {expr2} is appended.
2532 Examples: >
2533 :echo sort(extend(mylist, [7, 5]))
2534 :call extend(mylist, [2, 3], 1)
2535< When {expr1} is the same List as {expr2} then the number of
2536 items copied is equal to the original length of the List.
2537 E.g., when {expr3} is 1 you get N new copies of the first item
2538 (where N is the original length of the List).
2539 Use |add()| to concatenate one item to a list. To concatenate
2540 two lists into a new list use the + operator: >
2541 :let newlist = [1, 2, 3] + [4, 5]
2542<
2543 If they are |Dictionaries|:
2544 Add all entries from {expr2} to {expr1}.
2545 If a key exists in both {expr1} and {expr2} then {expr3} is
2546 used to decide what to do:
2547 {expr3} = "keep": keep the value of {expr1}
2548 {expr3} = "force": use the value of {expr2}
2549 {expr3} = "error": give an error message *E737*
2550 When {expr3} is omitted then "force" is assumed.
2551
2552 {expr1} is changed when {expr2} is not empty. If necessary
2553 make a copy of {expr1} first.
2554 {expr2} remains unchanged.
2555 When {expr1} is locked and {expr2} is not empty the operation
2556 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002557 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002558
2559 Can also be used as a |method|: >
2560 mylist->extend(otherlist)
2561
2562
2563extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2564 Like |extend()| but instead of adding items to {expr1} a new
2565 List or Dictionary is created and returned. {expr1} remains
2566 unchanged. Items can still be changed by {expr2}, if you
2567 don't want that use |deepcopy()| first.
2568
2569
2570feedkeys({string} [, {mode}]) *feedkeys()*
2571 Characters in {string} are queued for processing as if they
2572 come from a mapping or were typed by the user.
2573
2574 By default the string is added to the end of the typeahead
2575 buffer, thus if a mapping is still being executed the
2576 characters come after them. Use the 'i' flag to insert before
2577 other characters, they will be executed next, before any
2578 characters from a mapping.
2579
2580 The function does not wait for processing of keys contained in
2581 {string}.
2582
2583 To include special keys into {string}, use double-quotes
2584 and "\..." notation |expr-quote|. For example,
2585 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2586 feedkeys('\<CR>') pushes 5 characters.
2587 A special code that might be useful is <Ignore>, it exits the
2588 wait for a character without doing anything. *<Ignore>*
2589
2590 {mode} is a String, which can contain these character flags:
2591 'm' Remap keys. This is default. If {mode} is absent,
2592 keys are remapped.
2593 'n' Do not remap keys.
2594 't' Handle keys as if typed; otherwise they are handled as
2595 if coming from a mapping. This matters for undo,
2596 opening folds, etc.
2597 'L' Lowlevel input. Only works for Unix or when using the
2598 GUI. Keys are used as if they were coming from the
2599 terminal. Other flags are not used. *E980*
2600 When a CTRL-C interrupts and 't' is included it sets
2601 the internal "got_int" flag.
2602 'i' Insert the string instead of appending (see above).
2603 'x' Execute commands until typeahead is empty. This is
2604 similar to using ":normal!". You can call feedkeys()
2605 several times without 'x' and then one time with 'x'
2606 (possibly with an empty {string}) to execute all the
2607 typeahead. Note that when Vim ends in Insert mode it
2608 will behave as if <Esc> is typed, to avoid getting
2609 stuck, waiting for a character to be typed before the
2610 script continues.
2611 Note that if you manage to call feedkeys() while
2612 executing commands, thus calling it recursively, then
2613 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002614 'c' Remove any script context when executing, so that
2615 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002616 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002617 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002618 '!' When used with 'x' will not end Insert mode. Can be
2619 used in a test when a timer is set to exit Insert mode
2620 a little later. Useful for testing CursorHoldI.
2621
2622 Return value is always 0.
2623
2624 Can also be used as a |method|: >
2625 GetInput()->feedkeys()
2626
2627filereadable({file}) *filereadable()*
2628 The result is a Number, which is |TRUE| when a file with the
2629 name {file} exists, and can be read. If {file} doesn't exist,
2630 or is a directory, the result is |FALSE|. {file} is any
2631 expression, which is used as a String.
2632 If you don't care about the file being readable you can use
2633 |glob()|.
2634 {file} is used as-is, you may want to expand wildcards first: >
2635 echo filereadable('~/.vimrc')
2636 0
2637 echo filereadable(expand('~/.vimrc'))
2638 1
2639
2640< Can also be used as a |method|: >
2641 GetName()->filereadable()
2642< *file_readable()*
2643 Obsolete name: file_readable().
2644
2645
2646filewritable({file}) *filewritable()*
2647 The result is a Number, which is 1 when a file with the
2648 name {file} exists, and can be written. If {file} doesn't
2649 exist, or is not writable, the result is 0. If {file} is a
2650 directory, and we can write to it, the result is 2.
2651
2652 Can also be used as a |method|: >
2653 GetName()->filewritable()
2654
2655
2656filter({expr1}, {expr2}) *filter()*
2657 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
2658 For each item in {expr1} evaluate {expr2} and when the result
2659 is zero or false remove the item from the |List| or
2660 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002661 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002662
2663 {expr2} must be a |string| or |Funcref|.
2664
2665 If {expr2} is a |string|, inside {expr2} |v:val| has the value
2666 of the current item. For a |Dictionary| |v:key| has the key
2667 of the current item and for a |List| |v:key| has the index of
2668 the current item. For a |Blob| |v:key| has the index of the
2669 current byte. For a |String| |v:key| has the index of the
2670 current character.
2671 Examples: >
2672 call filter(mylist, 'v:val !~ "OLD"')
2673< Removes the items where "OLD" appears. >
2674 call filter(mydict, 'v:key >= 8')
2675< Removes the items with a key below 8. >
2676 call filter(var, 0)
2677< Removes all the items, thus clears the |List| or |Dictionary|.
2678
2679 Note that {expr2} is the result of expression and is then
2680 used as an expression again. Often it is good to use a
2681 |literal-string| to avoid having to double backslashes.
2682
2683 If {expr2} is a |Funcref| it must take two arguments:
2684 1. the key or the index of the current item.
2685 2. the value of the current item.
2686 The function must return |TRUE| if the item should be kept.
2687 Example that keeps the odd items of a list: >
2688 func Odd(idx, val)
2689 return a:idx % 2 == 1
2690 endfunc
2691 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002692< It is shorter when using a |lambda|. In |Vim9| syntax: >
2693 call filter(myList, (idx, val) => idx * val <= 42)
2694< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002695 call filter(myList, {idx, val -> idx * val <= 42})
2696< If you do not use "val" you can leave it out: >
2697 call filter(myList, {idx -> idx % 2 == 1})
2698<
2699 In |Vim9| script the result must be true, false, zero or one.
2700 Other values will result in a type error.
2701
2702 For a |List| and a |Dictionary| the operation is done
2703 in-place. If you want it to remain unmodified make a copy
2704 first: >
2705 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
2706
2707< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00002708 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002709 When an error is encountered while evaluating {expr2} no
2710 further items in {expr1} are processed.
2711 When {expr2} is a Funcref errors inside a function are ignored,
2712 unless it was defined with the "abort" flag.
2713
2714 Can also be used as a |method|: >
2715 mylist->filter(expr2)
2716
2717finddir({name} [, {path} [, {count}]]) *finddir()*
2718 Find directory {name} in {path}. Supports both downwards and
2719 upwards recursive directory searches. See |file-searching|
2720 for the syntax of {path}.
2721
2722 Returns the path of the first found match. When the found
2723 directory is below the current directory a relative path is
2724 returned. Otherwise a full path is returned.
2725 If {path} is omitted or empty then 'path' is used.
2726
2727 If the optional {count} is given, find {count}'s occurrence of
2728 {name} in {path} instead of the first one.
2729 When {count} is negative return all the matches in a |List|.
2730
Bram Moolenaar016188f2022-06-06 20:52:59 +01002731 Returns an empty string if the directory is not found.
2732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002733 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002734
2735 Can also be used as a |method|: >
2736 GetName()->finddir()
2737
2738findfile({name} [, {path} [, {count}]]) *findfile()*
2739 Just like |finddir()|, but find a file instead of a directory.
2740 Uses 'suffixesadd'.
2741 Example: >
2742 :echo findfile("tags.vim", ".;")
2743< Searches from the directory of the current file upwards until
2744 it finds the file "tags.vim".
2745
2746 Can also be used as a |method|: >
2747 GetName()->findfile()
2748
2749flatten({list} [, {maxdepth}]) *flatten()*
2750 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
2751 the result is a |List| without nesting, as if {maxdepth} is
2752 a very large number.
2753 The {list} is changed in place, use |flattennew()| if you do
2754 not want that.
2755 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00002756 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002757 *E900*
2758 {maxdepth} means how deep in nested lists changes are made.
2759 {list} is not modified when {maxdepth} is 0.
2760 {maxdepth} must be positive number.
2761
2762 If there is an error the number zero is returned.
2763
2764 Example: >
2765 :echo flatten([1, [2, [3, 4]], 5])
2766< [1, 2, 3, 4, 5] >
2767 :echo flatten([1, [2, [3, 4]], 5], 1)
2768< [1, 2, [3, 4], 5]
2769
2770 Can also be used as a |method|: >
2771 mylist->flatten()
2772<
2773flattennew({list} [, {maxdepth}]) *flattennew()*
2774 Like |flatten()| but first make a copy of {list}.
2775
2776
2777float2nr({expr}) *float2nr()*
2778 Convert {expr} to a Number by omitting the part after the
2779 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00002780 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002781 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002782 When the value of {expr} is out of range for a |Number| the
2783 result is truncated to 0x7fffffff or -0x7fffffff (or when
2784 64-bit Number support is enabled, 0x7fffffffffffffff or
2785 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
2786 64-bit Number support is enabled, -0x8000000000000000).
2787 Examples: >
2788 echo float2nr(3.95)
2789< 3 >
2790 echo float2nr(-23.45)
2791< -23 >
2792 echo float2nr(1.0e100)
2793< 2147483647 (or 9223372036854775807) >
2794 echo float2nr(-1.0e150)
2795< -2147483647 (or -9223372036854775807) >
2796 echo float2nr(1.0e-100)
2797< 0
2798
2799 Can also be used as a |method|: >
2800 Compute()->float2nr()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002801
2802
2803floor({expr}) *floor()*
2804 Return the largest integral value less than or equal to
2805 {expr} as a |Float| (round down).
2806 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002807 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002808 Examples: >
2809 echo floor(1.856)
2810< 1.0 >
2811 echo floor(-5.456)
2812< -6.0 >
2813 echo floor(4.0)
2814< 4.0
2815
2816 Can also be used as a |method|: >
2817 Compute()->floor()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002818
2819
2820fmod({expr1}, {expr2}) *fmod()*
2821 Return the remainder of {expr1} / {expr2}, even if the
2822 division is not representable. Returns {expr1} - i * {expr2}
2823 for some integer i such that if {expr2} is non-zero, the
2824 result has the same sign as {expr1} and magnitude less than
2825 the magnitude of {expr2}. If {expr2} is zero, the value
2826 returned is zero. The value returned is a |Float|.
2827 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002828 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
2829 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002830 Examples: >
2831 :echo fmod(12.33, 1.22)
2832< 0.13 >
2833 :echo fmod(-12.33, 1.22)
2834< -0.13
2835
2836 Can also be used as a |method|: >
2837 Compute()->fmod(1.22)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838
2839
2840fnameescape({string}) *fnameescape()*
2841 Escape {string} for use as file name command argument. All
2842 characters that have a special meaning, such as '%' and '|'
2843 are escaped with a backslash.
2844 For most systems the characters escaped are
2845 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
2846 appears in a filename, it depends on the value of 'isfname'.
2847 A leading '+' and '>' is also escaped (special after |:edit|
2848 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01002849 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002850 Example: >
2851 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002852 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002853< results in executing: >
2854 edit \+some\ str\%nge\|name
2855<
2856 Can also be used as a |method|: >
2857 GetName()->fnameescape()
2858
2859fnamemodify({fname}, {mods}) *fnamemodify()*
2860 Modify file name {fname} according to {mods}. {mods} is a
2861 string of characters like it is used for file names on the
2862 command line. See |filename-modifiers|.
2863 Example: >
2864 :echo fnamemodify("main.c", ":p:h")
2865< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01002866 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01002867< If {mods} is empty or an unsupported modifier is used then
2868 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01002869 When {fname} is empty then with {mods} ":h" returns ".", so
2870 that `:cd` can be used with it. This is different from
2871 expand('%:h') without a buffer name, which returns an empty
2872 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002873 Note: Environment variables don't work in {fname}, use
2874 |expand()| first then.
2875
2876 Can also be used as a |method|: >
2877 GetName()->fnamemodify(':p:h')
2878
2879foldclosed({lnum}) *foldclosed()*
2880 The result is a Number. If the line {lnum} is in a closed
2881 fold, the result is the number of the first line in that fold.
2882 If the line {lnum} is not in a closed fold, -1 is returned.
2883 {lnum} is used like with |getline()|. Thus "." is the current
2884 line, "'m" mark m, etc.
2885
2886 Can also be used as a |method|: >
2887 GetLnum()->foldclosed()
2888
2889foldclosedend({lnum}) *foldclosedend()*
2890 The result is a Number. If the line {lnum} is in a closed
2891 fold, the result is the number of the last line in that fold.
2892 If the line {lnum} is not in a closed fold, -1 is returned.
2893 {lnum} is used like with |getline()|. Thus "." is the current
2894 line, "'m" mark m, etc.
2895
2896 Can also be used as a |method|: >
2897 GetLnum()->foldclosedend()
2898
2899foldlevel({lnum}) *foldlevel()*
2900 The result is a Number, which is the foldlevel of line {lnum}
2901 in the current buffer. For nested folds the deepest level is
2902 returned. If there is no fold at line {lnum}, zero is
2903 returned. It doesn't matter if the folds are open or closed.
2904 When used while updating folds (from 'foldexpr') -1 is
2905 returned for lines where folds are still to be updated and the
2906 foldlevel is unknown. As a special case the level of the
2907 previous line is usually available.
2908 {lnum} is used like with |getline()|. Thus "." is the current
2909 line, "'m" mark m, etc.
2910
2911 Can also be used as a |method|: >
2912 GetLnum()->foldlevel()
2913<
2914 *foldtext()*
2915foldtext() Returns a String, to be displayed for a closed fold. This is
2916 the default function used for the 'foldtext' option and should
2917 only be called from evaluating 'foldtext'. It uses the
2918 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
2919 The returned string looks like this: >
2920 +-- 45 lines: abcdef
2921< The number of leading dashes depends on the foldlevel. The
2922 "45" is the number of lines in the fold. "abcdef" is the text
2923 in the first non-blank line of the fold. Leading white space,
2924 "//" or "/*" and the text from the 'foldmarker' and
2925 'commentstring' options is removed.
2926 When used to draw the actual foldtext, the rest of the line
2927 will be filled with the fold char from the 'fillchars'
2928 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002929 Returns an empty string when there is no fold.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002930 {not available when compiled without the |+folding| feature}
2931
2932foldtextresult({lnum}) *foldtextresult()*
2933 Returns the text that is displayed for the closed fold at line
2934 {lnum}. Evaluates 'foldtext' in the appropriate context.
2935 When there is no closed fold at {lnum} an empty string is
2936 returned.
2937 {lnum} is used like with |getline()|. Thus "." is the current
2938 line, "'m" mark m, etc.
2939 Useful when exporting folded text, e.g., to HTML.
2940 {not available when compiled without the |+folding| feature}
2941
2942
2943 Can also be used as a |method|: >
2944 GetLnum()->foldtextresult()
2945<
2946 *foreground()*
2947foreground() Move the Vim window to the foreground. Useful when sent from
2948 a client to a Vim server. |remote_send()|
2949 On Win32 systems this might not work, the OS does not always
2950 allow a window to bring itself to the foreground. Use
2951 |remote_foreground()| instead.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002952 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002953 Win32 console version}
2954
Bram Moolenaaraa534142022-09-15 21:46:02 +01002955fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002956 Get the full command name from a short abbreviated command
2957 name; see |20.2| for details on command abbreviations.
2958
2959 The string argument {name} may start with a `:` and can
2960 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01002961 Returns an empty string if a command doesn't exist, if it's
2962 ambiguous (for user-defined commands) or cannot be shortened
2963 this way. |vim9-no-shorten|
2964
2965 Without the {vim9} argument uses the current script version.
2966 If {vim9} is present and FALSE then legacy script rules are
2967 used. When {vim9} is present and TRUE then Vim9 rules are
2968 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002969
2970 For example `fullcommand('s')`, `fullcommand('sub')`,
2971 `fullcommand(':%substitute')` all return "substitute".
2972
2973 Can also be used as a |method|: >
2974 GetName()->fullcommand()
2975<
2976 *funcref()*
2977funcref({name} [, {arglist}] [, {dict}])
2978 Just like |function()|, but the returned Funcref will lookup
2979 the function by reference, not by name. This matters when the
2980 function {name} is redefined later.
2981
2982 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00002983 It only works for an autoloaded function if it has already
2984 been loaded (to avoid mistakenly loading the autoload script
2985 when only intending to use the function name, use |function()|
2986 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002987 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002988
2989 Can also be used as a |method|: >
2990 GetFuncname()->funcref([arg])
2991<
2992 *function()* *partial* *E700* *E922* *E923*
2993function({name} [, {arglist}] [, {dict}])
2994 Return a |Funcref| variable that refers to function {name}.
2995 {name} can be the name of a user defined function or an
2996 internal function.
2997
2998 {name} can also be a Funcref or a partial. When it is a
2999 partial the dict stored in it will be used and the {dict}
3000 argument is not allowed. E.g.: >
3001 let FuncWithArg = function(dict.Func, [arg])
3002 let Broken = function(dict.Func, [arg], dict)
3003<
3004 When using the Funcref the function will be found by {name},
3005 also when it was redefined later. Use |funcref()| to keep the
3006 same function.
3007
3008 When {arglist} or {dict} is present this creates a partial.
3009 That means the argument list and/or the dictionary is stored in
3010 the Funcref and will be used when the Funcref is called.
3011
3012 The arguments are passed to the function in front of other
3013 arguments, but after any argument from |method|. Example: >
3014 func Callback(arg1, arg2, name)
3015 ...
3016 let Partial = function('Callback', ['one', 'two'])
3017 ...
3018 call Partial('name')
3019< Invokes the function as with: >
3020 call Callback('one', 'two', 'name')
3021
3022< With a |method|: >
3023 func Callback(one, two, three)
3024 ...
3025 let Partial = function('Callback', ['two'])
3026 ...
3027 eval 'one'->Partial('three')
3028< Invokes the function as with: >
3029 call Callback('one', 'two', 'three')
3030
3031< The function() call can be nested to add more arguments to the
3032 Funcref. The extra arguments are appended to the list of
3033 arguments. Example: >
3034 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003035 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003036 let Func = function('Callback', ['one'])
3037 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003038 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003039 call Func2('name')
3040< Invokes the function as with: >
3041 call Callback('one', 'two', 'name')
3042
3043< The Dictionary is only useful when calling a "dict" function.
3044 In that case the {dict} is passed in as "self". Example: >
3045 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003046 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003047 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003048 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003049 let context = {"name": "example"}
3050 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003051 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003052 call Func() " will echo: called for example
3053< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003054 arguments, these two are equivalent, if Callback() is defined
3055 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003056 let Func = function('Callback', context)
3057 let Func = context.Callback
3058
3059< The argument list and the Dictionary can be combined: >
3060 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003061 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003062 let context = {"name": "example"}
3063 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003064 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003065 call Func(500)
3066< Invokes the function as with: >
3067 call context.Callback('one', 500)
3068<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003069 Returns 0 on error.
3070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003071 Can also be used as a |method|: >
3072 GetFuncname()->function([arg])
3073
3074
3075garbagecollect([{atexit}]) *garbagecollect()*
3076 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3077 that have circular references.
3078
3079 There is hardly ever a need to invoke this function, as it is
3080 automatically done when Vim runs out of memory or is waiting
3081 for the user to press a key after 'updatetime'. Items without
3082 circular references are always freed when they become unused.
3083 This is useful if you have deleted a very big |List| and/or
3084 |Dictionary| with circular references in a script that runs
3085 for a long time.
3086
3087 When the optional {atexit} argument is one, garbage
3088 collection will also be done when exiting Vim, if it wasn't
3089 done before. This is useful when checking for memory leaks.
3090
3091 The garbage collection is not done immediately but only when
3092 it's safe to perform. This is when waiting for the user to
3093 type a character. To force garbage collection immediately use
3094 |test_garbagecollect_now()|.
3095
3096get({list}, {idx} [, {default}]) *get()*
3097 Get item {idx} from |List| {list}. When this item is not
3098 available return {default}. Return zero when {default} is
3099 omitted.
3100 Preferably used as a |method|: >
3101 mylist->get(idx)
3102get({blob}, {idx} [, {default}])
3103 Get byte {idx} from |Blob| {blob}. When this byte is not
3104 available return {default}. Return -1 when {default} is
3105 omitted.
3106 Preferably used as a |method|: >
3107 myblob->get(idx)
3108get({dict}, {key} [, {default}])
3109 Get item with key {key} from |Dictionary| {dict}. When this
3110 item is not available return {default}. Return zero when
3111 {default} is omitted. Useful example: >
3112 let val = get(g:, 'var_name', 'default')
3113< This gets the value of g:var_name if it exists, and uses
3114 'default' when it does not exist.
3115 Preferably used as a |method|: >
3116 mydict->get(key)
3117get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003118 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003119 {what} are:
3120 "name" The function name
3121 "func" The function
3122 "dict" The dictionary
3123 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003124 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003125 Preferably used as a |method|: >
3126 myfunc->get(what)
3127<
3128 *getbufinfo()*
3129getbufinfo([{buf}])
3130getbufinfo([{dict}])
3131 Get information about buffers as a List of Dictionaries.
3132
3133 Without an argument information about all the buffers is
3134 returned.
3135
3136 When the argument is a |Dictionary| only the buffers matching
3137 the specified criteria are returned. The following keys can
3138 be specified in {dict}:
3139 buflisted include only listed buffers.
3140 bufloaded include only loaded buffers.
3141 bufmodified include only modified buffers.
3142
3143 Otherwise, {buf} specifies a particular buffer to return
3144 information for. For the use of {buf}, see |bufname()|
3145 above. If the buffer is found the returned List has one item.
3146 Otherwise the result is an empty list.
3147
3148 Each returned List item is a dictionary with the following
3149 entries:
3150 bufnr Buffer number.
3151 changed TRUE if the buffer is modified.
3152 changedtick Number of changes made to the buffer.
3153 hidden TRUE if the buffer is hidden.
3154 lastused Timestamp in seconds, like
3155 |localtime()|, when the buffer was
3156 last used.
3157 {only with the |+viminfo| feature}
3158 listed TRUE if the buffer is listed.
3159 lnum Line number used for the buffer when
3160 opened in the current window.
3161 Only valid if the buffer has been
3162 displayed in the window in the past.
3163 If you want the line number of the
3164 last known cursor position in a given
3165 window, use |line()|: >
3166 :echo line('.', {winid})
3167<
3168 linecount Number of lines in the buffer (only
3169 valid when loaded)
3170 loaded TRUE if the buffer is loaded.
3171 name Full path to the file in the buffer.
3172 signs List of signs placed in the buffer.
3173 Each list item is a dictionary with
3174 the following fields:
3175 id sign identifier
3176 lnum line number
3177 name sign name
3178 variables A reference to the dictionary with
3179 buffer-local variables.
3180 windows List of |window-ID|s that display this
3181 buffer
3182 popups List of popup |window-ID|s that
3183 display this buffer
3184
3185 Examples: >
3186 for buf in getbufinfo()
3187 echo buf.name
3188 endfor
3189 for buf in getbufinfo({'buflisted':1})
3190 if buf.changed
3191 ....
3192 endif
3193 endfor
3194<
3195 To get buffer-local options use: >
3196 getbufvar({bufnr}, '&option_name')
3197<
3198 Can also be used as a |method|: >
3199 GetBufnr()->getbufinfo()
3200<
3201
3202 *getbufline()*
3203getbufline({buf}, {lnum} [, {end}])
3204 Return a |List| with the lines starting from {lnum} to {end}
3205 (inclusive) in the buffer {buf}. If {end} is omitted, a
3206 |List| with only the line {lnum} is returned.
3207
3208 For the use of {buf}, see |bufname()| above.
3209
3210 For {lnum} and {end} "$" can be used for the last line of the
3211 buffer. Otherwise a number must be used.
3212
3213 When {lnum} is smaller than 1 or bigger than the number of
3214 lines in the buffer, an empty |List| is returned.
3215
3216 When {end} is greater than the number of lines in the buffer,
3217 it is treated as {end} is set to the number of lines in the
3218 buffer. When {end} is before {lnum} an empty |List| is
3219 returned.
3220
3221 This function works only for loaded buffers. For unloaded and
3222 non-existing buffers, an empty |List| is returned.
3223
3224 Example: >
3225 :let lines = getbufline(bufnr("myfile"), 1, "$")
3226
3227< Can also be used as a |method|: >
3228 GetBufnr()->getbufline(lnum)
3229
3230getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3231 The result is the value of option or local buffer variable
3232 {varname} in buffer {buf}. Note that the name without "b:"
3233 must be used.
3234 The {varname} argument is a string.
3235 When {varname} is empty returns a |Dictionary| with all the
3236 buffer-local variables.
3237 When {varname} is equal to "&" returns a |Dictionary| with all
3238 the buffer-local options.
3239 Otherwise, when {varname} starts with "&" returns the value of
3240 a buffer-local option.
3241 This also works for a global or buffer-local option, but it
3242 doesn't work for a global variable, window-local variable or
3243 window-local option.
3244 For the use of {buf}, see |bufname()| above.
3245 When the buffer or variable doesn't exist {def} or an empty
3246 string is returned, there is no error message.
3247 Examples: >
3248 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003249 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003250
3251< Can also be used as a |method|: >
3252 GetBufnr()->getbufvar(varname)
3253<
3254getchangelist([{buf}]) *getchangelist()*
3255 Returns the |changelist| for the buffer {buf}. For the use
3256 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3257 exist, an empty list is returned.
3258
3259 The returned list contains two entries: a list with the change
3260 locations and the current position in the list. Each
3261 entry in the change list is a dictionary with the following
3262 entries:
3263 col column number
3264 coladd column offset for 'virtualedit'
3265 lnum line number
3266 If buffer {buf} is the current buffer, then the current
3267 position refers to the position in the list. For other
3268 buffers, it is set to the length of the list.
3269
3270 Can also be used as a |method|: >
3271 GetBufnr()->getchangelist()
3272
3273getchar([expr]) *getchar()*
3274 Get a single character from the user or input stream.
3275 If [expr] is omitted, wait until a character is available.
3276 If [expr] is 0, only get a character when one is available.
3277 Return zero otherwise.
3278 If [expr] is 1, only check if a character is available, it is
3279 not consumed. Return zero if no character available.
3280 If you prefer always getting a string use |getcharstr()|.
3281
3282 Without [expr] and when [expr] is 0 a whole character or
3283 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003284 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003285 Otherwise a String is returned with the encoded character.
3286 For a special key it's a String with a sequence of bytes
3287 starting with 0x80 (decimal: 128). This is the same value as
3288 the String "\<Key>", e.g., "\<Left>". The returned value is
3289 also a String when a modifier (shift, control, alt) was used
3290 that is not included in the character.
3291
3292 When [expr] is 0 and Esc is typed, there will be a short delay
3293 while Vim waits to see if this is the start of an escape
3294 sequence.
3295
3296 When [expr] is 1 only the first byte is returned. For a
3297 one-byte character it is the character itself as a number.
3298 Use nr2char() to convert it to a String.
3299
3300 Use getcharmod() to obtain any additional modifiers.
3301
3302 When the user clicks a mouse button, the mouse event will be
3303 returned. The position can then be found in |v:mouse_col|,
3304 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3305 |getmousepos()| can also be used. Mouse move events will be
3306 ignored.
3307 This example positions the mouse as it would normally happen: >
3308 let c = getchar()
3309 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003310 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003311 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003312 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003313 endif
3314<
3315 When using bracketed paste only the first character is
3316 returned, the rest of the pasted text is dropped.
3317 |xterm-bracketed-paste|.
3318
3319 There is no prompt, you will somehow have to make clear to the
3320 user that a character has to be typed. The screen is not
3321 redrawn, e.g. when resizing the window. When using a popup
3322 window it should work better with a |popup-filter|.
3323
3324 There is no mapping for the character.
3325 Key codes are replaced, thus when the user presses the <Del>
3326 key you get the code for the <Del> key, not the raw character
3327 sequence. Examples: >
3328 getchar() == "\<Del>"
3329 getchar() == "\<S-Left>"
3330< This example redefines "f" to ignore case: >
3331 :nmap f :call FindChar()<CR>
3332 :function FindChar()
3333 : let c = nr2char(getchar())
3334 : while col('.') < col('$') - 1
3335 : normal l
3336 : if getline('.')[col('.') - 1] ==? c
3337 : break
3338 : endif
3339 : endwhile
3340 :endfunction
3341<
3342 You may also receive synthetic characters, such as
3343 |<CursorHold>|. Often you will want to ignore this and get
3344 another character: >
3345 :function GetKey()
3346 : let c = getchar()
3347 : while c == "\<CursorHold>"
3348 : let c = getchar()
3349 : endwhile
3350 : return c
3351 :endfunction
3352
3353getcharmod() *getcharmod()*
3354 The result is a Number which is the state of the modifiers for
3355 the last obtained character with getchar() or in another way.
3356 These values are added together:
3357 2 shift
3358 4 control
3359 8 alt (meta)
3360 16 meta (when it's different from ALT)
3361 32 mouse double click
3362 64 mouse triple click
3363 96 mouse quadruple click (== 32 + 64)
3364 128 command (Macintosh only)
3365 Only the modifiers that have not been included in the
3366 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003367 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003368
3369 *getcharpos()*
3370getcharpos({expr})
3371 Get the position for String {expr}. Same as |getpos()| but the
3372 column number in the returned List is a character index
3373 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003374 If |getpos()| returns a very large column number, equal to
3375 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003376 of the last character.
3377
3378 Example:
3379 With the cursor on '세' in line 5 with text "여보세요": >
3380 getcharpos('.') returns [0, 5, 3, 0]
3381 getpos('.') returns [0, 5, 7, 0]
3382<
3383 Can also be used as a |method|: >
3384 GetMark()->getcharpos()
3385
3386getcharsearch() *getcharsearch()*
3387 Return the current character search information as a {dict}
3388 with the following entries:
3389
3390 char character previously used for a character
3391 search (|t|, |f|, |T|, or |F|); empty string
3392 if no character search has been performed
3393 forward direction of character search; 1 for forward,
3394 0 for backward
3395 until type of character search; 1 for a |t| or |T|
3396 character search, 0 for an |f| or |F|
3397 character search
3398
3399 This can be useful to always have |;| and |,| search
3400 forward/backward regardless of the direction of the previous
3401 character search: >
3402 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3403 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3404< Also see |setcharsearch()|.
3405
3406
3407getcharstr([expr]) *getcharstr()*
3408 Get a single character from the user or input stream as a
3409 string.
3410 If [expr] is omitted, wait until a character is available.
3411 If [expr] is 0 or false, only get a character when one is
3412 available. Return an empty string otherwise.
3413 If [expr] is 1 or true, only check if a character is
3414 available, it is not consumed. Return an empty string
3415 if no character is available.
3416 Otherwise this works like |getchar()|, except that a number
3417 result is converted to a string.
3418
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003419getcmdcompltype() *getcmdcompltype()*
3420 Return the type of the current command-line completion.
3421 Only works when the command line is being edited, thus
3422 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003423 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003424 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3425 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003426 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427
3428getcmdline() *getcmdline()*
3429 Return the current command-line. Only works when the command
3430 line is being edited, thus requires use of |c_CTRL-\_e| or
3431 |c_CTRL-R_=|.
3432 Example: >
3433 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003434< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3435 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003436 Returns an empty string when entering a password or using
3437 |inputsecret()|.
3438
3439getcmdpos() *getcmdpos()*
3440 Return the position of the cursor in the command line as a
3441 byte count. The first column is 1.
3442 Only works when editing the command line, thus requires use of
3443 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3444 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003445 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3446 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003447
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003448getcmdscreenpos() *getcmdscreenpos()*
3449 Return the screen position of the cursor in the command line
3450 as a byte count. The first column is 1.
3451 Instead of |getcmdpos()|, it adds the prompt position.
3452 Only works when editing the command line, thus requires use of
3453 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3454 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003455 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3456 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003457
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003458getcmdtype() *getcmdtype()*
3459 Return the current command-line type. Possible return values
3460 are:
3461 : normal Ex command
3462 > debug mode command |debug-mode|
3463 / forward search command
3464 ? backward search command
3465 @ |input()| command
3466 - |:insert| or |:append| command
3467 = |i_CTRL-R_=|
3468 Only works when editing the command line, thus requires use of
3469 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3470 Returns an empty string otherwise.
3471 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
3472
3473getcmdwintype() *getcmdwintype()*
3474 Return the current |command-line-window| type. Possible return
3475 values are the same as |getcmdtype()|. Returns an empty string
3476 when not in the command-line window.
3477
3478getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
3479 Return a list of command-line completion matches. The String
3480 {type} argument specifies what for. The following completion
3481 types are supported:
3482
3483 arglist file names in argument list
3484 augroup autocmd groups
3485 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003486 behave |:behave| suboptions
3487 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003488 color color schemes
3489 command Ex command
3490 cmdline |cmdline-completion| result
3491 compiler compilers
3492 cscope |:cscope| suboptions
3493 diff_buffer |:diffget| and |:diffput| completion
3494 dir directory names
3495 environment environment variable names
3496 event autocommand events
3497 expression Vim expression
3498 file file and directory names
3499 file_in_path file and directory names in |'path'|
3500 filetype filetype names |'filetype'|
3501 function function name
3502 help help subjects
3503 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00003504 history |:history| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003505 locale locale names (as output of locale -a)
3506 mapclear buffer argument
3507 mapping mapping name
3508 menu menus
3509 messages |:messages| suboptions
3510 option options
3511 packadd optional package |pack-add| names
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003512 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003513 shellcmd Shell command
3514 sign |:sign| suboptions
3515 syntax syntax file names |'syntax'|
3516 syntime |:syntime| suboptions
3517 tag tags
3518 tag_listfiles tags, file names
3519 user user names
3520 var user variables
3521
3522 If {pat} is an empty string, then all the matches are
3523 returned. Otherwise only items matching {pat} are returned.
3524 See |wildcards| for the use of special characters in {pat}.
3525
3526 If the optional {filtered} flag is set to 1, then 'wildignore'
3527 is applied to filter the results. Otherwise all the matches
3528 are returned. The 'wildignorecase' option always applies.
3529
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003530 If the 'wildoptions' option contains 'fuzzy', then fuzzy
3531 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00003532 regular expression matching is used. Thus this function
3533 follows the user preference, what happens on the command line.
3534 If you do not want this you can make 'wildoptions' empty
3535 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00003536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003537 If {type} is "cmdline", then the |cmdline-completion| result is
3538 returned. For example, to complete the possible values after
3539 a ":call" command: >
3540 echo getcompletion('call ', 'cmdline')
3541<
3542 If there are no matches, an empty list is returned. An
3543 invalid value for {type} produces an error.
3544
3545 Can also be used as a |method|: >
3546 GetPattern()->getcompletion('color')
3547<
3548 *getcurpos()*
3549getcurpos([{winid}])
3550 Get the position of the cursor. This is like getpos('.'), but
3551 includes an extra "curswant" item in the list:
3552 [0, lnum, col, off, curswant] ~
3553 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00003554 cursor vertically. After |$| command it will be a very large
3555 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003556 |getpos()|.
3557 The first "bufnum" item is always zero. The byte position of
3558 the cursor is returned in 'col'. To get the character
3559 position, use |getcursorcharpos()|.
3560
3561 The optional {winid} argument can specify the window. It can
3562 be the window number or the |window-ID|. The last known
3563 cursor position is returned, this may be invalid for the
3564 current value of the buffer if it is not the current window.
3565 If {winid} is invalid a list with zeroes is returned.
3566
3567 This can be used to save and restore the cursor position: >
3568 let save_cursor = getcurpos()
3569 MoveTheCursorAround
3570 call setpos('.', save_cursor)
3571< Note that this only works within the window. See
3572 |winrestview()| for restoring more state.
3573
3574 Can also be used as a |method|: >
3575 GetWinid()->getcurpos()
3576<
3577 *getcursorcharpos()*
3578getcursorcharpos([{winid}])
3579 Same as |getcurpos()| but the column number in the returned
3580 List is a character index instead of a byte index.
3581
3582 Example:
3583 With the cursor on '보' in line 3 with text "여보세요": >
3584 getcursorcharpos() returns [0, 3, 2, 0, 3]
3585 getcurpos() returns [0, 3, 4, 0, 3]
3586<
3587 Can also be used as a |method|: >
3588 GetWinid()->getcursorcharpos()
3589
3590< *getcwd()*
3591getcwd([{winnr} [, {tabnr}]])
3592 The result is a String, which is the name of the current
3593 working directory. 'autochdir' is ignored.
3594
3595 With {winnr} return the local current directory of this window
3596 in the current tab page. {winnr} can be the window number or
3597 the |window-ID|.
3598 If {winnr} is -1 return the name of the global working
3599 directory. See also |haslocaldir()|.
3600
3601 With {winnr} and {tabnr} return the local current directory of
3602 the window in the specified tab page. If {winnr} is -1 return
3603 the working directory of the tabpage.
3604 If {winnr} is zero use the current window, if {tabnr} is zero
3605 use the current tabpage.
3606 Without any arguments, return the actual working directory of
3607 the current window.
3608 Return an empty string if the arguments are invalid.
3609
3610 Examples: >
3611 " Get the working directory of the current window
3612 :echo getcwd()
3613 :echo getcwd(0)
3614 :echo getcwd(0, 0)
3615 " Get the working directory of window 3 in tabpage 2
3616 :echo getcwd(3, 2)
3617 " Get the global working directory
3618 :echo getcwd(-1)
3619 " Get the working directory of tabpage 3
3620 :echo getcwd(-1, 3)
3621 " Get the working directory of current tabpage
3622 :echo getcwd(-1, 0)
3623
3624< Can also be used as a |method|: >
3625 GetWinnr()->getcwd()
3626
3627getenv({name}) *getenv()*
3628 Return the value of environment variable {name}. The {name}
3629 argument is a string, without a leading '$'. Example: >
3630 myHome = getenv('HOME')
3631
3632< When the variable does not exist |v:null| is returned. That
3633 is different from a variable set to an empty string, although
3634 some systems interpret the empty value as the variable being
3635 deleted. See also |expr-env|.
3636
3637 Can also be used as a |method|: >
3638 GetVarname()->getenv()
3639
3640getfontname([{name}]) *getfontname()*
3641 Without an argument returns the name of the normal font being
3642 used. Like what is used for the Normal highlight group
3643 |hl-Normal|.
3644 With an argument a check is done whether String {name} is a
3645 valid font name. If not then an empty string is returned.
3646 Otherwise the actual font name is returned, or {name} if the
3647 GUI does not support obtaining the real name.
3648 Only works when the GUI is running, thus not in your vimrc or
3649 gvimrc file. Use the |GUIEnter| autocommand to use this
3650 function just after the GUI has started.
3651 Note that the GTK GUI accepts any font name, thus checking for
3652 a valid name does not work.
3653
3654getfperm({fname}) *getfperm()*
3655 The result is a String, which is the read, write, and execute
3656 permissions of the given file {fname}.
3657 If {fname} does not exist or its directory cannot be read, an
3658 empty string is returned.
3659 The result is of the form "rwxrwxrwx", where each group of
3660 "rwx" flags represent, in turn, the permissions of the owner
3661 of the file, the group the file belongs to, and other users.
3662 If a user does not have a given permission the flag for this
3663 is replaced with the string "-". Examples: >
3664 :echo getfperm("/etc/passwd")
3665 :echo getfperm(expand("~/.vimrc"))
3666< This will hopefully (from a security point of view) display
3667 the string "rw-r--r--" or even "rw-------".
3668
3669 Can also be used as a |method|: >
3670 GetFilename()->getfperm()
3671<
3672 For setting permissions use |setfperm()|.
3673
3674getfsize({fname}) *getfsize()*
3675 The result is a Number, which is the size in bytes of the
3676 given file {fname}.
3677 If {fname} is a directory, 0 is returned.
3678 If the file {fname} can't be found, -1 is returned.
3679 If the size of {fname} is too big to fit in a Number then -2
3680 is returned.
3681
3682 Can also be used as a |method|: >
3683 GetFilename()->getfsize()
3684
3685getftime({fname}) *getftime()*
3686 The result is a Number, which is the last modification time of
3687 the given file {fname}. The value is measured as seconds
3688 since 1st Jan 1970, and may be passed to strftime(). See also
3689 |localtime()| and |strftime()|.
3690 If the file {fname} can't be found -1 is returned.
3691
3692 Can also be used as a |method|: >
3693 GetFilename()->getftime()
3694
3695getftype({fname}) *getftype()*
3696 The result is a String, which is a description of the kind of
3697 file of the given file {fname}.
3698 If {fname} does not exist an empty string is returned.
3699 Here is a table over different kinds of files and their
3700 results:
3701 Normal file "file"
3702 Directory "dir"
3703 Symbolic link "link"
3704 Block device "bdev"
3705 Character device "cdev"
3706 Socket "socket"
3707 FIFO "fifo"
3708 All other "other"
3709 Example: >
3710 getftype("/home")
3711< Note that a type such as "link" will only be returned on
3712 systems that support it. On some systems only "dir" and
3713 "file" are returned. On MS-Windows a symbolic link to a
3714 directory returns "dir" instead of "link".
3715
3716 Can also be used as a |method|: >
3717 GetFilename()->getftype()
3718
3719getimstatus() *getimstatus()*
3720 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01003721 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722 See 'imstatusfunc'.
3723
3724getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
3725 Returns the |jumplist| for the specified window.
3726
3727 Without arguments use the current window.
3728 With {winnr} only use this window in the current tab page.
3729 {winnr} can also be a |window-ID|.
3730 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01003731 page. If {winnr} or {tabnr} is invalid, an empty list is
3732 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003733
3734 The returned list contains two entries: a list with the jump
3735 locations and the last used jump position number in the list.
3736 Each entry in the jump location list is a dictionary with
3737 the following entries:
3738 bufnr buffer number
3739 col column number
3740 coladd column offset for 'virtualedit'
3741 filename filename if available
3742 lnum line number
3743
3744 Can also be used as a |method|: >
3745 GetWinnr()->getjumplist()
3746
3747< *getline()*
3748getline({lnum} [, {end}])
3749 Without {end} the result is a String, which is line {lnum}
3750 from the current buffer. Example: >
3751 getline(1)
3752< When {lnum} is a String that doesn't start with a
3753 digit, |line()| is called to translate the String into a Number.
3754 To get the line under the cursor: >
3755 getline(".")
3756< When {lnum} is a number smaller than 1 or bigger than the
3757 number of lines in the buffer, an empty string is returned.
3758
3759 When {end} is given the result is a |List| where each item is
3760 a line from the current buffer in the range {lnum} to {end},
3761 including line {end}.
3762 {end} is used in the same way as {lnum}.
3763 Non-existing lines are silently omitted.
3764 When {end} is before {lnum} an empty |List| is returned.
3765 Example: >
3766 :let start = line('.')
3767 :let end = search("^$") - 1
3768 :let lines = getline(start, end)
3769
3770< Can also be used as a |method|: >
3771 ComputeLnum()->getline()
3772
3773< To get lines from another buffer see |getbufline()|
3774
3775getloclist({nr} [, {what}]) *getloclist()*
3776 Returns a |List| with all the entries in the location list for
3777 window {nr}. {nr} can be the window number or the |window-ID|.
3778 When {nr} is zero the current window is used.
3779
3780 For a location list window, the displayed location list is
3781 returned. For an invalid window number {nr}, an empty list is
3782 returned. Otherwise, same as |getqflist()|.
3783
3784 If the optional {what} dictionary argument is supplied, then
3785 returns the items listed in {what} as a dictionary. Refer to
3786 |getqflist()| for the supported items in {what}.
3787
3788 In addition to the items supported by |getqflist()| in {what},
3789 the following item is supported by |getloclist()|:
3790
3791 filewinid id of the window used to display files
3792 from the location list. This field is
3793 applicable only when called from a
3794 location list window. See
3795 |location-list-file-window| for more
3796 details.
3797
3798 Returns a |Dictionary| with default values if there is no
3799 location list for the window {nr}.
3800 Returns an empty Dictionary if window {nr} does not exist.
3801
3802 Examples (See also |getqflist-examples|): >
3803 :echo getloclist(3, {'all': 0})
3804 :echo getloclist(5, {'filewinid': 0})
3805
3806
3807getmarklist([{buf}]) *getmarklist()*
3808 Without the {buf} argument returns a |List| with information
3809 about all the global marks. |mark|
3810
3811 If the optional {buf} argument is specified, returns the
3812 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01003813 see |bufname()|. If {buf} is invalid, an empty list is
3814 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003815
3816 Each item in the returned List is a |Dict| with the following:
3817 mark name of the mark prefixed by "'"
3818 pos a |List| with the position of the mark:
3819 [bufnum, lnum, col, off]
3820 Refer to |getpos()| for more information.
3821 file file name
3822
3823 Refer to |getpos()| for getting information about a specific
3824 mark.
3825
3826 Can also be used as a |method|: >
3827 GetBufnr()->getmarklist()
3828
3829getmatches([{win}]) *getmatches()*
3830 Returns a |List| with all matches previously defined for the
3831 current window by |matchadd()| and the |:match| commands.
3832 |getmatches()| is useful in combination with |setmatches()|,
3833 as |setmatches()| can restore a list of matches saved by
3834 |getmatches()|.
3835 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01003836 window ID instead of the current window. If {win} is invalid,
3837 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003838 Example: >
3839 :echo getmatches()
3840< [{'group': 'MyGroup1', 'pattern': 'TODO',
3841 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3842 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3843 :let m = getmatches()
3844 :call clearmatches()
3845 :echo getmatches()
3846< [] >
3847 :call setmatches(m)
3848 :echo getmatches()
3849< [{'group': 'MyGroup1', 'pattern': 'TODO',
3850 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
3851 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
3852 :unlet m
3853<
3854getmousepos() *getmousepos()*
3855 Returns a |Dictionary| with the last known position of the
3856 mouse. This can be used in a mapping for a mouse click or in
3857 a filter of a popup window. The items are:
3858 screenrow screen row
3859 screencol screen column
3860 winid Window ID of the click
3861 winrow row inside "winid"
3862 wincol column inside "winid"
3863 line text line inside "winid"
3864 column text column inside "winid"
3865 All numbers are 1-based.
3866
3867 If not over a window, e.g. when in the command line, then only
3868 "screenrow" and "screencol" are valid, the others are zero.
3869
3870 When on the status line below a window or the vertical
3871 separator right of a window, the "line" and "column" values
3872 are zero.
3873
3874 When the position is after the text then "column" is the
3875 length of the text in bytes plus one.
3876
3877 If the mouse is over a popup window then that window is used.
3878
3879 When using |getchar()| the Vim variables |v:mouse_lnum|,
3880 |v:mouse_col| and |v:mouse_winid| also provide these values.
3881
3882 *getpid()*
3883getpid() Return a Number which is the process ID of the Vim process.
3884 On Unix and MS-Windows this is a unique number, until Vim
3885 exits.
3886
3887 *getpos()*
3888getpos({expr}) Get the position for String {expr}. For possible values of
3889 {expr} see |line()|. For getting the cursor position see
3890 |getcurpos()|.
3891 The result is a |List| with four numbers:
3892 [bufnum, lnum, col, off]
3893 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
3894 is the buffer number of the mark.
3895 "lnum" and "col" are the position in the buffer. The first
3896 column is 1.
3897 The "off" number is zero, unless 'virtualedit' is used. Then
3898 it is the offset in screen columns from the start of the
3899 character. E.g., a position within a <Tab> or after the last
3900 character.
3901 Note that for '< and '> Visual mode matters: when it is "V"
3902 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00003903 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003904 The column number in the returned List is the byte position
3905 within the line. To get the character position in the line,
3906 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00003907 A very large column number equal to |v:maxcol| can be returned,
3908 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01003909 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003910 This can be used to save and restore the position of a mark: >
3911 let save_a_mark = getpos("'a")
3912 ...
3913 call setpos("'a", save_a_mark)
3914< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
3915
3916 Can also be used as a |method|: >
3917 GetMark()->getpos()
3918
3919getqflist([{what}]) *getqflist()*
3920 Returns a |List| with all the current quickfix errors. Each
3921 list item is a dictionary with these entries:
3922 bufnr number of buffer that has the file name, use
3923 bufname() to get the name
3924 module module name
3925 lnum line number in the buffer (first line is 1)
3926 end_lnum
3927 end of line number if the item is multiline
3928 col column number (first column is 1)
3929 end_col end of column number if the item has range
3930 vcol |TRUE|: "col" is visual column
3931 |FALSE|: "col" is byte index
3932 nr error number
3933 pattern search pattern used to locate the error
3934 text description of the error
3935 type type of the error, 'E', '1', etc.
3936 valid |TRUE|: recognized error message
3937
3938 When there is no error list or it's empty, an empty list is
3939 returned. Quickfix list entries with a non-existing buffer
3940 number are returned with "bufnr" set to zero (Note: some
3941 functions accept buffer number zero for the alternate buffer,
3942 you may need to explicitly check for zero).
3943
3944 Useful application: Find pattern matches in multiple files and
3945 do something with them: >
3946 :vimgrep /theword/jg *.c
3947 :for d in getqflist()
3948 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
3949 :endfor
3950<
3951 If the optional {what} dictionary argument is supplied, then
3952 returns only the items listed in {what} as a dictionary. The
3953 following string items are supported in {what}:
3954 changedtick get the total number of changes made
3955 to the list |quickfix-changedtick|
3956 context get the |quickfix-context|
3957 efm errorformat to use when parsing "lines". If
3958 not present, then the 'errorformat' option
3959 value is used.
3960 id get information for the quickfix list with
3961 |quickfix-ID|; zero means the id for the
3962 current list or the list specified by "nr"
3963 idx get information for the quickfix entry at this
3964 index in the list specified by 'id' or 'nr'.
3965 If set to zero, then uses the current entry.
3966 See |quickfix-index|
3967 items quickfix list entries
3968 lines parse a list of lines using 'efm' and return
3969 the resulting entries. Only a |List| type is
3970 accepted. The current quickfix list is not
3971 modified. See |quickfix-parse|.
3972 nr get information for this quickfix list; zero
3973 means the current quickfix list and "$" means
3974 the last quickfix list
3975 qfbufnr number of the buffer displayed in the quickfix
3976 window. Returns 0 if the quickfix buffer is
3977 not present. See |quickfix-buffer|.
3978 size number of entries in the quickfix list
3979 title get the list title |quickfix-title|
3980 winid get the quickfix |window-ID|
3981 all all of the above quickfix properties
3982 Non-string items in {what} are ignored. To get the value of a
3983 particular item, set it to zero.
3984 If "nr" is not present then the current quickfix list is used.
3985 If both "nr" and a non-zero "id" are specified, then the list
3986 specified by "id" is used.
3987 To get the number of lists in the quickfix stack, set "nr" to
3988 "$" in {what}. The "nr" value in the returned dictionary
3989 contains the quickfix stack size.
3990 When "lines" is specified, all the other items except "efm"
3991 are ignored. The returned dictionary contains the entry
3992 "items" with the list of entries.
3993
3994 The returned dictionary contains the following entries:
3995 changedtick total number of changes made to the
3996 list |quickfix-changedtick|
3997 context quickfix list context. See |quickfix-context|
3998 If not present, set to "".
3999 id quickfix list ID |quickfix-ID|. If not
4000 present, set to 0.
4001 idx index of the quickfix entry in the list. If not
4002 present, set to 0.
4003 items quickfix list entries. If not present, set to
4004 an empty list.
4005 nr quickfix list number. If not present, set to 0
4006 qfbufnr number of the buffer displayed in the quickfix
4007 window. If not present, set to 0.
4008 size number of entries in the quickfix list. If not
4009 present, set to 0.
4010 title quickfix list title text. If not present, set
4011 to "".
4012 winid quickfix |window-ID|. If not present, set to 0
4013
4014 Examples (See also |getqflist-examples|): >
4015 :echo getqflist({'all': 1})
4016 :echo getqflist({'nr': 2, 'title': 1})
4017 :echo getqflist({'lines' : ["F1:10:L10"]})
4018<
4019getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4020 The result is a String, which is the contents of register
4021 {regname}. Example: >
4022 :let cliptext = getreg('*')
4023< When register {regname} was not set the result is an empty
4024 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004025 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004026
4027 getreg('=') returns the last evaluated value of the expression
4028 register. (For use in maps.)
4029 getreg('=', 1) returns the expression itself, so that it can
4030 be restored with |setreg()|. For other registers the extra
4031 argument is ignored, thus you can always give it.
4032
4033 If {list} is present and |TRUE|, the result type is changed
4034 to |List|. Each list item is one text line. Use it if you care
4035 about zero bytes possibly present inside register: without
4036 third argument both NLs and zero bytes are represented as NLs
4037 (see |NL-used-for-Nul|).
4038 When the register was not set an empty list is returned.
4039
4040 If {regname} is "", the unnamed register '"' is used.
4041 If {regname} is not specified, |v:register| is used.
4042 In |Vim9-script| {regname} must be one character.
4043
4044 Can also be used as a |method|: >
4045 GetRegname()->getreg()
4046
4047getreginfo([{regname}]) *getreginfo()*
4048 Returns detailed information about register {regname} as a
4049 Dictionary with the following entries:
4050 regcontents List of lines contained in register
4051 {regname}, like
4052 |getreg|({regname}, 1, 1).
4053 regtype the type of register {regname}, as in
4054 |getregtype()|.
4055 isunnamed Boolean flag, v:true if this register
4056 is currently pointed to by the unnamed
4057 register.
4058 points_to for the unnamed register, gives the
4059 single letter name of the register
4060 currently pointed to (see |quotequote|).
4061 For example, after deleting a line
4062 with `dd`, this field will be "1",
4063 which is the register that got the
4064 deleted text.
4065
4066 The {regname} argument is a string. If {regname} is invalid
4067 or not set, an empty Dictionary will be returned.
4068 If {regname} is "" or "@", the unnamed register '"' is used.
4069 If {regname} is not specified, |v:register| is used.
4070 The returned Dictionary can be passed to |setreg()|.
4071 In |Vim9-script| {regname} must be one character.
4072
4073 Can also be used as a |method|: >
4074 GetRegname()->getreginfo()
4075
4076getregtype([{regname}]) *getregtype()*
4077 The result is a String, which is type of register {regname}.
4078 The value will be one of:
4079 "v" for |characterwise| text
4080 "V" for |linewise| text
4081 "<CTRL-V>{width}" for |blockwise-visual| text
4082 "" for an empty or unknown register
4083 <CTRL-V> is one character with value 0x16.
4084 The {regname} argument is a string. If {regname} is "", the
4085 unnamed register '"' is used. If {regname} is not specified,
4086 |v:register| is used.
4087 In |Vim9-script| {regname} must be one character.
4088
4089 Can also be used as a |method|: >
4090 GetRegname()->getregtype()
4091
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004092getscriptinfo([{opts}) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004093 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004094 scripts in the order they were sourced, like what
4095 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004096
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004097 The optional Dict argument {opts} supports the following
4098 optional items:
4099 name Script name match pattern. If specified,
4100 and "sid" is not specified, information about
4101 scripts with name that match the pattern
4102 "name" are returned.
4103 sid Script ID |<SID>|. If specified, only
4104 information about the script with ID "sid" is
4105 returned and "name" is ignored.
4106
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004107 Each item in the returned List is a |Dict| with the following
4108 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004109 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004110 `import autoload` but was not actually sourced
4111 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004112 functions List of script-local function names defined in
4113 the script. Present only when a particular
4114 script is specified using the "sid" item in
4115 {opts}.
4116 name Vim script file name.
4117 sid Script ID |<SID>|.
4118 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004119 this script name links to, if any, otherwise
4120 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004121 variables A dictionary with the script-local variables.
4122 Present only when the a particular script is
4123 specified using the "sid" item in {opts}.
4124 Note that this is a copy, the value of
4125 script-local variables cannot be changed using
4126 this dictionary.
4127 version Vimscript version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004128
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004129 Examples: >
4130 :echo getscriptinfo({'name': 'myscript'})
4131 :echo getscriptinfo({'sid': 15}).variables
4132<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004133gettabinfo([{tabnr}]) *gettabinfo()*
4134 If {tabnr} is not specified, then information about all the
4135 tab pages is returned as a |List|. Each List item is a
4136 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4137 number and information about that one is returned. If the tab
4138 page does not exist an empty List is returned.
4139
4140 Each List item is a |Dictionary| with the following entries:
4141 tabnr tab page number.
4142 variables a reference to the dictionary with
4143 tabpage-local variables
4144 windows List of |window-ID|s in the tab page.
4145
4146 Can also be used as a |method|: >
4147 GetTabnr()->gettabinfo()
4148
4149gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4150 Get the value of a tab-local variable {varname} in tab page
4151 {tabnr}. |t:var|
4152 Tabs are numbered starting with one.
4153 The {varname} argument is a string. When {varname} is empty a
4154 dictionary with all tab-local variables is returned.
4155 Note that the name without "t:" must be used.
4156 When the tab or variable doesn't exist {def} or an empty
4157 string is returned, there is no error message.
4158
4159 Can also be used as a |method|: >
4160 GetTabnr()->gettabvar(varname)
4161
4162gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4163 Get the value of window-local variable {varname} in window
4164 {winnr} in tab page {tabnr}.
4165 The {varname} argument is a string. When {varname} is empty a
4166 dictionary with all window-local variables is returned.
4167 When {varname} is equal to "&" get the values of all
4168 window-local options in a |Dictionary|.
4169 Otherwise, when {varname} starts with "&" get the value of a
4170 window-local option.
4171 Note that {varname} must be the name without "w:".
4172 Tabs are numbered starting with one. For the current tabpage
4173 use |getwinvar()|.
4174 {winnr} can be the window number or the |window-ID|.
4175 When {winnr} is zero the current window is used.
4176 This also works for a global option, buffer-local option and
4177 window-local option, but it doesn't work for a global variable
4178 or buffer-local variable.
4179 When the tab, window or variable doesn't exist {def} or an
4180 empty string is returned, there is no error message.
4181 Examples: >
4182 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004183 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004184<
4185 To obtain all window-local variables use: >
4186 gettabwinvar({tabnr}, {winnr}, '&')
4187
4188< Can also be used as a |method|: >
4189 GetTabnr()->gettabwinvar(winnr, varname)
4190
4191gettagstack([{winnr}]) *gettagstack()*
4192 The result is a Dict, which is the tag stack of window {winnr}.
4193 {winnr} can be the window number or the |window-ID|.
4194 When {winnr} is not specified, the current window is used.
4195 When window {winnr} doesn't exist, an empty Dict is returned.
4196
4197 The returned dictionary contains the following entries:
4198 curidx Current index in the stack. When at
4199 top of the stack, set to (length + 1).
4200 Index of bottom of the stack is 1.
4201 items List of items in the stack. Each item
4202 is a dictionary containing the
4203 entries described below.
4204 length Number of entries in the stack.
4205
4206 Each item in the stack is a dictionary with the following
4207 entries:
4208 bufnr buffer number of the current jump
4209 from cursor position before the tag jump.
4210 See |getpos()| for the format of the
4211 returned list.
4212 matchnr current matching tag number. Used when
4213 multiple matching tags are found for a
4214 name.
4215 tagname name of the tag
4216
4217 See |tagstack| for more information about the tag stack.
4218
4219 Can also be used as a |method|: >
4220 GetWinnr()->gettagstack()
4221
4222
4223gettext({text}) *gettext()*
4224 Translate String {text} if possible.
4225 This is mainly for use in the distributed Vim scripts. When
4226 generating message translations the {text} is extracted by
4227 xgettext, the translator can add the translated message in the
4228 .po file and Vim will lookup the translation when gettext() is
4229 called.
4230 For {text} double quoted strings are preferred, because
4231 xgettext does not understand escaping in single quoted
4232 strings.
4233
4234
4235getwininfo([{winid}]) *getwininfo()*
4236 Returns information about windows as a |List| with Dictionaries.
4237
4238 If {winid} is given Information about the window with that ID
4239 is returned, as a |List| with one item. If the window does not
4240 exist the result is an empty list.
4241
4242 Without {winid} information about all the windows in all the
4243 tab pages is returned.
4244
4245 Each List item is a |Dictionary| with the following entries:
4246 botline last complete displayed buffer line
4247 bufnr number of buffer in the window
4248 height window height (excluding winbar)
4249 loclist 1 if showing a location list
4250 {only with the +quickfix feature}
4251 quickfix 1 if quickfix or location list window
4252 {only with the +quickfix feature}
4253 terminal 1 if a terminal window
4254 {only with the +terminal feature}
4255 tabnr tab page number
4256 topline first displayed buffer line
4257 variables a reference to the dictionary with
4258 window-local variables
4259 width window width
4260 winbar 1 if the window has a toolbar, 0
4261 otherwise
4262 wincol leftmost screen column of the window;
4263 "col" from |win_screenpos()|
4264 textoff number of columns occupied by any
4265 'foldcolumn', 'signcolumn' and line
4266 number in front of the text
4267 winid |window-ID|
4268 winnr window number
4269 winrow topmost screen line of the window;
4270 "row" from |win_screenpos()|
4271
4272 Can also be used as a |method|: >
4273 GetWinnr()->getwininfo()
4274
4275getwinpos([{timeout}]) *getwinpos()*
4276 The result is a |List| with two numbers, the result of
4277 |getwinposx()| and |getwinposy()| combined:
4278 [x-pos, y-pos]
4279 {timeout} can be used to specify how long to wait in msec for
4280 a response from the terminal. When omitted 100 msec is used.
4281 Use a longer time for a remote terminal.
4282 When using a value less than 10 and no response is received
4283 within that time, a previously reported position is returned,
4284 if available. This can be used to poll for the position and
4285 do some work in the meantime: >
4286 while 1
4287 let res = getwinpos(1)
4288 if res[0] >= 0
4289 break
4290 endif
4291 " Do some work here
4292 endwhile
4293<
4294
4295 Can also be used as a |method|: >
4296 GetTimeout()->getwinpos()
4297<
4298 *getwinposx()*
4299getwinposx() The result is a Number, which is the X coordinate in pixels of
4300 the left hand side of the GUI Vim window. Also works for an
4301 xterm (uses a timeout of 100 msec).
4302 The result will be -1 if the information is not available.
4303 The value can be used with `:winpos`.
4304
4305 *getwinposy()*
4306getwinposy() The result is a Number, which is the Y coordinate in pixels of
4307 the top of the GUI Vim window. Also works for an xterm (uses
4308 a timeout of 100 msec).
4309 The result will be -1 if the information is not available.
4310 The value can be used with `:winpos`.
4311
4312getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
4313 Like |gettabwinvar()| for the current tabpage.
4314 Examples: >
4315 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004316 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004317
4318< Can also be used as a |method|: >
4319 GetWinnr()->getwinvar(varname)
4320<
4321glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
4322 Expand the file wildcards in {expr}. See |wildcards| for the
4323 use of special characters.
4324
4325 Unless the optional {nosuf} argument is given and is |TRUE|,
4326 the 'suffixes' and 'wildignore' options apply: Names matching
4327 one of the patterns in 'wildignore' will be skipped and
4328 'suffixes' affect the ordering of matches.
4329 'wildignorecase' always applies.
4330
4331 When {list} is present and it is |TRUE| the result is a |List|
4332 with all matching files. The advantage of using a List is,
4333 you also get filenames containing newlines correctly.
4334 Otherwise the result is a String and when there are several
4335 matches, they are separated by <NL> characters.
4336
4337 If the expansion fails, the result is an empty String or List.
4338
4339 You can also use |readdir()| if you need to do complicated
4340 things, such as limiting the number of matches.
4341
4342 A name for a non-existing file is not included. A symbolic
4343 link is only included if it points to an existing file.
4344 However, when the {alllinks} argument is present and it is
4345 |TRUE| then all symbolic links are included.
4346
4347 For most systems backticks can be used to get files names from
4348 any external command. Example: >
4349 :let tagfiles = glob("`find . -name tags -print`")
4350 :let &tags = substitute(tagfiles, "\n", ",", "g")
4351< The result of the program inside the backticks should be one
4352 item per line. Spaces inside an item are allowed.
4353
4354 See |expand()| for expanding special Vim variables. See
4355 |system()| for getting the raw output of an external command.
4356
4357 Can also be used as a |method|: >
4358 GetExpr()->glob()
4359
4360glob2regpat({string}) *glob2regpat()*
4361 Convert a file pattern, as used by glob(), into a search
4362 pattern. The result can be used to match with a string that
4363 is a file name. E.g. >
4364 if filename =~ glob2regpat('Make*.mak')
4365< This is equivalent to: >
4366 if filename =~ '^Make.*\.mak$'
4367< When {string} is an empty string the result is "^$", match an
4368 empty string.
4369 Note that the result depends on the system. On MS-Windows
4370 a backslash usually means a path separator.
4371
4372 Can also be used as a |method|: >
4373 GetExpr()->glob2regpat()
4374< *globpath()*
4375globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
4376 Perform glob() for String {expr} on all directories in {path}
4377 and concatenate the results. Example: >
4378 :echo globpath(&rtp, "syntax/c.vim")
4379<
4380 {path} is a comma-separated list of directory names. Each
4381 directory name is prepended to {expr} and expanded like with
4382 |glob()|. A path separator is inserted when needed.
4383 To add a comma inside a directory name escape it with a
4384 backslash. Note that on MS-Windows a directory may have a
4385 trailing backslash, remove it if you put a comma after it.
4386 If the expansion fails for one of the directories, there is no
4387 error message.
4388
4389 Unless the optional {nosuf} argument is given and is |TRUE|,
4390 the 'suffixes' and 'wildignore' options apply: Names matching
4391 one of the patterns in 'wildignore' will be skipped and
4392 'suffixes' affect the ordering of matches.
4393
4394 When {list} is present and it is |TRUE| the result is a |List|
4395 with all matching files. The advantage of using a List is, you
4396 also get filenames containing newlines correctly. Otherwise
4397 the result is a String and when there are several matches,
4398 they are separated by <NL> characters. Example: >
4399 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
4400<
4401 {alllinks} is used as with |glob()|.
4402
4403 The "**" item can be used to search in a directory tree.
4404 For example, to find all "README.txt" files in the directories
4405 in 'runtimepath' and below: >
4406 :echo globpath(&rtp, "**/README.txt")
4407< Upwards search and limiting the depth of "**" is not
4408 supported, thus using 'path' will not always work properly.
4409
4410 Can also be used as a |method|, the base is passed as the
4411 second argument: >
4412 GetExpr()->globpath(&rtp)
4413<
4414 *has()*
4415has({feature} [, {check}])
4416 When {check} is omitted or is zero: The result is a Number,
4417 which is 1 if the feature {feature} is supported, zero
4418 otherwise. The {feature} argument is a string, case is
4419 ignored. See |feature-list| below.
4420
4421 When {check} is present and not zero: The result is a Number,
4422 which is 1 if the feature {feature} could ever be supported,
4423 zero otherwise. This is useful to check for a typo in
4424 {feature} and to detect dead code. Keep in mind that an older
4425 Vim version will not know about a feature added later and
4426 features that have been abandoned will not be known by the
4427 current Vim version.
4428
4429 Also see |exists()| and |exists_compiled()|.
4430
4431 Note that to skip code that has a syntax error when the
4432 feature is not available, Vim may skip the rest of the line
4433 and miss a following `endif`. Therefore put the `endif` on a
4434 separate line: >
4435 if has('feature')
4436 let x = this->breaks->without->the->feature
4437 endif
4438< If the `endif` would be moved to the second line as "| endif" it
4439 would not be found.
4440
4441
4442has_key({dict}, {key}) *has_key()*
4443 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01004444 has an entry with key {key}. FALSE otherwise.
4445 The {key} argument is a string. In |Vim9| script a number is
4446 also accepted (and converted to a string) but no other types.
4447 In legacy script the usual automatic conversion to string is
4448 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004449
4450 Can also be used as a |method|: >
4451 mydict->has_key(key)
4452
4453haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
4454 The result is a Number:
4455 1 when the window has set a local directory via |:lcd|
4456 2 when the tab-page has set a local directory via |:tcd|
4457 0 otherwise.
4458
4459 Without arguments use the current window.
4460 With {winnr} use this window in the current tab page.
4461 With {winnr} and {tabnr} use the window in the specified tab
4462 page.
4463 {winnr} can be the window number or the |window-ID|.
4464 If {winnr} is -1 it is ignored and only the tabpage is used.
4465 Return 0 if the arguments are invalid.
4466 Examples: >
4467 if haslocaldir() == 1
4468 " window local directory case
4469 elseif haslocaldir() == 2
4470 " tab-local directory case
4471 else
4472 " global directory case
4473 endif
4474
4475 " current window
4476 :echo haslocaldir()
4477 :echo haslocaldir(0)
4478 :echo haslocaldir(0, 0)
4479 " window n in current tab page
4480 :echo haslocaldir(n)
4481 :echo haslocaldir(n, 0)
4482 " window n in tab page m
4483 :echo haslocaldir(n, m)
4484 " tab page m
4485 :echo haslocaldir(-1, m)
4486<
4487 Can also be used as a |method|: >
4488 GetWinnr()->haslocaldir()
4489
4490hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
4491 The result is a Number, which is TRUE if there is a mapping
4492 that contains {what} in somewhere in the rhs (what it is
4493 mapped to) and this mapping exists in one of the modes
4494 indicated by {mode}.
4495 The arguments {what} and {mode} are strings.
4496 When {abbr} is there and it is |TRUE| use abbreviations
4497 instead of mappings. Don't forget to specify Insert and/or
4498 Command-line mode.
4499 Both the global mappings and the mappings local to the current
4500 buffer are checked for a match.
4501 If no matching mapping is found FALSE is returned.
4502 The following characters are recognized in {mode}:
4503 n Normal mode
4504 v Visual and Select mode
4505 x Visual mode
4506 s Select mode
4507 o Operator-pending mode
4508 i Insert mode
4509 l Language-Argument ("r", "f", "t", etc.)
4510 c Command-line mode
4511 When {mode} is omitted, "nvo" is used.
4512
4513 This function is useful to check if a mapping already exists
4514 to a function in a Vim script. Example: >
4515 :if !hasmapto('\ABCdoit')
4516 : map <Leader>d \ABCdoit
4517 :endif
4518< This installs the mapping to "\ABCdoit" only if there isn't
4519 already a mapping to "\ABCdoit".
4520
4521 Can also be used as a |method|: >
4522 GetRHS()->hasmapto()
4523
4524histadd({history}, {item}) *histadd()*
4525 Add the String {item} to the history {history} which can be
4526 one of: *hist-names*
4527 "cmd" or ":" command line history
4528 "search" or "/" search pattern history
4529 "expr" or "=" typed expression history
4530 "input" or "@" input line history
4531 "debug" or ">" debug command history
4532 empty the current or last used history
4533 The {history} string does not need to be the whole name, one
4534 character is sufficient.
4535 If {item} does already exist in the history, it will be
4536 shifted to become the newest entry.
4537 The result is a Number: TRUE if the operation was successful,
4538 otherwise FALSE is returned.
4539
4540 Example: >
4541 :call histadd("input", strftime("%Y %b %d"))
4542 :let date=input("Enter date: ")
4543< This function is not available in the |sandbox|.
4544
4545 Can also be used as a |method|, the base is passed as the
4546 second argument: >
4547 GetHistory()->histadd('search')
4548
4549histdel({history} [, {item}]) *histdel()*
4550 Clear {history}, i.e. delete all its entries. See |hist-names|
4551 for the possible values of {history}.
4552
4553 If the parameter {item} evaluates to a String, it is used as a
4554 regular expression. All entries matching that expression will
4555 be removed from the history (if there are any).
4556 Upper/lowercase must match, unless "\c" is used |/\c|.
4557 If {item} evaluates to a Number, it will be interpreted as
4558 an index, see |:history-indexing|. The respective entry will
4559 be removed if it exists.
4560
4561 The result is TRUE for a successful operation, otherwise FALSE
4562 is returned.
4563
4564 Examples:
4565 Clear expression register history: >
4566 :call histdel("expr")
4567<
4568 Remove all entries starting with "*" from the search history: >
4569 :call histdel("/", '^\*')
4570<
4571 The following three are equivalent: >
4572 :call histdel("search", histnr("search"))
4573 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004574 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004575<
4576 To delete the last search pattern and use the last-but-one for
4577 the "n" command and 'hlsearch': >
4578 :call histdel("search", -1)
4579 :let @/ = histget("search", -1)
4580<
4581 Can also be used as a |method|: >
4582 GetHistory()->histdel()
4583
4584histget({history} [, {index}]) *histget()*
4585 The result is a String, the entry with Number {index} from
4586 {history}. See |hist-names| for the possible values of
4587 {history}, and |:history-indexing| for {index}. If there is
4588 no such entry, an empty String is returned. When {index} is
4589 omitted, the most recent item from the history is used.
4590
4591 Examples:
4592 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004593 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004594
4595< Define an Ex command ":H {num}" that supports re-execution of
4596 the {num}th entry from the output of |:history|. >
4597 :command -nargs=1 H execute histget("cmd", 0+<args>)
4598<
4599 Can also be used as a |method|: >
4600 GetHistory()->histget()
4601
4602histnr({history}) *histnr()*
4603 The result is the Number of the current entry in {history}.
4604 See |hist-names| for the possible values of {history}.
4605 If an error occurred, -1 is returned.
4606
4607 Example: >
4608 :let inp_index = histnr("expr")
4609
4610< Can also be used as a |method|: >
4611 GetHistory()->histnr()
4612<
4613hlexists({name}) *hlexists()*
4614 The result is a Number, which is TRUE if a highlight group
4615 called {name} exists. This is when the group has been
4616 defined in some way. Not necessarily when highlighting has
4617 been defined for it, it may also have been used for a syntax
4618 item.
4619 *highlight_exists()*
4620 Obsolete name: highlight_exists().
4621
4622 Can also be used as a |method|: >
4623 GetName()->hlexists()
4624<
4625hlget([{name} [, {resolve}]]) *hlget()*
4626 Returns a List of all the highlight group attributes. If the
4627 optional {name} is specified, then returns a List with only
4628 the attributes of the specified highlight group. Returns an
4629 empty List if the highlight group {name} is not present.
4630
4631 If the optional {resolve} argument is set to v:true and the
4632 highlight group {name} is linked to another group, then the
4633 link is resolved recursively and the attributes of the
4634 resolved highlight group are returned.
4635
4636 Each entry in the returned List is a Dictionary with the
4637 following items:
4638 cleared boolean flag, set to v:true if the highlight
4639 group attributes are cleared or not yet
4640 specified. See |highlight-clear|.
4641 cterm cterm attributes. See |highlight-cterm|.
4642 ctermbg cterm background color.
4643 See |highlight-ctermbg|.
4644 ctermfg cterm foreground color.
4645 See |highlight-ctermfg|.
4646 ctermul cterm underline color. See |highlight-ctermul|.
4647 default boolean flag, set to v:true if the highlight
4648 group link is a default link. See
4649 |highlight-default|.
4650 font highlight group font. See |highlight-font|.
4651 gui gui attributes. See |highlight-gui|.
4652 guibg gui background color. See |highlight-guibg|.
4653 guifg gui foreground color. See |highlight-guifg|.
4654 guisp gui special color. See |highlight-guisp|.
4655 id highlight group ID.
4656 linksto linked highlight group name.
4657 See |:highlight-link|.
4658 name highlight group name. See |group-name|.
4659 start start terminal keycode. See |highlight-start|.
4660 stop stop terminal keycode. See |highlight-stop|.
4661 term term attributes. See |highlight-term|.
4662
4663 The 'term', 'cterm' and 'gui' items in the above Dictionary
4664 have a dictionary value with the following optional boolean
4665 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
4666 'reverse', 'inverse' and 'strikethrough'.
4667
4668 Example(s): >
4669 :echo hlget()
4670 :echo hlget('ModeMsg')
4671 :echo hlget('Number', v:true)
4672<
4673 Can also be used as a |method|: >
4674 GetName()->hlget()
4675<
4676hlset({list}) *hlset()*
4677 Creates or modifies the attributes of a List of highlight
4678 groups. Each item in {list} is a dictionary containing the
4679 attributes of a highlight group. See |hlget()| for the list of
4680 supported items in this dictionary.
4681
4682 In addition to the items described in |hlget()|, the following
4683 additional items are supported in the dictionary:
4684
4685 force boolean flag to force the creation of
4686 a link for an existing highlight group
4687 with attributes.
4688
4689 The highlight group is identified using the 'name' item and
4690 the 'id' item (if supplied) is ignored. If a highlight group
4691 with a specified name doesn't exist, then it is created.
4692 Otherwise the attributes of an existing highlight group are
4693 modified.
4694
4695 If an empty dictionary value is used for the 'term' or 'cterm'
4696 or 'gui' entries, then the corresponding attributes are
4697 cleared. If the 'cleared' item is set to v:true, then all the
4698 attributes of the highlight group are cleared.
4699
4700 The 'linksto' item can be used to link a highlight group to
4701 another highlight group. See |:highlight-link|.
4702
4703 Returns zero for success, -1 for failure.
4704
4705 Example(s): >
4706 " add bold attribute to the Visual highlight group
4707 :call hlset([#{name: 'Visual',
4708 \ term: #{reverse: 1 , bold: 1}}])
4709 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
4710 :let l = hlget()
4711 :call hlset(l)
4712 " clear the Search highlight group
4713 :call hlset([#{name: 'Search', cleared: v:true}])
4714 " clear the 'term' attributes for a highlight group
4715 :call hlset([#{name: 'Title', term: {}}])
4716 " create the MyHlg group linking it to DiffAdd
4717 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
4718 " remove the MyHlg group link
4719 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
4720 " clear the attributes and a link
4721 :call hlset([#{name: 'MyHlg', cleared: v:true,
4722 \ linksto: 'NONE'}])
4723<
4724 Can also be used as a |method|: >
4725 GetAttrList()->hlset()
4726<
4727 *hlID()*
4728hlID({name}) The result is a Number, which is the ID of the highlight group
4729 with name {name}. When the highlight group doesn't exist,
4730 zero is returned.
4731 This can be used to retrieve information about the highlight
4732 group. For example, to get the background color of the
4733 "Comment" group: >
4734 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
4735< *highlightID()*
4736 Obsolete name: highlightID().
4737
4738 Can also be used as a |method|: >
4739 GetName()->hlID()
4740
4741hostname() *hostname()*
4742 The result is a String, which is the name of the machine on
4743 which Vim is currently running. Machine names greater than
4744 256 characters long are truncated.
4745
4746iconv({string}, {from}, {to}) *iconv()*
4747 The result is a String, which is the text {string} converted
4748 from encoding {from} to encoding {to}.
4749 When the conversion completely fails an empty string is
4750 returned. When some characters could not be converted they
4751 are replaced with "?".
4752 The encoding names are whatever the iconv() library function
4753 can accept, see ":!man 3 iconv".
4754 Most conversions require Vim to be compiled with the |+iconv|
4755 feature. Otherwise only UTF-8 to latin1 conversion and back
4756 can be done.
4757 This can be used to display messages with special characters,
4758 no matter what 'encoding' is set to. Write the message in
4759 UTF-8 and use: >
4760 echo iconv(utf8_str, "utf-8", &enc)
4761< Note that Vim uses UTF-8 for all Unicode encodings, conversion
4762 from/to UCS-2 is automatically changed to use UTF-8. You
4763 cannot use UCS-2 in a string anyway, because of the NUL bytes.
4764
4765 Can also be used as a |method|: >
4766 GetText()->iconv('latin1', 'utf-8')
4767<
4768 *indent()*
4769indent({lnum}) The result is a Number, which is indent of line {lnum} in the
4770 current buffer. The indent is counted in spaces, the value
4771 of 'tabstop' is relevant. {lnum} is used just like in
4772 |getline()|.
4773 When {lnum} is invalid -1 is returned. In |Vim9| script an
4774 error is given.
4775
4776 Can also be used as a |method|: >
4777 GetLnum()->indent()
4778
4779index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004780 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004781 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004783 If {object} is a |List| return the lowest index where the item
4784 has a value equal to {expr}. There is no automatic
4785 conversion, so the String "4" is different from the Number 4.
4786 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004787 of 'ignorecase' is not used here, case matters as indicated by
4788 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004789
4790 If {object} is |Blob| return the lowest index where the byte
4791 value is equal to {expr}.
4792
4793 If {start} is given then start looking at the item with index
4794 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004796 When {ic} is given and it is |TRUE|, ignore case. Otherwise
4797 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004799 -1 is returned when {expr} is not found in {object}.
4800 Example: >
4801 :let idx = index(words, "the")
4802 :if index(numbers, 123) >= 0
4803
4804< Can also be used as a |method|: >
4805 GetObject()->index(what)
4806
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004807indexof({object}, {expr} [, {opts}]) *indexof()*
4808 Returns the index of an item in {object} where {expr} is
4809 v:true. {object} must be a |List| or a |Blob|.
4810
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004811 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004812 List until the expression is v:true and return the index of
4813 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004814
4815 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004816 Blob until the expression is v:true and return the index of
4817 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004818
4819 {expr} must be a |string| or |Funcref|.
4820
4821 If {expr} is a |string|: If {object} is a |List|, inside
4822 {expr} |v:key| has the index of the current List item and
4823 |v:val| has the value of the item. If {object} is a |Blob|,
4824 inside {expr} |v:key| has the index of the current byte and
4825 |v:val| has the byte value.
4826
4827 If {expr} is a |Funcref| it must take two arguments:
4828 1. the key or the index of the current item.
4829 2. the value of the current item.
4830 The function must return |TRUE| if the item is found and the
4831 search should stop.
4832
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004833 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004834 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004835 startidx start evaluating {expr} at the item with this
4836 index; may be negative for an item relative to
4837 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004838 Returns -1 when {expr} evaluates to v:false for all the items.
4839 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01004840 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
4841 :echo indexof(l, "v:val.n == 20")
4842 :echo indexof(l, {i, v -> v.n == 30})
4843 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01004844
4845< Can also be used as a |method|: >
4846 mylist->indexof(expr)
4847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004848input({prompt} [, {text} [, {completion}]]) *input()*
4849 The result is a String, which is whatever the user typed on
4850 the command-line. The {prompt} argument is either a prompt
4851 string, or a blank string (for no prompt). A '\n' can be used
4852 in the prompt to start a new line.
4853 The highlighting set with |:echohl| is used for the prompt.
4854 The input is entered just like a command-line, with the same
4855 editing commands and mappings. There is a separate history
4856 for lines typed for input().
4857 Example: >
4858 :if input("Coffee or beer? ") == "beer"
4859 : echo "Cheers!"
4860 :endif
4861<
4862 If the optional {text} argument is present and not empty, this
4863 is used for the default reply, as if the user typed this.
4864 Example: >
4865 :let color = input("Color? ", "white")
4866
4867< The optional {completion} argument specifies the type of
4868 completion supported for the input. Without it completion is
4869 not performed. The supported completion types are the same as
4870 that can be supplied to a user-defined command using the
4871 "-complete=" argument. Refer to |:command-completion| for
4872 more information. Example: >
4873 let fname = input("File: ", "", "file")
4874<
4875 NOTE: This function must not be used in a startup file, for
4876 the versions that only run in GUI mode (e.g., the Win32 GUI).
4877 Note: When input() is called from within a mapping it will
4878 consume remaining characters from that mapping, because a
4879 mapping is handled like the characters were typed.
4880 Use |inputsave()| before input() and |inputrestore()|
4881 after input() to avoid that. Another solution is to avoid
4882 that further characters follow in the mapping, e.g., by using
4883 |:execute| or |:normal|.
4884
4885 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004886 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004887 :function GetFoo()
4888 : call inputsave()
4889 : let g:Foo = input("enter search pattern: ")
4890 : call inputrestore()
4891 :endfunction
4892
4893< Can also be used as a |method|: >
4894 GetPrompt()->input()
4895
4896inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
4897 Like |input()|, but when the GUI is running and text dialogs
4898 are supported, a dialog window pops up to input the text.
4899 Example: >
4900 :let n = inputdialog("value for shiftwidth", shiftwidth())
4901 :if n != ""
4902 : let &sw = n
4903 :endif
4904< When the dialog is cancelled {cancelreturn} is returned. When
4905 omitted an empty string is returned.
4906 Hitting <Enter> works like pressing the OK button. Hitting
4907 <Esc> works like pressing the Cancel button.
4908 NOTE: Command-line completion is not supported.
4909
4910 Can also be used as a |method|: >
4911 GetPrompt()->inputdialog()
4912
4913inputlist({textlist}) *inputlist()*
4914 {textlist} must be a |List| of strings. This |List| is
4915 displayed, one string per line. The user will be prompted to
4916 enter a number, which is returned.
4917 The user can also select an item by clicking on it with the
4918 mouse, if the mouse is enabled in the command line ('mouse' is
4919 "a" or includes "c"). For the first string 0 is returned.
4920 When clicking above the first item a negative number is
4921 returned. When clicking on the prompt one more than the
4922 length of {textlist} is returned.
4923 Make sure {textlist} has less than 'lines' entries, otherwise
4924 it won't work. It's a good idea to put the entry number at
4925 the start of the string. And put a prompt in the first item.
4926 Example: >
4927 let color = inputlist(['Select color:', '1. red',
4928 \ '2. green', '3. blue'])
4929
4930< Can also be used as a |method|: >
4931 GetChoices()->inputlist()
4932
4933inputrestore() *inputrestore()*
4934 Restore typeahead that was saved with a previous |inputsave()|.
4935 Should be called the same number of times inputsave() is
4936 called. Calling it more often is harmless though.
4937 Returns TRUE when there is nothing to restore, FALSE otherwise.
4938
4939inputsave() *inputsave()*
4940 Preserve typeahead (also from mappings) and clear it, so that
4941 a following prompt gets input from the user. Should be
4942 followed by a matching inputrestore() after the prompt. Can
4943 be used several times, in which case there must be just as
4944 many inputrestore() calls.
4945 Returns TRUE when out of memory, FALSE otherwise.
4946
4947inputsecret({prompt} [, {text}]) *inputsecret()*
4948 This function acts much like the |input()| function with but
4949 two exceptions:
4950 a) the user's response will be displayed as a sequence of
4951 asterisks ("*") thereby keeping the entry secret, and
4952 b) the user's response will not be recorded on the input
4953 |history| stack.
4954 The result is a String, which is whatever the user actually
4955 typed on the command-line in response to the issued prompt.
4956 NOTE: Command-line completion is not supported.
4957
4958 Can also be used as a |method|: >
4959 GetPrompt()->inputsecret()
4960
4961insert({object}, {item} [, {idx}]) *insert()*
4962 When {object} is a |List| or a |Blob| insert {item} at the start
4963 of it.
4964
4965 If {idx} is specified insert {item} before the item with index
4966 {idx}. If {idx} is zero it goes before the first item, just
4967 like omitting {idx}. A negative {idx} is also possible, see
4968 |list-index|. -1 inserts just before the last item.
4969
4970 Returns the resulting |List| or |Blob|. Examples: >
4971 :let mylist = insert([2, 3, 5], 1)
4972 :call insert(mylist, 4, -1)
4973 :call insert(mylist, 6, len(mylist))
4974< The last example can be done simpler with |add()|.
4975 Note that when {item} is a |List| it is inserted as a single
4976 item. Use |extend()| to concatenate |Lists|.
4977
4978 Can also be used as a |method|: >
4979 mylist->insert(item)
4980
4981interrupt() *interrupt()*
4982 Interrupt script execution. It works more or less like the
4983 user typing CTRL-C, most commands won't execute and control
4984 returns to the user. This is useful to abort execution
4985 from lower down, e.g. in an autocommand. Example: >
4986 :function s:check_typoname(file)
4987 : if fnamemodify(a:file, ':t') == '['
4988 : echomsg 'Maybe typo'
4989 : call interrupt()
4990 : endif
4991 :endfunction
4992 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
4993
4994invert({expr}) *invert()*
4995 Bitwise invert. The argument is converted to a number. A
4996 List, Dict or Float argument causes an error. Example: >
4997 :let bits = invert(bits)
4998< Can also be used as a |method|: >
4999 :let bits = bits->invert()
5000
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005001isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005002 The result is a Number, which is |TRUE| when {path} is an
5003 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005004 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005005 On MS-Windows, it is considered absolute when it starts with an
5006 optional drive prefix and is followed by a '\' or '/'. UNC paths
5007 are always absolute.
5008 Example: >
5009 echo isabsolutepath('/usr/share/') " 1
5010 echo isabsolutepath('./foobar') " 0
5011 echo isabsolutepath('C:\Windows') " 1
5012 echo isabsolutepath('foobar') " 0
5013 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005014<
LemonBoydca1d402022-04-28 15:26:33 +01005015 Can also be used as a |method|: >
5016 GetName()->isabsolutepath()
5017
5018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005019isdirectory({directory}) *isdirectory()*
5020 The result is a Number, which is |TRUE| when a directory
5021 with the name {directory} exists. If {directory} doesn't
5022 exist, or isn't a directory, the result is |FALSE|. {directory}
5023 is any expression, which is used as a String.
5024
5025 Can also be used as a |method|: >
5026 GetName()->isdirectory()
5027
5028isinf({expr}) *isinf()*
5029 Return 1 if {expr} is a positive infinity, or -1 a negative
5030 infinity, otherwise 0. >
5031 :echo isinf(1.0 / 0.0)
5032< 1 >
5033 :echo isinf(-1.0 / 0.0)
5034< -1
5035
5036 Can also be used as a |method|: >
5037 Compute()->isinf()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005038
5039islocked({expr}) *islocked()* *E786*
5040 The result is a Number, which is |TRUE| when {expr} is the
5041 name of a locked variable.
5042 The string argument {expr} must be the name of a variable,
5043 |List| item or |Dictionary| entry, not the variable itself!
5044 Example: >
5045 :let alist = [0, ['a', 'b'], 2, 3]
5046 :lockvar 1 alist
5047 :echo islocked('alist') " 1
5048 :echo islocked('alist[1]') " 0
5049
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005050< When {expr} is a variable that does not exist -1 is returned.
5051 If {expr} uses a range, list or dict index that is out of
5052 range or does not exist you get an error message. Use
5053 |exists()| to check for existence.
5054 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005055
5056 Can also be used as a |method|: >
5057 GetName()->islocked()
5058
5059isnan({expr}) *isnan()*
5060 Return |TRUE| if {expr} is a float with value NaN. >
5061 echo isnan(0.0 / 0.0)
5062< 1
5063
5064 Can also be used as a |method|: >
5065 Compute()->isnan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005066
5067items({dict}) *items()*
5068 Return a |List| with all the key-value pairs of {dict}. Each
5069 |List| item is a list with two items: the key of a {dict}
5070 entry and the value of this entry. The |List| is in arbitrary
5071 order. Also see |keys()| and |values()|.
5072 Example: >
5073 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005074 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005075 endfor
5076
5077< Can also be used as a |method|: >
5078 mydict->items()
5079
5080job_ functions are documented here: |job-functions-details|
5081
5082
5083join({list} [, {sep}]) *join()*
5084 Join the items in {list} together into one String.
5085 When {sep} is specified it is put in between the items. If
5086 {sep} is omitted a single space is used.
5087 Note that {sep} is not added at the end. You might want to
5088 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005089 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005090< String items are used as-is. |Lists| and |Dictionaries| are
5091 converted into a string like with |string()|.
5092 The opposite function is |split()|.
5093
5094 Can also be used as a |method|: >
5095 mylist->join()
5096
5097js_decode({string}) *js_decode()*
5098 This is similar to |json_decode()| with these differences:
5099 - Object key names do not have to be in quotes.
5100 - Strings can be in single quotes.
5101 - Empty items in an array (between two commas) are allowed and
5102 result in v:none items.
5103
5104 Can also be used as a |method|: >
5105 ReadObject()->js_decode()
5106
5107js_encode({expr}) *js_encode()*
5108 This is similar to |json_encode()| with these differences:
5109 - Object key names are not in quotes.
5110 - v:none items in an array result in an empty item between
5111 commas.
5112 For example, the Vim object:
5113 [1,v:none,{"one":1},v:none] ~
5114 Will be encoded as:
5115 [1,,{one:1},,] ~
5116 While json_encode() would produce:
5117 [1,null,{"one":1},null] ~
5118 This encoding is valid for JavaScript. It is more efficient
5119 than JSON, especially when using an array with optional items.
5120
5121 Can also be used as a |method|: >
5122 GetObject()->js_encode()
5123
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005124json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005125 This parses a JSON formatted string and returns the equivalent
5126 in Vim values. See |json_encode()| for the relation between
5127 JSON and Vim values.
5128 The decoding is permissive:
5129 - A trailing comma in an array and object is ignored, e.g.
5130 "[1, 2, ]" is the same as "[1, 2]".
5131 - Integer keys are accepted in objects, e.g. {1:2} is the
5132 same as {"1":2}.
5133 - More floating point numbers are recognized, e.g. "1." for
5134 "1.0", or "001.2" for "1.2". Special floating point values
5135 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
5136 are accepted.
5137 - Leading zeroes in integer numbers are ignored, e.g. "012"
5138 for "12" or "-012" for "-12".
5139 - Capitalization is ignored in literal names null, true or
5140 false, e.g. "NULL" for "null", "True" for "true".
5141 - Control characters U+0000 through U+001F which are not
5142 escaped in strings are accepted, e.g. " " (tab
5143 character in string) for "\t".
5144 - An empty JSON expression or made of only spaces is accepted
5145 and results in v:none.
5146 - Backslash in an invalid 2-character sequence escape is
5147 ignored, e.g. "\a" is decoded as "a".
5148 - A correct surrogate pair in JSON strings should normally be
5149 a 12 character sequence such as "\uD834\uDD1E", but
5150 json_decode() silently accepts truncated surrogate pairs
5151 such as "\uD834" or "\uD834\u"
5152 *E938*
5153 A duplicate key in an object, valid in rfc7159, is not
5154 accepted by json_decode() as the result must be a valid Vim
5155 type, e.g. this fails: {"a":"b", "a":"c"}
5156
5157 Can also be used as a |method|: >
5158 ReadObject()->json_decode()
5159
5160json_encode({expr}) *json_encode()*
5161 Encode {expr} as JSON and return this as a string.
5162 The encoding is specified in:
5163 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00005164 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005165 |Number| decimal number
5166 |Float| floating point number
5167 Float nan "NaN"
5168 Float inf "Infinity"
5169 Float -inf "-Infinity"
5170 |String| in double quotes (possibly null)
5171 |Funcref| not possible, error
5172 |List| as an array (possibly null); when
5173 used recursively: []
5174 |Dict| as an object (possibly null); when
5175 used recursively: {}
5176 |Blob| as an array of the individual bytes
5177 v:false "false"
5178 v:true "true"
5179 v:none "null"
5180 v:null "null"
5181 Note that NaN and Infinity are passed on as values. This is
5182 missing in the JSON standard, but several implementations do
5183 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01005184 If a string contains an illegal character then the replacement
5185 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005186
5187 Can also be used as a |method|: >
5188 GetObject()->json_encode()
5189
5190keys({dict}) *keys()*
5191 Return a |List| with all the keys of {dict}. The |List| is in
5192 arbitrary order. Also see |items()| and |values()|.
5193
5194 Can also be used as a |method|: >
5195 mydict->keys()
5196
zeertzjqcdc83932022-09-12 13:38:41 +01005197keytrans({string}) *keytrans()*
5198 Turn the internal byte representation of keys into a form that
5199 can be used for |:map|. E.g. >
5200 :let xx = "\<C-Home>"
5201 :echo keytrans(xx)
5202< <C-Home>
5203
5204 Can also be used as a |method|: >
5205 "\<C-Home>"->keytrans()
5206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005207< *len()* *E701*
5208len({expr}) The result is a Number, which is the length of the argument.
5209 When {expr} is a String or a Number the length in bytes is
5210 used, as with |strlen()|.
5211 When {expr} is a |List| the number of items in the |List| is
5212 returned.
5213 When {expr} is a |Blob| the number of bytes is returned.
5214 When {expr} is a |Dictionary| the number of entries in the
5215 |Dictionary| is returned.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005216 Otherwise an error is given and returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005217
5218 Can also be used as a |method|: >
5219 mylist->len()
5220
5221< *libcall()* *E364* *E368*
5222libcall({libname}, {funcname}, {argument})
5223 Call function {funcname} in the run-time library {libname}
5224 with single argument {argument}.
5225 This is useful to call functions in a library that you
5226 especially made to be used with Vim. Since only one argument
5227 is possible, calling standard library functions is rather
5228 limited.
5229 The result is the String returned by the function. If the
5230 function returns NULL, this will appear as an empty string ""
5231 to Vim.
5232 If the function returns a number, use libcallnr()!
5233 If {argument} is a number, it is passed to the function as an
5234 int; if {argument} is a string, it is passed as a
5235 null-terminated string.
5236 This function will fail in |restricted-mode|.
5237
5238 libcall() allows you to write your own 'plug-in' extensions to
5239 Vim without having to recompile the program. It is NOT a
5240 means to call system functions! If you try to do so Vim will
5241 very probably crash.
5242
5243 For Win32, the functions you write must be placed in a DLL
5244 and use the normal C calling convention (NOT Pascal which is
5245 used in Windows System DLLs). The function must take exactly
5246 one parameter, either a character pointer or a long integer,
5247 and must return a character pointer or NULL. The character
5248 pointer returned must point to memory that will remain valid
5249 after the function has returned (e.g. in static data in the
5250 DLL). If it points to allocated memory, that memory will
5251 leak away. Using a static buffer in the function should work,
5252 it's then freed when the DLL is unloaded.
5253
5254 WARNING: If the function returns a non-valid pointer, Vim may
5255 crash! This also happens if the function returns a number,
5256 because Vim thinks it's a pointer.
5257 For Win32 systems, {libname} should be the filename of the DLL
5258 without the ".DLL" suffix. A full path is only required if
5259 the DLL is not in the usual places.
5260 For Unix: When compiling your own plugins, remember that the
5261 object code must be compiled as position-independent ('PIC').
5262 {only in Win32 and some Unix versions, when the |+libcall|
5263 feature is present}
5264 Examples: >
5265 :echo libcall("libc.so", "getenv", "HOME")
5266
5267< Can also be used as a |method|, the base is passed as the
5268 third argument: >
5269 GetValue()->libcall("libc.so", "getenv")
5270<
5271 *libcallnr()*
5272libcallnr({libname}, {funcname}, {argument})
5273 Just like |libcall()|, but used for a function that returns an
5274 int instead of a string.
5275 {only in Win32 on some Unix versions, when the |+libcall|
5276 feature is present}
5277 Examples: >
5278 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
5279 :call libcallnr("libc.so", "printf", "Hello World!\n")
5280 :call libcallnr("libc.so", "sleep", 10)
5281<
5282 Can also be used as a |method|, the base is passed as the
5283 third argument: >
5284 GetValue()->libcallnr("libc.so", "printf")
5285<
5286
5287line({expr} [, {winid}]) *line()*
5288 The result is a Number, which is the line number of the file
5289 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00005290 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005291 . the cursor position
5292 $ the last line in the current buffer
5293 'x position of mark x (if the mark is not set, 0 is
5294 returned)
5295 w0 first line visible in current window (one if the
5296 display isn't updated, e.g. in silent Ex mode)
5297 w$ last line visible in current window (this is one
5298 less than "w0" if no lines are visible)
5299 v In Visual mode: the start of the Visual area (the
5300 cursor is the end). When not in Visual mode
5301 returns the cursor position. Differs from |'<| in
5302 that it's updated right away.
5303 Note that a mark in another file can be used. The line number
5304 then applies to another buffer.
5305 To get the column number use |col()|. To get both use
5306 |getpos()|.
5307 With the optional {winid} argument the values are obtained for
5308 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005309 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005310 Examples: >
5311 line(".") line number of the cursor
5312 line(".", winid) idem, in window "winid"
5313 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005314 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005315<
5316 To jump to the last known position when opening a file see
5317 |last-position-jump|.
5318
5319 Can also be used as a |method|: >
5320 GetValue()->line()
5321
5322line2byte({lnum}) *line2byte()*
5323 Return the byte count from the start of the buffer for line
5324 {lnum}. This includes the end-of-line character, depending on
5325 the 'fileformat' option for the current buffer. The first
5326 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
5327 This can also be used to get the byte count for the line just
5328 below the last line: >
5329 line2byte(line("$") + 1)
5330< This is the buffer size plus one. If 'fileencoding' is empty
5331 it is the file size plus one. {lnum} is used like with
5332 |getline()|. When {lnum} is invalid, or the |+byte_offset|
5333 feature has been disabled at compile time, -1 is returned.
5334 Also see |byte2line()|, |go| and |:goto|.
5335
5336 Can also be used as a |method|: >
5337 GetLnum()->line2byte()
5338
5339lispindent({lnum}) *lispindent()*
5340 Get the amount of indent for line {lnum} according the lisp
5341 indenting rules, as with 'lisp'.
5342 The indent is counted in spaces, the value of 'tabstop' is
5343 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01005344 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005345 error is given.
5346
5347 Can also be used as a |method|: >
5348 GetLnum()->lispindent()
5349
5350list2blob({list}) *list2blob()*
5351 Return a Blob concatenating all the number values in {list}.
5352 Examples: >
5353 list2blob([1, 2, 3, 4]) returns 0z01020304
5354 list2blob([]) returns 0z
5355< Returns an empty Blob on error. If one of the numbers is
5356 negative or more than 255 error *E1239* is given.
5357
5358 |blob2list()| does the opposite.
5359
5360 Can also be used as a |method|: >
5361 GetList()->list2blob()
5362
5363list2str({list} [, {utf8}]) *list2str()*
5364 Convert each number in {list} to a character string can
5365 concatenate them all. Examples: >
5366 list2str([32]) returns " "
5367 list2str([65, 66, 67]) returns "ABC"
5368< The same can be done (slowly) with: >
5369 join(map(list, {nr, val -> nr2char(val)}), '')
5370< |str2list()| does the opposite.
5371
5372 When {utf8} is omitted or zero, the current 'encoding' is used.
5373 When {utf8} is TRUE, always return UTF-8 characters.
5374 With UTF-8 composing characters work as expected: >
5375 list2str([97, 769]) returns "á"
5376<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005377 Returns an empty string on error.
5378
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005379 Can also be used as a |method|: >
5380 GetList()->list2str()
5381
5382listener_add({callback} [, {buf}]) *listener_add()*
5383 Add a callback function that will be invoked when changes have
5384 been made to buffer {buf}.
5385 {buf} refers to a buffer name or number. For the accepted
5386 values, see |bufname()|. When {buf} is omitted the current
5387 buffer is used.
5388 Returns a unique ID that can be passed to |listener_remove()|.
5389
5390 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00005391 bufnr the buffer that was changed
5392 start first changed line number
5393 end first line number below the change
5394 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005395 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00005396 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005397
5398 Example: >
5399 func Listener(bufnr, start, end, added, changes)
5400 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
5401 endfunc
5402 call listener_add('Listener', bufnr)
5403
Bram Moolenaar944697a2022-02-20 19:48:20 +00005404< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005405 dictionary with these entries:
5406 lnum the first line number of the change
5407 end the first line below the change
5408 added number of lines added; negative if lines were
5409 deleted
5410 col first column in "lnum" that was affected by
5411 the change; one if unknown or the whole line
5412 was affected; this is a byte index, first
5413 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01005414 When lines are inserted (not when a line is split, e.g. by
5415 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005416 lnum line above which the new line is added
5417 end equal to "lnum"
5418 added number of lines inserted
5419 col 1
5420 When lines are deleted the values are:
5421 lnum the first deleted line
5422 end the line below the first deleted line, before
5423 the deletion was done
5424 added negative, number of lines deleted
5425 col 1
5426 When lines are changed:
5427 lnum the first changed line
5428 end the line below the last changed line
5429 added 0
5430 col first column with a change or 1
5431
5432 The entries are in the order the changes were made, thus the
5433 most recent change is at the end. The line numbers are valid
5434 when the callback is invoked, but later changes may make them
5435 invalid, thus keeping a copy for later might not work.
5436
5437 The {callback} is invoked just before the screen is updated,
5438 when |listener_flush()| is called or when a change is being
5439 made that changes the line count in a way it causes a line
5440 number in the list of changes to become invalid.
5441
5442 The {callback} is invoked with the text locked, see
5443 |textlock|. If you do need to make changes to the buffer, use
5444 a timer to do this later |timer_start()|.
5445
5446 The {callback} is not invoked when the buffer is first loaded.
5447 Use the |BufReadPost| autocmd event to handle the initial text
5448 of a buffer.
5449 The {callback} is also not invoked when the buffer is
5450 unloaded, use the |BufUnload| autocmd event for that.
5451
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005452 Returns zero if {callback} or {buf} is invalid.
5453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005454 Can also be used as a |method|, the base is passed as the
5455 second argument: >
5456 GetBuffer()->listener_add(callback)
5457
5458listener_flush([{buf}]) *listener_flush()*
5459 Invoke listener callbacks for buffer {buf}. If there are no
5460 pending changes then no callbacks are invoked.
5461
5462 {buf} refers to a buffer name or number. For the accepted
5463 values, see |bufname()|. When {buf} is omitted the current
5464 buffer is used.
5465
5466 Can also be used as a |method|: >
5467 GetBuffer()->listener_flush()
5468
5469listener_remove({id}) *listener_remove()*
5470 Remove a listener previously added with listener_add().
5471 Returns FALSE when {id} could not be found, TRUE when {id} was
5472 removed.
5473
5474 Can also be used as a |method|: >
5475 GetListenerId()->listener_remove()
5476
5477localtime() *localtime()*
5478 Return the current time, measured as seconds since 1st Jan
5479 1970. See also |strftime()|, |strptime()| and |getftime()|.
5480
5481
5482log({expr}) *log()*
5483 Return the natural logarithm (base e) of {expr} as a |Float|.
5484 {expr} must evaluate to a |Float| or a |Number| in the range
5485 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005486 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005487 Examples: >
5488 :echo log(10)
5489< 2.302585 >
5490 :echo log(exp(5))
5491< 5.0
5492
5493 Can also be used as a |method|: >
5494 Compute()->log()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005495
5496
5497log10({expr}) *log10()*
5498 Return the logarithm of Float {expr} to base 10 as a |Float|.
5499 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005500 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005501 Examples: >
5502 :echo log10(1000)
5503< 3.0 >
5504 :echo log10(0.01)
5505< -2.0
5506
5507 Can also be used as a |method|: >
5508 Compute()->log10()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005509
5510luaeval({expr} [, {expr}]) *luaeval()*
5511 Evaluate Lua expression {expr} and return its result converted
5512 to Vim data structures. Second {expr} may hold additional
5513 argument accessible as _A inside first {expr}.
5514 Strings are returned as they are.
5515 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01005516 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005517 Dictionaries and lists obtained by vim.eval() are returned
5518 as-is.
5519 Other objects are returned as zero without any errors.
5520 See |lua-luaeval| for more details.
5521 Note that in a `:def` function local variables are not visible
5522 to {expr}.
5523
5524 Can also be used as a |method|: >
5525 GetExpr()->luaeval()
5526
5527< {only available when compiled with the |+lua| feature}
5528
5529map({expr1}, {expr2}) *map()*
5530 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00005531 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005532 item in {expr1} with the result of evaluating {expr2}.
5533 For a |Blob| each byte is replaced.
5534 For a |String|, each character, including composing
5535 characters, is replaced.
5536 If the item type changes you may want to use |mapnew()| to
5537 create a new List or Dictionary. This is required when using
5538 Vim9 script.
5539
5540 {expr2} must be a |String| or |Funcref|.
5541
5542 If {expr2} is a |String|, inside {expr2} |v:val| has the value
5543 of the current item. For a |Dictionary| |v:key| has the key
5544 of the current item and for a |List| |v:key| has the index of
5545 the current item. For a |Blob| |v:key| has the index of the
5546 current byte. For a |String| |v:key| has the index of the
5547 current character.
5548 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005549 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005550< This puts "> " before and " <" after each item in "mylist".
5551
5552 Note that {expr2} is the result of an expression and is then
5553 used as an expression again. Often it is good to use a
5554 |literal-string| to avoid having to double backslashes. You
5555 still have to double ' quotes
5556
5557 If {expr2} is a |Funcref| it is called with two arguments:
5558 1. The key or the index of the current item.
5559 2. the value of the current item.
5560 The function must return the new value of the item. Example
5561 that changes each value by "key-value": >
5562 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005563 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005564 endfunc
5565 call map(myDict, function('KeyValue'))
5566< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005567 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005568< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005569 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005570< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005571 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005572<
5573 The operation is done in-place for a |List| and |Dictionary|.
5574 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005575 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005576
5577< Returns {expr1}, the |List| or |Dictionary| that was filtered,
5578 or a new |Blob| or |String|.
5579 When an error is encountered while evaluating {expr2} no
5580 further items in {expr1} are processed.
5581 When {expr2} is a Funcref errors inside a function are ignored,
5582 unless it was defined with the "abort" flag.
5583
5584 Can also be used as a |method|: >
5585 mylist->map(expr2)
5586
5587
5588maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
5589 When {dict} is omitted or zero: Return the rhs of mapping
5590 {name} in mode {mode}. The returned String has special
5591 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01005592 listing. When {dict} is TRUE a dictionary is returned, see
5593 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005594
5595 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005596 returned if {dict} is FALSE, otherwise returns an empty Dict.
5597 When the mapping for {name} is empty, then "<Nop>" is
5598 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005599
5600 The {name} can have special key names, like in the ":map"
5601 command.
5602
5603 {mode} can be one of these strings:
5604 "n" Normal
5605 "v" Visual (including Select)
5606 "o" Operator-pending
5607 "i" Insert
5608 "c" Cmd-line
5609 "s" Select
5610 "x" Visual
5611 "l" langmap |language-mapping|
5612 "t" Terminal-Job
5613 "" Normal, Visual and Operator-pending
5614 When {mode} is omitted, the modes for "" are used.
5615
5616 When {abbr} is there and it is |TRUE| use abbreviations
5617 instead of mappings.
5618
5619 When {dict} is there and it is |TRUE| return a dictionary
5620 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01005621 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005622 "lhs" The {lhs} of the mapping as it would be typed
5623 "lhsraw" The {lhs} of the mapping as raw bytes
5624 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
5625 form, only present when it differs from "lhsraw"
5626 "rhs" The {rhs} of the mapping as typed.
5627 "silent" 1 for a |:map-silent| mapping, else 0.
5628 "noremap" 1 if the {rhs} of the mapping is not remappable.
5629 "script" 1 if mapping was defined with <script>.
5630 "expr" 1 for an expression mapping (|:map-<expr>|).
5631 "buffer" 1 for a buffer local mapping (|:map-local|).
5632 "mode" Modes for which the mapping is defined. In
5633 addition to the modes mentioned above, these
5634 characters will be used:
5635 " " Normal, Visual and Operator-pending
5636 "!" Insert and Commandline mode
5637 (|mapmode-ic|)
5638 "sid" The script local ID, used for <sid> mappings
5639 (|<SID>|).
Bram Moolenaara9528b32022-01-18 20:51:35 +00005640 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005641 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005642 "lnum" The line number in "sid", zero if unknown.
5643 "nowait" Do not wait for other, longer mappings.
5644 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01005645 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01005646 "mode_bits" Vim's internal binary representation of "mode".
5647 |mapset()| ignores this; only "mode" is used.
5648 See |maplist()| for usage examples. The values
5649 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005650
5651 The dictionary can be used to restore a mapping with
5652 |mapset()|.
5653
5654 The mappings local to the current buffer are checked first,
5655 then the global mappings.
5656 This function can be used to map a key even when it's already
5657 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005658 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005659
5660< Can also be used as a |method|: >
5661 GetKey()->maparg('n')
5662
5663mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
5664 Check if there is a mapping that matches with {name} in mode
5665 {mode}. See |maparg()| for {mode} and special names in
5666 {name}.
5667 When {abbr} is there and it is |TRUE| use abbreviations
5668 instead of mappings.
5669 A match happens with a mapping that starts with {name} and
5670 with a mapping which is equal to the start of {name}.
5671
5672 matches mapping "a" "ab" "abc" ~
5673 mapcheck("a") yes yes yes
5674 mapcheck("abc") yes yes yes
5675 mapcheck("ax") yes no no
5676 mapcheck("b") no no no
5677
5678 The difference with maparg() is that mapcheck() finds a
5679 mapping that matches with {name}, while maparg() only finds a
5680 mapping for {name} exactly.
5681 When there is no mapping that starts with {name}, an empty
5682 String is returned. If there is one, the RHS of that mapping
5683 is returned. If there are several mappings that start with
5684 {name}, the RHS of one of them is returned. This will be
5685 "<Nop>" if the RHS is empty.
5686 The mappings local to the current buffer are checked first,
5687 then the global mappings.
5688 This function can be used to check if a mapping can be added
5689 without being ambiguous. Example: >
5690 :if mapcheck("_vv") == ""
5691 : map _vv :set guifont=7x13<CR>
5692 :endif
5693< This avoids adding the "_vv" mapping when there already is a
5694 mapping for "_v" or for "_vvv".
5695
5696 Can also be used as a |method|: >
5697 GetKey()->mapcheck('n')
5698
5699
Ernie Rael09661202022-04-25 14:40:44 +01005700maplist([{abbr}]) *maplist()*
5701 Returns a |List| of all mappings. Each List item is a |Dict|,
5702 the same as what is returned by |maparg()|, see
5703 |mapping-dict|. When {abbr} is there and it is |TRUE| use
5704 abbreviations instead of mappings.
5705
5706 Example to show all mappings with 'MultiMatch' in rhs: >
5707 vim9script
5708 echo maplist()->filter(
5709 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01005710< It can be tricky to find mappings for particular |:map-modes|.
5711 |mapping-dict|'s "mode_bits" can simplify this. For example,
5712 the mode_bits for Normal, Insert or Command-line modes are
5713 0x19. To find all the mappings available in those modes you
5714 can do: >
5715 vim9script
5716 var saved_maps = []
5717 for m in maplist()
5718 if and(m.mode_bits, 0x19) != 0
5719 saved_maps->add(m)
5720 endif
5721 endfor
5722 echo saved_maps->mapnew((_, m) => m.lhs)
5723< The values of the mode_bits are defined in Vim's src/vim.h
5724 file and they can be discovered at runtime using
5725 |:map-commands| and "maplist()". Example: >
5726 vim9script
5727 omap xyzzy <Nop>
5728 var op_bit = maplist()->filter(
5729 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
5730 ounmap xyzzy
5731 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Ernie Rael09661202022-04-25 14:40:44 +01005732
5733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005734mapnew({expr1}, {expr2}) *mapnew()*
5735 Like |map()| but instead of replacing items in {expr1} a new
5736 List or Dictionary is created and returned. {expr1} remains
5737 unchanged. Items can still be changed by {expr2}, if you
5738 don't want that use |deepcopy()| first.
5739
5740
5741mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01005742mapset({dict})
5743 Restore a mapping from a dictionary, possibly returned by
5744 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
5745 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01005746 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01005747 feature allows copying mappings from one buffer to another.
5748 The dict.mode value may restore a single mapping that covers
5749 more than one mode, like with mode values of '!', ' ', 'nox',
5750 or 'v'. *E1276*
5751
5752 In the first form, {mode} and {abbr} should be the same as
5753 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005754 {mode} is used to define the mode in which the mapping is set,
5755 not the "mode" entry in {dict}.
5756 Example for saving and restoring a mapping: >
5757 let save_map = maparg('K', 'n', 0, 1)
5758 nnoremap K somethingelse
5759 ...
5760 call mapset('n', 0, save_map)
5761< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01005762 e.g. with `:map!`, you need to save/restore the mapping for
5763 all of them, when they might differ.
5764
5765 In the second form, with {dict} as the only argument, mode
5766 and abbr are taken from the dict.
5767 Example: >
5768 vim9script
5769 var save_maps = maplist()->filter(
5770 (_, m) => m.lhs == 'K')
5771 nnoremap K somethingelse
5772 cnoremap K somethingelse2
5773 # ...
5774 unmap K
5775 for d in save_maps
5776 mapset(d)
5777 endfor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005778
5779
5780match({expr}, {pat} [, {start} [, {count}]]) *match()*
5781 When {expr} is a |List| then this returns the index of the
5782 first item where {pat} matches. Each item is used as a
5783 String, |Lists| and |Dictionaries| are used as echoed.
5784
5785 Otherwise, {expr} is used as a String. The result is a
5786 Number, which gives the index (byte offset) in {expr} where
5787 {pat} matches.
5788
5789 A match at the first character or |List| item returns zero.
5790 If there is no match -1 is returned.
5791
5792 For getting submatches see |matchlist()|.
5793 Example: >
5794 :echo match("testing", "ing") " results in 4
5795 :echo match([1, 'x'], '\a') " results in 1
5796< See |string-match| for how {pat} is used.
5797 *strpbrk()*
5798 Vim doesn't have a strpbrk() function. But you can do: >
5799 :let sepidx = match(line, '[.,;: \t]')
5800< *strcasestr()*
5801 Vim doesn't have a strcasestr() function. But you can add
5802 "\c" to the pattern to ignore case: >
5803 :let idx = match(haystack, '\cneedle')
5804<
5805 If {start} is given, the search starts from byte index
5806 {start} in a String or item {start} in a |List|.
5807 The result, however, is still the index counted from the
5808 first character/item. Example: >
5809 :echo match("testing", "ing", 2)
5810< result is again "4". >
5811 :echo match("testing", "ing", 4)
5812< result is again "4". >
5813 :echo match("testing", "t", 2)
5814< result is "3".
5815 For a String, if {start} > 0 then it is like the string starts
5816 {start} bytes later, thus "^" will match at {start}. Except
5817 when {count} is given, then it's like matches before the
5818 {start} byte are ignored (this is a bit complicated to keep it
5819 backwards compatible).
5820 For a String, if {start} < 0, it will be set to 0. For a list
5821 the index is counted from the end.
5822 If {start} is out of range ({start} > strlen({expr}) for a
5823 String or {start} > len({expr}) for a |List|) -1 is returned.
5824
5825 When {count} is given use the {count}'th match. When a match
5826 is found in a String the search for the next one starts one
5827 character further. Thus this example results in 1: >
5828 echo match("testing", "..", 0, 2)
5829< In a |List| the search continues in the next item.
5830 Note that when {count} is added the way {start} works changes,
5831 see above.
5832
5833 See |pattern| for the patterns that are accepted.
5834 The 'ignorecase' option is used to set the ignore-caseness of
5835 the pattern. 'smartcase' is NOT used. The matching is always
5836 done like 'magic' is set and 'cpoptions' is empty.
5837 Note that a match at the start is preferred, thus when the
5838 pattern is using "*" (any number of matches) it tends to find
5839 zero matches at the start instead of a number of matches
5840 further down in the text.
5841
5842 Can also be used as a |method|: >
5843 GetText()->match('word')
5844 GetList()->match('word')
5845<
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00005846 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005847matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
5848 Defines a pattern to be highlighted in the current window (a
5849 "match"). It will be highlighted with {group}. Returns an
5850 identification number (ID), which can be used to delete the
5851 match using |matchdelete()|. The ID is bound to the window.
5852 Matching is case sensitive and magic, unless case sensitivity
5853 or magicness are explicitly overridden in {pattern}. The
5854 'magic', 'smartcase' and 'ignorecase' options are not used.
5855 The "Conceal" value is special, it causes the match to be
5856 concealed.
5857
5858 The optional {priority} argument assigns a priority to the
5859 match. A match with a high priority will have its
5860 highlighting overrule that of a match with a lower priority.
5861 A priority is specified as an integer (negative numbers are no
5862 exception). If the {priority} argument is not specified, the
5863 default priority is 10. The priority of 'hlsearch' is zero,
5864 hence all matches with a priority greater than zero will
5865 overrule it. Syntax highlighting (see 'syntax') is a separate
5866 mechanism, and regardless of the chosen priority a match will
5867 always overrule syntax highlighting.
5868
5869 The optional {id} argument allows the request for a specific
5870 match ID. If a specified ID is already taken, an error
5871 message will appear and the match will not be added. An ID
5872 is specified as a positive integer (zero excluded). IDs 1, 2
5873 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01005874 respectively. 3 is reserved for use by the |matchparen|
5875 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01005876 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01005877 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005878
5879 The optional {dict} argument allows for further custom
5880 values. Currently this is used to specify a match specific
5881 conceal character that will be shown for |hl-Conceal|
5882 highlighted matches. The dict can have the following members:
5883
5884 conceal Special character to show instead of the
5885 match (only for |hl-Conceal| highlighted
5886 matches, see |:syn-cchar|)
5887 window Instead of the current window use the
5888 window with this number or window ID.
5889
5890 The number of matches is not limited, as it is the case with
5891 the |:match| commands.
5892
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005893 Returns -1 on error.
5894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005895 Example: >
5896 :highlight MyGroup ctermbg=green guibg=green
5897 :let m = matchadd("MyGroup", "TODO")
5898< Deletion of the pattern: >
5899 :call matchdelete(m)
5900
5901< A list of matches defined by |matchadd()| and |:match| are
5902 available from |getmatches()|. All matches can be deleted in
5903 one operation by |clearmatches()|.
5904
5905 Can also be used as a |method|: >
5906 GetGroup()->matchadd('TODO')
5907<
5908 *matchaddpos()*
5909matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
5910 Same as |matchadd()|, but requires a list of positions {pos}
5911 instead of a pattern. This command is faster than |matchadd()|
5912 because it does not require to handle regular expressions and
5913 sets buffer line boundaries to redraw screen. It is supposed
5914 to be used when fast match additions and deletions are
5915 required, for example to highlight matching parentheses.
5916
5917 {pos} is a list of positions. Each position can be one of
5918 these:
5919 - A number. This whole line will be highlighted. The first
5920 line has number 1.
5921 - A list with one number, e.g., [23]. The whole line with this
5922 number will be highlighted.
5923 - A list with two numbers, e.g., [23, 11]. The first number is
5924 the line number, the second one is the column number (first
5925 column is 1, the value must correspond to the byte index as
5926 |col()| would return). The character at this position will
5927 be highlighted.
5928 - A list with three numbers, e.g., [23, 11, 3]. As above, but
5929 the third number gives the length of the highlight in bytes.
5930
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01005931 Returns -1 on error.
5932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005933 Example: >
5934 :highlight MyGroup ctermbg=green guibg=green
5935 :let m = matchaddpos("MyGroup", [[23, 24], 34])
5936< Deletion of the pattern: >
5937 :call matchdelete(m)
5938
5939< Matches added by |matchaddpos()| are returned by
5940 |getmatches()|.
5941
5942 Can also be used as a |method|: >
5943 GetGroup()->matchaddpos([23, 11])
5944
5945matcharg({nr}) *matcharg()*
5946 Selects the {nr} match item, as set with a |:match|,
5947 |:2match| or |:3match| command.
5948 Return a |List| with two elements:
5949 The name of the highlight group used
5950 The pattern used.
5951 When {nr} is not 1, 2 or 3 returns an empty |List|.
5952 When there is no match item set returns ['', ''].
5953 This is useful to save and restore a |:match|.
5954 Highlighting matches using the |:match| commands are limited
5955 to three matches. |matchadd()| does not have this limitation.
5956
5957 Can also be used as a |method|: >
5958 GetMatch()->matcharg()
5959
5960matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
5961 Deletes a match with ID {id} previously defined by |matchadd()|
5962 or one of the |:match| commands. Returns 0 if successful,
5963 otherwise -1. See example for |matchadd()|. All matches can
5964 be deleted in one operation by |clearmatches()|.
5965 If {win} is specified, use the window with this number or
5966 window ID instead of the current window.
5967
5968 Can also be used as a |method|: >
5969 GetMatch()->matchdelete()
5970
5971matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
5972 Same as |match()|, but return the index of first character
5973 after the match. Example: >
5974 :echo matchend("testing", "ing")
5975< results in "7".
5976 *strspn()* *strcspn()*
5977 Vim doesn't have a strspn() or strcspn() function, but you can
5978 do it with matchend(): >
5979 :let span = matchend(line, '[a-zA-Z]')
5980 :let span = matchend(line, '[^a-zA-Z]')
5981< Except that -1 is returned when there are no matches.
5982
5983 The {start}, if given, has the same meaning as for |match()|. >
5984 :echo matchend("testing", "ing", 2)
5985< results in "7". >
5986 :echo matchend("testing", "ing", 5)
5987< result is "-1".
5988 When {expr} is a |List| the result is equal to |match()|.
5989
5990 Can also be used as a |method|: >
5991 GetText()->matchend('word')
5992
5993
5994matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
5995 If {list} is a list of strings, then returns a |List| with all
5996 the strings in {list} that fuzzy match {str}. The strings in
5997 the returned list are sorted based on the matching score.
5998
5999 The optional {dict} argument always supports the following
6000 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01006001 matchseq When this item is present return only matches
6002 that contain the characters in {str} in the
6003 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01006004 limit Maximum number of matches in {list} to be
6005 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006006
6007 If {list} is a list of dictionaries, then the optional {dict}
6008 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006009 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006010 {str}. The value of this item should be a
6011 string.
6012 text_cb |Funcref| that will be called for every item
6013 in {list} to get the text for fuzzy matching.
6014 This should accept a dictionary item as the
6015 argument and return the text for that item to
6016 use for fuzzy matching.
6017
6018 {str} is treated as a literal string and regular expression
6019 matching is NOT supported. The maximum supported {str} length
6020 is 256.
6021
6022 When {str} has multiple words each separated by white space,
6023 then the list of strings that have all the words is returned.
6024
6025 If there are no matching strings or there is an error, then an
6026 empty list is returned. If length of {str} is greater than
6027 256, then returns an empty list.
6028
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01006029 When {limit} is given, matchfuzzy() will find up to this
6030 number of matches in {list} and return them in sorted order.
6031
Bram Moolenaar1588bc82022-03-08 21:35:07 +00006032 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006033 matching strings.
6034
6035 Example: >
6036 :echo matchfuzzy(["clay", "crow"], "cay")
6037< results in ["clay"]. >
6038 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
6039< results in a list of buffer names fuzzy matching "ndl". >
6040 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
6041< results in a list of buffer information dicts with buffer
6042 names fuzzy matching "ndl". >
6043 :echo getbufinfo()->matchfuzzy("spl",
6044 \ {'text_cb' : {v -> v.name}})
6045< results in a list of buffer information dicts with buffer
6046 names fuzzy matching "spl". >
6047 :echo v:oldfiles->matchfuzzy("test")
6048< results in a list of file names fuzzy matching "test". >
6049 :let l = readfile("buffer.c")->matchfuzzy("str")
6050< results in a list of lines in "buffer.c" fuzzy matching "str". >
6051 :echo ['one two', 'two one']->matchfuzzy('two one')
6052< results in ['two one', 'one two']. >
6053 :echo ['one two', 'two one']->matchfuzzy('two one',
6054 \ {'matchseq': 1})
6055< results in ['two one'].
6056
6057matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
6058 Same as |matchfuzzy()|, but returns the list of matched
6059 strings, the list of character positions where characters
6060 in {str} matches and a list of matching scores. You can
6061 use |byteidx()| to convert a character position to a byte
6062 position.
6063
6064 If {str} matches multiple times in a string, then only the
6065 positions for the best match is returned.
6066
6067 If there are no matching strings or there is an error, then a
6068 list with three empty list items is returned.
6069
6070 Example: >
6071 :echo matchfuzzypos(['testing'], 'tsg')
6072< results in [['testing'], [[0, 2, 6]], [99]] >
6073 :echo matchfuzzypos(['clay', 'lacy'], 'la')
6074< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
6075 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
6076< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
6077
6078matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
6079 Same as |match()|, but return a |List|. The first item in the
6080 list is the matched string, same as what matchstr() would
6081 return. Following items are submatches, like "\1", "\2", etc.
6082 in |:substitute|. When an optional submatch didn't match an
6083 empty string is used. Example: >
6084 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
6085< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
6086 When there is no match an empty list is returned.
6087
6088 You can pass in a List, but that is not very useful.
6089
6090 Can also be used as a |method|: >
6091 GetText()->matchlist('word')
6092
6093matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
6094 Same as |match()|, but return the matched string. Example: >
6095 :echo matchstr("testing", "ing")
6096< results in "ing".
6097 When there is no match "" is returned.
6098 The {start}, if given, has the same meaning as for |match()|. >
6099 :echo matchstr("testing", "ing", 2)
6100< results in "ing". >
6101 :echo matchstr("testing", "ing", 5)
6102< result is "".
6103 When {expr} is a |List| then the matching item is returned.
6104 The type isn't changed, it's not necessarily a String.
6105
6106 Can also be used as a |method|: >
6107 GetText()->matchstr('word')
6108
6109matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
6110 Same as |matchstr()|, but return the matched string, the start
6111 position and the end position of the match. Example: >
6112 :echo matchstrpos("testing", "ing")
6113< results in ["ing", 4, 7].
6114 When there is no match ["", -1, -1] is returned.
6115 The {start}, if given, has the same meaning as for |match()|. >
6116 :echo matchstrpos("testing", "ing", 2)
6117< results in ["ing", 4, 7]. >
6118 :echo matchstrpos("testing", "ing", 5)
6119< result is ["", -1, -1].
6120 When {expr} is a |List| then the matching item, the index
6121 of first item where {pat} matches, the start position and the
6122 end position of the match are returned. >
6123 :echo matchstrpos([1, '__x'], '\a')
6124< result is ["x", 1, 2, 3].
6125 The type isn't changed, it's not necessarily a String.
6126
6127 Can also be used as a |method|: >
6128 GetText()->matchstrpos('word')
6129<
6130
6131 *max()*
6132max({expr}) Return the maximum value of all items in {expr}. Example: >
6133 echo max([apples, pears, oranges])
6134
6135< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6136 it returns the maximum of all values in the Dictionary.
6137 If {expr} is neither a List nor a Dictionary, or one of the
6138 items in {expr} cannot be used as a Number this results in
6139 an error. An empty |List| or |Dictionary| results in zero.
6140
6141 Can also be used as a |method|: >
6142 mylist->max()
6143
6144
6145menu_info({name} [, {mode}]) *menu_info()*
6146 Return information about the specified menu {name} in
6147 mode {mode}. The menu name should be specified without the
6148 shortcut character ('&'). If {name} is "", then the top-level
6149 menu names are returned.
6150
6151 {mode} can be one of these strings:
6152 "n" Normal
6153 "v" Visual (including Select)
6154 "o" Operator-pending
6155 "i" Insert
6156 "c" Cmd-line
6157 "s" Select
6158 "x" Visual
6159 "t" Terminal-Job
6160 "" Normal, Visual and Operator-pending
6161 "!" Insert and Cmd-line
6162 When {mode} is omitted, the modes for "" are used.
6163
6164 Returns a |Dictionary| containing the following items:
6165 accel menu item accelerator text |menu-text|
6166 display display name (name without '&')
6167 enabled v:true if this menu item is enabled
6168 Refer to |:menu-enable|
6169 icon name of the icon file (for toolbar)
6170 |toolbar-icon|
6171 iconidx index of a built-in icon
6172 modes modes for which the menu is defined. In
6173 addition to the modes mentioned above, these
6174 characters will be used:
6175 " " Normal, Visual and Operator-pending
6176 name menu item name.
6177 noremenu v:true if the {rhs} of the menu item is not
6178 remappable else v:false.
6179 priority menu order priority |menu-priority|
6180 rhs right-hand-side of the menu item. The returned
6181 string has special characters translated like
6182 in the output of the ":menu" command listing.
6183 When the {rhs} of a menu item is empty, then
6184 "<Nop>" is returned.
6185 script v:true if script-local remapping of {rhs} is
6186 allowed else v:false. See |:menu-script|.
6187 shortcut shortcut key (character after '&' in
6188 the menu name) |menu-shortcut|
6189 silent v:true if the menu item is created
6190 with <silent> argument |:menu-silent|
6191 submenus |List| containing the names of
6192 all the submenus. Present only if the menu
6193 item has submenus.
6194
6195 Returns an empty dictionary if the menu item is not found.
6196
6197 Examples: >
6198 :echo menu_info('Edit.Cut')
6199 :echo menu_info('File.Save', 'n')
6200
6201 " Display the entire menu hierarchy in a buffer
6202 func ShowMenu(name, pfx)
6203 let m = menu_info(a:name)
6204 call append(line('$'), a:pfx .. m.display)
6205 for child in m->get('submenus', [])
6206 call ShowMenu(a:name .. '.' .. escape(child, '.'),
6207 \ a:pfx .. ' ')
6208 endfor
6209 endfunc
6210 new
6211 for topmenu in menu_info('').submenus
6212 call ShowMenu(topmenu, '')
6213 endfor
6214<
6215 Can also be used as a |method|: >
6216 GetMenuName()->menu_info('v')
6217
6218
6219< *min()*
6220min({expr}) Return the minimum value of all items in {expr}. Example: >
6221 echo min([apples, pears, oranges])
6222
6223< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
6224 it returns the minimum of all values in the Dictionary.
6225 If {expr} is neither a List nor a Dictionary, or one of the
6226 items in {expr} cannot be used as a Number this results in
6227 an error. An empty |List| or |Dictionary| results in zero.
6228
6229 Can also be used as a |method|: >
6230 mylist->min()
6231
6232< *mkdir()* *E739*
6233mkdir({name} [, {path} [, {prot}]])
6234 Create directory {name}.
6235
Bram Moolenaar6f14da12022-09-07 21:30:44 +01006236 If {path} contains "p" then intermediate directories are
6237 created as necessary. Otherwise it must be "".
6238
6239 If {path} contains "D" then {name} is deleted at the end of
6240 the current function, as with: >
6241 defer delete({name}, 'd')
6242<
6243 If {path} contains "R" then {name} is deleted recursively at
6244 the end of the current function, as with: >
6245 defer delete({name}, 'rf')
6246< Note that when {name} has more than one part and "p" is used
6247 some directories may already exist. Only the first one that
6248 is created and what it contains is scheduled to be deleted.
6249 E.g. when using: >
6250 call mkdir('subdir/tmp/autoload', 'pR')
6251< and "subdir" already exists then "subdir/tmp" will be
6252 scheduled for deletion, like with: >
6253 defer delete('subdir/tmp', 'rf')
6254< Note that if scheduling the defer fails the directory is not
6255 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006256
6257 If {prot} is given it is used to set the protection bits of
6258 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
6259 the user, readable for others). Use 0o700 to make it
6260 unreadable for others. This is only used for the last part of
6261 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
6262 created with 0o755.
6263 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006264 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265
6266< This function is not available in the |sandbox|.
6267
6268 There is no error if the directory already exists and the "p"
6269 flag is passed (since patch 8.0.1708). However, without the
6270 "p" option the call will fail.
6271
6272 The function result is a Number, which is TRUE if the call was
6273 successful or FALSE if the directory creation failed or partly
6274 failed.
6275
6276 Not available on all systems. To check use: >
6277 :if exists("*mkdir")
6278
6279< Can also be used as a |method|: >
6280 GetName()->mkdir()
6281<
6282 *mode()*
6283mode([expr]) Return a string that indicates the current mode.
6284 If [expr] is supplied and it evaluates to a non-zero Number or
6285 a non-empty String (|non-zero-arg|), then the full mode is
6286 returned, otherwise only the first letter is returned.
6287 Also see |state()|.
6288
6289 n Normal
6290 no Operator-pending
6291 nov Operator-pending (forced characterwise |o_v|)
6292 noV Operator-pending (forced linewise |o_V|)
6293 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
6294 CTRL-V is one character
6295 niI Normal using |i_CTRL-O| in |Insert-mode|
6296 niR Normal using |i_CTRL-O| in |Replace-mode|
6297 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
6298 nt Terminal-Normal (insert goes to Terminal-Job mode)
6299 v Visual by character
6300 vs Visual by character using |v_CTRL-O| in Select mode
6301 V Visual by line
6302 Vs Visual by line using |v_CTRL-O| in Select mode
6303 CTRL-V Visual blockwise
6304 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
6305 s Select by character
6306 S Select by line
6307 CTRL-S Select blockwise
6308 i Insert
6309 ic Insert mode completion |compl-generic|
6310 ix Insert mode |i_CTRL-X| completion
6311 R Replace |R|
6312 Rc Replace mode completion |compl-generic|
6313 Rx Replace mode |i_CTRL-X| completion
6314 Rv Virtual Replace |gR|
6315 Rvc Virtual Replace mode completion |compl-generic|
6316 Rvx Virtual Replace mode |i_CTRL-X| completion
6317 c Command-line editing
6318 cv Vim Ex mode |gQ|
6319 ce Normal Ex mode |Q|
6320 r Hit-enter prompt
6321 rm The -- more -- prompt
6322 r? A |:confirm| query of some sort
6323 ! Shell or external command is executing
6324 t Terminal-Job mode: keys go to the job
6325
6326 This is useful in the 'statusline' option or when used
6327 with |remote_expr()| In most other places it always returns
6328 "c" or "n".
6329 Note that in the future more modes and more specific modes may
6330 be added. It's better not to compare the whole string but only
6331 the leading character(s).
6332 Also see |visualmode()|.
6333
6334 Can also be used as a |method|: >
6335 DoFull()->mode()
6336
6337mzeval({expr}) *mzeval()*
6338 Evaluate MzScheme expression {expr} and return its result
6339 converted to Vim data structures.
6340 Numbers and strings are returned as they are.
6341 Pairs (including lists and improper lists) and vectors are
6342 returned as Vim |Lists|.
6343 Hash tables are represented as Vim |Dictionary| type with keys
6344 converted to strings.
6345 All other types are converted to string with display function.
6346 Examples: >
6347 :mz (define l (list 1 2 3))
6348 :mz (define h (make-hash)) (hash-set! h "list" l)
6349 :echo mzeval("l")
6350 :echo mzeval("h")
6351<
6352 Note that in a `:def` function local variables are not visible
6353 to {expr}.
6354
6355 Can also be used as a |method|: >
6356 GetExpr()->mzeval()
6357<
6358 {only available when compiled with the |+mzscheme| feature}
6359
6360nextnonblank({lnum}) *nextnonblank()*
6361 Return the line number of the first line at or below {lnum}
6362 that is not blank. Example: >
6363 if getline(nextnonblank(1)) =~ "Java"
6364< When {lnum} is invalid or there is no non-blank line at or
6365 below it, zero is returned.
6366 {lnum} is used like with |getline()|.
6367 See also |prevnonblank()|.
6368
6369 Can also be used as a |method|: >
6370 GetLnum()->nextnonblank()
6371
6372nr2char({expr} [, {utf8}]) *nr2char()*
6373 Return a string with a single character, which has the number
6374 value {expr}. Examples: >
6375 nr2char(64) returns "@"
6376 nr2char(32) returns " "
6377< When {utf8} is omitted or zero, the current 'encoding' is used.
6378 Example for "utf-8": >
6379 nr2char(300) returns I with bow character
6380< When {utf8} is TRUE, always return UTF-8 characters.
6381 Note that a NUL character in the file is specified with
6382 nr2char(10), because NULs are represented with newline
6383 characters. nr2char(0) is a real NUL and terminates the
6384 string, thus results in an empty string.
6385 To turn a list of character numbers into a string: >
6386 let list = [65, 66, 67]
6387 let str = join(map(list, {_, val -> nr2char(val)}), '')
6388< Result: "ABC"
6389
6390 Can also be used as a |method|: >
6391 GetNumber()->nr2char()
6392
6393or({expr}, {expr}) *or()*
6394 Bitwise OR on the two arguments. The arguments are converted
6395 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006396 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006397 Example: >
6398 :let bits = or(bits, 0x80)
6399< Can also be used as a |method|: >
6400 :let bits = bits->or(0x80)
6401
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01006402< Rationale: The reason this is a function and not using the "|"
6403 character like many languages, is that Vi has always used "|"
6404 to separate commands. In many places it would not be clear if
6405 "|" is an operator or a command separator.
6406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006407
6408pathshorten({path} [, {len}]) *pathshorten()*
6409 Shorten directory names in the path {path} and return the
6410 result. The tail, the file name, is kept as-is. The other
6411 components in the path are reduced to {len} letters in length.
6412 If {len} is omitted or smaller than 1 then 1 is used (single
6413 letters). Leading '~' and '.' characters are kept. Examples: >
6414 :echo pathshorten('~/.vim/autoload/myfile.vim')
6415< ~/.v/a/myfile.vim ~
6416>
6417 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
6418< ~/.vi/au/myfile.vim ~
6419 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006420 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006421
6422 Can also be used as a |method|: >
6423 GetDirectories()->pathshorten()
6424
6425perleval({expr}) *perleval()*
6426 Evaluate Perl expression {expr} in scalar context and return
6427 its result converted to Vim data structures. If value can't be
6428 converted, it is returned as a string Perl representation.
6429 Note: If you want an array or hash, {expr} must return a
6430 reference to it.
6431 Example: >
6432 :echo perleval('[1 .. 4]')
6433< [1, 2, 3, 4]
6434
6435 Note that in a `:def` function local variables are not visible
6436 to {expr}.
6437
6438 Can also be used as a |method|: >
6439 GetExpr()->perleval()
6440
6441< {only available when compiled with the |+perl| feature}
6442
6443
6444popup_ functions are documented here: |popup-functions|
6445
6446
6447pow({x}, {y}) *pow()*
6448 Return the power of {x} to the exponent {y} as a |Float|.
6449 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006450 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006451 Examples: >
6452 :echo pow(3, 3)
6453< 27.0 >
6454 :echo pow(2, 16)
6455< 65536.0 >
6456 :echo pow(32, 0.20)
6457< 2.0
6458
6459 Can also be used as a |method|: >
6460 Compute()->pow(3)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006461
6462prevnonblank({lnum}) *prevnonblank()*
6463 Return the line number of the first line at or above {lnum}
6464 that is not blank. Example: >
6465 let ind = indent(prevnonblank(v:lnum - 1))
6466< When {lnum} is invalid or there is no non-blank line at or
6467 above it, zero is returned.
6468 {lnum} is used like with |getline()|.
6469 Also see |nextnonblank()|.
6470
6471 Can also be used as a |method|: >
6472 GetLnum()->prevnonblank()
6473
6474printf({fmt}, {expr1} ...) *printf()*
6475 Return a String with {fmt}, where "%" items are replaced by
6476 the formatted form of their respective arguments. Example: >
6477 printf("%4d: E%d %.30s", lnum, errno, msg)
6478< May result in:
6479 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
6480
6481 When used as a |method| the base is passed as the second
6482 argument: >
6483 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006484<
6485 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006486
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006487 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006488 %s string
6489 %6S string right-aligned in 6 display cells
6490 %6s string right-aligned in 6 bytes
6491 %.9s string truncated to 9 bytes
6492 %c single byte
6493 %d decimal number
6494 %5d decimal number padded with spaces to 5 characters
6495 %x hex number
6496 %04x hex number padded with zeros to at least 4 characters
6497 %X hex number using upper case letters
6498 %o octal number
6499 %08b binary number padded with zeros to at least 8 chars
6500 %f floating point number as 12.23, inf, -inf or nan
6501 %F floating point number as 12.23, INF, -INF or NAN
6502 %e floating point number as 1.23e3, inf, -inf or nan
6503 %E floating point number as 1.23E3, INF, -INF or NAN
6504 %g floating point number, as %f or %e depending on value
6505 %G floating point number, as %F or %E depending on value
6506 %% the % character itself
6507
6508 Conversion specifications start with '%' and end with the
6509 conversion type. All other characters are copied unchanged to
6510 the result.
6511
6512 The "%" starts a conversion specification. The following
6513 arguments appear in sequence:
6514
6515 % [flags] [field-width] [.precision] type
6516
6517 flags
6518 Zero or more of the following flags:
6519
6520 # The value should be converted to an "alternate
6521 form". For c, d, and s conversions, this option
6522 has no effect. For o conversions, the precision
6523 of the number is increased to force the first
6524 character of the output string to a zero (except
6525 if a zero value is printed with an explicit
6526 precision of zero).
6527 For b and B conversions, a non-zero result has
6528 the string "0b" (or "0B" for B conversions)
6529 prepended to it.
6530 For x and X conversions, a non-zero result has
6531 the string "0x" (or "0X" for X conversions)
6532 prepended to it.
6533
6534 0 (zero) Zero padding. For all conversions the converted
6535 value is padded on the left with zeros rather
6536 than blanks. If a precision is given with a
6537 numeric conversion (d, b, B, o, x, and X), the 0
6538 flag is ignored.
6539
6540 - A negative field width flag; the converted value
6541 is to be left adjusted on the field boundary.
6542 The converted value is padded on the right with
6543 blanks, rather than on the left with blanks or
6544 zeros. A - overrides a 0 if both are given.
6545
6546 ' ' (space) A blank should be left before a positive
6547 number produced by a signed conversion (d).
6548
6549 + A sign must always be placed before a number
6550 produced by a signed conversion. A + overrides
6551 a space if both are used.
6552
6553 field-width
6554 An optional decimal digit string specifying a minimum
6555 field width. If the converted value has fewer bytes
6556 than the field width, it will be padded with spaces on
6557 the left (or right, if the left-adjustment flag has
6558 been given) to fill out the field width. For the S
6559 conversion the count is in cells.
6560
6561 .precision
6562 An optional precision, in the form of a period '.'
6563 followed by an optional digit string. If the digit
6564 string is omitted, the precision is taken as zero.
6565 This gives the minimum number of digits to appear for
6566 d, o, x, and X conversions, the maximum number of
6567 bytes to be printed from a string for s conversions,
6568 or the maximum number of cells to be printed from a
6569 string for S conversions.
6570 For floating point it is the number of digits after
6571 the decimal point.
6572
6573 type
6574 A character that specifies the type of conversion to
6575 be applied, see below.
6576
6577 A field width or precision, or both, may be indicated by an
6578 asterisk '*' instead of a digit string. In this case, a
6579 Number argument supplies the field width or precision. A
6580 negative field width is treated as a left adjustment flag
6581 followed by a positive field width; a negative precision is
6582 treated as though it were missing. Example: >
6583 :echo printf("%d: %.*s", nr, width, line)
6584< This limits the length of the text used from "line" to
6585 "width" bytes.
6586
6587 The conversion specifiers and their meanings are:
6588
6589 *printf-d* *printf-b* *printf-B* *printf-o*
6590 *printf-x* *printf-X*
6591 dbBoxX The Number argument is converted to signed decimal
6592 (d), unsigned binary (b and B), unsigned octal (o), or
6593 unsigned hexadecimal (x and X) notation. The letters
6594 "abcdef" are used for x conversions; the letters
6595 "ABCDEF" are used for X conversions.
6596 The precision, if any, gives the minimum number of
6597 digits that must appear; if the converted value
6598 requires fewer digits, it is padded on the left with
6599 zeros.
6600 In no case does a non-existent or small field width
6601 cause truncation of a numeric field; if the result of
6602 a conversion is wider than the field width, the field
6603 is expanded to contain the conversion result.
6604 The 'h' modifier indicates the argument is 16 bits.
6605 The 'l' modifier indicates the argument is 32 bits.
6606 The 'L' modifier indicates the argument is 64 bits.
6607 Generally, these modifiers are not useful. They are
6608 ignored when type is known from the argument.
6609
6610 i alias for d
6611 D alias for ld
6612 U alias for lu
6613 O alias for lo
6614
6615 *printf-c*
6616 c The Number argument is converted to a byte, and the
6617 resulting character is written.
6618
6619 *printf-s*
6620 s The text of the String argument is used. If a
6621 precision is specified, no more bytes than the number
6622 specified are used.
6623 If the argument is not a String type, it is
6624 automatically converted to text with the same format
6625 as ":echo".
6626 *printf-S*
6627 S The text of the String argument is used. If a
6628 precision is specified, no more display cells than the
6629 number specified are used.
6630
6631 *printf-f* *E807*
6632 f F The Float argument is converted into a string of the
6633 form 123.456. The precision specifies the number of
6634 digits after the decimal point. When the precision is
6635 zero the decimal point is omitted. When the precision
6636 is not specified 6 is used. A really big number
6637 (out of range or dividing by zero) results in "inf"
6638 or "-inf" with %f (INF or -INF with %F).
6639 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
6640 Example: >
6641 echo printf("%.2f", 12.115)
6642< 12.12
6643 Note that roundoff depends on the system libraries.
6644 Use |round()| when in doubt.
6645
6646 *printf-e* *printf-E*
6647 e E The Float argument is converted into a string of the
6648 form 1.234e+03 or 1.234E+03 when using 'E'. The
6649 precision specifies the number of digits after the
6650 decimal point, like with 'f'.
6651
6652 *printf-g* *printf-G*
6653 g G The Float argument is converted like with 'f' if the
6654 value is between 0.001 (inclusive) and 10000000.0
6655 (exclusive). Otherwise 'e' is used for 'g' and 'E'
6656 for 'G'. When no precision is specified superfluous
6657 zeroes and '+' signs are removed, except for the zero
6658 immediately after the decimal point. Thus 10000000.0
6659 results in 1.0e7.
6660
6661 *printf-%*
6662 % A '%' is written. No argument is converted. The
6663 complete conversion specification is "%%".
6664
6665 When a Number argument is expected a String argument is also
6666 accepted and automatically converted.
6667 When a Float or String argument is expected a Number argument
6668 is also accepted and automatically converted.
6669 Any other argument type results in an error message.
6670
6671 *E766* *E767*
6672 The number of {exprN} arguments must exactly match the number
6673 of "%" items. If there are not sufficient or too many
6674 arguments an error is given. Up to 18 arguments can be used.
6675
6676
6677prompt_getprompt({buf}) *prompt_getprompt()*
6678 Returns the effective prompt text for buffer {buf}. {buf} can
6679 be a buffer name or number. See |prompt-buffer|.
6680
6681 If the buffer doesn't exist or isn't a prompt buffer, an empty
6682 string is returned.
6683
6684 Can also be used as a |method|: >
6685 GetBuffer()->prompt_getprompt()
6686
6687< {only available when compiled with the |+channel| feature}
6688
6689
6690prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
6691 Set prompt callback for buffer {buf} to {expr}. When {expr}
6692 is an empty string the callback is removed. This has only
6693 effect if {buf} has 'buftype' set to "prompt".
6694
6695 The callback is invoked when pressing Enter. The current
6696 buffer will always be the prompt buffer. A new line for a
6697 prompt is added before invoking the callback, thus the prompt
6698 for which the callback was invoked will be in the last but one
6699 line.
6700 If the callback wants to add text to the buffer, it must
6701 insert it above the last line, since that is where the current
6702 prompt is. This can also be done asynchronously.
6703 The callback is invoked with one argument, which is the text
6704 that was entered at the prompt. This can be an empty string
6705 if the user only typed Enter.
6706 Example: >
6707 call prompt_setcallback(bufnr(), function('s:TextEntered'))
6708 func s:TextEntered(text)
6709 if a:text == 'exit' || a:text == 'quit'
6710 stopinsert
6711 close
6712 else
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006713 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006714 " Reset 'modified' to allow the buffer to be closed.
6715 set nomodified
6716 endif
6717 endfunc
6718
6719< Can also be used as a |method|: >
6720 GetBuffer()->prompt_setcallback(callback)
6721
6722< {only available when compiled with the |+channel| feature}
6723
6724prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
6725 Set a callback for buffer {buf} to {expr}. When {expr} is an
6726 empty string the callback is removed. This has only effect if
6727 {buf} has 'buftype' set to "prompt".
6728
6729 This callback will be invoked when pressing CTRL-C in Insert
6730 mode. Without setting a callback Vim will exit Insert mode,
6731 as in any buffer.
6732
6733 Can also be used as a |method|: >
6734 GetBuffer()->prompt_setinterrupt(callback)
6735
6736< {only available when compiled with the |+channel| feature}
6737
6738prompt_setprompt({buf}, {text}) *prompt_setprompt()*
6739 Set prompt for buffer {buf} to {text}. You most likely want
6740 {text} to end in a space.
6741 The result is only visible if {buf} has 'buftype' set to
6742 "prompt". Example: >
6743 call prompt_setprompt(bufnr(), 'command: ')
6744<
6745 Can also be used as a |method|: >
6746 GetBuffer()->prompt_setprompt('command: ')
6747
6748< {only available when compiled with the |+channel| feature}
6749
6750prop_ functions are documented here: |text-prop-functions|
6751
6752pum_getpos() *pum_getpos()*
6753 If the popup menu (see |ins-completion-menu|) is not visible,
6754 returns an empty |Dictionary|, otherwise, returns a
6755 |Dictionary| with the following keys:
6756 height nr of items visible
6757 width screen cells
6758 row top screen row (0 first row)
6759 col leftmost screen column (0 first col)
6760 size total nr of items
6761 scrollbar |TRUE| if scrollbar is visible
6762
6763 The values are the same as in |v:event| during
6764 |CompleteChanged|.
6765
6766pumvisible() *pumvisible()*
6767 Returns non-zero when the popup menu is visible, zero
6768 otherwise. See |ins-completion-menu|.
6769 This can be used to avoid some things that would remove the
6770 popup menu.
6771
6772py3eval({expr}) *py3eval()*
6773 Evaluate Python expression {expr} and return its result
6774 converted to Vim data structures.
6775 Numbers and strings are returned as they are (strings are
6776 copied though, Unicode strings are additionally converted to
6777 'encoding').
6778 Lists are represented as Vim |List| type.
6779 Dictionaries are represented as Vim |Dictionary| type with
6780 keys converted to strings.
6781 Note that in a `:def` function local variables are not visible
6782 to {expr}.
6783
6784 Can also be used as a |method|: >
6785 GetExpr()->py3eval()
6786
6787< {only available when compiled with the |+python3| feature}
6788
6789 *E858* *E859*
6790pyeval({expr}) *pyeval()*
6791 Evaluate Python expression {expr} and return its result
6792 converted to Vim data structures.
6793 Numbers and strings are returned as they are (strings are
6794 copied though).
6795 Lists are represented as Vim |List| type.
6796 Dictionaries are represented as Vim |Dictionary| type,
6797 non-string keys result in error.
6798 Note that in a `:def` function local variables are not visible
6799 to {expr}.
6800
6801 Can also be used as a |method|: >
6802 GetExpr()->pyeval()
6803
6804< {only available when compiled with the |+python| feature}
6805
6806pyxeval({expr}) *pyxeval()*
6807 Evaluate Python expression {expr} and return its result
6808 converted to Vim data structures.
6809 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
6810 See also: |pyeval()|, |py3eval()|
6811
6812 Can also be used as a |method|: >
6813 GetExpr()->pyxeval()
6814
6815< {only available when compiled with the |+python| or the
6816 |+python3| feature}
6817
6818rand([{expr}]) *rand()* *random*
6819 Return a pseudo-random Number generated with an xoshiro128**
6820 algorithm using seed {expr}. The returned number is 32 bits,
6821 also on 64 bits systems, for consistency.
6822 {expr} can be initialized by |srand()| and will be updated by
6823 rand(). If {expr} is omitted, an internal seed value is used
6824 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006825 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006826
6827 Examples: >
6828 :echo rand()
6829 :let seed = srand()
6830 :echo rand(seed)
6831 :echo rand(seed) % 16 " random number 0 - 15
6832<
6833
6834 *E726* *E727*
6835range({expr} [, {max} [, {stride}]]) *range()*
6836 Returns a |List| with Numbers:
6837 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
6838 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
6839 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
6840 {max}] (increasing {expr} with {stride} each time, not
6841 producing a value past {max}).
6842 When the maximum is one before the start the result is an
6843 empty list. When the maximum is more than one before the
6844 start this is an error.
6845 Examples: >
6846 range(4) " [0, 1, 2, 3]
6847 range(2, 4) " [2, 3, 4]
6848 range(2, 9, 3) " [2, 5, 8]
6849 range(2, -2, -1) " [2, 1, 0, -1, -2]
6850 range(0) " []
6851 range(2, 0) " error!
6852<
6853 Can also be used as a |method|: >
6854 GetExpr()->range()
6855<
6856
K.Takata11df3ae2022-10-19 14:02:40 +01006857readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006858 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01006859 If {offset} is specified, read the file from the specified
6860 offset. If it is a negative value, it is used as an offset
6861 from the end of the file. E.g., to read the last 12 bytes: >
6862 readblob('file.bin', -12)
6863< If {size} is specified, only the specified size will be read.
6864 E.g. to read the first 100 bytes of a file: >
6865 readblob('file.bin', 0, 100)
6866< If {size} is -1 or omitted, the whole data starting from
6867 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01006868 This can be also used to read the data from a character device
6869 on Unix when {size} is explicitly set. Only if the device
6870 supports seeking {offset} can be used. Otherwise it should be
6871 zero. E.g. to read 10 bytes from a serial console: >
6872 readblob('/dev/ttyS0', 0, 10)
6873< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006874 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01006875 When the offset is beyond the end of the file the result is an
6876 empty blob.
6877 When trying to read more bytes than are available the result
6878 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006879 Also see |readfile()| and |writefile()|.
6880
6881
6882readdir({directory} [, {expr} [, {dict}]]) *readdir()*
6883 Return a list with file and directory names in {directory}.
6884 You can also use |glob()| if you don't need to do complicated
6885 things, such as limiting the number of matches.
6886 The list will be sorted (case sensitive), see the {dict}
6887 argument below for changing the sort order.
6888
6889 When {expr} is omitted all entries are included.
6890 When {expr} is given, it is evaluated to check what to do:
6891 If {expr} results in -1 then no further entries will
6892 be handled.
6893 If {expr} results in 0 then this entry will not be
6894 added to the list.
6895 If {expr} results in 1 then this entry will be added
6896 to the list.
6897 The entries "." and ".." are always excluded.
6898 Each time {expr} is evaluated |v:val| is set to the entry name.
6899 When {expr} is a function the name is passed as the argument.
6900 For example, to get a list of files ending in ".txt": >
6901 readdir(dirname, {n -> n =~ '.txt$'})
6902< To skip hidden and backup files: >
6903 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00006904< *E857*
6905 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006906 values. Currently this is used to specify if and how sorting
6907 should be performed. The dict can have the following members:
6908
6909 sort How to sort the result returned from the system.
6910 Valid values are:
6911 "none" do not sort (fastest method)
6912 "case" sort case sensitive (byte value of
6913 each character, technically, using
6914 strcmp()) (default)
6915 "icase" sort case insensitive (technically
6916 using strcasecmp())
6917 "collate" sort using the collation order
6918 of the "POSIX" or "C" |locale|
6919 (technically using strcoll())
6920 Other values are silently ignored.
6921
6922 For example, to get a list of all files in the current
6923 directory without sorting the individual entries: >
6924 readdir('.', '1', #{sort: 'none'})
6925< If you want to get a directory tree: >
6926 function! s:tree(dir)
6927 return {a:dir : map(readdir(a:dir),
6928 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006929 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006930 endfunction
6931 echo s:tree(".")
6932<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006933 Returns an empty List on error.
6934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006935 Can also be used as a |method|: >
6936 GetDirName()->readdir()
6937<
6938readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
6939 Extended version of |readdir()|.
6940 Return a list of Dictionaries with file and directory
6941 information in {directory}.
6942 This is useful if you want to get the attributes of file and
6943 directory at the same time as getting a list of a directory.
6944 This is much faster than calling |readdir()| then calling
6945 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
6946 each file and directory especially on MS-Windows.
6947 The list will by default be sorted by name (case sensitive),
6948 the sorting can be changed by using the optional {dict}
6949 argument, see |readdir()|.
6950
6951 The Dictionary for file and directory information has the
6952 following items:
6953 group Group name of the entry. (Only on Unix)
6954 name Name of the entry.
6955 perm Permissions of the entry. See |getfperm()|.
6956 size Size of the entry. See |getfsize()|.
6957 time Timestamp of the entry. See |getftime()|.
6958 type Type of the entry.
6959 On Unix, almost same as |getftype()| except:
6960 Symlink to a dir "linkd"
6961 Other symlink "link"
6962 On MS-Windows:
6963 Normal file "file"
6964 Directory "dir"
6965 Junction "junction"
6966 Symlink to a dir "linkd"
6967 Other symlink "link"
6968 Other reparse point "reparse"
6969 user User name of the entry's owner. (Only on Unix)
6970 On Unix, if the entry is a symlink, the Dictionary includes
6971 the information of the target (except the "type" item).
6972 On MS-Windows, it includes the information of the symlink
6973 itself because of performance reasons.
6974
6975 When {expr} is omitted all entries are included.
6976 When {expr} is given, it is evaluated to check what to do:
6977 If {expr} results in -1 then no further entries will
6978 be handled.
6979 If {expr} results in 0 then this entry will not be
6980 added to the list.
6981 If {expr} results in 1 then this entry will be added
6982 to the list.
6983 The entries "." and ".." are always excluded.
6984 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
6985 of the entry.
6986 When {expr} is a function the entry is passed as the argument.
6987 For example, to get a list of files ending in ".txt": >
6988 readdirex(dirname, {e -> e.name =~ '.txt$'})
6989<
6990 For example, to get a list of all files in the current
6991 directory without sorting the individual entries: >
6992 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006993<
6994 Can also be used as a |method|: >
6995 GetDirName()->readdirex()
6996<
6997
6998 *readfile()*
6999readfile({fname} [, {type} [, {max}]])
7000 Read file {fname} and return a |List|, each line of the file
7001 as an item. Lines are broken at NL characters. Macintosh
7002 files separated with CR will result in a single long line
7003 (unless a NL appears somewhere).
7004 All NUL characters are replaced with a NL character.
7005 When {type} contains "b" binary mode is used:
7006 - When the last line ends in a NL an extra empty list item is
7007 added.
7008 - No CR characters are removed.
7009 Otherwise:
7010 - CR characters that appear before a NL are removed.
7011 - Whether the last line ends in a NL or not does not matter.
7012 - When 'encoding' is Unicode any UTF-8 byte order mark is
7013 removed from the text.
7014 When {max} is given this specifies the maximum number of lines
7015 to be read. Useful if you only want to check the first ten
7016 lines of a file: >
7017 :for line in readfile(fname, '', 10)
7018 : if line =~ 'Date' | echo line | endif
7019 :endfor
7020< When {max} is negative -{max} lines from the end of the file
7021 are returned, or as many as there are.
7022 When {max} is zero the result is an empty list.
7023 Note that without {max} the whole file is read into memory.
7024 Also note that there is no recognition of encoding. Read a
7025 file into a buffer if you need to.
7026 Deprecated (use |readblob()| instead): When {type} contains
7027 "B" a |Blob| is returned with the binary data of the file
7028 unmodified.
7029 When the file can't be opened an error message is given and
7030 the result is an empty list.
7031 Also see |writefile()|.
7032
7033 Can also be used as a |method|: >
7034 GetFileName()->readfile()
7035
7036reduce({object}, {func} [, {initial}]) *reduce()* *E998*
7037 {func} is called for every item in {object}, which can be a
7038 |String|, |List| or a |Blob|. {func} is called with two
7039 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007040 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007041
7042 {initial} is the initial result. When omitted, the first item
7043 in {object} is used and {func} is first called for the second
7044 item. If {initial} is not given and {object} is empty no
7045 result can be computed, an E998 error is given.
7046
7047 Examples: >
7048 echo reduce([1, 3, 5], { acc, val -> acc + val })
7049 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
7050 echo reduce(0z1122, { acc, val -> 2 * acc + val })
7051 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
7052<
7053 Can also be used as a |method|: >
7054 echo mylist->reduce({ acc, val -> acc + val }, 0)
7055
7056
7057reg_executing() *reg_executing()*
7058 Returns the single letter name of the register being executed.
7059 Returns an empty string when no register is being executed.
7060 See |@|.
7061
7062reg_recording() *reg_recording()*
7063 Returns the single letter name of the register being recorded.
7064 Returns an empty string when not recording. See |q|.
7065
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007066reltime()
7067reltime({start})
7068reltime({start}, {end}) *reltime()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007069 Return an item that represents a time value. The item is a
7070 list with items that depend on the system. In Vim 9 script
7071 list<any> can be used.
7072 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007073 string or |reltimefloat()| to convert to a Float. For
7074 example, to see the time spent in function Work(): >
7075 var startTime = reltime()
7076 Work()
7077 echo startTime->reltime()->reltimestr()
7078<
Bram Moolenaar016188f2022-06-06 20:52:59 +01007079 Without an argument reltime() returns the current time (the
Bram Moolenaareb490412022-06-28 13:44:46 +01007080 representation is system-dependent, it can not be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01007081 wall-clock time, see |localtime()| for that).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007082 With one argument is returns the time passed since the time
7083 specified in the argument.
7084 With two arguments it returns the time passed between {start}
7085 and {end}.
7086
7087 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007088 reltime(). If there is an error an empty List is returned in
7089 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007090
7091 Can also be used as a |method|: >
7092 GetStart()->reltime()
7093<
7094 {only available when compiled with the |+reltime| feature}
7095
7096reltimefloat({time}) *reltimefloat()*
7097 Return a Float that represents the time value of {time}.
7098 Example: >
7099 let start = reltime()
7100 call MyFunction()
7101 let seconds = reltimefloat(reltime(start))
7102< See the note of reltimestr() about overhead.
7103 Also see |profiling|.
7104 If there is an error 0.0 is returned in legacy script, in Vim9
7105 script an error is given.
7106
7107 Can also be used as a |method|: >
7108 reltime(start)->reltimefloat()
7109
7110< {only available when compiled with the |+reltime| feature}
7111
7112reltimestr({time}) *reltimestr()*
7113 Return a String that represents the time value of {time}.
7114 This is the number of seconds, a dot and the number of
7115 microseconds. Example: >
7116 let start = reltime()
7117 call MyFunction()
7118 echo reltimestr(reltime(start))
7119< Note that overhead for the commands will be added to the time.
7120 The accuracy depends on the system.
7121 Leading spaces are used to make the string align nicely. You
7122 can use split() to remove it. >
7123 echo split(reltimestr(reltime(start)))[0]
7124< Also see |profiling|.
7125 If there is an error an empty string is returned in legacy
7126 script, in Vim9 script an error is given.
7127
7128 Can also be used as a |method|: >
7129 reltime(start)->reltimestr()
7130
7131< {only available when compiled with the |+reltime| feature}
7132
7133 *remote_expr()* *E449*
7134remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007135 Send the {string} to {server}. The {server} argument is a
7136 string, also see |{server}|.
7137
7138 The string is sent as an expression and the result is returned
7139 after evaluation. The result must be a String or a |List|. A
7140 |List| is turned into a String by joining the items with a
7141 line break in between (not at the end), like with join(expr,
7142 "\n").
7143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007144 If {idvar} is present and not empty, it is taken as the name
7145 of a variable and a {serverid} for later use with
7146 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007147
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007148 If {timeout} is given the read times out after this many
7149 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007151 See also |clientserver| |RemoteReply|.
7152 This function is not available in the |sandbox|.
7153 {only available when compiled with the |+clientserver| feature}
7154 Note: Any errors will cause a local error message to be issued
7155 and the result will be the empty string.
7156
7157 Variables will be evaluated in the global namespace,
7158 independent of a function currently being active. Except
7159 when in debug mode, then local function variables and
7160 arguments can be evaluated.
7161
7162 Examples: >
7163 :echo remote_expr("gvim", "2+2")
7164 :echo remote_expr("gvim1", "b:current_syntax")
7165<
7166 Can also be used as a |method|: >
7167 ServerName()->remote_expr(expr)
7168
7169remote_foreground({server}) *remote_foreground()*
7170 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007171 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007172 This works like: >
7173 remote_expr({server}, "foreground()")
7174< Except that on Win32 systems the client does the work, to work
7175 around the problem that the OS doesn't always allow the server
7176 to bring itself to the foreground.
7177 Note: This does not restore the window if it was minimized,
7178 like foreground() does.
7179 This function is not available in the |sandbox|.
7180
7181 Can also be used as a |method|: >
7182 ServerName()->remote_foreground()
7183
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007184< {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007185 Win32 console version}
7186
7187
7188remote_peek({serverid} [, {retvar}]) *remote_peek()*
7189 Returns a positive number if there are available strings
7190 from {serverid}. Copies any reply string into the variable
7191 {retvar} if specified. {retvar} must be a string with the
7192 name of a variable.
7193 Returns zero if none are available.
7194 Returns -1 if something is wrong.
7195 See also |clientserver|.
7196 This function is not available in the |sandbox|.
7197 {only available when compiled with the |+clientserver| feature}
7198 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007199 :let repl = ""
7200 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007201
7202< Can also be used as a |method|: >
7203 ServerId()->remote_peek()
7204
7205remote_read({serverid}, [{timeout}]) *remote_read()*
7206 Return the oldest available reply from {serverid} and consume
7207 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007208 reply is available. Returns an empty string, if a reply is
7209 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007210 See also |clientserver|.
7211 This function is not available in the |sandbox|.
7212 {only available when compiled with the |+clientserver| feature}
7213 Example: >
7214 :echo remote_read(id)
7215
7216< Can also be used as a |method|: >
7217 ServerId()->remote_read()
7218<
7219 *remote_send()* *E241*
7220remote_send({server}, {string} [, {idvar}])
Bram Moolenaar944697a2022-02-20 19:48:20 +00007221 Send the {string} to {server}. The {server} argument is a
7222 string, also see |{server}|.
7223
7224 The string is sent as input keys and the function returns
7225 immediately. At the Vim server the keys are not mapped
7226 |:map|.
7227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007228 If {idvar} is present, it is taken as the name of a variable
7229 and a {serverid} for later use with remote_read() is stored
7230 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007232 See also |clientserver| |RemoteReply|.
7233 This function is not available in the |sandbox|.
7234 {only available when compiled with the |+clientserver| feature}
7235
7236 Note: Any errors will be reported in the server and may mess
7237 up the display.
7238 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007239 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007240 \ remote_read(serverid)
7241
7242 :autocmd NONE RemoteReply *
7243 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007244 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007245 \ 'server2client(expand("<client>"), "HELLO")<CR>')
7246<
7247 Can also be used as a |method|: >
7248 ServerName()->remote_send(keys)
7249<
7250 *remote_startserver()* *E941* *E942*
7251remote_startserver({name})
7252 Become the server {name}. This fails if already running as a
7253 server, when |v:servername| is not empty.
7254
7255 Can also be used as a |method|: >
7256 ServerName()->remote_startserver()
7257
7258< {only available when compiled with the |+clientserver| feature}
7259
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007260remove({list}, {idx})
7261remove({list}, {idx}, {end}) *remove()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007262 Without {end}: Remove the item at {idx} from |List| {list} and
7263 return the item.
7264 With {end}: Remove items from {idx} to {end} (inclusive) and
7265 return a |List| with these items. When {idx} points to the same
7266 item as {end} a list with one item is returned. When {end}
7267 points to an item before {idx} this is an error.
7268 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007269 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007270 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007271 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007272 :call remove(mylist, 0, 9)
7273<
7274 Use |delete()| to remove a file.
7275
7276 Can also be used as a |method|: >
7277 mylist->remove(idx)
7278
Bram Moolenaarf269eab2022-10-03 18:04:35 +01007279remove({blob}, {idx})
7280remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007281 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7282 return the byte.
7283 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7284 return a |Blob| with these bytes. When {idx} points to the same
7285 byte as {end} a |Blob| with one byte is returned. When {end}
7286 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007287 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007288 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007289 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007290 :call remove(mylist, 0, 9)
7291
7292remove({dict}, {key})
7293 Remove the entry from {dict} with key {key} and return it.
7294 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007295 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007296< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007297 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007298
7299rename({from}, {to}) *rename()*
7300 Rename the file by the name {from} to the name {to}. This
7301 should also work to move files across file systems. The
7302 result is a Number, which is 0 if the file was renamed
7303 successfully, and non-zero when the renaming failed.
7304 NOTE: If {to} exists it is overwritten without warning.
7305 This function is not available in the |sandbox|.
7306
7307 Can also be used as a |method|: >
7308 GetOldName()->rename(newname)
7309
7310repeat({expr}, {count}) *repeat()*
7311 Repeat {expr} {count} times and return the concatenated
7312 result. Example: >
7313 :let separator = repeat('-', 80)
7314< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01007315 When {expr} is a |List| or a |Blob| the result is {expr}
7316 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007317 :let longlist = repeat(['a', 'b'], 3)
7318< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7319
7320 Can also be used as a |method|: >
7321 mylist->repeat(count)
7322
7323resolve({filename}) *resolve()* *E655*
7324 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7325 returns the path the shortcut points to in a simplified form.
7326 When {filename} is a symbolic link or junction point, return
7327 the full path to the target. If the target of junction is
7328 removed, return {filename}.
7329 On Unix, repeat resolving symbolic links in all path
7330 components of {filename} and return the simplified result.
7331 To cope with link cycles, resolving of symbolic links is
7332 stopped after 100 iterations.
7333 On other systems, return the simplified {filename}.
7334 The simplification step is done as by |simplify()|.
7335 resolve() keeps a leading path component specifying the
7336 current directory (provided the result is still a relative
7337 path name) and also keeps a trailing path separator.
7338
7339 Can also be used as a |method|: >
7340 GetName()->resolve()
7341
7342reverse({object}) *reverse()*
7343 Reverse the order of items in {object} in-place.
7344 {object} can be a |List| or a |Blob|.
7345 Returns {object}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007346 Returns zero if {object} is not a List or a Blob.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007347 If you want an object to remain unmodified make a copy first: >
7348 :let revlist = reverse(copy(mylist))
7349< Can also be used as a |method|: >
7350 mylist->reverse()
7351
7352round({expr}) *round()*
7353 Round off {expr} to the nearest integral value and return it
7354 as a |Float|. If {expr} lies halfway between two integral
7355 values, then use the larger one (away from zero).
7356 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007357 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007358 Examples: >
7359 echo round(0.456)
7360< 0.0 >
7361 echo round(4.5)
7362< 5.0 >
7363 echo round(-4.5)
7364< -5.0
7365
7366 Can also be used as a |method|: >
7367 Compute()->round()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007368
7369rubyeval({expr}) *rubyeval()*
7370 Evaluate Ruby expression {expr} and return its result
7371 converted to Vim data structures.
7372 Numbers, floats and strings are returned as they are (strings
7373 are copied though).
7374 Arrays are represented as Vim |List| type.
7375 Hashes are represented as Vim |Dictionary| type.
7376 Other objects are represented as strings resulted from their
7377 "Object#to_s" method.
7378 Note that in a `:def` function local variables are not visible
7379 to {expr}.
7380
7381 Can also be used as a |method|: >
7382 GetRubyExpr()->rubyeval()
7383
7384< {only available when compiled with the |+ruby| feature}
7385
7386screenattr({row}, {col}) *screenattr()*
7387 Like |screenchar()|, but return the attribute. This is a rather
7388 arbitrary number that can only be used to compare to the
7389 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007390 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007391
7392 Can also be used as a |method|: >
7393 GetRow()->screenattr(col)
7394
7395screenchar({row}, {col}) *screenchar()*
7396 The result is a Number, which is the character at position
7397 [row, col] on the screen. This works for every possible
7398 screen position, also status lines, window separators and the
7399 command line. The top left position is row one, column one
7400 The character excludes composing characters. For double-byte
7401 encodings it may only be the first byte.
7402 This is mainly to be used for testing.
7403 Returns -1 when row or col is out of range.
7404
7405 Can also be used as a |method|: >
7406 GetRow()->screenchar(col)
7407
7408screenchars({row}, {col}) *screenchars()*
7409 The result is a |List| of Numbers. The first number is the same
7410 as what |screenchar()| returns. Further numbers are
7411 composing characters on top of the base character.
7412 This is mainly to be used for testing.
7413 Returns an empty List when row or col is out of range.
7414
7415 Can also be used as a |method|: >
7416 GetRow()->screenchars(col)
7417
7418screencol() *screencol()*
7419 The result is a Number, which is the current screen column of
7420 the cursor. The leftmost column has number 1.
7421 This function is mainly used for testing.
7422
7423 Note: Always returns the current screen column, thus if used
7424 in a command (e.g. ":echo screencol()") it will return the
7425 column inside the command line, which is 1 when the command is
7426 executed. To get the cursor position in the file use one of
7427 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007428 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007429 nnoremap <silent> GG :echom screencol()<CR>
7430 nnoremap GG <Cmd>echom screencol()<CR>
7431<
7432screenpos({winid}, {lnum}, {col}) *screenpos()*
7433 The result is a Dict with the screen position of the text
7434 character in window {winid} at buffer line {lnum} and column
7435 {col}. {col} is a one-based byte index.
7436 The Dict has these members:
7437 row screen row
7438 col first screen column
7439 endcol last screen column
7440 curscol cursor screen column
7441 If the specified position is not visible, all values are zero.
7442 The "endcol" value differs from "col" when the character
7443 occupies more than one screen cell. E.g. for a Tab "col" can
7444 be 1 and "endcol" can be 8.
7445 The "curscol" value is where the cursor would be placed. For
7446 a Tab it would be the same as "endcol", while for a double
7447 width character it would be the same as "col".
7448 The |conceal| feature is ignored here, the column numbers are
7449 as if 'conceallevel' is zero. You can set the cursor to the
7450 right position and use |screencol()| to get the value with
7451 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00007452 If the position is in a closed fold the screen position of the
7453 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007454 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007455
7456 Can also be used as a |method|: >
7457 GetWinid()->screenpos(lnum, col)
7458
7459screenrow() *screenrow()*
7460 The result is a Number, which is the current screen row of the
7461 cursor. The top line has number one.
7462 This function is mainly used for testing.
7463 Alternatively you can use |winline()|.
7464
7465 Note: Same restrictions as with |screencol()|.
7466
7467screenstring({row}, {col}) *screenstring()*
7468 The result is a String that contains the base character and
7469 any composing characters at position [row, col] on the screen.
7470 This is like |screenchars()| but returning a String with the
7471 characters.
7472 This is mainly to be used for testing.
7473 Returns an empty String when row or col is out of range.
7474
7475 Can also be used as a |method|: >
7476 GetRow()->screenstring(col)
7477<
7478 *search()*
7479search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7480 Search for regexp pattern {pattern}. The search starts at the
7481 cursor position (you can use |cursor()| to set it).
7482
7483 When a match has been found its line number is returned.
7484 If there is no match a 0 is returned and the cursor doesn't
7485 move. No error message is given.
7486
7487 {flags} is a String, which can contain these character flags:
7488 'b' search Backward instead of forward
7489 'c' accept a match at the Cursor position
7490 'e' move to the End of the match
7491 'n' do Not move the cursor
7492 'p' return number of matching sub-Pattern (see below)
7493 's' Set the ' mark at the previous location of the cursor
7494 'w' Wrap around the end of the file
7495 'W' don't Wrap around the end of the file
7496 'z' start searching at the cursor column instead of zero
7497 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
7498
7499 If the 's' flag is supplied, the ' mark is set, only if the
7500 cursor is moved. The 's' flag cannot be combined with the 'n'
7501 flag.
7502
7503 'ignorecase', 'smartcase' and 'magic' are used.
7504
7505 When the 'z' flag is not given, forward searching always
7506 starts in column zero and then matches before the cursor are
7507 skipped. When the 'c' flag is present in 'cpo' the next
7508 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01007509 search starts one column after the start of the match. This
7510 matters for overlapping matches. See |cpo-c|. You can also
7511 insert "\ze" to change where the match ends, see |/\ze|.
7512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007513 When searching backwards and the 'z' flag is given then the
7514 search starts in column zero, thus no match in the current
7515 line will be found (unless wrapping around the end of the
7516 file).
7517
7518 When the {stopline} argument is given then the search stops
7519 after searching this line. This is useful to restrict the
7520 search to a range of lines. Examples: >
7521 let match = search('(', 'b', line("w0"))
7522 let end = search('END', '', line("w$"))
7523< When {stopline} is used and it is not zero this also implies
7524 that the search does not wrap around the end of the file.
7525 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007526 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007527 When the {timeout} argument is given the search stops when
7528 more than this many milliseconds have passed. Thus when
7529 {timeout} is 500 the search stops after half a second.
7530 The value must not be negative. A zero value is like not
7531 giving the argument.
7532 {only available when compiled with the |+reltime| feature}
7533
7534 If the {skip} expression is given it is evaluated with the
7535 cursor positioned on the start of a match. If it evaluates to
7536 non-zero this match is skipped. This can be used, for
7537 example, to skip a match in a comment or a string.
7538 {skip} can be a string, which is evaluated as an expression, a
7539 function reference or a lambda.
7540 When {skip} is omitted or empty, every match is accepted.
7541 When evaluating {skip} causes an error the search is aborted
7542 and -1 returned.
7543 *search()-sub-match*
7544 With the 'p' flag the returned value is one more than the
7545 first sub-match in \(\). One if none of them matched but the
7546 whole pattern did match.
7547 To get the column number too use |searchpos()|.
7548
7549 The cursor will be positioned at the match, unless the 'n'
7550 flag is used.
7551
7552 Example (goes over all files in the argument list): >
7553 :let n = 1
7554 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007555 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007556 : " start at the last char in the file and wrap for the
7557 : " first search to find match at start of file
7558 : normal G$
7559 : let flags = "w"
7560 : while search("foo", flags) > 0
7561 : s/foo/bar/g
7562 : let flags = "W"
7563 : endwhile
7564 : update " write the file if modified
7565 : let n = n + 1
7566 :endwhile
7567<
7568 Example for using some flags: >
7569 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
7570< This will search for the keywords "if", "else", and "endif"
7571 under or after the cursor. Because of the 'p' flag, it
7572 returns 1, 2, or 3 depending on which keyword is found, or 0
7573 if the search fails. With the cursor on the first word of the
7574 line:
7575 if (foo == 0) | let foo = foo + 1 | endif ~
7576 the function returns 1. Without the 'c' flag, the function
7577 finds the "endif" and returns 3. The same thing happens
7578 without the 'e' flag if the cursor is on the "f" of "if".
7579 The 'n' flag tells the function not to move the cursor.
7580
7581 Can also be used as a |method|: >
7582 GetPattern()->search()
7583
7584searchcount([{options}]) *searchcount()*
7585 Get or update the last search count, like what is displayed
7586 without the "S" flag in 'shortmess'. This works even if
7587 'shortmess' does contain the "S" flag.
7588
7589 This returns a |Dictionary|. The dictionary is empty if the
7590 previous pattern was not set and "pattern" was not specified.
7591
7592 key type meaning ~
7593 current |Number| current position of match;
7594 0 if the cursor position is
7595 before the first match
7596 exact_match |Boolean| 1 if "current" is matched on
7597 "pos", otherwise 0
7598 total |Number| total count of matches found
7599 incomplete |Number| 0: search was fully completed
7600 1: recomputing was timed out
7601 2: max count exceeded
7602
7603 For {options} see further down.
7604
7605 To get the last search count when |n| or |N| was pressed, call
7606 this function with `recompute: 0` . This sometimes returns
7607 wrong information because |n| and |N|'s maximum count is 99.
7608 If it exceeded 99 the result must be max count + 1 (100). If
7609 you want to get correct information, specify `recompute: 1`: >
7610
7611 " result == maxcount + 1 (100) when many matches
7612 let result = searchcount(#{recompute: 0})
7613
7614 " Below returns correct result (recompute defaults
7615 " to 1)
7616 let result = searchcount()
7617<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007618 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007619 function! LastSearchCount() abort
7620 let result = searchcount(#{recompute: 0})
7621 if empty(result)
7622 return ''
7623 endif
7624 if result.incomplete ==# 1 " timed out
7625 return printf(' /%s [?/??]', @/)
7626 elseif result.incomplete ==# 2 " max count exceeded
7627 if result.total > result.maxcount &&
7628 \ result.current > result.maxcount
7629 return printf(' /%s [>%d/>%d]', @/,
7630 \ result.current, result.total)
7631 elseif result.total > result.maxcount
7632 return printf(' /%s [%d/>%d]', @/,
7633 \ result.current, result.total)
7634 endif
7635 endif
7636 return printf(' /%s [%d/%d]', @/,
7637 \ result.current, result.total)
7638 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007639 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007640
7641 " Or if you want to show the count only when
7642 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007643 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007644 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
7645<
7646 You can also update the search count, which can be useful in a
7647 |CursorMoved| or |CursorMovedI| autocommand: >
7648
7649 autocmd CursorMoved,CursorMovedI *
7650 \ let s:searchcount_timer = timer_start(
7651 \ 200, function('s:update_searchcount'))
7652 function! s:update_searchcount(timer) abort
7653 if a:timer ==# s:searchcount_timer
7654 call searchcount(#{
7655 \ recompute: 1, maxcount: 0, timeout: 100})
7656 redrawstatus
7657 endif
7658 endfunction
7659<
7660 This can also be used to count matched texts with specified
7661 pattern in the current buffer using "pattern": >
7662
7663 " Count '\<foo\>' in this buffer
7664 " (Note that it also updates search count)
7665 let result = searchcount(#{pattern: '\<foo\>'})
7666
7667 " To restore old search count by old pattern,
7668 " search again
7669 call searchcount()
7670<
7671 {options} must be a |Dictionary|. It can contain:
7672 key type meaning ~
7673 recompute |Boolean| if |TRUE|, recompute the count
7674 like |n| or |N| was executed.
7675 otherwise returns the last
7676 computed result (when |n| or
7677 |N| was used when "S" is not
7678 in 'shortmess', or this
7679 function was called).
7680 (default: |TRUE|)
7681 pattern |String| recompute if this was given
7682 and different with |@/|.
7683 this works as same as the
7684 below command is executed
7685 before calling this function >
7686 let @/ = pattern
7687< (default: |@/|)
7688 timeout |Number| 0 or negative number is no
7689 timeout. timeout milliseconds
7690 for recomputing the result
7691 (default: 0)
7692 maxcount |Number| 0 or negative number is no
7693 limit. max count of matched
7694 text while recomputing the
7695 result. if search exceeded
7696 total count, "total" value
7697 becomes `maxcount + 1`
7698 (default: 99)
7699 pos |List| `[lnum, col, off]` value
7700 when recomputing the result.
7701 this changes "current" result
7702 value. see |cursor()|,
7703 |getpos()|
7704 (default: cursor's position)
7705
7706 Can also be used as a |method|: >
7707 GetSearchOpts()->searchcount()
7708<
7709searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
7710 Search for the declaration of {name}.
7711
7712 With a non-zero {global} argument it works like |gD|, find
7713 first match in the file. Otherwise it works like |gd|, find
7714 first match in the function.
7715
7716 With a non-zero {thisblock} argument matches in a {} block
7717 that ends before the cursor position are ignored. Avoids
7718 finding variable declarations only valid in another scope.
7719
7720 Moves the cursor to the found match.
7721 Returns zero for success, non-zero for failure.
7722 Example: >
7723 if searchdecl('myvar') == 0
7724 echo getline('.')
7725 endif
7726<
7727 Can also be used as a |method|: >
7728 GetName()->searchdecl()
7729<
7730 *searchpair()*
7731searchpair({start}, {middle}, {end} [, {flags} [, {skip}
7732 [, {stopline} [, {timeout}]]]])
7733 Search for the match of a nested start-end pair. This can be
7734 used to find the "endif" that matches an "if", while other
7735 if/endif pairs in between are ignored.
7736 The search starts at the cursor. The default is to search
7737 forward, include 'b' in {flags} to search backward.
7738 If a match is found, the cursor is positioned at it and the
7739 line number is returned. If no match is found 0 or -1 is
7740 returned and the cursor doesn't move. No error message is
7741 given.
7742
7743 {start}, {middle} and {end} are patterns, see |pattern|. They
7744 must not contain \( \) pairs. Use of \%( \) is allowed. When
7745 {middle} is not empty, it is found when searching from either
7746 direction, but only when not in a nested start-end pair. A
7747 typical use is: >
7748 searchpair('\<if\>', '\<else\>', '\<endif\>')
7749< By leaving {middle} empty the "else" is skipped.
7750
7751 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
7752 |search()|. Additionally:
7753 'r' Repeat until no more matches found; will find the
7754 outer pair. Implies the 'W' flag.
7755 'm' Return number of matches instead of line number with
7756 the match; will be > 1 when 'r' is used.
7757 Note: it's nearly always a good idea to use the 'W' flag, to
7758 avoid wrapping around the end of the file.
7759
7760 When a match for {start}, {middle} or {end} is found, the
7761 {skip} expression is evaluated with the cursor positioned on
7762 the start of the match. It should return non-zero if this
7763 match is to be skipped. E.g., because it is inside a comment
7764 or a string.
7765 When {skip} is omitted or empty, every match is accepted.
7766 When evaluating {skip} causes an error the search is aborted
7767 and -1 returned.
7768 {skip} can be a string, a lambda, a funcref or a partial.
7769 Anything else makes the function fail.
7770 In a `:def` function when the {skip} argument is a string
7771 constant it is compiled into instructions.
7772
7773 For {stopline} and {timeout} see |search()|.
7774
7775 The value of 'ignorecase' is used. 'magic' is ignored, the
7776 patterns are used like it's on.
7777
7778 The search starts exactly at the cursor. A match with
7779 {start}, {middle} or {end} at the next character, in the
7780 direction of searching, is the first one found. Example: >
7781 if 1
7782 if 2
7783 endif 2
7784 endif 1
7785< When starting at the "if 2", with the cursor on the "i", and
7786 searching forwards, the "endif 2" is found. When starting on
7787 the character just before the "if 2", the "endif 1" will be
7788 found. That's because the "if 2" will be found first, and
7789 then this is considered to be a nested if/endif from "if 2" to
7790 "endif 2".
7791 When searching backwards and {end} is more than one character,
7792 it may be useful to put "\zs" at the end of the pattern, so
7793 that when the cursor is inside a match with the end it finds
7794 the matching start.
7795
7796 Example, to find the "endif" command in a Vim script: >
7797
7798 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
7799 \ 'getline(".") =~ "^\\s*\""')
7800
7801< The cursor must be at or after the "if" for which a match is
7802 to be found. Note that single-quote strings are used to avoid
7803 having to double the backslashes. The skip expression only
7804 catches comments at the start of a line, not after a command.
7805 Also, a word "en" or "if" halfway a line is considered a
7806 match.
7807 Another example, to search for the matching "{" of a "}": >
7808
7809 :echo searchpair('{', '', '}', 'bW')
7810
7811< This works when the cursor is at or before the "}" for which a
7812 match is to be found. To reject matches that syntax
7813 highlighting recognized as strings: >
7814
7815 :echo searchpair('{', '', '}', 'bW',
7816 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
7817<
7818 *searchpairpos()*
7819searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
7820 [, {stopline} [, {timeout}]]]])
7821 Same as |searchpair()|, but returns a |List| with the line and
7822 column position of the match. The first element of the |List|
7823 is the line number and the second element is the byte index of
7824 the column position of the match. If no match is found,
7825 returns [0, 0]. >
7826
7827 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
7828<
7829 See |match-parens| for a bigger and more useful example.
7830
7831 *searchpos()*
7832searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
7833 Same as |search()|, but returns a |List| with the line and
7834 column position of the match. The first element of the |List|
7835 is the line number and the second element is the byte index of
7836 the column position of the match. If no match is found,
7837 returns [0, 0].
7838 Example: >
7839 :let [lnum, col] = searchpos('mypattern', 'n')
7840
7841< When the 'p' flag is given then there is an extra item with
7842 the sub-pattern match number |search()-sub-match|. Example: >
7843 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
7844< In this example "submatch" is 2 when a lowercase letter is
7845 found |/\l|, 3 when an uppercase letter is found |/\u|.
7846
7847 Can also be used as a |method|: >
7848 GetPattern()->searchpos()
7849
7850server2client({clientid}, {string}) *server2client()*
7851 Send a reply string to {clientid}. The most recent {clientid}
7852 that sent a string can be retrieved with expand("<client>").
7853 {only available when compiled with the |+clientserver| feature}
7854 Returns zero for success, -1 for failure.
7855 Note:
7856 This id has to be stored before the next command can be
7857 received. I.e. before returning from the received command and
7858 before calling any commands that waits for input.
7859 See also |clientserver|.
7860 Example: >
7861 :echo server2client(expand("<client>"), "HELLO")
7862
7863< Can also be used as a |method|: >
7864 GetClientId()->server2client(string)
7865<
7866serverlist() *serverlist()*
7867 Return a list of available server names, one per line.
7868 When there are no servers or the information is not available
7869 an empty string is returned. See also |clientserver|.
7870 {only available when compiled with the |+clientserver| feature}
7871 Example: >
7872 :echo serverlist()
7873<
7874setbufline({buf}, {lnum}, {text}) *setbufline()*
7875 Set line {lnum} to {text} in buffer {buf}. This works like
7876 |setline()| for the specified buffer.
7877
7878 This function works only for loaded buffers. First call
7879 |bufload()| if needed.
7880
7881 To insert lines use |appendbufline()|.
7882 Any text properties in {lnum} are cleared.
7883
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00007884 {text} can be a string to set one line, or a List of strings
7885 to set multiple lines. If the List extends below the last
7886 line then those lines are added. If the List is empty then
7887 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007888
7889 For the use of {buf}, see |bufname()| above.
7890
7891 {lnum} is used like with |setline()|.
7892 Use "$" to refer to the last line in buffer {buf}.
7893 When {lnum} is just below the last line the {text} will be
7894 added below the last line.
7895
7896 When {buf} is not a valid buffer, the buffer is not loaded or
7897 {lnum} is not valid then 1 is returned. In |Vim9| script an
7898 error is given.
7899 On success 0 is returned.
7900
7901 Can also be used as a |method|, the base is passed as the
7902 third argument: >
7903 GetText()->setbufline(buf, lnum)
7904
7905setbufvar({buf}, {varname}, {val}) *setbufvar()*
7906 Set option or local variable {varname} in buffer {buf} to
7907 {val}.
7908 This also works for a global or local window option, but it
7909 doesn't work for a global or local window variable.
7910 For a local window option the global value is unchanged.
7911 For the use of {buf}, see |bufname()| above.
7912 The {varname} argument is a string.
7913 Note that the variable name without "b:" must be used.
7914 Examples: >
7915 :call setbufvar(1, "&mod", 1)
7916 :call setbufvar("todo", "myvar", "foobar")
7917< This function is not available in the |sandbox|.
7918
7919 Can also be used as a |method|, the base is passed as the
7920 third argument: >
7921 GetValue()->setbufvar(buf, varname)
7922
7923
7924setcellwidths({list}) *setcellwidths()*
7925 Specify overrides for cell widths of character ranges. This
7926 tells Vim how wide characters are, counted in screen cells.
7927 This overrides 'ambiwidth'. Example: >
7928 setcellwidths([[0xad, 0xad, 1],
7929 \ [0x2194, 0x2199, 2]])
7930
Bram Moolenaarf10911e2022-01-29 22:20:48 +00007931< *E1109* *E1110* *E1111* *E1112* *E1113* *E1114*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007932 The {list} argument is a list of lists with each three
7933 numbers. These three numbers are [low, high, width]. "low"
7934 and "high" can be the same, in which case this refers to one
7935 character. Otherwise it is the range of characters from "low"
7936 to "high" (inclusive). "width" is either 1 or 2, indicating
7937 the character width in screen cells.
7938 An error is given if the argument is invalid, also when a
7939 range overlaps with another.
7940 Only characters with value 0x100 and higher can be used.
7941
7942 If the new value causes 'fillchars' or 'listchars' to become
7943 invalid it is rejected and an error is given.
7944
7945 To clear the overrides pass an empty list: >
7946 setcellwidths([]);
7947< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
7948 the effect for known emoji characters.
7949
7950setcharpos({expr}, {list}) *setcharpos()*
7951 Same as |setpos()| but uses the specified column number as the
7952 character index instead of the byte index in the line.
7953
7954 Example:
7955 With the text "여보세요" in line 8: >
7956 call setcharpos('.', [0, 8, 4, 0])
7957< positions the cursor on the fourth character '요'. >
7958 call setpos('.', [0, 8, 4, 0])
7959< positions the cursor on the second character '보'.
7960
7961 Can also be used as a |method|: >
7962 GetPosition()->setcharpos('.')
7963
7964setcharsearch({dict}) *setcharsearch()*
7965 Set the current character search information to {dict},
7966 which contains one or more of the following entries:
7967
7968 char character which will be used for a subsequent
7969 |,| or |;| command; an empty string clears the
7970 character search
7971 forward direction of character search; 1 for forward,
7972 0 for backward
7973 until type of character search; 1 for a |t| or |T|
7974 character search, 0 for an |f| or |F|
7975 character search
7976
7977 This can be useful to save/restore a user's character search
7978 from a script: >
7979 :let prevsearch = getcharsearch()
7980 :" Perform a command which clobbers user's search
7981 :call setcharsearch(prevsearch)
7982< Also see |getcharsearch()|.
7983
7984 Can also be used as a |method|: >
7985 SavedSearch()->setcharsearch()
7986
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01007987setcmdline({str} [, {pos}]) *setcmdline()*
7988 Set the command line to {str} and set the cursor position to
7989 {pos}.
7990 If {pos} is omitted, the cursor is positioned after the text.
7991 Returns 0 when successful, 1 when not editing the command
7992 line.
7993
7994 Can also be used as a |method|: >
7995 GetText()->setcmdline()
7996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007997setcmdpos({pos}) *setcmdpos()*
7998 Set the cursor position in the command line to byte position
7999 {pos}. The first position is 1.
8000 Use |getcmdpos()| to obtain the current position.
8001 Only works while editing the command line, thus you must use
8002 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
8003 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
8004 set after the command line is set to the expression. For
8005 |c_CTRL-R_=| it is set after evaluating the expression but
8006 before inserting the resulting text.
8007 When the number is too big the cursor is put at the end of the
8008 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01008009 Returns 0 when successful, 1 when not editing the command
8010 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008011
8012 Can also be used as a |method|: >
8013 GetPos()->setcmdpos()
8014
8015setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
8016setcursorcharpos({list})
8017 Same as |cursor()| but uses the specified column number as the
8018 character index instead of the byte index in the line.
8019
8020 Example:
8021 With the text "여보세요" in line 4: >
8022 call setcursorcharpos(4, 3)
8023< positions the cursor on the third character '세'. >
8024 call cursor(4, 3)
8025< positions the cursor on the first character '여'.
8026
8027 Can also be used as a |method|: >
8028 GetCursorPos()->setcursorcharpos()
8029
8030
8031setenv({name}, {val}) *setenv()*
8032 Set environment variable {name} to {val}. Example: >
8033 call setenv('HOME', '/home/myhome')
8034
8035< When {val} is |v:null| the environment variable is deleted.
8036 See also |expr-env|.
8037
8038 Can also be used as a |method|, the base is passed as the
8039 second argument: >
8040 GetPath()->setenv('PATH')
8041
8042setfperm({fname}, {mode}) *setfperm()* *chmod*
8043 Set the file permissions for {fname} to {mode}.
8044 {mode} must be a string with 9 characters. It is of the form
8045 "rwxrwxrwx", where each group of "rwx" flags represent, in
8046 turn, the permissions of the owner of the file, the group the
8047 file belongs to, and other users. A '-' character means the
8048 permission is off, any other character means on. Multi-byte
8049 characters are not supported.
8050
8051 For example "rw-r-----" means read-write for the user,
8052 readable by the group, not accessible by others. "xx-x-----"
8053 would do the same thing.
8054
8055 Returns non-zero for success, zero for failure.
8056
8057 Can also be used as a |method|: >
8058 GetFilename()->setfperm(mode)
8059<
8060 To read permissions see |getfperm()|.
8061
8062
8063setline({lnum}, {text}) *setline()*
8064 Set line {lnum} of the current buffer to {text}. To insert
8065 lines use |append()|. To set lines in another buffer use
8066 |setbufline()|. Any text properties in {lnum} are cleared.
8067
8068 {lnum} is used like with |getline()|.
8069 When {lnum} is just below the last line the {text} will be
8070 added below the last line.
8071 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00008072 converted to a String. When {text} is an empty List then
8073 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008074
8075 If this succeeds, FALSE is returned. If this fails (most likely
8076 because {lnum} is invalid) TRUE is returned.
8077 In |Vim9| script an error is given if {lnum} is invalid.
8078
8079 Example: >
8080 :call setline(5, strftime("%c"))
8081
8082< When {text} is a |List| then line {lnum} and following lines
8083 will be set to the items in the list. Example: >
8084 :call setline(5, ['aaa', 'bbb', 'ccc'])
8085< This is equivalent to: >
8086 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
8087 : call setline(n, l)
8088 :endfor
8089
8090< Note: The '[ and '] marks are not set.
8091
8092 Can also be used as a |method|, the base is passed as the
8093 second argument: >
8094 GetText()->setline(lnum)
8095
8096setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
8097 Create or replace or add to the location list for window {nr}.
8098 {nr} can be the window number or the |window-ID|.
8099 When {nr} is zero the current window is used.
8100
8101 For a location list window, the displayed location list is
8102 modified. For an invalid window number {nr}, -1 is returned.
8103 Otherwise, same as |setqflist()|.
8104 Also see |location-list|.
8105
8106 For {action} see |setqflist-action|.
8107
8108 If the optional {what} dictionary argument is supplied, then
8109 only the items listed in {what} are set. Refer to |setqflist()|
8110 for the list of supported keys in {what}.
8111
8112 Can also be used as a |method|, the base is passed as the
8113 second argument: >
8114 GetLoclist()->setloclist(winnr)
8115
8116setmatches({list} [, {win}]) *setmatches()*
8117 Restores a list of matches saved by |getmatches()| for the
8118 current window. Returns 0 if successful, otherwise -1. All
8119 current matches are cleared before the list is restored. See
8120 example for |getmatches()|.
8121 If {win} is specified, use the window with this number or
8122 window ID instead of the current window.
8123
8124 Can also be used as a |method|: >
8125 GetMatches()->setmatches()
8126<
8127 *setpos()*
8128setpos({expr}, {list})
8129 Set the position for String {expr}. Possible values:
8130 . the cursor
8131 'x mark x
8132
8133 {list} must be a |List| with four or five numbers:
8134 [bufnum, lnum, col, off]
8135 [bufnum, lnum, col, off, curswant]
8136
8137 "bufnum" is the buffer number. Zero can be used for the
8138 current buffer. When setting an uppercase mark "bufnum" is
8139 used for the mark position. For other marks it specifies the
8140 buffer to set the mark in. You can use the |bufnr()| function
8141 to turn a file name into a buffer number.
8142 For setting the cursor and the ' mark "bufnum" is ignored,
8143 since these are associated with a window, not a buffer.
8144 Does not change the jumplist.
8145
8146 "lnum" and "col" are the position in the buffer. The first
8147 column is 1. Use a zero "lnum" to delete a mark. If "col" is
8148 smaller than 1 then 1 is used. To use the character count
8149 instead of the byte count, use |setcharpos()|.
8150
8151 The "off" number is only used when 'virtualedit' is set. Then
8152 it is the offset in screen columns from the start of the
8153 character. E.g., a position within a <Tab> or after the last
8154 character.
8155
8156 The "curswant" number is only used when setting the cursor
8157 position. It sets the preferred column for when moving the
8158 cursor vertically. When the "curswant" number is missing the
8159 preferred column is not set. When it is present and setting a
8160 mark position it is not used.
8161
8162 Note that for '< and '> changing the line number may result in
8163 the marks to be effectively be swapped, so that '< is always
8164 before '>.
8165
8166 Returns 0 when the position could be set, -1 otherwise.
8167 An error message is given if {expr} is invalid.
8168
8169 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
8170
8171 This does not restore the preferred column for moving
8172 vertically; if you set the cursor position with this, |j| and
8173 |k| motions will jump to previous columns! Use |cursor()| to
8174 also set the preferred column. Also see the "curswant" key in
8175 |winrestview()|.
8176
8177 Can also be used as a |method|: >
8178 GetPosition()->setpos('.')
8179
8180setqflist({list} [, {action} [, {what}]]) *setqflist()*
8181 Create or replace or add to the quickfix list.
8182
8183 If the optional {what} dictionary argument is supplied, then
8184 only the items listed in {what} are set. The first {list}
8185 argument is ignored. See below for the supported items in
8186 {what}.
8187 *setqflist-what*
8188 When {what} is not present, the items in {list} are used. Each
8189 item must be a dictionary. Non-dictionary items in {list} are
8190 ignored. Each dictionary item can contain the following
8191 entries:
8192
8193 bufnr buffer number; must be the number of a valid
8194 buffer
8195 filename name of a file; only used when "bufnr" is not
8196 present or it is invalid.
8197 module name of a module; if given it will be used in
8198 quickfix error window instead of the filename.
8199 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00008200 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008201 pattern search pattern used to locate the error
8202 col column number
8203 vcol when non-zero: "col" is visual column
8204 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00008205 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008206 nr error number
8207 text description of the error
8208 type single-character error type, 'E', 'W', etc.
8209 valid recognized error message
8210
8211 The "col", "vcol", "nr", "type" and "text" entries are
8212 optional. Either "lnum" or "pattern" entry can be used to
8213 locate a matching error line.
8214 If the "filename" and "bufnr" entries are not present or
8215 neither the "lnum" or "pattern" entries are present, then the
8216 item will not be handled as an error line.
8217 If both "pattern" and "lnum" are present then "pattern" will
8218 be used.
8219 If the "valid" entry is not supplied, then the valid flag is
8220 set when "bufnr" is a valid buffer or "filename" exists.
8221 If you supply an empty {list}, the quickfix list will be
8222 cleared.
8223 Note that the list is not exactly the same as what
8224 |getqflist()| returns.
8225
8226 {action} values: *setqflist-action* *E927*
8227 'a' The items from {list} are added to the existing
8228 quickfix list. If there is no existing list, then a
8229 new list is created.
8230
8231 'r' The items from the current quickfix list are replaced
8232 with the items from {list}. This can also be used to
8233 clear the list: >
8234 :call setqflist([], 'r')
8235<
8236 'f' All the quickfix lists in the quickfix stack are
8237 freed.
8238
8239 If {action} is not present or is set to ' ', then a new list
8240 is created. The new quickfix list is added after the current
8241 quickfix list in the stack and all the following lists are
8242 freed. To add a new quickfix list at the end of the stack,
8243 set "nr" in {what} to "$".
8244
8245 The following items can be specified in dictionary {what}:
8246 context quickfix list context. See |quickfix-context|
8247 efm errorformat to use when parsing text from
8248 "lines". If this is not present, then the
8249 'errorformat' option value is used.
8250 See |quickfix-parse|
8251 id quickfix list identifier |quickfix-ID|
8252 idx index of the current entry in the quickfix
8253 list specified by 'id' or 'nr'. If set to '$',
8254 then the last entry in the list is set as the
8255 current entry. See |quickfix-index|
8256 items list of quickfix entries. Same as the {list}
8257 argument.
8258 lines use 'errorformat' to parse a list of lines and
8259 add the resulting entries to the quickfix list
8260 {nr} or {id}. Only a |List| value is supported.
8261 See |quickfix-parse|
8262 nr list number in the quickfix stack; zero
8263 means the current quickfix list and "$" means
8264 the last quickfix list.
8265 quickfixtextfunc
8266 function to get the text to display in the
8267 quickfix window. The value can be the name of
8268 a function or a funcref or a lambda. Refer to
8269 |quickfix-window-function| for an explanation
8270 of how to write the function and an example.
8271 title quickfix list title text. See |quickfix-title|
8272 Unsupported keys in {what} are ignored.
8273 If the "nr" item is not present, then the current quickfix list
8274 is modified. When creating a new quickfix list, "nr" can be
8275 set to a value one greater than the quickfix stack size.
8276 When modifying a quickfix list, to guarantee that the correct
8277 list is modified, "id" should be used instead of "nr" to
8278 specify the list.
8279
8280 Examples (See also |setqflist-examples|): >
8281 :call setqflist([], 'r', {'title': 'My search'})
8282 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
8283 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
8284<
8285 Returns zero for success, -1 for failure.
8286
8287 This function can be used to create a quickfix list
8288 independent of the 'errorformat' setting. Use a command like
8289 `:cc 1` to jump to the first position.
8290
8291 Can also be used as a |method|, the base is passed as the
8292 second argument: >
8293 GetErrorlist()->setqflist()
8294<
8295 *setreg()*
8296setreg({regname}, {value} [, {options}])
8297 Set the register {regname} to {value}.
8298 If {regname} is "" or "@", the unnamed register '"' is used.
8299 The {regname} argument is a string. In |Vim9-script|
8300 {regname} must be one character.
8301
8302 {value} may be any value returned by |getreg()| or
8303 |getreginfo()|, including a |List| or |Dict|.
8304 If {options} contains "a" or {regname} is upper case,
8305 then the value is appended.
8306
8307 {options} can also contain a register type specification:
8308 "c" or "v" |characterwise| mode
8309 "l" or "V" |linewise| mode
8310 "b" or "<CTRL-V>" |blockwise-visual| mode
8311 If a number immediately follows "b" or "<CTRL-V>" then this is
8312 used as the width of the selection - if it is not specified
8313 then the width of the block is set to the number of characters
8314 in the longest line (counting a <Tab> as 1 character).
8315
8316 If {options} contains no register settings, then the default
8317 is to use character mode unless {value} ends in a <NL> for
8318 string {value} and linewise mode for list {value}. Blockwise
8319 mode is never selected automatically.
8320 Returns zero for success, non-zero for failure.
8321
8322 *E883*
8323 Note: you may not use |List| containing more than one item to
8324 set search and expression registers. Lists containing no
8325 items act like empty strings.
8326
8327 Examples: >
8328 :call setreg(v:register, @*)
8329 :call setreg('*', @%, 'ac')
8330 :call setreg('a', "1\n2\n3", 'b5')
8331 :call setreg('"', { 'points_to': 'a'})
8332
8333< This example shows using the functions to save and restore a
8334 register: >
8335 :let var_a = getreginfo()
8336 :call setreg('a', var_a)
8337< or: >
8338 :let var_a = getreg('a', 1, 1)
8339 :let var_amode = getregtype('a')
8340 ....
8341 :call setreg('a', var_a, var_amode)
8342< Note: you may not reliably restore register value
8343 without using the third argument to |getreg()| as without it
8344 newlines are represented as newlines AND Nul bytes are
8345 represented as newlines as well, see |NL-used-for-Nul|.
8346
8347 You can also change the type of a register by appending
8348 nothing: >
8349 :call setreg('a', '', 'al')
8350
8351< Can also be used as a |method|, the base is passed as the
8352 second argument: >
8353 GetText()->setreg('a')
8354
8355settabvar({tabnr}, {varname}, {val}) *settabvar()*
8356 Set tab-local variable {varname} to {val} in tab page {tabnr}.
8357 |t:var|
8358 The {varname} argument is a string.
8359 Note that autocommands are blocked, side effects may not be
8360 triggered, e.g. when setting 'filetype'.
8361 Note that the variable name without "t:" must be used.
8362 Tabs are numbered starting with one.
8363 This function is not available in the |sandbox|.
8364
8365 Can also be used as a |method|, the base is passed as the
8366 third argument: >
8367 GetValue()->settabvar(tab, name)
8368
8369settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
8370 Set option or local variable {varname} in window {winnr} to
8371 {val}.
8372 Tabs are numbered starting with one. For the current tabpage
8373 use |setwinvar()|.
8374 {winnr} can be the window number or the |window-ID|.
8375 When {winnr} is zero the current window is used.
8376 Note that autocommands are blocked, side effects may not be
8377 triggered, e.g. when setting 'filetype' or 'syntax'.
8378 This also works for a global or local buffer option, but it
8379 doesn't work for a global or local buffer variable.
8380 For a local buffer option the global value is unchanged.
8381 Note that the variable name without "w:" must be used.
8382 Examples: >
8383 :call settabwinvar(1, 1, "&list", 0)
8384 :call settabwinvar(3, 2, "myvar", "foobar")
8385< This function is not available in the |sandbox|.
8386
8387 Can also be used as a |method|, the base is passed as the
8388 fourth argument: >
8389 GetValue()->settabwinvar(tab, winnr, name)
8390
8391settagstack({nr}, {dict} [, {action}]) *settagstack()*
8392 Modify the tag stack of the window {nr} using {dict}.
8393 {nr} can be the window number or the |window-ID|.
8394
8395 For a list of supported items in {dict}, refer to
8396 |gettagstack()|. "curidx" takes effect before changing the tag
8397 stack.
8398 *E962*
8399 How the tag stack is modified depends on the {action}
8400 argument:
8401 - If {action} is not present or is set to 'r', then the tag
8402 stack is replaced.
8403 - If {action} is set to 'a', then new entries from {dict} are
8404 pushed (added) onto the tag stack.
8405 - If {action} is set to 't', then all the entries from the
8406 current entry in the tag stack or "curidx" in {dict} are
8407 removed and then new entries are pushed to the stack.
8408
8409 The current index is set to one after the length of the tag
8410 stack after the modification.
8411
8412 Returns zero for success, -1 for failure.
8413
8414 Examples (for more examples see |tagstack-examples|):
8415 Empty the tag stack of window 3: >
8416 call settagstack(3, {'items' : []})
8417
8418< Save and restore the tag stack: >
8419 let stack = gettagstack(1003)
8420 " do something else
8421 call settagstack(1003, stack)
8422 unlet stack
8423<
8424 Can also be used as a |method|, the base is passed as the
8425 second argument: >
8426 GetStack()->settagstack(winnr)
8427
8428setwinvar({winnr}, {varname}, {val}) *setwinvar()*
8429 Like |settabwinvar()| for the current tab page.
8430 Examples: >
8431 :call setwinvar(1, "&list", 0)
8432 :call setwinvar(2, "myvar", "foobar")
8433
8434< Can also be used as a |method|, the base is passed as the
8435 third argument: >
8436 GetValue()->setwinvar(winnr, name)
8437
8438sha256({string}) *sha256()*
8439 Returns a String with 64 hex characters, which is the SHA256
8440 checksum of {string}.
8441
8442 Can also be used as a |method|: >
8443 GetText()->sha256()
8444
8445< {only available when compiled with the |+cryptv| feature}
8446
8447shellescape({string} [, {special}]) *shellescape()*
8448 Escape {string} for use as a shell command argument.
8449 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00008450 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008451 in single quotes and will double up all internal single
8452 quotes.
8453 On MS-Windows, when 'shellslash' is not set, it will enclose
8454 {string} in double quotes and double all double quotes within
8455 {string}.
8456 Otherwise it will enclose {string} in single quotes and
8457 replace all "'" with "'\''".
8458
8459 When the {special} argument is present and it's a non-zero
8460 Number or a non-empty String (|non-zero-arg|), then special
8461 items such as "!", "%", "#" and "<cword>" will be preceded by
8462 a backslash. This backslash will be removed again by the |:!|
8463 command.
8464
8465 The "!" character will be escaped (again with a |non-zero-arg|
8466 {special}) when 'shell' contains "csh" in the tail. That is
8467 because for csh and tcsh "!" is used for history replacement
8468 even when inside single quotes.
8469
8470 With a |non-zero-arg| {special} the <NL> character is also
8471 escaped. When 'shell' containing "csh" in the tail it's
8472 escaped a second time.
8473
8474 The "\" character will be escaped when 'shell' contains "fish"
8475 in the tail. That is because for fish "\" is used as an escape
8476 character inside single quotes.
8477
8478 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008479 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008480< This results in a directory listing for the file under the
8481 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008482 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008483< See also |::S|.
8484
8485 Can also be used as a |method|: >
8486 GetCommand()->shellescape()
8487
8488shiftwidth([{col}]) *shiftwidth()*
8489 Returns the effective value of 'shiftwidth'. This is the
8490 'shiftwidth' value unless it is zero, in which case it is the
8491 'tabstop' value. This function was introduced with patch
8492 7.3.694 in 2012, everybody should have it by now (however it
8493 did not allow for the optional {col} argument until 8.1.542).
8494
8495 When there is one argument {col} this is used as column number
8496 for which to return the 'shiftwidth' value. This matters for the
8497 'vartabstop' feature. If the 'vartabstop' setting is enabled and
8498 no {col} argument is given, column 1 will be assumed.
8499
8500 Can also be used as a |method|: >
8501 GetColumn()->shiftwidth()
8502
8503sign_ functions are documented here: |sign-functions-details|
8504
8505
8506simplify({filename}) *simplify()*
8507 Simplify the file name as much as possible without changing
8508 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
8509 Unix) are not resolved. If the first path component in
8510 {filename} designates the current directory, this will be
8511 valid for the result as well. A trailing path separator is
8512 not removed either. On Unix "//path" is unchanged, but
8513 "///path" is simplified to "/path" (this follows the Posix
8514 standard).
8515 Example: >
8516 simplify("./dir/.././/file/") == "./file/"
8517< Note: The combination "dir/.." is only removed if "dir" is
8518 a searchable directory or does not exist. On Unix, it is also
8519 removed when "dir" is a symbolic link within the same
8520 directory. In order to resolve all the involved symbolic
8521 links before simplifying the path name, use |resolve()|.
8522
8523 Can also be used as a |method|: >
8524 GetName()->simplify()
8525
8526sin({expr}) *sin()*
8527 Return the sine of {expr}, measured in radians, as a |Float|.
8528 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008529 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008530 Examples: >
8531 :echo sin(100)
8532< -0.506366 >
8533 :echo sin(-4.01)
8534< 0.763301
8535
8536 Can also be used as a |method|: >
8537 Compute()->sin()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008538
8539
8540sinh({expr}) *sinh()*
8541 Return the hyperbolic sine of {expr} as a |Float| in the range
8542 [-inf, inf].
8543 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008544 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008545 Examples: >
8546 :echo sinh(0.5)
8547< 0.521095 >
8548 :echo sinh(-0.9)
8549< -1.026517
8550
8551 Can also be used as a |method|: >
8552 Compute()->sinh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008553
8554
8555slice({expr}, {start} [, {end}]) *slice()*
8556 Similar to using a |slice| "expr[start : end]", but "end" is
8557 used exclusive. And for a string the indexes are used as
8558 character indexes instead of byte indexes, like in
8559 |vim9script|. Also, composing characters are not counted.
8560 When {end} is omitted the slice continues to the last item.
8561 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008562 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008563
8564 Can also be used as a |method|: >
8565 GetList()->slice(offset)
8566
8567
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008568sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569 Sort the items in {list} in-place. Returns {list}.
8570
8571 If you want a list to remain unmodified make a copy first: >
8572 :let sortedlist = sort(copy(mylist))
8573
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01008574< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008575 string representation of each item to sort on. Numbers sort
8576 after Strings, |Lists| after Numbers. For sorting text in the
8577 current buffer use |:sort|.
8578
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008579 When {how} is given and it is 'i' then case is ignored.
8580 In legacy script, for backwards compatibility, the value one
8581 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008583 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008584 locale is used for ordering. Implementation details: strcoll()
8585 is used to compare strings. See |:language| check or set the
8586 collation locale. |v:collate| can also be used to check the
8587 current locale. Sorting using the locale typically ignores
8588 case. Example: >
8589 " ö is sorted similarly to o with English locale.
8590 :language collate en_US.UTF8
8591 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8592< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
8593>
8594 " ö is sorted after z with Swedish locale.
8595 :language collate sv_SE.UTF8
8596 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
8597< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
8598 This does not work properly on Mac.
8599
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008600 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008601 sorted numerical (Implementation detail: this uses the
8602 strtod() function to parse numbers, Strings, Lists, Dicts and
8603 Funcrefs will be considered as being 0).
8604
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008605 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008606 sorted numerical. This is like 'n' but a string containing
8607 digits will be used as the number they represent.
8608
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008609 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008610 sorted numerical. All values must be a Number or a Float.
8611
Bram Moolenaar2007dd42022-02-23 13:17:47 +00008612 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008613 is called to compare items. The function is invoked with two
8614 items as argument and must return zero if they are equal, 1 or
8615 bigger if the first one sorts after the second one, -1 or
8616 smaller if the first one sorts before the second one.
8617
8618 {dict} is for functions with the "dict" attribute. It will be
8619 used to set the local variable "self". |Dictionary-function|
8620
8621 The sort is stable, items which compare equal (as number or as
8622 string) will keep their relative position. E.g., when sorting
8623 on numbers, text strings will sort next to each other, in the
8624 same order as they were originally.
8625
8626 Can also be used as a |method|: >
8627 mylist->sort()
8628
8629< Also see |uniq()|.
8630
8631 Example: >
8632 func MyCompare(i1, i2)
8633 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8634 endfunc
8635 eval mylist->sort("MyCompare")
8636< A shorter compare version for this specific simple case, which
8637 ignores overflow: >
8638 func MyCompare(i1, i2)
8639 return a:i1 - a:i2
8640 endfunc
8641< For a simple expression you can use a lambda: >
8642 eval mylist->sort({i1, i2 -> i1 - i2})
8643<
8644sound_clear() *sound_clear()*
8645 Stop playing all sounds.
8646
8647 On some Linux systems you may need the libcanberra-pulse
8648 package, otherwise sound may not stop.
8649
8650 {only available when compiled with the |+sound| feature}
8651
8652 *sound_playevent()*
8653sound_playevent({name} [, {callback}])
8654 Play a sound identified by {name}. Which event names are
8655 supported depends on the system. Often the XDG sound names
8656 are used. On Ubuntu they may be found in
8657 /usr/share/sounds/freedesktop/stereo. Example: >
8658 call sound_playevent('bell')
8659< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
8660 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
8661 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +01008662 On macOS, {name} refers to files located in
8663 /System/Library/Sounds (e.g. "Tink"). It will also work for
8664 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665
8666 When {callback} is specified it is invoked when the sound is
8667 finished. The first argument is the sound ID, the second
8668 argument is the status:
8669 0 sound was played to the end
8670 1 sound was interrupted
8671 2 error occurred after sound started
8672 Example: >
8673 func Callback(id, status)
8674 echomsg "sound " .. a:id .. " finished with " .. a:status
8675 endfunc
8676 call sound_playevent('bell', 'Callback')
8677
8678< MS-Windows: {callback} doesn't work for this function.
8679
8680 Returns the sound ID, which can be passed to `sound_stop()`.
8681 Returns zero if the sound could not be played.
8682
8683 Can also be used as a |method|: >
8684 GetSoundName()->sound_playevent()
8685
8686< {only available when compiled with the |+sound| feature}
8687
8688 *sound_playfile()*
8689sound_playfile({path} [, {callback}])
8690 Like `sound_playevent()` but play sound file {path}. {path}
8691 must be a full path. On Ubuntu you may find files to play
8692 with this command: >
8693 :!find /usr/share/sounds -type f | grep -v index.theme
8694
8695< Can also be used as a |method|: >
8696 GetSoundPath()->sound_playfile()
8697
Bram Moolenaar1588bc82022-03-08 21:35:07 +00008698< {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699
8700
8701sound_stop({id}) *sound_stop()*
8702 Stop playing sound {id}. {id} must be previously returned by
8703 `sound_playevent()` or `sound_playfile()`.
8704
8705 On some Linux systems you may need the libcanberra-pulse
8706 package, otherwise sound may not stop.
8707
8708 On MS-Windows, this does not work for event sound started by
8709 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
8710
8711 Can also be used as a |method|: >
8712 soundid->sound_stop()
8713
8714< {only available when compiled with the |+sound| feature}
8715
8716 *soundfold()*
8717soundfold({word})
8718 Return the sound-folded equivalent of {word}. Uses the first
8719 language in 'spelllang' for the current window that supports
8720 soundfolding. 'spell' must be set. When no sound folding is
8721 possible the {word} is returned unmodified.
8722 This can be used for making spelling suggestions. Note that
8723 the method can be quite slow.
8724
8725 Can also be used as a |method|: >
8726 GetWord()->soundfold()
8727<
8728 *spellbadword()*
8729spellbadword([{sentence}])
8730 Without argument: The result is the badly spelled word under
8731 or after the cursor. The cursor is moved to the start of the
8732 bad word. When no bad word is found in the cursor line the
8733 result is an empty string and the cursor doesn't move.
8734
8735 With argument: The result is the first word in {sentence} that
8736 is badly spelled. If there are no spelling mistakes the
8737 result is an empty string.
8738
8739 The return value is a list with two items:
8740 - The badly spelled word or an empty string.
8741 - The type of the spelling error:
8742 "bad" spelling mistake
8743 "rare" rare word
8744 "local" word only valid in another region
8745 "caps" word should start with Capital
8746 Example: >
8747 echo spellbadword("the quik brown fox")
8748< ['quik', 'bad'] ~
8749
8750 The spelling information for the current window and the value
8751 of 'spelllang' are used.
8752
8753 Can also be used as a |method|: >
8754 GetText()->spellbadword()
8755<
8756 *spellsuggest()*
8757spellsuggest({word} [, {max} [, {capital}]])
8758 Return a |List| with spelling suggestions to replace {word}.
8759 When {max} is given up to this number of suggestions are
8760 returned. Otherwise up to 25 suggestions are returned.
8761
8762 When the {capital} argument is given and it's non-zero only
8763 suggestions with a leading capital will be given. Use this
8764 after a match with 'spellcapcheck'.
8765
8766 {word} can be a badly spelled word followed by other text.
8767 This allows for joining two words that were split. The
8768 suggestions also include the following text, thus you can
8769 replace a line.
8770
8771 {word} may also be a good word. Similar words will then be
8772 returned. {word} itself is not included in the suggestions,
8773 although it may appear capitalized.
8774
8775 The spelling information for the current window is used. The
8776 values of 'spelllang' and 'spellsuggest' are used.
8777
8778 Can also be used as a |method|: >
8779 GetWord()->spellsuggest()
8780
8781split({string} [, {pattern} [, {keepempty}]]) *split()*
8782 Make a |List| out of {string}. When {pattern} is omitted or
8783 empty each white-separated sequence of characters becomes an
8784 item.
8785 Otherwise the string is split where {pattern} matches,
8786 removing the matched characters. 'ignorecase' is not used
8787 here, add \c to ignore case. |/\c|
8788 When the first or last item is empty it is omitted, unless the
8789 {keepempty} argument is given and it's non-zero.
8790 Other empty items are kept when {pattern} matches at least one
8791 character or when {keepempty} is non-zero.
8792 Example: >
8793 :let words = split(getline('.'), '\W\+')
8794< To split a string in individual characters: >
8795 :for c in split(mystring, '\zs')
8796< If you want to keep the separator you can also use '\zs' at
8797 the end of the pattern: >
8798 :echo split('abc:def:ghi', ':\zs')
8799< ['abc:', 'def:', 'ghi'] ~
8800 Splitting a table where the first element can be empty: >
8801 :let items = split(line, ':', 1)
8802< The opposite function is |join()|.
8803
8804 Can also be used as a |method|: >
8805 GetString()->split()
8806
8807sqrt({expr}) *sqrt()*
8808 Return the non-negative square root of Float {expr} as a
8809 |Float|.
8810 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008811 is negative the result is NaN (Not a Number). Returns 0.0 if
8812 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008813 Examples: >
8814 :echo sqrt(100)
8815< 10.0 >
8816 :echo sqrt(-4.01)
8817< nan
8818 "nan" may be different, it depends on system libraries.
8819
8820 Can also be used as a |method|: >
8821 Compute()->sqrt()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008822
8823
8824srand([{expr}]) *srand()*
8825 Initialize seed used by |rand()|:
8826 - If {expr} is not given, seed values are initialized by
8827 reading from /dev/urandom, if possible, or using time(NULL)
8828 a.k.a. epoch time otherwise; this only has second accuracy.
8829 - If {expr} is given it must be a Number. It is used to
8830 initialize the seed values. This is useful for testing or
8831 when a predictable sequence is intended.
8832
8833 Examples: >
8834 :let seed = srand()
8835 :let seed = srand(userinput)
8836 :echo rand(seed)
8837
8838state([{what}]) *state()*
8839 Return a string which contains characters indicating the
8840 current state. Mostly useful in callbacks that want to do
8841 work that may not always be safe. Roughly this works like:
8842 - callback uses state() to check if work is safe to do.
8843 Yes: then do it right away.
8844 No: add to work queue and add a |SafeState| and/or
8845 |SafeStateAgain| autocommand (|SafeState| triggers at
8846 toplevel, |SafeStateAgain| triggers after handling
8847 messages and callbacks).
8848 - When SafeState or SafeStateAgain is triggered and executes
8849 your autocommand, check with `state()` if the work can be
8850 done now, and if yes remove it from the queue and execute.
8851 Remove the autocommand if the queue is now empty.
8852 Also see |mode()|.
8853
8854 When {what} is given only characters in this string will be
8855 added. E.g, this checks if the screen has scrolled: >
8856 if state('s') == ''
8857 " screen has not scrolled
8858<
8859 These characters indicate the state, generally indicating that
8860 something is busy:
8861 m halfway a mapping, :normal command, feedkeys() or
8862 stuffed command
8863 o operator pending, e.g. after |d|
8864 a Insert mode autocomplete active
8865 x executing an autocommand
8866 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
8867 ch_readraw() when reading json
8868 S not triggering SafeState or SafeStateAgain, e.g. after
8869 |f| or a count
8870 c callback invoked, including timer (repeats for
8871 recursiveness up to "ccc")
8872 s screen has scrolled for messages
8873
8874str2float({string} [, {quoted}]) *str2float()*
8875 Convert String {string} to a Float. This mostly works the
8876 same as when using a floating point number in an expression,
8877 see |floating-point-format|. But it's a bit more permissive.
8878 E.g., "1e40" is accepted, while in an expression you need to
8879 write "1.0e40". The hexadecimal form "0x123" is also
8880 accepted, but not others, like binary or octal.
8881 When {quoted} is present and non-zero then embedded single
8882 quotes before the dot are ignored, thus "1'000.0" is a
8883 thousand.
8884 Text after the number is silently ignored.
8885 The decimal point is always '.', no matter what the locale is
8886 set to. A comma ends the number: "12,345.67" is converted to
8887 12.0. You can strip out thousands separators with
8888 |substitute()|: >
8889 let f = str2float(substitute(text, ',', '', 'g'))
8890<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008891 Returns 0.0 if the conversion fails.
8892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008893 Can also be used as a |method|: >
8894 let f = text->substitute(',', '', 'g')->str2float()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008895
8896str2list({string} [, {utf8}]) *str2list()*
8897 Return a list containing the number values which represent
8898 each character in String {string}. Examples: >
8899 str2list(" ") returns [32]
8900 str2list("ABC") returns [65, 66, 67]
8901< |list2str()| does the opposite.
8902
8903 When {utf8} is omitted or zero, the current 'encoding' is used.
8904 When {utf8} is TRUE, always treat the String as UTF-8
8905 characters. With UTF-8 composing characters are handled
8906 properly: >
8907 str2list("á") returns [97, 769]
8908
8909< Can also be used as a |method|: >
8910 GetString()->str2list()
8911
8912
8913str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
8914 Convert string {string} to a number.
8915 {base} is the conversion base, it can be 2, 8, 10 or 16.
8916 When {quoted} is present and non-zero then embedded single
8917 quotes are ignored, thus "1'000'000" is a million.
8918
8919 When {base} is omitted base 10 is used. This also means that
8920 a leading zero doesn't cause octal conversion to be used, as
8921 with the default String to Number conversion. Example: >
8922 let nr = str2nr('0123')
8923<
8924 When {base} is 16 a leading "0x" or "0X" is ignored. With a
8925 different base the result will be zero. Similarly, when
8926 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
8927 {base} is 2 a leading "0b" or "0B" is ignored.
8928 Text after the number is silently ignored.
8929
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008930 Returns 0 if {string} is empty or on error.
8931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008932 Can also be used as a |method|: >
8933 GetText()->str2nr()
8934
8935
8936strcharlen({string}) *strcharlen()*
8937 The result is a Number, which is the number of characters
8938 in String {string}. Composing characters are ignored.
8939 |strchars()| can count the number of characters, counting
8940 composing characters separately.
8941
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008942 Returns 0 if {string} is empty or on error.
8943
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008944 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8945
8946 Can also be used as a |method|: >
8947 GetText()->strcharlen()
8948
8949
8950strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
8951 Like |strpart()| but using character index and length instead
8952 of byte index and length.
8953 When {skipcc} is omitted or zero, composing characters are
8954 counted separately.
8955 When {skipcc} set to 1, Composing characters are ignored,
8956 similar to |slice()|.
8957 When a character index is used where a character does not
8958 exist it is omitted and counted as one character. For
8959 example: >
8960 strcharpart('abc', -1, 2)
8961< results in 'a'.
8962
Bram Moolenaard592deb2022-06-17 15:42:40 +01008963 Returns an empty string on error.
8964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008965 Can also be used as a |method|: >
8966 GetText()->strcharpart(5)
8967
8968
8969strchars({string} [, {skipcc}]) *strchars()*
8970 The result is a Number, which is the number of characters
8971 in String {string}.
8972 When {skipcc} is omitted or zero, composing characters are
8973 counted separately.
8974 When {skipcc} set to 1, Composing characters are ignored.
8975 |strcharlen()| always does this.
8976
Bram Moolenaard592deb2022-06-17 15:42:40 +01008977 Returns zero on error.
8978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008979 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
8980
8981 {skipcc} is only available after 7.4.755. For backward
8982 compatibility, you can define a wrapper function: >
8983 if has("patch-7.4.755")
8984 function s:strchars(str, skipcc)
8985 return strchars(a:str, a:skipcc)
8986 endfunction
8987 else
8988 function s:strchars(str, skipcc)
8989 if a:skipcc
8990 return strlen(substitute(a:str, ".", "x", "g"))
8991 else
8992 return strchars(a:str)
8993 endif
8994 endfunction
8995 endif
8996<
8997 Can also be used as a |method|: >
8998 GetText()->strchars()
8999
9000strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
9001 The result is a Number, which is the number of display cells
9002 String {string} occupies on the screen when it starts at {col}
9003 (first column is zero). When {col} is omitted zero is used.
9004 Otherwise it is the screen column where to start. This
9005 matters for Tab characters.
9006 The option settings of the current window are used. This
9007 matters for anything that's displayed differently, such as
9008 'tabstop' and 'display'.
9009 When {string} contains characters with East Asian Width Class
9010 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009011 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009012 Also see |strlen()|, |strwidth()| and |strchars()|.
9013
9014 Can also be used as a |method|: >
9015 GetText()->strdisplaywidth()
9016
9017strftime({format} [, {time}]) *strftime()*
9018 The result is a String, which is a formatted date and time, as
9019 specified by the {format} string. The given {time} is used,
9020 or the current time if no time is given. The accepted
9021 {format} depends on your system, thus this is not portable!
9022 See the manual page of the C function strftime() for the
9023 format. The maximum length of the result is 80 characters.
9024 See also |localtime()|, |getftime()| and |strptime()|.
9025 The language can be changed with the |:language| command.
9026 Examples: >
9027 :echo strftime("%c") Sun Apr 27 11:49:23 1997
9028 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
9029 :echo strftime("%y%m%d %T") 970427 11:53:55
9030 :echo strftime("%H:%M") 11:55
9031 :echo strftime("%c", getftime("file.c"))
9032 Show mod time of file.c.
9033< Not available on all systems. To check use: >
9034 :if exists("*strftime")
9035
9036< Can also be used as a |method|: >
9037 GetFormat()->strftime()
9038
9039strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01009040 Get a Number corresponding to the character at {index} in
9041 {str}. This uses a zero-based character index, not a byte
9042 index. Composing characters are considered separate
9043 characters here. Use |nr2char()| to convert the Number to a
9044 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009045 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009046 Also see |strcharpart()| and |strchars()|.
9047
9048 Can also be used as a |method|: >
9049 GetText()->strgetchar(5)
9050
9051stridx({haystack}, {needle} [, {start}]) *stridx()*
9052 The result is a Number, which gives the byte index in
9053 {haystack} of the first occurrence of the String {needle}.
9054 If {start} is specified, the search starts at index {start}.
9055 This can be used to find a second match: >
9056 :let colon1 = stridx(line, ":")
9057 :let colon2 = stridx(line, ":", colon1 + 1)
9058< The search is done case-sensitive.
9059 For pattern searches use |match()|.
9060 -1 is returned if the {needle} does not occur in {haystack}.
9061 See also |strridx()|.
9062 Examples: >
9063 :echo stridx("An Example", "Example") 3
9064 :echo stridx("Starting point", "Start") 0
9065 :echo stridx("Starting point", "start") -1
9066< *strstr()* *strchr()*
9067 stridx() works similar to the C function strstr(). When used
9068 with a single character it works similar to strchr().
9069
9070 Can also be used as a |method|: >
9071 GetHaystack()->stridx(needle)
9072<
9073 *string()*
9074string({expr}) Return {expr} converted to a String. If {expr} is a Number,
9075 Float, String, Blob or a composition of them, then the result
9076 can be parsed back with |eval()|.
9077 {expr} type result ~
9078 String 'string' (single quotes are doubled)
9079 Number 123
9080 Float 123.123456 or 1.123456e8
9081 Funcref function('name')
9082 Blob 0z00112233.44556677.8899
9083 List [item, item]
9084 Dictionary {key: value, key: value}
9085
9086 When a |List| or |Dictionary| has a recursive reference it is
9087 replaced by "[...]" or "{...}". Using eval() on the result
9088 will then fail.
9089
9090 Can also be used as a |method|: >
9091 mylist->string()
9092
9093< Also see |strtrans()|.
9094
9095
9096strlen({string}) *strlen()*
9097 The result is a Number, which is the length of the String
9098 {string} in bytes.
9099 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009100 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009101 If you want to count the number of multibyte characters use
9102 |strchars()|.
9103 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
9104
9105 Can also be used as a |method|: >
9106 GetString()->strlen()
9107
9108strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
9109 The result is a String, which is part of {src}, starting from
9110 byte {start}, with the byte length {len}.
9111 When {chars} is present and TRUE then {len} is the number of
9112 characters positions (composing characters are not counted
9113 separately, thus "1" means one base character and any
9114 following composing characters).
9115 To count {start} as characters instead of bytes use
9116 |strcharpart()|.
9117
9118 When bytes are selected which do not exist, this doesn't
9119 result in an error, the bytes are simply omitted.
9120 If {len} is missing, the copy continues from {start} till the
9121 end of the {src}. >
9122 strpart("abcdefg", 3, 2) == "de"
9123 strpart("abcdefg", -2, 4) == "ab"
9124 strpart("abcdefg", 5, 4) == "fg"
9125 strpart("abcdefg", 3) == "defg"
9126
9127< Note: To get the first character, {start} must be 0. For
9128 example, to get the character under the cursor: >
9129 strpart(getline("."), col(".") - 1, 1, v:true)
9130<
Bram Moolenaard592deb2022-06-17 15:42:40 +01009131 Returns an empty string on error.
9132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009133 Can also be used as a |method|: >
9134 GetText()->strpart(5)
9135
9136strptime({format}, {timestring}) *strptime()*
9137 The result is a Number, which is a unix timestamp representing
9138 the date and time in {timestring}, which is expected to match
9139 the format specified in {format}.
9140
9141 The accepted {format} depends on your system, thus this is not
9142 portable! See the manual page of the C function strptime()
9143 for the format. Especially avoid "%c". The value of $TZ also
9144 matters.
9145
9146 If the {timestring} cannot be parsed with {format} zero is
9147 returned. If you do not know the format of {timestring} you
9148 can try different {format} values until you get a non-zero
9149 result.
9150
9151 See also |strftime()|.
9152 Examples: >
9153 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
9154< 862156163 >
9155 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
9156< Sun Apr 27 11:53:55 1997 >
9157 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
9158< Sun Apr 27 12:53:55 1997
9159
9160 Can also be used as a |method|: >
9161 GetFormat()->strptime(timestring)
9162<
9163 Not available on all systems. To check use: >
9164 :if exists("*strptime")
9165
9166strridx({haystack}, {needle} [, {start}]) *strridx()*
9167 The result is a Number, which gives the byte index in
9168 {haystack} of the last occurrence of the String {needle}.
9169 When {start} is specified, matches beyond this index are
9170 ignored. This can be used to find a match before a previous
9171 match: >
9172 :let lastcomma = strridx(line, ",")
9173 :let comma2 = strridx(line, ",", lastcomma - 1)
9174< The search is done case-sensitive.
9175 For pattern searches use |match()|.
9176 -1 is returned if the {needle} does not occur in {haystack}.
9177 If the {needle} is empty the length of {haystack} is returned.
9178 See also |stridx()|. Examples: >
9179 :echo strridx("an angry armadillo", "an") 3
9180< *strrchr()*
9181 When used with a single character it works similar to the C
9182 function strrchr().
9183
9184 Can also be used as a |method|: >
9185 GetHaystack()->strridx(needle)
9186
9187strtrans({string}) *strtrans()*
9188 The result is a String, which is {string} with all unprintable
9189 characters translated into printable characters |'isprint'|.
9190 Like they are shown in a window. Example: >
9191 echo strtrans(@a)
9192< This displays a newline in register a as "^@" instead of
9193 starting a new line.
9194
Bram Moolenaard592deb2022-06-17 15:42:40 +01009195 Returns an empty string on error.
9196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009197 Can also be used as a |method|: >
9198 GetString()->strtrans()
9199
9200strwidth({string}) *strwidth()*
9201 The result is a Number, which is the number of display cells
9202 String {string} occupies. A Tab character is counted as one
9203 cell, alternatively use |strdisplaywidth()|.
9204 When {string} contains characters with East Asian Width Class
9205 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009206 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009207 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
9208
9209 Can also be used as a |method|: >
9210 GetString()->strwidth()
9211
9212submatch({nr} [, {list}]) *submatch()* *E935*
9213 Only for an expression in a |:substitute| command or
9214 substitute() function.
9215 Returns the {nr}'th submatch of the matched text. When {nr}
9216 is 0 the whole matched text is returned.
9217 Note that a NL in the string can stand for a line break of a
9218 multi-line match or a NUL character in the text.
9219 Also see |sub-replace-expression|.
9220
9221 If {list} is present and non-zero then submatch() returns
9222 a list of strings, similar to |getline()| with two arguments.
9223 NL characters in the text represent NUL characters in the
9224 text.
9225 Only returns more than one item for |:substitute|, inside
9226 |substitute()| this list will always contain one or zero
9227 items, since there are no real line breaks.
9228
9229 When substitute() is used recursively only the submatches in
9230 the current (deepest) call can be obtained.
9231
Bram Moolenaard592deb2022-06-17 15:42:40 +01009232 Returns an empty string or list on error.
9233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009234 Examples: >
9235 :s/\d\+/\=submatch(0) + 1/
9236 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
9237< This finds the first number in the line and adds one to it.
9238 A line break is included as a newline character.
9239
9240 Can also be used as a |method|: >
9241 GetNr()->submatch()
9242
9243substitute({string}, {pat}, {sub}, {flags}) *substitute()*
9244 The result is a String, which is a copy of {string}, in which
9245 the first match of {pat} is replaced with {sub}.
9246 When {flags} is "g", all matches of {pat} in {string} are
9247 replaced. Otherwise {flags} should be "".
9248
9249 This works like the ":substitute" command (without any flags).
9250 But the matching with {pat} is always done like the 'magic'
9251 option is set and 'cpoptions' is empty (to make scripts
9252 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
9253 if you want to ignore or match case and ignore 'ignorecase'.
9254 'smartcase' is not used. See |string-match| for how {pat} is
9255 used.
9256
9257 A "~" in {sub} is not replaced with the previous {sub}.
9258 Note that some codes in {sub} have a special meaning
9259 |sub-replace-special|. For example, to replace something with
9260 "\n" (two characters), use "\\\\n" or '\\n'.
9261
9262 When {pat} does not match in {string}, {string} is returned
9263 unmodified.
9264
9265 Example: >
9266 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
9267< This removes the last component of the 'path' option. >
9268 :echo substitute("testing", ".*", "\\U\\0", "")
9269< results in "TESTING".
9270
9271 When {sub} starts with "\=", the remainder is interpreted as
9272 an expression. See |sub-replace-expression|. Example: >
9273 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009274 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009275
9276< When {sub} is a Funcref that function is called, with one
9277 optional argument. Example: >
9278 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
9279< The optional argument is a list which contains the whole
9280 matched string and up to nine submatches, like what
9281 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009282 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009283
Bram Moolenaard592deb2022-06-17 15:42:40 +01009284< Returns an empty string on error.
9285
9286 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009287 GetString()->substitute(pat, sub, flags)
9288
9289swapinfo({fname}) *swapinfo()*
9290 The result is a dictionary, which holds information about the
9291 swapfile {fname}. The available fields are:
9292 version Vim version
9293 user user name
9294 host host name
9295 fname original file name
9296 pid PID of the Vim process that created the swap
9297 file
9298 mtime last modification time in seconds
9299 inode Optional: INODE number of the file
9300 dirty 1 if file was modified, 0 if not
9301 Note that "user" and "host" are truncated to at most 39 bytes.
9302 In case of failure an "error" item is added with the reason:
9303 Cannot open file: file not found or in accessible
9304 Cannot read file: cannot read first block
9305 Not a swap file: does not contain correct block ID
9306 Magic number mismatch: Info in first block is invalid
9307
9308 Can also be used as a |method|: >
9309 GetFilename()->swapinfo()
9310
9311swapname({buf}) *swapname()*
9312 The result is the swap file path of the buffer {expr}.
9313 For the use of {buf}, see |bufname()| above.
9314 If buffer {buf} is the current buffer, the result is equal to
9315 |:swapname| (unless there is no swap file).
9316 If buffer {buf} has no swap file, returns an empty string.
9317
9318 Can also be used as a |method|: >
9319 GetBufname()->swapname()
9320
9321synID({lnum}, {col}, {trans}) *synID()*
9322 The result is a Number, which is the syntax ID at the position
9323 {lnum} and {col} in the current window.
9324 The syntax ID can be used with |synIDattr()| and
9325 |synIDtrans()| to obtain syntax information about text.
9326
9327 {col} is 1 for the leftmost column, {lnum} is 1 for the first
9328 line. 'synmaxcol' applies, in a longer line zero is returned.
9329 Note that when the position is after the last character,
9330 that's where the cursor can be in Insert mode, synID() returns
9331 zero. {lnum} is used like with |getline()|.
9332
9333 When {trans} is |TRUE|, transparent items are reduced to the
9334 item that they reveal. This is useful when wanting to know
9335 the effective color. When {trans} is |FALSE|, the transparent
9336 item is returned. This is useful when wanting to know which
9337 syntax item is effective (e.g. inside parens).
9338 Warning: This function can be very slow. Best speed is
9339 obtained by going through the file in forward direction.
9340
Bram Moolenaard592deb2022-06-17 15:42:40 +01009341 Returns zero on error.
9342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009343 Example (echoes the name of the syntax item under the cursor): >
9344 :echo synIDattr(synID(line("."), col("."), 1), "name")
9345<
9346
9347synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
9348 The result is a String, which is the {what} attribute of
9349 syntax ID {synID}. This can be used to obtain information
9350 about a syntax item.
9351 {mode} can be "gui", "cterm" or "term", to get the attributes
9352 for that mode. When {mode} is omitted, or an invalid value is
9353 used, the attributes for the currently active highlighting are
9354 used (GUI, cterm or term).
9355 Use synIDtrans() to follow linked highlight groups.
9356 {what} result
9357 "name" the name of the syntax item
9358 "fg" foreground color (GUI: color name used to set
9359 the color, cterm: color number as a string,
9360 term: empty string)
9361 "bg" background color (as with "fg")
9362 "font" font name (only available in the GUI)
9363 |highlight-font|
9364 "sp" special color for the GUI (as with "fg")
9365 |highlight-guisp|
9366 "ul" underline color for cterm: number as a string
9367 "fg#" like "fg", but for the GUI and the GUI is
9368 running the name in "#RRGGBB" form
9369 "bg#" like "fg#" for "bg"
9370 "sp#" like "fg#" for "sp"
9371 "bold" "1" if bold
9372 "italic" "1" if italic
9373 "reverse" "1" if reverse
9374 "inverse" "1" if inverse (= reverse)
9375 "standout" "1" if standout
9376 "underline" "1" if underlined
9377 "undercurl" "1" if undercurled
9378 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +01009379 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009380
Bram Moolenaard592deb2022-06-17 15:42:40 +01009381 Returns an empty string on error.
9382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009383 Example (echoes the color of the syntax item under the
9384 cursor): >
9385 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
9386<
9387 Can also be used as a |method|: >
9388 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9389
9390
9391synIDtrans({synID}) *synIDtrans()*
9392 The result is a Number, which is the translated syntax ID of
9393 {synID}. This is the syntax group ID of what is being used to
9394 highlight the character. Highlight links given with
9395 ":highlight link" are followed.
9396
Bram Moolenaard592deb2022-06-17 15:42:40 +01009397 Returns zero on error.
9398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009399 Can also be used as a |method|: >
9400 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
9401
9402synconcealed({lnum}, {col}) *synconcealed()*
9403 The result is a |List| with currently three items:
9404 1. The first item in the list is 0 if the character at the
9405 position {lnum} and {col} is not part of a concealable
9406 region, 1 if it is. {lnum} is used like with |getline()|.
9407 2. The second item in the list is a string. If the first item
9408 is 1, the second item contains the text which will be
9409 displayed in place of the concealed text, depending on the
9410 current setting of 'conceallevel' and 'listchars'.
9411 3. The third and final item in the list is a number
9412 representing the specific syntax region matched in the
9413 line. When the character is not concealed the value is
9414 zero. This allows detection of the beginning of a new
9415 concealable region if there are two consecutive regions
9416 with the same replacement character. For an example, if
9417 the text is "123456" and both "23" and "45" are concealed
9418 and replaced by the character "X", then:
9419 call returns ~
9420 synconcealed(lnum, 1) [0, '', 0]
9421 synconcealed(lnum, 2) [1, 'X', 1]
9422 synconcealed(lnum, 3) [1, 'X', 1]
9423 synconcealed(lnum, 4) [1, 'X', 2]
9424 synconcealed(lnum, 5) [1, 'X', 2]
9425 synconcealed(lnum, 6) [0, '', 0]
9426
9427
9428synstack({lnum}, {col}) *synstack()*
9429 Return a |List|, which is the stack of syntax items at the
9430 position {lnum} and {col} in the current window. {lnum} is
9431 used like with |getline()|. Each item in the List is an ID
9432 like what |synID()| returns.
9433 The first item in the List is the outer region, following are
9434 items contained in that one. The last one is what |synID()|
9435 returns, unless not the whole item is highlighted or it is a
9436 transparent item.
9437 This function is useful for debugging a syntax file.
9438 Example that shows the syntax stack under the cursor: >
9439 for id in synstack(line("."), col("."))
9440 echo synIDattr(id, "name")
9441 endfor
9442< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +01009443 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009444 character in a line and the first column in an empty line are
9445 valid positions.
9446
9447system({expr} [, {input}]) *system()* *E677*
9448 Get the output of the shell command {expr} as a |String|. See
9449 |systemlist()| to get the output as a |List|.
9450
9451 When {input} is given and is a |String| this string is written
9452 to a file and passed as stdin to the command. The string is
9453 written as-is, you need to take care of using the correct line
9454 separators yourself.
9455 If {input} is given and is a |List| it is written to the file
9456 in a way |writefile()| does with {binary} set to "b" (i.e.
9457 with a newline between each list item with newlines inside
9458 list items converted to NULs).
9459 When {input} is given and is a number that is a valid id for
9460 an existing buffer then the content of the buffer is written
9461 to the file line by line, each line terminated by a NL and
9462 NULs characters where the text has a NL.
9463
9464 Pipes are not used, the 'shelltemp' option is not used.
9465
9466 When prepended by |:silent| the terminal will not be set to
9467 cooked mode. This is meant to be used for commands that do
9468 not need the user to type. It avoids stray characters showing
9469 up on the screen which require |CTRL-L| to remove. >
9470 :silent let f = system('ls *.vim')
9471<
9472 Note: Use |shellescape()| or |::S| with |expand()| or
9473 |fnamemodify()| to escape special characters in a command
9474 argument. Newlines in {expr} may cause the command to fail.
9475 The characters in 'shellquote' and 'shellxquote' may also
9476 cause trouble.
9477 This is not to be used for interactive commands.
9478
9479 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009480 :let files = system('ls ' .. shellescape(expand('%:h')))
9481 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009482
9483< To make the result more system-independent, the shell output
9484 is filtered to replace <CR> with <NL> for Macintosh, and
9485 <CR><NL> with <NL> for DOS-like systems.
9486 To avoid the string being truncated at a NUL, all NUL
9487 characters are replaced with SOH (0x01).
9488
9489 The command executed is constructed using several options:
9490 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
9491 ({tmp} is an automatically generated file name).
9492 For Unix, braces are put around {expr} to allow for
9493 concatenated commands.
9494
9495 The command will be executed in "cooked" mode, so that a
9496 CTRL-C will interrupt the command (on Unix at least).
9497
9498 The resulting error code can be found in |v:shell_error|.
9499 This function will fail in |restricted-mode|.
9500
9501 Note that any wrong value in the options mentioned above may
9502 make the function fail. It has also been reported to fail
9503 when using a security agent application.
9504 Unlike ":!cmd" there is no automatic check for changed files.
9505 Use |:checktime| to force a check.
9506
9507 Can also be used as a |method|: >
9508 :echo GetCmd()->system()
9509
9510
9511systemlist({expr} [, {input}]) *systemlist()*
9512 Same as |system()|, but returns a |List| with lines (parts of
9513 output separated by NL) with NULs transformed into NLs. Output
9514 is the same as |readfile()| will output with {binary} argument
9515 set to "b", except that there is no extra empty item when the
9516 result ends in a NL.
9517 Note that on MS-Windows you may get trailing CR characters.
9518
9519 To see the difference between "echo hello" and "echo -n hello"
9520 use |system()| and |split()|: >
9521 echo system('echo hello')->split('\n', 1)
9522<
9523 Returns an empty string on error.
9524
9525 Can also be used as a |method|: >
9526 :echo GetCmd()->systemlist()
9527
9528
9529tabpagebuflist([{arg}]) *tabpagebuflist()*
9530 The result is a |List|, where each item is the number of the
9531 buffer associated with each window in the current tab page.
9532 {arg} specifies the number of the tab page to be used. When
9533 omitted the current tab page is used.
9534 When {arg} is invalid the number zero is returned.
9535 To get a list of all buffers in all tabs use this: >
9536 let buflist = []
9537 for i in range(tabpagenr('$'))
9538 call extend(buflist, tabpagebuflist(i + 1))
9539 endfor
9540< Note that a buffer may appear in more than one window.
9541
9542 Can also be used as a |method|: >
9543 GetTabpage()->tabpagebuflist()
9544
9545tabpagenr([{arg}]) *tabpagenr()*
9546 The result is a Number, which is the number of the current
9547 tab page. The first tab page has number 1.
9548
9549 The optional argument {arg} supports the following values:
9550 $ the number of the last tab page (the tab page
9551 count).
9552 # the number of the last accessed tab page
9553 (where |g<Tab>| goes to). if there is no
9554 previous tab page 0 is returned.
9555 The number can be used with the |:tab| command.
9556
Bram Moolenaard592deb2022-06-17 15:42:40 +01009557 Returns zero on error.
9558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009559
9560tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
9561 Like |winnr()| but for tab page {tabarg}.
9562 {tabarg} specifies the number of tab page to be used.
9563 {arg} is used like with |winnr()|:
9564 - When omitted the current window number is returned. This is
9565 the window which will be used when going to this tab page.
9566 - When "$" the number of windows is returned.
9567 - When "#" the previous window nr is returned.
9568 Useful examples: >
9569 tabpagewinnr(1) " current window of tab page 1
9570 tabpagewinnr(4, '$') " number of windows in tab page 4
9571< When {tabarg} is invalid zero is returned.
9572
9573 Can also be used as a |method|: >
9574 GetTabpage()->tabpagewinnr()
9575<
9576 *tagfiles()*
9577tagfiles() Returns a |List| with the file names used to search for tags
9578 for the current buffer. This is the 'tags' option expanded.
9579
9580
9581taglist({expr} [, {filename}]) *taglist()*
9582 Returns a |List| of tags matching the regular expression {expr}.
9583
9584 If {filename} is passed it is used to prioritize the results
9585 in the same way that |:tselect| does. See |tag-priority|.
9586 {filename} should be the full path of the file.
9587
9588 Each list item is a dictionary with at least the following
9589 entries:
9590 name Name of the tag.
9591 filename Name of the file where the tag is
9592 defined. It is either relative to the
9593 current directory or a full path.
9594 cmd Ex command used to locate the tag in
9595 the file.
9596 kind Type of the tag. The value for this
9597 entry depends on the language specific
9598 kind values. Only available when
9599 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +00009600 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009601 static A file specific tag. Refer to
9602 |static-tag| for more information.
9603 More entries may be present, depending on the content of the
9604 tags file: access, implementation, inherits and signature.
9605 Refer to the ctags documentation for information about these
9606 fields. For C code the fields "struct", "class" and "enum"
9607 may appear, they give the name of the entity the tag is
9608 contained in.
9609
9610 The ex-command "cmd" can be either an ex search pattern, a
9611 line number or a line number followed by a byte number.
9612
9613 If there are no matching tags, then an empty list is returned.
9614
9615 To get an exact tag match, the anchors '^' and '$' should be
9616 used in {expr}. This also make the function work faster.
9617 Refer to |tag-regexp| for more information about the tag
9618 search regular expression pattern.
9619
9620 Refer to |'tags'| for information about how the tags file is
9621 located by Vim. Refer to |tags-file-format| for the format of
9622 the tags file generated by the different ctags tools.
9623
9624 Can also be used as a |method|: >
9625 GetTagpattern()->taglist()
9626
9627tan({expr}) *tan()*
9628 Return the tangent of {expr}, measured in radians, as a |Float|
9629 in the range [-inf, inf].
9630 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009631 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009632 Examples: >
9633 :echo tan(10)
9634< 0.648361 >
9635 :echo tan(-4.01)
9636< -1.181502
9637
9638 Can also be used as a |method|: >
9639 Compute()->tan()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009640
9641
9642tanh({expr}) *tanh()*
9643 Return the hyperbolic tangent of {expr} as a |Float| in the
9644 range [-1, 1].
9645 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009646 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009647 Examples: >
9648 :echo tanh(0.5)
9649< 0.462117 >
9650 :echo tanh(-1)
9651< -0.761594
9652
9653 Can also be used as a |method|: >
9654 Compute()->tanh()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009655
9656
9657tempname() *tempname()* *temp-file-name*
9658 The result is a String, which is the name of a file that
9659 doesn't exist. It can be used for a temporary file. The name
9660 is different for at least 26 consecutive calls. Example: >
9661 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009662 :exe "redir > " .. tmpfile
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009663< For Unix, the file will be in a private directory |tempfile|.
9664 For MS-Windows forward slashes are used when the 'shellslash'
9665 option is set, or when 'shellcmdflag' starts with '-' and
9666 'shell' does not contain powershell or pwsh.
9667
9668
9669term_ functions are documented here: |terminal-function-details|
9670
9671
9672terminalprops() *terminalprops()*
9673 Returns a |Dictionary| with properties of the terminal that Vim
9674 detected from the response to |t_RV| request. See
9675 |v:termresponse| for the response itself. If |v:termresponse|
9676 is empty most values here will be 'u' for unknown.
9677 cursor_style whether sending |t_RS| works **
9678 cursor_blink_mode whether sending |t_RC| works **
9679 underline_rgb whether |t_8u| works **
9680 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +01009681 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009682
9683 ** value 'u' for unknown, 'y' for yes, 'n' for no
9684
9685 If the |+termresponse| feature is missing then the result is
9686 an empty dictionary.
9687
9688 If "cursor_style" is 'y' then |t_RS| will be sent to request the
9689 current cursor style.
9690 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
9691 request the cursor blink status.
9692 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
9693 is not empty, Vim will detect the working of sending |t_RS|
9694 and |t_RC| on startup.
9695
9696 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
9697 This avoids sending it to xterm, which would clear the colors.
9698
9699 For "mouse" the value 'u' is unknown
9700
9701 Also see:
9702 - 'ambiwidth' - detected by using |t_u7|.
9703 - |v:termstyleresp| and |v:termblinkresp| for the response to
9704 |t_RS| and |t_RC|.
9705
9706
9707test_ functions are documented here: |test-functions-details|
9708
9709
9710 *timer_info()*
9711timer_info([{id}])
9712 Return a list with information about timers.
9713 When {id} is given only information about this timer is
9714 returned. When timer {id} does not exist an empty list is
9715 returned.
9716 When {id} is omitted information about all timers is returned.
9717
9718 For each timer the information is stored in a |Dictionary| with
9719 these items:
9720 "id" the timer ID
9721 "time" time the timer was started with
9722 "remaining" time until the timer fires
9723 "repeat" number of times the timer will still fire;
9724 -1 means forever
9725 "callback" the callback
9726 "paused" 1 if the timer is paused, 0 otherwise
9727
9728 Can also be used as a |method|: >
9729 GetTimer()->timer_info()
9730
9731< {only available when compiled with the |+timers| feature}
9732
9733timer_pause({timer}, {paused}) *timer_pause()*
9734 Pause or unpause a timer. A paused timer does not invoke its
9735 callback when its time expires. Unpausing a timer may cause
9736 the callback to be invoked almost immediately if enough time
9737 has passed.
9738
9739 Pausing a timer is useful to avoid the callback to be called
9740 for a short time.
9741
9742 If {paused} evaluates to a non-zero Number or a non-empty
9743 String, then the timer is paused, otherwise it is unpaused.
9744 See |non-zero-arg|.
9745
9746 Can also be used as a |method|: >
9747 GetTimer()->timer_pause(1)
9748
9749< {only available when compiled with the |+timers| feature}
9750
9751 *timer_start()* *timer* *timers*
9752timer_start({time}, {callback} [, {options}])
9753 Create a timer and return the timer ID.
9754
9755 {time} is the waiting time in milliseconds. This is the
9756 minimum time before invoking the callback. When the system is
9757 busy or Vim is not waiting for input the time will be longer.
9758
9759 {callback} is the function to call. It can be the name of a
9760 function or a |Funcref|. It is called with one argument, which
9761 is the timer ID. The callback is only invoked when Vim is
9762 waiting for input.
9763 If you want to show a message look at |popup_notification()|
9764 to avoid interfering with what the user is doing.
9765
9766 {options} is a dictionary. Supported entries:
9767 "repeat" Number of times to repeat calling the
9768 callback. -1 means forever. When not present
9769 the callback will be called once.
9770 If the timer causes an error three times in a
9771 row the repeat is cancelled. This avoids that
9772 Vim becomes unusable because of all the error
9773 messages.
9774
Bram Moolenaard592deb2022-06-17 15:42:40 +01009775 Returns -1 on error.
9776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009777 Example: >
9778 func MyHandler(timer)
9779 echo 'Handler called'
9780 endfunc
9781 let timer = timer_start(500, 'MyHandler',
9782 \ {'repeat': 3})
9783< This will invoke MyHandler() three times at 500 msec
9784 intervals.
9785
9786 Can also be used as a |method|: >
9787 GetMsec()->timer_start(callback)
9788
9789< Not available in the |sandbox|.
9790 {only available when compiled with the |+timers| feature}
9791
9792timer_stop({timer}) *timer_stop()*
9793 Stop a timer. The timer callback will no longer be invoked.
9794 {timer} is an ID returned by timer_start(), thus it must be a
9795 Number. If {timer} does not exist there is no error.
9796
9797 Can also be used as a |method|: >
9798 GetTimer()->timer_stop()
9799
9800< {only available when compiled with the |+timers| feature}
9801
9802timer_stopall() *timer_stopall()*
9803 Stop all timers. The timer callbacks will no longer be
9804 invoked. Useful if a timer is misbehaving. If there are no
9805 timers there is no error.
9806
9807 {only available when compiled with the |+timers| feature}
9808
9809tolower({expr}) *tolower()*
9810 The result is a copy of the String given, with all uppercase
9811 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009812 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009813
9814 Can also be used as a |method|: >
9815 GetText()->tolower()
9816
9817toupper({expr}) *toupper()*
9818 The result is a copy of the String given, with all lowercase
9819 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +01009820 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009821
9822 Can also be used as a |method|: >
9823 GetText()->toupper()
9824
9825tr({src}, {fromstr}, {tostr}) *tr()*
9826 The result is a copy of the {src} string with all characters
9827 which appear in {fromstr} replaced by the character in that
9828 position in the {tostr} string. Thus the first character in
9829 {fromstr} is translated into the first character in {tostr}
9830 and so on. Exactly like the unix "tr" command.
9831 This code also deals with multibyte characters properly.
9832
Bram Moolenaard592deb2022-06-17 15:42:40 +01009833 Returns an empty string on error.
9834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009835 Examples: >
9836 echo tr("hello there", "ht", "HT")
9837< returns "Hello THere" >
9838 echo tr("<blob>", "<>", "{}")
9839< returns "{blob}"
9840
9841 Can also be used as a |method|: >
9842 GetText()->tr(from, to)
9843
9844trim({text} [, {mask} [, {dir}]]) *trim()*
9845 Return {text} as a String where any character in {mask} is
9846 removed from the beginning and/or end of {text}.
9847
9848 If {mask} is not given, {mask} is all characters up to 0x20,
9849 which includes Tab, space, NL and CR, plus the non-breaking
9850 space character 0xa0.
9851
9852 The optional {dir} argument specifies where to remove the
9853 characters:
9854 0 remove from the beginning and end of {text}
9855 1 remove only at the beginning of {text}
9856 2 remove only at the end of {text}
9857 When omitted both ends are trimmed.
9858
9859 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009860 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009861
9862 Examples: >
9863 echo trim(" some text ")
9864< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009865 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009866< returns "RESERVE_TAIL" >
9867 echo trim("rm<Xrm<>X>rrm", "rm<>")
9868< returns "Xrm<>X" (characters in the middle are not removed) >
9869 echo trim(" vim ", " ", 2)
9870< returns " vim"
9871
9872 Can also be used as a |method|: >
9873 GetText()->trim()
9874
9875trunc({expr}) *trunc()*
9876 Return the largest integral value with magnitude less than or
9877 equal to {expr} as a |Float| (truncate towards zero).
9878 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +01009879 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009880 Examples: >
9881 echo trunc(1.456)
9882< 1.0 >
9883 echo trunc(-5.456)
9884< -5.0 >
9885 echo trunc(4.0)
9886< 4.0
9887
9888 Can also be used as a |method|: >
9889 Compute()->trunc()
9890<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009891 *type()*
9892type({expr}) The result is a Number representing the type of {expr}.
9893 Instead of using the number directly, it is better to use the
9894 v:t_ variable that has the value:
9895 Number: 0 |v:t_number|
9896 String: 1 |v:t_string|
9897 Funcref: 2 |v:t_func|
9898 List: 3 |v:t_list|
9899 Dictionary: 4 |v:t_dict|
9900 Float: 5 |v:t_float|
9901 Boolean: 6 |v:t_bool| (v:false and v:true)
9902 None: 7 |v:t_none| (v:null and v:none)
9903 Job: 8 |v:t_job|
9904 Channel: 9 |v:t_channel|
9905 Blob: 10 |v:t_blob|
9906 For backward compatibility, this method can be used: >
9907 :if type(myvar) == type(0)
9908 :if type(myvar) == type("")
9909 :if type(myvar) == type(function("tr"))
9910 :if type(myvar) == type([])
9911 :if type(myvar) == type({})
9912 :if type(myvar) == type(0.0)
9913 :if type(myvar) == type(v:false)
9914 :if type(myvar) == type(v:none)
9915< To check if the v:t_ variables exist use this: >
9916 :if exists('v:t_number')
9917
9918< Can also be used as a |method|: >
9919 mylist->type()
9920
9921
9922typename({expr}) *typename()*
9923 Return a string representation of the type of {expr}.
9924 Example: >
9925 echo typename([1, 2, 3])
9926 list<number>
9927
9928
9929undofile({name}) *undofile()*
9930 Return the name of the undo file that would be used for a file
9931 with name {name} when writing. This uses the 'undodir'
9932 option, finding directories that exist. It does not check if
9933 the undo file exists.
9934 {name} is always expanded to the full path, since that is what
9935 is used internally.
9936 If {name} is empty undofile() returns an empty string, since a
9937 buffer without a file name will not write an undo file.
9938 Useful in combination with |:wundo| and |:rundo|.
9939 When compiled without the |+persistent_undo| option this always
9940 returns an empty string.
9941
9942 Can also be used as a |method|: >
9943 GetFilename()->undofile()
9944
9945undotree() *undotree()*
9946 Return the current state of the undo tree in a dictionary with
9947 the following items:
9948 "seq_last" The highest undo sequence number used.
9949 "seq_cur" The sequence number of the current position in
9950 the undo tree. This differs from "seq_last"
9951 when some changes were undone.
9952 "time_cur" Time last used for |:earlier| and related
9953 commands. Use |strftime()| to convert to
9954 something readable.
9955 "save_last" Number of the last file write. Zero when no
9956 write yet.
9957 "save_cur" Number of the current position in the undo
9958 tree.
9959 "synced" Non-zero when the last undo block was synced.
9960 This happens when waiting from input from the
9961 user. See |undo-blocks|.
9962 "entries" A list of dictionaries with information about
9963 undo blocks.
9964
9965 The first item in the "entries" list is the oldest undo item.
9966 Each List item is a |Dictionary| with these items:
9967 "seq" Undo sequence number. Same as what appears in
9968 |:undolist|.
9969 "time" Timestamp when the change happened. Use
9970 |strftime()| to convert to something readable.
9971 "newhead" Only appears in the item that is the last one
9972 that was added. This marks the last change
9973 and where further changes will be added.
9974 "curhead" Only appears in the item that is the last one
9975 that was undone. This marks the current
9976 position in the undo tree, the block that will
9977 be used by a redo command. When nothing was
9978 undone after the last change this item will
9979 not appear anywhere.
9980 "save" Only appears on the last block before a file
9981 write. The number is the write count. The
9982 first write has number 1, the last one the
9983 "save_last" mentioned above.
9984 "alt" Alternate entry. This is again a List of undo
9985 blocks. Each item may again have an "alt"
9986 item.
9987
9988uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
9989 Remove second and succeeding copies of repeated adjacent
9990 {list} items in-place. Returns {list}. If you want a list
9991 to remain unmodified make a copy first: >
9992 :let newlist = uniq(copy(mylist))
9993< The default compare function uses the string representation of
9994 each item. For the use of {func} and {dict} see |sort()|.
9995
Bram Moolenaard592deb2022-06-17 15:42:40 +01009996 Returns zero if {list} is not a |List|.
9997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009998 Can also be used as a |method|: >
9999 mylist->uniq()
10000
10001values({dict}) *values()*
10002 Return a |List| with all the values of {dict}. The |List| is
10003 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010004 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010005
10006 Can also be used as a |method|: >
10007 mydict->values()
10008
LemonBoy0f7a3e12022-05-26 12:10:37 +010010009virtcol({expr} [, {list}]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010010 The result is a Number, which is the screen column of the file
10011 position given with {expr}. That is, the last screen position
10012 occupied by the character at that position, when the screen
10013 would be of unlimited width. When there is a <Tab> at the
10014 position, the returned Number will be the column at the end of
10015 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
10016 set to 8, it returns 8. |conceal| is ignored.
10017 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010019 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010020
10021 When 'virtualedit' is used {expr} can be [lnum, col, off],
10022 where "off" is the offset in screen columns from the start of
10023 the character. E.g., a position within a <Tab> or after the
10024 last character. When "off" is omitted zero is used. When
10025 Virtual editing is active in the current mode, a position
10026 beyond the end of the line can be returned. Also see
10027 |'virtualedit'|
10028
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010029 The accepted positions are:
10030 . the cursor position
10031 $ the end of the cursor line (the result is the
10032 number of displayed characters in the cursor line
10033 plus one)
10034 'x position of mark x (if the mark is not set, 0 is
10035 returned)
10036 v In Visual mode: the start of the Visual area (the
10037 cursor is the end). When not in Visual mode
10038 returns the cursor position. Differs from |'<| in
10039 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010010040
10041 If {list} is present and non-zero then virtcol() returns a List
10042 with the first and last screen position occupied by the
10043 character.
10044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010045 Note that only marks in the current file can be used.
10046 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010010047 " With text "foo^Lbar" and cursor on the "^L":
10048
10049 virtcol(".") " returns 5
10050 virtcol(".", 1) " returns [4, 5]
10051 virtcol("$") " returns 9
10052
10053 " With text " there", with 't at 'h':
10054
10055 virtcol("'t") " returns 6
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010056< The first column is 1. 0 is returned for an error.
10057 A more advanced example that echoes the maximum length of
10058 all lines: >
10059 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
10060
10061< Can also be used as a |method|: >
10062 GetPos()->virtcol()
10063
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010064virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
10065 The result is a Number, which is the byte index of the
10066 character in window {winid} at buffer line {lnum} and virtual
10067 column {col}.
10068
10069 If {col} is greater than the last virtual column in line
10070 {lnum}, then the byte index of the character at the last
10071 virtual column is returned.
10072
10073 The {winid} argument can be the window number or the
10074 |window-ID|. If this is zero, then the current window is used.
10075
10076 Returns -1 if the window {winid} doesn't exist or the buffer
10077 line {lnum} or virtual column {col} is invalid.
10078
10079 See also |screenpos()|, |virtcol()| and |col()|.
10080
10081 Can also be used as a |method|: >
10082 GetWinid()->virtcol2col(lnum, col)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010083
10084visualmode([{expr}]) *visualmode()*
10085 The result is a String, which describes the last Visual mode
10086 used in the current buffer. Initially it returns an empty
10087 string, but once Visual mode has been used, it returns "v",
10088 "V", or "<CTRL-V>" (a single CTRL-V character) for
10089 character-wise, line-wise, or block-wise Visual mode
10090 respectively.
10091 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010092 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010093< This enters the same Visual mode as before. It is also useful
10094 in scripts if you wish to act differently depending on the
10095 Visual mode that was used.
10096 If Visual mode is active, use |mode()| to get the Visual mode
10097 (e.g., in a |:vmap|).
10098 If {expr} is supplied and it evaluates to a non-zero Number or
10099 a non-empty String, then the Visual mode will be cleared and
10100 the old value is returned. See |non-zero-arg|.
10101
10102wildmenumode() *wildmenumode()*
10103 Returns |TRUE| when the wildmenu is active and |FALSE|
10104 otherwise. See 'wildmenu' and 'wildmode'.
10105 This can be used in mappings to handle the 'wildcharm' option
10106 gracefully. (Makes only sense with |mapmode-c| mappings).
10107
10108 For example to make <c-j> work like <down> in wildmode, use: >
10109 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
10110<
10111 (Note, this needs the 'wildcharm' option set appropriately).
10112
10113win_execute({id}, {command} [, {silent}]) *win_execute()*
10114 Like `execute()` but in the context of window {id}.
10115 The window will temporarily be made the current window,
10116 without triggering autocommands or changing directory. When
10117 executing {command} autocommands will be triggered, this may
10118 have unexpected side effects. Use |:noautocmd| if needed.
10119 Example: >
10120 call win_execute(winid, 'set syntax=python')
10121< Doing the same with `setwinvar()` would not trigger
10122 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010123 *E994*
10124 Not all commands are allowed in popup windows.
10125 When window {id} does not exist then no error is given and
10126 an empty string is returned.
10127
10128 Can also be used as a |method|, the base is passed as the
10129 second argument: >
10130 GetCommand()->win_execute(winid)
10131
10132win_findbuf({bufnr}) *win_findbuf()*
10133 Returns a |List| with |window-ID|s for windows that contain
10134 buffer {bufnr}. When there is none the list is empty.
10135
10136 Can also be used as a |method|: >
10137 GetBufnr()->win_findbuf()
10138
10139win_getid([{win} [, {tab}]]) *win_getid()*
10140 Get the |window-ID| for the specified window.
10141 When {win} is missing use the current window.
10142 With {win} this is the window number. The top window has
10143 number 1.
10144 Without {tab} use the current tab, otherwise the tab with
10145 number {tab}. The first tab has number one.
10146 Return zero if the window cannot be found.
10147
10148 Can also be used as a |method|: >
10149 GetWinnr()->win_getid()
10150
10151
10152win_gettype([{nr}]) *win_gettype()*
10153 Return the type of the window:
10154 "autocmd" autocommand window. Temporary window
10155 used to execute autocommands.
10156 "command" command-line window |cmdwin|
10157 (empty) normal window
10158 "loclist" |location-list-window|
10159 "popup" popup window |popup|
10160 "preview" preview window |preview-window|
10161 "quickfix" |quickfix-window|
10162 "unknown" window {nr} not found
10163
10164 When {nr} is omitted return the type of the current window.
10165 When {nr} is given return the type of this window by number or
10166 |window-ID|.
10167
10168 Also see the 'buftype' option. When running a terminal in a
10169 popup window then 'buftype' is "terminal" and win_gettype()
10170 returns "popup".
10171
10172 Can also be used as a |method|: >
10173 GetWinid()->win_gettype()
10174<
10175win_gotoid({expr}) *win_gotoid()*
10176 Go to window with ID {expr}. This may also change the current
10177 tabpage.
10178 Return TRUE if successful, FALSE if the window cannot be found.
10179
10180 Can also be used as a |method|: >
10181 GetWinid()->win_gotoid()
10182
10183win_id2tabwin({expr}) *win_id2tabwin()*
10184 Return a list with the tab number and window number of window
10185 with ID {expr}: [tabnr, winnr].
10186 Return [0, 0] if the window cannot be found.
10187
10188 Can also be used as a |method|: >
10189 GetWinid()->win_id2tabwin()
10190
10191win_id2win({expr}) *win_id2win()*
10192 Return the window number of window with ID {expr}.
10193 Return 0 if the window cannot be found in the current tabpage.
10194
10195 Can also be used as a |method|: >
10196 GetWinid()->win_id2win()
10197
Daniel Steinbergee630312022-01-10 13:36:34 +000010198win_move_separator({nr}, {offset}) *win_move_separator()*
10199 Move window {nr}'s vertical separator (i.e., the right border)
10200 by {offset} columns, as if being dragged by the mouse. {nr}
10201 can be a window number or |window-ID|. A positive {offset}
10202 moves right and a negative {offset} moves left. Moving a
10203 window's vertical separator will change the width of the
10204 window and the width of other windows adjacent to the vertical
10205 separator. The magnitude of movement may be smaller than
10206 specified (e.g., as a consequence of maintaining
10207 'winminwidth'). Returns TRUE if the window can be found and
10208 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010209 This will fail for the rightmost window and a full-width
10210 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010211 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000010212
10213 Can also be used as a |method|: >
10214 GetWinnr()->win_move_separator(offset)
10215
10216win_move_statusline({nr}, {offset}) *win_move_statusline()*
10217 Move window {nr}'s status line (i.e., the bottom border) by
10218 {offset} rows, as if being dragged by the mouse. {nr} can be a
10219 window number or |window-ID|. A positive {offset} moves down
10220 and a negative {offset} moves up. Moving a window's status
10221 line will change the height of the window and the height of
10222 other windows adjacent to the status line. The magnitude of
10223 movement may be smaller than specified (e.g., as a consequence
10224 of maintaining 'winminheight'). Returns TRUE if the window can
10225 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000010226 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000010227
10228 Can also be used as a |method|: >
10229 GetWinnr()->win_move_statusline(offset)
10230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010231win_screenpos({nr}) *win_screenpos()*
10232 Return the screen position of window {nr} as a list with two
10233 numbers: [row, col]. The first window always has position
10234 [1, 1], unless there is a tabline, then it is [2, 1].
10235 {nr} can be the window number or the |window-ID|. Use zero
10236 for the current window.
10237 Returns [0, 0] if the window cannot be found in the current
10238 tabpage.
10239
10240 Can also be used as a |method|: >
10241 GetWinid()->win_screenpos()
10242<
10243win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
10244 Move the window {nr} to a new split of the window {target}.
10245 This is similar to moving to {target}, creating a new window
10246 using |:split| but having the same contents as window {nr}, and
10247 then closing {nr}.
10248
10249 Both {nr} and {target} can be window numbers or |window-ID|s.
10250 Both must be in the current tab page.
10251
10252 Returns zero for success, non-zero for failure.
10253
10254 {options} is a |Dictionary| with the following optional entries:
10255 "vertical" When TRUE, the split is created vertically,
10256 like with |:vsplit|.
10257 "rightbelow" When TRUE, the split is made below or to the
10258 right (if vertical). When FALSE, it is done
10259 above or to the left (if vertical). When not
10260 present, the values of 'splitbelow' and
10261 'splitright' are used.
10262
10263 Can also be used as a |method|: >
10264 GetWinid()->win_splitmove(target)
10265<
10266
10267 *winbufnr()*
10268winbufnr({nr}) The result is a Number, which is the number of the buffer
10269 associated with window {nr}. {nr} can be the window number or
10270 the |window-ID|.
10271 When {nr} is zero, the number of the buffer in the current
10272 window is returned.
10273 When window {nr} doesn't exist, -1 is returned.
10274 Example: >
10275 :echo "The file in the current window is " . bufname(winbufnr(0))
10276<
10277 Can also be used as a |method|: >
10278 FindWindow()->winbufnr()->bufname()
10279<
10280 *wincol()*
10281wincol() The result is a Number, which is the virtual column of the
10282 cursor in the window. This is counting screen cells from the
10283 left side of the window. The leftmost column is one.
10284
10285 *windowsversion()*
10286windowsversion()
10287 The result is a String. For MS-Windows it indicates the OS
10288 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
10289 Windows XP is "5.1". For non-MS-Windows systems the result is
10290 an empty string.
10291
10292winheight({nr}) *winheight()*
10293 The result is a Number, which is the height of window {nr}.
10294 {nr} can be the window number or the |window-ID|.
10295 When {nr} is zero, the height of the current window is
10296 returned. When window {nr} doesn't exist, -1 is returned.
10297 An existing window always has a height of zero or more.
10298 This excludes any window toolbar line.
10299 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010300 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010301
10302< Can also be used as a |method|: >
10303 GetWinid()->winheight()
10304<
10305winlayout([{tabnr}]) *winlayout()*
10306 The result is a nested List containing the layout of windows
10307 in a tabpage.
10308
10309 Without {tabnr} use the current tabpage, otherwise the tabpage
10310 with number {tabnr}. If the tabpage {tabnr} is not found,
10311 returns an empty list.
10312
10313 For a leaf window, it returns:
10314 ['leaf', {winid}]
10315 For horizontally split windows, which form a column, it
10316 returns:
10317 ['col', [{nested list of windows}]]
10318 For vertically split windows, which form a row, it returns:
10319 ['row', [{nested list of windows}]]
10320
10321 Example: >
10322 " Only one window in the tab page
10323 :echo winlayout()
10324 ['leaf', 1000]
10325 " Two horizontally split windows
10326 :echo winlayout()
10327 ['col', [['leaf', 1000], ['leaf', 1001]]]
10328 " The second tab page, with three horizontally split
10329 " windows, with two vertically split windows in the
10330 " middle window
10331 :echo winlayout(2)
10332 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
10333 ['leaf', 1001]]], ['leaf', 1000]]]
10334<
10335 Can also be used as a |method|: >
10336 GetTabnr()->winlayout()
10337<
10338 *winline()*
10339winline() The result is a Number, which is the screen line of the cursor
10340 in the window. This is counting screen lines from the top of
10341 the window. The first line is one.
10342 If the cursor was moved the view on the file will be updated
10343 first, this may cause a scroll.
10344
10345 *winnr()*
10346winnr([{arg}]) The result is a Number, which is the number of the current
10347 window. The top window has number 1.
10348 Returns zero for a popup window.
10349
10350 The optional argument {arg} supports the following values:
10351 $ the number of the last window (the window
10352 count).
10353 # the number of the last accessed window (where
10354 |CTRL-W_p| goes to). If there is no previous
10355 window or it is in another tab page 0 is
10356 returned.
10357 {N}j the number of the Nth window below the
10358 current window (where |CTRL-W_j| goes to).
10359 {N}k the number of the Nth window above the current
10360 window (where |CTRL-W_k| goes to).
10361 {N}h the number of the Nth window left of the
10362 current window (where |CTRL-W_h| goes to).
10363 {N}l the number of the Nth window right of the
10364 current window (where |CTRL-W_l| goes to).
10365 The number can be used with |CTRL-W_w| and ":wincmd w"
10366 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010010367 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010368 Also see |tabpagewinnr()| and |win_getid()|.
10369 Examples: >
10370 let window_count = winnr('$')
10371 let prev_window = winnr('#')
10372 let wnum = winnr('3k')
10373
10374< Can also be used as a |method|: >
10375 GetWinval()->winnr()
10376<
10377 *winrestcmd()*
10378winrestcmd() Returns a sequence of |:resize| commands that should restore
10379 the current window sizes. Only works properly when no windows
10380 are opened or closed and the current window and tab page is
10381 unchanged.
10382 Example: >
10383 :let cmd = winrestcmd()
10384 :call MessWithWindowSizes()
10385 :exe cmd
10386<
10387 *winrestview()*
10388winrestview({dict})
10389 Uses the |Dictionary| returned by |winsaveview()| to restore
10390 the view of the current window.
10391 Note: The {dict} does not have to contain all values, that are
10392 returned by |winsaveview()|. If values are missing, those
10393 settings won't be restored. So you can use: >
10394 :call winrestview({'curswant': 4})
10395<
10396 This will only set the curswant value (the column the cursor
10397 wants to move on vertical movements) of the cursor to column 5
10398 (yes, that is 5), while all other settings will remain the
10399 same. This is useful, if you set the cursor position manually.
10400
10401 If you have changed the values the result is unpredictable.
10402 If the window size changed the result won't be the same.
10403
10404 Can also be used as a |method|: >
10405 GetView()->winrestview()
10406<
10407 *winsaveview()*
10408winsaveview() Returns a |Dictionary| that contains information to restore
10409 the view of the current window. Use |winrestview()| to
10410 restore the view.
10411 This is useful if you have a mapping that jumps around in the
10412 buffer and you want to go back to the original view.
10413 This does not save fold information. Use the 'foldenable'
10414 option to temporarily switch off folding, so that folds are
10415 not opened when moving around. This may have side effects.
10416 The return value includes:
10417 lnum cursor line number
10418 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000010419 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010420 returns)
10421 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000010422 curswant column for vertical movement (Note:
10423 the first column is zero, as opposed
10424 to what |getcurpos()| returns). After
10425 |$| command it will be a very large
10426 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010427 topline first line in the window
10428 topfill filler lines, only in diff mode
10429 leftcol first column displayed; only used when
10430 'wrap' is off
10431 skipcol columns skipped
10432 Note that no option values are saved.
10433
10434
10435winwidth({nr}) *winwidth()*
10436 The result is a Number, which is the width of window {nr}.
10437 {nr} can be the window number or the |window-ID|.
10438 When {nr} is zero, the width of the current window is
10439 returned. When window {nr} doesn't exist, -1 is returned.
10440 An existing window always has a width of zero or more.
10441 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010442 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010443 :if winwidth(0) <= 50
10444 : 50 wincmd |
10445 :endif
10446< For getting the terminal or screen size, see the 'columns'
10447 option.
10448
10449 Can also be used as a |method|: >
10450 GetWinid()->winwidth()
10451
10452
10453wordcount() *wordcount()*
10454 The result is a dictionary of byte/chars/word statistics for
10455 the current buffer. This is the same info as provided by
10456 |g_CTRL-G|
10457 The return value includes:
10458 bytes Number of bytes in the buffer
10459 chars Number of chars in the buffer
10460 words Number of words in the buffer
10461 cursor_bytes Number of bytes before cursor position
10462 (not in Visual mode)
10463 cursor_chars Number of chars before cursor position
10464 (not in Visual mode)
10465 cursor_words Number of words before cursor position
10466 (not in Visual mode)
10467 visual_bytes Number of bytes visually selected
10468 (only in Visual mode)
10469 visual_chars Number of chars visually selected
10470 (only in Visual mode)
10471 visual_words Number of words visually selected
10472 (only in Visual mode)
10473
10474
10475 *writefile()*
10476writefile({object}, {fname} [, {flags}])
10477 When {object} is a |List| write it to file {fname}. Each list
10478 item is separated with a NL. Each list item must be a String
10479 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010480 All NL characters are replaced with a NUL character.
10481 Inserting CR characters needs to be done before passing {list}
10482 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010010483
10484 When {object} is a |Blob| write the bytes to file {fname}
10485 unmodified, also when binary mode is not specified.
10486
10487 {flags} must be a String. These characters are recognized:
10488
10489 'b' Binary mode is used: There will not be a NL after the
10490 last list item. An empty item at the end does cause the
10491 last line in the file to end in a NL.
10492
10493 'a' Append mode is used, lines are appended to the file: >
10494 :call writefile(["foo"], "event.log", "a")
10495 :call writefile(["bar"], "event.log", "a")
10496<
10497 'D' Delete the file when the current function ends. This
10498 works like: >
10499 :defer delete({fname})
10500< Fails when not in a function. Also see |:defer|.
10501
10502 's' fsync() is called after writing the file. This flushes
10503 the file to disk, if possible. This takes more time but
10504 avoids losing the file if the system crashes.
10505
10506 'S' fsync() is not called, even when 'fsync' is set.
10507
10508 When {flags} does not contain "S" or "s" then fsync() is
10509 called if the 'fsync' option is set.
10510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010511 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010513 When the write fails -1 is returned, otherwise 0. There is an
10514 error message if the file can't be created or when writing
10515 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010010516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010517 Also see |readfile()|.
10518 To copy a file byte for byte: >
10519 :let fl = readfile("foo", "b")
10520 :call writefile(fl, "foocopy", "b")
10521
10522< Can also be used as a |method|: >
10523 GetText()->writefile("thefile")
10524
10525
10526xor({expr}, {expr}) *xor()*
10527 Bitwise XOR on the two arguments. The arguments are converted
10528 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010010529 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010530 Example: >
10531 :let bits = xor(bits, 0x80)
10532<
10533 Can also be used as a |method|: >
10534 :let bits = bits->xor(0x80)
10535<
10536
10537==============================================================================
105383. Feature list *feature-list*
10539
10540There are three types of features:
105411. Features that are only supported when they have been enabled when Vim
10542 was compiled |+feature-list|. Example: >
10543 :if has("cindent")
10544< *gui_running*
105452. Features that are only supported when certain conditions have been met.
10546 Example: >
10547 :if has("gui_running")
10548< *has-patch*
105493. Beyond a certain version or at a certain version and including a specific
10550 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
10551 later, or it is version 7.4 and patch 248 was included. Example: >
10552 :if has("patch-7.4.248")
10553< Note that it's possible for patch 248 to be omitted even though 249 is
10554 included. Only happens when cherry-picking patches.
10555 Note that this form only works for patch 7.4.237 and later, before that
10556 you need to check for the patch and the v:version. Example (checking
10557 version 6.2.148 or later): >
10558 :if v:version > 602 || (v:version == 602 && has("patch148"))
10559
10560Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
10561use: `if exists('+shellslash')`
10562
10563
10564acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010565all_builtin_terms Compiled with all builtin terminals enabled. (always
10566 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010567amiga Amiga version of Vim.
10568arabic Compiled with Arabic support |Arabic|.
10569arp Compiled with ARP support (Amiga).
10570autocmd Compiled with autocommand support. (always true)
10571autochdir Compiled with support for 'autochdir'
10572autoservername Automatically enable |clientserver|
10573balloon_eval Compiled with |balloon-eval| support.
10574balloon_multiline GUI supports multiline balloons.
10575beos BeOS version of Vim.
10576browse Compiled with |:browse| support, and browse() will
10577 work.
10578browsefilter Compiled with support for |browsefilter|.
10579bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010010580builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010581byte_offset Compiled with support for 'o' in 'statusline'
10582channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010583cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010584clientserver Compiled with remote invocation support |clientserver|.
10585clipboard Compiled with 'clipboard' support.
10586clipboard_working Compiled with 'clipboard' support and it can be used.
10587cmdline_compl Compiled with |cmdline-completion| support.
10588cmdline_hist Compiled with |cmdline-history| support.
10589cmdline_info Compiled with 'showcmd' and 'ruler' support.
10590comments Compiled with |'comments'| support.
10591compatible Compiled to be very Vi compatible.
10592conpty Platform where |ConPTY| can be used.
10593cryptv Compiled with encryption support |encryption|.
10594cscope Compiled with |cscope| support.
10595cursorbind Compiled with |'cursorbind'| (always true)
10596debug Compiled with "DEBUG" defined.
10597dialog_con Compiled with console dialog support.
10598dialog_gui Compiled with GUI dialog support.
10599diff Compiled with |vimdiff| and 'diff' support.
10600digraphs Compiled with support for digraphs.
10601directx Compiled with support for DirectX and 'renderoptions'.
10602dnd Compiled with support for the "~ register |quote_~|.
10603drop_file Compiled with |drop_file| support.
10604ebcdic Compiled on a machine with ebcdic character set.
10605emacs_tags Compiled with support for Emacs tags.
10606eval Compiled with expression evaluation support. Always
10607 true, of course!
10608ex_extra |+ex_extra| (always true)
10609extra_search Compiled with support for |'incsearch'| and
10610 |'hlsearch'|
10611farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010010612file_in_path Compiled with support for |gf| and |<cfile>| (always
10613 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010614filterpipe When 'shelltemp' is off pipes are used for shell
10615 read/write/filter commands
10616find_in_path Compiled with support for include file searches
10617 |+find_in_path|.
10618float Compiled with support for |Float|.
10619fname_case Case in file names matters (for Amiga and MS-Windows
10620 this is not present).
10621folding Compiled with |folding| support.
10622footer Compiled with GUI footer support. |gui-footer|
10623fork Compiled to use fork()/exec() instead of system().
10624gettext Compiled with message translation |multi-lang|
10625gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010010626gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010627gui_gnome Compiled with Gnome support (gui_gtk is also defined).
10628gui_gtk Compiled with GTK+ GUI (any version).
10629gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
10630gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
10631gui_haiku Compiled with Haiku GUI.
10632gui_mac Compiled with Macintosh GUI.
10633gui_motif Compiled with Motif GUI.
10634gui_photon Compiled with Photon GUI.
10635gui_running Vim is running in the GUI, or it will start soon.
10636gui_win32 Compiled with MS-Windows Win32 GUI.
10637gui_win32s idem, and Win32s system being used (Windows 3.1)
10638haiku Haiku version of Vim.
10639hangul_input Compiled with Hangul input support. |hangul|
10640hpux HP-UX version of Vim.
10641iconv Can use iconv() for conversion.
10642insert_expand Compiled with support for CTRL-X expansion commands in
10643 Insert mode. (always true)
10644job Compiled with support for |channel| and |job|
10645ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010646jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010647keymap Compiled with 'keymap' support.
10648lambda Compiled with |lambda| support.
10649langmap Compiled with 'langmap' support.
10650libcall Compiled with |libcall()| support.
10651linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
10652 'breakindent' support.
10653linux Linux version of Vim.
10654lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010655 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010656listcmds Compiled with commands for the buffer list |:files|
10657 and the argument list |arglist|.
10658localmap Compiled with local mappings and abbr. |:map-local|
10659lua Compiled with Lua interface |Lua|.
10660mac Any Macintosh version of Vim cf. osx
10661macunix Synonym for osxdarwin
10662menu Compiled with support for |:menu|.
10663mksession Compiled with support for |:mksession|.
10664modify_fname Compiled with file name modifiers. |filename-modifiers|
10665 (always true)
10666mouse Compiled with support for mouse.
10667mouse_dec Compiled with support for Dec terminal mouse.
10668mouse_gpm Compiled with support for gpm (Linux console mouse)
10669mouse_gpm_enabled GPM mouse is working
10670mouse_netterm Compiled with support for netterm mouse.
10671mouse_pterm Compiled with support for qnx pterm mouse.
10672mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
10673mouse_sgr Compiled with support for sgr mouse.
10674mouse_urxvt Compiled with support for urxvt mouse.
10675mouse_xterm Compiled with support for xterm mouse.
10676mouseshape Compiled with support for 'mouseshape'.
10677multi_byte Compiled with support for 'encoding' (always true)
10678multi_byte_encoding 'encoding' is set to a multibyte encoding.
10679multi_byte_ime Compiled with support for IME input method.
10680multi_lang Compiled with support for multiple languages.
10681mzscheme Compiled with MzScheme interface |mzscheme|.
10682nanotime Compiled with sub-second time stamp checks.
10683netbeans_enabled Compiled with support for |netbeans| and connected.
10684netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010685num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010686ole Compiled with OLE automation support for Win32.
10687osx Compiled for macOS cf. mac
10688osxdarwin Compiled for macOS, with |mac-darwin-feature|
10689packages Compiled with |packages| support.
10690path_extra Compiled with up/downwards search in 'path' and 'tags'
10691perl Compiled with Perl interface.
10692persistent_undo Compiled with support for persistent undo history.
10693postscript Compiled with PostScript file printing.
10694printer Compiled with |:hardcopy| support.
10695profile Compiled with |:profile| support.
10696python Python 2.x interface available. |has-python|
10697python_compiled Compiled with Python 2.x interface. |has-python|
10698python_dynamic Python 2.x interface is dynamically loaded. |has-python|
10699python3 Python 3.x interface available. |has-python|
10700python3_compiled Compiled with Python 3.x interface. |has-python|
10701python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
10702pythonx Python 2.x and/or 3.x interface available. |python_x|
10703qnx QNX version of Vim.
10704quickfix Compiled with |quickfix| support.
10705reltime Compiled with |reltime()| support.
10706rightleft Compiled with 'rightleft' support.
10707ruby Compiled with Ruby interface |ruby|.
10708scrollbind Compiled with 'scrollbind' support. (always true)
10709showcmd Compiled with 'showcmd' support.
10710signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010711smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010712sodium Compiled with libsodium for better crypt support
10713sound Compiled with sound support, e.g. `sound_playevent()`
10714spell Compiled with spell checking support |spell|.
10715startuptime Compiled with |--startuptime| support.
10716statusline Compiled with support for 'statusline', 'rulerformat'
10717 and special formats of 'titlestring' and 'iconstring'.
10718sun SunOS version of Vim.
10719sun_workshop Support for Sun |workshop| has been removed.
10720syntax Compiled with syntax highlighting support |syntax|.
10721syntax_items There are active syntax highlighting items for the
10722 current buffer.
10723system Compiled to use system() instead of fork()/exec().
10724tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010725 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010726tag_old_static Support for old static tags was removed, see
10727 |tag-old-static|.
10728tcl Compiled with Tcl interface.
10729termguicolors Compiled with true color in terminal support.
10730terminal Compiled with |terminal| support.
10731terminfo Compiled with terminfo instead of termcap.
10732termresponse Compiled with support for |t_RV| and |v:termresponse|.
10733textobjects Compiled with support for |text-objects|.
10734textprop Compiled with support for |text-properties|.
10735tgetent Compiled with tgetent support, able to use a termcap
10736 or terminfo file.
10737timers Compiled with |timer_start()| support.
10738title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010010739 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010740toolbar Compiled with support for |gui-toolbar|.
10741ttyin input is a terminal (tty)
10742ttyout output is a terminal (tty)
10743unix Unix version of Vim. *+unix*
10744unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
10745user_commands User-defined commands. (always true)
10746vartabs Compiled with variable tabstop support |'vartabstop'|.
10747vcon Win32: Virtual console support is working, can use
10748 'termguicolors'. Also see |+vtp|.
10749vertsplit Compiled with vertically split windows |:vsplit|.
10750 (always true)
10751vim_starting True while initial source'ing takes place. |startup|
10752 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000010753vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010754viminfo Compiled with viminfo support.
10755vimscript-1 Compiled Vim script version 1 support
10756vimscript-2 Compiled Vim script version 2 support
10757vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010010758vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010759virtualedit Compiled with 'virtualedit' option. (always true)
10760visual Compiled with Visual mode. (always true)
10761visualextra Compiled with extra Visual mode commands. (always
10762 true) |blockwise-operators|.
10763vms VMS version of Vim.
10764vreplace Compiled with |gR| and |gr| commands. (always true)
10765vtp Compiled for vcon support |+vtp| (check vcon to find
10766 out if it works in the current console).
10767wildignore Compiled with 'wildignore' option.
10768wildmenu Compiled with 'wildmenu' option.
10769win16 old version for MS-Windows 3.1 (always false)
10770win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
10771 64 bits)
10772win32unix Win32 version of Vim, using Unix files (Cygwin)
10773win64 Win64 version of Vim (MS-Windows 64 bit).
10774win95 Win32 version for MS-Windows 95/98/ME (always false)
10775winaltkeys Compiled with 'winaltkeys' option.
10776windows Compiled with support for more than one window.
10777 (always true)
10778writebackup Compiled with 'writebackup' default on.
10779xfontset Compiled with X fontset support |xfontset|.
10780xim Compiled with X input method support |xim|.
10781xpm Compiled with pixmap support.
10782xpm_w32 Compiled with pixmap support for Win32. (Only for
10783 backward compatibility. Use "xpm" instead.)
10784xsmp Compiled with X session management support.
10785xsmp_interact Compiled with interactive X session management support.
10786xterm_clipboard Compiled with support for xterm clipboard.
10787xterm_save Compiled with support for saving and restoring the
10788 xterm screen.
10789x11 Compiled with X11 support.
10790
10791
10792==============================================================================
107934. Matching a pattern in a String *string-match*
10794
10795This is common between several functions. A regexp pattern as explained at
10796|pattern| is normally used to find a match in the buffer lines. When a
10797pattern is used to find a match in a String, almost everything works in the
10798same way. The difference is that a String is handled like it is one line.
10799When it contains a "\n" character, this is not seen as a line break for the
10800pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
10801>
10802 :let a = "aaaa\nxxxx"
10803 :echo matchstr(a, "..\n..")
10804 aa
10805 xx
10806 :echo matchstr(a, "a.x")
10807 a
10808 x
10809
10810Don't forget that "^" will only match at the first character of the String and
10811"$" at the last character of the string. They don't match after or before a
10812"\n".
10813
10814 vim:tw=78:ts=8:noet:ft=help:norl: