blob: 66f1bae1325192b1e988dcb929c6c8237ccf2567 [file] [log] [blame]
Peter Aronoff210b39c2024-06-11 19:22:53 +02001*builtin.txt* For Vim version 9.1. Last change: 2024 Jun 11
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
31appendbufline({expr}, {lnum}, {text})
32 Number append {text} below line {lnum}
33 in buffer {expr}
34argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
70blob2list({blob}) List convert {blob} into a list of numbers
71browse({save}, {title}, {initdir}, {default})
72 String put up a file requester
73browsedir({title}, {initdir}) String put up a directory requester
74bufadd({name}) Number add a buffer to the buffer list
75bufexists({buf}) Number |TRUE| if buffer {buf} exists
76buflisted({buf}) Number |TRUE| if buffer {buf} is listed
77bufload({buf}) Number load buffer {buf} if not loaded yet
78bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
79bufname([{buf}]) String Name of the buffer {buf}
80bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
81bufwinid({buf}) Number window ID of buffer {buf}
82bufwinnr({buf}) Number window number of buffer {buf}
83byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010084byteidx({expr}, {nr} [, {utf16}])
85 Number byte index of {nr}'th char in {expr}
86byteidxcomp({expr}, {nr} [, {utf16}])
87 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000088call({func}, {arglist} [, {dict}])
89 any call {func} with arguments {arglist}
90ceil({expr}) Float round {expr} up
91ch_canread({handle}) Number check if there is something to read
92ch_close({handle}) none close {handle}
93ch_close_in({handle}) none close in part of {handle}
94ch_evalexpr({handle}, {expr} [, {options}])
95 any evaluate {expr} on JSON {handle}
96ch_evalraw({handle}, {string} [, {options}])
97 any evaluate {string} on raw {handle}
98ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
99ch_getjob({channel}) Job get the Job of {channel}
100ch_info({handle}) String info about channel {handle}
101ch_log({msg} [, {handle}]) none write {msg} in the channel log file
102ch_logfile({fname} [, {mode}]) none start logging channel activity
103ch_open({address} [, {options}])
104 Channel open a channel to {address}
105ch_read({handle} [, {options}]) String read from {handle}
106ch_readblob({handle} [, {options}])
107 Blob read Blob from {handle}
108ch_readraw({handle} [, {options}])
109 String read raw from {handle}
110ch_sendexpr({handle}, {expr} [, {options}])
111 any send {expr} over JSON {handle}
112ch_sendraw({handle}, {expr} [, {options}])
113 any send {expr} over raw {handle}
114ch_setoptions({handle}, {options})
115 none set options for {handle}
116ch_status({handle} [, {options}])
117 String status of channel {handle}
118changenr() Number current change number
119char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
120charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000121charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100122charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000123 Number char index of byte {idx} in {string}
124chdir({dir}) String change current working directory
125cindent({lnum}) Number C indent for line {lnum}
126clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000127col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128complete({startcol}, {matches}) none set Insert mode completion
129complete_add({expr}) Number add completion match
130complete_check() Number check for key typed during completion
131complete_info([{what}]) Dict get current completion information
132confirm({msg} [, {choices} [, {default} [, {type}]]])
133 Number number of choice picked by user
134copy({expr}) any make a shallow copy of {expr}
135cos({expr}) Float cosine of {expr}
136cosh({expr}) Float hyperbolic cosine of {expr}
137count({comp}, {expr} [, {ic} [, {start}]])
138 Number count how many {expr} are in {comp}
139cscope_connection([{num}, {dbpath} [, {prepend}]])
140 Number checks existence of cscope connection
141cursor({lnum}, {col} [, {off}])
142 Number move cursor to {lnum}, {col}, {off}
143cursor({list}) Number move cursor to position in {list}
144debugbreak({pid}) Number interrupt process being debugged
145deepcopy({expr} [, {noref}]) any make a full copy of {expr}
146delete({fname} [, {flags}]) Number delete the file or directory {fname}
147deletebufline({buf}, {first} [, {last}])
148 Number delete lines from buffer {buf}
149did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100150diff({fromlist}, {tolist} [, {options}])
151 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000152diff_filler({lnum}) Number diff filler lines about {lnum}
153diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
154digraph_get({chars}) String get the |digraph| of {chars}
155digraph_getlist([{listall}]) List get all |digraph|s
156digraph_set({chars}, {digraph}) Boolean register |digraph|
157digraph_setlist({digraphlist}) Boolean register multiple |digraph|s
158echoraw({expr}) none output {expr} as-is
159empty({expr}) Number |TRUE| if {expr} is empty
160environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100161err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162escape({string}, {chars}) String escape {chars} in {string} with '\'
163eval({string}) any evaluate {string} into its value
164eventhandler() Number |TRUE| if inside an event handler
165executable({expr}) Number 1 if executable {expr} exists
166execute({command}) String execute {command} and get the output
167exepath({expr}) String full path of the command {expr}
168exists({expr}) Number |TRUE| if {expr} exists
169exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
170exp({expr}) Float exponential of {expr}
171expand({expr} [, {nosuf} [, {list}]])
172 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100173expandcmd({string} [, {options}])
174 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000175extend({expr1}, {expr2} [, {expr3}])
176 List/Dict insert items of {expr2} into {expr1}
177extendnew({expr1}, {expr2} [, {expr3}])
178 List/Dict like |extend()| but creates a new
179 List or Dictionary
180feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200181filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
182 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000183filereadable({file}) Number |TRUE| if {file} is a readable file
184filewritable({file}) Number |TRUE| if {file} is a writable file
185filter({expr1}, {expr2}) List/Dict/Blob/String
186 remove items from {expr1} where
187 {expr2} is 0
188finddir({name} [, {path} [, {count}]])
189 String find directory {name} in {path}
190findfile({name} [, {path} [, {count}]])
191 String find file {name} in {path}
192flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
193flattennew({list} [, {maxdepth}])
194 List flatten a copy of {list}
195float2nr({expr}) Number convert Float {expr} to a Number
196floor({expr}) Float round {expr} down
197fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
198fnameescape({fname}) String escape special characters in {fname}
199fnamemodify({fname}, {mods}) String modify file name
200foldclosed({lnum}) Number first line of fold at {lnum} if closed
201foldclosedend({lnum}) Number last line of fold at {lnum} if closed
202foldlevel({lnum}) Number fold level at {lnum}
203foldtext() String line displayed for closed fold
204foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100205foreach({expr1}, {expr2}) List/Dict/Blob/String
206 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000207foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100208fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000209funcref({name} [, {arglist}] [, {dict}])
210 Funcref reference to function {name}
211function({name} [, {arglist}] [, {dict}])
212 Funcref named reference to function {name}
213garbagecollect([{atexit}]) none free memory, breaking cyclic references
214get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
215get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
216get({func}, {what}) any get property of funcref/partial {func}
217getbufinfo([{buf}]) List information about buffers
218getbufline({buf}, {lnum} [, {end}])
219 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000220getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000221getbufvar({buf}, {varname} [, {def}])
222 any variable {varname} in buffer {buf}
Kota Kato66bb9ae2023-01-17 18:31:56 +0000223getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000224getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200225getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226 get one character from the user
227getcharmod() Number modifiers for the last typed character
228getcharpos({expr}) List position of cursor, mark, etc.
229getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getcharstr([{expr}]) String get one character from the user
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100231getcmdcompltype() String return the type of the current
232 command-line completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000233getcmdline() String return the current command-line
234getcmdpos() Number return cursor position in command-line
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100235getcmdscreenpos() Number return cursor screen position in
236 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000237getcmdtype() String return current command-line type
238getcmdwintype() String return current command-line window type
239getcompletion({pat}, {type} [, {filtered}])
240 List list of cmdline completion matches
241getcurpos([{winnr}]) List position of the cursor
242getcursorcharpos([{winnr}]) List character position of the cursor
243getcwd([{winnr} [, {tabnr}]]) String get the current working directory
244getenv({name}) String return environment variable
245getfontname([{name}]) String name of font being used
246getfperm({fname}) String file permissions of file {fname}
247getfsize({fname}) Number size in bytes of file {fname}
248getftime({fname}) Number last modification time of file
249getftype({fname}) String description of type of file {fname}
250getimstatus() Number |TRUE| if the IME status is active
251getjumplist([{winnr} [, {tabnr}]])
252 List list of jump list items
253getline({lnum}) String line {lnum} of current buffer
254getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
255getloclist({nr}) List list of location list items
256getloclist({nr}, {what}) Dict get specific location list properties
257getmarklist([{buf}]) List list of global/local marks
258getmatches([{win}]) List list of current matches
259getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000260getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000261getpid() Number process ID of Vim
262getpos({expr}) List position of cursor, mark, etc.
263getqflist() List list of quickfix items
264getqflist({what}) Dict get specific quickfix list properties
265getreg([{regname} [, 1 [, {list}]]])
266 String or List contents of a register
267getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100268getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100269 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200270getregionpos({pos1}, {pos2} [, {opts}])
271 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100273getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000274gettabinfo([{expr}]) List list of tab pages
275gettabvar({nr}, {varname} [, {def}])
276 any variable {varname} in tab {nr} or {def}
277gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
278 any {name} in {winnr} in tab page {tabnr}
279gettagstack([{nr}]) Dict get the tag stack of window {nr}
280gettext({text}) String lookup translation of {text}
281getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000282getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getwinposx() Number X coord in pixels of the Vim window
284getwinposy() Number Y coord in pixels of the Vim window
285getwinvar({nr}, {varname} [, {def}])
286 any variable {varname} in window {nr}
287glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
288 any expand file wildcards in {expr}
289glob2regpat({expr}) String convert a glob pat into a search pat
290globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
291 String do glob({expr}) for all dirs in {path}
292has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
293has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
294haslocaldir([{winnr} [, {tabnr}]])
295 Number |TRUE| if the window executed |:lcd|
296 or |:tcd|
297hasmapto({what} [, {mode} [, {abbr}]])
298 Number |TRUE| if mapping to {what} exists
299histadd({history}, {item}) Number add an item to a history
300histdel({history} [, {item}]) Number remove an item from a history
301histget({history} [, {index}]) String get the item {index} from a history
302histnr({history}) Number highest index of a history
303hlID({name}) Number syntax ID of highlight group {name}
304hlexists({name}) Number |TRUE| if highlight group {name} exists
305hlget([{name} [, {resolve}]]) List get highlight group attributes
306hlset({list}) Number set highlight group attributes
307hostname() String name of the machine Vim is running on
308iconv({expr}, {from}, {to}) String convert encoding of {expr}
309indent({lnum}) Number indent of line {lnum}
310index({object}, {expr} [, {start} [, {ic}]])
311 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100312indexof({object}, {expr} [, {opts}]])
313 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000314input({prompt} [, {text} [, {completion}]])
315 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100316inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000317 String like input() but in a GUI dialog
318inputlist({textlist}) Number let the user pick from a choice list
319inputrestore() Number restore typeahead
320inputsave() Number save and clear typeahead
321inputsecret({prompt} [, {text}]) String like input() but hiding the text
322insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200323instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000324interrupt() none interrupt script execution
325invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100326isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327isdirectory({directory}) Number |TRUE| if {directory} is a directory
328isinf({expr}) Number determine if {expr} is infinity value
329 (positive or negative)
330islocked({expr}) Number |TRUE| if {expr} is locked
331isnan({expr}) Number |TRUE| if {expr} is NaN
332items({dict}) List key-value pairs in {dict}
333job_getchannel({job}) Channel get the channel handle for {job}
334job_info([{job}]) Dict get information about {job}
335job_setoptions({job}, {options}) none set options for {job}
336job_start({command} [, {options}])
337 Job start a job
338job_status({job}) String get the status of {job}
339job_stop({job} [, {how}]) Number stop {job}
340join({list} [, {sep}]) String join {list} items into one String
341js_decode({string}) any decode JS style JSON
342js_encode({expr}) String encode JS style JSON
343json_decode({string}) any decode JSON
344json_encode({expr}) String encode JSON
345keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100346keytrans({string}) String translate internal keycodes to a form
347 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000348len({expr}) Number the length of {expr}
349libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
350libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
351line({expr} [, {winid}]) Number line nr of cursor, last line or mark
352line2byte({lnum}) Number byte count of line {lnum}
353lispindent({lnum}) Number Lisp indent for line {lnum}
354list2blob({list}) Blob turn {list} of numbers into a Blob
355list2str({list} [, {utf8}]) String turn {list} of numbers into a String
356listener_add({callback} [, {buf}])
357 Number add a callback to listen to changes
358listener_flush([{buf}]) none invoke listener callbacks
359listener_remove({id}) none remove a listener callback
360localtime() Number current time
361log({expr}) Float natural logarithm (base e) of {expr}
362log10({expr}) Float logarithm of Float {expr} to base 10
363luaeval({expr} [, {expr}]) any evaluate |Lua| expression
364map({expr1}, {expr2}) List/Dict/Blob/String
365 change each item in {expr1} to {expr2}
366maparg({name} [, {mode} [, {abbr} [, {dict}]]])
367 String or Dict
368 rhs of mapping {name} in mode {mode}
369mapcheck({name} [, {mode} [, {abbr}]])
370 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100371maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000372mapnew({expr1}, {expr2}) List/Dict/Blob/String
373 like |map()| but creates a new List or
374 Dictionary
375mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
376match({expr}, {pat} [, {start} [, {count}]])
377 Number position where {pat} matches in {expr}
378matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
379 Number highlight {pattern} with {group}
380matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
381 Number highlight positions with {group}
382matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100383matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
384 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000385matchdelete({id} [, {win}]) Number delete match identified by {id}
386matchend({expr}, {pat} [, {start} [, {count}]])
387 Number position where {pat} ends in {expr}
388matchfuzzy({list}, {str} [, {dict}])
389 List fuzzy match {str} in {list}
390matchfuzzypos({list}, {str} [, {dict}])
391 List fuzzy match {str} in {list}
392matchlist({expr}, {pat} [, {start} [, {count}]])
393 List match and submatches of {pat} in {expr}
394matchstr({expr}, {pat} [, {start} [, {count}]])
395 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100396matchstrlist({list}, {pat} [, {dict})
397 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000398matchstrpos({expr}, {pat} [, {start} [, {count}]])
399 List {count}'th match of {pat} in {expr}
400max({expr}) Number maximum value of items in {expr}
401menu_info({name} [, {mode}]) Dict get menu item information
402min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000403mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000404 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200405mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000406mzeval({expr}) any evaluate |MzScheme| expression
407nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
408nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
409or({expr}, {expr}) Number bitwise OR
410pathshorten({expr} [, {len}]) String shorten directory names in a path
411perleval({expr}) any evaluate |Perl| expression
412popup_atcursor({what}, {options}) Number create popup window near the cursor
413popup_beval({what}, {options}) Number create popup window for 'ballooneval'
414popup_clear() none close all popup windows
415popup_close({id} [, {result}]) none close popup window {id}
416popup_create({what}, {options}) Number create a popup window
417popup_dialog({what}, {options}) Number create a popup window used as a dialog
418popup_filter_menu({id}, {key}) Number filter for a menu popup window
419popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100420popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000421popup_findinfo() Number get window ID of info popup window
422popup_findpreview() Number get window ID of preview popup window
423popup_getoptions({id}) Dict get options of popup window {id}
424popup_getpos({id}) Dict get position of popup window {id}
425popup_hide({id}) none hide popup menu {id}
426popup_list() List get a list of window IDs of all popups
427popup_locate({row}, {col}) Number get window ID of popup at position
428popup_menu({what}, {options}) Number create a popup window used as a menu
429popup_move({id}, {options}) none set position of popup window {id}
430popup_notification({what}, {options})
431 Number create a notification popup window
432popup_setoptions({id}, {options})
433 none set options for popup window {id}
434popup_settext({id}, {text}) none set the text of popup window {id}
435popup_show({id}) none unhide popup window {id}
436pow({x}, {y}) Float {x} to the power of {y}
437prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
438printf({fmt}, {expr1}...) String format text
439prompt_getprompt({buf}) String get prompt text
440prompt_setcallback({buf}, {expr}) none set prompt callback function
441prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
442prompt_setprompt({buf}, {text}) none set prompt text
443prop_add({lnum}, {col}, {props}) none add one text property
444prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
445 none add multiple text properties
446prop_clear({lnum} [, {lnum-end} [, {props}]])
447 none remove all text properties
448prop_find({props} [, {direction}])
449 Dict search for a text property
450prop_list({lnum} [, {props}]) List text properties in {lnum}
451prop_remove({props} [, {lnum} [, {lnum-end}]])
452 Number remove a text property
453prop_type_add({name}, {props}) none define a new property type
454prop_type_change({name}, {props})
455 none change an existing property type
456prop_type_delete({name} [, {props}])
457 none delete a property type
458prop_type_get({name} [, {props}])
459 Dict get property type values
460prop_type_list([{props}]) List get list of property types
461pum_getpos() Dict position and size of pum if visible
462pumvisible() Number whether popup menu is visible
463py3eval({expr}) any evaluate |python3| expression
464pyeval({expr}) any evaluate |Python| expression
465pyxeval({expr}) any evaluate |python_x| expression
466rand([{expr}]) Number get pseudo-random number
467range({expr} [, {max} [, {stride}]])
468 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100469readblob({fname} [, {offset} [, {size}]])
470 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000471readdir({dir} [, {expr} [, {dict}]])
472 List file names in {dir} selected by {expr}
473readdirex({dir} [, {expr} [, {dict}]])
474 List file info in {dir} selected by {expr}
475readfile({fname} [, {type} [, {max}]])
476 List get list of lines from file {fname}
477reduce({object}, {func} [, {initial}])
478 any reduce {object} using {func}
479reg_executing() String get the executing register name
480reg_recording() String get the recording register name
481reltime([{start} [, {end}]]) List get time value
482reltimefloat({time}) Float turn the time value into a Float
483reltimestr({time}) String turn time value into a String
484remote_expr({server}, {string} [, {idvar} [, {timeout}]])
485 String send expression
486remote_foreground({server}) Number bring Vim server to the foreground
487remote_peek({serverid} [, {retvar}])
488 Number check for reply string
489remote_read({serverid} [, {timeout}])
490 String read reply string
491remote_send({server}, {string} [, {idvar}])
492 String send key sequence
493remote_startserver({name}) none become server {name}
494remove({list}, {idx} [, {end}]) any/List
495 remove items {idx}-{end} from {list}
496remove({blob}, {idx} [, {end}]) Number/Blob
497 remove bytes {idx}-{end} from {blob}
498remove({dict}, {key}) any remove entry {key} from {dict}
499rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100500repeat({expr}, {count}) List/Blob/String
501 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000502resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100503reverse({obj}) List/Blob/String
504 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000505round({expr}) Float round off {expr}
506rubyeval({expr}) any evaluate |Ruby| expression
507screenattr({row}, {col}) Number attribute at screen position
508screenchar({row}, {col}) Number character at screen position
509screenchars({row}, {col}) List List of characters at screen position
510screencol() Number current cursor column
511screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
512screenrow() Number current cursor row
513screenstring({row}, {col}) String characters at screen position
514search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
515 Number search for {pattern}
516searchcount([{options}]) Dict get or update search stats
517searchdecl({name} [, {global} [, {thisblock}]])
518 Number search for variable declaration
519searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
520 Number search for other end of start/end pair
521searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
522 List search for other end of start/end pair
523searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
524 List search for {pattern}
525server2client({clientid}, {string})
526 Number send reply string
527serverlist() String get a list of available servers
528setbufline({expr}, {lnum}, {text})
529 Number set line {lnum} to {text} in buffer
530 {expr}
531setbufvar({buf}, {varname}, {val})
532 none set {varname} in buffer {buf} to {val}
533setcellwidths({list}) none set character cell width overrides
534setcharpos({expr}, {list}) Number set the {expr} position to {list}
535setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100536setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000537setcmdpos({pos}) Number set cursor position in command-line
538setcursorcharpos({list}) Number move cursor to position in {list}
539setenv({name}, {val}) none set environment variable
540setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
541setline({lnum}, {line}) Number set line {lnum} to {line}
542setloclist({nr}, {list} [, {action}])
543 Number modify location list using {list}
544setloclist({nr}, {list}, {action}, {what})
545 Number modify specific location list props
546setmatches({list} [, {win}]) Number restore a list of matches
547setpos({expr}, {list}) Number set the {expr} position to {list}
548setqflist({list} [, {action}]) Number modify quickfix list using {list}
549setqflist({list}, {action}, {what})
550 Number modify specific quickfix list props
551setreg({n}, {v} [, {opt}]) Number set register to value and type
552settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
553settabwinvar({tabnr}, {winnr}, {varname}, {val})
554 none set {varname} in window {winnr} in tab
555 page {tabnr} to {val}
556settagstack({nr}, {dict} [, {action}])
557 Number modify tag stack using {dict}
558setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
559sha256({string}) String SHA256 checksum of {string}
560shellescape({string} [, {special}])
561 String escape {string} for use as shell
562 command argument
563shiftwidth([{col}]) Number effective value of 'shiftwidth'
564sign_define({name} [, {dict}]) Number define or update a sign
565sign_define({list}) List define or update a list of signs
566sign_getdefined([{name}]) List get a list of defined signs
567sign_getplaced([{buf} [, {dict}]])
568 List get a list of placed signs
569sign_jump({id}, {group}, {buf})
570 Number jump to a sign
571sign_place({id}, {group}, {name}, {buf} [, {dict}])
572 Number place a sign
573sign_placelist({list}) List place a list of signs
574sign_undefine([{name}]) Number undefine a sign
575sign_undefine({list}) List undefine a list of signs
576sign_unplace({group} [, {dict}])
577 Number unplace a sign
578sign_unplacelist({list}) List unplace a list of signs
579simplify({filename}) String simplify filename as much as possible
580sin({expr}) Float sine of {expr}
581sinh({expr}) Float hyperbolic sine of {expr}
582slice({expr}, {start} [, {end}]) String, List or Blob
583 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000584sort({list} [, {how} [, {dict}]])
585 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000586sound_clear() none stop playing all sounds
587sound_playevent({name} [, {callback}])
588 Number play an event sound
589sound_playfile({path} [, {callback}])
590 Number play sound file {path}
591sound_stop({id}) none stop playing sound {id}
592soundfold({word}) String sound-fold {word}
593spellbadword() String badly spelled word at cursor
594spellsuggest({word} [, {max} [, {capital}]])
595 List spelling suggestions
596split({expr} [, {pat} [, {keepempty}]])
597 List make |List| from {pat} separated {expr}
598sqrt({expr}) Float square root of {expr}
599srand([{expr}]) List get seed for |rand()|
600state([{what}]) String current state of Vim
601str2float({expr} [, {quoted}]) Float convert String to Float
602str2list({expr} [, {utf8}]) List convert each character of {expr} to
603 ASCII/UTF-8 value
604str2nr({expr} [, {base} [, {quoted}]])
605 Number convert String to Number
606strcharlen({expr}) Number character length of the String {expr}
607strcharpart({str}, {start} [, {len} [, {skipcc}]])
608 String {len} characters of {str} at
609 character {start}
610strchars({expr} [, {skipcc}]) Number character count of the String {expr}
611strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
612strftime({format} [, {time}]) String format time with a specified format
613strgetchar({str}, {index}) Number get char {index} from {str}
614stridx({haystack}, {needle} [, {start}])
615 Number index of {needle} in {haystack}
616string({expr}) String String representation of {expr} value
617strlen({expr}) Number length of the String {expr}
618strpart({str}, {start} [, {len} [, {chars}]])
619 String {len} bytes/chars of {str} at
620 byte {start}
621strptime({format}, {timestring})
622 Number Convert {timestring} to unix timestamp
623strridx({haystack}, {needle} [, {start}])
624 Number last index of {needle} in {haystack}
625strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100626strutf16len({string} [, {countcc}])
627 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000628strwidth({expr}) Number display cell length of the String {expr}
629submatch({nr} [, {list}]) String or List
630 specific match in ":s" or substitute()
631substitute({expr}, {pat}, {sub}, {flags})
632 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000633swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000634swapinfo({fname}) Dict information about swap file {fname}
635swapname({buf}) String swap file of buffer {buf}
636synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
637synIDattr({synID}, {what} [, {mode}])
638 String attribute {what} of syntax ID {synID}
639synIDtrans({synID}) Number translated syntax ID of {synID}
640synconcealed({lnum}, {col}) List info about concealing
641synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
642system({expr} [, {input}]) String output of shell command/filter {expr}
643systemlist({expr} [, {input}]) List output of shell command/filter {expr}
644tabpagebuflist([{arg}]) List list of buffer numbers in tab page
645tabpagenr([{arg}]) Number number of current or last tab page
646tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
647tagfiles() List tags files used
648taglist({expr} [, {filename}]) List list of tags matching {expr}
649tan({expr}) Float tangent of {expr}
650tanh({expr}) Float hyperbolic tangent of {expr}
651tempname() String name for a temporary file
652term_dumpdiff({filename}, {filename} [, {options}])
653 Number display difference between two dumps
654term_dumpload({filename} [, {options}])
655 Number displaying a screen dump
656term_dumpwrite({buf}, {filename} [, {options}])
657 none dump terminal window contents
658term_getaltscreen({buf}) Number get the alternate screen flag
659term_getansicolors({buf}) List get ANSI palette in GUI color mode
660term_getattr({attr}, {what}) Number get the value of attribute {what}
661term_getcursor({buf}) List get the cursor position of a terminal
662term_getjob({buf}) Job get the job associated with a terminal
663term_getline({buf}, {row}) String get a line of text from a terminal
664term_getscrolled({buf}) Number get the scroll count of a terminal
665term_getsize({buf}) List get the size of a terminal
666term_getstatus({buf}) String get the status of a terminal
667term_gettitle({buf}) String get the title of a terminal
668term_gettty({buf}, [{input}]) String get the tty name of a terminal
669term_list() List get the list of terminal buffers
670term_scrape({buf}, {row}) List get row of a terminal screen
671term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
672term_setansicolors({buf}, {colors})
673 none set ANSI palette in GUI color mode
674term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
675term_setkill({buf}, {how}) none set signal to stop job in terminal
676term_setrestore({buf}, {command}) none set command to restore terminal
677term_setsize({buf}, {rows}, {cols})
678 none set the size of a terminal
679term_start({cmd} [, {options}]) Number open a terminal window and run a job
680term_wait({buf} [, {time}]) Number wait for screen to be updated
681terminalprops() Dict properties of the terminal
682test_alloc_fail({id}, {countdown}, {repeat})
683 none make memory allocation fail
684test_autochdir() none enable 'autochdir' during startup
685test_feedinput({string}) none add key sequence to input buffer
686test_garbagecollect_now() none free memory right now for testing
687test_garbagecollect_soon() none free memory soon for testing
688test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000689test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000690test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000691test_mswin_event({event}, {args})
692 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000693test_null_blob() Blob null value for testing
694test_null_channel() Channel null value for testing
695test_null_dict() Dict null value for testing
696test_null_function() Funcref null value for testing
697test_null_job() Job null value for testing
698test_null_list() List null value for testing
699test_null_partial() Funcref null value for testing
700test_null_string() String null value for testing
701test_option_not_set({name}) none reset flag indicating option was set
702test_override({expr}, {val}) none test with Vim internal overrides
703test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000704test_setmouse({row}, {col}) none set the mouse position for testing
705test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200706test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000707test_unknown() any unknown value for testing
708test_void() any void value for testing
709timer_info([{id}]) List information about timers
710timer_pause({id}, {pause}) none pause or unpause a timer
711timer_start({time}, {callback} [, {options}])
712 Number create a timer
713timer_stop({timer}) none stop a timer
714timer_stopall() none stop all timers
715tolower({expr}) String the String {expr} switched to lowercase
716toupper({expr}) String the String {expr} switched to uppercase
717tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
718 to chars in {tostr}
719trim({text} [, {mask} [, {dir}]])
720 String trim characters in {mask} from {text}
721trunc({expr}) Float truncate Float {expr}
722type({expr}) Number type of value {expr}
723typename({expr}) String representation of the type of {expr}
724undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500725undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726uniq({list} [, {func} [, {dict}]])
727 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100728utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
729 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000730values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200731virtcol({expr} [, {list} [, {winid}])
732 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100733 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100734virtcol2col({winid}, {lnum}, {col})
735 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200736visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000737wildmenumode() Number whether 'wildmenu' mode is active
738win_execute({id}, {command} [, {silent}])
739 String execute {command} in window {id}
740win_findbuf({bufnr}) List find windows containing {bufnr}
741win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
742win_gettype([{nr}]) String type of window {nr}
743win_gotoid({expr}) Number go to window with ID {expr}
744win_id2tabwin({expr}) List get tab and window nr from window ID
745win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000746win_move_separator({nr}) Number move window vertical separator
747win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000748win_screenpos({nr}) List get screen position of window {nr}
749win_splitmove({nr}, {target} [, {options}])
750 Number move window {nr} to split of {target}
751winbufnr({nr}) Number buffer number of window {nr}
752wincol() Number window column of the cursor
753windowsversion() String MS-Windows OS version
754winheight({nr}) Number height of window {nr}
755winlayout([{tabnr}]) List layout of windows in tab {tabnr}
756winline() Number window line of the cursor
757winnr([{expr}]) Number number of current window
758winrestcmd() String returns command to restore window sizes
759winrestview({dict}) none restore view of current window
760winsaveview() Dict save view of current window
761winwidth({nr}) Number width of window {nr}
762wordcount() Dict get byte/char/word statistics
763writefile({object}, {fname} [, {flags}])
764 Number write |Blob| or |List| of lines to file
765xor({expr}, {expr}) Number bitwise XOR
766
767==============================================================================
7682. Details *builtin-function-details*
769
770Not all functions are here, some have been moved to a help file covering the
771specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200772Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000773
774abs({expr}) *abs()*
775 Return the absolute value of {expr}. When {expr} evaluates to
776 a |Float| abs() returns a |Float|. When {expr} can be
777 converted to a |Number| abs() returns a |Number|. Otherwise
778 abs() gives an error message and returns -1.
779 Examples: >
780 echo abs(1.456)
781< 1.456 >
782 echo abs(-5.456)
783< 5.456 >
784 echo abs(-4)
785< 4
786
787 Can also be used as a |method|: >
788 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200789<
790 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000792
793acos({expr}) *acos()*
794 Return the arc cosine of {expr} measured in radians, as a
795 |Float| in the range of [0, pi].
796 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100797 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000798 Examples: >
799 :echo acos(0)
800< 1.570796 >
801 :echo acos(-0.5)
802< 2.094395
803
804 Can also be used as a |method|: >
805 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200806<
807 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000809
810add({object}, {expr}) *add()*
811 Append the item {expr} to |List| or |Blob| {object}. Returns
812 the resulting |List| or |Blob|. Examples: >
813 :let alist = add([1, 2, 3], item)
814 :call add(mylist, "woodstock")
815< Note that when {expr} is a |List| it is appended as a single
816 item. Use |extend()| to concatenate |Lists|.
817 When {object} is a |Blob| then {expr} must be a number.
818 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100819 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000820
821 Can also be used as a |method|: >
822 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200823<
824 Return type: list<{type}> (depending on the given |List|) or
825 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000826
827
828and({expr}, {expr}) *and()*
829 Bitwise AND on the two arguments. The arguments are converted
830 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100831 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000832 Example: >
833 :let flag = and(bits, 0x80)
834< Can also be used as a |method|: >
835 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200836<
837 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000838
839
840append({lnum}, {text}) *append()*
841 When {text} is a |List|: Append each item of the |List| as a
842 text line below line {lnum} in the current buffer.
843 Otherwise append {text} as one text line below line {lnum} in
844 the current buffer.
845 Any type of item is accepted and converted to a String.
846 {lnum} can be zero to insert a line before the first one.
847 {lnum} is used like with |getline()|.
848 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000849 0 for success. When {text} is an empty list zero is returned,
850 no matter the value of {lnum}.
851 In |Vim9| script an invalid argument or negative number
852 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000853 :let failed = append(line('$'), "# THE END")
854 :let failed = append(0, ["Chapter 1", "the beginning"])
855
856< Can also be used as a |method| after a List, the base is
857 passed as the second argument: >
858 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200859<
860 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000861
862
863appendbufline({buf}, {lnum}, {text}) *appendbufline()*
864 Like |append()| but append the text in buffer {buf}.
865
866 This function works only for loaded buffers. First call
867 |bufload()| if needed.
868
869 For the use of {buf}, see |bufname()|.
870
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000871 {lnum} is the line number to append below. Note that using
872 |line()| would use the current buffer, not the one appending
873 to. Use "$" to append at the end of the buffer. Other string
874 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000875
876 On success 0 is returned, on failure 1 is returned.
877 In |Vim9| script an error is given for an invalid {lnum}.
878
879 If {buf} is not a valid buffer or {lnum} is not valid, an
880 error message is given. Example: >
881 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000882< However, when {text} is an empty list then no error is given
883 for an invalid {lnum}, since {lnum} isn't actually used.
884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000885 Can also be used as a |method| after a List, the base is
886 passed as the second argument: >
887 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200888<
889 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000890
891
892argc([{winid}]) *argc()*
893 The result is the number of files in the argument list. See
894 |arglist|.
895 If {winid} is not supplied, the argument list of the current
896 window is used.
897 If {winid} is -1, the global argument list is used.
898 Otherwise {winid} specifies the window of which the argument
899 list is used: either the window number or the window ID.
900 Returns -1 if the {winid} argument is invalid.
901
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200902 Return type: |Number|
903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000904 *argidx()*
905argidx() The result is the current index in the argument list. 0 is
906 the first file. argc() - 1 is the last one. See |arglist|.
907
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200908 Return type: |Number|
909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910 *arglistid()*
911arglistid([{winnr} [, {tabnr}]])
912 Return the argument list ID. This is a number which
913 identifies the argument list being used. Zero is used for the
914 global argument list. See |arglist|.
915 Returns -1 if the arguments are invalid.
916
917 Without arguments use the current window.
918 With {winnr} only use this window in the current tab page.
919 With {winnr} and {tabnr} use the window in the specified tab
920 page.
921 {winnr} can be the window number or the |window-ID|.
922
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200923 Return type: |Number|
924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000925 *argv()*
926argv([{nr} [, {winid}]])
927 The result is the {nr}th file in the argument list. See
928 |arglist|. "argv(0)" is the first one. Example: >
929 :let i = 0
930 :while i < argc()
931 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000932 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000933 : let i = i + 1
934 :endwhile
935< Without the {nr} argument, or when {nr} is -1, a |List| with
936 the whole |arglist| is returned.
937
938 The {winid} argument specifies the window ID, see |argc()|.
939 For the Vim command line arguments see |v:argv|.
940
Bram Moolenaar016188f2022-06-06 20:52:59 +0100941 Returns an empty string if {nr}th argument is not present in
942 the argument list. Returns an empty List if the {winid}
943 argument is invalid.
944
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200945 Return type: |String|
946
947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000948asin({expr}) *asin()*
949 Return the arc sine of {expr} measured in radians, as a |Float|
950 in the range of [-pi/2, pi/2].
951 {expr} must evaluate to a |Float| or a |Number| in the range
952 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100953 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
954 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000955 Examples: >
956 :echo asin(0.8)
957< 0.927295 >
958 :echo asin(-0.5)
959< -0.523599
960
961 Can also be used as a |method|: >
962 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200963<
964 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000965
966assert_ functions are documented here: |assert-functions-details|
967
968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969atan({expr}) *atan()*
970 Return the principal value of the arc tangent of {expr}, in
971 the range [-pi/2, +pi/2] radians, as a |Float|.
972 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100973 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000974 Examples: >
975 :echo atan(100)
976< 1.560797 >
977 :echo atan(-4.01)
978< -1.326405
979
980 Can also be used as a |method|: >
981 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200982<
983 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984
985
986atan2({expr1}, {expr2}) *atan2()*
987 Return the arc tangent of {expr1} / {expr2}, measured in
988 radians, as a |Float| in the range [-pi, pi].
989 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100990 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
991 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000992 Examples: >
993 :echo atan2(-1, 1)
994< -0.785398 >
995 :echo atan2(1, -1)
996< 2.356194
997
998 Can also be used as a |method|: >
999 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001000<
1001 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001003
1004autocmd_add({acmds}) *autocmd_add()*
1005 Adds a List of autocmds and autocmd groups.
1006
1007 The {acmds} argument is a List where each item is a Dict with
1008 the following optional items:
1009 bufnr buffer number to add a buffer-local autocmd.
1010 If this item is specified, then the "pattern"
1011 item is ignored.
1012 cmd Ex command to execute for this autocmd event
1013 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001014 This can be either a String with a single
1015 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001016 group autocmd group name. Refer to |autocmd-groups|.
1017 If this group doesn't exist then it is
1018 created. If not specified or empty, then the
1019 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001020 nested boolean flag, set to v:true to add a nested
1021 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001022 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001023 which executes only once. Refer to
1024 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001025 pattern autocmd pattern string. Refer to
1026 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001027 present, then this item is ignored. This can
1028 be a String with a single pattern or a List of
1029 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 replace boolean flag, set to v:true to remove all the
1031 commands associated with the specified autocmd
1032 event and group and add the {cmd}. This is
1033 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001034 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001035
1036 Returns v:true on success and v:false on failure.
1037 Examples: >
1038 " Create a buffer-local autocmd for buffer 5
1039 let acmd = {}
1040 let acmd.group = 'MyGroup'
1041 let acmd.event = 'BufEnter'
1042 let acmd.bufnr = 5
1043 let acmd.cmd = 'call BufEnterFunc()'
1044 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001045<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001046 Can also be used as a |method|: >
1047 GetAutocmdList()->autocmd_add()
1048<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001049 Return type: |vim9-boolean|
1050
1051
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001052autocmd_delete({acmds}) *autocmd_delete()*
1053 Deletes a List of autocmds and autocmd groups.
1054
1055 The {acmds} argument is a List where each item is a Dict with
1056 the following optional items:
1057 bufnr buffer number to delete a buffer-local autocmd.
1058 If this item is specified, then the "pattern"
1059 item is ignored.
1060 cmd Ex command for this autocmd event
1061 event autocmd event name. Refer to |autocmd-events|.
1062 If '*' then all the autocmd events in this
1063 group are deleted.
1064 group autocmd group name. Refer to |autocmd-groups|.
1065 If not specified or empty, then the default
1066 group is used.
1067 nested set to v:true for a nested autocmd.
1068 Refer to |autocmd-nested|.
1069 once set to v:true for an autocmd which executes
1070 only once. Refer to |autocmd-once|.
1071 pattern autocmd pattern string. Refer to
1072 |autocmd-patterns|. If "bufnr" item is
1073 present, then this item is ignored.
1074
1075 If only {group} is specified in a {acmds} entry and {event},
1076 {pattern} and {cmd} are not specified, then that autocmd group
1077 is deleted.
1078
Bram Moolenaar016188f2022-06-06 20:52:59 +01001079 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001080 Examples: >
1081 " :autocmd! BufLeave *.vim
1082 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1083 call autocmd_delete([acmd]})
1084 " :autocmd! MyGroup1 BufLeave
1085 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1086 call autocmd_delete([acmd])
1087 " :autocmd! MyGroup2 BufEnter *.c
1088 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1089 \ pattern: '*.c'}
1090 " :autocmd! MyGroup2 * *.c
1091 let acmd = #{group: 'MyGroup2', event: '*',
1092 \ pattern: '*.c'}
1093 call autocmd_delete([acmd])
1094 " :autocmd! MyGroup3
1095 let acmd = #{group: 'MyGroup3'}
1096 call autocmd_delete([acmd])
1097<
1098 Can also be used as a |method|: >
1099 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001100<
1101 Return type: |vim9-boolean|
1102
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001103
1104autocmd_get([{opts}]) *autocmd_get()*
1105 Returns a |List| of autocmds. If {opts} is not supplied, then
1106 returns the autocmds for all the events in all the groups.
1107
1108 The optional {opts} Dict argument supports the following
1109 items:
1110 group Autocmd group name. If specified, returns only
1111 the autocmds defined in this group. If the
1112 specified group doesn't exist, results in an
1113 error message. If set to an empty string,
1114 then the default autocmd group is used.
1115 event Autocmd event name. If specified, returns only
1116 the autocmds defined for this event. If set
1117 to "*", then returns autocmds for all the
1118 events. If the specified event doesn't exist,
1119 results in an error message.
1120 pattern Autocmd pattern. If specified, returns only
1121 the autocmds defined for this pattern.
1122 A combination of the above three times can be supplied in
1123 {opts}.
1124
1125 Each Dict in the returned List contains the following items:
1126 bufnr For buffer-local autocmds, buffer number where
1127 the autocmd is defined.
1128 cmd Command executed for this autocmd.
1129 event Autocmd event name.
1130 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001131 nested Boolean flag, set to v:true for a nested
1132 autocmd. See |autocmd-nested|.
1133 once Boolean flag, set to v:true, if the autocmd
1134 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001135 pattern Autocmd pattern. For a buffer-local
1136 autocmd, this will be of the form "<buffer=n>".
1137 If there are multiple commands for an autocmd event in a
1138 group, then separate items are returned for each command.
1139
Bram Moolenaar016188f2022-06-06 20:52:59 +01001140 Returns an empty List if an autocmd with the specified group
1141 or event or pattern is not found.
1142
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001143 Examples: >
1144 " :autocmd MyGroup
1145 echo autocmd_get(#{group: 'Mygroup'})
1146 " :autocmd G BufUnload
1147 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1148 " :autocmd G * *.ts
1149 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1150 echo autocmd_get(acmd)
1151 " :autocmd Syntax
1152 echo autocmd_get(#{event: 'Syntax'})
1153 " :autocmd G BufEnter *.ts
1154 let acmd = #{group: 'G', event: 'BufEnter',
1155 \ pattern: '*.ts'}
1156 echo autocmd_get(acmd)
1157<
1158 Can also be used as a |method|: >
1159 Getopts()->autocmd_get()
1160<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001161 Return type: list<dict<any>>
1162
1163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001164balloon_gettext() *balloon_gettext()*
1165 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001166 not used for the List. Returns an empty string if balloon
1167 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001168
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001169 Return type: |String|
1170
1171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001172balloon_show({expr}) *balloon_show()*
1173 Show {expr} inside the balloon. For the GUI {expr} is used as
1174 a string. For a terminal {expr} can be a list, which contains
1175 the lines of the balloon. If {expr} is not a list it will be
1176 split with |balloon_split()|.
1177 If {expr} is an empty string any existing balloon is removed.
1178
1179 Example: >
1180 func GetBalloonContent()
1181 " ... initiate getting the content
1182 return ''
1183 endfunc
1184 set balloonexpr=GetBalloonContent()
1185
1186 func BalloonCallback(result)
1187 call balloon_show(a:result)
1188 endfunc
1189< Can also be used as a |method|: >
1190 GetText()->balloon_show()
1191<
1192 The intended use is that fetching the content of the balloon
1193 is initiated from 'balloonexpr'. It will invoke an
1194 asynchronous method, in which a callback invokes
1195 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001196 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001197
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001198 When showing a balloon is not possible then nothing happens,
1199 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001200 {only available when compiled with the |+balloon_eval| or
1201 |+balloon_eval_term| feature}
1202
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001203 Return type: |Number|
1204
1205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001206balloon_split({msg}) *balloon_split()*
1207 Split String {msg} into lines to be displayed in a balloon.
1208 The splits are made for the current window size and optimize
1209 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001210 Returns a |List| with the split lines. Returns an empty List
1211 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001212 Can also be used as a |method|: >
1213 GetText()->balloon_split()->balloon_show()
1214
1215< {only available when compiled with the |+balloon_eval_term|
1216 feature}
1217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001218 Return type: list<any> or list<string>
1219
1220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001221blob2list({blob}) *blob2list()*
1222 Return a List containing the number value of each byte in Blob
1223 {blob}. Examples: >
1224 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1225 blob2list(0z) returns []
1226< Returns an empty List on error. |list2blob()| does the
1227 opposite.
1228
1229 Can also be used as a |method|: >
1230 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001231<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001232 Return type: list<any> or list<number>
1233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001234 *browse()*
1235browse({save}, {title}, {initdir}, {default})
1236 Put up a file requester. This only works when "has("browse")"
1237 returns |TRUE| (only in some GUI versions).
1238 The input fields are:
1239 {save} when |TRUE|, select file to write
1240 {title} title for the requester
1241 {initdir} directory to start browsing in
1242 {default} default file name
1243 An empty string is returned when the "Cancel" button is hit,
1244 something went wrong, or browsing is not possible.
1245
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001246 Return type: |String|
1247
1248
1249browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001250 Put up a directory requester. This only works when
1251 "has("browse")" returns |TRUE| (only in some GUI versions).
1252 On systems where a directory browser is not supported a file
1253 browser is used. In that case: select a file in the directory
1254 to be used.
1255 The input fields are:
1256 {title} title for the requester
1257 {initdir} directory to start browsing in
1258 When the "Cancel" button is hit, something went wrong, or
1259 browsing is not possible, an empty string is returned.
1260
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001261 Return type: |String|
1262
1263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001264bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001265 Add a buffer to the buffer list with name {name} (must be a
1266 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001267 If a buffer for file {name} already exists, return that buffer
1268 number. Otherwise return the buffer number of the newly
1269 created buffer. When {name} is an empty string then a new
1270 buffer is always created.
1271 The buffer will not have 'buflisted' set and not be loaded
1272 yet. To add some text to the buffer use this: >
1273 let bufnr = bufadd('someName')
1274 call bufload(bufnr)
1275 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001276< Returns 0 on error.
1277 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001279<
1280 Return type: |Number|
1281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282
1283bufexists({buf}) *bufexists()*
1284 The result is a Number, which is |TRUE| if a buffer called
1285 {buf} exists.
1286 If the {buf} argument is a number, buffer numbers are used.
1287 Number zero is the alternate buffer for the current window.
1288
1289 If the {buf} argument is a string it must match a buffer name
1290 exactly. The name can be:
1291 - Relative to the current directory.
1292 - A full path.
1293 - The name of a buffer with 'buftype' set to "nofile".
1294 - A URL name.
1295 Unlisted buffers will be found.
1296 Note that help files are listed by their short name in the
1297 output of |:buffers|, but bufexists() requires using their
1298 long name to be able to find them.
1299 bufexists() may report a buffer exists, but to use the name
1300 with a |:buffer| command you may need to use |expand()|. Esp
1301 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1302 Use "bufexists(0)" to test for the existence of an alternate
1303 file name.
1304
1305 Can also be used as a |method|: >
1306 let exists = 'somename'->bufexists()
1307<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001308 Return type: |Number|
1309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001310 Obsolete name: buffer_exists(). *buffer_exists()*
1311
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001313buflisted({buf}) *buflisted()*
1314 The result is a Number, which is |TRUE| if a buffer called
1315 {buf} exists and is listed (has the 'buflisted' option set).
1316 The {buf} argument is used like with |bufexists()|.
1317
1318 Can also be used as a |method|: >
1319 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001320<
1321 Return type: |Number|
1322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001323
1324bufload({buf}) *bufload()*
1325 Ensure the buffer {buf} is loaded. When the buffer name
1326 refers to an existing file then the file is read. Otherwise
1327 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001328 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001329 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001330 If there is an existing swap file for the file of the buffer,
1331 there will be no dialog, the buffer will be loaded anyway.
1332 The {buf} argument is used like with |bufexists()|.
1333
1334 Can also be used as a |method|: >
1335 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001336<
1337 Return type: |Number|
1338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001339
1340bufloaded({buf}) *bufloaded()*
1341 The result is a Number, which is |TRUE| if a buffer called
1342 {buf} exists and is loaded (shown in a window or hidden).
1343 The {buf} argument is used like with |bufexists()|.
1344
1345 Can also be used as a |method|: >
1346 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001347<
1348 Return type: |Number|
1349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001350
1351bufname([{buf}]) *bufname()*
1352 The result is the name of a buffer. Mostly as it is displayed
1353 by the `:ls` command, but not using special names such as
1354 "[No Name]".
1355 If {buf} is omitted the current buffer is used.
1356 If {buf} is a Number, that buffer number's name is given.
1357 Number zero is the alternate buffer for the current window.
1358 If {buf} is a String, it is used as a |file-pattern| to match
1359 with the buffer names. This is always done like 'magic' is
1360 set and 'cpoptions' is empty. When there is more than one
1361 match an empty string is returned.
1362 "" or "%" can be used for the current buffer, "#" for the
1363 alternate buffer.
1364 A full match is preferred, otherwise a match at the start, end
1365 or middle of the buffer name is accepted. If you only want a
1366 full match then put "^" at the start and "$" at the end of the
1367 pattern.
1368 Listed buffers are found first. If there is a single match
1369 with a listed buffer, that one is returned. Next unlisted
1370 buffers are searched for.
1371 If the {buf} is a String, but you want to use it as a buffer
1372 number, force it to be a Number by adding zero to it: >
1373 :echo bufname("3" + 0)
1374< Can also be used as a |method|: >
1375 echo bufnr->bufname()
1376
1377< If the buffer doesn't exist, or doesn't have a name, an empty
1378 string is returned. >
1379 bufname("#") alternate buffer name
1380 bufname(3) name of buffer 3
1381 bufname("%") name of current buffer
1382 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001383<
1384 Return type: |String|
1385 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001386 Obsolete name: buffer_name().
1387
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001388
1389bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001390 The result is the number of a buffer, as it is displayed by
1391 the `:ls` command. For the use of {buf}, see |bufname()|
1392 above.
1393
1394 If the buffer doesn't exist, -1 is returned. Or, if the
1395 {create} argument is present and TRUE, a new, unlisted,
1396 buffer is created and its number is returned. Example: >
1397 let newbuf = bufnr('Scratch001', 1)
1398< Using an empty name uses the current buffer. To create a new
1399 buffer with an empty name use |bufadd()|.
1400
1401 bufnr("$") is the last buffer: >
1402 :let last_buffer = bufnr("$")
1403< The result is a Number, which is the highest buffer number
1404 of existing buffers. Note that not all buffers with a smaller
1405 number necessarily exist, because ":bwipeout" may have removed
1406 them. Use bufexists() to test for the existence of a buffer.
1407
1408 Can also be used as a |method|: >
1409 echo bufref->bufnr()
1410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001411 Return type: |Number|
1412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001413 Obsolete name: buffer_number(). *buffer_number()*
1414 *last_buffer_nr()*
1415 Obsolete name for bufnr("$"): last_buffer_nr().
1416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001418bufwinid({buf}) *bufwinid()*
1419 The result is a Number, which is the |window-ID| of the first
1420 window associated with buffer {buf}. For the use of {buf},
1421 see |bufname()| above. If buffer {buf} doesn't exist or
1422 there is no such window, -1 is returned. Example: >
1423
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001424 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001425<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001426 Only deals with the current tab page. See |win_findbuf()| for
1427 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001428
1429 Can also be used as a |method|: >
1430 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001431<
1432 Return type: |Number|
1433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001434
1435bufwinnr({buf}) *bufwinnr()*
1436 Like |bufwinid()| but return the window number instead of the
1437 |window-ID|.
1438 If buffer {buf} doesn't exist or there is no such window, -1
1439 is returned. Example: >
1440
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001441 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001442
1443< The number can be used with |CTRL-W_w| and ":wincmd w"
1444 |:wincmd|.
1445
1446 Can also be used as a |method|: >
1447 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001448<
1449 Return type: |Number|
1450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001451
1452byte2line({byte}) *byte2line()*
1453 Return the line number that contains the character at byte
1454 count {byte} in the current buffer. This includes the
1455 end-of-line character, depending on the 'fileformat' option
1456 for the current buffer. The first character has byte count
1457 one.
1458 Also see |line2byte()|, |go| and |:goto|.
1459
Bram Moolenaar016188f2022-06-06 20:52:59 +01001460 Returns -1 if the {byte} value is invalid.
1461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001462 Can also be used as a |method|: >
1463 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001464<
1465 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001466
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001467 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001468 feature}
1469
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001470
Christian Brabandt67672ef2023-04-24 21:09:54 +01001471byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001472 Return byte index of the {nr}'th character in the String
1473 {expr}. Use zero for the first character, it then returns
1474 zero.
1475 If there are no multibyte characters the returned value is
1476 equal to {nr}.
1477 Composing characters are not counted separately, their byte
1478 length is added to the preceding base character. See
1479 |byteidxcomp()| below for counting composing characters
1480 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001481 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1482 index in the String {expr} instead of as the character index.
1483 The UTF-16 index is the index in the string when it is encoded
1484 with 16-bit words. If the specified UTF-16 index is in the
1485 middle of a character (e.g. in a 4-byte character), then the
1486 byte index of the first byte in the character is returned.
1487 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001488 Example : >
1489 echo matchstr(str, ".", byteidx(str, 3))
1490< will display the fourth character. Another way to do the
1491 same: >
1492 let s = strpart(str, byteidx(str, 3))
1493 echo strpart(s, 0, byteidx(s, 1))
1494< Also see |strgetchar()| and |strcharpart()|.
1495
1496 If there are less than {nr} characters -1 is returned.
1497 If there are exactly {nr} characters the length of the string
1498 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001499 See |charidx()| and |utf16idx()| for getting the character and
1500 UTF-16 index respectively from the byte index.
1501 Examples: >
1502 echo byteidx('a😊😊', 2) returns 5
1503 echo byteidx('a😊😊', 2, 1) returns 1
1504 echo byteidx('a😊😊', 3, 1) returns 5
1505<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001506 Can also be used as a |method|: >
1507 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001508<
1509 Return type: |Number|
1510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001511
Christian Brabandt67672ef2023-04-24 21:09:54 +01001512byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001513 Like byteidx(), except that a composing character is counted
1514 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001515 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001516 echo byteidx(s, 1)
1517 echo byteidxcomp(s, 1)
1518 echo byteidxcomp(s, 2)
1519< The first and third echo result in 3 ('e' plus composing
1520 character is 3 bytes), the second echo results in 1 ('e' is
1521 one byte).
1522 Only works differently from byteidx() when 'encoding' is set
1523 to a Unicode encoding.
1524
1525 Can also be used as a |method|: >
1526 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001527<
1528 Return type: |Number|
1529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530
1531call({func}, {arglist} [, {dict}]) *call()* *E699*
1532 Call function {func} with the items in |List| {arglist} as
1533 arguments.
1534 {func} can either be a |Funcref| or the name of a function.
1535 a:firstline and a:lastline are set to the cursor line.
1536 Returns the return value of the called function.
1537 {dict} is for functions with the "dict" attribute. It will be
1538 used to set the local variable "self". |Dictionary-function|
1539
1540 Can also be used as a |method|: >
1541 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001542<
1543 Return type: any, depending on {func}
1544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001545
1546ceil({expr}) *ceil()*
1547 Return the smallest integral value greater than or equal to
1548 {expr} as a |Float| (round up).
1549 {expr} must evaluate to a |Float| or a |Number|.
1550 Examples: >
1551 echo ceil(1.456)
1552< 2.0 >
1553 echo ceil(-5.456)
1554< -5.0 >
1555 echo ceil(4.0)
1556< 4.0
1557
Bram Moolenaar016188f2022-06-06 20:52:59 +01001558 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560 Can also be used as a |method|: >
1561 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001562<
1563 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001564
1565
1566ch_ functions are documented here: |channel-functions-details|
1567
1568
1569changenr() *changenr()*
1570 Return the number of the most recent change. This is the same
1571 number as what is displayed with |:undolist| and can be used
1572 with the |:undo| command.
1573 When a change was made it is the number of that change. After
1574 redo it is the number of the redone change. After undo it is
1575 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001576 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001578 Return type: |Number|
1579
1580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001582 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001583 Examples: >
1584 char2nr(" ") returns 32
1585 char2nr("ABC") returns 65
1586< When {utf8} is omitted or zero, the current 'encoding' is used.
1587 Example for "utf-8": >
1588 char2nr("á") returns 225
1589 char2nr("á"[0]) returns 195
1590< When {utf8} is TRUE, always treat as UTF-8 characters.
1591 A combining character is a separate character.
1592 |nr2char()| does the opposite.
1593 To turn a string into a list of character numbers: >
1594 let str = "ABC"
1595 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1596< Result: [65, 66, 67]
1597
Bram Moolenaar016188f2022-06-06 20:52:59 +01001598 Returns 0 if {string} is not a |String|.
1599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001600 Can also be used as a |method|: >
1601 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001602<
1603 Return type: |Number|
1604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001606charclass({string}) *charclass()*
1607 Return the character class of the first character in {string}.
1608 The character class is one of:
1609 0 blank
1610 1 punctuation
1611 2 word character
1612 3 emoji
1613 other specific Unicode class
1614 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001616
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001617 Return type: |Number|
1618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001619
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001620charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001621 Same as |col()| but returns the character index of the column
1622 position given with {expr} instead of the byte position.
1623
1624 Example:
1625 With the cursor on '세' in line 5 with text "여보세요": >
1626 charcol('.') returns 3
1627 col('.') returns 7
1628
1629< Can also be used as a |method|: >
1630 GetPos()->col()
1631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001632 Return type: |Number|
1633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001635charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001636 Return the character index of the byte at {idx} in {string}.
1637 The index of the first character is zero.
1638 If there are no multibyte characters the returned value is
1639 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001641 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001642 are not counted separately, their byte length is added to the
1643 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001644 When {countcc} is |TRUE|, then composing characters are
1645 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001646
1647 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1648 index in the String {expr} instead of as the byte index.
1649
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001650 Returns -1 if the arguments are invalid or if there are less
1651 than {idx} bytes. If there are exactly {idx} bytes the length
1652 of the string in characters is returned.
1653
1654 An error is given and -1 is returned if the first argument is
1655 not a string, the second argument is not a number or when the
1656 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001659 from the character index and |utf16idx()| for getting the
1660 UTF-16 index from the character index.
1661 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662 Examples: >
1663 echo charidx('áb́ć', 3) returns 1
1664 echo charidx('áb́ć', 6, 1) returns 4
1665 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001666 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001667<
1668 Can also be used as a |method|: >
1669 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001670<
1671 Return type: |Number|
1672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
1674chdir({dir}) *chdir()*
1675 Change the current working directory to {dir}. The scope of
1676 the directory change depends on the directory of the current
1677 window:
1678 - If the current window has a window-local directory
1679 (|:lcd|), then changes the window local directory.
1680 - Otherwise, if the current tabpage has a local
1681 directory (|:tcd|) then changes the tabpage local
1682 directory.
1683 - Otherwise, changes the global directory.
1684 {dir} must be a String.
1685 If successful, returns the previous working directory. Pass
1686 this to another chdir() to restore the directory.
1687 On failure, returns an empty string.
1688
1689 Example: >
1690 let save_dir = chdir(newdir)
1691 if save_dir != ""
1692 " ... do some work
1693 call chdir(save_dir)
1694 endif
1695
1696< Can also be used as a |method|: >
1697 GetDir()->chdir()
1698<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001699 Return type: |String|
1700
1701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001702cindent({lnum}) *cindent()*
1703 Get the amount of indent for line {lnum} according the C
1704 indenting rules, as with 'cindent'.
1705 The indent is counted in spaces, the value of 'tabstop' is
1706 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001707 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001708 See |C-indenting|.
1709
1710 Can also be used as a |method|: >
1711 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001712<
1713 Return type: |Number|
1714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715
1716clearmatches([{win}]) *clearmatches()*
1717 Clears all matches previously defined for the current window
1718 by |matchadd()| and the |:match| commands.
1719 If {win} is specified, use the window with this number or
1720 window ID instead of the current window.
1721
1722 Can also be used as a |method|: >
1723 GetWin()->clearmatches()
1724<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001725 Return type: |Number|
1726
1727
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001728col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001729 The result is a Number, which is the byte index of the column
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730 position given with {expr}. The accepted positions are:
1731 . the cursor position
1732 $ the end of the cursor line (the result is the
1733 number of bytes in the cursor line plus one)
1734 'x position of mark x (if the mark is not set, 0 is
1735 returned)
1736 v In Visual mode: the start of the Visual area (the
1737 cursor is the end). When not in Visual mode
1738 returns the cursor position. Differs from |'<| in
1739 that it's updated right away.
1740 Additionally {expr} can be [lnum, col]: a |List| with the line
1741 and column number. Most useful when the column is "$", to get
1742 the last column of a specific line. When "lnum" or "col" is
1743 out of range then col() returns zero.
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001744 With the optional {winid} argument the values are obtained for
1745 that window instead of the current window.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001746 To get the line number use |line()|. To get both use
1747 |getpos()|.
1748 For the screen column position use |virtcol()|. For the
1749 character position use |charcol()|.
1750 Note that only marks in the current file can be used.
1751 Examples: >
1752 col(".") column of cursor
1753 col("$") length of cursor line plus one
1754 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001755 col("'" .. markname) column of mark markname
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001756< The first column is 1. Returns 0 if {expr} is invalid or when
1757 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001758 For an uppercase mark the column may actually be in another
1759 buffer.
1760 For the cursor position, when 'virtualedit' is active, the
1761 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001762 line. Also, when using a <Cmd> mapping the cursor isn't
1763 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001764 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765
1766< Can also be used as a |method|: >
1767 GetPos()->col()
1768<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001769 Return type: |Number|
1770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771
1772complete({startcol}, {matches}) *complete()* *E785*
1773 Set the matches for Insert mode completion.
1774 Can only be used in Insert mode. You need to use a mapping
1775 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1776 or with an expression mapping.
1777 {startcol} is the byte offset in the line where the completed
1778 text start. The text up to the cursor is the original text
1779 that will be replaced by the matches. Use col('.') for an
1780 empty string. "col('.') - 1" will replace one character by a
1781 match.
1782 {matches} must be a |List|. Each |List| item is one match.
1783 See |complete-items| for the kind of items that are possible.
1784 "longest" in 'completeopt' is ignored.
1785 Note that the after calling this function you need to avoid
1786 inserting anything that would cause completion to stop.
1787 The match can be selected with CTRL-N and CTRL-P as usual with
1788 Insert mode completion. The popup menu will appear if
1789 specified, see |ins-completion-menu|.
1790 Example: >
1791 inoremap <F5> <C-R>=ListMonths()<CR>
1792
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001793 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001794 call complete(col('.'), ['January', 'February', 'March',
1795 \ 'April', 'May', 'June', 'July', 'August', 'September',
1796 \ 'October', 'November', 'December'])
1797 return ''
1798 endfunc
1799< This isn't very useful, but it shows how it works. Note that
1800 an empty string is returned to avoid a zero being inserted.
1801
1802 Can also be used as a |method|, the base is passed as the
1803 second argument: >
1804 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001805<
1806 Return type: |Number|
1807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001808
1809complete_add({expr}) *complete_add()*
1810 Add {expr} to the list of matches. Only to be used by the
1811 function specified with the 'completefunc' option.
1812 Returns 0 for failure (empty string or out of memory),
1813 1 when the match was added, 2 when the match was already in
1814 the list.
1815 See |complete-functions| for an explanation of {expr}. It is
1816 the same as one item in the list that 'omnifunc' would return.
1817
1818 Can also be used as a |method|: >
1819 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001820<
1821 Return type: |Number|
1822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001823
1824complete_check() *complete_check()*
1825 Check for a key typed while looking for completion matches.
1826 This is to be used when looking for matches takes some time.
1827 Returns |TRUE| when searching for matches is to be aborted,
1828 zero otherwise.
1829 Only to be used by the function specified with the
1830 'completefunc' option.
1831
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001832 Return type: |Number|
1833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001834
1835complete_info([{what}]) *complete_info()*
1836 Returns a |Dictionary| with information about Insert mode
1837 completion. See |ins-completion|.
1838 The items are:
1839 mode Current completion mode name string.
1840 See |complete_info_mode| for the values.
1841 pum_visible |TRUE| if popup menu is visible.
1842 See |pumvisible()|.
1843 items List of completion matches. Each item is a
1844 dictionary containing the entries "word",
1845 "abbr", "menu", "kind", "info" and "user_data".
1846 See |complete-items|.
1847 selected Selected item index. First index is zero.
1848 Index is -1 if no item is selected (showing
1849 typed text only, or the last completion after
1850 no item is selected when using the <Up> or
1851 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001852 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001853
1854 *complete_info_mode*
1855 mode values are:
1856 "" Not in completion mode
1857 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1858 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1859 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1860 |i_CTRL-X_CTRL-Y|
1861 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1862 "files" File names |i_CTRL-X_CTRL-F|
1863 "tags" Tags |i_CTRL-X_CTRL-]|
1864 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1865 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1866 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1867 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1868 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1869 "function" User defined completion |i_CTRL-X_CTRL-U|
1870 "omni" Omni completion |i_CTRL-X_CTRL-O|
1871 "spell" Spelling suggestions |i_CTRL-X_s|
1872 "eval" |complete()| completion
1873 "unknown" Other internal modes
1874
1875 If the optional {what} list argument is supplied, then only
1876 the items listed in {what} are returned. Unsupported items in
1877 {what} are silently ignored.
1878
1879 To get the position and size of the popup menu, see
1880 |pum_getpos()|. It's also available in |v:event| during the
1881 |CompleteChanged| event.
1882
Bram Moolenaar016188f2022-06-06 20:52:59 +01001883 Returns an empty |Dictionary| on error.
1884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001885 Examples: >
1886 " Get all items
1887 call complete_info()
1888 " Get only 'mode'
1889 call complete_info(['mode'])
1890 " Get only 'mode' and 'pum_visible'
1891 call complete_info(['mode', 'pum_visible'])
1892
1893< Can also be used as a |method|: >
1894 GetItems()->complete_info()
1895<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001896 Return type: dict<any>
1897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001898 *confirm()*
1899confirm({msg} [, {choices} [, {default} [, {type}]]])
1900 confirm() offers the user a dialog, from which a choice can be
1901 made. It returns the number of the choice. For the first
1902 choice this is 1.
1903 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001904 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001905
1906 {msg} is displayed in a |dialog| with {choices} as the
1907 alternatives. When {choices} is missing or empty, "&OK" is
1908 used (and translated).
1909 {msg} is a String, use '\n' to include a newline. Only on
1910 some systems the string is wrapped when it doesn't fit.
1911
1912 {choices} is a String, with the individual choices separated
1913 by '\n', e.g. >
1914 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1915< The letter after the '&' is the shortcut key for that choice.
1916 Thus you can type 'c' to select "Cancel". The shortcut does
1917 not need to be the first letter: >
1918 confirm("file has been modified", "&Save\nSave &All")
1919< For the console, the first letter of each choice is used as
1920 the default shortcut key. Case is ignored.
1921
1922 The optional {default} argument is the number of the choice
1923 that is made if the user hits <CR>. Use 1 to make the first
1924 choice the default one. Use 0 to not set a default. If
1925 {default} is omitted, 1 is used.
1926
1927 The optional {type} String argument gives the type of dialog.
1928 This is only used for the icon of the GTK, Mac, Motif and
1929 Win32 GUI. It can be one of these values: "Error",
1930 "Question", "Info", "Warning" or "Generic". Only the first
1931 character is relevant. When {type} is omitted, "Generic" is
1932 used.
1933
1934 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1935 or another valid interrupt key, confirm() returns 0.
1936
1937 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001938 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001939 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01001940 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001941 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001942 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001943 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01001944 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001945 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01001946 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001947< In a GUI dialog, buttons are used. The layout of the buttons
1948 depends on the 'v' flag in 'guioptions'. If it is included,
1949 the buttons are always put vertically. Otherwise, confirm()
1950 tries to put the buttons in one horizontal line. If they
1951 don't fit, a vertical layout is used anyway. For some systems
1952 the horizontal layout is always used.
1953
1954 Can also be used as a |method|in: >
1955 BuildMessage()->confirm("&Yes\n&No")
1956<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001957 Return type: |Number|
1958
1959
1960copy({expr}) *copy()*
1961 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001962 different from using {expr} directly.
1963 When {expr} is a |List| a shallow copy is created. This means
1964 that the original |List| can be changed without changing the
1965 copy, and vice versa. But the items are identical, thus
1966 changing an item changes the contents of both |Lists|.
1967 A |Dictionary| is copied in a similar way as a |List|.
1968 Also see |deepcopy()|.
1969 Can also be used as a |method|: >
1970 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001971<
1972 Return type: any, depending on {expr}
1973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001974
1975cos({expr}) *cos()*
1976 Return the cosine of {expr}, measured in radians, as a |Float|.
1977 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001978 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001979 Examples: >
1980 :echo cos(100)
1981< 0.862319 >
1982 :echo cos(-4.01)
1983< -0.646043
1984
1985 Can also be used as a |method|: >
1986 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001987<
1988 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001989
1990
1991cosh({expr}) *cosh()*
1992 Return the hyperbolic cosine of {expr} as a |Float| in the range
1993 [1, inf].
1994 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001995 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001996 Examples: >
1997 :echo cosh(0.5)
1998< 1.127626 >
1999 :echo cosh(-0.5)
2000< -1.127626
2001
2002 Can also be used as a |method|: >
2003 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002004<
2005 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006
2007
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002008count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002009 Return the number of times an item with value {expr} appears
2010 in |String|, |List| or |Dictionary| {comp}.
2011
2012 If {start} is given then start with the item with this index.
2013 {start} can only be used with a |List|.
2014
2015 When {ic} is given and it's |TRUE| then case is ignored.
2016
2017 When {comp} is a string then the number of not overlapping
2018 occurrences of {expr} is returned. Zero is returned when
2019 {expr} is an empty string.
2020
2021 Can also be used as a |method|: >
2022 mylist->count(val)
2023<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002024 Return type: |Number|
2025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002026 *cscope_connection()*
2027cscope_connection([{num} , {dbpath} [, {prepend}]])
2028 Checks for the existence of a |cscope| connection. If no
2029 parameters are specified, then the function returns:
2030 0, if cscope was not available (not compiled in), or
2031 if there are no cscope connections;
2032 1, if there is at least one cscope connection.
2033
2034 If parameters are specified, then the value of {num}
2035 determines how existence of a cscope connection is checked:
2036
2037 {num} Description of existence check
2038 ----- ------------------------------
2039 0 Same as no parameters (e.g., "cscope_connection()").
2040 1 Ignore {prepend}, and use partial string matches for
2041 {dbpath}.
2042 2 Ignore {prepend}, and use exact string matches for
2043 {dbpath}.
2044 3 Use {prepend}, use partial string matches for both
2045 {dbpath} and {prepend}.
2046 4 Use {prepend}, use exact string matches for both
2047 {dbpath} and {prepend}.
2048
2049 Note: All string comparisons are case sensitive!
2050
2051 Examples. Suppose we had the following (from ":cs show"): >
2052
2053 # pid database name prepend path
2054 0 27664 cscope.out /usr/local
2055<
2056 Invocation Return Val ~
2057 ---------- ---------- >
2058 cscope_connection() 1
2059 cscope_connection(1, "out") 1
2060 cscope_connection(2, "out") 0
2061 cscope_connection(3, "out") 0
2062 cscope_connection(3, "out", "local") 1
2063 cscope_connection(4, "out") 0
2064 cscope_connection(4, "out", "local") 0
2065 cscope_connection(4, "cscope.out", "/usr/local") 1
2066<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002067 Return type: |Number|
2068
2069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002070cursor({lnum}, {col} [, {off}]) *cursor()*
2071cursor({list})
2072 Positions the cursor at the column (byte count) {col} in the
2073 line {lnum}. The first column is one.
2074
2075 When there is one argument {list} this is used as a |List|
2076 with two, three or four item:
2077 [{lnum}, {col}]
2078 [{lnum}, {col}, {off}]
2079 [{lnum}, {col}, {off}, {curswant}]
2080 This is like the return value of |getpos()| or |getcurpos()|,
2081 but without the first item.
2082
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002083 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002084 |setcursorcharpos()|.
2085
2086 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002087 {lnum} is used like with |getline()|, except that if {lnum} is
2088 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002089 If {lnum} is greater than the number of lines in the buffer,
2090 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002091 If {col} is greater than the number of bytes in the line,
2092 the cursor will be positioned at the last character in the
2093 line.
2094 If {col} is zero, the cursor will stay in the current column.
2095 If {curswant} is given it is used to set the preferred column
2096 for vertical movement. Otherwise {col} is used.
2097
2098 When 'virtualedit' is used {off} specifies the offset in
2099 screen columns from the start of the character. E.g., a
2100 position within a <Tab> or after the last character.
2101 Returns 0 when the position could be set, -1 otherwise.
2102
2103 Can also be used as a |method|: >
2104 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002105<
2106 Return type: |Number|
2107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002108
2109debugbreak({pid}) *debugbreak()*
2110 Specifically used to interrupt a program being debugged. It
2111 will cause process {pid} to get a SIGTRAP. Behavior for other
2112 processes is undefined. See |terminal-debugger|.
2113 {only available on MS-Windows}
2114
Bram Moolenaar016188f2022-06-06 20:52:59 +01002115 Returns |TRUE| if successfully interrupted the program.
2116 Otherwise returns |FALSE|.
2117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002118 Can also be used as a |method|: >
2119 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002120<
2121 Return type: |Number|
2122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002123
2124deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2125 Make a copy of {expr}. For Numbers and Strings this isn't
2126 different from using {expr} directly.
2127 When {expr} is a |List| a full copy is created. This means
2128 that the original |List| can be changed without changing the
2129 copy, and vice versa. When an item is a |List| or
2130 |Dictionary|, a copy for it is made, recursively. Thus
2131 changing an item in the copy does not change the contents of
2132 the original |List|.
2133 A |Dictionary| is copied in a similar way as a |List|.
2134
2135 When {noref} is omitted or zero a contained |List| or
2136 |Dictionary| is only copied once. All references point to
2137 this single copy. With {noref} set to 1 every occurrence of a
2138 |List| or |Dictionary| results in a new copy. This also means
2139 that a cyclic reference causes deepcopy() to fail.
2140 *E724*
2141 Nesting is possible up to 100 levels. When there is an item
2142 that refers back to a higher level making a deep copy with
2143 {noref} set to 1 will fail.
2144 Also see |copy()|.
2145
2146 Can also be used as a |method|: >
2147 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002148<
2149 Return type: any, depending on {expr}
2150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002151
2152delete({fname} [, {flags}]) *delete()*
2153 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002154 name {fname}.
2155
2156 This also works when {fname} is a symbolic link. The symbolic
2157 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002158
2159 When {flags} is "d": Deletes the directory by the name
2160 {fname}. This fails when directory {fname} is not empty.
2161
2162 When {flags} is "rf": Deletes the directory by the name
2163 {fname} and everything in it, recursively. BE CAREFUL!
2164 Note: on MS-Windows it is not possible to delete a directory
2165 that is being used.
2166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002167 The result is a Number, which is 0/false if the delete
2168 operation was successful and -1/true when the deletion failed
2169 or partly failed.
2170
2171 Use |remove()| to delete an item from a |List|.
2172 To delete a line from the buffer use |:delete| or
2173 |deletebufline()|.
2174
2175 Can also be used as a |method|: >
2176 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002177<
2178 Return type: |Number|
2179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002180
2181deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2182 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2183 If {last} is omitted then delete line {first} only.
2184 On success 0 is returned, on failure 1 is returned.
2185
2186 This function works only for loaded buffers. First call
2187 |bufload()| if needed.
2188
2189 For the use of {buf}, see |bufname()| above.
2190
2191 {first} and {last} are used like with |getline()|. Note that
2192 when using |line()| this refers to the current buffer. Use "$"
2193 to refer to the last line in buffer {buf}.
2194
2195 Can also be used as a |method|: >
2196 GetBuffer()->deletebufline(1)
2197<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002198 Return type: |Number|
2199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002200 *did_filetype()*
2201did_filetype() Returns |TRUE| when autocommands are being executed and the
2202 FileType event has been triggered at least once. Can be used
2203 to avoid triggering the FileType event again in the scripts
2204 that detect the file type. |FileType|
2205 Returns |FALSE| when `:setf FALLBACK` was used.
2206 When editing another file, the counter is reset, thus this
2207 really checks if the FileType event has been triggered for the
2208 current buffer. This allows an autocommand that starts
2209 editing another buffer to set 'filetype' and load a syntax
2210 file.
2211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002212 Return type: |Number|
2213
2214
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002215diff({fromlist}, {tolist} [, {options}]) *diff()*
2216 Returns a String or a List containing the diff between the
2217 strings in {fromlist} and {tolist}. Uses the Vim internal
2218 diff library to compute the diff.
2219
2220 *E106*
2221 The optional "output" item in {options} specifies the returned
2222 diff format. The following values are supported:
2223 indices Return a List of the starting and ending
2224 indices and a count of the strings in each
2225 diff hunk.
2226 unified Return the unified diff output as a String.
2227 This is the default.
2228
2229 If the "output" item in {options} is "indices", then a List is
2230 returned. Each List item contains a Dict with the following
2231 items for each diff hunk:
2232 from_idx start index in {fromlist} for this diff hunk.
2233 from_count number of strings in {fromlist} that are
2234 added/removed/modified in this diff hunk.
2235 to_idx start index in {tolist} for this diff hunk.
2236 to_count number of strings in {tolist} that are
2237 added/removed/modified in this diff hunk.
2238
2239 The {options} Dict argument also specifies diff options
2240 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002241 algorithm Dict specifying the diff algorithm to
2242 use. Supported boolean items are
2243 "myers", "minimal", "patience" and
2244 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002245 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002246 iblank ignore changes where lines are all
2247 blank.
2248 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002249 indent-heuristic use the indent heuristic for the
2250 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002251 iwhite ignore changes in amount of white
2252 space.
2253 iwhiteall ignore all white space changes.
2254 iwhiteeol ignore white space changes at end of
2255 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002256 For more information about these options, refer to 'diffopt'.
2257
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002258 To compute the unified diff, all the items in {fromlist} are
2259 concatenated into a string using a newline separator and the
2260 same for {tolist}. The unified diff output uses line numbers.
2261
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002262 Returns an empty List or String if {fromlist} and {tolist} are
2263 identical.
2264
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002265 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002266 :echo diff(['abc'], ['xxx'])
2267 @@ -1 +1 @@
2268 -abc
2269 +xxx
2270
2271 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2272 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2273 :echo diff(readfile('oldfile'), readfile('newfile'))
2274 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002275<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002276 For more examples, refer to |diff-func-examples|
2277
2278 Can also be used as a |method|: >
2279 GetFromList->diff(to_list)
2280<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002281 Return type: |String| or list<dict<number>> or list<any>
2282 depending on {options}
2283
2284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002285diff_filler({lnum}) *diff_filler()*
2286 Returns the number of filler lines above line {lnum}.
2287 These are the lines that were inserted at this point in
2288 another diff'ed window. These filler lines are shown in the
2289 display but don't exist in the buffer.
2290 {lnum} is used like with |getline()|. Thus "." is the current
2291 line, "'m" mark m, etc.
2292 Returns 0 if the current window is not in diff mode.
2293
2294 Can also be used as a |method|: >
2295 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002296<
2297 Return type: |Number|
2298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002299
2300diff_hlID({lnum}, {col}) *diff_hlID()*
2301 Returns the highlight ID for diff mode at line {lnum} column
2302 {col} (byte index). When the current line does not have a
2303 diff change zero is returned.
2304 {lnum} is used like with |getline()|. Thus "." is the current
2305 line, "'m" mark m, etc.
2306 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2307 line.
2308 The highlight ID can be used with |synIDattr()| to obtain
2309 syntax information about the highlighting.
2310
2311 Can also be used as a |method|: >
2312 GetLnum()->diff_hlID(col)
2313<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002314 Return type: |Number|
2315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002316
2317digraph_get({chars}) *digraph_get()* *E1214*
2318 Return the digraph of {chars}. This should be a string with
2319 exactly two characters. If {chars} are not just two
2320 characters, or the digraph of {chars} does not exist, an error
2321 is given and an empty string is returned.
2322
2323 The character will be converted from Unicode to 'encoding'
2324 when needed. This does require the conversion to be
2325 available, it might fail.
2326
2327 Also see |digraph_getlist()|.
2328
2329 Examples: >
2330 " Get a built-in digraph
2331 :echo digraph_get('00') " Returns '∞'
2332
2333 " Get a user-defined digraph
2334 :call digraph_set('aa', 'あ')
2335 :echo digraph_get('aa') " Returns 'あ'
2336<
2337 Can also be used as a |method|: >
2338 GetChars()->digraph_get()
2339<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002340 Return type: |String|
2341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002342 This function works only when compiled with the |+digraphs|
2343 feature. If this feature is disabled, this function will
2344 display an error message.
2345
2346
2347digraph_getlist([{listall}]) *digraph_getlist()*
2348 Return a list of digraphs. If the {listall} argument is given
2349 and it is TRUE, return all digraphs, including the default
2350 digraphs. Otherwise, return only user-defined digraphs.
2351
2352 The characters will be converted from Unicode to 'encoding'
2353 when needed. This does require the conservation to be
2354 available, it might fail.
2355
2356 Also see |digraph_get()|.
2357
2358 Examples: >
2359 " Get user-defined digraphs
2360 :echo digraph_getlist()
2361
2362 " Get all the digraphs, including default digraphs
2363 :echo digraph_getlist(1)
2364<
2365 Can also be used as a |method|: >
2366 GetNumber()->digraph_getlist()
2367<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002368 Return type: list<list<string>>
2369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002370 This function works only when compiled with the |+digraphs|
2371 feature. If this feature is disabled, this function will
2372 display an error message.
2373
2374
Bram Moolenaara2baa732022-02-04 16:09:54 +00002375digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002376 Add digraph {chars} to the list. {chars} must be a string
2377 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002378 encoded character. *E1215*
2379 Be careful, composing characters are NOT ignored. This
2380 function is similar to |:digraphs| command, but useful to add
2381 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002382
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002383 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002384 this fails an error message is given and v:false is returned.
2385
2386 If you want to define multiple digraphs at once, you can use
2387 |digraph_setlist()|.
2388
2389 Example: >
2390 call digraph_set(' ', 'あ')
2391<
2392 Can be used as a |method|: >
2393 GetString()->digraph_set('あ')
2394<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002395 Return type: |vim9-boolean|
2396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002397 This function works only when compiled with the |+digraphs|
2398 feature. If this feature is disabled, this function will
2399 display an error message.
2400
2401
2402digraph_setlist({digraphlist}) *digraph_setlist()*
2403 Similar to |digraph_set()| but this function can add multiple
2404 digraphs at once. {digraphlist} is a list composed of lists,
2405 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002406 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002407 Example: >
2408 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2409<
2410 It is similar to the following: >
2411 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2412 call digraph_set(chars, digraph)
2413 endfor
2414< Except that the function returns after the first error,
2415 following digraphs will not be added.
2416
2417 Can be used as a |method|: >
2418 GetList()->digraph_setlist()
2419<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002420 Return type: |vim9-boolean|
2421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002422 This function works only when compiled with the |+digraphs|
2423 feature. If this feature is disabled, this function will
2424 display an error message.
2425
2426
2427echoraw({string}) *echoraw()*
2428 Output {string} as-is, including unprintable characters.
2429 This can be used to output a terminal code. For example, to
2430 disable modifyOtherKeys: >
2431 call echoraw(&t_TE)
2432< and to enable it again: >
2433 call echoraw(&t_TI)
2434< Use with care, you can mess up the terminal this way.
2435
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002436 Return type: |Number|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438
2439empty({expr}) *empty()*
2440 Return the Number 1 if {expr} is empty, zero otherwise.
2441 - A |List| or |Dictionary| is empty when it does not have any
2442 items.
2443 - A |String| is empty when its length is zero.
2444 - A |Number| and |Float| are empty when their value is zero.
2445 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2446 - A |Job| is empty when it failed to start.
2447 - A |Channel| is empty when it is closed.
2448 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002449 - An |Object| is empty, when the empty() method in the object
2450 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002451
2452 For a long |List| this is much faster than comparing the
2453 length with zero.
2454
2455 Can also be used as a |method|: >
2456 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002457<
2458 Return type: |Number|
2459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002460
2461environ() *environ()*
2462 Return all of environment variables as dictionary. You can
2463 check if an environment variable exists like this: >
2464 :echo has_key(environ(), 'HOME')
2465< Note that the variable name may be CamelCase; to ignore case
2466 use this: >
2467 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002468<
2469 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002470
Bram Moolenaar416bd912023-07-07 23:19:18 +01002471
2472err_teapot([{expr}]) *err_teapot()*
2473 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002474 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002475 If {expr} is present and it is TRUE error 503 is given,
2476 indicating that coffee is temporarily not available.
2477 If {expr} is present it must be a String.
2478
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002479 Return type: |Number|
2480
Bram Moolenaar416bd912023-07-07 23:19:18 +01002481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002482escape({string}, {chars}) *escape()*
2483 Escape the characters in {chars} that occur in {string} with a
2484 backslash. Example: >
2485 :echo escape('c:\program files\vim', ' \')
2486< results in: >
2487 c:\\program\ files\\vim
2488< Also see |shellescape()| and |fnameescape()|.
2489
2490 Can also be used as a |method|: >
2491 GetText()->escape(' \')
2492<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002493 Return type: |String|
2494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002495 *eval()*
2496eval({string}) Evaluate {string} and return the result. Especially useful to
2497 turn the result of |string()| back into the original value.
2498 This works for Numbers, Floats, Strings, Blobs and composites
2499 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002500 functions. In |Vim9| script, it can be used to obtain |enum|
2501 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002502
2503 Can also be used as a |method|: >
2504 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002505<
2506 Return type: any, depending on {string}
2507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002508
2509eventhandler() *eventhandler()*
2510 Returns 1 when inside an event handler. That is that Vim got
2511 interrupted while waiting for the user to type a character,
2512 e.g., when dropping a file on Vim. This means interactive
2513 commands cannot be used. Otherwise zero is returned.
2514
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002515 Return type: |Number|
2516
2517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002518executable({expr}) *executable()*
2519 This function checks if an executable with the name {expr}
2520 exists. {expr} must be the name of the program without any
2521 arguments.
2522 executable() uses the value of $PATH and/or the normal
2523 searchpath for programs. *PATHEXT*
2524 On MS-Windows the ".exe", ".bat", etc. can optionally be
2525 included. Then the extensions in $PATHEXT are tried. Thus if
2526 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2527 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2528 by itself can be used in $PATHEXT to try using the name
2529 without an extension. When 'shell' looks like a Unix shell,
2530 then the name is also tried without adding an extension.
2531 On MS-Windows it only checks if the file exists and is not a
2532 directory, not if it's really executable.
2533 On MS-Windows an executable in the same directory as Vim is
Yasuhiro Matsumoto05cf63e2022-05-03 11:02:28 +01002534 normally found. Since this directory is added to $PATH it
2535 should also work to execute it |win32-PATH|. This can be
2536 disabled by setting the $NoDefaultCurrentDirectoryInExePath
2537 environment variable. *NoDefaultCurrentDirectoryInExePath*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002538 The result is a Number:
2539 1 exists
2540 0 does not exist
2541 -1 not implemented on this system
2542 |exepath()| can be used to get the full path of an executable.
2543
2544 Can also be used as a |method|: >
2545 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002546<
2547 Return type: |Number|
2548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002549
2550execute({command} [, {silent}]) *execute()*
2551 Execute an Ex command or commands and return the output as a
2552 string.
2553 {command} can be a string or a List. In case of a List the
2554 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002555 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002556 redir => var
2557 {command}
2558 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002559< Except that line continuation in {command} is not recognized.
2560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002561 The optional {silent} argument can have these values:
2562 "" no `:silent` used
2563 "silent" `:silent` used
2564 "silent!" `:silent!` used
2565 The default is "silent". Note that with "silent!", unlike
2566 `:redir`, error messages are dropped. When using an external
2567 command the screen may be messed up, use `system()` instead.
2568 *E930*
2569 It is not possible to use `:redir` anywhere in {command}.
2570
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002571 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002572 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002573
2574< To execute a command in another window than the current one
2575 use `win_execute()`.
2576
2577 When used recursively the output of the recursive call is not
2578 included in the output of the higher level call.
2579
2580 Can also be used as a |method|: >
2581 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002582<
2583 Return type: |Number|
2584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002585
2586exepath({expr}) *exepath()*
2587 If {expr} is an executable and is either an absolute path, a
2588 relative path or found in $PATH, return the full path.
2589 Note that the current directory is used when {expr} starts
2590 with "./", which may be a problem for Vim: >
2591 echo exepath(v:progpath)
2592< If {expr} cannot be found in $PATH or is not executable then
2593 an empty string is returned.
2594
2595 Can also be used as a |method|: >
2596 GetCommand()->exepath()
2597<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002598 Return type: |String|
2599
2600
2601exists({expr}) *exists()*
2602 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002603 zero otherwise.
2604
2605 Note: In a compiled |:def| function the evaluation is done at
2606 runtime. Use `exists_compiled()` to evaluate the expression
2607 at compile time.
2608
2609 For checking for a supported feature use |has()|.
2610 For checking if a file exists use |filereadable()|.
2611
2612 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002613 varname internal variable (see
2614 dict.key |internal-variables|). Also works
2615 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002616 import.Func entries, |List| items, class and
2617 class.Func object methods, imported items, etc.
2618 object.Func Does not work for local variables in a
2619 class.varname compiled `:def` function.
2620 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002621 script, since it can be used as a
2622 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002623 Beware that evaluating an index may
2624 cause an error message for an invalid
2625 expression. E.g.: >
2626 :let l = [1, 2, 3]
2627 :echo exists("l[5]")
2628< 0 >
2629 :echo exists("l[xx]")
2630< E121: Undefined variable: xx
2631 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002632 &option-name Vim option (only checks if it exists,
2633 not if it really works)
2634 +option-name Vim option that works.
2635 $ENVNAME environment variable (could also be
2636 done by comparing with an empty
2637 string)
2638 *funcname built-in function (see |functions|)
2639 or user defined function (see
2640 |user-functions|) that is implemented.
2641 Also works for a variable that is a
2642 Funcref.
2643 ?funcname built-in function that could be
2644 implemented; to be used to check if
2645 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002646 :cmdname Ex command: built-in command, user
2647 command or command modifier |:command|.
2648 Returns:
2649 1 for match with start of a command
2650 2 full match with a command
2651 3 matches several user commands
2652 To check for a supported command
2653 always check the return value to be 2.
2654 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002655 :3match The |:3match| command (but you
2656 probably should not use it, it is
2657 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002658 #event autocommand defined for this event
2659 #event#pattern autocommand defined for this event and
2660 pattern (the pattern is taken
2661 literally and compared to the
2662 autocommand patterns character by
2663 character)
2664 #group autocommand group exists
2665 #group#event autocommand defined for this group and
2666 event.
2667 #group#event#pattern
2668 autocommand defined for this group,
2669 event and pattern.
2670 ##event autocommand for this event is
2671 supported.
2672
2673 Examples: >
2674 exists("&shortname")
2675 exists("$HOSTNAME")
2676 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002677 exists("*s:MyFunc") " only for legacy script
2678 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679 exists("bufcount")
2680 exists(":Make")
2681 exists("#CursorHold")
2682 exists("#BufReadPre#*.gz")
2683 exists("#filetypeindent")
2684 exists("#filetypeindent#FileType")
2685 exists("#filetypeindent#FileType#*")
2686 exists("##ColorScheme")
2687< There must be no space between the symbol (&/$/*/#) and the
2688 name.
2689 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002690 a few cases this is ignored. That may become stricter in the
2691 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002692 Working example: >
2693 exists(":make")
2694< NOT working example: >
2695 exists(":make install")
2696
2697< Note that the argument must be a string, not the name of the
2698 variable itself. For example: >
2699 exists(bufcount)
2700< This doesn't check for existence of the "bufcount" variable,
2701 but gets the value of "bufcount", and checks if that exists.
2702
2703 Can also be used as a |method|: >
2704 Varname()->exists()
2705<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002706 Return type: |String|
2707
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002708
2709exists_compiled({expr}) *exists_compiled()*
2710 Like `exists()` but evaluated at compile time. This is useful
2711 to skip a block where a function is used that would otherwise
2712 give an error: >
2713 if exists_compiled('*ThatFunction')
2714 ThatFunction('works')
2715 endif
2716< If `exists()` were used then a compilation error would be
2717 given if ThatFunction() is not defined.
2718
2719 {expr} must be a literal string. *E1232*
2720 Can only be used in a |:def| function. *E1233*
2721 This does not work to check for arguments or local variables.
2722
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002723 Return type: |String|
2724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002725
2726exp({expr}) *exp()*
2727 Return the exponential of {expr} as a |Float| in the range
2728 [0, inf].
2729 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002730 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002731 Examples: >
2732 :echo exp(2)
2733< 7.389056 >
2734 :echo exp(-1)
2735< 0.367879
2736
2737 Can also be used as a |method|: >
2738 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002739<
2740 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002741
2742
2743expand({string} [, {nosuf} [, {list}]]) *expand()*
2744 Expand wildcards and the following special keywords in
2745 {string}. 'wildignorecase' applies.
2746
2747 If {list} is given and it is |TRUE|, a List will be returned.
2748 Otherwise the result is a String and when there are several
2749 matches, they are separated by <NL> characters. [Note: in
2750 version 5.0 a space was used, which caused problems when a
2751 file name contains a space]
2752
2753 If the expansion fails, the result is an empty string. A name
2754 for a non-existing file is not included, unless {string} does
2755 not start with '%', '#' or '<', see below.
2756
Christian Brabandtec9c3262024-02-21 20:40:05 +01002757 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002758 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002760 When {string} starts with '%', '#' or '<', the expansion is
2761 done like for the |cmdline-special| variables with their
2762 associated modifiers. Here is a short overview:
2763
2764 % current file name
2765 # alternate file name
2766 #n alternate file name n
2767 <cfile> file name under the cursor
2768 <afile> autocmd file name
2769 <abuf> autocmd buffer number (as a String!)
2770 <amatch> autocmd matched name
2771 <cexpr> C expression under the cursor
2772 <sfile> sourced script file or function name
2773 <slnum> sourced script line number or function
2774 line number
2775 <sflnum> script file line number, also when in
2776 a function
2777 <SID> "<SNR>123_" where "123" is the
2778 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002779 <script> sourced script file, or script file
2780 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002781 <stack> call stack
2782 <cword> word under the cursor
2783 <cWORD> WORD under the cursor
2784 <client> the {clientid} of the last received
2785 message |server2client()|
2786 Modifiers:
2787 :p expand to full path
2788 :h head (last path component removed)
2789 :t tail (last path component only)
2790 :r root (one extension removed)
2791 :e extension only
2792
2793 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002794 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002795< Note that when expanding a string that starts with '%', '#' or
2796 '<', any following text is ignored. This does NOT work: >
2797 :let doesntwork = expand("%:h.bak")
2798< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002799 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002800< Also note that expanding "<cfile>" and others only returns the
2801 referenced file name without further expansion. If "<cfile>"
2802 is "~/.cshrc", you need to do another expand() to have the
2803 "~/" expanded into the path of the home directory: >
2804 :echo expand(expand("<cfile>"))
2805<
2806 There cannot be white space between the variables and the
2807 following modifier. The |fnamemodify()| function can be used
2808 to modify normal file names.
2809
2810 When using '%' or '#', and the current or alternate file name
2811 is not defined, an empty string is used. Using "%:p" in a
2812 buffer with no name, results in the current directory, with a
2813 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002814 When 'verbose' is set then expanding '%', '#' and <> items
2815 will result in an error message if the argument cannot be
2816 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002817
2818 When {string} does not start with '%', '#' or '<', it is
2819 expanded like a file name is expanded on the command line.
2820 'suffixes' and 'wildignore' are used, unless the optional
2821 {nosuf} argument is given and it is |TRUE|.
2822 Names for non-existing files are included. The "**" item can
2823 be used to search in a directory tree. For example, to find
2824 all "README" files in the current directory and below: >
2825 :echo expand("**/README")
2826<
2827 expand() can also be used to expand variables and environment
2828 variables that are only known in a shell. But this can be
2829 slow, because a shell may be used to do the expansion. See
2830 |expr-env-expand|.
2831 The expanded variable is still handled like a list of file
2832 names. When an environment variable cannot be expanded, it is
2833 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2834 "$FOOBAR".
2835
2836 See |glob()| for finding existing files. See |system()| for
2837 getting the raw output of an external command.
2838
2839 Can also be used as a |method|: >
2840 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002841<
2842 Return type: |String| or list<string> depending on {list}
2843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002844
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002845expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002846 Expand special items in String {string} like what is done for
2847 an Ex command such as `:edit`. This expands special keywords,
2848 like with |expand()|, and environment variables, anywhere in
2849 {string}. "~user" and "~/path" are only expanded at the
2850 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002851
2852 The following items are supported in the {options} Dict
2853 argument:
2854 errmsg If set to TRUE, error messages are displayed
2855 if an error is encountered during expansion.
2856 By default, error messages are not displayed.
2857
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002858 Returns the expanded string. If an error is encountered
2859 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002860
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002861 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002862 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002863 make /path/runtime/doc/builtin.o
2864 :echo expandcmd('make %<.o', {'errmsg': v:true})
2865<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002866 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 GetCommand()->expandcmd()
2868<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002869 Return type: |String| or list<string> depending on {list}
2870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002871extend({expr1}, {expr2} [, {expr3}]) *extend()*
2872 {expr1} and {expr2} must be both |Lists| or both
2873 |Dictionaries|.
2874
2875 If they are |Lists|: Append {expr2} to {expr1}.
2876 If {expr3} is given insert the items of {expr2} before the
2877 item with index {expr3} in {expr1}. When {expr3} is zero
2878 insert before the first item. When {expr3} is equal to
2879 len({expr1}) then {expr2} is appended.
2880 Examples: >
2881 :echo sort(extend(mylist, [7, 5]))
2882 :call extend(mylist, [2, 3], 1)
2883< When {expr1} is the same List as {expr2} then the number of
2884 items copied is equal to the original length of the List.
2885 E.g., when {expr3} is 1 you get N new copies of the first item
2886 (where N is the original length of the List).
2887 Use |add()| to concatenate one item to a list. To concatenate
2888 two lists into a new list use the + operator: >
2889 :let newlist = [1, 2, 3] + [4, 5]
2890<
2891 If they are |Dictionaries|:
2892 Add all entries from {expr2} to {expr1}.
2893 If a key exists in both {expr1} and {expr2} then {expr3} is
2894 used to decide what to do:
2895 {expr3} = "keep": keep the value of {expr1}
2896 {expr3} = "force": use the value of {expr2}
2897 {expr3} = "error": give an error message *E737*
2898 When {expr3} is omitted then "force" is assumed.
2899
2900 {expr1} is changed when {expr2} is not empty. If necessary
2901 make a copy of {expr1} first.
2902 {expr2} remains unchanged.
2903 When {expr1} is locked and {expr2} is not empty the operation
2904 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002905 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002906
2907 Can also be used as a |method|: >
2908 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002909<
2910 Return type: list<{type}> or dict<{type}> depending on {expr1}
2911 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002912
2913
2914extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2915 Like |extend()| but instead of adding items to {expr1} a new
2916 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002917 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002918
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002919 Return type: list<{type}> or dict<{type}> depending on {expr1}
2920 and {expr2}, in case of error: |Number|
2921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002922
2923feedkeys({string} [, {mode}]) *feedkeys()*
2924 Characters in {string} are queued for processing as if they
2925 come from a mapping or were typed by the user.
2926
2927 By default the string is added to the end of the typeahead
2928 buffer, thus if a mapping is still being executed the
2929 characters come after them. Use the 'i' flag to insert before
2930 other characters, they will be executed next, before any
2931 characters from a mapping.
2932
2933 The function does not wait for processing of keys contained in
2934 {string}.
2935
2936 To include special keys into {string}, use double-quotes
2937 and "\..." notation |expr-quote|. For example,
2938 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
2939 feedkeys('\<CR>') pushes 5 characters.
2940 A special code that might be useful is <Ignore>, it exits the
2941 wait for a character without doing anything. *<Ignore>*
2942
2943 {mode} is a String, which can contain these character flags:
2944 'm' Remap keys. This is default. If {mode} is absent,
2945 keys are remapped.
2946 'n' Do not remap keys.
2947 't' Handle keys as if typed; otherwise they are handled as
2948 if coming from a mapping. This matters for undo,
2949 opening folds, etc.
2950 'L' Lowlevel input. Only works for Unix or when using the
2951 GUI. Keys are used as if they were coming from the
2952 terminal. Other flags are not used. *E980*
2953 When a CTRL-C interrupts and 't' is included it sets
2954 the internal "got_int" flag.
2955 'i' Insert the string instead of appending (see above).
2956 'x' Execute commands until typeahead is empty. This is
2957 similar to using ":normal!". You can call feedkeys()
2958 several times without 'x' and then one time with 'x'
2959 (possibly with an empty {string}) to execute all the
2960 typeahead. Note that when Vim ends in Insert mode it
2961 will behave as if <Esc> is typed, to avoid getting
2962 stuck, waiting for a character to be typed before the
2963 script continues.
2964 Note that if you manage to call feedkeys() while
2965 executing commands, thus calling it recursively, then
2966 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00002967 'c' Remove any script context when executing, so that
2968 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01002969 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01002970 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002971 '!' When used with 'x' will not end Insert mode. Can be
2972 used in a test when a timer is set to exit Insert mode
2973 a little later. Useful for testing CursorHoldI.
2974
2975 Return value is always 0.
2976
2977 Can also be used as a |method|: >
2978 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002979<
2980 Return type: |String| or list<string> depending on {list}
2981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002982
Shougo Matsushita60c87432024-06-03 22:59:27 +02002983filecopy({from}, {to}) *filecopy()*
2984 Copy the file pointed to by the name {from} to {to}. The
2985 result is a Number, which is |TRUE| if the file was copied
2986 successfully, and |FALSE| when it failed.
2987 If a file with name {to} already exists, it will fail.
2988 Note that it does not handle directories (yet).
2989
2990 This function is not available in the |sandbox|.
2991
2992 Can also be used as a |method|: >
2993 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002994<
2995 Return type: |Number|
2996
Shougo Matsushita60c87432024-06-03 22:59:27 +02002997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002998filereadable({file}) *filereadable()*
2999 The result is a Number, which is |TRUE| when a file with the
3000 name {file} exists, and can be read. If {file} doesn't exist,
3001 or is a directory, the result is |FALSE|. {file} is any
3002 expression, which is used as a String.
3003 If you don't care about the file being readable you can use
3004 |glob()|.
3005 {file} is used as-is, you may want to expand wildcards first: >
3006 echo filereadable('~/.vimrc')
3007 0
3008 echo filereadable(expand('~/.vimrc'))
3009 1
3010
3011< Can also be used as a |method|: >
3012 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003013<
3014 Return type: |Number|
3015
3016 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003017 Obsolete name: file_readable().
3018
3019
3020filewritable({file}) *filewritable()*
3021 The result is a Number, which is 1 when a file with the
3022 name {file} exists, and can be written. If {file} doesn't
3023 exist, or is not writable, the result is 0. If {file} is a
3024 directory, and we can write to it, the result is 2.
3025
3026 Can also be used as a |method|: >
3027 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003028<
3029 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003030
3031
3032filter({expr1}, {expr2}) *filter()*
3033 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3034 For each item in {expr1} evaluate {expr2} and when the result
3035 is zero or false remove the item from the |List| or
3036 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003037 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003038
3039 {expr2} must be a |string| or |Funcref|.
3040
3041 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3042 of the current item. For a |Dictionary| |v:key| has the key
3043 of the current item and for a |List| |v:key| has the index of
3044 the current item. For a |Blob| |v:key| has the index of the
3045 current byte. For a |String| |v:key| has the index of the
3046 current character.
3047 Examples: >
3048 call filter(mylist, 'v:val !~ "OLD"')
3049< Removes the items where "OLD" appears. >
3050 call filter(mydict, 'v:key >= 8')
3051< Removes the items with a key below 8. >
3052 call filter(var, 0)
3053< Removes all the items, thus clears the |List| or |Dictionary|.
3054
3055 Note that {expr2} is the result of expression and is then
3056 used as an expression again. Often it is good to use a
3057 |literal-string| to avoid having to double backslashes.
3058
3059 If {expr2} is a |Funcref| it must take two arguments:
3060 1. the key or the index of the current item.
3061 2. the value of the current item.
3062 The function must return |TRUE| if the item should be kept.
3063 Example that keeps the odd items of a list: >
3064 func Odd(idx, val)
3065 return a:idx % 2 == 1
3066 endfunc
3067 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003068< It is shorter when using a |lambda|. In |Vim9| syntax: >
3069 call filter(myList, (idx, val) => idx * val <= 42)
3070< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003071 call filter(myList, {idx, val -> idx * val <= 42})
3072< If you do not use "val" you can leave it out: >
3073 call filter(myList, {idx -> idx % 2 == 1})
3074<
3075 In |Vim9| script the result must be true, false, zero or one.
3076 Other values will result in a type error.
3077
3078 For a |List| and a |Dictionary| the operation is done
3079 in-place. If you want it to remain unmodified make a copy
3080 first: >
3081 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3082
3083< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003084 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003085 When an error is encountered while evaluating {expr2} no
3086 further items in {expr1} are processed.
3087 When {expr2} is a Funcref errors inside a function are ignored,
3088 unless it was defined with the "abort" flag.
3089
3090 Can also be used as a |method|: >
3091 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003092<
3093 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3094 depending on {expr1}
3095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003096
3097finddir({name} [, {path} [, {count}]]) *finddir()*
3098 Find directory {name} in {path}. Supports both downwards and
3099 upwards recursive directory searches. See |file-searching|
3100 for the syntax of {path}.
3101
3102 Returns the path of the first found match. When the found
3103 directory is below the current directory a relative path is
3104 returned. Otherwise a full path is returned.
3105 If {path} is omitted or empty then 'path' is used.
3106
3107 If the optional {count} is given, find {count}'s occurrence of
3108 {name} in {path} instead of the first one.
3109 When {count} is negative return all the matches in a |List|.
3110
Bram Moolenaar016188f2022-06-06 20:52:59 +01003111 Returns an empty string if the directory is not found.
3112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003113 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003114
3115 Can also be used as a |method|: >
3116 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003117<
3118 Return type: |String|
3119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003120
3121findfile({name} [, {path} [, {count}]]) *findfile()*
3122 Just like |finddir()|, but find a file instead of a directory.
3123 Uses 'suffixesadd'.
3124 Example: >
3125 :echo findfile("tags.vim", ".;")
3126< Searches from the directory of the current file upwards until
3127 it finds the file "tags.vim".
3128
3129 Can also be used as a |method|: >
3130 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003131<
3132 Return type: |String|
3133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003134
3135flatten({list} [, {maxdepth}]) *flatten()*
3136 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3137 the result is a |List| without nesting, as if {maxdepth} is
3138 a very large number.
3139 The {list} is changed in place, use |flattennew()| if you do
3140 not want that.
3141 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003142 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003143 *E900*
3144 {maxdepth} means how deep in nested lists changes are made.
3145 {list} is not modified when {maxdepth} is 0.
3146 {maxdepth} must be positive number.
3147
3148 If there is an error the number zero is returned.
3149
3150 Example: >
3151 :echo flatten([1, [2, [3, 4]], 5])
3152< [1, 2, 3, 4, 5] >
3153 :echo flatten([1, [2, [3, 4]], 5], 1)
3154< [1, 2, [3, 4], 5]
3155
3156 Can also be used as a |method|: >
3157 mylist->flatten()
3158<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003159 Return type: list<{type}>
3160
3161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003162flattennew({list} [, {maxdepth}]) *flattennew()*
3163 Like |flatten()| but first make a copy of {list}.
3164
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003165 Return type: list<{type}>
3166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003167
3168float2nr({expr}) *float2nr()*
3169 Convert {expr} to a Number by omitting the part after the
3170 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003171 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003172 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003173 When the value of {expr} is out of range for a |Number| the
3174 result is truncated to 0x7fffffff or -0x7fffffff (or when
3175 64-bit Number support is enabled, 0x7fffffffffffffff or
3176 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3177 64-bit Number support is enabled, -0x8000000000000000).
3178 Examples: >
3179 echo float2nr(3.95)
3180< 3 >
3181 echo float2nr(-23.45)
3182< -23 >
3183 echo float2nr(1.0e100)
3184< 2147483647 (or 9223372036854775807) >
3185 echo float2nr(-1.0e150)
3186< -2147483647 (or -9223372036854775807) >
3187 echo float2nr(1.0e-100)
3188< 0
3189
3190 Can also be used as a |method|: >
3191 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003192<
3193 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003194
3195
3196floor({expr}) *floor()*
3197 Return the largest integral value less than or equal to
3198 {expr} as a |Float| (round down).
3199 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003200 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003201 Examples: >
3202 echo floor(1.856)
3203< 1.0 >
3204 echo floor(-5.456)
3205< -6.0 >
3206 echo floor(4.0)
3207< 4.0
3208
3209 Can also be used as a |method|: >
3210 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003211<
3212 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003213
3214
3215fmod({expr1}, {expr2}) *fmod()*
3216 Return the remainder of {expr1} / {expr2}, even if the
3217 division is not representable. Returns {expr1} - i * {expr2}
3218 for some integer i such that if {expr2} is non-zero, the
3219 result has the same sign as {expr1} and magnitude less than
3220 the magnitude of {expr2}. If {expr2} is zero, the value
3221 returned is zero. The value returned is a |Float|.
3222 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003223 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3224 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003225 Examples: >
3226 :echo fmod(12.33, 1.22)
3227< 0.13 >
3228 :echo fmod(-12.33, 1.22)
3229< -0.13
3230
3231 Can also be used as a |method|: >
3232 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003233<
3234 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003235
3236
3237fnameescape({string}) *fnameescape()*
3238 Escape {string} for use as file name command argument. All
3239 characters that have a special meaning, such as '%' and '|'
3240 are escaped with a backslash.
3241 For most systems the characters escaped are
3242 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3243 appears in a filename, it depends on the value of 'isfname'.
3244 A leading '+' and '>' is also escaped (special after |:edit|
3245 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003246 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003247 Example: >
3248 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003249 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003250< results in executing: >
3251 edit \+some\ str\%nge\|name
3252<
3253 Can also be used as a |method|: >
3254 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003255<
3256 Return type: |String|
3257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003258
3259fnamemodify({fname}, {mods}) *fnamemodify()*
3260 Modify file name {fname} according to {mods}. {mods} is a
3261 string of characters like it is used for file names on the
3262 command line. See |filename-modifiers|.
3263 Example: >
3264 :echo fnamemodify("main.c", ":p:h")
3265< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003266 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003267< If {mods} is empty or an unsupported modifier is used then
3268 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003269 When {fname} is empty then with {mods} ":h" returns ".", so
3270 that `:cd` can be used with it. This is different from
3271 expand('%:h') without a buffer name, which returns an empty
3272 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003273 Note: Environment variables don't work in {fname}, use
3274 |expand()| first then.
3275
3276 Can also be used as a |method|: >
3277 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003278<
3279 Return type: |String|
3280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003281
3282foldclosed({lnum}) *foldclosed()*
3283 The result is a Number. If the line {lnum} is in a closed
3284 fold, the result is the number of the first line in that fold.
3285 If the line {lnum} is not in a closed fold, -1 is returned.
3286 {lnum} is used like with |getline()|. Thus "." is the current
3287 line, "'m" mark m, etc.
3288
3289 Can also be used as a |method|: >
3290 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003291<
3292 Return type: |Number|
3293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003294
3295foldclosedend({lnum}) *foldclosedend()*
3296 The result is a Number. If the line {lnum} is in a closed
3297 fold, the result is the number of the last line in that fold.
3298 If the line {lnum} is not in a closed fold, -1 is returned.
3299 {lnum} is used like with |getline()|. Thus "." is the current
3300 line, "'m" mark m, etc.
3301
3302 Can also be used as a |method|: >
3303 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003304<
3305 Return type: |Number|
3306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003307
3308foldlevel({lnum}) *foldlevel()*
3309 The result is a Number, which is the foldlevel of line {lnum}
3310 in the current buffer. For nested folds the deepest level is
3311 returned. If there is no fold at line {lnum}, zero is
3312 returned. It doesn't matter if the folds are open or closed.
3313 When used while updating folds (from 'foldexpr') -1 is
3314 returned for lines where folds are still to be updated and the
3315 foldlevel is unknown. As a special case the level of the
3316 previous line is usually available.
3317 {lnum} is used like with |getline()|. Thus "." is the current
3318 line, "'m" mark m, etc.
3319
3320 Can also be used as a |method|: >
3321 GetLnum()->foldlevel()
3322<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003323 Return type: |Number|
3324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003325 *foldtext()*
3326foldtext() Returns a String, to be displayed for a closed fold. This is
3327 the default function used for the 'foldtext' option and should
3328 only be called from evaluating 'foldtext'. It uses the
3329 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3330 The returned string looks like this: >
3331 +-- 45 lines: abcdef
3332< The number of leading dashes depends on the foldlevel. The
3333 "45" is the number of lines in the fold. "abcdef" is the text
3334 in the first non-blank line of the fold. Leading white space,
3335 "//" or "/*" and the text from the 'foldmarker' and
3336 'commentstring' options is removed.
3337 When used to draw the actual foldtext, the rest of the line
3338 will be filled with the fold char from the 'fillchars'
3339 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003340 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003341
3342 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003343 {not available when compiled without the |+folding| feature}
3344
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003346foldtextresult({lnum}) *foldtextresult()*
3347 Returns the text that is displayed for the closed fold at line
3348 {lnum}. Evaluates 'foldtext' in the appropriate context.
3349 When there is no closed fold at {lnum} an empty string is
3350 returned.
3351 {lnum} is used like with |getline()|. Thus "." is the current
3352 line, "'m" mark m, etc.
3353 Useful when exporting folded text, e.g., to HTML.
3354 {not available when compiled without the |+folding| feature}
3355
3356
3357 Can also be used as a |method|: >
3358 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003359<
3360 Return type: |String|
3361
Ernie Raele79e2072024-01-13 11:47:33 +01003362
3363foreach({expr1}, {expr2}) *foreach()*
3364 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3365 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003366 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003367 See |map()| and |filter()| to modify {expr1}.
3368
3369 {expr2} must be a |string| or |Funcref|.
3370
3371 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3372 of the current item. For a |Dictionary| |v:key| has the key
3373 of the current item and for a |List| |v:key| has the index of
3374 the current item. For a |Blob| |v:key| has the index of the
3375 current byte. For a |String| |v:key| has the index of the
3376 current character.
3377 Examples: >
3378 call foreach(mylist, 'used[v:val] = true')
3379< This records the items that are in the {expr1} list.
3380
3381 Note that {expr2} is the result of expression and is then used
3382 as a command. Often it is good to use a |literal-string| to
3383 avoid having to double backslashes.
3384
3385 If {expr2} is a |Funcref| it must take two arguments:
3386 1. the key or the index of the current item.
3387 2. the value of the current item.
3388 With a legacy script lambda you don't get an error if it only
3389 accepts one argument, but with a Vim9 lambda you get "E1106:
3390 One argument too many", the number of arguments must match.
3391 If the function returns a value, it is ignored.
3392
3393 Returns {expr1} in all cases.
3394 When an error is encountered while executing {expr2} no
3395 further items in {expr1} are processed.
3396 When {expr2} is a Funcref errors inside a function are ignored,
3397 unless it was defined with the "abort" flag.
3398
3399 Can also be used as a |method|: >
3400 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003401<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003402 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3403 depending on {expr1}
3404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003405 *foreground()*
3406foreground() Move the Vim window to the foreground. Useful when sent from
3407 a client to a Vim server. |remote_send()|
3408 On Win32 systems this might not work, the OS does not always
3409 allow a window to bring itself to the foreground. Use
3410 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003411
3412 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003413 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003414 Win32 console version}
3415
Bram Moolenaaraa534142022-09-15 21:46:02 +01003416fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003417 Get the full command name from a short abbreviated command
3418 name; see |20.2| for details on command abbreviations.
3419
3420 The string argument {name} may start with a `:` and can
3421 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003422 Returns an empty string if a command doesn't exist, if it's
3423 ambiguous (for user-defined commands) or cannot be shortened
3424 this way. |vim9-no-shorten|
3425
3426 Without the {vim9} argument uses the current script version.
3427 If {vim9} is present and FALSE then legacy script rules are
3428 used. When {vim9} is present and TRUE then Vim9 rules are
3429 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003430
3431 For example `fullcommand('s')`, `fullcommand('sub')`,
3432 `fullcommand(':%substitute')` all return "substitute".
3433
3434 Can also be used as a |method|: >
3435 GetName()->fullcommand()
3436<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003437 Return type: |String|
3438
3439
3440funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003441 Just like |function()|, but the returned Funcref will lookup
3442 the function by reference, not by name. This matters when the
3443 function {name} is redefined later.
3444
3445 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003446 It only works for an autoloaded function if it has already
3447 been loaded (to avoid mistakenly loading the autoload script
3448 when only intending to use the function name, use |function()|
3449 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003450 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003451
3452 Can also be used as a |method|: >
3453 GetFuncname()->funcref([arg])
3454<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003455 Return type: func(...): any or |Number| on error
3456
Dominique Pellee764d1b2023-03-12 21:20:59 +00003457 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003458function({name} [, {arglist}] [, {dict}])
3459 Return a |Funcref| variable that refers to function {name}.
3460 {name} can be the name of a user defined function or an
3461 internal function.
3462
3463 {name} can also be a Funcref or a partial. When it is a
3464 partial the dict stored in it will be used and the {dict}
3465 argument is not allowed. E.g.: >
3466 let FuncWithArg = function(dict.Func, [arg])
3467 let Broken = function(dict.Func, [arg], dict)
3468<
3469 When using the Funcref the function will be found by {name},
3470 also when it was redefined later. Use |funcref()| to keep the
3471 same function.
3472
3473 When {arglist} or {dict} is present this creates a partial.
3474 That means the argument list and/or the dictionary is stored in
3475 the Funcref and will be used when the Funcref is called.
3476
3477 The arguments are passed to the function in front of other
3478 arguments, but after any argument from |method|. Example: >
3479 func Callback(arg1, arg2, name)
3480 ...
3481 let Partial = function('Callback', ['one', 'two'])
3482 ...
3483 call Partial('name')
3484< Invokes the function as with: >
3485 call Callback('one', 'two', 'name')
3486
3487< With a |method|: >
3488 func Callback(one, two, three)
3489 ...
3490 let Partial = function('Callback', ['two'])
3491 ...
3492 eval 'one'->Partial('three')
3493< Invokes the function as with: >
3494 call Callback('one', 'two', 'three')
3495
3496< The function() call can be nested to add more arguments to the
3497 Funcref. The extra arguments are appended to the list of
3498 arguments. Example: >
3499 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003500 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003501 let Func = function('Callback', ['one'])
3502 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003503 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003504 call Func2('name')
3505< Invokes the function as with: >
3506 call Callback('one', 'two', 'name')
3507
3508< The Dictionary is only useful when calling a "dict" function.
3509 In that case the {dict} is passed in as "self". Example: >
3510 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003511 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003512 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003513 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 let context = {"name": "example"}
3515 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003516 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003517 call Func() " will echo: called for example
3518< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003519 arguments, these two are equivalent, if Callback() is defined
3520 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003521 let Func = function('Callback', context)
3522 let Func = context.Callback
3523
3524< The argument list and the Dictionary can be combined: >
3525 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003526 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003527 let context = {"name": "example"}
3528 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003529 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003530 call Func(500)
3531< Invokes the function as with: >
3532 call context.Callback('one', 500)
3533<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003534 Returns 0 on error.
3535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003536 Can also be used as a |method|: >
3537 GetFuncname()->function([arg])
3538
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003539<
3540 Return type: func(...): any or |Number| on error
3541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003542
3543garbagecollect([{atexit}]) *garbagecollect()*
3544 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3545 that have circular references.
3546
3547 There is hardly ever a need to invoke this function, as it is
3548 automatically done when Vim runs out of memory or is waiting
3549 for the user to press a key after 'updatetime'. Items without
3550 circular references are always freed when they become unused.
3551 This is useful if you have deleted a very big |List| and/or
3552 |Dictionary| with circular references in a script that runs
3553 for a long time.
3554
3555 When the optional {atexit} argument is one, garbage
3556 collection will also be done when exiting Vim, if it wasn't
3557 done before. This is useful when checking for memory leaks.
3558
3559 The garbage collection is not done immediately but only when
3560 it's safe to perform. This is when waiting for the user to
3561 type a character. To force garbage collection immediately use
3562 |test_garbagecollect_now()|.
3563
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003564 Return type: |String|
3565
3566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003567get({list}, {idx} [, {default}]) *get()*
3568 Get item {idx} from |List| {list}. When this item is not
3569 available return {default}. Return zero when {default} is
3570 omitted.
3571 Preferably used as a |method|: >
3572 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003573<
3574 Return type: any, depending on {list}
3575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003576get({blob}, {idx} [, {default}])
3577 Get byte {idx} from |Blob| {blob}. When this byte is not
3578 available return {default}. Return -1 when {default} is
3579 omitted.
3580 Preferably used as a |method|: >
3581 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003582<
3583 Return type: |Number|
3584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003585get({dict}, {key} [, {default}])
3586 Get item with key {key} from |Dictionary| {dict}. When this
3587 item is not available return {default}. Return zero when
3588 {default} is omitted. Useful example: >
3589 let val = get(g:, 'var_name', 'default')
3590< This gets the value of g:var_name if it exists, and uses
3591 'default' when it does not exist.
3592 Preferably used as a |method|: >
3593 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003594<
3595 Return type: any, depending on {list}
3596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597get({func}, {what})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00003598 Get item {what} from Funcref {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003599 {what} are:
3600 "name" The function name
3601 "func" The function
3602 "dict" The dictionary
3603 "args" The list with arguments
Bram Moolenaar016188f2022-06-06 20:52:59 +01003604 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003605 Preferably used as a |method|: >
3606 myfunc->get(what)
3607<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003608 Return type: any, depending on {func}
3609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003610 *getbufinfo()*
3611getbufinfo([{buf}])
3612getbufinfo([{dict}])
3613 Get information about buffers as a List of Dictionaries.
3614
3615 Without an argument information about all the buffers is
3616 returned.
3617
3618 When the argument is a |Dictionary| only the buffers matching
3619 the specified criteria are returned. The following keys can
3620 be specified in {dict}:
3621 buflisted include only listed buffers.
3622 bufloaded include only loaded buffers.
3623 bufmodified include only modified buffers.
3624
3625 Otherwise, {buf} specifies a particular buffer to return
3626 information for. For the use of {buf}, see |bufname()|
3627 above. If the buffer is found the returned List has one item.
3628 Otherwise the result is an empty list.
3629
3630 Each returned List item is a dictionary with the following
3631 entries:
3632 bufnr Buffer number.
3633 changed TRUE if the buffer is modified.
3634 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003635 command TRUE if the buffer belongs to the
3636 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003637 hidden TRUE if the buffer is hidden.
3638 lastused Timestamp in seconds, like
3639 |localtime()|, when the buffer was
3640 last used.
3641 {only with the |+viminfo| feature}
3642 listed TRUE if the buffer is listed.
3643 lnum Line number used for the buffer when
3644 opened in the current window.
3645 Only valid if the buffer has been
3646 displayed in the window in the past.
3647 If you want the line number of the
3648 last known cursor position in a given
3649 window, use |line()|: >
3650 :echo line('.', {winid})
3651<
3652 linecount Number of lines in the buffer (only
3653 valid when loaded)
3654 loaded TRUE if the buffer is loaded.
3655 name Full path to the file in the buffer.
3656 signs List of signs placed in the buffer.
3657 Each list item is a dictionary with
3658 the following fields:
3659 id sign identifier
3660 lnum line number
3661 name sign name
3662 variables A reference to the dictionary with
3663 buffer-local variables.
3664 windows List of |window-ID|s that display this
3665 buffer
3666 popups List of popup |window-ID|s that
3667 display this buffer
3668
3669 Examples: >
3670 for buf in getbufinfo()
3671 echo buf.name
3672 endfor
3673 for buf in getbufinfo({'buflisted':1})
3674 if buf.changed
3675 ....
3676 endif
3677 endfor
3678<
3679 To get buffer-local options use: >
3680 getbufvar({bufnr}, '&option_name')
3681<
3682 Can also be used as a |method|: >
3683 GetBufnr()->getbufinfo()
3684<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003685 Return type: list<dict<any>>
3686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003687
3688 *getbufline()*
3689getbufline({buf}, {lnum} [, {end}])
3690 Return a |List| with the lines starting from {lnum} to {end}
3691 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003692 |List| with only the line {lnum} is returned. See
3693 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003694
3695 For the use of {buf}, see |bufname()| above.
3696
3697 For {lnum} and {end} "$" can be used for the last line of the
3698 buffer. Otherwise a number must be used.
3699
3700 When {lnum} is smaller than 1 or bigger than the number of
3701 lines in the buffer, an empty |List| is returned.
3702
3703 When {end} is greater than the number of lines in the buffer,
3704 it is treated as {end} is set to the number of lines in the
3705 buffer. When {end} is before {lnum} an empty |List| is
3706 returned.
3707
3708 This function works only for loaded buffers. For unloaded and
3709 non-existing buffers, an empty |List| is returned.
3710
3711 Example: >
3712 :let lines = getbufline(bufnr("myfile"), 1, "$")
3713
3714< Can also be used as a |method|: >
3715 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003717 Return type: list<string>
3718
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003719 *getbufoneline()*
3720getbufoneline({buf}, {lnum})
3721 Just like `getbufline()` but only get one line and return it
3722 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003724 Return type: |String|
3725
3726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003727getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3728 The result is the value of option or local buffer variable
3729 {varname} in buffer {buf}. Note that the name without "b:"
3730 must be used.
3731 The {varname} argument is a string.
3732 When {varname} is empty returns a |Dictionary| with all the
3733 buffer-local variables.
3734 When {varname} is equal to "&" returns a |Dictionary| with all
3735 the buffer-local options.
3736 Otherwise, when {varname} starts with "&" returns the value of
3737 a buffer-local option.
3738 This also works for a global or buffer-local option, but it
3739 doesn't work for a global variable, window-local variable or
3740 window-local option.
3741 For the use of {buf}, see |bufname()| above.
3742 When the buffer or variable doesn't exist {def} or an empty
3743 string is returned, there is no error message.
3744 Examples: >
3745 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003746 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003747
3748< Can also be used as a |method|: >
3749 GetBufnr()->getbufvar(varname)
3750<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003751 Return type: any, depending on {varname}
3752
3753
Kota Kato66bb9ae2023-01-17 18:31:56 +00003754getcellwidths() *getcellwidths()*
3755 Returns a |List| of cell widths of character ranges overridden
3756 by |setcellwidths()|. The format is equal to the argument of
3757 |setcellwidths()|. If no character ranges have their cell
3758 widths overridden, an empty List is returned.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003759<
3760 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003761
3762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003763getchangelist([{buf}]) *getchangelist()*
3764 Returns the |changelist| for the buffer {buf}. For the use
3765 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3766 exist, an empty list is returned.
3767
3768 The returned list contains two entries: a list with the change
3769 locations and the current position in the list. Each
3770 entry in the change list is a dictionary with the following
3771 entries:
3772 col column number
3773 coladd column offset for 'virtualedit'
3774 lnum line number
3775 If buffer {buf} is the current buffer, then the current
3776 position refers to the position in the list. For other
3777 buffers, it is set to the length of the list.
3778
3779 Can also be used as a |method|: >
3780 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003781<
3782 Return type: list<any>
3783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003784
Doug Kearns9cd9e752024-04-07 17:42:17 +02003785getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003786 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003787 If {expr} is omitted, wait until a character is available.
3788 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003789 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003790 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003791 not consumed. Return zero if no character available.
3792 If you prefer always getting a string use |getcharstr()|.
3793
Doug Kearns9cd9e752024-04-07 17:42:17 +02003794 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003795 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003796 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003797 Otherwise a String is returned with the encoded character.
3798 For a special key it's a String with a sequence of bytes
3799 starting with 0x80 (decimal: 128). This is the same value as
3800 the String "\<Key>", e.g., "\<Left>". The returned value is
3801 also a String when a modifier (shift, control, alt) was used
3802 that is not included in the character.
3803
Doug Kearns9cd9e752024-04-07 17:42:17 +02003804 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003805 while Vim waits to see if this is the start of an escape
3806 sequence.
3807
Doug Kearns9cd9e752024-04-07 17:42:17 +02003808 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003809 one-byte character it is the character itself as a number.
3810 Use nr2char() to convert it to a String.
3811
3812 Use getcharmod() to obtain any additional modifiers.
3813
3814 When the user clicks a mouse button, the mouse event will be
3815 returned. The position can then be found in |v:mouse_col|,
3816 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3817 |getmousepos()| can also be used. Mouse move events will be
3818 ignored.
3819 This example positions the mouse as it would normally happen: >
3820 let c = getchar()
3821 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003822 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003823 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003824 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003825 endif
3826<
3827 When using bracketed paste only the first character is
3828 returned, the rest of the pasted text is dropped.
3829 |xterm-bracketed-paste|.
3830
3831 There is no prompt, you will somehow have to make clear to the
3832 user that a character has to be typed. The screen is not
3833 redrawn, e.g. when resizing the window. When using a popup
3834 window it should work better with a |popup-filter|.
3835
3836 There is no mapping for the character.
3837 Key codes are replaced, thus when the user presses the <Del>
3838 key you get the code for the <Del> key, not the raw character
3839 sequence. Examples: >
3840 getchar() == "\<Del>"
3841 getchar() == "\<S-Left>"
3842< This example redefines "f" to ignore case: >
3843 :nmap f :call FindChar()<CR>
3844 :function FindChar()
3845 : let c = nr2char(getchar())
3846 : while col('.') < col('$') - 1
3847 : normal l
3848 : if getline('.')[col('.') - 1] ==? c
3849 : break
3850 : endif
3851 : endwhile
3852 :endfunction
3853<
3854 You may also receive synthetic characters, such as
3855 |<CursorHold>|. Often you will want to ignore this and get
3856 another character: >
3857 :function GetKey()
3858 : let c = getchar()
3859 : while c == "\<CursorHold>"
3860 : let c = getchar()
3861 : endwhile
3862 : return c
3863 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003864<
3865 Return type: |Number| or |String|
3866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003867
3868getcharmod() *getcharmod()*
3869 The result is a Number which is the state of the modifiers for
3870 the last obtained character with getchar() or in another way.
3871 These values are added together:
3872 2 shift
3873 4 control
3874 8 alt (meta)
3875 16 meta (when it's different from ALT)
3876 32 mouse double click
3877 64 mouse triple click
3878 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003879 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003880 Only the modifiers that have not been included in the
3881 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003882 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003883
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003884 Return type: |Number|
3885
3886
3887getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003888 Get the position for String {expr}. Same as |getpos()| but the
3889 column number in the returned List is a character index
3890 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003891 If |getpos()| returns a very large column number, equal to
3892 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003893 of the last character.
3894
3895 Example:
3896 With the cursor on '세' in line 5 with text "여보세요": >
3897 getcharpos('.') returns [0, 5, 3, 0]
3898 getpos('.') returns [0, 5, 7, 0]
3899<
3900 Can also be used as a |method|: >
3901 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003902<
3903 Return type: list<number>
3904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003905
3906getcharsearch() *getcharsearch()*
3907 Return the current character search information as a {dict}
3908 with the following entries:
3909
3910 char character previously used for a character
3911 search (|t|, |f|, |T|, or |F|); empty string
3912 if no character search has been performed
3913 forward direction of character search; 1 for forward,
3914 0 for backward
3915 until type of character search; 1 for a |t| or |T|
3916 character search, 0 for an |f| or |F|
3917 character search
3918
3919 This can be useful to always have |;| and |,| search
3920 forward/backward regardless of the direction of the previous
3921 character search: >
3922 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
3923 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
3924< Also see |setcharsearch()|.
3925
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003926 Return type: dict<any>
3927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928
Doug Kearns9cd9e752024-04-07 17:42:17 +02003929getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003930 Get a single character from the user or input stream as a
3931 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003932 If {expr} is omitted, wait until a character is available.
3933 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003934 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003935 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003936 available, it is not consumed. Return an empty string
3937 if no character is available.
3938 Otherwise this works like |getchar()|, except that a number
3939 result is converted to a string.
3940
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003941 Return type: |String|
3942
3943
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003944getcmdcompltype() *getcmdcompltype()*
3945 Return the type of the current command-line completion.
3946 Only works when the command line is being edited, thus
3947 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01003948 See |:command-completion| for the return string.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003949 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3950 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003951 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003952
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003953 Return type: |String|
3954
3955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003956getcmdline() *getcmdline()*
3957 Return the current command-line. Only works when the command
3958 line is being edited, thus requires use of |c_CTRL-\_e| or
3959 |c_CTRL-R_=|.
3960 Example: >
3961 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003962< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
3963 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003964 Returns an empty string when entering a password or using
3965 |inputsecret()|.
3966
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003967 Return type: |String|
3968
3969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003970getcmdpos() *getcmdpos()*
3971 Return the position of the cursor in the command line as a
3972 byte count. The first column is 1.
3973 Only works when editing the command line, thus requires use of
3974 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3975 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003976 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
3977 |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003978
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003979 Return type: |Number|
3980
3981
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003982getcmdscreenpos() *getcmdscreenpos()*
3983 Return the screen position of the cursor in the command line
3984 as a byte count. The first column is 1.
3985 Instead of |getcmdpos()|, it adds the prompt position.
3986 Only works when editing the command line, thus requires use of
3987 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
3988 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01003989 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
3990 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01003991
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003992 Return type: |Number|
3993
3994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003995getcmdtype() *getcmdtype()*
3996 Return the current command-line type. Possible return values
3997 are:
3998 : normal Ex command
3999 > debug mode command |debug-mode|
4000 / forward search command
4001 ? backward search command
4002 @ |input()| command
4003 - |:insert| or |:append| command
4004 = |i_CTRL-R_=|
4005 Only works when editing the command line, thus requires use of
4006 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4007 Returns an empty string otherwise.
4008 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4009
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004010 Return type: |String|
4011
4012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004013getcmdwintype() *getcmdwintype()*
4014 Return the current |command-line-window| type. Possible return
4015 values are the same as |getcmdtype()|. Returns an empty string
4016 when not in the command-line window.
4017
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004018 Return type: |String|
4019
4020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004021getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4022 Return a list of command-line completion matches. The String
4023 {type} argument specifies what for. The following completion
4024 types are supported:
4025
4026 arglist file names in argument list
4027 augroup autocmd groups
4028 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004029 behave |:behave| suboptions
4030 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004031 color color schemes
4032 command Ex command
4033 cmdline |cmdline-completion| result
4034 compiler compilers
4035 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004036 custom,{func} custom completion, defined via {func}
4037 customlist,{func} custom completion, defined via {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038 diff_buffer |:diffget| and |:diffput| completion
4039 dir directory names
4040 environment environment variable names
4041 event autocommand events
4042 expression Vim expression
4043 file file and directory names
4044 file_in_path file and directory names in |'path'|
4045 filetype filetype names |'filetype'|
4046 function function name
4047 help help subjects
4048 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004049 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004050 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051 locale locale names (as output of locale -a)
4052 mapclear buffer argument
4053 mapping mapping name
4054 menu menus
4055 messages |:messages| suboptions
4056 option options
4057 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004058 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004059 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004060 shellcmd Shell command
4061 sign |:sign| suboptions
4062 syntax syntax file names |'syntax'|
4063 syntime |:syntime| suboptions
4064 tag tags
4065 tag_listfiles tags, file names
4066 user user names
4067 var user variables
4068
4069 If {pat} is an empty string, then all the matches are
4070 returned. Otherwise only items matching {pat} are returned.
4071 See |wildcards| for the use of special characters in {pat}.
4072
4073 If the optional {filtered} flag is set to 1, then 'wildignore'
4074 is applied to filter the results. Otherwise all the matches
4075 are returned. The 'wildignorecase' option always applies.
4076
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004077 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4078 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004079 regular expression matching is used. Thus this function
4080 follows the user preference, what happens on the command line.
4081 If you do not want this you can make 'wildoptions' empty
4082 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004084 If {type} is "cmdline", then the |cmdline-completion| result is
4085 returned. For example, to complete the possible values after
4086 a ":call" command: >
4087 echo getcompletion('call ', 'cmdline')
4088<
4089 If there are no matches, an empty list is returned. An
4090 invalid value for {type} produces an error.
4091
4092 Can also be used as a |method|: >
4093 GetPattern()->getcompletion('color')
4094<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004095 Return type: list<string>
4096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097 *getcurpos()*
4098getcurpos([{winid}])
4099 Get the position of the cursor. This is like getpos('.'), but
4100 includes an extra "curswant" item in the list:
4101 [0, lnum, col, off, curswant] ~
4102 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004103 cursor vertically. After |$| command it will be a very large
4104 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004105 |getpos()|.
4106 The first "bufnum" item is always zero. The byte position of
4107 the cursor is returned in 'col'. To get the character
4108 position, use |getcursorcharpos()|.
4109
4110 The optional {winid} argument can specify the window. It can
4111 be the window number or the |window-ID|. The last known
4112 cursor position is returned, this may be invalid for the
4113 current value of the buffer if it is not the current window.
4114 If {winid} is invalid a list with zeroes is returned.
4115
4116 This can be used to save and restore the cursor position: >
4117 let save_cursor = getcurpos()
4118 MoveTheCursorAround
4119 call setpos('.', save_cursor)
4120< Note that this only works within the window. See
4121 |winrestview()| for restoring more state.
4122
4123 Can also be used as a |method|: >
4124 GetWinid()->getcurpos()
4125<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004126 Return type: list<number>
4127
4128
4129getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004130 Same as |getcurpos()| but the column number in the returned
4131 List is a character index instead of a byte index.
4132
4133 Example:
4134 With the cursor on '보' in line 3 with text "여보세요": >
4135 getcursorcharpos() returns [0, 3, 2, 0, 3]
4136 getcurpos() returns [0, 3, 4, 0, 3]
4137<
4138 Can also be used as a |method|: >
4139 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004140<
4141 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004142
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004143
4144getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004145 The result is a String, which is the name of the current
4146 working directory. 'autochdir' is ignored.
4147
4148 With {winnr} return the local current directory of this window
4149 in the current tab page. {winnr} can be the window number or
4150 the |window-ID|.
4151 If {winnr} is -1 return the name of the global working
4152 directory. See also |haslocaldir()|.
4153
4154 With {winnr} and {tabnr} return the local current directory of
4155 the window in the specified tab page. If {winnr} is -1 return
4156 the working directory of the tabpage.
4157 If {winnr} is zero use the current window, if {tabnr} is zero
4158 use the current tabpage.
4159 Without any arguments, return the actual working directory of
4160 the current window.
4161 Return an empty string if the arguments are invalid.
4162
4163 Examples: >
4164 " Get the working directory of the current window
4165 :echo getcwd()
4166 :echo getcwd(0)
4167 :echo getcwd(0, 0)
4168 " Get the working directory of window 3 in tabpage 2
4169 :echo getcwd(3, 2)
4170 " Get the global working directory
4171 :echo getcwd(-1)
4172 " Get the working directory of tabpage 3
4173 :echo getcwd(-1, 3)
4174 " Get the working directory of current tabpage
4175 :echo getcwd(-1, 0)
4176
4177< Can also be used as a |method|: >
4178 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004179<
4180 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004181
4182getenv({name}) *getenv()*
4183 Return the value of environment variable {name}. The {name}
4184 argument is a string, without a leading '$'. Example: >
4185 myHome = getenv('HOME')
4186
4187< When the variable does not exist |v:null| is returned. That
4188 is different from a variable set to an empty string, although
4189 some systems interpret the empty value as the variable being
4190 deleted. See also |expr-env|.
4191
4192 Can also be used as a |method|: >
4193 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004194<
4195 Return type: |String| or |Number|
4196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004197
4198getfontname([{name}]) *getfontname()*
4199 Without an argument returns the name of the normal font being
4200 used. Like what is used for the Normal highlight group
4201 |hl-Normal|.
4202 With an argument a check is done whether String {name} is a
4203 valid font name. If not then an empty string is returned.
4204 Otherwise the actual font name is returned, or {name} if the
4205 GUI does not support obtaining the real name.
4206 Only works when the GUI is running, thus not in your vimrc or
4207 gvimrc file. Use the |GUIEnter| autocommand to use this
4208 function just after the GUI has started.
4209 Note that the GTK GUI accepts any font name, thus checking for
4210 a valid name does not work.
4211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004212 Return type: |String|
4213
4214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215getfperm({fname}) *getfperm()*
4216 The result is a String, which is the read, write, and execute
4217 permissions of the given file {fname}.
4218 If {fname} does not exist or its directory cannot be read, an
4219 empty string is returned.
4220 The result is of the form "rwxrwxrwx", where each group of
4221 "rwx" flags represent, in turn, the permissions of the owner
4222 of the file, the group the file belongs to, and other users.
4223 If a user does not have a given permission the flag for this
4224 is replaced with the string "-". Examples: >
4225 :echo getfperm("/etc/passwd")
4226 :echo getfperm(expand("~/.vimrc"))
4227< This will hopefully (from a security point of view) display
4228 the string "rw-r--r--" or even "rw-------".
4229
4230 Can also be used as a |method|: >
4231 GetFilename()->getfperm()
4232<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004233 Return type: |String|
4234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004235 For setting permissions use |setfperm()|.
4236
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004238getfsize({fname}) *getfsize()*
4239 The result is a Number, which is the size in bytes of the
4240 given file {fname}.
4241 If {fname} is a directory, 0 is returned.
4242 If the file {fname} can't be found, -1 is returned.
4243 If the size of {fname} is too big to fit in a Number then -2
4244 is returned.
4245
4246 Can also be used as a |method|: >
4247 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004248<
4249 Return type: |Number|
4250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004251
4252getftime({fname}) *getftime()*
4253 The result is a Number, which is the last modification time of
4254 the given file {fname}. The value is measured as seconds
4255 since 1st Jan 1970, and may be passed to strftime(). See also
4256 |localtime()| and |strftime()|.
4257 If the file {fname} can't be found -1 is returned.
4258
4259 Can also be used as a |method|: >
4260 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004261<
4262 Return type: |Number|
4263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004264
4265getftype({fname}) *getftype()*
4266 The result is a String, which is a description of the kind of
4267 file of the given file {fname}.
4268 If {fname} does not exist an empty string is returned.
4269 Here is a table over different kinds of files and their
4270 results:
4271 Normal file "file"
4272 Directory "dir"
4273 Symbolic link "link"
4274 Block device "bdev"
4275 Character device "cdev"
4276 Socket "socket"
4277 FIFO "fifo"
4278 All other "other"
4279 Example: >
4280 getftype("/home")
4281< Note that a type such as "link" will only be returned on
4282 systems that support it. On some systems only "dir" and
4283 "file" are returned. On MS-Windows a symbolic link to a
4284 directory returns "dir" instead of "link".
4285
4286 Can also be used as a |method|: >
4287 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004288<
4289 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004290
4291getimstatus() *getimstatus()*
4292 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004293 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004294 See 'imstatusfunc'.
4295
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004296 Return type: |Number|
4297
4298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004299getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4300 Returns the |jumplist| for the specified window.
4301
4302 Without arguments use the current window.
4303 With {winnr} only use this window in the current tab page.
4304 {winnr} can also be a |window-ID|.
4305 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004306 page. If {winnr} or {tabnr} is invalid, an empty list is
4307 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004308
4309 The returned list contains two entries: a list with the jump
4310 locations and the last used jump position number in the list.
4311 Each entry in the jump location list is a dictionary with
4312 the following entries:
4313 bufnr buffer number
4314 col column number
4315 coladd column offset for 'virtualedit'
4316 filename filename if available
4317 lnum line number
4318
4319 Can also be used as a |method|: >
4320 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004321<
4322 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004323
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004324 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004325getline({lnum} [, {end}])
4326 Without {end} the result is a String, which is line {lnum}
4327 from the current buffer. Example: >
4328 getline(1)
4329< When {lnum} is a String that doesn't start with a
4330 digit, |line()| is called to translate the String into a Number.
4331 To get the line under the cursor: >
4332 getline(".")
4333< When {lnum} is a number smaller than 1 or bigger than the
4334 number of lines in the buffer, an empty string is returned.
4335
4336 When {end} is given the result is a |List| where each item is
4337 a line from the current buffer in the range {lnum} to {end},
4338 including line {end}.
4339 {end} is used in the same way as {lnum}.
4340 Non-existing lines are silently omitted.
4341 When {end} is before {lnum} an empty |List| is returned.
4342 Example: >
4343 :let start = line('.')
4344 :let end = search("^$") - 1
4345 :let lines = getline(start, end)
4346
4347< Can also be used as a |method|: >
4348 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004349<
4350 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004351
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004352 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004353 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004354
4355getloclist({nr} [, {what}]) *getloclist()*
4356 Returns a |List| with all the entries in the location list for
4357 window {nr}. {nr} can be the window number or the |window-ID|.
4358 When {nr} is zero the current window is used.
4359
4360 For a location list window, the displayed location list is
4361 returned. For an invalid window number {nr}, an empty list is
4362 returned. Otherwise, same as |getqflist()|.
4363
4364 If the optional {what} dictionary argument is supplied, then
4365 returns the items listed in {what} as a dictionary. Refer to
4366 |getqflist()| for the supported items in {what}.
4367
4368 In addition to the items supported by |getqflist()| in {what},
4369 the following item is supported by |getloclist()|:
4370
4371 filewinid id of the window used to display files
4372 from the location list. This field is
4373 applicable only when called from a
4374 location list window. See
4375 |location-list-file-window| for more
4376 details.
4377
4378 Returns a |Dictionary| with default values if there is no
4379 location list for the window {nr}.
4380 Returns an empty Dictionary if window {nr} does not exist.
4381
4382 Examples (See also |getqflist-examples|): >
4383 :echo getloclist(3, {'all': 0})
4384 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004385<
4386 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004387
4388
4389getmarklist([{buf}]) *getmarklist()*
4390 Without the {buf} argument returns a |List| with information
4391 about all the global marks. |mark|
4392
4393 If the optional {buf} argument is specified, returns the
4394 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004395 see |bufname()|. If {buf} is invalid, an empty list is
4396 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004397
4398 Each item in the returned List is a |Dict| with the following:
4399 mark name of the mark prefixed by "'"
4400 pos a |List| with the position of the mark:
4401 [bufnum, lnum, col, off]
4402 Refer to |getpos()| for more information.
4403 file file name
4404
4405 Refer to |getpos()| for getting information about a specific
4406 mark.
4407
4408 Can also be used as a |method|: >
4409 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004410<
4411 Return type: list<dict<any>> or list<any>
4412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004413
4414getmatches([{win}]) *getmatches()*
4415 Returns a |List| with all matches previously defined for the
4416 current window by |matchadd()| and the |:match| commands.
4417 |getmatches()| is useful in combination with |setmatches()|,
4418 as |setmatches()| can restore a list of matches saved by
4419 |getmatches()|.
4420 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004421 window ID instead of the current window. If {win} is invalid,
4422 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004423 Example: >
4424 :echo getmatches()
4425< [{'group': 'MyGroup1', 'pattern': 'TODO',
4426 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4427 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4428 :let m = getmatches()
4429 :call clearmatches()
4430 :echo getmatches()
4431< [] >
4432 :call setmatches(m)
4433 :echo getmatches()
4434< [{'group': 'MyGroup1', 'pattern': 'TODO',
4435 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4436 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4437 :unlet m
4438<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004439 Return type: list<dict<any>> or list<any>
4440
4441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004442getmousepos() *getmousepos()*
4443 Returns a |Dictionary| with the last known position of the
4444 mouse. This can be used in a mapping for a mouse click or in
4445 a filter of a popup window. The items are:
4446 screenrow screen row
4447 screencol screen column
4448 winid Window ID of the click
4449 winrow row inside "winid"
4450 wincol column inside "winid"
4451 line text line inside "winid"
4452 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004453 coladd offset (in screen columns) from the
4454 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004455 All numbers are 1-based.
4456
4457 If not over a window, e.g. when in the command line, then only
4458 "screenrow" and "screencol" are valid, the others are zero.
4459
4460 When on the status line below a window or the vertical
4461 separator right of a window, the "line" and "column" values
4462 are zero.
4463
4464 When the position is after the text then "column" is the
4465 length of the text in bytes plus one.
4466
4467 If the mouse is over a popup window then that window is used.
4468
4469 When using |getchar()| the Vim variables |v:mouse_lnum|,
4470 |v:mouse_col| and |v:mouse_winid| also provide these values.
4471
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004472 Return type: dict<number>
4473
4474
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004475getmouseshape() *getmouseshape()*
4476 Returns the name of the currently showing mouse pointer.
4477 When the |+mouseshape| feature is not supported or the shape
4478 is unknown an empty string is returned.
4479 This function is mainly intended for testing.
4480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004481 Return type: |String|
4482
4483
4484getpid() *getpid()*
4485 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004486 On Unix and MS-Windows this is a unique number, until Vim
4487 exits.
4488
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004489 Return type: |Number|
4490
4491
4492getpos({expr}) *getpos()*
4493 Get the position for String {expr}. For possible values of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004494 {expr} see |line()|. For getting the cursor position see
4495 |getcurpos()|.
4496 The result is a |List| with four numbers:
4497 [bufnum, lnum, col, off]
4498 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4499 is the buffer number of the mark.
4500 "lnum" and "col" are the position in the buffer. The first
4501 column is 1.
4502 The "off" number is zero, unless 'virtualedit' is used. Then
4503 it is the offset in screen columns from the start of the
4504 character. E.g., a position within a <Tab> or after the last
4505 character.
4506 Note that for '< and '> Visual mode matters: when it is "V"
4507 (visual line mode) the column of '< is zero and the column of
naohiro ono56200ee2022-01-01 14:59:44 +00004508 '> is a large number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004509 The column number in the returned List is the byte position
4510 within the line. To get the character position in the line,
4511 use |getcharpos()|.
naohiro ono56200ee2022-01-01 14:59:44 +00004512 A very large column number equal to |v:maxcol| can be returned,
4513 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004514 If {expr} is invalid, returns a list with all zeros.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004515 This can be used to save and restore the position of a mark: >
4516 let save_a_mark = getpos("'a")
4517 ...
4518 call setpos("'a", save_a_mark)
4519< Also see |getcharpos()|, |getcurpos()| and |setpos()|.
4520
4521 Can also be used as a |method|: >
4522 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004523<
4524 Return type: list<number>
4525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004526
4527getqflist([{what}]) *getqflist()*
4528 Returns a |List| with all the current quickfix errors. Each
4529 list item is a dictionary with these entries:
4530 bufnr number of buffer that has the file name, use
4531 bufname() to get the name
4532 module module name
4533 lnum line number in the buffer (first line is 1)
4534 end_lnum
4535 end of line number if the item is multiline
4536 col column number (first column is 1)
4537 end_col end of column number if the item has range
4538 vcol |TRUE|: "col" is visual column
4539 |FALSE|: "col" is byte index
4540 nr error number
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004541 pattern search list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004542 text description of the error
4543 type type of the error, 'E', '1', etc.
4544 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004545 user_data
4546 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004547 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004548
4549 When there is no error list or it's empty, an empty list is
4550 returned. Quickfix list entries with a non-existing buffer
4551 number are returned with "bufnr" set to zero (Note: some
4552 functions accept buffer number zero for the alternate buffer,
4553 you may need to explicitly check for zero).
4554
4555 Useful application: Find pattern matches in multiple files and
4556 do something with them: >
4557 :vimgrep /theword/jg *.c
4558 :for d in getqflist()
4559 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4560 :endfor
4561<
4562 If the optional {what} dictionary argument is supplied, then
4563 returns only the items listed in {what} as a dictionary. The
4564 following string items are supported in {what}:
4565 changedtick get the total number of changes made
4566 to the list |quickfix-changedtick|
4567 context get the |quickfix-context|
4568 efm errorformat to use when parsing "lines". If
4569 not present, then the 'errorformat' option
4570 value is used.
4571 id get information for the quickfix list with
4572 |quickfix-ID|; zero means the id for the
4573 current list or the list specified by "nr"
4574 idx get information for the quickfix entry at this
4575 index in the list specified by 'id' or 'nr'.
4576 If set to zero, then uses the current entry.
4577 See |quickfix-index|
4578 items quickfix list entries
4579 lines parse a list of lines using 'efm' and return
4580 the resulting entries. Only a |List| type is
4581 accepted. The current quickfix list is not
4582 modified. See |quickfix-parse|.
4583 nr get information for this quickfix list; zero
4584 means the current quickfix list and "$" means
4585 the last quickfix list
4586 qfbufnr number of the buffer displayed in the quickfix
4587 window. Returns 0 if the quickfix buffer is
4588 not present. See |quickfix-buffer|.
4589 size number of entries in the quickfix list
4590 title get the list title |quickfix-title|
4591 winid get the quickfix |window-ID|
4592 all all of the above quickfix properties
4593 Non-string items in {what} are ignored. To get the value of a
4594 particular item, set it to zero.
4595 If "nr" is not present then the current quickfix list is used.
4596 If both "nr" and a non-zero "id" are specified, then the list
4597 specified by "id" is used.
4598 To get the number of lists in the quickfix stack, set "nr" to
4599 "$" in {what}. The "nr" value in the returned dictionary
4600 contains the quickfix stack size.
4601 When "lines" is specified, all the other items except "efm"
4602 are ignored. The returned dictionary contains the entry
4603 "items" with the list of entries.
4604
4605 The returned dictionary contains the following entries:
4606 changedtick total number of changes made to the
4607 list |quickfix-changedtick|
4608 context quickfix list context. See |quickfix-context|
4609 If not present, set to "".
4610 id quickfix list ID |quickfix-ID|. If not
4611 present, set to 0.
4612 idx index of the quickfix entry in the list. If not
4613 present, set to 0.
4614 items quickfix list entries. If not present, set to
4615 an empty list.
4616 nr quickfix list number. If not present, set to 0
4617 qfbufnr number of the buffer displayed in the quickfix
4618 window. If not present, set to 0.
4619 size number of entries in the quickfix list. If not
4620 present, set to 0.
4621 title quickfix list title text. If not present, set
4622 to "".
4623 winid quickfix |window-ID|. If not present, set to 0
4624
4625 Examples (See also |getqflist-examples|): >
4626 :echo getqflist({'all': 1})
4627 :echo getqflist({'nr': 2, 'title': 1})
4628 :echo getqflist({'lines' : ["F1:10:L10"]})
4629<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004630 Return type: list<dict<any>> or list<any>
4631
4632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004633getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4634 The result is a String, which is the contents of register
4635 {regname}. Example: >
4636 :let cliptext = getreg('*')
4637< When register {regname} was not set the result is an empty
4638 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004639 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004640
4641 getreg('=') returns the last evaluated value of the expression
4642 register. (For use in maps.)
4643 getreg('=', 1) returns the expression itself, so that it can
4644 be restored with |setreg()|. For other registers the extra
4645 argument is ignored, thus you can always give it.
4646
4647 If {list} is present and |TRUE|, the result type is changed
4648 to |List|. Each list item is one text line. Use it if you care
4649 about zero bytes possibly present inside register: without
4650 third argument both NLs and zero bytes are represented as NLs
4651 (see |NL-used-for-Nul|).
4652 When the register was not set an empty list is returned.
4653
4654 If {regname} is "", the unnamed register '"' is used.
4655 If {regname} is not specified, |v:register| is used.
4656 In |Vim9-script| {regname} must be one character.
4657
4658 Can also be used as a |method|: >
4659 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004660<
4661 Return type: |String|
4662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004663
4664getreginfo([{regname}]) *getreginfo()*
4665 Returns detailed information about register {regname} as a
4666 Dictionary with the following entries:
4667 regcontents List of lines contained in register
4668 {regname}, like
4669 |getreg|({regname}, 1, 1).
4670 regtype the type of register {regname}, as in
4671 |getregtype()|.
4672 isunnamed Boolean flag, v:true if this register
4673 is currently pointed to by the unnamed
4674 register.
4675 points_to for the unnamed register, gives the
4676 single letter name of the register
4677 currently pointed to (see |quotequote|).
4678 For example, after deleting a line
4679 with `dd`, this field will be "1",
4680 which is the register that got the
4681 deleted text.
4682
4683 The {regname} argument is a string. If {regname} is invalid
4684 or not set, an empty Dictionary will be returned.
4685 If {regname} is "" or "@", the unnamed register '"' is used.
4686 If {regname} is not specified, |v:register| is used.
4687 The returned Dictionary can be passed to |setreg()|.
4688 In |Vim9-script| {regname} must be one character.
4689
4690 Can also be used as a |method|: >
4691 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004692<
4693 Return type: dict<any>
4694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004695
Shougo Matsushita19b71882024-02-28 22:48:12 +01004696getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004697 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004698 buffer.
4699
4700 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004701 See |getpos()| for the format of the list. It's possible
4702 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004703 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004704
4705 The optional argument {opts} is a Dict and supports the
4706 following items:
4707
zeertzjqafc22952024-05-24 19:07:12 +02004708 type Specify the region's selection type.
4709 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004710 except that the width can be omitted
4711 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004712 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004713
zeertzjq87410ab2024-03-02 06:00:23 +08004714 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004715 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004716 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004717
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004718 You can get the last selection type by |visualmode()|.
4719 If Visual mode is active, use |mode()| to get the Visual mode
4720 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004721 This function is useful to get text starting and ending in
4722 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004723
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004724 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004725 Note that:
4726 - Order of {pos1} and {pos2} doesn't matter, it will always
4727 return content from the upper left position to the lower
4728 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004729 - If 'virtualedit' is enabled and the region is past the end
4730 of the lines, resulting lines are padded with spaces.
4731 - If the region is blockwise and it starts or ends in the
4732 middle of a multi-cell character, it is not included but
4733 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004734 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004735 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004736 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004737 - It is evaluated in current window context, which makes a
4738 difference if the buffer is displayed in a window with
4739 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004740
4741 Examples: >
4742 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004743 \ <Cmd>echow getregion(
4744 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004745<
4746 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004747 getpos('.')->getregion(getpos("'a"))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004748
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004749<
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004750getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4751 Same as |getregion()|, but returns a list of positions
4752 describing the buffer text segments bound by {pos1} and
4753 {pos2}.
4754 The segments are a pair of positions for every line: >
4755 [[{start_pos}, {end_pos}], ...]
4756<
4757 The position is a |List| with four numbers:
4758 [bufnum, lnum, col, off]
4759 "bufnum" is the buffer number.
4760 "lnum" and "col" are the position in the buffer. The first
4761 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004762 If the "off" number of a starting position is non-zero, it is
4763 the offset in screen columns from the start of the character.
4764 E.g., a position within a <Tab> or after the last character.
4765 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004766 the offset of the character's first cell not included in the
4767 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004768
zeertzjq2b09de92024-05-24 07:48:51 +02004769 Apart from the options supported by |getregion()|, {opts} also
4770 supports the following:
4771
4772 eol If |TRUE|, indicate positions beyond
4773 the end of a line with "col" values
4774 one more than the length of the line.
4775 If |FALSE|, positions are limited
4776 within their lines, and if a line is
4777 empty or the selection is entirely
4778 beyond the end of a line, a "col"
4779 value of 0 is used for both positions.
4780 (default: |FALSE|)
4781
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004782 Can also be used as a |method|: >
4783 getpos('.')->getregionpos(getpos("'a"))
4784<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004785 Return type: list<string>
4786
4787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004788getregtype([{regname}]) *getregtype()*
4789 The result is a String, which is type of register {regname}.
4790 The value will be one of:
4791 "v" for |characterwise| text
4792 "V" for |linewise| text
4793 "<CTRL-V>{width}" for |blockwise-visual| text
4794 "" for an empty or unknown register
4795 <CTRL-V> is one character with value 0x16.
4796 The {regname} argument is a string. If {regname} is "", the
4797 unnamed register '"' is used. If {regname} is not specified,
4798 |v:register| is used.
4799 In |Vim9-script| {regname} must be one character.
4800
4801 Can also be used as a |method|: >
4802 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004803<
4804 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004805
Bram Moolenaar71badf92023-04-22 22:40:14 +01004806getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004807 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004808 scripts in the order they were sourced, like what
4809 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004810
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004811 The optional Dict argument {opts} supports the following
4812 optional items:
4813 name Script name match pattern. If specified,
4814 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004815 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004816 "name" are returned.
4817 sid Script ID |<SID>|. If specified, only
4818 information about the script with ID "sid" is
4819 returned and "name" is ignored.
4820
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004821 Each item in the returned List is a |Dict| with the following
4822 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004823 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004824 `import autoload` but was not actually sourced
4825 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004826 functions List of script-local function names defined in
4827 the script. Present only when a particular
4828 script is specified using the "sid" item in
4829 {opts}.
4830 name Vim script file name.
4831 sid Script ID |<SID>|.
4832 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004833 this script name links to, if any, otherwise
4834 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004835 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004836 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004837 specified using the "sid" item in {opts}.
4838 Note that this is a copy, the value of
4839 script-local variables cannot be changed using
4840 this dictionary.
h_east59858792023-10-25 22:47:05 +09004841 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004842
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004843 Examples: >
4844 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004845 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004846<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004847 Return type: list<dict<any>>
4848
4849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004850gettabinfo([{tabnr}]) *gettabinfo()*
4851 If {tabnr} is not specified, then information about all the
4852 tab pages is returned as a |List|. Each List item is a
4853 |Dictionary|. Otherwise, {tabnr} specifies the tab page
4854 number and information about that one is returned. If the tab
4855 page does not exist an empty List is returned.
4856
4857 Each List item is a |Dictionary| with the following entries:
4858 tabnr tab page number.
4859 variables a reference to the dictionary with
4860 tabpage-local variables
4861 windows List of |window-ID|s in the tab page.
4862
4863 Can also be used as a |method|: >
4864 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004865<
4866 Return type: list<dict<any>>
4867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004868
4869gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
4870 Get the value of a tab-local variable {varname} in tab page
4871 {tabnr}. |t:var|
4872 Tabs are numbered starting with one.
4873 The {varname} argument is a string. When {varname} is empty a
4874 dictionary with all tab-local variables is returned.
4875 Note that the name without "t:" must be used.
4876 When the tab or variable doesn't exist {def} or an empty
4877 string is returned, there is no error message.
4878
4879 Can also be used as a |method|: >
4880 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004881<
4882 Return type: any, depending on {varname}
4883
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004884
4885gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
4886 Get the value of window-local variable {varname} in window
4887 {winnr} in tab page {tabnr}.
4888 The {varname} argument is a string. When {varname} is empty a
4889 dictionary with all window-local variables is returned.
4890 When {varname} is equal to "&" get the values of all
4891 window-local options in a |Dictionary|.
4892 Otherwise, when {varname} starts with "&" get the value of a
4893 window-local option.
4894 Note that {varname} must be the name without "w:".
4895 Tabs are numbered starting with one. For the current tabpage
4896 use |getwinvar()|.
4897 {winnr} can be the window number or the |window-ID|.
4898 When {winnr} is zero the current window is used.
4899 This also works for a global option, buffer-local option and
4900 window-local option, but it doesn't work for a global variable
4901 or buffer-local variable.
4902 When the tab, window or variable doesn't exist {def} or an
4903 empty string is returned, there is no error message.
4904 Examples: >
4905 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004906 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004907<
4908 To obtain all window-local variables use: >
4909 gettabwinvar({tabnr}, {winnr}, '&')
4910
4911< Can also be used as a |method|: >
4912 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004913<
4914 Return type: any, depending on {varname}
4915
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004916
4917gettagstack([{winnr}]) *gettagstack()*
4918 The result is a Dict, which is the tag stack of window {winnr}.
4919 {winnr} can be the window number or the |window-ID|.
4920 When {winnr} is not specified, the current window is used.
4921 When window {winnr} doesn't exist, an empty Dict is returned.
4922
4923 The returned dictionary contains the following entries:
4924 curidx Current index in the stack. When at
4925 top of the stack, set to (length + 1).
4926 Index of bottom of the stack is 1.
4927 items List of items in the stack. Each item
4928 is a dictionary containing the
4929 entries described below.
4930 length Number of entries in the stack.
4931
4932 Each item in the stack is a dictionary with the following
4933 entries:
4934 bufnr buffer number of the current jump
4935 from cursor position before the tag jump.
4936 See |getpos()| for the format of the
4937 returned list.
4938 matchnr current matching tag number. Used when
4939 multiple matching tags are found for a
4940 name.
4941 tagname name of the tag
4942
4943 See |tagstack| for more information about the tag stack.
4944
4945 Can also be used as a |method|: >
4946 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004947<
4948 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004949
4950
4951gettext({text}) *gettext()*
4952 Translate String {text} if possible.
4953 This is mainly for use in the distributed Vim scripts. When
4954 generating message translations the {text} is extracted by
4955 xgettext, the translator can add the translated message in the
4956 .po file and Vim will lookup the translation when gettext() is
4957 called.
4958 For {text} double quoted strings are preferred, because
4959 xgettext does not understand escaping in single quoted
4960 strings.
4961
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004962 Return type: |String|
4963
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004964
4965getwininfo([{winid}]) *getwininfo()*
4966 Returns information about windows as a |List| with Dictionaries.
4967
4968 If {winid} is given Information about the window with that ID
4969 is returned, as a |List| with one item. If the window does not
4970 exist the result is an empty list.
4971
4972 Without {winid} information about all the windows in all the
4973 tab pages is returned.
4974
4975 Each List item is a |Dictionary| with the following entries:
4976 botline last complete displayed buffer line
4977 bufnr number of buffer in the window
4978 height window height (excluding winbar)
4979 loclist 1 if showing a location list
4980 {only with the +quickfix feature}
4981 quickfix 1 if quickfix or location list window
4982 {only with the +quickfix feature}
4983 terminal 1 if a terminal window
4984 {only with the +terminal feature}
4985 tabnr tab page number
4986 topline first displayed buffer line
4987 variables a reference to the dictionary with
4988 window-local variables
4989 width window width
4990 winbar 1 if the window has a toolbar, 0
4991 otherwise
4992 wincol leftmost screen column of the window;
4993 "col" from |win_screenpos()|
4994 textoff number of columns occupied by any
4995 'foldcolumn', 'signcolumn' and line
4996 number in front of the text
4997 winid |window-ID|
4998 winnr window number
4999 winrow topmost screen line of the window;
5000 "row" from |win_screenpos()|
5001
5002 Can also be used as a |method|: >
5003 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005004<
5005 Return type: list<dict<any>>
5006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005007
5008getwinpos([{timeout}]) *getwinpos()*
5009 The result is a |List| with two numbers, the result of
5010 |getwinposx()| and |getwinposy()| combined:
5011 [x-pos, y-pos]
5012 {timeout} can be used to specify how long to wait in msec for
5013 a response from the terminal. When omitted 100 msec is used.
5014 Use a longer time for a remote terminal.
5015 When using a value less than 10 and no response is received
5016 within that time, a previously reported position is returned,
5017 if available. This can be used to poll for the position and
5018 do some work in the meantime: >
5019 while 1
5020 let res = getwinpos(1)
5021 if res[0] >= 0
5022 break
5023 endif
5024 " Do some work here
5025 endwhile
5026<
5027
5028 Can also be used as a |method|: >
5029 GetTimeout()->getwinpos()
5030<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005031 Return type: list<number>
5032
5033
5034getwinposx() *getwinposx()*
5035 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005036 the left hand side of the GUI Vim window. Also works for an
5037 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005038 The result will be -1 if the information is not available
5039 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005040 The value can be used with `:winpos`.
5041
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005042 Return type: |Number|
5043
5044
5045getwinposy() *getwinposy()*
5046 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005047 the top of the GUI Vim window. Also works for an xterm (uses
5048 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005049 The result will be -1 if the information is not available
5050 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005051 The value can be used with `:winpos`.
5052
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005053 Return type: |Number|
5054
5055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005056getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5057 Like |gettabwinvar()| for the current tabpage.
5058 Examples: >
5059 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005060 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005061
5062< Can also be used as a |method|: >
5063 GetWinnr()->getwinvar(varname)
5064<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005065 Return type: any, depending on {varname}
5066
5067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005068glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5069 Expand the file wildcards in {expr}. See |wildcards| for the
5070 use of special characters.
5071
5072 Unless the optional {nosuf} argument is given and is |TRUE|,
5073 the 'suffixes' and 'wildignore' options apply: Names matching
5074 one of the patterns in 'wildignore' will be skipped and
5075 'suffixes' affect the ordering of matches.
5076 'wildignorecase' always applies.
5077
5078 When {list} is present and it is |TRUE| the result is a |List|
5079 with all matching files. The advantage of using a List is,
5080 you also get filenames containing newlines correctly.
5081 Otherwise the result is a String and when there are several
5082 matches, they are separated by <NL> characters.
5083
5084 If the expansion fails, the result is an empty String or List.
5085
5086 You can also use |readdir()| if you need to do complicated
5087 things, such as limiting the number of matches.
5088
5089 A name for a non-existing file is not included. A symbolic
5090 link is only included if it points to an existing file.
5091 However, when the {alllinks} argument is present and it is
5092 |TRUE| then all symbolic links are included.
5093
5094 For most systems backticks can be used to get files names from
5095 any external command. Example: >
5096 :let tagfiles = glob("`find . -name tags -print`")
5097 :let &tags = substitute(tagfiles, "\n", ",", "g")
5098< The result of the program inside the backticks should be one
5099 item per line. Spaces inside an item are allowed.
5100
5101 See |expand()| for expanding special Vim variables. See
5102 |system()| for getting the raw output of an external command.
5103
5104 Can also be used as a |method|: >
5105 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005106<
5107 Return type: |String| or list<string> or list<any> depending
5108 on {list}
5109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005110
5111glob2regpat({string}) *glob2regpat()*
5112 Convert a file pattern, as used by glob(), into a search
5113 pattern. The result can be used to match with a string that
5114 is a file name. E.g. >
5115 if filename =~ glob2regpat('Make*.mak')
5116< This is equivalent to: >
5117 if filename =~ '^Make.*\.mak$'
5118< When {string} is an empty string the result is "^$", match an
5119 empty string.
5120 Note that the result depends on the system. On MS-Windows
5121 a backslash usually means a path separator.
5122
5123 Can also be used as a |method|: >
5124 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005125<
5126 Return type: |String|
5127
5128 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005129globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5130 Perform glob() for String {expr} on all directories in {path}
5131 and concatenate the results. Example: >
5132 :echo globpath(&rtp, "syntax/c.vim")
5133<
5134 {path} is a comma-separated list of directory names. Each
5135 directory name is prepended to {expr} and expanded like with
5136 |glob()|. A path separator is inserted when needed.
5137 To add a comma inside a directory name escape it with a
5138 backslash. Note that on MS-Windows a directory may have a
5139 trailing backslash, remove it if you put a comma after it.
5140 If the expansion fails for one of the directories, there is no
5141 error message.
5142
5143 Unless the optional {nosuf} argument is given and is |TRUE|,
5144 the 'suffixes' and 'wildignore' options apply: Names matching
5145 one of the patterns in 'wildignore' will be skipped and
5146 'suffixes' affect the ordering of matches.
5147
5148 When {list} is present and it is |TRUE| the result is a |List|
5149 with all matching files. The advantage of using a List is, you
5150 also get filenames containing newlines correctly. Otherwise
5151 the result is a String and when there are several matches,
5152 they are separated by <NL> characters. Example: >
5153 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5154<
5155 {alllinks} is used as with |glob()|.
5156
5157 The "**" item can be used to search in a directory tree.
5158 For example, to find all "README.txt" files in the directories
5159 in 'runtimepath' and below: >
5160 :echo globpath(&rtp, "**/README.txt")
5161< Upwards search and limiting the depth of "**" is not
5162 supported, thus using 'path' will not always work properly.
5163
5164 Can also be used as a |method|, the base is passed as the
5165 second argument: >
5166 GetExpr()->globpath(&rtp)
5167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005168 Return type: |String| or list<string> or list<any> depending
5169 on {list}
5170
5171
5172has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005173 When {check} is omitted or is zero: The result is a Number,
5174 which is 1 if the feature {feature} is supported, zero
5175 otherwise. The {feature} argument is a string, case is
5176 ignored. See |feature-list| below.
5177
5178 When {check} is present and not zero: The result is a Number,
5179 which is 1 if the feature {feature} could ever be supported,
5180 zero otherwise. This is useful to check for a typo in
5181 {feature} and to detect dead code. Keep in mind that an older
5182 Vim version will not know about a feature added later and
5183 features that have been abandoned will not be known by the
5184 current Vim version.
5185
5186 Also see |exists()| and |exists_compiled()|.
5187
5188 Note that to skip code that has a syntax error when the
5189 feature is not available, Vim may skip the rest of the line
5190 and miss a following `endif`. Therefore put the `endif` on a
5191 separate line: >
5192 if has('feature')
5193 let x = this->breaks->without->the->feature
5194 endif
5195< If the `endif` would be moved to the second line as "| endif" it
5196 would not be found.
5197
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005198 Return type: |Number|
5199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005200
5201has_key({dict}, {key}) *has_key()*
5202 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005203 has an entry with key {key}. FALSE otherwise.
5204 The {key} argument is a string. In |Vim9| script a number is
5205 also accepted (and converted to a string) but no other types.
5206 In legacy script the usual automatic conversion to string is
5207 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005208
5209 Can also be used as a |method|: >
5210 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005211<
5212 Return type: |Number|
5213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005214
5215haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5216 The result is a Number:
5217 1 when the window has set a local directory via |:lcd|
5218 2 when the tab-page has set a local directory via |:tcd|
5219 0 otherwise.
5220
5221 Without arguments use the current window.
5222 With {winnr} use this window in the current tab page.
5223 With {winnr} and {tabnr} use the window in the specified tab
5224 page.
5225 {winnr} can be the window number or the |window-ID|.
5226 If {winnr} is -1 it is ignored and only the tabpage is used.
5227 Return 0 if the arguments are invalid.
5228 Examples: >
5229 if haslocaldir() == 1
5230 " window local directory case
5231 elseif haslocaldir() == 2
5232 " tab-local directory case
5233 else
5234 " global directory case
5235 endif
5236
5237 " current window
5238 :echo haslocaldir()
5239 :echo haslocaldir(0)
5240 :echo haslocaldir(0, 0)
5241 " window n in current tab page
5242 :echo haslocaldir(n)
5243 :echo haslocaldir(n, 0)
5244 " window n in tab page m
5245 :echo haslocaldir(n, m)
5246 " tab page m
5247 :echo haslocaldir(-1, m)
5248<
5249 Can also be used as a |method|: >
5250 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005251<
5252 Return type: |Number|
5253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005254
5255hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5256 The result is a Number, which is TRUE if there is a mapping
5257 that contains {what} in somewhere in the rhs (what it is
5258 mapped to) and this mapping exists in one of the modes
5259 indicated by {mode}.
5260 The arguments {what} and {mode} are strings.
5261 When {abbr} is there and it is |TRUE| use abbreviations
5262 instead of mappings. Don't forget to specify Insert and/or
5263 Command-line mode.
5264 Both the global mappings and the mappings local to the current
5265 buffer are checked for a match.
5266 If no matching mapping is found FALSE is returned.
5267 The following characters are recognized in {mode}:
5268 n Normal mode
5269 v Visual and Select mode
5270 x Visual mode
5271 s Select mode
5272 o Operator-pending mode
5273 i Insert mode
5274 l Language-Argument ("r", "f", "t", etc.)
5275 c Command-line mode
5276 When {mode} is omitted, "nvo" is used.
5277
5278 This function is useful to check if a mapping already exists
5279 to a function in a Vim script. Example: >
5280 :if !hasmapto('\ABCdoit')
5281 : map <Leader>d \ABCdoit
5282 :endif
5283< This installs the mapping to "\ABCdoit" only if there isn't
5284 already a mapping to "\ABCdoit".
5285
5286 Can also be used as a |method|: >
5287 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005288<
5289 Return type: |Number|
5290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005291
5292histadd({history}, {item}) *histadd()*
5293 Add the String {item} to the history {history} which can be
5294 one of: *hist-names*
5295 "cmd" or ":" command line history
5296 "search" or "/" search pattern history
5297 "expr" or "=" typed expression history
5298 "input" or "@" input line history
5299 "debug" or ">" debug command history
5300 empty the current or last used history
5301 The {history} string does not need to be the whole name, one
5302 character is sufficient.
5303 If {item} does already exist in the history, it will be
5304 shifted to become the newest entry.
5305 The result is a Number: TRUE if the operation was successful,
5306 otherwise FALSE is returned.
5307
5308 Example: >
5309 :call histadd("input", strftime("%Y %b %d"))
5310 :let date=input("Enter date: ")
5311< This function is not available in the |sandbox|.
5312
5313 Can also be used as a |method|, the base is passed as the
5314 second argument: >
5315 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005316<
5317 Return type: |Number|
5318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005319
5320histdel({history} [, {item}]) *histdel()*
5321 Clear {history}, i.e. delete all its entries. See |hist-names|
5322 for the possible values of {history}.
5323
5324 If the parameter {item} evaluates to a String, it is used as a
5325 regular expression. All entries matching that expression will
5326 be removed from the history (if there are any).
5327 Upper/lowercase must match, unless "\c" is used |/\c|.
5328 If {item} evaluates to a Number, it will be interpreted as
5329 an index, see |:history-indexing|. The respective entry will
5330 be removed if it exists.
5331
5332 The result is TRUE for a successful operation, otherwise FALSE
5333 is returned.
5334
5335 Examples:
5336 Clear expression register history: >
5337 :call histdel("expr")
5338<
5339 Remove all entries starting with "*" from the search history: >
5340 :call histdel("/", '^\*')
5341<
5342 The following three are equivalent: >
5343 :call histdel("search", histnr("search"))
5344 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005345 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005346<
5347 To delete the last search pattern and use the last-but-one for
5348 the "n" command and 'hlsearch': >
5349 :call histdel("search", -1)
5350 :let @/ = histget("search", -1)
5351<
5352 Can also be used as a |method|: >
5353 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005354<
5355 Return type: |Number|
5356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005357
5358histget({history} [, {index}]) *histget()*
5359 The result is a String, the entry with Number {index} from
5360 {history}. See |hist-names| for the possible values of
5361 {history}, and |:history-indexing| for {index}. If there is
5362 no such entry, an empty String is returned. When {index} is
5363 omitted, the most recent item from the history is used.
5364
5365 Examples:
5366 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005367 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005368
5369< Define an Ex command ":H {num}" that supports re-execution of
5370 the {num}th entry from the output of |:history|. >
5371 :command -nargs=1 H execute histget("cmd", 0+<args>)
5372<
5373 Can also be used as a |method|: >
5374 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005375<
5376 Return type: |String|
5377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005378
5379histnr({history}) *histnr()*
5380 The result is the Number of the current entry in {history}.
5381 See |hist-names| for the possible values of {history}.
5382 If an error occurred, -1 is returned.
5383
5384 Example: >
5385 :let inp_index = histnr("expr")
5386
5387< Can also be used as a |method|: >
5388 GetHistory()->histnr()
5389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005390 Return type: |Number|
5391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005392hlexists({name}) *hlexists()*
5393 The result is a Number, which is TRUE if a highlight group
5394 called {name} exists. This is when the group has been
5395 defined in some way. Not necessarily when highlighting has
5396 been defined for it, it may also have been used for a syntax
5397 item.
5398 *highlight_exists()*
5399 Obsolete name: highlight_exists().
5400
5401 Can also be used as a |method|: >
5402 GetName()->hlexists()
5403<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005404 Return type: |Number|
5405
5406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005407hlget([{name} [, {resolve}]]) *hlget()*
5408 Returns a List of all the highlight group attributes. If the
5409 optional {name} is specified, then returns a List with only
5410 the attributes of the specified highlight group. Returns an
5411 empty List if the highlight group {name} is not present.
5412
5413 If the optional {resolve} argument is set to v:true and the
5414 highlight group {name} is linked to another group, then the
5415 link is resolved recursively and the attributes of the
5416 resolved highlight group are returned.
5417
5418 Each entry in the returned List is a Dictionary with the
5419 following items:
5420 cleared boolean flag, set to v:true if the highlight
5421 group attributes are cleared or not yet
5422 specified. See |highlight-clear|.
5423 cterm cterm attributes. See |highlight-cterm|.
5424 ctermbg cterm background color.
5425 See |highlight-ctermbg|.
5426 ctermfg cterm foreground color.
5427 See |highlight-ctermfg|.
5428 ctermul cterm underline color. See |highlight-ctermul|.
5429 default boolean flag, set to v:true if the highlight
5430 group link is a default link. See
5431 |highlight-default|.
5432 font highlight group font. See |highlight-font|.
5433 gui gui attributes. See |highlight-gui|.
5434 guibg gui background color. See |highlight-guibg|.
5435 guifg gui foreground color. See |highlight-guifg|.
5436 guisp gui special color. See |highlight-guisp|.
5437 id highlight group ID.
5438 linksto linked highlight group name.
5439 See |:highlight-link|.
5440 name highlight group name. See |group-name|.
5441 start start terminal keycode. See |highlight-start|.
5442 stop stop terminal keycode. See |highlight-stop|.
5443 term term attributes. See |highlight-term|.
5444
5445 The 'term', 'cterm' and 'gui' items in the above Dictionary
5446 have a dictionary value with the following optional boolean
5447 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5448 'reverse', 'inverse' and 'strikethrough'.
5449
5450 Example(s): >
5451 :echo hlget()
5452 :echo hlget('ModeMsg')
5453 :echo hlget('Number', v:true)
5454<
5455 Can also be used as a |method|: >
5456 GetName()->hlget()
5457<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005458 Return type: list<dict<any>>
5459
5460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005461hlset({list}) *hlset()*
5462 Creates or modifies the attributes of a List of highlight
5463 groups. Each item in {list} is a dictionary containing the
5464 attributes of a highlight group. See |hlget()| for the list of
5465 supported items in this dictionary.
5466
5467 In addition to the items described in |hlget()|, the following
5468 additional items are supported in the dictionary:
5469
5470 force boolean flag to force the creation of
5471 a link for an existing highlight group
5472 with attributes.
5473
5474 The highlight group is identified using the 'name' item and
5475 the 'id' item (if supplied) is ignored. If a highlight group
5476 with a specified name doesn't exist, then it is created.
5477 Otherwise the attributes of an existing highlight group are
5478 modified.
5479
5480 If an empty dictionary value is used for the 'term' or 'cterm'
5481 or 'gui' entries, then the corresponding attributes are
5482 cleared. If the 'cleared' item is set to v:true, then all the
5483 attributes of the highlight group are cleared.
5484
5485 The 'linksto' item can be used to link a highlight group to
5486 another highlight group. See |:highlight-link|.
5487
5488 Returns zero for success, -1 for failure.
5489
5490 Example(s): >
5491 " add bold attribute to the Visual highlight group
5492 :call hlset([#{name: 'Visual',
5493 \ term: #{reverse: 1 , bold: 1}}])
5494 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5495 :let l = hlget()
5496 :call hlset(l)
5497 " clear the Search highlight group
5498 :call hlset([#{name: 'Search', cleared: v:true}])
5499 " clear the 'term' attributes for a highlight group
5500 :call hlset([#{name: 'Title', term: {}}])
5501 " create the MyHlg group linking it to DiffAdd
5502 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5503 " remove the MyHlg group link
5504 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5505 " clear the attributes and a link
5506 :call hlset([#{name: 'MyHlg', cleared: v:true,
5507 \ linksto: 'NONE'}])
5508<
5509 Can also be used as a |method|: >
5510 GetAttrList()->hlset()
5511<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005512 Return type: |Number|
5513
5514hlID({name}) *hlID()*
5515 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005516 with name {name}. When the highlight group doesn't exist,
5517 zero is returned.
5518 This can be used to retrieve information about the highlight
5519 group. For example, to get the background color of the
5520 "Comment" group: >
5521 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5522< *highlightID()*
5523 Obsolete name: highlightID().
5524
5525 Can also be used as a |method|: >
5526 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005527<
5528 Return type: |Number|
5529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005530
5531hostname() *hostname()*
5532 The result is a String, which is the name of the machine on
5533 which Vim is currently running. Machine names greater than
5534 256 characters long are truncated.
5535
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005536 Return type: |String|
5537
5538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005539iconv({string}, {from}, {to}) *iconv()*
5540 The result is a String, which is the text {string} converted
5541 from encoding {from} to encoding {to}.
5542 When the conversion completely fails an empty string is
5543 returned. When some characters could not be converted they
5544 are replaced with "?".
5545 The encoding names are whatever the iconv() library function
5546 can accept, see ":!man 3 iconv".
5547 Most conversions require Vim to be compiled with the |+iconv|
5548 feature. Otherwise only UTF-8 to latin1 conversion and back
5549 can be done.
5550 This can be used to display messages with special characters,
5551 no matter what 'encoding' is set to. Write the message in
5552 UTF-8 and use: >
5553 echo iconv(utf8_str, "utf-8", &enc)
5554< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5555 from/to UCS-2 is automatically changed to use UTF-8. You
5556 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5557
5558 Can also be used as a |method|: >
5559 GetText()->iconv('latin1', 'utf-8')
5560<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005561 Return type: |String|
5562
5563
5564indent({lnum}) *indent()*
5565 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005566 current buffer. The indent is counted in spaces, the value
5567 of 'tabstop' is relevant. {lnum} is used just like in
5568 |getline()|.
5569 When {lnum} is invalid -1 is returned. In |Vim9| script an
5570 error is given.
5571
5572 Can also be used as a |method|: >
5573 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005574<
5575 Return type: |Number|
5576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005577
5578index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005579 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005580 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005581
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005582 If {object} is a |List| return the lowest index where the item
5583 has a value equal to {expr}. There is no automatic
5584 conversion, so the String "4" is different from the Number 4.
5585 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005586 of 'ignorecase' is not used here, case matters as indicated by
5587 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005588
5589 If {object} is |Blob| return the lowest index where the byte
5590 value is equal to {expr}.
5591
5592 If {start} is given then start looking at the item with index
5593 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005595 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5596 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005598 -1 is returned when {expr} is not found in {object}.
5599 Example: >
5600 :let idx = index(words, "the")
5601 :if index(numbers, 123) >= 0
5602
5603< Can also be used as a |method|: >
5604 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005605<
5606 Return type: |Number|
5607
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005608
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005609indexof({object}, {expr} [, {opts}]) *indexof()*
5610 Returns the index of an item in {object} where {expr} is
5611 v:true. {object} must be a |List| or a |Blob|.
5612
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005613 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005614 List until the expression is v:true and return the index of
5615 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005616
5617 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005618 Blob until the expression is v:true and return the index of
5619 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005620
5621 {expr} must be a |string| or |Funcref|.
5622
5623 If {expr} is a |string|: If {object} is a |List|, inside
5624 {expr} |v:key| has the index of the current List item and
5625 |v:val| has the value of the item. If {object} is a |Blob|,
5626 inside {expr} |v:key| has the index of the current byte and
5627 |v:val| has the byte value.
5628
5629 If {expr} is a |Funcref| it must take two arguments:
5630 1. the key or the index of the current item.
5631 2. the value of the current item.
5632 The function must return |TRUE| if the item is found and the
5633 search should stop.
5634
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005635 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005636 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005637 startidx start evaluating {expr} at the item with this
5638 index; may be negative for an item relative to
5639 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005640 Returns -1 when {expr} evaluates to v:false for all the items.
5641 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005642 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5643 :echo indexof(l, "v:val.n == 20")
5644 :echo indexof(l, {i, v -> v.n == 30})
5645 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005646
5647< Can also be used as a |method|: >
5648 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005649<
5650 Return type: |Number|
5651
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005653input({prompt} [, {text} [, {completion}]]) *input()*
5654 The result is a String, which is whatever the user typed on
5655 the command-line. The {prompt} argument is either a prompt
5656 string, or a blank string (for no prompt). A '\n' can be used
5657 in the prompt to start a new line.
5658 The highlighting set with |:echohl| is used for the prompt.
5659 The input is entered just like a command-line, with the same
5660 editing commands and mappings. There is a separate history
5661 for lines typed for input().
5662 Example: >
5663 :if input("Coffee or beer? ") == "beer"
5664 : echo "Cheers!"
5665 :endif
5666<
5667 If the optional {text} argument is present and not empty, this
5668 is used for the default reply, as if the user typed this.
5669 Example: >
5670 :let color = input("Color? ", "white")
5671
5672< The optional {completion} argument specifies the type of
5673 completion supported for the input. Without it completion is
5674 not performed. The supported completion types are the same as
5675 that can be supplied to a user-defined command using the
5676 "-complete=" argument. Refer to |:command-completion| for
5677 more information. Example: >
5678 let fname = input("File: ", "", "file")
5679<
5680 NOTE: This function must not be used in a startup file, for
5681 the versions that only run in GUI mode (e.g., the Win32 GUI).
5682 Note: When input() is called from within a mapping it will
5683 consume remaining characters from that mapping, because a
5684 mapping is handled like the characters were typed.
5685 Use |inputsave()| before input() and |inputrestore()|
5686 after input() to avoid that. Another solution is to avoid
5687 that further characters follow in the mapping, e.g., by using
5688 |:execute| or |:normal|.
5689
5690 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005691 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005692 :function GetFoo()
5693 : call inputsave()
5694 : let g:Foo = input("enter search pattern: ")
5695 : call inputrestore()
5696 :endfunction
5697
5698< Can also be used as a |method|: >
5699 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005700<
5701 Return type: |String|
5702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005703
5704inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5705 Like |input()|, but when the GUI is running and text dialogs
5706 are supported, a dialog window pops up to input the text.
5707 Example: >
5708 :let n = inputdialog("value for shiftwidth", shiftwidth())
5709 :if n != ""
5710 : let &sw = n
5711 :endif
5712< When the dialog is cancelled {cancelreturn} is returned. When
5713 omitted an empty string is returned.
5714 Hitting <Enter> works like pressing the OK button. Hitting
5715 <Esc> works like pressing the Cancel button.
5716 NOTE: Command-line completion is not supported.
5717
5718 Can also be used as a |method|: >
5719 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005720<
5721 Return type: |String|
5722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005723
5724inputlist({textlist}) *inputlist()*
5725 {textlist} must be a |List| of strings. This |List| is
5726 displayed, one string per line. The user will be prompted to
5727 enter a number, which is returned.
5728 The user can also select an item by clicking on it with the
5729 mouse, if the mouse is enabled in the command line ('mouse' is
5730 "a" or includes "c"). For the first string 0 is returned.
5731 When clicking above the first item a negative number is
5732 returned. When clicking on the prompt one more than the
5733 length of {textlist} is returned.
5734 Make sure {textlist} has less than 'lines' entries, otherwise
5735 it won't work. It's a good idea to put the entry number at
5736 the start of the string. And put a prompt in the first item.
5737 Example: >
5738 let color = inputlist(['Select color:', '1. red',
5739 \ '2. green', '3. blue'])
5740
5741< Can also be used as a |method|: >
5742 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005743<
5744 Return type: |Number|
5745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005746
5747inputrestore() *inputrestore()*
5748 Restore typeahead that was saved with a previous |inputsave()|.
5749 Should be called the same number of times inputsave() is
5750 called. Calling it more often is harmless though.
5751 Returns TRUE when there is nothing to restore, FALSE otherwise.
5752
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005753 Return type: |Number|
5754
5755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005756inputsave() *inputsave()*
5757 Preserve typeahead (also from mappings) and clear it, so that
5758 a following prompt gets input from the user. Should be
5759 followed by a matching inputrestore() after the prompt. Can
5760 be used several times, in which case there must be just as
5761 many inputrestore() calls.
5762 Returns TRUE when out of memory, FALSE otherwise.
5763
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005764 Return type: |Number|
5765
5766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005767inputsecret({prompt} [, {text}]) *inputsecret()*
5768 This function acts much like the |input()| function with but
5769 two exceptions:
5770 a) the user's response will be displayed as a sequence of
5771 asterisks ("*") thereby keeping the entry secret, and
5772 b) the user's response will not be recorded on the input
5773 |history| stack.
5774 The result is a String, which is whatever the user actually
5775 typed on the command-line in response to the issued prompt.
5776 NOTE: Command-line completion is not supported.
5777
5778 Can also be used as a |method|: >
5779 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005780<
5781 Return type: |String|
5782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005783
5784insert({object}, {item} [, {idx}]) *insert()*
5785 When {object} is a |List| or a |Blob| insert {item} at the start
5786 of it.
5787
5788 If {idx} is specified insert {item} before the item with index
5789 {idx}. If {idx} is zero it goes before the first item, just
5790 like omitting {idx}. A negative {idx} is also possible, see
5791 |list-index|. -1 inserts just before the last item.
5792
5793 Returns the resulting |List| or |Blob|. Examples: >
5794 :let mylist = insert([2, 3, 5], 1)
5795 :call insert(mylist, 4, -1)
5796 :call insert(mylist, 6, len(mylist))
5797< The last example can be done simpler with |add()|.
5798 Note that when {item} is a |List| it is inserted as a single
5799 item. Use |extend()| to concatenate |Lists|.
5800
5801 Can also be used as a |method|: >
5802 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005803<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005804 Return type: |Number|
5805
5806
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005807 *instanceof()* *E614* *E616* *E693*
5808instanceof({object}, {class})
5809 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005810 argument is a direct or indirect instance of a |Class|,
5811 |Interface|, or class |:type| alias specified by {class}.
5812 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005813 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005814 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005815 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02005816
5817< Can also be used as a |method|: >
5818 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005819<
5820 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02005821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005822interrupt() *interrupt()*
5823 Interrupt script execution. It works more or less like the
5824 user typing CTRL-C, most commands won't execute and control
5825 returns to the user. This is useful to abort execution
5826 from lower down, e.g. in an autocommand. Example: >
5827 :function s:check_typoname(file)
5828 : if fnamemodify(a:file, ':t') == '['
5829 : echomsg 'Maybe typo'
5830 : call interrupt()
5831 : endif
5832 :endfunction
5833 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005834<
5835 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005836
5837invert({expr}) *invert()*
5838 Bitwise invert. The argument is converted to a number. A
5839 List, Dict or Float argument causes an error. Example: >
5840 :let bits = invert(bits)
5841< Can also be used as a |method|: >
5842 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005843<
5844 Return type: |Number|
5845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005846
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005847isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01005848 The result is a Number, which is |TRUE| when {path} is an
5849 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005850 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01005851 On MS-Windows, it is considered absolute when it starts with an
5852 optional drive prefix and is followed by a '\' or '/'. UNC paths
5853 are always absolute.
5854 Example: >
5855 echo isabsolutepath('/usr/share/') " 1
5856 echo isabsolutepath('./foobar') " 0
5857 echo isabsolutepath('C:\Windows') " 1
5858 echo isabsolutepath('foobar') " 0
5859 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01005860<
LemonBoydca1d402022-04-28 15:26:33 +01005861 Can also be used as a |method|: >
5862 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005863<
5864 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01005865
5866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005867isdirectory({directory}) *isdirectory()*
5868 The result is a Number, which is |TRUE| when a directory
5869 with the name {directory} exists. If {directory} doesn't
5870 exist, or isn't a directory, the result is |FALSE|. {directory}
5871 is any expression, which is used as a String.
5872
5873 Can also be used as a |method|: >
5874 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005875<
5876 Return type: |Number|
5877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005878
5879isinf({expr}) *isinf()*
5880 Return 1 if {expr} is a positive infinity, or -1 a negative
5881 infinity, otherwise 0. >
5882 :echo isinf(1.0 / 0.0)
5883< 1 >
5884 :echo isinf(-1.0 / 0.0)
5885< -1
5886
5887 Can also be used as a |method|: >
5888 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005889<
5890 Return type: |Number|
5891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005892
5893islocked({expr}) *islocked()* *E786*
5894 The result is a Number, which is |TRUE| when {expr} is the
5895 name of a locked variable.
5896 The string argument {expr} must be the name of a variable,
5897 |List| item or |Dictionary| entry, not the variable itself!
5898 Example: >
5899 :let alist = [0, ['a', 'b'], 2, 3]
5900 :lockvar 1 alist
5901 :echo islocked('alist') " 1
5902 :echo islocked('alist[1]') " 0
5903
Bram Moolenaar9da17d72022-02-09 21:50:44 +00005904< When {expr} is a variable that does not exist -1 is returned.
5905 If {expr} uses a range, list or dict index that is out of
5906 range or does not exist you get an error message. Use
5907 |exists()| to check for existence.
5908 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005909
5910 Can also be used as a |method|: >
5911 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005912<
5913 Return type: |Number|
5914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005915
5916isnan({expr}) *isnan()*
5917 Return |TRUE| if {expr} is a float with value NaN. >
5918 echo isnan(0.0 / 0.0)
5919< 1
5920
5921 Can also be used as a |method|: >
5922 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005923<
5924 Return type: |Number|
5925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005926
5927items({dict}) *items()*
5928 Return a |List| with all the key-value pairs of {dict}. Each
5929 |List| item is a list with two items: the key of a {dict}
5930 entry and the value of this entry. The |List| is in arbitrary
5931 order. Also see |keys()| and |values()|.
5932 Example: >
5933 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005934 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005935 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005936<
5937 A List or a String argument is also supported. In these
5938 cases, items() returns a List with the index and the value at
5939 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005940
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01005941 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005942 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005943<
5944 Return type: list<list<any>> or list<any>
5945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005946
5947job_ functions are documented here: |job-functions-details|
5948
5949
5950join({list} [, {sep}]) *join()*
5951 Join the items in {list} together into one String.
5952 When {sep} is specified it is put in between the items. If
5953 {sep} is omitted a single space is used.
5954 Note that {sep} is not added at the end. You might want to
5955 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005956 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005957< String items are used as-is. |Lists| and |Dictionaries| are
5958 converted into a string like with |string()|.
5959 The opposite function is |split()|.
5960
5961 Can also be used as a |method|: >
5962 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005963<
5964 Return type: |String|
5965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005966
5967js_decode({string}) *js_decode()*
5968 This is similar to |json_decode()| with these differences:
5969 - Object key names do not have to be in quotes.
5970 - Strings can be in single quotes.
5971 - Empty items in an array (between two commas) are allowed and
5972 result in v:none items.
5973
5974 Can also be used as a |method|: >
5975 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005976<
5977 Return type: any, depending on {varname}
5978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005979
5980js_encode({expr}) *js_encode()*
5981 This is similar to |json_encode()| with these differences:
5982 - Object key names are not in quotes.
5983 - v:none items in an array result in an empty item between
5984 commas.
5985 For example, the Vim object:
5986 [1,v:none,{"one":1},v:none] ~
5987 Will be encoded as:
5988 [1,,{one:1},,] ~
5989 While json_encode() would produce:
5990 [1,null,{"one":1},null] ~
5991 This encoding is valid for JavaScript. It is more efficient
5992 than JSON, especially when using an array with optional items.
5993
5994 Can also be used as a |method|: >
5995 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005996<
5997 Return type: |String|
5998
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005999
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006000json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006001 This parses a JSON formatted string and returns the equivalent
6002 in Vim values. See |json_encode()| for the relation between
6003 JSON and Vim values.
6004 The decoding is permissive:
6005 - A trailing comma in an array and object is ignored, e.g.
6006 "[1, 2, ]" is the same as "[1, 2]".
6007 - Integer keys are accepted in objects, e.g. {1:2} is the
6008 same as {"1":2}.
6009 - More floating point numbers are recognized, e.g. "1." for
6010 "1.0", or "001.2" for "1.2". Special floating point values
6011 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6012 are accepted.
6013 - Leading zeroes in integer numbers are ignored, e.g. "012"
6014 for "12" or "-012" for "-12".
6015 - Capitalization is ignored in literal names null, true or
6016 false, e.g. "NULL" for "null", "True" for "true".
6017 - Control characters U+0000 through U+001F which are not
6018 escaped in strings are accepted, e.g. " " (tab
6019 character in string) for "\t".
6020 - An empty JSON expression or made of only spaces is accepted
6021 and results in v:none.
6022 - Backslash in an invalid 2-character sequence escape is
6023 ignored, e.g. "\a" is decoded as "a".
6024 - A correct surrogate pair in JSON strings should normally be
6025 a 12 character sequence such as "\uD834\uDD1E", but
6026 json_decode() silently accepts truncated surrogate pairs
6027 such as "\uD834" or "\uD834\u"
6028 *E938*
6029 A duplicate key in an object, valid in rfc7159, is not
6030 accepted by json_decode() as the result must be a valid Vim
6031 type, e.g. this fails: {"a":"b", "a":"c"}
6032
6033 Can also be used as a |method|: >
6034 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006035<
6036 Return type: any, depending on {varname}
6037
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006038
6039json_encode({expr}) *json_encode()*
6040 Encode {expr} as JSON and return this as a string.
6041 The encoding is specified in:
6042 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006043 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006044 |Number| decimal number
6045 |Float| floating point number
6046 Float nan "NaN"
6047 Float inf "Infinity"
6048 Float -inf "-Infinity"
6049 |String| in double quotes (possibly null)
6050 |Funcref| not possible, error
6051 |List| as an array (possibly null); when
6052 used recursively: []
6053 |Dict| as an object (possibly null); when
6054 used recursively: {}
6055 |Blob| as an array of the individual bytes
6056 v:false "false"
6057 v:true "true"
6058 v:none "null"
6059 v:null "null"
6060 Note that NaN and Infinity are passed on as values. This is
6061 missing in the JSON standard, but several implementations do
6062 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006063 If a string contains an illegal character then the replacement
6064 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006065
6066 Can also be used as a |method|: >
6067 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006068<
6069 Return type: |String|
6070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006071
6072keys({dict}) *keys()*
6073 Return a |List| with all the keys of {dict}. The |List| is in
6074 arbitrary order. Also see |items()| and |values()|.
6075
6076 Can also be used as a |method|: >
6077 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006078<
6079 Return type: list<string>
6080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006081
zeertzjqcdc83932022-09-12 13:38:41 +01006082keytrans({string}) *keytrans()*
6083 Turn the internal byte representation of keys into a form that
6084 can be used for |:map|. E.g. >
6085 :let xx = "\<C-Home>"
6086 :echo keytrans(xx)
6087< <C-Home>
6088
6089 Can also be used as a |method|: >
6090 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006091<
6092 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006093
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006094
6095len({expr}) *len()* *E701*
6096 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006097 When {expr} is a String or a Number the length in bytes is
6098 used, as with |strlen()|.
6099 When {expr} is a |List| the number of items in the |List| is
6100 returned.
6101 When {expr} is a |Blob| the number of bytes is returned.
6102 When {expr} is a |Dictionary| the number of entries in the
6103 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006104 When {expr} is an |Object|, invokes the len() method in the
6105 object (if present) to get the length (|object-len()|).
6106 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006107
6108 Can also be used as a |method|: >
6109 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006110<
6111 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006112
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006113
6114 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006115libcall({libname}, {funcname}, {argument})
6116 Call function {funcname} in the run-time library {libname}
6117 with single argument {argument}.
6118 This is useful to call functions in a library that you
6119 especially made to be used with Vim. Since only one argument
6120 is possible, calling standard library functions is rather
6121 limited.
6122 The result is the String returned by the function. If the
6123 function returns NULL, this will appear as an empty string ""
6124 to Vim.
6125 If the function returns a number, use libcallnr()!
6126 If {argument} is a number, it is passed to the function as an
6127 int; if {argument} is a string, it is passed as a
6128 null-terminated string.
6129 This function will fail in |restricted-mode|.
6130
6131 libcall() allows you to write your own 'plug-in' extensions to
6132 Vim without having to recompile the program. It is NOT a
6133 means to call system functions! If you try to do so Vim will
6134 very probably crash.
6135
6136 For Win32, the functions you write must be placed in a DLL
6137 and use the normal C calling convention (NOT Pascal which is
6138 used in Windows System DLLs). The function must take exactly
6139 one parameter, either a character pointer or a long integer,
6140 and must return a character pointer or NULL. The character
6141 pointer returned must point to memory that will remain valid
6142 after the function has returned (e.g. in static data in the
6143 DLL). If it points to allocated memory, that memory will
6144 leak away. Using a static buffer in the function should work,
6145 it's then freed when the DLL is unloaded.
6146
6147 WARNING: If the function returns a non-valid pointer, Vim may
6148 crash! This also happens if the function returns a number,
6149 because Vim thinks it's a pointer.
6150 For Win32 systems, {libname} should be the filename of the DLL
6151 without the ".DLL" suffix. A full path is only required if
6152 the DLL is not in the usual places.
6153 For Unix: When compiling your own plugins, remember that the
6154 object code must be compiled as position-independent ('PIC').
6155 {only in Win32 and some Unix versions, when the |+libcall|
6156 feature is present}
6157 Examples: >
6158 :echo libcall("libc.so", "getenv", "HOME")
6159
6160< Can also be used as a |method|, the base is passed as the
6161 third argument: >
6162 GetValue()->libcall("libc.so", "getenv")
6163<
6164 *libcallnr()*
6165libcallnr({libname}, {funcname}, {argument})
6166 Just like |libcall()|, but used for a function that returns an
6167 int instead of a string.
6168 {only in Win32 on some Unix versions, when the |+libcall|
6169 feature is present}
6170 Examples: >
6171 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6172 :call libcallnr("libc.so", "printf", "Hello World!\n")
6173 :call libcallnr("libc.so", "sleep", 10)
6174<
6175 Can also be used as a |method|, the base is passed as the
6176 third argument: >
6177 GetValue()->libcallnr("libc.so", "printf")
6178<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006179 Return type: |String|
6180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006181
6182line({expr} [, {winid}]) *line()*
6183 The result is a Number, which is the line number of the file
6184 position given with {expr}. The {expr} argument is a string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00006185 The accepted positions are: *E1209*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006186 . the cursor position
6187 $ the last line in the current buffer
6188 'x position of mark x (if the mark is not set, 0 is
6189 returned)
6190 w0 first line visible in current window (one if the
6191 display isn't updated, e.g. in silent Ex mode)
6192 w$ last line visible in current window (this is one
6193 less than "w0" if no lines are visible)
Peter Aronoff210b39c2024-06-11 19:22:53 +02006194 v When not in Visual mode, returns the cursor
6195 position. In Visual mode, returns the other end
6196 of the Visual area. A good way to think about
6197 this is that in Visual mode "v" and "." complement
6198 each other. While "." refers to the cursor
6199 position, "v" refers to where |v_o| would move the
6200 cursor. As a result, you can use "v" and "."
6201 together to work on all of a selection in
6202 characterwise visual mode. If the cursor is at
6203 the end of a characterwise visual area, "v" refers
6204 to the start of the same visual area. And if the
6205 cursor is at the start of a characterwise visual
6206 area, "v" refers to the end of the same visual
6207 area. "v" differs from |'<| and |'>| in that it's
6208 updated right away.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006209 Note that a mark in another file can be used. The line number
6210 then applies to another buffer.
6211 To get the column number use |col()|. To get both use
6212 |getpos()|.
6213 With the optional {winid} argument the values are obtained for
6214 that window instead of the current window.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006215 Returns 0 for invalid values of {expr} and {winid}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006216 Examples: >
6217 line(".") line number of the cursor
6218 line(".", winid) idem, in window "winid"
6219 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006220 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006221<
6222 To jump to the last known position when opening a file see
6223 |last-position-jump|.
6224
6225 Can also be used as a |method|: >
6226 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006227<
6228 Return type: |Number|
6229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006230
6231line2byte({lnum}) *line2byte()*
6232 Return the byte count from the start of the buffer for line
6233 {lnum}. This includes the end-of-line character, depending on
6234 the 'fileformat' option for the current buffer. The first
6235 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6236 This can also be used to get the byte count for the line just
6237 below the last line: >
6238 line2byte(line("$") + 1)
6239< This is the buffer size plus one. If 'fileencoding' is empty
6240 it is the file size plus one. {lnum} is used like with
6241 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6242 feature has been disabled at compile time, -1 is returned.
6243 Also see |byte2line()|, |go| and |:goto|.
6244
6245 Can also be used as a |method|: >
6246 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006247<
6248 Return type: |Number|
6249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006250
6251lispindent({lnum}) *lispindent()*
6252 Get the amount of indent for line {lnum} according the lisp
6253 indenting rules, as with 'lisp'.
6254 The indent is counted in spaces, the value of 'tabstop' is
6255 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006256 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006257 error is given.
6258
6259 Can also be used as a |method|: >
6260 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006261<
6262 Return type: |Number|
6263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006264
6265list2blob({list}) *list2blob()*
6266 Return a Blob concatenating all the number values in {list}.
6267 Examples: >
6268 list2blob([1, 2, 3, 4]) returns 0z01020304
6269 list2blob([]) returns 0z
6270< Returns an empty Blob on error. If one of the numbers is
6271 negative or more than 255 error *E1239* is given.
6272
6273 |blob2list()| does the opposite.
6274
6275 Can also be used as a |method|: >
6276 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006277<
6278 Return type: |Blob|
6279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006280
6281list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006282 Convert each number in {list} to a character string and
6283 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006284 list2str([32]) returns " "
6285 list2str([65, 66, 67]) returns "ABC"
6286< The same can be done (slowly) with: >
6287 join(map(list, {nr, val -> nr2char(val)}), '')
6288< |str2list()| does the opposite.
6289
6290 When {utf8} is omitted or zero, the current 'encoding' is used.
6291 When {utf8} is TRUE, always return UTF-8 characters.
6292 With UTF-8 composing characters work as expected: >
6293 list2str([97, 769]) returns "á"
6294<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006295 Returns an empty string on error.
6296
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006297 Can also be used as a |method|: >
6298 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006299<
6300 Return type: |String|
6301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006302
6303listener_add({callback} [, {buf}]) *listener_add()*
6304 Add a callback function that will be invoked when changes have
6305 been made to buffer {buf}.
6306 {buf} refers to a buffer name or number. For the accepted
6307 values, see |bufname()|. When {buf} is omitted the current
6308 buffer is used.
6309 Returns a unique ID that can be passed to |listener_remove()|.
6310
6311 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006312 bufnr the buffer that was changed
6313 start first changed line number
6314 end first line number below the change
6315 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006316 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006317 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006318
6319 Example: >
6320 func Listener(bufnr, start, end, added, changes)
6321 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6322 endfunc
6323 call listener_add('Listener', bufnr)
6324
Bram Moolenaar944697a2022-02-20 19:48:20 +00006325< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006326 dictionary with these entries:
6327 lnum the first line number of the change
6328 end the first line below the change
6329 added number of lines added; negative if lines were
6330 deleted
6331 col first column in "lnum" that was affected by
6332 the change; one if unknown or the whole line
6333 was affected; this is a byte index, first
6334 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006335 When lines are inserted (not when a line is split, e.g. by
6336 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006337 lnum line above which the new line is added
6338 end equal to "lnum"
6339 added number of lines inserted
6340 col 1
6341 When lines are deleted the values are:
6342 lnum the first deleted line
6343 end the line below the first deleted line, before
6344 the deletion was done
6345 added negative, number of lines deleted
6346 col 1
6347 When lines are changed:
6348 lnum the first changed line
6349 end the line below the last changed line
6350 added 0
6351 col first column with a change or 1
6352
6353 The entries are in the order the changes were made, thus the
6354 most recent change is at the end. The line numbers are valid
6355 when the callback is invoked, but later changes may make them
6356 invalid, thus keeping a copy for later might not work.
6357
6358 The {callback} is invoked just before the screen is updated,
6359 when |listener_flush()| is called or when a change is being
6360 made that changes the line count in a way it causes a line
6361 number in the list of changes to become invalid.
6362
6363 The {callback} is invoked with the text locked, see
6364 |textlock|. If you do need to make changes to the buffer, use
6365 a timer to do this later |timer_start()|.
6366
6367 The {callback} is not invoked when the buffer is first loaded.
6368 Use the |BufReadPost| autocmd event to handle the initial text
6369 of a buffer.
6370 The {callback} is also not invoked when the buffer is
6371 unloaded, use the |BufUnload| autocmd event for that.
6372
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006373 Returns zero if {callback} or {buf} is invalid.
6374
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006375 Can also be used as a |method|, the base is passed as the
6376 second argument: >
6377 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006378<
6379 Return type: |Number|
6380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006381
6382listener_flush([{buf}]) *listener_flush()*
6383 Invoke listener callbacks for buffer {buf}. If there are no
6384 pending changes then no callbacks are invoked.
6385
6386 {buf} refers to a buffer name or number. For the accepted
6387 values, see |bufname()|. When {buf} is omitted the current
6388 buffer is used.
6389
6390 Can also be used as a |method|: >
6391 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006392<
6393 Return type: |Number|
6394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006395
6396listener_remove({id}) *listener_remove()*
6397 Remove a listener previously added with listener_add().
6398 Returns FALSE when {id} could not be found, TRUE when {id} was
6399 removed.
6400
6401 Can also be used as a |method|: >
6402 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006403<
6404 Return type: |Number|
6405
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006406
6407localtime() *localtime()*
6408 Return the current time, measured as seconds since 1st Jan
6409 1970. See also |strftime()|, |strptime()| and |getftime()|.
6410
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006411 Return type: |Number|
6412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006413
6414log({expr}) *log()*
6415 Return the natural logarithm (base e) of {expr} as a |Float|.
6416 {expr} must evaluate to a |Float| or a |Number| in the range
6417 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006418 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006419 Examples: >
6420 :echo log(10)
6421< 2.302585 >
6422 :echo log(exp(5))
6423< 5.0
6424
6425 Can also be used as a |method|: >
6426 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006427<
6428 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006429
6430
6431log10({expr}) *log10()*
6432 Return the logarithm of Float {expr} to base 10 as a |Float|.
6433 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006434 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006435 Examples: >
6436 :echo log10(1000)
6437< 3.0 >
6438 :echo log10(0.01)
6439< -2.0
6440
6441 Can also be used as a |method|: >
6442 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006443<
6444 Return type: |Float|
6445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006446
6447luaeval({expr} [, {expr}]) *luaeval()*
6448 Evaluate Lua expression {expr} and return its result converted
6449 to Vim data structures. Second {expr} may hold additional
6450 argument accessible as _A inside first {expr}.
6451 Strings are returned as they are.
6452 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006453 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006454 Dictionaries and lists obtained by vim.eval() are returned
6455 as-is.
6456 Other objects are returned as zero without any errors.
6457 See |lua-luaeval| for more details.
6458 Note that in a `:def` function local variables are not visible
6459 to {expr}.
6460
6461 Can also be used as a |method|: >
6462 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006463<
6464 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006465
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006466 {only available when compiled with the |+lua| feature}
6467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006468
6469map({expr1}, {expr2}) *map()*
6470 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006471 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006472 item in {expr1} with the result of evaluating {expr2}.
6473 For a |Blob| each byte is replaced.
6474 For a |String|, each character, including composing
6475 characters, is replaced.
6476 If the item type changes you may want to use |mapnew()| to
6477 create a new List or Dictionary. This is required when using
6478 Vim9 script.
6479
6480 {expr2} must be a |String| or |Funcref|.
6481
6482 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6483 of the current item. For a |Dictionary| |v:key| has the key
6484 of the current item and for a |List| |v:key| has the index of
6485 the current item. For a |Blob| |v:key| has the index of the
6486 current byte. For a |String| |v:key| has the index of the
6487 current character.
6488 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006489 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006490< This puts "> " before and " <" after each item in "mylist".
6491
6492 Note that {expr2} is the result of an expression and is then
6493 used as an expression again. Often it is good to use a
6494 |literal-string| to avoid having to double backslashes. You
6495 still have to double ' quotes
6496
6497 If {expr2} is a |Funcref| it is called with two arguments:
6498 1. The key or the index of the current item.
6499 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006500 With a legacy script lambda you don't get an error if it only
6501 accepts one argument, but with a Vim9 lambda you get "E1106:
6502 One argument too many", the number of arguments must match.
6503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006504 The function must return the new value of the item. Example
6505 that changes each value by "key-value": >
6506 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006507 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006508 endfunc
6509 call map(myDict, function('KeyValue'))
6510< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006511 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006512< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006513 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006514< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006515 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006516<
6517 The operation is done in-place for a |List| and |Dictionary|.
6518 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006519 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006520
6521< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6522 or a new |Blob| or |String|.
6523 When an error is encountered while evaluating {expr2} no
6524 further items in {expr1} are processed.
6525 When {expr2} is a Funcref errors inside a function are ignored,
6526 unless it was defined with the "abort" flag.
6527
6528 Can also be used as a |method|: >
6529 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006530<
6531 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6532 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006533
6534
6535maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6536 When {dict} is omitted or zero: Return the rhs of mapping
6537 {name} in mode {mode}. The returned String has special
6538 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006539 listing. When {dict} is TRUE a dictionary is returned, see
6540 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006541
6542 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006543 returned if {dict} is FALSE, otherwise returns an empty Dict.
6544 When the mapping for {name} is empty, then "<Nop>" is
6545 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006546
6547 The {name} can have special key names, like in the ":map"
6548 command.
6549
6550 {mode} can be one of these strings:
6551 "n" Normal
6552 "v" Visual (including Select)
6553 "o" Operator-pending
6554 "i" Insert
6555 "c" Cmd-line
6556 "s" Select
6557 "x" Visual
6558 "l" langmap |language-mapping|
6559 "t" Terminal-Job
6560 "" Normal, Visual and Operator-pending
6561 When {mode} is omitted, the modes for "" are used.
6562
6563 When {abbr} is there and it is |TRUE| use abbreviations
6564 instead of mappings.
6565
6566 When {dict} is there and it is |TRUE| return a dictionary
6567 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006568 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006569 "lhs" The {lhs} of the mapping as it would be typed
6570 "lhsraw" The {lhs} of the mapping as raw bytes
6571 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6572 form, only present when it differs from "lhsraw"
6573 "rhs" The {rhs} of the mapping as typed.
6574 "silent" 1 for a |:map-silent| mapping, else 0.
6575 "noremap" 1 if the {rhs} of the mapping is not remappable.
6576 "script" 1 if mapping was defined with <script>.
6577 "expr" 1 for an expression mapping (|:map-<expr>|).
6578 "buffer" 1 for a buffer local mapping (|:map-local|).
6579 "mode" Modes for which the mapping is defined. In
6580 addition to the modes mentioned above, these
6581 characters will be used:
6582 " " Normal, Visual and Operator-pending
6583 "!" Insert and Commandline mode
6584 (|mapmode-ic|)
6585 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006586 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006587 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006588 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006589 "lnum" The line number in "sid", zero if unknown.
6590 "nowait" Do not wait for other, longer mappings.
6591 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006592 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006593 "mode_bits" Vim's internal binary representation of "mode".
6594 |mapset()| ignores this; only "mode" is used.
6595 See |maplist()| for usage examples. The values
6596 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006597
6598 The dictionary can be used to restore a mapping with
6599 |mapset()|.
6600
6601 The mappings local to the current buffer are checked first,
6602 then the global mappings.
6603 This function can be used to map a key even when it's already
6604 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006605 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006606
6607< Can also be used as a |method|: >
6608 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006609<
6610 Return type: |String| or dict<any> depending on {dict}
6611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006612
6613mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6614 Check if there is a mapping that matches with {name} in mode
6615 {mode}. See |maparg()| for {mode} and special names in
6616 {name}.
6617 When {abbr} is there and it is |TRUE| use abbreviations
6618 instead of mappings.
6619 A match happens with a mapping that starts with {name} and
6620 with a mapping which is equal to the start of {name}.
6621
6622 matches mapping "a" "ab" "abc" ~
6623 mapcheck("a") yes yes yes
6624 mapcheck("abc") yes yes yes
6625 mapcheck("ax") yes no no
6626 mapcheck("b") no no no
6627
6628 The difference with maparg() is that mapcheck() finds a
6629 mapping that matches with {name}, while maparg() only finds a
6630 mapping for {name} exactly.
6631 When there is no mapping that starts with {name}, an empty
6632 String is returned. If there is one, the RHS of that mapping
6633 is returned. If there are several mappings that start with
6634 {name}, the RHS of one of them is returned. This will be
6635 "<Nop>" if the RHS is empty.
6636 The mappings local to the current buffer are checked first,
6637 then the global mappings.
6638 This function can be used to check if a mapping can be added
6639 without being ambiguous. Example: >
6640 :if mapcheck("_vv") == ""
6641 : map _vv :set guifont=7x13<CR>
6642 :endif
6643< This avoids adding the "_vv" mapping when there already is a
6644 mapping for "_v" or for "_vvv".
6645
6646 Can also be used as a |method|: >
6647 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006648<
6649 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006650
6651
Ernie Rael09661202022-04-25 14:40:44 +01006652maplist([{abbr}]) *maplist()*
6653 Returns a |List| of all mappings. Each List item is a |Dict|,
6654 the same as what is returned by |maparg()|, see
6655 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6656 abbreviations instead of mappings.
6657
6658 Example to show all mappings with 'MultiMatch' in rhs: >
6659 vim9script
6660 echo maplist()->filter(
6661 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006662< It can be tricky to find mappings for particular |:map-modes|.
6663 |mapping-dict|'s "mode_bits" can simplify this. For example,
6664 the mode_bits for Normal, Insert or Command-line modes are
6665 0x19. To find all the mappings available in those modes you
6666 can do: >
6667 vim9script
6668 var saved_maps = []
6669 for m in maplist()
6670 if and(m.mode_bits, 0x19) != 0
6671 saved_maps->add(m)
6672 endif
6673 endfor
6674 echo saved_maps->mapnew((_, m) => m.lhs)
6675< The values of the mode_bits are defined in Vim's src/vim.h
6676 file and they can be discovered at runtime using
6677 |:map-commands| and "maplist()". Example: >
6678 vim9script
6679 omap xyzzy <Nop>
6680 var op_bit = maplist()->filter(
6681 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6682 ounmap xyzzy
6683 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006684<
6685 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006686
6687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006688mapnew({expr1}, {expr2}) *mapnew()*
6689 Like |map()| but instead of replacing items in {expr1} a new
6690 List or Dictionary is created and returned. {expr1} remains
6691 unchanged. Items can still be changed by {expr2}, if you
6692 don't want that use |deepcopy()| first.
6693
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006694 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6695 depending on {expr1}
6696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006697
6698mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006699mapset({dict})
6700 Restore a mapping from a dictionary, possibly returned by
6701 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6702 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006703 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006704 feature allows copying mappings from one buffer to another.
6705 The dict.mode value may restore a single mapping that covers
6706 more than one mode, like with mode values of '!', ' ', 'nox',
6707 or 'v'. *E1276*
6708
6709 In the first form, {mode} and {abbr} should be the same as
6710 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006711 {mode} is used to define the mode in which the mapping is set,
6712 not the "mode" entry in {dict}.
6713 Example for saving and restoring a mapping: >
6714 let save_map = maparg('K', 'n', 0, 1)
6715 nnoremap K somethingelse
6716 ...
6717 call mapset('n', 0, save_map)
6718< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006719 e.g. with `:map!`, you need to save/restore the mapping for
6720 all of them, when they might differ.
6721
6722 In the second form, with {dict} as the only argument, mode
6723 and abbr are taken from the dict.
6724 Example: >
6725 vim9script
6726 var save_maps = maplist()->filter(
6727 (_, m) => m.lhs == 'K')
6728 nnoremap K somethingelse
6729 cnoremap K somethingelse2
6730 # ...
6731 unmap K
6732 for d in save_maps
6733 mapset(d)
6734 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006735<
6736 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006737
6738
6739match({expr}, {pat} [, {start} [, {count}]]) *match()*
6740 When {expr} is a |List| then this returns the index of the
6741 first item where {pat} matches. Each item is used as a
6742 String, |Lists| and |Dictionaries| are used as echoed.
6743
6744 Otherwise, {expr} is used as a String. The result is a
6745 Number, which gives the index (byte offset) in {expr} where
6746 {pat} matches.
6747
6748 A match at the first character or |List| item returns zero.
6749 If there is no match -1 is returned.
6750
6751 For getting submatches see |matchlist()|.
6752 Example: >
6753 :echo match("testing", "ing") " results in 4
6754 :echo match([1, 'x'], '\a') " results in 1
6755< See |string-match| for how {pat} is used.
6756 *strpbrk()*
6757 Vim doesn't have a strpbrk() function. But you can do: >
6758 :let sepidx = match(line, '[.,;: \t]')
6759< *strcasestr()*
6760 Vim doesn't have a strcasestr() function. But you can add
6761 "\c" to the pattern to ignore case: >
6762 :let idx = match(haystack, '\cneedle')
6763<
6764 If {start} is given, the search starts from byte index
6765 {start} in a String or item {start} in a |List|.
6766 The result, however, is still the index counted from the
6767 first character/item. Example: >
6768 :echo match("testing", "ing", 2)
6769< result is again "4". >
6770 :echo match("testing", "ing", 4)
6771< result is again "4". >
6772 :echo match("testing", "t", 2)
6773< result is "3".
6774 For a String, if {start} > 0 then it is like the string starts
6775 {start} bytes later, thus "^" will match at {start}. Except
6776 when {count} is given, then it's like matches before the
6777 {start} byte are ignored (this is a bit complicated to keep it
6778 backwards compatible).
6779 For a String, if {start} < 0, it will be set to 0. For a list
6780 the index is counted from the end.
6781 If {start} is out of range ({start} > strlen({expr}) for a
6782 String or {start} > len({expr}) for a |List|) -1 is returned.
6783
6784 When {count} is given use the {count}'th match. When a match
6785 is found in a String the search for the next one starts one
6786 character further. Thus this example results in 1: >
6787 echo match("testing", "..", 0, 2)
6788< In a |List| the search continues in the next item.
6789 Note that when {count} is added the way {start} works changes,
6790 see above.
6791
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006792 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006793 See |pattern| for the patterns that are accepted.
6794 The 'ignorecase' option is used to set the ignore-caseness of
6795 the pattern. 'smartcase' is NOT used. The matching is always
6796 done like 'magic' is set and 'cpoptions' is empty.
6797 Note that a match at the start is preferred, thus when the
6798 pattern is using "*" (any number of matches) it tends to find
6799 zero matches at the start instead of a number of matches
6800 further down in the text.
6801
6802 Can also be used as a |method|: >
6803 GetText()->match('word')
6804 GetList()->match('word')
6805<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006806 Return type: |Number|
6807
6808
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006809 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006810matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6811 Defines a pattern to be highlighted in the current window (a
6812 "match"). It will be highlighted with {group}. Returns an
6813 identification number (ID), which can be used to delete the
6814 match using |matchdelete()|. The ID is bound to the window.
6815 Matching is case sensitive and magic, unless case sensitivity
6816 or magicness are explicitly overridden in {pattern}. The
6817 'magic', 'smartcase' and 'ignorecase' options are not used.
6818 The "Conceal" value is special, it causes the match to be
6819 concealed.
6820
6821 The optional {priority} argument assigns a priority to the
6822 match. A match with a high priority will have its
6823 highlighting overrule that of a match with a lower priority.
6824 A priority is specified as an integer (negative numbers are no
6825 exception). If the {priority} argument is not specified, the
6826 default priority is 10. The priority of 'hlsearch' is zero,
6827 hence all matches with a priority greater than zero will
6828 overrule it. Syntax highlighting (see 'syntax') is a separate
6829 mechanism, and regardless of the chosen priority a match will
6830 always overrule syntax highlighting.
6831
6832 The optional {id} argument allows the request for a specific
6833 match ID. If a specified ID is already taken, an error
6834 message will appear and the match will not be added. An ID
6835 is specified as a positive integer (zero excluded). IDs 1, 2
6836 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01006837 respectively. 3 is reserved for use by the |matchparen|
6838 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01006839 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01006840 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006841
6842 The optional {dict} argument allows for further custom
6843 values. Currently this is used to specify a match specific
6844 conceal character that will be shown for |hl-Conceal|
6845 highlighted matches. The dict can have the following members:
6846
6847 conceal Special character to show instead of the
6848 match (only for |hl-Conceal| highlighted
6849 matches, see |:syn-cchar|)
6850 window Instead of the current window use the
6851 window with this number or window ID.
6852
6853 The number of matches is not limited, as it is the case with
6854 the |:match| commands.
6855
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006856 Returns -1 on error.
6857
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006858 Example: >
6859 :highlight MyGroup ctermbg=green guibg=green
6860 :let m = matchadd("MyGroup", "TODO")
6861< Deletion of the pattern: >
6862 :call matchdelete(m)
6863
6864< A list of matches defined by |matchadd()| and |:match| are
6865 available from |getmatches()|. All matches can be deleted in
6866 one operation by |clearmatches()|.
6867
6868 Can also be used as a |method|: >
6869 GetGroup()->matchadd('TODO')
6870<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006871 Return type: |Number|
6872
6873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006874 *matchaddpos()*
6875matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6876 Same as |matchadd()|, but requires a list of positions {pos}
6877 instead of a pattern. This command is faster than |matchadd()|
6878 because it does not require to handle regular expressions and
6879 sets buffer line boundaries to redraw screen. It is supposed
6880 to be used when fast match additions and deletions are
6881 required, for example to highlight matching parentheses.
6882
6883 {pos} is a list of positions. Each position can be one of
6884 these:
6885 - A number. This whole line will be highlighted. The first
6886 line has number 1.
6887 - A list with one number, e.g., [23]. The whole line with this
6888 number will be highlighted.
6889 - A list with two numbers, e.g., [23, 11]. The first number is
6890 the line number, the second one is the column number (first
6891 column is 1, the value must correspond to the byte index as
6892 |col()| would return). The character at this position will
6893 be highlighted.
6894 - A list with three numbers, e.g., [23, 11, 3]. As above, but
6895 the third number gives the length of the highlight in bytes.
6896
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006897 Returns -1 on error.
6898
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006899 Example: >
6900 :highlight MyGroup ctermbg=green guibg=green
6901 :let m = matchaddpos("MyGroup", [[23, 24], 34])
6902< Deletion of the pattern: >
6903 :call matchdelete(m)
6904
6905< Matches added by |matchaddpos()| are returned by
6906 |getmatches()|.
6907
6908 Can also be used as a |method|: >
6909 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006910<
6911 Return type: |Number|
6912
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006913
6914matcharg({nr}) *matcharg()*
6915 Selects the {nr} match item, as set with a |:match|,
6916 |:2match| or |:3match| command.
6917 Return a |List| with two elements:
6918 The name of the highlight group used
6919 The pattern used.
6920 When {nr} is not 1, 2 or 3 returns an empty |List|.
6921 When there is no match item set returns ['', ''].
6922 This is useful to save and restore a |:match|.
6923 Highlighting matches using the |:match| commands are limited
6924 to three matches. |matchadd()| does not have this limitation.
6925
6926 Can also be used as a |method|: >
6927 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006928<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006929 Return type: list<string>
6930
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006931 *matchbufline()*
6932matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
6933 Returns the |List| of matches in lines from {lnum} to {end} in
6934 buffer {buf} where {pat} matches.
6935
6936 {lnum} and {end} can either be a line number or the string "$"
6937 to refer to the last line in {buf}.
6938
6939 The {dict} argument supports following items:
6940 submatches include submatch information (|/\(|)
6941
6942 For each match, a |Dict| with the following items is returned:
6943 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006944 lnum line number where there is a match
6945 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006946 Note that there can be multiple matches in a single line.
6947
6948 This function works only for loaded buffers. First call
6949 |bufload()| if needed.
6950
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006951 See |match-pattern| for information about the effect of some
6952 option settings on the pattern.
6953
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006954 When {buf} is not a valid buffer, the buffer is not loaded or
6955 {lnum} or {end} is not valid then an error is given and an
6956 empty |List| is returned.
6957
6958 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006959 " Assuming line 3 in buffer 5 contains "a"
6960 :echo matchbufline(5, '\<\k\+\>', 3, 3)
6961 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
6962 " Assuming line 4 in buffer 10 contains "tik tok"
6963 :echo matchbufline(10, '\<\k\+\>', 1, 4)
6964 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006965<
6966 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006967 "\1", "\2", etc. are also returned. Example: >
6968 " Assuming line 2 in buffer 2 contains "acd"
6969 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006970 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08006971 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01006972< The "submatches" List always contains 9 items. If a submatch
6973 is not found, then an empty string is returned for that
6974 submatch.
6975
6976 Can also be used as a |method|: >
6977 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006978<
6979 Return type: list<dict<any>> or list<any>
6980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006981
6982matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
6983 Deletes a match with ID {id} previously defined by |matchadd()|
6984 or one of the |:match| commands. Returns 0 if successful,
6985 otherwise -1. See example for |matchadd()|. All matches can
6986 be deleted in one operation by |clearmatches()|.
6987 If {win} is specified, use the window with this number or
6988 window ID instead of the current window.
6989
6990 Can also be used as a |method|: >
6991 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006992<
6993 Return type: |Number|
6994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006995
6996matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
6997 Same as |match()|, but return the index of first character
6998 after the match. Example: >
6999 :echo matchend("testing", "ing")
7000< results in "7".
7001 *strspn()* *strcspn()*
7002 Vim doesn't have a strspn() or strcspn() function, but you can
7003 do it with matchend(): >
7004 :let span = matchend(line, '[a-zA-Z]')
7005 :let span = matchend(line, '[^a-zA-Z]')
7006< Except that -1 is returned when there are no matches.
7007
7008 The {start}, if given, has the same meaning as for |match()|. >
7009 :echo matchend("testing", "ing", 2)
7010< results in "7". >
7011 :echo matchend("testing", "ing", 5)
7012< result is "-1".
7013 When {expr} is a |List| the result is equal to |match()|.
7014
7015 Can also be used as a |method|: >
7016 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007017<
7018 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007019
7020
7021matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7022 If {list} is a list of strings, then returns a |List| with all
7023 the strings in {list} that fuzzy match {str}. The strings in
7024 the returned list are sorted based on the matching score.
7025
7026 The optional {dict} argument always supports the following
7027 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007028 matchseq When this item is present return only matches
7029 that contain the characters in {str} in the
7030 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007031 limit Maximum number of matches in {list} to be
7032 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007033
7034 If {list} is a list of dictionaries, then the optional {dict}
7035 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007036 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007037 {str}. The value of this item should be a
7038 string.
7039 text_cb |Funcref| that will be called for every item
7040 in {list} to get the text for fuzzy matching.
7041 This should accept a dictionary item as the
7042 argument and return the text for that item to
7043 use for fuzzy matching.
7044
7045 {str} is treated as a literal string and regular expression
7046 matching is NOT supported. The maximum supported {str} length
7047 is 256.
7048
7049 When {str} has multiple words each separated by white space,
7050 then the list of strings that have all the words is returned.
7051
7052 If there are no matching strings or there is an error, then an
7053 empty list is returned. If length of {str} is greater than
7054 256, then returns an empty list.
7055
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007056 When {limit} is given, matchfuzzy() will find up to this
7057 number of matches in {list} and return them in sorted order.
7058
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007059 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007060 matching strings.
7061
7062 Example: >
7063 :echo matchfuzzy(["clay", "crow"], "cay")
7064< results in ["clay"]. >
7065 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7066< results in a list of buffer names fuzzy matching "ndl". >
7067 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7068< results in a list of buffer information dicts with buffer
7069 names fuzzy matching "ndl". >
7070 :echo getbufinfo()->matchfuzzy("spl",
7071 \ {'text_cb' : {v -> v.name}})
7072< results in a list of buffer information dicts with buffer
7073 names fuzzy matching "spl". >
7074 :echo v:oldfiles->matchfuzzy("test")
7075< results in a list of file names fuzzy matching "test". >
7076 :let l = readfile("buffer.c")->matchfuzzy("str")
7077< results in a list of lines in "buffer.c" fuzzy matching "str". >
7078 :echo ['one two', 'two one']->matchfuzzy('two one')
7079< results in ['two one', 'one two']. >
7080 :echo ['one two', 'two one']->matchfuzzy('two one',
7081 \ {'matchseq': 1})
7082< results in ['two one'].
7083
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007084 Return type: list<string> or list<any>
7085
7086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007087matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7088 Same as |matchfuzzy()|, but returns the list of matched
7089 strings, the list of character positions where characters
7090 in {str} matches and a list of matching scores. You can
7091 use |byteidx()| to convert a character position to a byte
7092 position.
7093
7094 If {str} matches multiple times in a string, then only the
7095 positions for the best match is returned.
7096
7097 If there are no matching strings or there is an error, then a
7098 list with three empty list items is returned.
7099
7100 Example: >
7101 :echo matchfuzzypos(['testing'], 'tsg')
7102< results in [['testing'], [[0, 2, 6]], [99]] >
7103 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7104< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7105 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7106< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7107
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007108 Return type: list<list<any>>
7109
7110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007111matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7112 Same as |match()|, but return a |List|. The first item in the
7113 list is the matched string, same as what matchstr() would
7114 return. Following items are submatches, like "\1", "\2", etc.
7115 in |:substitute|. When an optional submatch didn't match an
7116 empty string is used. Example: >
7117 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7118< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7119 When there is no match an empty list is returned.
7120
7121 You can pass in a List, but that is not very useful.
7122
7123 Can also be used as a |method|: >
7124 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007125<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007126 Return type: list<string> or list<any>
7127
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007128 *matchstrlist()*
7129matchstrlist({list}, {pat} [, {dict}])
7130 Returns the |List| of matches in {list} where {pat} matches.
7131 {list} is a |List| of strings. {pat} is matched against each
7132 string in {list}.
7133
7134 The {dict} argument supports following items:
7135 submatches include submatch information (|/\(|)
7136
7137 For each match, a |Dict| with the following items is returned:
7138 byteidx starting byte index of the match.
7139 idx index in {list} of the match.
7140 text matched string
7141 submatches a List of submatches. Present only if
7142 "submatches" is set to v:true in {dict}.
7143
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007144 See |match-pattern| for information about the effect of some
7145 option settings on the pattern.
7146
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007147 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007148 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7149 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7150 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7151 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007152<
7153 If "submatches" is present and is v:true, then submatches like
7154 "\1", "\2", etc. are also returned. Example: >
7155 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7156 \ #{submatches: v:true})
7157 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7158< The "submatches" List always contains 9 items. If a submatch
7159 is not found, then an empty string is returned for that
7160 submatch.
7161
7162 Can also be used as a |method|: >
7163 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007164<
7165 Return type: list<dict<any>> or list<any>
7166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007167
7168matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7169 Same as |match()|, but return the matched string. Example: >
7170 :echo matchstr("testing", "ing")
7171< results in "ing".
7172 When there is no match "" is returned.
7173 The {start}, if given, has the same meaning as for |match()|. >
7174 :echo matchstr("testing", "ing", 2)
7175< results in "ing". >
7176 :echo matchstr("testing", "ing", 5)
7177< result is "".
7178 When {expr} is a |List| then the matching item is returned.
7179 The type isn't changed, it's not necessarily a String.
7180
7181 Can also be used as a |method|: >
7182 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007183<
7184 Return type: |String|
7185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007186
7187matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7188 Same as |matchstr()|, but return the matched string, the start
7189 position and the end position of the match. Example: >
7190 :echo matchstrpos("testing", "ing")
7191< results in ["ing", 4, 7].
7192 When there is no match ["", -1, -1] is returned.
7193 The {start}, if given, has the same meaning as for |match()|. >
7194 :echo matchstrpos("testing", "ing", 2)
7195< results in ["ing", 4, 7]. >
7196 :echo matchstrpos("testing", "ing", 5)
7197< result is ["", -1, -1].
7198 When {expr} is a |List| then the matching item, the index
7199 of first item where {pat} matches, the start position and the
7200 end position of the match are returned. >
7201 :echo matchstrpos([1, '__x'], '\a')
7202< result is ["x", 1, 2, 3].
7203 The type isn't changed, it's not necessarily a String.
7204
7205 Can also be used as a |method|: >
7206 GetText()->matchstrpos('word')
7207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007208 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007209
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007210
7211max({expr}) *max()*
7212 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007213 echo max([apples, pears, oranges])
7214
7215< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7216 it returns the maximum of all values in the Dictionary.
7217 If {expr} is neither a List nor a Dictionary, or one of the
7218 items in {expr} cannot be used as a Number this results in
7219 an error. An empty |List| or |Dictionary| results in zero.
7220
7221 Can also be used as a |method|: >
7222 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007223<
7224 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007225
7226
7227menu_info({name} [, {mode}]) *menu_info()*
7228 Return information about the specified menu {name} in
7229 mode {mode}. The menu name should be specified without the
7230 shortcut character ('&'). If {name} is "", then the top-level
7231 menu names are returned.
7232
7233 {mode} can be one of these strings:
7234 "n" Normal
7235 "v" Visual (including Select)
7236 "o" Operator-pending
7237 "i" Insert
7238 "c" Cmd-line
7239 "s" Select
7240 "x" Visual
7241 "t" Terminal-Job
7242 "" Normal, Visual and Operator-pending
7243 "!" Insert and Cmd-line
7244 When {mode} is omitted, the modes for "" are used.
7245
7246 Returns a |Dictionary| containing the following items:
7247 accel menu item accelerator text |menu-text|
7248 display display name (name without '&')
7249 enabled v:true if this menu item is enabled
7250 Refer to |:menu-enable|
7251 icon name of the icon file (for toolbar)
7252 |toolbar-icon|
7253 iconidx index of a built-in icon
7254 modes modes for which the menu is defined. In
7255 addition to the modes mentioned above, these
7256 characters will be used:
7257 " " Normal, Visual and Operator-pending
7258 name menu item name.
7259 noremenu v:true if the {rhs} of the menu item is not
7260 remappable else v:false.
7261 priority menu order priority |menu-priority|
7262 rhs right-hand-side of the menu item. The returned
7263 string has special characters translated like
7264 in the output of the ":menu" command listing.
7265 When the {rhs} of a menu item is empty, then
7266 "<Nop>" is returned.
7267 script v:true if script-local remapping of {rhs} is
7268 allowed else v:false. See |:menu-script|.
7269 shortcut shortcut key (character after '&' in
7270 the menu name) |menu-shortcut|
7271 silent v:true if the menu item is created
7272 with <silent> argument |:menu-silent|
7273 submenus |List| containing the names of
7274 all the submenus. Present only if the menu
7275 item has submenus.
7276
7277 Returns an empty dictionary if the menu item is not found.
7278
7279 Examples: >
7280 :echo menu_info('Edit.Cut')
7281 :echo menu_info('File.Save', 'n')
7282
7283 " Display the entire menu hierarchy in a buffer
7284 func ShowMenu(name, pfx)
7285 let m = menu_info(a:name)
7286 call append(line('$'), a:pfx .. m.display)
7287 for child in m->get('submenus', [])
7288 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7289 \ a:pfx .. ' ')
7290 endfor
7291 endfunc
7292 new
7293 for topmenu in menu_info('').submenus
7294 call ShowMenu(topmenu, '')
7295 endfor
7296<
7297 Can also be used as a |method|: >
7298 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007299<
7300 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007301
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007302min({expr}) *min()*
7303 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007304 echo min([apples, pears, oranges])
7305
7306< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7307 it returns the minimum of all values in the Dictionary.
7308 If {expr} is neither a List nor a Dictionary, or one of the
7309 items in {expr} cannot be used as a Number this results in
7310 an error. An empty |List| or |Dictionary| results in zero.
7311
7312 Can also be used as a |method|: >
7313 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007314<
7315 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007316
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007317
7318mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007319 Create directory {name}.
7320
Bram Moolenaar938ae282023-02-20 20:44:55 +00007321 When {flags} is present it must be a string. An empty string
7322 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007323
Bram Moolenaar938ae282023-02-20 20:44:55 +00007324 If {flags} contains "p" then intermediate directories are
7325 created as necessary.
7326
7327 If {flags} contains "D" then {name} is deleted at the end of
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007328 the current function, as with: >
7329 defer delete({name}, 'd')
7330<
Bram Moolenaar938ae282023-02-20 20:44:55 +00007331 If {flags} contains "R" then {name} is deleted recursively at
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007332 the end of the current function, as with: >
7333 defer delete({name}, 'rf')
7334< Note that when {name} has more than one part and "p" is used
7335 some directories may already exist. Only the first one that
7336 is created and what it contains is scheduled to be deleted.
7337 E.g. when using: >
7338 call mkdir('subdir/tmp/autoload', 'pR')
7339< and "subdir" already exists then "subdir/tmp" will be
7340 scheduled for deletion, like with: >
7341 defer delete('subdir/tmp', 'rf')
7342< Note that if scheduling the defer fails the directory is not
7343 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007344
7345 If {prot} is given it is used to set the protection bits of
7346 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7347 the user, readable for others). Use 0o700 to make it
7348 unreadable for others. This is only used for the last part of
7349 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7350 created with 0o755.
7351 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007352 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007353
7354< This function is not available in the |sandbox|.
7355
7356 There is no error if the directory already exists and the "p"
7357 flag is passed (since patch 8.0.1708). However, without the
7358 "p" option the call will fail.
7359
7360 The function result is a Number, which is TRUE if the call was
7361 successful or FALSE if the directory creation failed or partly
7362 failed.
7363
7364 Not available on all systems. To check use: >
7365 :if exists("*mkdir")
7366
7367< Can also be used as a |method|: >
7368 GetName()->mkdir()
7369<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007370 Return type: |Number|
7371
7372
7373mode([{expr}]) *mode()*
7374 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007375 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007376 a non-empty String (|non-zero-arg|), then the full mode is
7377 returned, otherwise only the first letter is returned.
7378 Also see |state()|.
7379
7380 n Normal
7381 no Operator-pending
7382 nov Operator-pending (forced characterwise |o_v|)
7383 noV Operator-pending (forced linewise |o_V|)
7384 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7385 CTRL-V is one character
7386 niI Normal using |i_CTRL-O| in |Insert-mode|
7387 niR Normal using |i_CTRL-O| in |Replace-mode|
7388 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7389 nt Terminal-Normal (insert goes to Terminal-Job mode)
7390 v Visual by character
7391 vs Visual by character using |v_CTRL-O| in Select mode
7392 V Visual by line
7393 Vs Visual by line using |v_CTRL-O| in Select mode
7394 CTRL-V Visual blockwise
7395 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7396 s Select by character
7397 S Select by line
7398 CTRL-S Select blockwise
7399 i Insert
7400 ic Insert mode completion |compl-generic|
7401 ix Insert mode |i_CTRL-X| completion
7402 R Replace |R|
7403 Rc Replace mode completion |compl-generic|
7404 Rx Replace mode |i_CTRL-X| completion
7405 Rv Virtual Replace |gR|
7406 Rvc Virtual Replace mode completion |compl-generic|
7407 Rvx Virtual Replace mode |i_CTRL-X| completion
7408 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007409 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007410 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007411 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007412 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007413 ce Normal Ex mode |Q|
7414 r Hit-enter prompt
7415 rm The -- more -- prompt
7416 r? A |:confirm| query of some sort
7417 ! Shell or external command is executing
7418 t Terminal-Job mode: keys go to the job
7419
7420 This is useful in the 'statusline' option or when used
7421 with |remote_expr()| In most other places it always returns
7422 "c" or "n".
7423 Note that in the future more modes and more specific modes may
7424 be added. It's better not to compare the whole string but only
7425 the leading character(s).
7426 Also see |visualmode()|.
7427
7428 Can also be used as a |method|: >
7429 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007430<
7431 Return type: |String|
7432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007433
7434mzeval({expr}) *mzeval()*
7435 Evaluate MzScheme expression {expr} and return its result
7436 converted to Vim data structures.
7437 Numbers and strings are returned as they are.
7438 Pairs (including lists and improper lists) and vectors are
7439 returned as Vim |Lists|.
7440 Hash tables are represented as Vim |Dictionary| type with keys
7441 converted to strings.
7442 All other types are converted to string with display function.
7443 Examples: >
7444 :mz (define l (list 1 2 3))
7445 :mz (define h (make-hash)) (hash-set! h "list" l)
7446 :echo mzeval("l")
7447 :echo mzeval("h")
7448<
7449 Note that in a `:def` function local variables are not visible
7450 to {expr}.
7451
7452 Can also be used as a |method|: >
7453 GetExpr()->mzeval()
7454<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007455 Return type: any, depending on {expr}
7456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007457 {only available when compiled with the |+mzscheme| feature}
7458
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007460nextnonblank({lnum}) *nextnonblank()*
7461 Return the line number of the first line at or below {lnum}
7462 that is not blank. Example: >
7463 if getline(nextnonblank(1)) =~ "Java"
7464< When {lnum} is invalid or there is no non-blank line at or
7465 below it, zero is returned.
7466 {lnum} is used like with |getline()|.
7467 See also |prevnonblank()|.
7468
7469 Can also be used as a |method|: >
7470 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007471<
7472 Return type: |Number|
7473
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007474
7475nr2char({expr} [, {utf8}]) *nr2char()*
7476 Return a string with a single character, which has the number
7477 value {expr}. Examples: >
7478 nr2char(64) returns "@"
7479 nr2char(32) returns " "
7480< When {utf8} is omitted or zero, the current 'encoding' is used.
7481 Example for "utf-8": >
7482 nr2char(300) returns I with bow character
7483< When {utf8} is TRUE, always return UTF-8 characters.
7484 Note that a NUL character in the file is specified with
7485 nr2char(10), because NULs are represented with newline
7486 characters. nr2char(0) is a real NUL and terminates the
7487 string, thus results in an empty string.
7488 To turn a list of character numbers into a string: >
7489 let list = [65, 66, 67]
7490 let str = join(map(list, {_, val -> nr2char(val)}), '')
7491< Result: "ABC"
7492
7493 Can also be used as a |method|: >
7494 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007495<
7496 Return type: |String|
7497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007498
7499or({expr}, {expr}) *or()*
7500 Bitwise OR on the two arguments. The arguments are converted
7501 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007502 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007503 Example: >
7504 :let bits = or(bits, 0x80)
7505< Can also be used as a |method|: >
7506 :let bits = bits->or(0x80)
7507
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007508< Rationale: The reason this is a function and not using the "|"
7509 character like many languages, is that Vi has always used "|"
7510 to separate commands. In many places it would not be clear if
7511 "|" is an operator or a command separator.
7512
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007513 Return type: |Number|
7514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007515
7516pathshorten({path} [, {len}]) *pathshorten()*
7517 Shorten directory names in the path {path} and return the
7518 result. The tail, the file name, is kept as-is. The other
7519 components in the path are reduced to {len} letters in length.
7520 If {len} is omitted or smaller than 1 then 1 is used (single
7521 letters). Leading '~' and '.' characters are kept. Examples: >
7522 :echo pathshorten('~/.vim/autoload/myfile.vim')
7523< ~/.v/a/myfile.vim ~
7524>
7525 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7526< ~/.vi/au/myfile.vim ~
7527 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007528 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007529
7530 Can also be used as a |method|: >
7531 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007532<
7533 Return type: |String|
7534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007535
7536perleval({expr}) *perleval()*
7537 Evaluate Perl expression {expr} in scalar context and return
7538 its result converted to Vim data structures. If value can't be
7539 converted, it is returned as a string Perl representation.
7540 Note: If you want an array or hash, {expr} must return a
7541 reference to it.
7542 Example: >
7543 :echo perleval('[1 .. 4]')
7544< [1, 2, 3, 4]
7545
7546 Note that in a `:def` function local variables are not visible
7547 to {expr}.
7548
7549 Can also be used as a |method|: >
7550 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007551<
7552 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007553
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007554 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007555
7556
7557popup_ functions are documented here: |popup-functions|
7558
7559
7560pow({x}, {y}) *pow()*
7561 Return the power of {x} to the exponent {y} as a |Float|.
7562 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007563 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007564 Examples: >
7565 :echo pow(3, 3)
7566< 27.0 >
7567 :echo pow(2, 16)
7568< 65536.0 >
7569 :echo pow(32, 0.20)
7570< 2.0
7571
7572 Can also be used as a |method|: >
7573 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007574<
7575 Return type: |Number|
7576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007577
7578prevnonblank({lnum}) *prevnonblank()*
7579 Return the line number of the first line at or above {lnum}
7580 that is not blank. Example: >
7581 let ind = indent(prevnonblank(v:lnum - 1))
7582< When {lnum} is invalid or there is no non-blank line at or
7583 above it, zero is returned.
7584 {lnum} is used like with |getline()|.
7585 Also see |nextnonblank()|.
7586
7587 Can also be used as a |method|: >
7588 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007589<
7590 Return type: |Number|
7591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007592
7593printf({fmt}, {expr1} ...) *printf()*
7594 Return a String with {fmt}, where "%" items are replaced by
7595 the formatted form of their respective arguments. Example: >
7596 printf("%4d: E%d %.30s", lnum, errno, msg)
7597< May result in:
7598 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7599
7600 When used as a |method| the base is passed as the second
7601 argument: >
7602 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007603<
7604 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007605
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007606 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007607 %s string
7608 %6S string right-aligned in 6 display cells
7609 %6s string right-aligned in 6 bytes
7610 %.9s string truncated to 9 bytes
7611 %c single byte
7612 %d decimal number
7613 %5d decimal number padded with spaces to 5 characters
7614 %x hex number
7615 %04x hex number padded with zeros to at least 4 characters
7616 %X hex number using upper case letters
7617 %o octal number
7618 %08b binary number padded with zeros to at least 8 chars
7619 %f floating point number as 12.23, inf, -inf or nan
7620 %F floating point number as 12.23, INF, -INF or NAN
7621 %e floating point number as 1.23e3, inf, -inf or nan
7622 %E floating point number as 1.23E3, INF, -INF or NAN
7623 %g floating point number, as %f or %e depending on value
7624 %G floating point number, as %F or %E depending on value
7625 %% the % character itself
7626
7627 Conversion specifications start with '%' and end with the
7628 conversion type. All other characters are copied unchanged to
7629 the result.
7630
7631 The "%" starts a conversion specification. The following
7632 arguments appear in sequence:
7633
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007634 % [pos-argument] [flags] [field-width] [.precision] type
7635
7636 pos-argument
7637 At most one positional argument specifier. These
7638 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007639
7640 flags
7641 Zero or more of the following flags:
7642
7643 # The value should be converted to an "alternate
7644 form". For c, d, and s conversions, this option
7645 has no effect. For o conversions, the precision
7646 of the number is increased to force the first
7647 character of the output string to a zero (except
7648 if a zero value is printed with an explicit
7649 precision of zero).
7650 For b and B conversions, a non-zero result has
7651 the string "0b" (or "0B" for B conversions)
7652 prepended to it.
7653 For x and X conversions, a non-zero result has
7654 the string "0x" (or "0X" for X conversions)
7655 prepended to it.
7656
7657 0 (zero) Zero padding. For all conversions the converted
7658 value is padded on the left with zeros rather
7659 than blanks. If a precision is given with a
7660 numeric conversion (d, b, B, o, x, and X), the 0
7661 flag is ignored.
7662
7663 - A negative field width flag; the converted value
7664 is to be left adjusted on the field boundary.
7665 The converted value is padded on the right with
7666 blanks, rather than on the left with blanks or
7667 zeros. A - overrides a 0 if both are given.
7668
7669 ' ' (space) A blank should be left before a positive
7670 number produced by a signed conversion (d).
7671
7672 + A sign must always be placed before a number
7673 produced by a signed conversion. A + overrides
7674 a space if both are used.
7675
7676 field-width
7677 An optional decimal digit string specifying a minimum
7678 field width. If the converted value has fewer bytes
7679 than the field width, it will be padded with spaces on
7680 the left (or right, if the left-adjustment flag has
7681 been given) to fill out the field width. For the S
7682 conversion the count is in cells.
7683
7684 .precision
7685 An optional precision, in the form of a period '.'
7686 followed by an optional digit string. If the digit
7687 string is omitted, the precision is taken as zero.
7688 This gives the minimum number of digits to appear for
7689 d, o, x, and X conversions, the maximum number of
7690 bytes to be printed from a string for s conversions,
7691 or the maximum number of cells to be printed from a
7692 string for S conversions.
7693 For floating point it is the number of digits after
7694 the decimal point.
7695
7696 type
7697 A character that specifies the type of conversion to
7698 be applied, see below.
7699
7700 A field width or precision, or both, may be indicated by an
7701 asterisk '*' instead of a digit string. In this case, a
7702 Number argument supplies the field width or precision. A
7703 negative field width is treated as a left adjustment flag
7704 followed by a positive field width; a negative precision is
7705 treated as though it were missing. Example: >
7706 :echo printf("%d: %.*s", nr, width, line)
7707< This limits the length of the text used from "line" to
7708 "width" bytes.
7709
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007710 If the argument to be formatted is specified using a
7711 positional argument specifier, and a '*' is used to indicate
7712 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007713 precision, the argument(s) to be used must also be specified
7714 using a {n$} positional argument specifier. See |printf-$|.
7715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007716 The conversion specifiers and their meanings are:
7717
7718 *printf-d* *printf-b* *printf-B* *printf-o*
7719 *printf-x* *printf-X*
7720 dbBoxX The Number argument is converted to signed decimal
7721 (d), unsigned binary (b and B), unsigned octal (o), or
7722 unsigned hexadecimal (x and X) notation. The letters
7723 "abcdef" are used for x conversions; the letters
7724 "ABCDEF" are used for X conversions.
7725 The precision, if any, gives the minimum number of
7726 digits that must appear; if the converted value
7727 requires fewer digits, it is padded on the left with
7728 zeros.
7729 In no case does a non-existent or small field width
7730 cause truncation of a numeric field; if the result of
7731 a conversion is wider than the field width, the field
7732 is expanded to contain the conversion result.
7733 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007734 The 'l' modifier indicates the argument is a long
7735 integer. The size will be 32 bits or 64 bits
7736 depending on your platform.
7737 The "ll" modifier indicates the argument is 64 bits.
7738 The b and B conversion specifiers never take a width
7739 modifier and always assume their argument is a 64 bit
7740 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007741 Generally, these modifiers are not useful. They are
7742 ignored when type is known from the argument.
7743
7744 i alias for d
7745 D alias for ld
7746 U alias for lu
7747 O alias for lo
7748
7749 *printf-c*
7750 c The Number argument is converted to a byte, and the
7751 resulting character is written.
7752
7753 *printf-s*
7754 s The text of the String argument is used. If a
7755 precision is specified, no more bytes than the number
7756 specified are used.
7757 If the argument is not a String type, it is
7758 automatically converted to text with the same format
7759 as ":echo".
7760 *printf-S*
7761 S The text of the String argument is used. If a
7762 precision is specified, no more display cells than the
7763 number specified are used.
7764
7765 *printf-f* *E807*
7766 f F The Float argument is converted into a string of the
7767 form 123.456. The precision specifies the number of
7768 digits after the decimal point. When the precision is
7769 zero the decimal point is omitted. When the precision
7770 is not specified 6 is used. A really big number
7771 (out of range or dividing by zero) results in "inf"
7772 or "-inf" with %f (INF or -INF with %F).
7773 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7774 Example: >
7775 echo printf("%.2f", 12.115)
7776< 12.12
7777 Note that roundoff depends on the system libraries.
7778 Use |round()| when in doubt.
7779
7780 *printf-e* *printf-E*
7781 e E The Float argument is converted into a string of the
7782 form 1.234e+03 or 1.234E+03 when using 'E'. The
7783 precision specifies the number of digits after the
7784 decimal point, like with 'f'.
7785
7786 *printf-g* *printf-G*
7787 g G The Float argument is converted like with 'f' if the
7788 value is between 0.001 (inclusive) and 10000000.0
7789 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7790 for 'G'. When no precision is specified superfluous
7791 zeroes and '+' signs are removed, except for the zero
7792 immediately after the decimal point. Thus 10000000.0
7793 results in 1.0e7.
7794
7795 *printf-%*
7796 % A '%' is written. No argument is converted. The
7797 complete conversion specification is "%%".
7798
7799 When a Number argument is expected a String argument is also
7800 accepted and automatically converted.
7801 When a Float or String argument is expected a Number argument
7802 is also accepted and automatically converted.
7803 Any other argument type results in an error message.
7804
7805 *E766* *E767*
7806 The number of {exprN} arguments must exactly match the number
7807 of "%" items. If there are not sufficient or too many
7808 arguments an error is given. Up to 18 arguments can be used.
7809
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007810 *printf-$*
7811 In certain languages, error and informative messages are
7812 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007813 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007814 having a different word order, positional arguments may be
7815 used to indicate this. For instance: >
7816
h_east596a9f22023-11-21 21:24:23 +09007817 #, c-format
7818 msgid "%s returning %s"
7819 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007820<
h_east596a9f22023-11-21 21:24:23 +09007821 In this example, the sentence has its 2 string arguments
7822 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007823
h_east596a9f22023-11-21 21:24:23 +09007824 echo printf(
7825 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7826 "Bram", "Moolenaar")
7827< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007828
h_east596a9f22023-11-21 21:24:23 +09007829 echo printf(
7830 "In Belgium, vim's creator's name is: %2$s %1$s",
7831 "Bram", "Moolenaar")
7832< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007833
7834 Width (and precision) can be specified using the '*' specifier.
7835 In this case, you must specify the field width position in the
7836 argument list. >
7837
h_east596a9f22023-11-21 21:24:23 +09007838 echo printf("%1$*2$.*3$d", 1, 2, 3)
7839< 001 >
7840 echo printf("%2$*3$.*1$d", 1, 2, 3)
7841< 2 >
7842 echo printf("%3$*1$.*2$d", 1, 2, 3)
7843< 03 >
7844 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
7845< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007846
7847 You can mix specifying the width and/or precision directly
7848 and via positional arguments: >
7849
h_east596a9f22023-11-21 21:24:23 +09007850 echo printf("%1$4.*2$f", 1.4142135, 6)
7851< 1.414214 >
7852 echo printf("%1$*2$.4f", 1.4142135, 6)
7853< 1.4142 >
7854 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
7855< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007856
Christ van Willegenc35fc032024-03-14 18:30:41 +01007857 You will get an overflow error |E1510|, when the field-width
7858 or precision will result in a string longer than 6400 chars.
7859
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007860 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007861 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09007862 echo printf("%s%1$s", "One", "Two")
7863< E1500: Cannot mix positional and non-positional arguments:
7864 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007865
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007866 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007867 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09007868 echo printf("%3$s%1$s", "One", "Two", "Three")
7869< E1501: format argument 2 unused in $-style format:
7870 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007871
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007872 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007873 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09007874 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
7875< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007876
7877 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09007878 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
7879< E1502: Positional argument 2 used as field width reused as
7880 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007881
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007882 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007883 When a positional argument is used, but not the correct number
7884 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09007885 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
7886< E1503: Positional argument 3 out of bounds: %1$d at width
7887 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007888
7889 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09007890 echo printf("%01$*2$.*3$d %4$d", 1, 2)
7891< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
7892 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007893
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007894 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007895 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09007896 echo printf("%1$s %2$s %1$s", "One", "Two")
7897< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007898
7899 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09007900 echo printf("%1$s %2$s %1$d", "One", "Two")
7901< E1504: Positional argument 1 type used inconsistently:
7902 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007903
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02007904 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007905 Various other errors that lead to a format string being
7906 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09007907 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
7908< E1505: Invalid format specifier: %1$d at width %2$d is:
7909 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007910
Christ van Willegenea746f92023-10-05 20:48:36 +02007911 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08007912 This internal error indicates that the logic to parse a
7913 positional format argument ran into a problem that couldn't be
7914 otherwise reported. Please file a bug against Vim if you run
7915 into this, copying the exact format string and parameters that
7916 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02007917
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007918 Return type: |String|
7919
Christ van Willegenea746f92023-10-05 20:48:36 +02007920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007921prompt_getprompt({buf}) *prompt_getprompt()*
7922 Returns the effective prompt text for buffer {buf}. {buf} can
7923 be a buffer name or number. See |prompt-buffer|.
7924
7925 If the buffer doesn't exist or isn't a prompt buffer, an empty
7926 string is returned.
7927
7928 Can also be used as a |method|: >
7929 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007930<
7931 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007932
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007933 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007934
7935
7936prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
7937 Set prompt callback for buffer {buf} to {expr}. When {expr}
7938 is an empty string the callback is removed. This has only
7939 effect if {buf} has 'buftype' set to "prompt".
7940
7941 The callback is invoked when pressing Enter. The current
7942 buffer will always be the prompt buffer. A new line for a
7943 prompt is added before invoking the callback, thus the prompt
7944 for which the callback was invoked will be in the last but one
7945 line.
7946 If the callback wants to add text to the buffer, it must
7947 insert it above the last line, since that is where the current
7948 prompt is. This can also be done asynchronously.
7949 The callback is invoked with one argument, which is the text
7950 that was entered at the prompt. This can be an empty string
7951 if the user only typed Enter.
7952 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007953 func s:TextEntered(text)
7954 if a:text == 'exit' || a:text == 'quit'
7955 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007956 " Reset 'modified' to allow the buffer to be closed.
7957 " We assume there is nothing useful to be saved.
7958 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007959 close
7960 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007961 " Do something useful with "a:text". In this example
7962 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007963 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007964 endif
7965 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01007966 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007967
7968< Can also be used as a |method|: >
7969 GetBuffer()->prompt_setcallback(callback)
7970
7971< {only available when compiled with the |+channel| feature}
7972
7973prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
7974 Set a callback for buffer {buf} to {expr}. When {expr} is an
7975 empty string the callback is removed. This has only effect if
7976 {buf} has 'buftype' set to "prompt".
7977
7978 This callback will be invoked when pressing CTRL-C in Insert
7979 mode. Without setting a callback Vim will exit Insert mode,
7980 as in any buffer.
7981
7982 Can also be used as a |method|: >
7983 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007984<
7985 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007986
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007987 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007988
7989prompt_setprompt({buf}, {text}) *prompt_setprompt()*
7990 Set prompt for buffer {buf} to {text}. You most likely want
7991 {text} to end in a space.
7992 The result is only visible if {buf} has 'buftype' set to
7993 "prompt". Example: >
7994 call prompt_setprompt(bufnr(), 'command: ')
7995<
7996 Can also be used as a |method|: >
7997 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007998<
7999 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008000
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008001 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008002
8003prop_ functions are documented here: |text-prop-functions|
8004
8005pum_getpos() *pum_getpos()*
8006 If the popup menu (see |ins-completion-menu|) is not visible,
8007 returns an empty |Dictionary|, otherwise, returns a
8008 |Dictionary| with the following keys:
8009 height nr of items visible
8010 width screen cells
8011 row top screen row (0 first row)
8012 col leftmost screen column (0 first col)
8013 size total nr of items
8014 scrollbar |TRUE| if scrollbar is visible
8015
8016 The values are the same as in |v:event| during
8017 |CompleteChanged|.
8018
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008019 Return type: dict<any>
8020
8021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008022pumvisible() *pumvisible()*
8023 Returns non-zero when the popup menu is visible, zero
8024 otherwise. See |ins-completion-menu|.
8025 This can be used to avoid some things that would remove the
8026 popup menu.
8027
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008028 Return type: |Number|
8029
8030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008031py3eval({expr}) *py3eval()*
8032 Evaluate Python expression {expr} and return its result
8033 converted to Vim data structures.
8034 Numbers and strings are returned as they are (strings are
8035 copied though, Unicode strings are additionally converted to
8036 'encoding').
8037 Lists are represented as Vim |List| type.
8038 Dictionaries are represented as Vim |Dictionary| type with
8039 keys converted to strings.
8040 Note that in a `:def` function local variables are not visible
8041 to {expr}.
8042
8043 Can also be used as a |method|: >
8044 GetExpr()->py3eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008045<
8046 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008047
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008048 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008049
8050 *E858* *E859*
8051pyeval({expr}) *pyeval()*
8052 Evaluate Python expression {expr} and return its result
8053 converted to Vim data structures.
8054 Numbers and strings are returned as they are (strings are
8055 copied though).
8056 Lists are represented as Vim |List| type.
8057 Dictionaries are represented as Vim |Dictionary| type,
8058 non-string keys result in error.
8059 Note that in a `:def` function local variables are not visible
8060 to {expr}.
8061
8062 Can also be used as a |method|: >
8063 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008064<
8065 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008066
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008067 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008068
8069pyxeval({expr}) *pyxeval()*
8070 Evaluate Python expression {expr} and return its result
8071 converted to Vim data structures.
8072 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8073 See also: |pyeval()|, |py3eval()|
8074
8075 Can also be used as a |method|: >
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008076 < GetExpr()->pyxeval()
8077<
8078 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008079
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008080 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008081 |+python3| feature}
8082
8083rand([{expr}]) *rand()* *random*
8084 Return a pseudo-random Number generated with an xoshiro128**
8085 algorithm using seed {expr}. The returned number is 32 bits,
8086 also on 64 bits systems, for consistency.
8087 {expr} can be initialized by |srand()| and will be updated by
8088 rand(). If {expr} is omitted, an internal seed value is used
8089 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008090 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008091
8092 Examples: >
8093 :echo rand()
8094 :let seed = srand()
8095 :echo rand(seed)
8096 :echo rand(seed) % 16 " random number 0 - 15
8097<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008098 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008099
8100 *E726* *E727*
8101range({expr} [, {max} [, {stride}]]) *range()*
8102 Returns a |List| with Numbers:
8103 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8104 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8105 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8106 {max}] (increasing {expr} with {stride} each time, not
8107 producing a value past {max}).
8108 When the maximum is one before the start the result is an
8109 empty list. When the maximum is more than one before the
8110 start this is an error.
8111 Examples: >
8112 range(4) " [0, 1, 2, 3]
8113 range(2, 4) " [2, 3, 4]
8114 range(2, 9, 3) " [2, 5, 8]
8115 range(2, -2, -1) " [2, 1, 0, -1, -2]
8116 range(0) " []
8117 range(2, 0) " error!
8118<
8119 Can also be used as a |method|: >
8120 GetExpr()->range()
8121<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008122 Return type: list<number>
8123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008124
K.Takata11df3ae2022-10-19 14:02:40 +01008125readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008126 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008127 If {offset} is specified, read the file from the specified
8128 offset. If it is a negative value, it is used as an offset
8129 from the end of the file. E.g., to read the last 12 bytes: >
8130 readblob('file.bin', -12)
8131< If {size} is specified, only the specified size will be read.
8132 E.g. to read the first 100 bytes of a file: >
8133 readblob('file.bin', 0, 100)
8134< If {size} is -1 or omitted, the whole data starting from
8135 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008136 This can be also used to read the data from a character device
8137 on Unix when {size} is explicitly set. Only if the device
8138 supports seeking {offset} can be used. Otherwise it should be
8139 zero. E.g. to read 10 bytes from a serial console: >
8140 readblob('/dev/ttyS0', 0, 10)
8141< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008142 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008143 When the offset is beyond the end of the file the result is an
8144 empty blob.
8145 When trying to read more bytes than are available the result
8146 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008147 Also see |readfile()| and |writefile()|.
8148
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008149 Return type: |Blob|
8150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008151
8152readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8153 Return a list with file and directory names in {directory}.
8154 You can also use |glob()| if you don't need to do complicated
8155 things, such as limiting the number of matches.
8156 The list will be sorted (case sensitive), see the {dict}
8157 argument below for changing the sort order.
8158
8159 When {expr} is omitted all entries are included.
8160 When {expr} is given, it is evaluated to check what to do:
8161 If {expr} results in -1 then no further entries will
8162 be handled.
8163 If {expr} results in 0 then this entry will not be
8164 added to the list.
8165 If {expr} results in 1 then this entry will be added
8166 to the list.
8167 The entries "." and ".." are always excluded.
8168 Each time {expr} is evaluated |v:val| is set to the entry name.
8169 When {expr} is a function the name is passed as the argument.
8170 For example, to get a list of files ending in ".txt": >
8171 readdir(dirname, {n -> n =~ '.txt$'})
8172< To skip hidden and backup files: >
8173 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008174< *E857*
8175 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008176 values. Currently this is used to specify if and how sorting
8177 should be performed. The dict can have the following members:
8178
8179 sort How to sort the result returned from the system.
8180 Valid values are:
8181 "none" do not sort (fastest method)
8182 "case" sort case sensitive (byte value of
8183 each character, technically, using
8184 strcmp()) (default)
8185 "icase" sort case insensitive (technically
8186 using strcasecmp())
8187 "collate" sort using the collation order
8188 of the "POSIX" or "C" |locale|
8189 (technically using strcoll())
8190 Other values are silently ignored.
8191
8192 For example, to get a list of all files in the current
8193 directory without sorting the individual entries: >
8194 readdir('.', '1', #{sort: 'none'})
8195< If you want to get a directory tree: >
8196 function! s:tree(dir)
8197 return {a:dir : map(readdir(a:dir),
8198 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008199 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008200 endfunction
8201 echo s:tree(".")
8202<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008203 Returns an empty List on error.
8204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008205 Can also be used as a |method|: >
8206 GetDirName()->readdir()
8207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008208 Return type: list<string> or list<any>
8209
8210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008211readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8212 Extended version of |readdir()|.
8213 Return a list of Dictionaries with file and directory
8214 information in {directory}.
8215 This is useful if you want to get the attributes of file and
8216 directory at the same time as getting a list of a directory.
8217 This is much faster than calling |readdir()| then calling
8218 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8219 each file and directory especially on MS-Windows.
8220 The list will by default be sorted by name (case sensitive),
8221 the sorting can be changed by using the optional {dict}
8222 argument, see |readdir()|.
8223
8224 The Dictionary for file and directory information has the
8225 following items:
8226 group Group name of the entry. (Only on Unix)
8227 name Name of the entry.
8228 perm Permissions of the entry. See |getfperm()|.
8229 size Size of the entry. See |getfsize()|.
8230 time Timestamp of the entry. See |getftime()|.
8231 type Type of the entry.
8232 On Unix, almost same as |getftype()| except:
8233 Symlink to a dir "linkd"
8234 Other symlink "link"
8235 On MS-Windows:
8236 Normal file "file"
8237 Directory "dir"
8238 Junction "junction"
8239 Symlink to a dir "linkd"
8240 Other symlink "link"
8241 Other reparse point "reparse"
8242 user User name of the entry's owner. (Only on Unix)
8243 On Unix, if the entry is a symlink, the Dictionary includes
8244 the information of the target (except the "type" item).
8245 On MS-Windows, it includes the information of the symlink
8246 itself because of performance reasons.
8247
8248 When {expr} is omitted all entries are included.
8249 When {expr} is given, it is evaluated to check what to do:
8250 If {expr} results in -1 then no further entries will
8251 be handled.
8252 If {expr} results in 0 then this entry will not be
8253 added to the list.
8254 If {expr} results in 1 then this entry will be added
8255 to the list.
8256 The entries "." and ".." are always excluded.
8257 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8258 of the entry.
8259 When {expr} is a function the entry is passed as the argument.
8260 For example, to get a list of files ending in ".txt": >
8261 readdirex(dirname, {e -> e.name =~ '.txt$'})
8262<
8263 For example, to get a list of all files in the current
8264 directory without sorting the individual entries: >
8265 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008266<
8267 Can also be used as a |method|: >
8268 GetDirName()->readdirex()
8269<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008270 Return type: list<dict<any>> or list<any>
8271
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008272
8273 *readfile()*
8274readfile({fname} [, {type} [, {max}]])
8275 Read file {fname} and return a |List|, each line of the file
8276 as an item. Lines are broken at NL characters. Macintosh
8277 files separated with CR will result in a single long line
8278 (unless a NL appears somewhere).
8279 All NUL characters are replaced with a NL character.
8280 When {type} contains "b" binary mode is used:
8281 - When the last line ends in a NL an extra empty list item is
8282 added.
8283 - No CR characters are removed.
8284 Otherwise:
8285 - CR characters that appear before a NL are removed.
8286 - Whether the last line ends in a NL or not does not matter.
8287 - When 'encoding' is Unicode any UTF-8 byte order mark is
8288 removed from the text.
8289 When {max} is given this specifies the maximum number of lines
8290 to be read. Useful if you only want to check the first ten
8291 lines of a file: >
8292 :for line in readfile(fname, '', 10)
8293 : if line =~ 'Date' | echo line | endif
8294 :endfor
8295< When {max} is negative -{max} lines from the end of the file
8296 are returned, or as many as there are.
8297 When {max} is zero the result is an empty list.
8298 Note that without {max} the whole file is read into memory.
8299 Also note that there is no recognition of encoding. Read a
8300 file into a buffer if you need to.
8301 Deprecated (use |readblob()| instead): When {type} contains
8302 "B" a |Blob| is returned with the binary data of the file
8303 unmodified.
8304 When the file can't be opened an error message is given and
8305 the result is an empty list.
8306 Also see |writefile()|.
8307
8308 Can also be used as a |method|: >
8309 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008310<
8311 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008312
8313reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8314 {func} is called for every item in {object}, which can be a
8315 |String|, |List| or a |Blob|. {func} is called with two
8316 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008317 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008318
8319 {initial} is the initial result. When omitted, the first item
8320 in {object} is used and {func} is first called for the second
8321 item. If {initial} is not given and {object} is empty no
8322 result can be computed, an E998 error is given.
8323
8324 Examples: >
8325 echo reduce([1, 3, 5], { acc, val -> acc + val })
8326 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8327 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8328 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8329<
8330 Can also be used as a |method|: >
8331 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008332<
8333 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8334 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335
8336
8337reg_executing() *reg_executing()*
8338 Returns the single letter name of the register being executed.
8339 Returns an empty string when no register is being executed.
8340 See |@|.
8341
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008342 Return type: |String|
8343
8344
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008345reg_recording() *reg_recording()*
8346 Returns the single letter name of the register being recorded.
8347 Returns an empty string when not recording. See |q|.
8348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008349 Return type: |String|
8350
8351
8352reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008353reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008354reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008355 Return an item that represents a time value. The item is a
8356 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008357 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008358 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008359 string or |reltimefloat()| to convert to a Float. For
8360 example, to see the time spent in function Work(): >
8361 var startTime = reltime()
8362 Work()
8363 echo startTime->reltime()->reltimestr()
8364<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008365 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008366 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008367 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008368 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008369 specified in the argument.
8370 With two arguments it returns the time passed between {start}
8371 and {end}.
8372
8373 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008374 reltime(). If there is an error an empty List is returned in
8375 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008376
8377 Can also be used as a |method|: >
8378 GetStart()->reltime()
8379<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008380 Return type: list<number>
8381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008382 {only available when compiled with the |+reltime| feature}
8383
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008384
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008385reltimefloat({time}) *reltimefloat()*
8386 Return a Float that represents the time value of {time}.
8387 Example: >
8388 let start = reltime()
8389 call MyFunction()
8390 let seconds = reltimefloat(reltime(start))
8391< See the note of reltimestr() about overhead.
8392 Also see |profiling|.
8393 If there is an error 0.0 is returned in legacy script, in Vim9
8394 script an error is given.
8395
8396 Can also be used as a |method|: >
8397 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008398<
8399 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008400
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008401 {only available when compiled with the |+reltime| feature}
8402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008403
8404reltimestr({time}) *reltimestr()*
8405 Return a String that represents the time value of {time}.
8406 This is the number of seconds, a dot and the number of
8407 microseconds. Example: >
8408 let start = reltime()
8409 call MyFunction()
8410 echo reltimestr(reltime(start))
8411< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008412 The accuracy depends on the system. Use reltimefloat() for the
8413 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008414 Leading spaces are used to make the string align nicely. You
8415 can use split() to remove it. >
8416 echo split(reltimestr(reltime(start)))[0]
8417< Also see |profiling|.
8418 If there is an error an empty string is returned in legacy
8419 script, in Vim9 script an error is given.
8420
8421 Can also be used as a |method|: >
8422 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008423<
8424 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008425
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008426 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008427
8428 *remote_expr()* *E449*
8429remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008430 Send the {string} to {server}. The {server} argument is a
8431 string, also see |{server}|.
8432
8433 The string is sent as an expression and the result is returned
8434 after evaluation. The result must be a String or a |List|. A
8435 |List| is turned into a String by joining the items with a
8436 line break in between (not at the end), like with join(expr,
8437 "\n").
8438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008439 If {idvar} is present and not empty, it is taken as the name
8440 of a variable and a {serverid} for later use with
8441 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008443 If {timeout} is given the read times out after this many
8444 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008446 See also |clientserver| |RemoteReply|.
8447 This function is not available in the |sandbox|.
8448 {only available when compiled with the |+clientserver| feature}
8449 Note: Any errors will cause a local error message to be issued
8450 and the result will be the empty string.
8451
8452 Variables will be evaluated in the global namespace,
8453 independent of a function currently being active. Except
8454 when in debug mode, then local function variables and
8455 arguments can be evaluated.
8456
8457 Examples: >
8458 :echo remote_expr("gvim", "2+2")
8459 :echo remote_expr("gvim1", "b:current_syntax")
8460<
8461 Can also be used as a |method|: >
8462 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008463<
8464 Return type: |String| or list<{type}>
8465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008466
8467remote_foreground({server}) *remote_foreground()*
8468 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008469 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008470 This works like: >
8471 remote_expr({server}, "foreground()")
8472< Except that on Win32 systems the client does the work, to work
8473 around the problem that the OS doesn't always allow the server
8474 to bring itself to the foreground.
8475 Note: This does not restore the window if it was minimized,
8476 like foreground() does.
8477 This function is not available in the |sandbox|.
8478
8479 Can also be used as a |method|: >
8480 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008481<
8482 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008483
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008484 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008485 Win32 console version}
8486
8487
8488remote_peek({serverid} [, {retvar}]) *remote_peek()*
8489 Returns a positive number if there are available strings
8490 from {serverid}. Copies any reply string into the variable
8491 {retvar} if specified. {retvar} must be a string with the
8492 name of a variable.
8493 Returns zero if none are available.
8494 Returns -1 if something is wrong.
8495 See also |clientserver|.
8496 This function is not available in the |sandbox|.
8497 {only available when compiled with the |+clientserver| feature}
8498 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008499 :let repl = ""
8500 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008501
8502< Can also be used as a |method|: >
8503 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008504<
8505 Return type: |Number|
8506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008507
8508remote_read({serverid}, [{timeout}]) *remote_read()*
8509 Return the oldest available reply from {serverid} and consume
8510 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008511 reply is available. Returns an empty string, if a reply is
8512 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008513 See also |clientserver|.
8514 This function is not available in the |sandbox|.
8515 {only available when compiled with the |+clientserver| feature}
8516 Example: >
8517 :echo remote_read(id)
8518
8519< Can also be used as a |method|: >
8520 ServerId()->remote_read()
8521<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008522 Return type: |String|
8523
8524
8525remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008526 Send the {string} to {server}. The {server} argument is a
8527 string, also see |{server}|.
8528
8529 The string is sent as input keys and the function returns
8530 immediately. At the Vim server the keys are not mapped
8531 |:map|.
8532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008533 If {idvar} is present, it is taken as the name of a variable
8534 and a {serverid} for later use with remote_read() is stored
8535 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008537 See also |clientserver| |RemoteReply|.
8538 This function is not available in the |sandbox|.
8539 {only available when compiled with the |+clientserver| feature}
8540
8541 Note: Any errors will be reported in the server and may mess
8542 up the display.
8543 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008544 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008545 \ remote_read(serverid)
8546
8547 :autocmd NONE RemoteReply *
8548 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008549 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008550 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8551<
8552 Can also be used as a |method|: >
8553 ServerName()->remote_send(keys)
8554<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008555 Return type: |String|
8556
8557
8558remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008559 Become the server {name}. {name} must be a non-empty string.
8560 This fails if already running as a server, when |v:servername|
8561 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008562
8563 Can also be used as a |method|: >
8564 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008565<
8566 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008568 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008570
8571remove({list}, {idx}) *remove()*
8572remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008573 Without {end}: Remove the item at {idx} from |List| {list} and
8574 return the item.
8575 With {end}: Remove items from {idx} to {end} (inclusive) and
8576 return a |List| with these items. When {idx} points to the same
8577 item as {end} a list with one item is returned. When {end}
8578 points to an item before {idx} this is an error.
8579 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008580 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008581 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008582 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008583 :call remove(mylist, 0, 9)
8584<
8585 Use |delete()| to remove a file.
8586
8587 Can also be used as a |method|: >
8588 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008589<
8590 Return type: any, depending on {list}
8591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008592
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008593remove({blob}, {idx})
8594remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008595 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8596 return the byte.
8597 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8598 return a |Blob| with these bytes. When {idx} points to the same
8599 byte as {end} a |Blob| with one byte is returned. When {end}
8600 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008601 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008602 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008603 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008604 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008605<
8606 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008607
8608remove({dict}, {key})
8609 Remove the entry from {dict} with key {key} and return it.
8610 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008611 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008612< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008613 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008614
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008615 Return type: any, depending on {dict}
8616
8617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008618rename({from}, {to}) *rename()*
8619 Rename the file by the name {from} to the name {to}. This
8620 should also work to move files across file systems. The
8621 result is a Number, which is 0 if the file was renamed
8622 successfully, and non-zero when the renaming failed.
8623 NOTE: If {to} exists it is overwritten without warning.
8624 This function is not available in the |sandbox|.
8625
8626 Can also be used as a |method|: >
8627 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008628<
8629 Return type: |Number|
8630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008631
8632repeat({expr}, {count}) *repeat()*
8633 Repeat {expr} {count} times and return the concatenated
8634 result. Example: >
8635 :let separator = repeat('-', 80)
8636< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008637 When {expr} is a |List| or a |Blob| the result is {expr}
8638 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008639 :let longlist = repeat(['a', 'b'], 3)
8640< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8641
8642 Can also be used as a |method|: >
8643 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008644<
8645 Return type: |String|, |Blob| or list<{type}> depending on
8646 {expr}
8647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008648
8649resolve({filename}) *resolve()* *E655*
8650 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8651 returns the path the shortcut points to in a simplified form.
8652 When {filename} is a symbolic link or junction point, return
8653 the full path to the target. If the target of junction is
8654 removed, return {filename}.
8655 On Unix, repeat resolving symbolic links in all path
8656 components of {filename} and return the simplified result.
8657 To cope with link cycles, resolving of symbolic links is
8658 stopped after 100 iterations.
8659 On other systems, return the simplified {filename}.
8660 The simplification step is done as by |simplify()|.
8661 resolve() keeps a leading path component specifying the
8662 current directory (provided the result is still a relative
8663 path name) and also keeps a trailing path separator.
8664
8665 Can also be used as a |method|: >
8666 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008667<
8668 Return type: |String|
8669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008670
8671reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008672 Reverse the order of items in {object}. {object} can be a
8673 |List|, a |Blob| or a |String|. For a List and a Blob the
8674 items are reversed in-place and {object} is returned.
8675 For a String a new String is returned.
8676 Returns zero if {object} is not a List, Blob or a String.
8677 If you want a List or Blob to remain unmodified make a copy
8678 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008679 :let revlist = reverse(copy(mylist))
8680< Can also be used as a |method|: >
8681 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008682<
8683 Return type: |String|, |Blob| or list<{type}> depending on
8684 {object}
8685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008686
8687round({expr}) *round()*
8688 Round off {expr} to the nearest integral value and return it
8689 as a |Float|. If {expr} lies halfway between two integral
8690 values, then use the larger one (away from zero).
8691 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008692 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008693 Examples: >
8694 echo round(0.456)
8695< 0.0 >
8696 echo round(4.5)
8697< 5.0 >
8698 echo round(-4.5)
8699< -5.0
8700
8701 Can also be used as a |method|: >
8702 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008703<
8704 Return type: |Float|
8705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008706
8707rubyeval({expr}) *rubyeval()*
8708 Evaluate Ruby expression {expr} and return its result
8709 converted to Vim data structures.
8710 Numbers, floats and strings are returned as they are (strings
8711 are copied though).
8712 Arrays are represented as Vim |List| type.
8713 Hashes are represented as Vim |Dictionary| type.
8714 Other objects are represented as strings resulted from their
8715 "Object#to_s" method.
8716 Note that in a `:def` function local variables are not visible
8717 to {expr}.
8718
8719 Can also be used as a |method|: >
8720 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008721<
8722 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008724 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008725
8726screenattr({row}, {col}) *screenattr()*
8727 Like |screenchar()|, but return the attribute. This is a rather
8728 arbitrary number that can only be used to compare to the
8729 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008730 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008731
8732 Can also be used as a |method|: >
8733 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008734<
8735 Return type: |Number|
8736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008737
8738screenchar({row}, {col}) *screenchar()*
8739 The result is a Number, which is the character at position
8740 [row, col] on the screen. This works for every possible
8741 screen position, also status lines, window separators and the
8742 command line. The top left position is row one, column one
8743 The character excludes composing characters. For double-byte
8744 encodings it may only be the first byte.
8745 This is mainly to be used for testing.
8746 Returns -1 when row or col is out of range.
8747
8748 Can also be used as a |method|: >
8749 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008750<
8751 Return type: |Number|
8752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008753
8754screenchars({row}, {col}) *screenchars()*
8755 The result is a |List| of Numbers. The first number is the same
8756 as what |screenchar()| returns. Further numbers are
8757 composing characters on top of the base character.
8758 This is mainly to be used for testing.
8759 Returns an empty List when row or col is out of range.
8760
8761 Can also be used as a |method|: >
8762 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008763<
8764 Return type: list<number> or list<any>
8765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008766
8767screencol() *screencol()*
8768 The result is a Number, which is the current screen column of
8769 the cursor. The leftmost column has number 1.
8770 This function is mainly used for testing.
8771
8772 Note: Always returns the current screen column, thus if used
8773 in a command (e.g. ":echo screencol()") it will return the
8774 column inside the command line, which is 1 when the command is
8775 executed. To get the cursor position in the file use one of
8776 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008777 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008778 nnoremap <silent> GG :echom screencol()<CR>
8779 nnoremap GG <Cmd>echom screencol()<CR>
8780<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008781 Return type: |Number|
8782
8783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008784screenpos({winid}, {lnum}, {col}) *screenpos()*
8785 The result is a Dict with the screen position of the text
8786 character in window {winid} at buffer line {lnum} and column
8787 {col}. {col} is a one-based byte index.
8788 The Dict has these members:
8789 row screen row
8790 col first screen column
8791 endcol last screen column
8792 curscol cursor screen column
8793 If the specified position is not visible, all values are zero.
8794 The "endcol" value differs from "col" when the character
8795 occupies more than one screen cell. E.g. for a Tab "col" can
8796 be 1 and "endcol" can be 8.
8797 The "curscol" value is where the cursor would be placed. For
8798 a Tab it would be the same as "endcol", while for a double
8799 width character it would be the same as "col".
8800 The |conceal| feature is ignored here, the column numbers are
8801 as if 'conceallevel' is zero. You can set the cursor to the
8802 right position and use |screencol()| to get the value with
8803 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008804 If the position is in a closed fold the screen position of the
8805 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008806 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008807
8808 Can also be used as a |method|: >
8809 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008810<
8811 Return type: dict<number> or dict<any>
8812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008813
8814screenrow() *screenrow()*
8815 The result is a Number, which is the current screen row of the
8816 cursor. The top line has number one.
8817 This function is mainly used for testing.
8818 Alternatively you can use |winline()|.
8819
8820 Note: Same restrictions as with |screencol()|.
8821
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008822 Return type: |Number|
8823
8824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008825screenstring({row}, {col}) *screenstring()*
8826 The result is a String that contains the base character and
8827 any composing characters at position [row, col] on the screen.
8828 This is like |screenchars()| but returning a String with the
8829 characters.
8830 This is mainly to be used for testing.
8831 Returns an empty String when row or col is out of range.
8832
8833 Can also be used as a |method|: >
8834 GetRow()->screenstring(col)
8835<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008836 Return type: |String|
8837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008838 *search()*
8839search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
8840 Search for regexp pattern {pattern}. The search starts at the
8841 cursor position (you can use |cursor()| to set it).
8842
8843 When a match has been found its line number is returned.
8844 If there is no match a 0 is returned and the cursor doesn't
8845 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01008846 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008847
8848 {flags} is a String, which can contain these character flags:
8849 'b' search Backward instead of forward
8850 'c' accept a match at the Cursor position
8851 'e' move to the End of the match
8852 'n' do Not move the cursor
8853 'p' return number of matching sub-Pattern (see below)
8854 's' Set the ' mark at the previous location of the cursor
8855 'w' Wrap around the end of the file
8856 'W' don't Wrap around the end of the file
8857 'z' start searching at the cursor column instead of zero
8858 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
8859
8860 If the 's' flag is supplied, the ' mark is set, only if the
8861 cursor is moved. The 's' flag cannot be combined with the 'n'
8862 flag.
8863
8864 'ignorecase', 'smartcase' and 'magic' are used.
8865
8866 When the 'z' flag is not given, forward searching always
8867 starts in column zero and then matches before the cursor are
8868 skipped. When the 'c' flag is present in 'cpo' the next
8869 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01008870 search starts one column after the start of the match. This
8871 matters for overlapping matches. See |cpo-c|. You can also
8872 insert "\ze" to change where the match ends, see |/\ze|.
8873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008874 When searching backwards and the 'z' flag is given then the
8875 search starts in column zero, thus no match in the current
8876 line will be found (unless wrapping around the end of the
8877 file).
8878
8879 When the {stopline} argument is given then the search stops
8880 after searching this line. This is useful to restrict the
8881 search to a range of lines. Examples: >
8882 let match = search('(', 'b', line("w0"))
8883 let end = search('END', '', line("w$"))
8884< When {stopline} is used and it is not zero this also implies
8885 that the search does not wrap around the end of the file.
8886 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01008887 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008888 When the {timeout} argument is given the search stops when
8889 more than this many milliseconds have passed. Thus when
8890 {timeout} is 500 the search stops after half a second.
8891 The value must not be negative. A zero value is like not
8892 giving the argument.
8893 {only available when compiled with the |+reltime| feature}
8894
8895 If the {skip} expression is given it is evaluated with the
8896 cursor positioned on the start of a match. If it evaluates to
8897 non-zero this match is skipped. This can be used, for
8898 example, to skip a match in a comment or a string.
8899 {skip} can be a string, which is evaluated as an expression, a
8900 function reference or a lambda.
8901 When {skip} is omitted or empty, every match is accepted.
8902 When evaluating {skip} causes an error the search is aborted
8903 and -1 returned.
8904 *search()-sub-match*
8905 With the 'p' flag the returned value is one more than the
8906 first sub-match in \(\). One if none of them matched but the
8907 whole pattern did match.
8908 To get the column number too use |searchpos()|.
8909
8910 The cursor will be positioned at the match, unless the 'n'
8911 flag is used.
8912
8913 Example (goes over all files in the argument list): >
8914 :let n = 1
8915 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008916 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008917 : " start at the last char in the file and wrap for the
8918 : " first search to find match at start of file
8919 : normal G$
8920 : let flags = "w"
8921 : while search("foo", flags) > 0
8922 : s/foo/bar/g
8923 : let flags = "W"
8924 : endwhile
8925 : update " write the file if modified
8926 : let n = n + 1
8927 :endwhile
8928<
8929 Example for using some flags: >
8930 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
8931< This will search for the keywords "if", "else", and "endif"
8932 under or after the cursor. Because of the 'p' flag, it
8933 returns 1, 2, or 3 depending on which keyword is found, or 0
8934 if the search fails. With the cursor on the first word of the
8935 line:
8936 if (foo == 0) | let foo = foo + 1 | endif ~
8937 the function returns 1. Without the 'c' flag, the function
8938 finds the "endif" and returns 3. The same thing happens
8939 without the 'e' flag if the cursor is on the "f" of "if".
8940 The 'n' flag tells the function not to move the cursor.
8941
8942 Can also be used as a |method|: >
8943 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008944<
8945 Return type: |Number|
8946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008947
8948searchcount([{options}]) *searchcount()*
8949 Get or update the last search count, like what is displayed
8950 without the "S" flag in 'shortmess'. This works even if
8951 'shortmess' does contain the "S" flag.
8952
8953 This returns a |Dictionary|. The dictionary is empty if the
8954 previous pattern was not set and "pattern" was not specified.
8955
8956 key type meaning ~
8957 current |Number| current position of match;
8958 0 if the cursor position is
8959 before the first match
8960 exact_match |Boolean| 1 if "current" is matched on
8961 "pos", otherwise 0
8962 total |Number| total count of matches found
8963 incomplete |Number| 0: search was fully completed
8964 1: recomputing was timed out
8965 2: max count exceeded
8966
8967 For {options} see further down.
8968
8969 To get the last search count when |n| or |N| was pressed, call
8970 this function with `recompute: 0` . This sometimes returns
8971 wrong information because |n| and |N|'s maximum count is 99.
8972 If it exceeded 99 the result must be max count + 1 (100). If
8973 you want to get correct information, specify `recompute: 1`: >
8974
8975 " result == maxcount + 1 (100) when many matches
8976 let result = searchcount(#{recompute: 0})
8977
8978 " Below returns correct result (recompute defaults
8979 " to 1)
8980 let result = searchcount()
8981<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01008982 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008983 function! LastSearchCount() abort
8984 let result = searchcount(#{recompute: 0})
8985 if empty(result)
8986 return ''
8987 endif
8988 if result.incomplete ==# 1 " timed out
8989 return printf(' /%s [?/??]', @/)
8990 elseif result.incomplete ==# 2 " max count exceeded
8991 if result.total > result.maxcount &&
8992 \ result.current > result.maxcount
8993 return printf(' /%s [>%d/>%d]', @/,
8994 \ result.current, result.total)
8995 elseif result.total > result.maxcount
8996 return printf(' /%s [%d/>%d]', @/,
8997 \ result.current, result.total)
8998 endif
8999 endif
9000 return printf(' /%s [%d/%d]', @/,
9001 \ result.current, result.total)
9002 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009003 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009004
9005 " Or if you want to show the count only when
9006 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009007 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009008 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9009<
9010 You can also update the search count, which can be useful in a
9011 |CursorMoved| or |CursorMovedI| autocommand: >
9012
9013 autocmd CursorMoved,CursorMovedI *
9014 \ let s:searchcount_timer = timer_start(
9015 \ 200, function('s:update_searchcount'))
9016 function! s:update_searchcount(timer) abort
9017 if a:timer ==# s:searchcount_timer
9018 call searchcount(#{
9019 \ recompute: 1, maxcount: 0, timeout: 100})
9020 redrawstatus
9021 endif
9022 endfunction
9023<
9024 This can also be used to count matched texts with specified
9025 pattern in the current buffer using "pattern": >
9026
9027 " Count '\<foo\>' in this buffer
9028 " (Note that it also updates search count)
9029 let result = searchcount(#{pattern: '\<foo\>'})
9030
9031 " To restore old search count by old pattern,
9032 " search again
9033 call searchcount()
9034<
9035 {options} must be a |Dictionary|. It can contain:
9036 key type meaning ~
9037 recompute |Boolean| if |TRUE|, recompute the count
9038 like |n| or |N| was executed.
9039 otherwise returns the last
9040 computed result (when |n| or
9041 |N| was used when "S" is not
9042 in 'shortmess', or this
9043 function was called).
9044 (default: |TRUE|)
9045 pattern |String| recompute if this was given
9046 and different with |@/|.
9047 this works as same as the
9048 below command is executed
9049 before calling this function >
9050 let @/ = pattern
9051< (default: |@/|)
9052 timeout |Number| 0 or negative number is no
9053 timeout. timeout milliseconds
9054 for recomputing the result
9055 (default: 0)
9056 maxcount |Number| 0 or negative number is no
9057 limit. max count of matched
9058 text while recomputing the
9059 result. if search exceeded
9060 total count, "total" value
9061 becomes `maxcount + 1`
9062 (default: 99)
9063 pos |List| `[lnum, col, off]` value
9064 when recomputing the result.
9065 this changes "current" result
9066 value. see |cursor()|,
9067 |getpos()|
9068 (default: cursor's position)
9069
9070 Can also be used as a |method|: >
9071 GetSearchOpts()->searchcount()
9072<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009073 Return type: dict<number>
9074
9075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009076searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9077 Search for the declaration of {name}.
9078
9079 With a non-zero {global} argument it works like |gD|, find
9080 first match in the file. Otherwise it works like |gd|, find
9081 first match in the function.
9082
9083 With a non-zero {thisblock} argument matches in a {} block
9084 that ends before the cursor position are ignored. Avoids
9085 finding variable declarations only valid in another scope.
9086
9087 Moves the cursor to the found match.
9088 Returns zero for success, non-zero for failure.
9089 Example: >
9090 if searchdecl('myvar') == 0
9091 echo getline('.')
9092 endif
9093<
9094 Can also be used as a |method|: >
9095 GetName()->searchdecl()
9096<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009097 Return type: |Number|
9098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009099 *searchpair()*
9100searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9101 [, {stopline} [, {timeout}]]]])
9102 Search for the match of a nested start-end pair. This can be
9103 used to find the "endif" that matches an "if", while other
9104 if/endif pairs in between are ignored.
9105 The search starts at the cursor. The default is to search
9106 forward, include 'b' in {flags} to search backward.
9107 If a match is found, the cursor is positioned at it and the
9108 line number is returned. If no match is found 0 or -1 is
9109 returned and the cursor doesn't move. No error message is
9110 given.
9111
9112 {start}, {middle} and {end} are patterns, see |pattern|. They
9113 must not contain \( \) pairs. Use of \%( \) is allowed. When
9114 {middle} is not empty, it is found when searching from either
9115 direction, but only when not in a nested start-end pair. A
9116 typical use is: >
9117 searchpair('\<if\>', '\<else\>', '\<endif\>')
9118< By leaving {middle} empty the "else" is skipped.
9119
9120 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9121 |search()|. Additionally:
9122 'r' Repeat until no more matches found; will find the
9123 outer pair. Implies the 'W' flag.
9124 'm' Return number of matches instead of line number with
9125 the match; will be > 1 when 'r' is used.
9126 Note: it's nearly always a good idea to use the 'W' flag, to
9127 avoid wrapping around the end of the file.
9128
9129 When a match for {start}, {middle} or {end} is found, the
9130 {skip} expression is evaluated with the cursor positioned on
9131 the start of the match. It should return non-zero if this
9132 match is to be skipped. E.g., because it is inside a comment
9133 or a string.
9134 When {skip} is omitted or empty, every match is accepted.
9135 When evaluating {skip} causes an error the search is aborted
9136 and -1 returned.
9137 {skip} can be a string, a lambda, a funcref or a partial.
9138 Anything else makes the function fail.
9139 In a `:def` function when the {skip} argument is a string
9140 constant it is compiled into instructions.
9141
9142 For {stopline} and {timeout} see |search()|.
9143
9144 The value of 'ignorecase' is used. 'magic' is ignored, the
9145 patterns are used like it's on.
9146
9147 The search starts exactly at the cursor. A match with
9148 {start}, {middle} or {end} at the next character, in the
9149 direction of searching, is the first one found. Example: >
9150 if 1
9151 if 2
9152 endif 2
9153 endif 1
9154< When starting at the "if 2", with the cursor on the "i", and
9155 searching forwards, the "endif 2" is found. When starting on
9156 the character just before the "if 2", the "endif 1" will be
9157 found. That's because the "if 2" will be found first, and
9158 then this is considered to be a nested if/endif from "if 2" to
9159 "endif 2".
9160 When searching backwards and {end} is more than one character,
9161 it may be useful to put "\zs" at the end of the pattern, so
9162 that when the cursor is inside a match with the end it finds
9163 the matching start.
9164
9165 Example, to find the "endif" command in a Vim script: >
9166
9167 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9168 \ 'getline(".") =~ "^\\s*\""')
9169
9170< The cursor must be at or after the "if" for which a match is
9171 to be found. Note that single-quote strings are used to avoid
9172 having to double the backslashes. The skip expression only
9173 catches comments at the start of a line, not after a command.
9174 Also, a word "en" or "if" halfway a line is considered a
9175 match.
9176 Another example, to search for the matching "{" of a "}": >
9177
9178 :echo searchpair('{', '', '}', 'bW')
9179
9180< This works when the cursor is at or before the "}" for which a
9181 match is to be found. To reject matches that syntax
9182 highlighting recognized as strings: >
9183
9184 :echo searchpair('{', '', '}', 'bW',
9185 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9186<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009187 Return type: |Number|
9188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009189 *searchpairpos()*
9190searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9191 [, {stopline} [, {timeout}]]]])
9192 Same as |searchpair()|, but returns a |List| with the line and
9193 column position of the match. The first element of the |List|
9194 is the line number and the second element is the byte index of
9195 the column position of the match. If no match is found,
9196 returns [0, 0]. >
9197
9198 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9199<
9200 See |match-parens| for a bigger and more useful example.
9201
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009202 Return type: list<number>
9203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009204 *searchpos()*
9205searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9206 Same as |search()|, but returns a |List| with the line and
9207 column position of the match. The first element of the |List|
9208 is the line number and the second element is the byte index of
9209 the column position of the match. If no match is found,
9210 returns [0, 0].
9211 Example: >
9212 :let [lnum, col] = searchpos('mypattern', 'n')
9213
9214< When the 'p' flag is given then there is an extra item with
9215 the sub-pattern match number |search()-sub-match|. Example: >
9216 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9217< In this example "submatch" is 2 when a lowercase letter is
9218 found |/\l|, 3 when an uppercase letter is found |/\u|.
9219
9220 Can also be used as a |method|: >
9221 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009222<
9223 Return type: list<number>
9224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009225
9226server2client({clientid}, {string}) *server2client()*
9227 Send a reply string to {clientid}. The most recent {clientid}
9228 that sent a string can be retrieved with expand("<client>").
9229 {only available when compiled with the |+clientserver| feature}
9230 Returns zero for success, -1 for failure.
9231 Note:
9232 This id has to be stored before the next command can be
9233 received. I.e. before returning from the received command and
9234 before calling any commands that waits for input.
9235 See also |clientserver|.
9236 Example: >
9237 :echo server2client(expand("<client>"), "HELLO")
9238
9239< Can also be used as a |method|: >
9240 GetClientId()->server2client(string)
9241<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009242 Return type: |Number|
9243
9244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009245serverlist() *serverlist()*
9246 Return a list of available server names, one per line.
9247 When there are no servers or the information is not available
9248 an empty string is returned. See also |clientserver|.
9249 {only available when compiled with the |+clientserver| feature}
9250 Example: >
9251 :echo serverlist()
9252<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009253 Return type: |String|
9254
9255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009256setbufline({buf}, {lnum}, {text}) *setbufline()*
9257 Set line {lnum} to {text} in buffer {buf}. This works like
9258 |setline()| for the specified buffer.
9259
9260 This function works only for loaded buffers. First call
9261 |bufload()| if needed.
9262
9263 To insert lines use |appendbufline()|.
9264 Any text properties in {lnum} are cleared.
9265
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009266 {text} can be a string to set one line, or a List of strings
9267 to set multiple lines. If the List extends below the last
9268 line then those lines are added. If the List is empty then
9269 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009270
9271 For the use of {buf}, see |bufname()| above.
9272
9273 {lnum} is used like with |setline()|.
9274 Use "$" to refer to the last line in buffer {buf}.
9275 When {lnum} is just below the last line the {text} will be
9276 added below the last line.
9277
9278 When {buf} is not a valid buffer, the buffer is not loaded or
9279 {lnum} is not valid then 1 is returned. In |Vim9| script an
9280 error is given.
9281 On success 0 is returned.
9282
9283 Can also be used as a |method|, the base is passed as the
9284 third argument: >
9285 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009286<
9287 Return type: |Number|
9288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009289
9290setbufvar({buf}, {varname}, {val}) *setbufvar()*
9291 Set option or local variable {varname} in buffer {buf} to
9292 {val}.
9293 This also works for a global or local window option, but it
9294 doesn't work for a global or local window variable.
9295 For a local window option the global value is unchanged.
9296 For the use of {buf}, see |bufname()| above.
9297 The {varname} argument is a string.
9298 Note that the variable name without "b:" must be used.
9299 Examples: >
9300 :call setbufvar(1, "&mod", 1)
9301 :call setbufvar("todo", "myvar", "foobar")
9302< This function is not available in the |sandbox|.
9303
9304 Can also be used as a |method|, the base is passed as the
9305 third argument: >
9306 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009307<
9308 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009309
9310
9311setcellwidths({list}) *setcellwidths()*
9312 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009313 tells Vim how wide characters are when displayed in the
9314 terminal, counted in screen cells. The values override
9315 'ambiwidth'. Example: >
9316 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009317 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009318 \ [0x2194, 0x2199, 2],
9319 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009320
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009321< The {list} argument is a List of Lists with each three
9322 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9323 {low} and {high} can be the same, in which case this refers to
9324 one character. Otherwise it is the range of characters from
9325 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009326 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009327
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009328 {width} must be either 1 or 2, indicating the character width
9329 in screen cells. *E1112*
9330 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009331 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009333 If the new value causes 'fillchars' or 'listchars' to become
9334 invalid it is rejected and an error is given.
9335
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009336 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009337 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009340 the effect for known emoji characters. Move the cursor
9341 through the text to check if the cell widths of your terminal
9342 match with what Vim knows about each emoji. If it doesn't
9343 look right you need to adjust the {list} argument.
9344
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009345 Return type: |Number|
9346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009347
9348setcharpos({expr}, {list}) *setcharpos()*
9349 Same as |setpos()| but uses the specified column number as the
9350 character index instead of the byte index in the line.
9351
9352 Example:
9353 With the text "여보세요" in line 8: >
9354 call setcharpos('.', [0, 8, 4, 0])
9355< positions the cursor on the fourth character '요'. >
9356 call setpos('.', [0, 8, 4, 0])
9357< positions the cursor on the second character '보'.
9358
9359 Can also be used as a |method|: >
9360 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009361<
9362 Return type: |Number|
9363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009364
9365setcharsearch({dict}) *setcharsearch()*
9366 Set the current character search information to {dict},
9367 which contains one or more of the following entries:
9368
9369 char character which will be used for a subsequent
9370 |,| or |;| command; an empty string clears the
9371 character search
9372 forward direction of character search; 1 for forward,
9373 0 for backward
9374 until type of character search; 1 for a |t| or |T|
9375 character search, 0 for an |f| or |F|
9376 character search
9377
9378 This can be useful to save/restore a user's character search
9379 from a script: >
9380 :let prevsearch = getcharsearch()
9381 :" Perform a command which clobbers user's search
9382 :call setcharsearch(prevsearch)
9383< Also see |getcharsearch()|.
9384
9385 Can also be used as a |method|: >
9386 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009387<
9388 Return type: dict<any>
9389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009390
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009391setcmdline({str} [, {pos}]) *setcmdline()*
9392 Set the command line to {str} and set the cursor position to
9393 {pos}.
9394 If {pos} is omitted, the cursor is positioned after the text.
9395 Returns 0 when successful, 1 when not editing the command
9396 line.
9397
9398 Can also be used as a |method|: >
9399 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009400<
9401 Return type: |Number|
9402
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009404setcmdpos({pos}) *setcmdpos()*
9405 Set the cursor position in the command line to byte position
9406 {pos}. The first position is 1.
9407 Use |getcmdpos()| to obtain the current position.
9408 Only works while editing the command line, thus you must use
9409 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9410 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9411 set after the command line is set to the expression. For
9412 |c_CTRL-R_=| it is set after evaluating the expression but
9413 before inserting the resulting text.
9414 When the number is too big the cursor is put at the end of the
9415 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009416 Returns 0 when successful, 1 when not editing the command
9417 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009418
9419 Can also be used as a |method|: >
9420 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009421<
9422 Return type: |Number|
9423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009424
9425setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9426setcursorcharpos({list})
9427 Same as |cursor()| but uses the specified column number as the
9428 character index instead of the byte index in the line.
9429
9430 Example:
9431 With the text "여보세요" in line 4: >
9432 call setcursorcharpos(4, 3)
9433< positions the cursor on the third character '세'. >
9434 call cursor(4, 3)
9435< positions the cursor on the first character '여'.
9436
9437 Can also be used as a |method|: >
9438 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009439<
9440 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009441
9442
9443setenv({name}, {val}) *setenv()*
9444 Set environment variable {name} to {val}. Example: >
9445 call setenv('HOME', '/home/myhome')
9446
9447< When {val} is |v:null| the environment variable is deleted.
9448 See also |expr-env|.
9449
9450 Can also be used as a |method|, the base is passed as the
9451 second argument: >
9452 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009453<
9454 Return type: |Number|
9455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009456
9457setfperm({fname}, {mode}) *setfperm()* *chmod*
9458 Set the file permissions for {fname} to {mode}.
9459 {mode} must be a string with 9 characters. It is of the form
9460 "rwxrwxrwx", where each group of "rwx" flags represent, in
9461 turn, the permissions of the owner of the file, the group the
9462 file belongs to, and other users. A '-' character means the
9463 permission is off, any other character means on. Multi-byte
9464 characters are not supported.
9465
9466 For example "rw-r-----" means read-write for the user,
9467 readable by the group, not accessible by others. "xx-x-----"
9468 would do the same thing.
9469
9470 Returns non-zero for success, zero for failure.
9471
9472 Can also be used as a |method|: >
9473 GetFilename()->setfperm(mode)
9474<
9475 To read permissions see |getfperm()|.
9476
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009477 Return type: |Number|
9478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009479
9480setline({lnum}, {text}) *setline()*
9481 Set line {lnum} of the current buffer to {text}. To insert
9482 lines use |append()|. To set lines in another buffer use
9483 |setbufline()|. Any text properties in {lnum} are cleared.
9484
9485 {lnum} is used like with |getline()|.
9486 When {lnum} is just below the last line the {text} will be
9487 added below the last line.
9488 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009489 converted to a String. When {text} is an empty List then
9490 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009491
9492 If this succeeds, FALSE is returned. If this fails (most likely
9493 because {lnum} is invalid) TRUE is returned.
9494 In |Vim9| script an error is given if {lnum} is invalid.
9495
9496 Example: >
9497 :call setline(5, strftime("%c"))
9498
9499< When {text} is a |List| then line {lnum} and following lines
9500 will be set to the items in the list. Example: >
9501 :call setline(5, ['aaa', 'bbb', 'ccc'])
9502< This is equivalent to: >
9503 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9504 : call setline(n, l)
9505 :endfor
9506
9507< Note: The '[ and '] marks are not set.
9508
9509 Can also be used as a |method|, the base is passed as the
9510 second argument: >
9511 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009512<
9513 Return type: |Number|
9514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009515
9516setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9517 Create or replace or add to the location list for window {nr}.
9518 {nr} can be the window number or the |window-ID|.
9519 When {nr} is zero the current window is used.
9520
9521 For a location list window, the displayed location list is
9522 modified. For an invalid window number {nr}, -1 is returned.
9523 Otherwise, same as |setqflist()|.
9524 Also see |location-list|.
9525
9526 For {action} see |setqflist-action|.
9527
9528 If the optional {what} dictionary argument is supplied, then
9529 only the items listed in {what} are set. Refer to |setqflist()|
9530 for the list of supported keys in {what}.
9531
9532 Can also be used as a |method|, the base is passed as the
9533 second argument: >
9534 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009535<
9536 Return type: |Number|
9537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009538
9539setmatches({list} [, {win}]) *setmatches()*
9540 Restores a list of matches saved by |getmatches()| for the
9541 current window. Returns 0 if successful, otherwise -1. All
9542 current matches are cleared before the list is restored. See
9543 example for |getmatches()|.
9544 If {win} is specified, use the window with this number or
9545 window ID instead of the current window.
9546
9547 Can also be used as a |method|: >
9548 GetMatches()->setmatches()
9549<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009550 Return type: |Number|
9551
9552
9553setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009554 Set the position for String {expr}. Possible values:
9555 . the cursor
9556 'x mark x
9557
9558 {list} must be a |List| with four or five numbers:
9559 [bufnum, lnum, col, off]
9560 [bufnum, lnum, col, off, curswant]
9561
9562 "bufnum" is the buffer number. Zero can be used for the
9563 current buffer. When setting an uppercase mark "bufnum" is
9564 used for the mark position. For other marks it specifies the
9565 buffer to set the mark in. You can use the |bufnr()| function
9566 to turn a file name into a buffer number.
9567 For setting the cursor and the ' mark "bufnum" is ignored,
9568 since these are associated with a window, not a buffer.
9569 Does not change the jumplist.
9570
9571 "lnum" and "col" are the position in the buffer. The first
9572 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9573 smaller than 1 then 1 is used. To use the character count
9574 instead of the byte count, use |setcharpos()|.
9575
9576 The "off" number is only used when 'virtualedit' is set. Then
9577 it is the offset in screen columns from the start of the
9578 character. E.g., a position within a <Tab> or after the last
9579 character.
9580
9581 The "curswant" number is only used when setting the cursor
9582 position. It sets the preferred column for when moving the
9583 cursor vertically. When the "curswant" number is missing the
9584 preferred column is not set. When it is present and setting a
9585 mark position it is not used.
9586
9587 Note that for '< and '> changing the line number may result in
9588 the marks to be effectively be swapped, so that '< is always
9589 before '>.
9590
9591 Returns 0 when the position could be set, -1 otherwise.
9592 An error message is given if {expr} is invalid.
9593
9594 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9595
9596 This does not restore the preferred column for moving
9597 vertically; if you set the cursor position with this, |j| and
9598 |k| motions will jump to previous columns! Use |cursor()| to
9599 also set the preferred column. Also see the "curswant" key in
9600 |winrestview()|.
9601
9602 Can also be used as a |method|: >
9603 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009604<
9605 Return type: |Number|
9606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009607
9608setqflist({list} [, {action} [, {what}]]) *setqflist()*
9609 Create or replace or add to the quickfix list.
9610
9611 If the optional {what} dictionary argument is supplied, then
9612 only the items listed in {what} are set. The first {list}
9613 argument is ignored. See below for the supported items in
9614 {what}.
9615 *setqflist-what*
9616 When {what} is not present, the items in {list} are used. Each
9617 item must be a dictionary. Non-dictionary items in {list} are
9618 ignored. Each dictionary item can contain the following
9619 entries:
9620
9621 bufnr buffer number; must be the number of a valid
9622 buffer
9623 filename name of a file; only used when "bufnr" is not
9624 present or it is invalid.
9625 module name of a module; if given it will be used in
9626 quickfix error window instead of the filename.
9627 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009628 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009629 pattern search pattern used to locate the error
9630 col column number
9631 vcol when non-zero: "col" is visual column
9632 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009633 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009634 nr error number
9635 text description of the error
9636 type single-character error type, 'E', 'W', etc.
9637 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009638 user_data custom data associated with the item, can be
9639 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009640
9641 The "col", "vcol", "nr", "type" and "text" entries are
9642 optional. Either "lnum" or "pattern" entry can be used to
9643 locate a matching error line.
9644 If the "filename" and "bufnr" entries are not present or
9645 neither the "lnum" or "pattern" entries are present, then the
9646 item will not be handled as an error line.
9647 If both "pattern" and "lnum" are present then "pattern" will
9648 be used.
9649 If the "valid" entry is not supplied, then the valid flag is
9650 set when "bufnr" is a valid buffer or "filename" exists.
9651 If you supply an empty {list}, the quickfix list will be
9652 cleared.
9653 Note that the list is not exactly the same as what
9654 |getqflist()| returns.
9655
9656 {action} values: *setqflist-action* *E927*
9657 'a' The items from {list} are added to the existing
9658 quickfix list. If there is no existing list, then a
9659 new list is created.
9660
9661 'r' The items from the current quickfix list are replaced
9662 with the items from {list}. This can also be used to
9663 clear the list: >
9664 :call setqflist([], 'r')
9665<
9666 'f' All the quickfix lists in the quickfix stack are
9667 freed.
9668
9669 If {action} is not present or is set to ' ', then a new list
9670 is created. The new quickfix list is added after the current
9671 quickfix list in the stack and all the following lists are
9672 freed. To add a new quickfix list at the end of the stack,
9673 set "nr" in {what} to "$".
9674
9675 The following items can be specified in dictionary {what}:
9676 context quickfix list context. See |quickfix-context|
9677 efm errorformat to use when parsing text from
9678 "lines". If this is not present, then the
9679 'errorformat' option value is used.
9680 See |quickfix-parse|
9681 id quickfix list identifier |quickfix-ID|
9682 idx index of the current entry in the quickfix
9683 list specified by 'id' or 'nr'. If set to '$',
9684 then the last entry in the list is set as the
9685 current entry. See |quickfix-index|
9686 items list of quickfix entries. Same as the {list}
9687 argument.
9688 lines use 'errorformat' to parse a list of lines and
9689 add the resulting entries to the quickfix list
9690 {nr} or {id}. Only a |List| value is supported.
9691 See |quickfix-parse|
9692 nr list number in the quickfix stack; zero
9693 means the current quickfix list and "$" means
9694 the last quickfix list.
9695 quickfixtextfunc
9696 function to get the text to display in the
9697 quickfix window. The value can be the name of
9698 a function or a funcref or a lambda. Refer to
9699 |quickfix-window-function| for an explanation
9700 of how to write the function and an example.
9701 title quickfix list title text. See |quickfix-title|
9702 Unsupported keys in {what} are ignored.
9703 If the "nr" item is not present, then the current quickfix list
9704 is modified. When creating a new quickfix list, "nr" can be
9705 set to a value one greater than the quickfix stack size.
9706 When modifying a quickfix list, to guarantee that the correct
9707 list is modified, "id" should be used instead of "nr" to
9708 specify the list.
9709
9710 Examples (See also |setqflist-examples|): >
9711 :call setqflist([], 'r', {'title': 'My search'})
9712 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9713 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9714<
9715 Returns zero for success, -1 for failure.
9716
9717 This function can be used to create a quickfix list
9718 independent of the 'errorformat' setting. Use a command like
9719 `:cc 1` to jump to the first position.
9720
9721 Can also be used as a |method|, the base is passed as the
9722 second argument: >
9723 GetErrorlist()->setqflist()
9724<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009725 Return type: |Number|
9726
9727
9728setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009729 Set the register {regname} to {value}.
9730 If {regname} is "" or "@", the unnamed register '"' is used.
9731 The {regname} argument is a string. In |Vim9-script|
9732 {regname} must be one character.
9733
9734 {value} may be any value returned by |getreg()| or
9735 |getreginfo()|, including a |List| or |Dict|.
9736 If {options} contains "a" or {regname} is upper case,
9737 then the value is appended.
9738
9739 {options} can also contain a register type specification:
9740 "c" or "v" |characterwise| mode
9741 "l" or "V" |linewise| mode
9742 "b" or "<CTRL-V>" |blockwise-visual| mode
9743 If a number immediately follows "b" or "<CTRL-V>" then this is
9744 used as the width of the selection - if it is not specified
9745 then the width of the block is set to the number of characters
9746 in the longest line (counting a <Tab> as 1 character).
9747
9748 If {options} contains no register settings, then the default
9749 is to use character mode unless {value} ends in a <NL> for
9750 string {value} and linewise mode for list {value}. Blockwise
9751 mode is never selected automatically.
9752 Returns zero for success, non-zero for failure.
9753
9754 *E883*
9755 Note: you may not use |List| containing more than one item to
9756 set search and expression registers. Lists containing no
9757 items act like empty strings.
9758
9759 Examples: >
9760 :call setreg(v:register, @*)
9761 :call setreg('*', @%, 'ac')
9762 :call setreg('a', "1\n2\n3", 'b5')
9763 :call setreg('"', { 'points_to': 'a'})
9764
9765< This example shows using the functions to save and restore a
9766 register: >
9767 :let var_a = getreginfo()
9768 :call setreg('a', var_a)
9769< or: >
9770 :let var_a = getreg('a', 1, 1)
9771 :let var_amode = getregtype('a')
9772 ....
9773 :call setreg('a', var_a, var_amode)
9774< Note: you may not reliably restore register value
9775 without using the third argument to |getreg()| as without it
9776 newlines are represented as newlines AND Nul bytes are
9777 represented as newlines as well, see |NL-used-for-Nul|.
9778
9779 You can also change the type of a register by appending
9780 nothing: >
9781 :call setreg('a', '', 'al')
9782
9783< Can also be used as a |method|, the base is passed as the
9784 second argument: >
9785 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009786<
9787 Return type: |Number|
9788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009789
9790settabvar({tabnr}, {varname}, {val}) *settabvar()*
9791 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9792 |t:var|
9793 The {varname} argument is a string.
9794 Note that autocommands are blocked, side effects may not be
9795 triggered, e.g. when setting 'filetype'.
9796 Note that the variable name without "t:" must be used.
9797 Tabs are numbered starting with one.
9798 This function is not available in the |sandbox|.
9799
9800 Can also be used as a |method|, the base is passed as the
9801 third argument: >
9802 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009803<
9804 Return type: |Number|
9805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009806
9807settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9808 Set option or local variable {varname} in window {winnr} to
9809 {val}.
9810 Tabs are numbered starting with one. For the current tabpage
9811 use |setwinvar()|.
9812 {winnr} can be the window number or the |window-ID|.
9813 When {winnr} is zero the current window is used.
9814 Note that autocommands are blocked, side effects may not be
9815 triggered, e.g. when setting 'filetype' or 'syntax'.
9816 This also works for a global or local buffer option, but it
9817 doesn't work for a global or local buffer variable.
9818 For a local buffer option the global value is unchanged.
9819 Note that the variable name without "w:" must be used.
9820 Examples: >
9821 :call settabwinvar(1, 1, "&list", 0)
9822 :call settabwinvar(3, 2, "myvar", "foobar")
9823< This function is not available in the |sandbox|.
9824
9825 Can also be used as a |method|, the base is passed as the
9826 fourth argument: >
9827 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009828<
9829 Return type: |Number|
9830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009831
9832settagstack({nr}, {dict} [, {action}]) *settagstack()*
9833 Modify the tag stack of the window {nr} using {dict}.
9834 {nr} can be the window number or the |window-ID|.
9835
9836 For a list of supported items in {dict}, refer to
9837 |gettagstack()|. "curidx" takes effect before changing the tag
9838 stack.
9839 *E962*
9840 How the tag stack is modified depends on the {action}
9841 argument:
9842 - If {action} is not present or is set to 'r', then the tag
9843 stack is replaced.
9844 - If {action} is set to 'a', then new entries from {dict} are
9845 pushed (added) onto the tag stack.
9846 - If {action} is set to 't', then all the entries from the
9847 current entry in the tag stack or "curidx" in {dict} are
9848 removed and then new entries are pushed to the stack.
9849
9850 The current index is set to one after the length of the tag
9851 stack after the modification.
9852
9853 Returns zero for success, -1 for failure.
9854
9855 Examples (for more examples see |tagstack-examples|):
9856 Empty the tag stack of window 3: >
9857 call settagstack(3, {'items' : []})
9858
9859< Save and restore the tag stack: >
9860 let stack = gettagstack(1003)
9861 " do something else
9862 call settagstack(1003, stack)
9863 unlet stack
9864<
9865 Can also be used as a |method|, the base is passed as the
9866 second argument: >
9867 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009868<
9869 Return type: |Number|
9870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009871
9872setwinvar({winnr}, {varname}, {val}) *setwinvar()*
9873 Like |settabwinvar()| for the current tab page.
9874 Examples: >
9875 :call setwinvar(1, "&list", 0)
9876 :call setwinvar(2, "myvar", "foobar")
9877
9878< Can also be used as a |method|, the base is passed as the
9879 third argument: >
9880 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009881<
9882 Return type: |Number|
9883
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009884
9885sha256({string}) *sha256()*
9886 Returns a String with 64 hex characters, which is the SHA256
9887 checksum of {string}.
9888
9889 Can also be used as a |method|: >
9890 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009891<
9892 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009893
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009894 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009895
9896shellescape({string} [, {special}]) *shellescape()*
9897 Escape {string} for use as a shell command argument.
9898 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +00009899 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009900 in single quotes and will double up all internal single
9901 quotes.
9902 On MS-Windows, when 'shellslash' is not set, it will enclose
9903 {string} in double quotes and double all double quotes within
9904 {string}.
9905 Otherwise it will enclose {string} in single quotes and
9906 replace all "'" with "'\''".
9907
Enno5faeb602024-05-15 21:54:19 +02009908 The {special} argument adds additional escaping of keywords
9909 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +09009910 number or a non-empty String (|non-zero-arg|), then special
9911 items such as "!", "%", "#" and "<cword>" (as listed in
9912 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +02009913 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009914
9915 The "!" character will be escaped (again with a |non-zero-arg|
9916 {special}) when 'shell' contains "csh" in the tail. That is
9917 because for csh and tcsh "!" is used for history replacement
9918 even when inside single quotes.
9919
9920 With a |non-zero-arg| {special} the <NL> character is also
9921 escaped. When 'shell' containing "csh" in the tail it's
9922 escaped a second time.
9923
9924 The "\" character will be escaped when 'shell' contains "fish"
9925 in the tail. That is because for fish "\" is used as an escape
9926 character inside single quotes.
9927
9928 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009929 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009930< This results in a directory listing for the file under the
9931 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009932 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009933< See also |::S|.
9934
9935 Can also be used as a |method|: >
9936 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009937<
9938 Return type: |String|
9939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009940
9941shiftwidth([{col}]) *shiftwidth()*
9942 Returns the effective value of 'shiftwidth'. This is the
9943 'shiftwidth' value unless it is zero, in which case it is the
9944 'tabstop' value. This function was introduced with patch
9945 7.3.694 in 2012, everybody should have it by now (however it
9946 did not allow for the optional {col} argument until 8.1.542).
9947
9948 When there is one argument {col} this is used as column number
9949 for which to return the 'shiftwidth' value. This matters for the
9950 'vartabstop' feature. If the 'vartabstop' setting is enabled and
9951 no {col} argument is given, column 1 will be assumed.
9952
9953 Can also be used as a |method|: >
9954 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009955<
9956 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009957
9958sign_ functions are documented here: |sign-functions-details|
9959
9960
9961simplify({filename}) *simplify()*
9962 Simplify the file name as much as possible without changing
9963 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
9964 Unix) are not resolved. If the first path component in
9965 {filename} designates the current directory, this will be
9966 valid for the result as well. A trailing path separator is
9967 not removed either. On Unix "//path" is unchanged, but
9968 "///path" is simplified to "/path" (this follows the Posix
9969 standard).
9970 Example: >
9971 simplify("./dir/.././/file/") == "./file/"
9972< Note: The combination "dir/.." is only removed if "dir" is
9973 a searchable directory or does not exist. On Unix, it is also
9974 removed when "dir" is a symbolic link within the same
9975 directory. In order to resolve all the involved symbolic
9976 links before simplifying the path name, use |resolve()|.
9977
9978 Can also be used as a |method|: >
9979 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009980<
9981 Return type: |String|
9982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009983
9984sin({expr}) *sin()*
9985 Return the sine of {expr}, measured in radians, as a |Float|.
9986 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009987 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009988 Examples: >
9989 :echo sin(100)
9990< -0.506366 >
9991 :echo sin(-4.01)
9992< 0.763301
9993
9994 Can also be used as a |method|: >
9995 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009996<
9997 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009998
9999
10000sinh({expr}) *sinh()*
10001 Return the hyperbolic sine of {expr} as a |Float| in the range
10002 [-inf, inf].
10003 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010004 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010005 Examples: >
10006 :echo sinh(0.5)
10007< 0.521095 >
10008 :echo sinh(-0.9)
10009< -1.026517
10010
10011 Can also be used as a |method|: >
10012 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010013<
10014 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010015
10016
10017slice({expr}, {start} [, {end}]) *slice()*
10018 Similar to using a |slice| "expr[start : end]", but "end" is
10019 used exclusive. And for a string the indexes are used as
10020 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010021 |vim9script|. Also, composing characters are treated as a
10022 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010023 When {end} is omitted the slice continues to the last item.
10024 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010025 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010026
10027 Can also be used as a |method|: >
10028 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010029<
10030 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010031
10032
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010033sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010034 Sort the items in {list} in-place. Returns {list}.
10035
10036 If you want a list to remain unmodified make a copy first: >
10037 :let sortedlist = sort(copy(mylist))
10038
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010039< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010040 string representation of each item to sort on. Numbers sort
10041 after Strings, |Lists| after Numbers. For sorting text in the
10042 current buffer use |:sort|.
10043
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010044 When {how} is given and it is 'i' then case is ignored.
10045 In legacy script, for backwards compatibility, the value one
10046 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010047
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010048 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010049 locale is used for ordering. Implementation details: strcoll()
10050 is used to compare strings. See |:language| check or set the
10051 collation locale. |v:collate| can also be used to check the
10052 current locale. Sorting using the locale typically ignores
10053 case. Example: >
10054 " ö is sorted similarly to o with English locale.
10055 :language collate en_US.UTF8
10056 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10057< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10058>
10059 " ö is sorted after z with Swedish locale.
10060 :language collate sv_SE.UTF8
10061 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10062< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10063 This does not work properly on Mac.
10064
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010065 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010066 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010067 strtod() function to parse numbers. Strings, Lists, Dicts and
10068 Funcrefs will be considered as being 0). Note that this won't
10069 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010070
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010071 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010072 sorted numerical. This is like 'n' but a string containing
10073 digits will be used as the number they represent.
10074
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010075 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010076 sorted numerical. All values must be a Number or a Float.
10077
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010078 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010079 is called to compare items. The function is invoked with two
10080 items as argument and must return zero if they are equal, 1 or
10081 bigger if the first one sorts after the second one, -1 or
10082 smaller if the first one sorts before the second one.
10083
10084 {dict} is for functions with the "dict" attribute. It will be
10085 used to set the local variable "self". |Dictionary-function|
10086
10087 The sort is stable, items which compare equal (as number or as
10088 string) will keep their relative position. E.g., when sorting
10089 on numbers, text strings will sort next to each other, in the
10090 same order as they were originally.
10091
10092 Can also be used as a |method|: >
10093 mylist->sort()
10094
10095< Also see |uniq()|.
10096
10097 Example: >
10098 func MyCompare(i1, i2)
10099 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10100 endfunc
10101 eval mylist->sort("MyCompare")
10102< A shorter compare version for this specific simple case, which
10103 ignores overflow: >
10104 func MyCompare(i1, i2)
10105 return a:i1 - a:i2
10106 endfunc
10107< For a simple expression you can use a lambda: >
10108 eval mylist->sort({i1, i2 -> i1 - i2})
10109<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010110 Return type: list<{type}>
10111
10112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010113sound_clear() *sound_clear()*
10114 Stop playing all sounds.
10115
10116 On some Linux systems you may need the libcanberra-pulse
10117 package, otherwise sound may not stop.
10118
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010119 Return type: |Number|
10120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010121 {only available when compiled with the |+sound| feature}
10122
10123 *sound_playevent()*
10124sound_playevent({name} [, {callback}])
10125 Play a sound identified by {name}. Which event names are
10126 supported depends on the system. Often the XDG sound names
10127 are used. On Ubuntu they may be found in
10128 /usr/share/sounds/freedesktop/stereo. Example: >
10129 call sound_playevent('bell')
10130< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10131 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10132 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010133 On macOS, {name} refers to files located in
10134 /System/Library/Sounds (e.g. "Tink"). It will also work for
10135 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010136
10137 When {callback} is specified it is invoked when the sound is
10138 finished. The first argument is the sound ID, the second
10139 argument is the status:
10140 0 sound was played to the end
10141 1 sound was interrupted
10142 2 error occurred after sound started
10143 Example: >
10144 func Callback(id, status)
10145 echomsg "sound " .. a:id .. " finished with " .. a:status
10146 endfunc
10147 call sound_playevent('bell', 'Callback')
10148
10149< MS-Windows: {callback} doesn't work for this function.
10150
10151 Returns the sound ID, which can be passed to `sound_stop()`.
10152 Returns zero if the sound could not be played.
10153
10154 Can also be used as a |method|: >
10155 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010156<
10157 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010158
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010159 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010160
10161 *sound_playfile()*
10162sound_playfile({path} [, {callback}])
10163 Like `sound_playevent()` but play sound file {path}. {path}
10164 must be a full path. On Ubuntu you may find files to play
10165 with this command: >
10166 :!find /usr/share/sounds -type f | grep -v index.theme
10167
10168< Can also be used as a |method|: >
10169 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010170<
10171 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010172
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010173 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010174
10175
10176sound_stop({id}) *sound_stop()*
10177 Stop playing sound {id}. {id} must be previously returned by
10178 `sound_playevent()` or `sound_playfile()`.
10179
10180 On some Linux systems you may need the libcanberra-pulse
10181 package, otherwise sound may not stop.
10182
10183 On MS-Windows, this does not work for event sound started by
10184 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10185
10186 Can also be used as a |method|: >
10187 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010188<
10189 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010190
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010191 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010192
10193 *soundfold()*
10194soundfold({word})
10195 Return the sound-folded equivalent of {word}. Uses the first
10196 language in 'spelllang' for the current window that supports
10197 soundfolding. 'spell' must be set. When no sound folding is
10198 possible the {word} is returned unmodified.
10199 This can be used for making spelling suggestions. Note that
10200 the method can be quite slow.
10201
10202 Can also be used as a |method|: >
10203 GetWord()->soundfold()
10204<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010205 Return type: |String|
10206
10207
10208spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010209 Without argument: The result is the badly spelled word under
10210 or after the cursor. The cursor is moved to the start of the
10211 bad word. When no bad word is found in the cursor line the
10212 result is an empty string and the cursor doesn't move.
10213
10214 With argument: The result is the first word in {sentence} that
10215 is badly spelled. If there are no spelling mistakes the
10216 result is an empty string.
10217
10218 The return value is a list with two items:
10219 - The badly spelled word or an empty string.
10220 - The type of the spelling error:
10221 "bad" spelling mistake
10222 "rare" rare word
10223 "local" word only valid in another region
10224 "caps" word should start with Capital
10225 Example: >
10226 echo spellbadword("the quik brown fox")
10227< ['quik', 'bad'] ~
10228
10229 The spelling information for the current window and the value
10230 of 'spelllang' are used.
10231
10232 Can also be used as a |method|: >
10233 GetText()->spellbadword()
10234<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010235 Return type: list<string>
10236
10237
10238spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010239 Return a |List| with spelling suggestions to replace {word}.
10240 When {max} is given up to this number of suggestions are
10241 returned. Otherwise up to 25 suggestions are returned.
10242
10243 When the {capital} argument is given and it's non-zero only
10244 suggestions with a leading capital will be given. Use this
10245 after a match with 'spellcapcheck'.
10246
10247 {word} can be a badly spelled word followed by other text.
10248 This allows for joining two words that were split. The
10249 suggestions also include the following text, thus you can
10250 replace a line.
10251
10252 {word} may also be a good word. Similar words will then be
10253 returned. {word} itself is not included in the suggestions,
10254 although it may appear capitalized.
10255
10256 The spelling information for the current window is used. The
10257 values of 'spelllang' and 'spellsuggest' are used.
10258
10259 Can also be used as a |method|: >
10260 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010261<
10262 Return type: list<string> or list<any>
10263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010264
10265split({string} [, {pattern} [, {keepempty}]]) *split()*
10266 Make a |List| out of {string}. When {pattern} is omitted or
10267 empty each white-separated sequence of characters becomes an
10268 item.
10269 Otherwise the string is split where {pattern} matches,
10270 removing the matched characters. 'ignorecase' is not used
10271 here, add \c to ignore case. |/\c|
10272 When the first or last item is empty it is omitted, unless the
10273 {keepempty} argument is given and it's non-zero.
10274 Other empty items are kept when {pattern} matches at least one
10275 character or when {keepempty} is non-zero.
10276 Example: >
10277 :let words = split(getline('.'), '\W\+')
10278< To split a string in individual characters: >
10279 :for c in split(mystring, '\zs')
10280< If you want to keep the separator you can also use '\zs' at
10281 the end of the pattern: >
10282 :echo split('abc:def:ghi', ':\zs')
10283< ['abc:', 'def:', 'ghi'] ~
10284 Splitting a table where the first element can be empty: >
10285 :let items = split(line, ':', 1)
10286< The opposite function is |join()|.
10287
10288 Can also be used as a |method|: >
10289 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010290<
10291 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010292
10293sqrt({expr}) *sqrt()*
10294 Return the non-negative square root of Float {expr} as a
10295 |Float|.
10296 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010297 is negative the result is NaN (Not a Number). Returns 0.0 if
10298 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010299 Examples: >
10300 :echo sqrt(100)
10301< 10.0 >
10302 :echo sqrt(-4.01)
10303< nan
10304 "nan" may be different, it depends on system libraries.
10305
10306 Can also be used as a |method|: >
10307 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010308<
10309 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010310
10311
10312srand([{expr}]) *srand()*
10313 Initialize seed used by |rand()|:
10314 - If {expr} is not given, seed values are initialized by
10315 reading from /dev/urandom, if possible, or using time(NULL)
10316 a.k.a. epoch time otherwise; this only has second accuracy.
10317 - If {expr} is given it must be a Number. It is used to
10318 initialize the seed values. This is useful for testing or
10319 when a predictable sequence is intended.
10320
10321 Examples: >
10322 :let seed = srand()
10323 :let seed = srand(userinput)
10324 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010325<
10326 Return type: list<number>
10327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010328
10329state([{what}]) *state()*
10330 Return a string which contains characters indicating the
10331 current state. Mostly useful in callbacks that want to do
10332 work that may not always be safe. Roughly this works like:
10333 - callback uses state() to check if work is safe to do.
10334 Yes: then do it right away.
10335 No: add to work queue and add a |SafeState| and/or
10336 |SafeStateAgain| autocommand (|SafeState| triggers at
10337 toplevel, |SafeStateAgain| triggers after handling
10338 messages and callbacks).
10339 - When SafeState or SafeStateAgain is triggered and executes
10340 your autocommand, check with `state()` if the work can be
10341 done now, and if yes remove it from the queue and execute.
10342 Remove the autocommand if the queue is now empty.
10343 Also see |mode()|.
10344
10345 When {what} is given only characters in this string will be
10346 added. E.g, this checks if the screen has scrolled: >
10347 if state('s') == ''
10348 " screen has not scrolled
10349<
10350 These characters indicate the state, generally indicating that
10351 something is busy:
10352 m halfway a mapping, :normal command, feedkeys() or
10353 stuffed command
10354 o operator pending, e.g. after |d|
10355 a Insert mode autocomplete active
10356 x executing an autocommand
10357 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10358 ch_readraw() when reading json
10359 S not triggering SafeState or SafeStateAgain, e.g. after
10360 |f| or a count
10361 c callback invoked, including timer (repeats for
10362 recursiveness up to "ccc")
10363 s screen has scrolled for messages
10364
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010365 Return type: |String|
10366
10367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010368str2float({string} [, {quoted}]) *str2float()*
10369 Convert String {string} to a Float. This mostly works the
10370 same as when using a floating point number in an expression,
10371 see |floating-point-format|. But it's a bit more permissive.
10372 E.g., "1e40" is accepted, while in an expression you need to
10373 write "1.0e40". The hexadecimal form "0x123" is also
10374 accepted, but not others, like binary or octal.
10375 When {quoted} is present and non-zero then embedded single
10376 quotes before the dot are ignored, thus "1'000.0" is a
10377 thousand.
10378 Text after the number is silently ignored.
10379 The decimal point is always '.', no matter what the locale is
10380 set to. A comma ends the number: "12,345.67" is converted to
10381 12.0. You can strip out thousands separators with
10382 |substitute()|: >
10383 let f = str2float(substitute(text, ',', '', 'g'))
10384<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010385 Returns 0.0 if the conversion fails.
10386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010387 Can also be used as a |method|: >
10388 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010389<
10390 Return type: |Float|
10391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010392
10393str2list({string} [, {utf8}]) *str2list()*
10394 Return a list containing the number values which represent
10395 each character in String {string}. Examples: >
10396 str2list(" ") returns [32]
10397 str2list("ABC") returns [65, 66, 67]
10398< |list2str()| does the opposite.
10399
10400 When {utf8} is omitted or zero, the current 'encoding' is used.
10401 When {utf8} is TRUE, always treat the String as UTF-8
10402 characters. With UTF-8 composing characters are handled
10403 properly: >
10404 str2list("á") returns [97, 769]
10405
10406< Can also be used as a |method|: >
10407 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010408<
10409 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010410
10411
10412str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10413 Convert string {string} to a number.
10414 {base} is the conversion base, it can be 2, 8, 10 or 16.
10415 When {quoted} is present and non-zero then embedded single
10416 quotes are ignored, thus "1'000'000" is a million.
10417
10418 When {base} is omitted base 10 is used. This also means that
10419 a leading zero doesn't cause octal conversion to be used, as
10420 with the default String to Number conversion. Example: >
10421 let nr = str2nr('0123')
10422<
10423 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10424 different base the result will be zero. Similarly, when
10425 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10426 {base} is 2 a leading "0b" or "0B" is ignored.
10427 Text after the number is silently ignored.
10428
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010429 Returns 0 if {string} is empty or on error.
10430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010431 Can also be used as a |method|: >
10432 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010433<
10434 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010435
10436
10437strcharlen({string}) *strcharlen()*
10438 The result is a Number, which is the number of characters
10439 in String {string}. Composing characters are ignored.
10440 |strchars()| can count the number of characters, counting
10441 composing characters separately.
10442
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010443 Returns 0 if {string} is empty or on error.
10444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010445 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10446
10447 Can also be used as a |method|: >
10448 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010449<
10450 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010451
10452
10453strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10454 Like |strpart()| but using character index and length instead
10455 of byte index and length.
10456 When {skipcc} is omitted or zero, composing characters are
10457 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010458 When {skipcc} set to 1, composing characters are treated as a
10459 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010460 When a character index is used where a character does not
10461 exist it is omitted and counted as one character. For
10462 example: >
10463 strcharpart('abc', -1, 2)
10464< results in 'a'.
10465
Bram Moolenaard592deb2022-06-17 15:42:40 +010010466 Returns an empty string on error.
10467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010468 Can also be used as a |method|: >
10469 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010470<
10471 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010472
10473
10474strchars({string} [, {skipcc}]) *strchars()*
10475 The result is a Number, which is the number of characters
10476 in String {string}.
10477 When {skipcc} is omitted or zero, composing characters are
10478 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010479 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010480 |strcharlen()| always does this.
10481
Bram Moolenaard592deb2022-06-17 15:42:40 +010010482 Returns zero on error.
10483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010484 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10485
10486 {skipcc} is only available after 7.4.755. For backward
10487 compatibility, you can define a wrapper function: >
10488 if has("patch-7.4.755")
10489 function s:strchars(str, skipcc)
10490 return strchars(a:str, a:skipcc)
10491 endfunction
10492 else
10493 function s:strchars(str, skipcc)
10494 if a:skipcc
10495 return strlen(substitute(a:str, ".", "x", "g"))
10496 else
10497 return strchars(a:str)
10498 endif
10499 endfunction
10500 endif
10501<
10502 Can also be used as a |method|: >
10503 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010504<
10505 Return type: |Number|
10506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010507
10508strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10509 The result is a Number, which is the number of display cells
10510 String {string} occupies on the screen when it starts at {col}
10511 (first column is zero). When {col} is omitted zero is used.
10512 Otherwise it is the screen column where to start. This
10513 matters for Tab characters.
10514 The option settings of the current window are used. This
10515 matters for anything that's displayed differently, such as
10516 'tabstop' and 'display'.
10517 When {string} contains characters with East Asian Width Class
10518 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010519 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010520 Also see |strlen()|, |strwidth()| and |strchars()|.
10521
10522 Can also be used as a |method|: >
10523 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010524<
10525 Return type: |Number|
10526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010527
10528strftime({format} [, {time}]) *strftime()*
10529 The result is a String, which is a formatted date and time, as
10530 specified by the {format} string. The given {time} is used,
10531 or the current time if no time is given. The accepted
10532 {format} depends on your system, thus this is not portable!
10533 See the manual page of the C function strftime() for the
10534 format. The maximum length of the result is 80 characters.
10535 See also |localtime()|, |getftime()| and |strptime()|.
10536 The language can be changed with the |:language| command.
10537 Examples: >
10538 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10539 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10540 :echo strftime("%y%m%d %T") 970427 11:53:55
10541 :echo strftime("%H:%M") 11:55
10542 :echo strftime("%c", getftime("file.c"))
10543 Show mod time of file.c.
10544< Not available on all systems. To check use: >
10545 :if exists("*strftime")
10546
10547< Can also be used as a |method|: >
10548 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010549<
10550 Return type: |String|
10551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010552
10553strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010554 Get a Number corresponding to the character at {index} in
10555 {str}. This uses a zero-based character index, not a byte
10556 index. Composing characters are considered separate
10557 characters here. Use |nr2char()| to convert the Number to a
10558 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010559 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010560 Also see |strcharpart()| and |strchars()|.
10561
10562 Can also be used as a |method|: >
10563 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010564<
10565 Return type: |Number|
10566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010567
10568stridx({haystack}, {needle} [, {start}]) *stridx()*
10569 The result is a Number, which gives the byte index in
10570 {haystack} of the first occurrence of the String {needle}.
10571 If {start} is specified, the search starts at index {start}.
10572 This can be used to find a second match: >
10573 :let colon1 = stridx(line, ":")
10574 :let colon2 = stridx(line, ":", colon1 + 1)
10575< The search is done case-sensitive.
10576 For pattern searches use |match()|.
10577 -1 is returned if the {needle} does not occur in {haystack}.
10578 See also |strridx()|.
10579 Examples: >
10580 :echo stridx("An Example", "Example") 3
10581 :echo stridx("Starting point", "Start") 0
10582 :echo stridx("Starting point", "start") -1
10583< *strstr()* *strchr()*
10584 stridx() works similar to the C function strstr(). When used
10585 with a single character it works similar to strchr().
10586
10587 Can also be used as a |method|: >
10588 GetHaystack()->stridx(needle)
10589<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010590 Return type: |Number|
10591
10592
10593string({expr}) *string()*
10594 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010595 Float, String, Blob or a composition of them, then the result
10596 can be parsed back with |eval()|.
10597 {expr} type result ~
10598 String 'string' (single quotes are doubled)
10599 Number 123
10600 Float 123.123456 or 1.123456e8
10601 Funcref function('name')
10602 Blob 0z00112233.44556677.8899
10603 List [item, item]
10604 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010605 Class class SomeName
10606 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010607 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010608 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010609
10610 When a |List| or |Dictionary| has a recursive reference it is
10611 replaced by "[...]" or "{...}". Using eval() on the result
10612 will then fail.
10613
mityu7f0bba22024-03-29 10:14:41 +010010614 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010615 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010616 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010618 Can also be used as a |method|: >
10619 mylist->string()
10620
10621< Also see |strtrans()|.
10622
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010623 Return type: |String|
10624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010625
10626strlen({string}) *strlen()*
10627 The result is a Number, which is the length of the String
10628 {string} in bytes.
10629 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010630 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010631 If you want to count the number of multibyte characters use
10632 |strchars()|.
10633 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10634
10635 Can also be used as a |method|: >
10636 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010637<
10638 Return type: |Number|
10639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010640
10641strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10642 The result is a String, which is part of {src}, starting from
10643 byte {start}, with the byte length {len}.
10644 When {chars} is present and TRUE then {len} is the number of
10645 characters positions (composing characters are not counted
10646 separately, thus "1" means one base character and any
10647 following composing characters).
10648 To count {start} as characters instead of bytes use
10649 |strcharpart()|.
10650
10651 When bytes are selected which do not exist, this doesn't
10652 result in an error, the bytes are simply omitted.
10653 If {len} is missing, the copy continues from {start} till the
10654 end of the {src}. >
10655 strpart("abcdefg", 3, 2) == "de"
10656 strpart("abcdefg", -2, 4) == "ab"
10657 strpart("abcdefg", 5, 4) == "fg"
10658 strpart("abcdefg", 3) == "defg"
10659
10660< Note: To get the first character, {start} must be 0. For
10661 example, to get the character under the cursor: >
10662 strpart(getline("."), col(".") - 1, 1, v:true)
10663<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010664 Returns an empty string on error.
10665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010666 Can also be used as a |method|: >
10667 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010668<
10669 Return type: |String|
10670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010671
10672strptime({format}, {timestring}) *strptime()*
10673 The result is a Number, which is a unix timestamp representing
10674 the date and time in {timestring}, which is expected to match
10675 the format specified in {format}.
10676
10677 The accepted {format} depends on your system, thus this is not
10678 portable! See the manual page of the C function strptime()
10679 for the format. Especially avoid "%c". The value of $TZ also
10680 matters.
10681
10682 If the {timestring} cannot be parsed with {format} zero is
10683 returned. If you do not know the format of {timestring} you
10684 can try different {format} values until you get a non-zero
10685 result.
10686
10687 See also |strftime()|.
10688 Examples: >
10689 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10690< 862156163 >
10691 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10692< Sun Apr 27 11:53:55 1997 >
10693 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10694< Sun Apr 27 12:53:55 1997
10695
10696 Can also be used as a |method|: >
10697 GetFormat()->strptime(timestring)
10698<
10699 Not available on all systems. To check use: >
10700 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010701<
10702 Return type: |Number|
10703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010704
10705strridx({haystack}, {needle} [, {start}]) *strridx()*
10706 The result is a Number, which gives the byte index in
10707 {haystack} of the last occurrence of the String {needle}.
10708 When {start} is specified, matches beyond this index are
10709 ignored. This can be used to find a match before a previous
10710 match: >
10711 :let lastcomma = strridx(line, ",")
10712 :let comma2 = strridx(line, ",", lastcomma - 1)
10713< The search is done case-sensitive.
10714 For pattern searches use |match()|.
10715 -1 is returned if the {needle} does not occur in {haystack}.
10716 If the {needle} is empty the length of {haystack} is returned.
10717 See also |stridx()|. Examples: >
10718 :echo strridx("an angry armadillo", "an") 3
10719< *strrchr()*
10720 When used with a single character it works similar to the C
10721 function strrchr().
10722
10723 Can also be used as a |method|: >
10724 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010725<
10726 Return type: |Number|
10727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010728
10729strtrans({string}) *strtrans()*
10730 The result is a String, which is {string} with all unprintable
10731 characters translated into printable characters |'isprint'|.
10732 Like they are shown in a window. Example: >
10733 echo strtrans(@a)
10734< This displays a newline in register a as "^@" instead of
10735 starting a new line.
10736
Bram Moolenaard592deb2022-06-17 15:42:40 +010010737 Returns an empty string on error.
10738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010739 Can also be used as a |method|: >
10740 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010741<
10742 Return type: |String|
10743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010744
Christian Brabandt67672ef2023-04-24 21:09:54 +010010745strutf16len({string} [, {countcc}]) *strutf16len()*
10746 The result is a Number, which is the number of UTF-16 code
10747 units in String {string} (after converting it to UTF-16).
10748
10749 When {countcc} is TRUE, composing characters are counted
10750 separately.
10751 When {countcc} is omitted or FALSE, composing characters are
10752 ignored.
10753
10754 Returns zero on error.
10755
10756 Also see |strlen()| and |strcharlen()|.
10757 Examples: >
10758 echo strutf16len('a') returns 1
10759 echo strutf16len('©') returns 1
10760 echo strutf16len('😊') returns 2
10761 echo strutf16len('ą́') returns 1
10762 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010763<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010764 Can also be used as a |method|: >
10765 GetText()->strutf16len()
10766<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010767 Return type: |Number|
10768
10769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010770strwidth({string}) *strwidth()*
10771 The result is a Number, which is the number of display cells
10772 String {string} occupies. A Tab character is counted as one
10773 cell, alternatively use |strdisplaywidth()|.
10774 When {string} contains characters with East Asian Width Class
10775 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010776 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010777 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10778
10779 Can also be used as a |method|: >
10780 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010781<
10782 Return type: |Number|
10783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010784
10785submatch({nr} [, {list}]) *submatch()* *E935*
10786 Only for an expression in a |:substitute| command or
10787 substitute() function.
10788 Returns the {nr}'th submatch of the matched text. When {nr}
10789 is 0 the whole matched text is returned.
10790 Note that a NL in the string can stand for a line break of a
10791 multi-line match or a NUL character in the text.
10792 Also see |sub-replace-expression|.
10793
10794 If {list} is present and non-zero then submatch() returns
10795 a list of strings, similar to |getline()| with two arguments.
10796 NL characters in the text represent NUL characters in the
10797 text.
10798 Only returns more than one item for |:substitute|, inside
10799 |substitute()| this list will always contain one or zero
10800 items, since there are no real line breaks.
10801
10802 When substitute() is used recursively only the submatches in
10803 the current (deepest) call can be obtained.
10804
Bram Moolenaard592deb2022-06-17 15:42:40 +010010805 Returns an empty string or list on error.
10806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010807 Examples: >
10808 :s/\d\+/\=submatch(0) + 1/
10809 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10810< This finds the first number in the line and adds one to it.
10811 A line break is included as a newline character.
10812
10813 Can also be used as a |method|: >
10814 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010815<
10816 Return type: |String| or list<string> depending on {list}
10817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010818
10819substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10820 The result is a String, which is a copy of {string}, in which
10821 the first match of {pat} is replaced with {sub}.
10822 When {flags} is "g", all matches of {pat} in {string} are
10823 replaced. Otherwise {flags} should be "".
10824
10825 This works like the ":substitute" command (without any flags).
10826 But the matching with {pat} is always done like the 'magic'
10827 option is set and 'cpoptions' is empty (to make scripts
10828 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
10829 if you want to ignore or match case and ignore 'ignorecase'.
10830 'smartcase' is not used. See |string-match| for how {pat} is
10831 used.
10832
10833 A "~" in {sub} is not replaced with the previous {sub}.
10834 Note that some codes in {sub} have a special meaning
10835 |sub-replace-special|. For example, to replace something with
10836 "\n" (two characters), use "\\\\n" or '\\n'.
10837
10838 When {pat} does not match in {string}, {string} is returned
10839 unmodified.
10840
10841 Example: >
10842 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
10843< This removes the last component of the 'path' option. >
10844 :echo substitute("testing", ".*", "\\U\\0", "")
10845< results in "TESTING".
10846
10847 When {sub} starts with "\=", the remainder is interpreted as
10848 an expression. See |sub-replace-expression|. Example: >
10849 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010850 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010851
10852< When {sub} is a Funcref that function is called, with one
10853 optional argument. Example: >
10854 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
10855< The optional argument is a list which contains the whole
10856 matched string and up to nine submatches, like what
10857 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010858 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010859
Bram Moolenaard592deb2022-06-17 15:42:40 +010010860< Returns an empty string on error.
10861
10862 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010863 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010864<
10865 Return type: |String|
10866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010867
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010868swapfilelist() *swapfilelist()*
10869 Returns a list of swap file names, like what "vim -r" shows.
10870 See the |-r| command argument. The 'directory' option is used
10871 for the directories to inspect. If you only want to get a
10872 list of swap files in the current directory then temporarily
10873 set 'directory' to a dot: >
10874 let save_dir = &directory
10875 let &directory = '.'
10876 let swapfiles = swapfilelist()
10877 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010878<
10879 Return type: list<string>
10880
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000010881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010882swapinfo({fname}) *swapinfo()*
10883 The result is a dictionary, which holds information about the
10884 swapfile {fname}. The available fields are:
10885 version Vim version
10886 user user name
10887 host host name
10888 fname original file name
10889 pid PID of the Vim process that created the swap
10890 file
10891 mtime last modification time in seconds
10892 inode Optional: INODE number of the file
10893 dirty 1 if file was modified, 0 if not
10894 Note that "user" and "host" are truncated to at most 39 bytes.
10895 In case of failure an "error" item is added with the reason:
10896 Cannot open file: file not found or in accessible
10897 Cannot read file: cannot read first block
10898 Not a swap file: does not contain correct block ID
10899 Magic number mismatch: Info in first block is invalid
10900
10901 Can also be used as a |method|: >
10902 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010903<
10904 Return type: dict<any> or dict<string>
10905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010906
10907swapname({buf}) *swapname()*
10908 The result is the swap file path of the buffer {expr}.
10909 For the use of {buf}, see |bufname()| above.
10910 If buffer {buf} is the current buffer, the result is equal to
10911 |:swapname| (unless there is no swap file).
10912 If buffer {buf} has no swap file, returns an empty string.
10913
10914 Can also be used as a |method|: >
10915 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010916<
10917 Return type: |String|
10918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010919
10920synID({lnum}, {col}, {trans}) *synID()*
10921 The result is a Number, which is the syntax ID at the position
10922 {lnum} and {col} in the current window.
10923 The syntax ID can be used with |synIDattr()| and
10924 |synIDtrans()| to obtain syntax information about text.
10925
10926 {col} is 1 for the leftmost column, {lnum} is 1 for the first
10927 line. 'synmaxcol' applies, in a longer line zero is returned.
10928 Note that when the position is after the last character,
10929 that's where the cursor can be in Insert mode, synID() returns
10930 zero. {lnum} is used like with |getline()|.
10931
10932 When {trans} is |TRUE|, transparent items are reduced to the
10933 item that they reveal. This is useful when wanting to know
10934 the effective color. When {trans} is |FALSE|, the transparent
10935 item is returned. This is useful when wanting to know which
10936 syntax item is effective (e.g. inside parens).
10937 Warning: This function can be very slow. Best speed is
10938 obtained by going through the file in forward direction.
10939
Bram Moolenaard592deb2022-06-17 15:42:40 +010010940 Returns zero on error.
10941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010942 Example (echoes the name of the syntax item under the cursor): >
10943 :echo synIDattr(synID(line("."), col("."), 1), "name")
10944<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010945 Return type: |Number|
10946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010947
10948synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
10949 The result is a String, which is the {what} attribute of
10950 syntax ID {synID}. This can be used to obtain information
10951 about a syntax item.
10952 {mode} can be "gui", "cterm" or "term", to get the attributes
10953 for that mode. When {mode} is omitted, or an invalid value is
10954 used, the attributes for the currently active highlighting are
10955 used (GUI, cterm or term).
10956 Use synIDtrans() to follow linked highlight groups.
10957 {what} result
10958 "name" the name of the syntax item
10959 "fg" foreground color (GUI: color name used to set
10960 the color, cterm: color number as a string,
10961 term: empty string)
10962 "bg" background color (as with "fg")
10963 "font" font name (only available in the GUI)
10964 |highlight-font|
10965 "sp" special color for the GUI (as with "fg")
10966 |highlight-guisp|
10967 "ul" underline color for cterm: number as a string
10968 "fg#" like "fg", but for the GUI and the GUI is
10969 running the name in "#RRGGBB" form
10970 "bg#" like "fg#" for "bg"
10971 "sp#" like "fg#" for "sp"
10972 "bold" "1" if bold
10973 "italic" "1" if italic
10974 "reverse" "1" if reverse
10975 "inverse" "1" if inverse (= reverse)
10976 "standout" "1" if standout
10977 "underline" "1" if underlined
10978 "undercurl" "1" if undercurled
10979 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010010980 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010981
Bram Moolenaard592deb2022-06-17 15:42:40 +010010982 Returns an empty string on error.
10983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010984 Example (echoes the color of the syntax item under the
10985 cursor): >
10986 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
10987<
10988 Can also be used as a |method|: >
10989 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010990<
10991 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010992
10993
10994synIDtrans({synID}) *synIDtrans()*
10995 The result is a Number, which is the translated syntax ID of
10996 {synID}. This is the syntax group ID of what is being used to
10997 highlight the character. Highlight links given with
10998 ":highlight link" are followed.
10999
Bram Moolenaard592deb2022-06-17 15:42:40 +010011000 Returns zero on error.
11001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011002 Can also be used as a |method|: >
11003 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011004<
11005 Return type: |Number|
11006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011007
11008synconcealed({lnum}, {col}) *synconcealed()*
11009 The result is a |List| with currently three items:
11010 1. The first item in the list is 0 if the character at the
11011 position {lnum} and {col} is not part of a concealable
11012 region, 1 if it is. {lnum} is used like with |getline()|.
11013 2. The second item in the list is a string. If the first item
11014 is 1, the second item contains the text which will be
11015 displayed in place of the concealed text, depending on the
11016 current setting of 'conceallevel' and 'listchars'.
11017 3. The third and final item in the list is a number
11018 representing the specific syntax region matched in the
11019 line. When the character is not concealed the value is
11020 zero. This allows detection of the beginning of a new
11021 concealable region if there are two consecutive regions
11022 with the same replacement character. For an example, if
11023 the text is "123456" and both "23" and "45" are concealed
11024 and replaced by the character "X", then:
11025 call returns ~
11026 synconcealed(lnum, 1) [0, '', 0]
11027 synconcealed(lnum, 2) [1, 'X', 1]
11028 synconcealed(lnum, 3) [1, 'X', 1]
11029 synconcealed(lnum, 4) [1, 'X', 2]
11030 synconcealed(lnum, 5) [1, 'X', 2]
11031 synconcealed(lnum, 6) [0, '', 0]
11032
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011033 Note: Doesn't consider |matchadd()| highlighting items,
11034 since syntax and matching highlighting are two different
11035 mechanisms |syntax-vs-match|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011036<
11037 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011038
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011039
11040synstack({lnum}, {col}) *synstack()*
11041 Return a |List|, which is the stack of syntax items at the
11042 position {lnum} and {col} in the current window. {lnum} is
11043 used like with |getline()|. Each item in the List is an ID
11044 like what |synID()| returns.
11045 The first item in the List is the outer region, following are
11046 items contained in that one. The last one is what |synID()|
11047 returns, unless not the whole item is highlighted or it is a
11048 transparent item.
11049 This function is useful for debugging a syntax file.
11050 Example that shows the syntax stack under the cursor: >
11051 for id in synstack(line("."), col("."))
11052 echo synIDattr(id, "name")
11053 endfor
11054< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011055 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011056 character in a line and the first column in an empty line are
11057 valid positions.
11058
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011059 Return type: list<number> or list<any>
11060
11061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011062system({expr} [, {input}]) *system()* *E677*
11063 Get the output of the shell command {expr} as a |String|. See
11064 |systemlist()| to get the output as a |List|.
11065
11066 When {input} is given and is a |String| this string is written
11067 to a file and passed as stdin to the command. The string is
11068 written as-is, you need to take care of using the correct line
11069 separators yourself.
11070 If {input} is given and is a |List| it is written to the file
11071 in a way |writefile()| does with {binary} set to "b" (i.e.
11072 with a newline between each list item with newlines inside
11073 list items converted to NULs).
11074 When {input} is given and is a number that is a valid id for
11075 an existing buffer then the content of the buffer is written
11076 to the file line by line, each line terminated by a NL and
11077 NULs characters where the text has a NL.
11078
11079 Pipes are not used, the 'shelltemp' option is not used.
11080
11081 When prepended by |:silent| the terminal will not be set to
11082 cooked mode. This is meant to be used for commands that do
11083 not need the user to type. It avoids stray characters showing
11084 up on the screen which require |CTRL-L| to remove. >
11085 :silent let f = system('ls *.vim')
11086<
11087 Note: Use |shellescape()| or |::S| with |expand()| or
11088 |fnamemodify()| to escape special characters in a command
11089 argument. Newlines in {expr} may cause the command to fail.
11090 The characters in 'shellquote' and 'shellxquote' may also
11091 cause trouble.
11092 This is not to be used for interactive commands.
11093
11094 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011095 :let files = system('ls ' .. shellescape(expand('%:h')))
11096 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011097
11098< To make the result more system-independent, the shell output
11099 is filtered to replace <CR> with <NL> for Macintosh, and
11100 <CR><NL> with <NL> for DOS-like systems.
11101 To avoid the string being truncated at a NUL, all NUL
11102 characters are replaced with SOH (0x01).
11103
11104 The command executed is constructed using several options:
11105 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11106 ({tmp} is an automatically generated file name).
11107 For Unix, braces are put around {expr} to allow for
11108 concatenated commands.
11109
11110 The command will be executed in "cooked" mode, so that a
11111 CTRL-C will interrupt the command (on Unix at least).
11112
11113 The resulting error code can be found in |v:shell_error|.
11114 This function will fail in |restricted-mode|.
11115
11116 Note that any wrong value in the options mentioned above may
11117 make the function fail. It has also been reported to fail
11118 when using a security agent application.
11119 Unlike ":!cmd" there is no automatic check for changed files.
11120 Use |:checktime| to force a check.
11121
11122 Can also be used as a |method|: >
11123 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011124<
11125 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011126
11127
11128systemlist({expr} [, {input}]) *systemlist()*
11129 Same as |system()|, but returns a |List| with lines (parts of
11130 output separated by NL) with NULs transformed into NLs. Output
11131 is the same as |readfile()| will output with {binary} argument
11132 set to "b", except that there is no extra empty item when the
11133 result ends in a NL.
11134 Note that on MS-Windows you may get trailing CR characters.
11135
11136 To see the difference between "echo hello" and "echo -n hello"
11137 use |system()| and |split()|: >
11138 echo system('echo hello')->split('\n', 1)
11139<
11140 Returns an empty string on error.
11141
11142 Can also be used as a |method|: >
11143 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011144<
11145 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011146
11147
11148tabpagebuflist([{arg}]) *tabpagebuflist()*
11149 The result is a |List|, where each item is the number of the
11150 buffer associated with each window in the current tab page.
11151 {arg} specifies the number of the tab page to be used. When
11152 omitted the current tab page is used.
11153 When {arg} is invalid the number zero is returned.
11154 To get a list of all buffers in all tabs use this: >
11155 let buflist = []
11156 for i in range(tabpagenr('$'))
11157 call extend(buflist, tabpagebuflist(i + 1))
11158 endfor
11159< Note that a buffer may appear in more than one window.
11160
11161 Can also be used as a |method|: >
11162 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011163<
11164 Return type: list<number>
11165
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011166
11167tabpagenr([{arg}]) *tabpagenr()*
11168 The result is a Number, which is the number of the current
11169 tab page. The first tab page has number 1.
11170
11171 The optional argument {arg} supports the following values:
11172 $ the number of the last tab page (the tab page
11173 count).
11174 # the number of the last accessed tab page
11175 (where |g<Tab>| goes to). if there is no
11176 previous tab page 0 is returned.
11177 The number can be used with the |:tab| command.
11178
Bram Moolenaard592deb2022-06-17 15:42:40 +010011179 Returns zero on error.
11180
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011181 Return type: |Number|
11182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011183
11184tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11185 Like |winnr()| but for tab page {tabarg}.
11186 {tabarg} specifies the number of tab page to be used.
11187 {arg} is used like with |winnr()|:
11188 - When omitted the current window number is returned. This is
11189 the window which will be used when going to this tab page.
11190 - When "$" the number of windows is returned.
11191 - When "#" the previous window nr is returned.
11192 Useful examples: >
11193 tabpagewinnr(1) " current window of tab page 1
11194 tabpagewinnr(4, '$') " number of windows in tab page 4
11195< When {tabarg} is invalid zero is returned.
11196
11197 Can also be used as a |method|: >
11198 GetTabpage()->tabpagewinnr()
11199<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011200 Return type: |Number|
11201
11202
11203tagfiles() *tagfiles()*
11204 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011205 for the current buffer. This is the 'tags' option expanded.
11206
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011207 Return type: list<string> or list<any>
11208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011209
11210taglist({expr} [, {filename}]) *taglist()*
11211 Returns a |List| of tags matching the regular expression {expr}.
11212
11213 If {filename} is passed it is used to prioritize the results
11214 in the same way that |:tselect| does. See |tag-priority|.
11215 {filename} should be the full path of the file.
11216
11217 Each list item is a dictionary with at least the following
11218 entries:
11219 name Name of the tag.
11220 filename Name of the file where the tag is
11221 defined. It is either relative to the
11222 current directory or a full path.
11223 cmd Ex command used to locate the tag in
11224 the file.
11225 kind Type of the tag. The value for this
11226 entry depends on the language specific
11227 kind values. Only available when
11228 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011229 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011230 static A file specific tag. Refer to
11231 |static-tag| for more information.
11232 More entries may be present, depending on the content of the
11233 tags file: access, implementation, inherits and signature.
11234 Refer to the ctags documentation for information about these
11235 fields. For C code the fields "struct", "class" and "enum"
11236 may appear, they give the name of the entity the tag is
11237 contained in.
11238
11239 The ex-command "cmd" can be either an ex search pattern, a
11240 line number or a line number followed by a byte number.
11241
11242 If there are no matching tags, then an empty list is returned.
11243
11244 To get an exact tag match, the anchors '^' and '$' should be
11245 used in {expr}. This also make the function work faster.
11246 Refer to |tag-regexp| for more information about the tag
11247 search regular expression pattern.
11248
11249 Refer to |'tags'| for information about how the tags file is
11250 located by Vim. Refer to |tags-file-format| for the format of
11251 the tags file generated by the different ctags tools.
11252
11253 Can also be used as a |method|: >
11254 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011255<
11256 Return type: list<dict<any>> or list<any>
11257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011258
11259tan({expr}) *tan()*
11260 Return the tangent of {expr}, measured in radians, as a |Float|
11261 in the range [-inf, inf].
11262 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011263 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011264 Examples: >
11265 :echo tan(10)
11266< 0.648361 >
11267 :echo tan(-4.01)
11268< -1.181502
11269
11270 Can also be used as a |method|: >
11271 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011272<
11273 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011274
11275
11276tanh({expr}) *tanh()*
11277 Return the hyperbolic tangent of {expr} as a |Float| in the
11278 range [-1, 1].
11279 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011280 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011281 Examples: >
11282 :echo tanh(0.5)
11283< 0.462117 >
11284 :echo tanh(-1)
11285< -0.761594
11286
11287 Can also be used as a |method|: >
11288 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011289<
11290 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011291
11292
11293tempname() *tempname()* *temp-file-name*
11294 The result is a String, which is the name of a file that
11295 doesn't exist. It can be used for a temporary file. The name
11296 is different for at least 26 consecutive calls. Example: >
11297 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011298 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011299< For Unix, the file will be in a private directory |tempfile|
11300 that is recursively deleted when Vim exits, on other systems
11301 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011302 For MS-Windows forward slashes are used when the 'shellslash'
11303 option is set, or when 'shellcmdflag' starts with '-' and
11304 'shell' does not contain powershell or pwsh.
11305
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011306 Return type: |String|
11307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011308
11309term_ functions are documented here: |terminal-function-details|
11310
11311
11312terminalprops() *terminalprops()*
11313 Returns a |Dictionary| with properties of the terminal that Vim
11314 detected from the response to |t_RV| request. See
11315 |v:termresponse| for the response itself. If |v:termresponse|
11316 is empty most values here will be 'u' for unknown.
11317 cursor_style whether sending |t_RS| works **
11318 cursor_blink_mode whether sending |t_RC| works **
11319 underline_rgb whether |t_8u| works **
11320 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011321 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011322
11323 ** value 'u' for unknown, 'y' for yes, 'n' for no
11324
11325 If the |+termresponse| feature is missing then the result is
11326 an empty dictionary.
11327
11328 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11329 current cursor style.
11330 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11331 request the cursor blink status.
11332 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11333 is not empty, Vim will detect the working of sending |t_RS|
11334 and |t_RC| on startup.
11335
11336 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11337 This avoids sending it to xterm, which would clear the colors.
11338
11339 For "mouse" the value 'u' is unknown
11340
11341 Also see:
11342 - 'ambiwidth' - detected by using |t_u7|.
11343 - |v:termstyleresp| and |v:termblinkresp| for the response to
11344 |t_RS| and |t_RC|.
11345
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011346 Return type: dict<string>
11347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011348
11349test_ functions are documented here: |test-functions-details|
11350
11351
11352 *timer_info()*
11353timer_info([{id}])
11354 Return a list with information about timers.
11355 When {id} is given only information about this timer is
11356 returned. When timer {id} does not exist an empty list is
11357 returned.
11358 When {id} is omitted information about all timers is returned.
11359
11360 For each timer the information is stored in a |Dictionary| with
11361 these items:
11362 "id" the timer ID
11363 "time" time the timer was started with
11364 "remaining" time until the timer fires
11365 "repeat" number of times the timer will still fire;
11366 -1 means forever
11367 "callback" the callback
11368 "paused" 1 if the timer is paused, 0 otherwise
11369
11370 Can also be used as a |method|: >
11371 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011372<
11373 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011374
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011375 {only available when compiled with the |+timers| feature}
11376
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011377
11378timer_pause({timer}, {paused}) *timer_pause()*
11379 Pause or unpause a timer. A paused timer does not invoke its
11380 callback when its time expires. Unpausing a timer may cause
11381 the callback to be invoked almost immediately if enough time
11382 has passed.
11383
11384 Pausing a timer is useful to avoid the callback to be called
11385 for a short time.
11386
11387 If {paused} evaluates to a non-zero Number or a non-empty
11388 String, then the timer is paused, otherwise it is unpaused.
11389 See |non-zero-arg|.
11390
11391 Can also be used as a |method|: >
11392 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011393<
11394 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011395
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011396 {only available when compiled with the |+timers| feature}
11397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011398
11399 *timer_start()* *timer* *timers*
11400timer_start({time}, {callback} [, {options}])
11401 Create a timer and return the timer ID.
11402
11403 {time} is the waiting time in milliseconds. This is the
11404 minimum time before invoking the callback. When the system is
11405 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011406 Zero can be used to execute the callback when Vim is back in
11407 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011408
11409 {callback} is the function to call. It can be the name of a
11410 function or a |Funcref|. It is called with one argument, which
11411 is the timer ID. The callback is only invoked when Vim is
11412 waiting for input.
11413 If you want to show a message look at |popup_notification()|
11414 to avoid interfering with what the user is doing.
11415
11416 {options} is a dictionary. Supported entries:
11417 "repeat" Number of times to repeat calling the
11418 callback. -1 means forever. When not present
11419 the callback will be called once.
11420 If the timer causes an error three times in a
11421 row the repeat is cancelled. This avoids that
11422 Vim becomes unusable because of all the error
11423 messages.
11424
Bram Moolenaard592deb2022-06-17 15:42:40 +010011425 Returns -1 on error.
11426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011427 Example: >
11428 func MyHandler(timer)
11429 echo 'Handler called'
11430 endfunc
11431 let timer = timer_start(500, 'MyHandler',
11432 \ {'repeat': 3})
11433< This will invoke MyHandler() three times at 500 msec
11434 intervals.
11435
11436 Can also be used as a |method|: >
11437 GetMsec()->timer_start(callback)
11438
11439< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011440
11441 Return type: |Number|
11442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011443 {only available when compiled with the |+timers| feature}
11444
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011446timer_stop({timer}) *timer_stop()*
11447 Stop a timer. The timer callback will no longer be invoked.
11448 {timer} is an ID returned by timer_start(), thus it must be a
11449 Number. If {timer} does not exist there is no error.
11450
11451 Can also be used as a |method|: >
11452 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011453<
11454 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011455
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011456 {only available when compiled with the |+timers| feature}
11457
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011458
11459timer_stopall() *timer_stopall()*
11460 Stop all timers. The timer callbacks will no longer be
11461 invoked. Useful if a timer is misbehaving. If there are no
11462 timers there is no error.
11463
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011464 Return type: |Number|
11465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011466 {only available when compiled with the |+timers| feature}
11467
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011469tolower({expr}) *tolower()*
11470 The result is a copy of the String given, with all uppercase
11471 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011472 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011473
11474 Can also be used as a |method|: >
11475 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011476<
11477 Return type: |String|
11478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011479
11480toupper({expr}) *toupper()*
11481 The result is a copy of the String given, with all lowercase
11482 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011483 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011484
11485 Can also be used as a |method|: >
11486 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011487<
11488 Return type: |String|
11489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011490
11491tr({src}, {fromstr}, {tostr}) *tr()*
11492 The result is a copy of the {src} string with all characters
11493 which appear in {fromstr} replaced by the character in that
11494 position in the {tostr} string. Thus the first character in
11495 {fromstr} is translated into the first character in {tostr}
11496 and so on. Exactly like the unix "tr" command.
11497 This code also deals with multibyte characters properly.
11498
Bram Moolenaard592deb2022-06-17 15:42:40 +010011499 Returns an empty string on error.
11500
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011501 Examples: >
11502 echo tr("hello there", "ht", "HT")
11503< returns "Hello THere" >
11504 echo tr("<blob>", "<>", "{}")
11505< returns "{blob}"
11506
11507 Can also be used as a |method|: >
11508 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011509<
11510 Return type: |String|
11511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011512
11513trim({text} [, {mask} [, {dir}]]) *trim()*
11514 Return {text} as a String where any character in {mask} is
11515 removed from the beginning and/or end of {text}.
11516
Illia Bobyr80799172023-10-17 18:00:50 +020011517 If {mask} is not given, or is an empty string, {mask} is all
11518 characters up to 0x20, which includes Tab, space, NL and CR,
11519 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011520
11521 The optional {dir} argument specifies where to remove the
11522 characters:
11523 0 remove from the beginning and end of {text}
11524 1 remove only at the beginning of {text}
11525 2 remove only at the end of {text}
11526 When omitted both ends are trimmed.
11527
11528 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011529 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011530
11531 Examples: >
11532 echo trim(" some text ")
11533< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011534 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011535< returns "RESERVE_TAIL" >
11536 echo trim("rm<Xrm<>X>rrm", "rm<>")
11537< returns "Xrm<>X" (characters in the middle are not removed) >
11538 echo trim(" vim ", " ", 2)
11539< returns " vim"
11540
11541 Can also be used as a |method|: >
11542 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011543<
11544 Return type: |String|
11545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011546
11547trunc({expr}) *trunc()*
11548 Return the largest integral value with magnitude less than or
11549 equal to {expr} as a |Float| (truncate towards zero).
11550 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011551 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011552 Examples: >
11553 echo trunc(1.456)
11554< 1.0 >
11555 echo trunc(-5.456)
11556< -5.0 >
11557 echo trunc(4.0)
11558< 4.0
11559
11560 Can also be used as a |method|: >
11561 Compute()->trunc()
11562<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011563 Return type: |Float|
11564
11565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011566 *type()*
11567type({expr}) The result is a Number representing the type of {expr}.
11568 Instead of using the number directly, it is better to use the
11569 v:t_ variable that has the value:
11570 Number: 0 |v:t_number|
11571 String: 1 |v:t_string|
11572 Funcref: 2 |v:t_func|
11573 List: 3 |v:t_list|
11574 Dictionary: 4 |v:t_dict|
11575 Float: 5 |v:t_float|
11576 Boolean: 6 |v:t_bool| (v:false and v:true)
11577 None: 7 |v:t_none| (v:null and v:none)
11578 Job: 8 |v:t_job|
11579 Channel: 9 |v:t_channel|
11580 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011581 Class: 12 |v:t_class|
11582 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011583 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011584 Enum: 15 |v:t_enum|
11585 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011586 For backward compatibility, this method can be used: >
11587 :if type(myvar) == type(0)
11588 :if type(myvar) == type("")
11589 :if type(myvar) == type(function("tr"))
11590 :if type(myvar) == type([])
11591 :if type(myvar) == type({})
11592 :if type(myvar) == type(0.0)
11593 :if type(myvar) == type(v:false)
11594 :if type(myvar) == type(v:none)
11595< To check if the v:t_ variables exist use this: >
11596 :if exists('v:t_number')
11597
11598< Can also be used as a |method|: >
11599 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011600<
11601 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011602
11603
11604typename({expr}) *typename()*
11605 Return a string representation of the type of {expr}.
11606 Example: >
11607 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011608< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011609
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011610 Return type: |String|
11611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011612
11613undofile({name}) *undofile()*
11614 Return the name of the undo file that would be used for a file
11615 with name {name} when writing. This uses the 'undodir'
11616 option, finding directories that exist. It does not check if
11617 the undo file exists.
11618 {name} is always expanded to the full path, since that is what
11619 is used internally.
11620 If {name} is empty undofile() returns an empty string, since a
11621 buffer without a file name will not write an undo file.
11622 Useful in combination with |:wundo| and |:rundo|.
11623 When compiled without the |+persistent_undo| option this always
11624 returns an empty string.
11625
11626 Can also be used as a |method|: >
11627 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011628<
11629 Return type: |String|
11630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011631
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011632undotree([{buf}]) *undotree()*
11633 Return the current state of the undo tree for the current
11634 buffer, or for a specific buffer if {buf} is given. The
11635 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011636 "seq_last" The highest undo sequence number used.
11637 "seq_cur" The sequence number of the current position in
11638 the undo tree. This differs from "seq_last"
11639 when some changes were undone.
11640 "time_cur" Time last used for |:earlier| and related
11641 commands. Use |strftime()| to convert to
11642 something readable.
11643 "save_last" Number of the last file write. Zero when no
11644 write yet.
11645 "save_cur" Number of the current position in the undo
11646 tree.
11647 "synced" Non-zero when the last undo block was synced.
11648 This happens when waiting from input from the
11649 user. See |undo-blocks|.
11650 "entries" A list of dictionaries with information about
11651 undo blocks.
11652
11653 The first item in the "entries" list is the oldest undo item.
11654 Each List item is a |Dictionary| with these items:
11655 "seq" Undo sequence number. Same as what appears in
11656 |:undolist|.
11657 "time" Timestamp when the change happened. Use
11658 |strftime()| to convert to something readable.
11659 "newhead" Only appears in the item that is the last one
11660 that was added. This marks the last change
11661 and where further changes will be added.
11662 "curhead" Only appears in the item that is the last one
11663 that was undone. This marks the current
11664 position in the undo tree, the block that will
11665 be used by a redo command. When nothing was
11666 undone after the last change this item will
11667 not appear anywhere.
11668 "save" Only appears on the last block before a file
11669 write. The number is the write count. The
11670 first write has number 1, the last one the
11671 "save_last" mentioned above.
11672 "alt" Alternate entry. This is again a List of undo
11673 blocks. Each item may again have an "alt"
11674 item.
11675
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011676 Return type: dict<any>
11677
11678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011679uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11680 Remove second and succeeding copies of repeated adjacent
11681 {list} items in-place. Returns {list}. If you want a list
11682 to remain unmodified make a copy first: >
11683 :let newlist = uniq(copy(mylist))
11684< The default compare function uses the string representation of
11685 each item. For the use of {func} and {dict} see |sort()|.
11686
Bram Moolenaard592deb2022-06-17 15:42:40 +010011687 Returns zero if {list} is not a |List|.
11688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011689 Can also be used as a |method|: >
11690 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011691<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011692 Return type: list<{type}>
11693
11694
Christian Brabandt67672ef2023-04-24 21:09:54 +010011695 *utf16idx()*
11696utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011697 Same as |charidx()| but returns the UTF-16 code unit index of
11698 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011699
11700 When {charidx} is present and TRUE, {idx} is used as the
11701 character index in the String {string} instead of as the byte
11702 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011703 An {idx} in the middle of a UTF-8 sequence is rounded
11704 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011705
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011706 Returns -1 if the arguments are invalid or if there are less
11707 than {idx} bytes in {string}. If there are exactly {idx} bytes
11708 the length of the string in UTF-16 code units is returned.
11709
Christian Brabandt67672ef2023-04-24 21:09:54 +010011710 See |byteidx()| and |byteidxcomp()| for getting the byte index
11711 from the UTF-16 index and |charidx()| for getting the
11712 character index from the UTF-16 index.
11713 Refer to |string-offset-encoding| for more information.
11714 Examples: >
11715 echo utf16idx('a😊😊', 3) returns 2
11716 echo utf16idx('a😊😊', 7) returns 4
11717 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11718 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11719 echo utf16idx('aą́c', 6) returns 2
11720 echo utf16idx('aą́c', 6, 1) returns 4
11721 echo utf16idx('a😊😊', 9) returns -1
11722<
11723 Can also be used as a |method|: >
11724 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011725<
11726 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011728
11729values({dict}) *values()*
11730 Return a |List| with all the values of {dict}. The |List| is
11731 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011732 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011733
11734 Can also be used as a |method|: >
11735 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011736<
11737 Return type: list<any>
11738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011739
zeertzjq825cf812023-08-17 22:55:25 +020011740virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011741 The result is a Number, which is the screen column of the file
11742 position given with {expr}. That is, the last screen position
11743 occupied by the character at that position, when the screen
11744 would be of unlimited width. When there is a <Tab> at the
11745 position, the returned Number will be the column at the end of
11746 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11747 set to 8, it returns 8. |conceal| is ignored.
11748 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011750 For the use of {expr} see |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011751
11752 When 'virtualedit' is used {expr} can be [lnum, col, off],
11753 where "off" is the offset in screen columns from the start of
11754 the character. E.g., a position within a <Tab> or after the
11755 last character. When "off" is omitted zero is used. When
11756 Virtual editing is active in the current mode, a position
11757 beyond the end of the line can be returned. Also see
11758 |'virtualedit'|
11759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011760 The accepted positions are:
11761 . the cursor position
11762 $ the end of the cursor line (the result is the
11763 number of displayed characters in the cursor line
11764 plus one)
11765 'x position of mark x (if the mark is not set, 0 is
11766 returned)
11767 v In Visual mode: the start of the Visual area (the
11768 cursor is the end). When not in Visual mode
11769 returns the cursor position. Differs from |'<| in
11770 that it's updated right away.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011771
zeertzjq825cf812023-08-17 22:55:25 +020011772 If {list} is present and non-zero then virtcol() returns a
11773 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011774 character.
11775
zeertzjq825cf812023-08-17 22:55:25 +020011776 With the optional {winid} argument the values are obtained for
11777 that window instead of the current window.
11778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011779 Note that only marks in the current file can be used.
11780 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011781 " With text "foo^Lbar" and cursor on the "^L":
11782
11783 virtcol(".") " returns 5
11784 virtcol(".", 1) " returns [4, 5]
11785 virtcol("$") " returns 9
11786
11787 " With text " there", with 't at 'h':
11788
11789 virtcol("'t") " returns 6
zeertzjq825cf812023-08-17 22:55:25 +020011790< The first column is 1. 0 or [0, 0] is returned for an error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011791 A more advanced example that echoes the maximum length of
11792 all lines: >
11793 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11794
11795< Can also be used as a |method|: >
11796 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011797<
11798 Return type: |Number|
11799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011800
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011801virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11802 The result is a Number, which is the byte index of the
11803 character in window {winid} at buffer line {lnum} and virtual
11804 column {col}.
11805
zeertzjqb583eda2023-10-14 11:32:28 +020011806 If buffer line {lnum} is an empty line, 0 is returned.
11807
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011808 If {col} is greater than the last virtual column in line
11809 {lnum}, then the byte index of the character at the last
11810 virtual column is returned.
11811
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011812 For a multi-byte character, the column number of the first
11813 byte in the character is returned.
11814
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011815 The {winid} argument can be the window number or the
11816 |window-ID|. If this is zero, then the current window is used.
11817
11818 Returns -1 if the window {winid} doesn't exist or the buffer
11819 line {lnum} or virtual column {col} is invalid.
11820
11821 See also |screenpos()|, |virtcol()| and |col()|.
11822
11823 Can also be used as a |method|: >
11824 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011825<
11826 Return type: |Number|
11827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011828
11829visualmode([{expr}]) *visualmode()*
11830 The result is a String, which describes the last Visual mode
11831 used in the current buffer. Initially it returns an empty
11832 string, but once Visual mode has been used, it returns "v",
11833 "V", or "<CTRL-V>" (a single CTRL-V character) for
11834 character-wise, line-wise, or block-wise Visual mode
11835 respectively.
11836 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011837 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011838< This enters the same Visual mode as before. It is also useful
11839 in scripts if you wish to act differently depending on the
11840 Visual mode that was used.
11841 If Visual mode is active, use |mode()| to get the Visual mode
11842 (e.g., in a |:vmap|).
11843 If {expr} is supplied and it evaluates to a non-zero Number or
11844 a non-empty String, then the Visual mode will be cleared and
11845 the old value is returned. See |non-zero-arg|.
11846
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011847 Return type: |String|
11848
11849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011850wildmenumode() *wildmenumode()*
11851 Returns |TRUE| when the wildmenu is active and |FALSE|
11852 otherwise. See 'wildmenu' and 'wildmode'.
11853 This can be used in mappings to handle the 'wildcharm' option
11854 gracefully. (Makes only sense with |mapmode-c| mappings).
11855
11856 For example to make <c-j> work like <down> in wildmode, use: >
11857 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
11858<
11859 (Note, this needs the 'wildcharm' option set appropriately).
11860
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011861 Return type: |Number|
11862
11863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011864win_execute({id}, {command} [, {silent}]) *win_execute()*
11865 Like `execute()` but in the context of window {id}.
11866 The window will temporarily be made the current window,
11867 without triggering autocommands or changing directory. When
11868 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010011869 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011870 Example: >
11871 call win_execute(winid, 'set syntax=python')
11872< Doing the same with `setwinvar()` would not trigger
11873 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011874 *E994*
11875 Not all commands are allowed in popup windows.
11876 When window {id} does not exist then no error is given and
11877 an empty string is returned.
11878
11879 Can also be used as a |method|, the base is passed as the
11880 second argument: >
11881 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011882<
11883 Return type: |String|
11884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011885
11886win_findbuf({bufnr}) *win_findbuf()*
11887 Returns a |List| with |window-ID|s for windows that contain
11888 buffer {bufnr}. When there is none the list is empty.
11889
11890 Can also be used as a |method|: >
11891 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011892<
11893 Return type: list<number> or list<any>
11894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011895
11896win_getid([{win} [, {tab}]]) *win_getid()*
11897 Get the |window-ID| for the specified window.
11898 When {win} is missing use the current window.
11899 With {win} this is the window number. The top window has
11900 number 1.
11901 Without {tab} use the current tab, otherwise the tab with
11902 number {tab}. The first tab has number one.
11903 Return zero if the window cannot be found.
11904
11905 Can also be used as a |method|: >
11906 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011907<
11908 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011909
11910
11911win_gettype([{nr}]) *win_gettype()*
11912 Return the type of the window:
11913 "autocmd" autocommand window. Temporary window
11914 used to execute autocommands.
11915 "command" command-line window |cmdwin|
11916 (empty) normal window
11917 "loclist" |location-list-window|
11918 "popup" popup window |popup|
11919 "preview" preview window |preview-window|
11920 "quickfix" |quickfix-window|
11921 "unknown" window {nr} not found
11922
11923 When {nr} is omitted return the type of the current window.
11924 When {nr} is given return the type of this window by number or
11925 |window-ID|.
11926
11927 Also see the 'buftype' option. When running a terminal in a
11928 popup window then 'buftype' is "terminal" and win_gettype()
11929 returns "popup".
11930
11931 Can also be used as a |method|: >
11932 GetWinid()->win_gettype()
11933<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011934 Return type: |String|
11935
11936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011937win_gotoid({expr}) *win_gotoid()*
11938 Go to window with ID {expr}. This may also change the current
11939 tabpage.
11940 Return TRUE if successful, FALSE if the window cannot be found.
11941
11942 Can also be used as a |method|: >
11943 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011944<
11945 Return type: |Number|
11946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011947
11948win_id2tabwin({expr}) *win_id2tabwin()*
11949 Return a list with the tab number and window number of window
11950 with ID {expr}: [tabnr, winnr].
11951 Return [0, 0] if the window cannot be found.
11952
11953 Can also be used as a |method|: >
11954 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011955<
11956 Return type: list<number>
11957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011958
11959win_id2win({expr}) *win_id2win()*
11960 Return the window number of window with ID {expr}.
11961 Return 0 if the window cannot be found in the current tabpage.
11962
11963 Can also be used as a |method|: >
11964 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011965<
11966 Return type: |Number|
11967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011968
Daniel Steinbergee630312022-01-10 13:36:34 +000011969win_move_separator({nr}, {offset}) *win_move_separator()*
11970 Move window {nr}'s vertical separator (i.e., the right border)
11971 by {offset} columns, as if being dragged by the mouse. {nr}
11972 can be a window number or |window-ID|. A positive {offset}
11973 moves right and a negative {offset} moves left. Moving a
11974 window's vertical separator will change the width of the
11975 window and the width of other windows adjacent to the vertical
11976 separator. The magnitude of movement may be smaller than
11977 specified (e.g., as a consequence of maintaining
11978 'winminwidth'). Returns TRUE if the window can be found and
11979 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011980 This will fail for the rightmost window and a full-width
11981 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000011982 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000011983
11984 Can also be used as a |method|: >
11985 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011986<
11987 Return type: |Number|
11988
Daniel Steinbergee630312022-01-10 13:36:34 +000011989
11990win_move_statusline({nr}, {offset}) *win_move_statusline()*
11991 Move window {nr}'s status line (i.e., the bottom border) by
11992 {offset} rows, as if being dragged by the mouse. {nr} can be a
11993 window number or |window-ID|. A positive {offset} moves down
11994 and a negative {offset} moves up. Moving a window's status
11995 line will change the height of the window and the height of
11996 other windows adjacent to the status line. The magnitude of
11997 movement may be smaller than specified (e.g., as a consequence
11998 of maintaining 'winminheight'). Returns TRUE if the window can
11999 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012000 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012001
12002 Can also be used as a |method|: >
12003 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012004<
12005 Return type: |Number|
12006
Daniel Steinbergee630312022-01-10 13:36:34 +000012007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012008win_screenpos({nr}) *win_screenpos()*
12009 Return the screen position of window {nr} as a list with two
12010 numbers: [row, col]. The first window always has position
12011 [1, 1], unless there is a tabline, then it is [2, 1].
12012 {nr} can be the window number or the |window-ID|. Use zero
12013 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012014 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012015
12016 Can also be used as a |method|: >
12017 GetWinid()->win_screenpos()
12018<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012019 Return type: list<number>
12020
12021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012022win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012023 Temporarily switch to window {target}, then move window {nr}
12024 to a new split adjacent to {target}.
12025 Unlike commands such as |:split|, no new windows are created
12026 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012027
12028 Both {nr} and {target} can be window numbers or |window-ID|s.
12029 Both must be in the current tab page.
12030
12031 Returns zero for success, non-zero for failure.
12032
12033 {options} is a |Dictionary| with the following optional entries:
12034 "vertical" When TRUE, the split is created vertically,
12035 like with |:vsplit|.
12036 "rightbelow" When TRUE, the split is made below or to the
12037 right (if vertical). When FALSE, it is done
12038 above or to the left (if vertical). When not
12039 present, the values of 'splitbelow' and
12040 'splitright' are used.
12041
12042 Can also be used as a |method|: >
12043 GetWinid()->win_splitmove(target)
12044<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012045 Return type: |Number|
12046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012047
12048 *winbufnr()*
12049winbufnr({nr}) The result is a Number, which is the number of the buffer
12050 associated with window {nr}. {nr} can be the window number or
12051 the |window-ID|.
12052 When {nr} is zero, the number of the buffer in the current
12053 window is returned.
12054 When window {nr} doesn't exist, -1 is returned.
12055 Example: >
12056 :echo "The file in the current window is " . bufname(winbufnr(0))
12057<
12058 Can also be used as a |method|: >
12059 FindWindow()->winbufnr()->bufname()
12060<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012061 Return type: |Number|
12062
12063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012064 *wincol()*
12065wincol() The result is a Number, which is the virtual column of the
12066 cursor in the window. This is counting screen cells from the
12067 left side of the window. The leftmost column is one.
12068
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012069 Return type: |Number|
12070
12071
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012072 *windowsversion()*
12073windowsversion()
12074 The result is a String. For MS-Windows it indicates the OS
12075 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12076 Windows XP is "5.1". For non-MS-Windows systems the result is
12077 an empty string.
12078
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012079 Return type: |String|
12080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012081winheight({nr}) *winheight()*
12082 The result is a Number, which is the height of window {nr}.
12083 {nr} can be the window number or the |window-ID|.
12084 When {nr} is zero, the height of the current window is
12085 returned. When window {nr} doesn't exist, -1 is returned.
12086 An existing window always has a height of zero or more.
12087 This excludes any window toolbar line.
12088 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012089 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012090
12091< Can also be used as a |method|: >
12092 GetWinid()->winheight()
12093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012094 Return type: |Number|
12095
12096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012097winlayout([{tabnr}]) *winlayout()*
12098 The result is a nested List containing the layout of windows
12099 in a tabpage.
12100
12101 Without {tabnr} use the current tabpage, otherwise the tabpage
12102 with number {tabnr}. If the tabpage {tabnr} is not found,
12103 returns an empty list.
12104
12105 For a leaf window, it returns:
12106 ['leaf', {winid}]
12107 For horizontally split windows, which form a column, it
12108 returns:
12109 ['col', [{nested list of windows}]]
12110 For vertically split windows, which form a row, it returns:
12111 ['row', [{nested list of windows}]]
12112
12113 Example: >
12114 " Only one window in the tab page
12115 :echo winlayout()
12116 ['leaf', 1000]
12117 " Two horizontally split windows
12118 :echo winlayout()
12119 ['col', [['leaf', 1000], ['leaf', 1001]]]
12120 " The second tab page, with three horizontally split
12121 " windows, with two vertically split windows in the
12122 " middle window
12123 :echo winlayout(2)
12124 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12125 ['leaf', 1001]]], ['leaf', 1000]]]
12126<
12127 Can also be used as a |method|: >
12128 GetTabnr()->winlayout()
12129<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012130 Return type: list<any>
12131
12132
12133winline() *winline()*
12134 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012135 in the window. This is counting screen lines from the top of
12136 the window. The first line is one.
12137 If the cursor was moved the view on the file will be updated
12138 first, this may cause a scroll.
12139
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012140 Return type: |Number|
12141
12142
12143winnr([{arg}]) *winnr()*
12144 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012145 window. The top window has number 1.
12146 Returns zero for a popup window.
12147
12148 The optional argument {arg} supports the following values:
12149 $ the number of the last window (the window
12150 count).
12151 # the number of the last accessed window (where
12152 |CTRL-W_p| goes to). If there is no previous
12153 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012154 returned. May refer to the current window in
12155 some cases (e.g. when evaluating 'statusline'
12156 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012157 {N}j the number of the Nth window below the
12158 current window (where |CTRL-W_j| goes to).
12159 {N}k the number of the Nth window above the current
12160 window (where |CTRL-W_k| goes to).
12161 {N}h the number of the Nth window left of the
12162 current window (where |CTRL-W_h| goes to).
12163 {N}l the number of the Nth window right of the
12164 current window (where |CTRL-W_l| goes to).
12165 The number can be used with |CTRL-W_w| and ":wincmd w"
12166 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012167 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012168 Also see |tabpagewinnr()| and |win_getid()|.
12169 Examples: >
12170 let window_count = winnr('$')
12171 let prev_window = winnr('#')
12172 let wnum = winnr('3k')
12173
12174< Can also be used as a |method|: >
12175 GetWinval()->winnr()
12176<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012177 Return type: |Number|
12178
12179
12180winrestcmd() *winrestcmd()*
12181 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012182 the current window sizes. Only works properly when no windows
12183 are opened or closed and the current window and tab page is
12184 unchanged.
12185 Example: >
12186 :let cmd = winrestcmd()
12187 :call MessWithWindowSizes()
12188 :exe cmd
12189<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012190 Return type: |String|
12191
12192
12193winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012194 Uses the |Dictionary| returned by |winsaveview()| to restore
12195 the view of the current window.
12196 Note: The {dict} does not have to contain all values, that are
12197 returned by |winsaveview()|. If values are missing, those
12198 settings won't be restored. So you can use: >
12199 :call winrestview({'curswant': 4})
12200<
12201 This will only set the curswant value (the column the cursor
12202 wants to move on vertical movements) of the cursor to column 5
12203 (yes, that is 5), while all other settings will remain the
12204 same. This is useful, if you set the cursor position manually.
12205
12206 If you have changed the values the result is unpredictable.
12207 If the window size changed the result won't be the same.
12208
12209 Can also be used as a |method|: >
12210 GetView()->winrestview()
12211<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012212 Return type: |Number|
12213
12214
12215winsaveview() *winsaveview()*
12216 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012217 the view of the current window. Use |winrestview()| to
12218 restore the view.
12219 This is useful if you have a mapping that jumps around in the
12220 buffer and you want to go back to the original view.
12221 This does not save fold information. Use the 'foldenable'
12222 option to temporarily switch off folding, so that folds are
12223 not opened when moving around. This may have side effects.
12224 The return value includes:
12225 lnum cursor line number
12226 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012227 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012228 returns)
12229 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012230 curswant column for vertical movement (Note:
12231 the first column is zero, as opposed
12232 to what |getcurpos()| returns). After
12233 |$| command it will be a very large
12234 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012235 topline first line in the window
12236 topfill filler lines, only in diff mode
12237 leftcol first column displayed; only used when
12238 'wrap' is off
12239 skipcol columns skipped
12240 Note that no option values are saved.
12241
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012242 Return type: dict<number>
12243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012244
12245winwidth({nr}) *winwidth()*
12246 The result is a Number, which is the width of window {nr}.
12247 {nr} can be the window number or the |window-ID|.
12248 When {nr} is zero, the width of the current window is
12249 returned. When window {nr} doesn't exist, -1 is returned.
12250 An existing window always has a width of zero or more.
12251 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012252 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012253 :if winwidth(0) <= 50
12254 : 50 wincmd |
12255 :endif
12256< For getting the terminal or screen size, see the 'columns'
12257 option.
12258
12259 Can also be used as a |method|: >
12260 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012261<
12262 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012263
12264
12265wordcount() *wordcount()*
12266 The result is a dictionary of byte/chars/word statistics for
12267 the current buffer. This is the same info as provided by
12268 |g_CTRL-G|
12269 The return value includes:
12270 bytes Number of bytes in the buffer
12271 chars Number of chars in the buffer
12272 words Number of words in the buffer
12273 cursor_bytes Number of bytes before cursor position
12274 (not in Visual mode)
12275 cursor_chars Number of chars before cursor position
12276 (not in Visual mode)
12277 cursor_words Number of words before cursor position
12278 (not in Visual mode)
12279 visual_bytes Number of bytes visually selected
12280 (only in Visual mode)
12281 visual_chars Number of chars visually selected
12282 (only in Visual mode)
12283 visual_words Number of words visually selected
12284 (only in Visual mode)
12285
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012286 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012287
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012288
12289writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012290 When {object} is a |List| write it to file {fname}. Each list
12291 item is separated with a NL. Each list item must be a String
12292 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012293 All NL characters are replaced with a NUL character.
12294 Inserting CR characters needs to be done before passing {list}
12295 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012296
12297 When {object} is a |Blob| write the bytes to file {fname}
12298 unmodified, also when binary mode is not specified.
12299
12300 {flags} must be a String. These characters are recognized:
12301
12302 'b' Binary mode is used: There will not be a NL after the
12303 last list item. An empty item at the end does cause the
12304 last line in the file to end in a NL.
12305
12306 'a' Append mode is used, lines are appended to the file: >
12307 :call writefile(["foo"], "event.log", "a")
12308 :call writefile(["bar"], "event.log", "a")
12309<
12310 'D' Delete the file when the current function ends. This
12311 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012312 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012313< Fails when not in a function. Also see |:defer|.
12314
12315 's' fsync() is called after writing the file. This flushes
12316 the file to disk, if possible. This takes more time but
12317 avoids losing the file if the system crashes.
12318
12319 'S' fsync() is not called, even when 'fsync' is set.
12320
12321 When {flags} does not contain "S" or "s" then fsync() is
12322 called if the 'fsync' option is set.
12323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012324 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012326 When the write fails -1 is returned, otherwise 0. There is an
12327 error message if the file can't be created or when writing
12328 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012330 Also see |readfile()|.
12331 To copy a file byte for byte: >
12332 :let fl = readfile("foo", "b")
12333 :call writefile(fl, "foocopy", "b")
12334
12335< Can also be used as a |method|: >
12336 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012337<
12338 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012339
12340
12341xor({expr}, {expr}) *xor()*
12342 Bitwise XOR on the two arguments. The arguments are converted
12343 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012344 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012345 Example: >
12346 :let bits = xor(bits, 0x80)
12347<
12348 Can also be used as a |method|: >
12349 :let bits = bits->xor(0x80)
12350<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012351 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012352
12353==============================================================================
123543. Feature list *feature-list*
12355
12356There are three types of features:
123571. Features that are only supported when they have been enabled when Vim
12358 was compiled |+feature-list|. Example: >
12359 :if has("cindent")
12360< *gui_running*
123612. Features that are only supported when certain conditions have been met.
12362 Example: >
12363 :if has("gui_running")
12364< *has-patch*
123653. Beyond a certain version or at a certain version and including a specific
12366 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12367 later, or it is version 7.4 and patch 248 was included. Example: >
12368 :if has("patch-7.4.248")
12369< Note that it's possible for patch 248 to be omitted even though 249 is
12370 included. Only happens when cherry-picking patches.
12371 Note that this form only works for patch 7.4.237 and later, before that
12372 you need to check for the patch and the v:version. Example (checking
12373 version 6.2.148 or later): >
12374 :if v:version > 602 || (v:version == 602 && has("patch148"))
12375
12376Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12377use: `if exists('+shellslash')`
12378
12379
12380acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012381all_builtin_terms Compiled with all builtin terminals enabled. (always
12382 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012383amiga Amiga version of Vim.
12384arabic Compiled with Arabic support |Arabic|.
12385arp Compiled with ARP support (Amiga).
12386autocmd Compiled with autocommand support. (always true)
12387autochdir Compiled with support for 'autochdir'
12388autoservername Automatically enable |clientserver|
12389balloon_eval Compiled with |balloon-eval| support.
12390balloon_multiline GUI supports multiline balloons.
12391beos BeOS version of Vim.
12392browse Compiled with |:browse| support, and browse() will
12393 work.
12394browsefilter Compiled with support for |browsefilter|.
12395bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012396builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012397byte_offset Compiled with support for 'o' in 'statusline'
12398channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012399cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012400clientserver Compiled with remote invocation support |clientserver|.
12401clipboard Compiled with 'clipboard' support.
12402clipboard_working Compiled with 'clipboard' support and it can be used.
12403cmdline_compl Compiled with |cmdline-completion| support.
12404cmdline_hist Compiled with |cmdline-history| support.
12405cmdline_info Compiled with 'showcmd' and 'ruler' support.
12406comments Compiled with |'comments'| support.
12407compatible Compiled to be very Vi compatible.
12408conpty Platform where |ConPTY| can be used.
12409cryptv Compiled with encryption support |encryption|.
12410cscope Compiled with |cscope| support.
12411cursorbind Compiled with |'cursorbind'| (always true)
12412debug Compiled with "DEBUG" defined.
12413dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012414dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012415dialog_gui Compiled with GUI dialog support.
12416diff Compiled with |vimdiff| and 'diff' support.
12417digraphs Compiled with support for digraphs.
12418directx Compiled with support for DirectX and 'renderoptions'.
12419dnd Compiled with support for the "~ register |quote_~|.
12420drop_file Compiled with |drop_file| support.
12421ebcdic Compiled on a machine with ebcdic character set.
12422emacs_tags Compiled with support for Emacs tags.
12423eval Compiled with expression evaluation support. Always
12424 true, of course!
12425ex_extra |+ex_extra| (always true)
12426extra_search Compiled with support for |'incsearch'| and
12427 |'hlsearch'|
12428farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012429file_in_path Compiled with support for |gf| and |<cfile>| (always
12430 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012431filterpipe When 'shelltemp' is off pipes are used for shell
12432 read/write/filter commands
12433find_in_path Compiled with support for include file searches
12434 |+find_in_path|.
12435float Compiled with support for |Float|.
12436fname_case Case in file names matters (for Amiga and MS-Windows
12437 this is not present).
12438folding Compiled with |folding| support.
12439footer Compiled with GUI footer support. |gui-footer|
12440fork Compiled to use fork()/exec() instead of system().
12441gettext Compiled with message translation |multi-lang|
12442gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012443gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012444gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12445gui_gtk Compiled with GTK+ GUI (any version).
12446gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12447gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12448gui_haiku Compiled with Haiku GUI.
12449gui_mac Compiled with Macintosh GUI.
12450gui_motif Compiled with Motif GUI.
12451gui_photon Compiled with Photon GUI.
12452gui_running Vim is running in the GUI, or it will start soon.
12453gui_win32 Compiled with MS-Windows Win32 GUI.
12454gui_win32s idem, and Win32s system being used (Windows 3.1)
12455haiku Haiku version of Vim.
12456hangul_input Compiled with Hangul input support. |hangul|
12457hpux HP-UX version of Vim.
12458iconv Can use iconv() for conversion.
12459insert_expand Compiled with support for CTRL-X expansion commands in
12460 Insert mode. (always true)
12461job Compiled with support for |channel| and |job|
12462ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012463jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012464keymap Compiled with 'keymap' support.
12465lambda Compiled with |lambda| support.
12466langmap Compiled with 'langmap' support.
12467libcall Compiled with |libcall()| support.
12468linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12469 'breakindent' support.
12470linux Linux version of Vim.
12471lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012472 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012473listcmds Compiled with commands for the buffer list |:files|
12474 and the argument list |arglist|.
12475localmap Compiled with local mappings and abbr. |:map-local|
12476lua Compiled with Lua interface |Lua|.
12477mac Any Macintosh version of Vim cf. osx
12478macunix Synonym for osxdarwin
12479menu Compiled with support for |:menu|.
12480mksession Compiled with support for |:mksession|.
12481modify_fname Compiled with file name modifiers. |filename-modifiers|
12482 (always true)
12483mouse Compiled with support for mouse.
12484mouse_dec Compiled with support for Dec terminal mouse.
12485mouse_gpm Compiled with support for gpm (Linux console mouse)
12486mouse_gpm_enabled GPM mouse is working
12487mouse_netterm Compiled with support for netterm mouse.
12488mouse_pterm Compiled with support for qnx pterm mouse.
12489mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12490mouse_sgr Compiled with support for sgr mouse.
12491mouse_urxvt Compiled with support for urxvt mouse.
12492mouse_xterm Compiled with support for xterm mouse.
12493mouseshape Compiled with support for 'mouseshape'.
12494multi_byte Compiled with support for 'encoding' (always true)
12495multi_byte_encoding 'encoding' is set to a multibyte encoding.
12496multi_byte_ime Compiled with support for IME input method.
12497multi_lang Compiled with support for multiple languages.
12498mzscheme Compiled with MzScheme interface |mzscheme|.
12499nanotime Compiled with sub-second time stamp checks.
12500netbeans_enabled Compiled with support for |netbeans| and connected.
12501netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012502num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012503ole Compiled with OLE automation support for Win32.
12504osx Compiled for macOS cf. mac
12505osxdarwin Compiled for macOS, with |mac-darwin-feature|
12506packages Compiled with |packages| support.
12507path_extra Compiled with up/downwards search in 'path' and 'tags'
12508perl Compiled with Perl interface.
12509persistent_undo Compiled with support for persistent undo history.
12510postscript Compiled with PostScript file printing.
12511printer Compiled with |:hardcopy| support.
12512profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012513prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012514python Python 2.x interface available. |has-python|
12515python_compiled Compiled with Python 2.x interface. |has-python|
12516python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12517python3 Python 3.x interface available. |has-python|
12518python3_compiled Compiled with Python 3.x interface. |has-python|
12519python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012520python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012521pythonx Python 2.x and/or 3.x interface available. |python_x|
12522qnx QNX version of Vim.
12523quickfix Compiled with |quickfix| support.
12524reltime Compiled with |reltime()| support.
12525rightleft Compiled with 'rightleft' support.
12526ruby Compiled with Ruby interface |ruby|.
12527scrollbind Compiled with 'scrollbind' support. (always true)
12528showcmd Compiled with 'showcmd' support.
12529signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012530smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012531sodium Compiled with libsodium for better crypt support
12532sound Compiled with sound support, e.g. `sound_playevent()`
12533spell Compiled with spell checking support |spell|.
12534startuptime Compiled with |--startuptime| support.
12535statusline Compiled with support for 'statusline', 'rulerformat'
12536 and special formats of 'titlestring' and 'iconstring'.
12537sun SunOS version of Vim.
12538sun_workshop Support for Sun |workshop| has been removed.
12539syntax Compiled with syntax highlighting support |syntax|.
12540syntax_items There are active syntax highlighting items for the
12541 current buffer.
12542system Compiled to use system() instead of fork()/exec().
12543tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012544 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012545tag_old_static Support for old static tags was removed, see
12546 |tag-old-static|.
12547tcl Compiled with Tcl interface.
12548termguicolors Compiled with true color in terminal support.
12549terminal Compiled with |terminal| support.
12550terminfo Compiled with terminfo instead of termcap.
12551termresponse Compiled with support for |t_RV| and |v:termresponse|.
12552textobjects Compiled with support for |text-objects|.
12553textprop Compiled with support for |text-properties|.
12554tgetent Compiled with tgetent support, able to use a termcap
12555 or terminfo file.
12556timers Compiled with |timer_start()| support.
12557title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012558 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012559toolbar Compiled with support for |gui-toolbar|.
12560ttyin input is a terminal (tty)
12561ttyout output is a terminal (tty)
12562unix Unix version of Vim. *+unix*
12563unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12564user_commands User-defined commands. (always true)
12565vartabs Compiled with variable tabstop support |'vartabstop'|.
12566vcon Win32: Virtual console support is working, can use
12567 'termguicolors'. Also see |+vtp|.
12568vertsplit Compiled with vertically split windows |:vsplit|.
12569 (always true)
12570vim_starting True while initial source'ing takes place. |startup|
12571 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012572vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012573viminfo Compiled with viminfo support.
12574vimscript-1 Compiled Vim script version 1 support
12575vimscript-2 Compiled Vim script version 2 support
12576vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012577vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012578virtualedit Compiled with 'virtualedit' option. (always true)
12579visual Compiled with Visual mode. (always true)
12580visualextra Compiled with extra Visual mode commands. (always
12581 true) |blockwise-operators|.
12582vms VMS version of Vim.
12583vreplace Compiled with |gR| and |gr| commands. (always true)
12584vtp Compiled for vcon support |+vtp| (check vcon to find
12585 out if it works in the current console).
12586wildignore Compiled with 'wildignore' option.
12587wildmenu Compiled with 'wildmenu' option.
12588win16 old version for MS-Windows 3.1 (always false)
12589win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12590 64 bits)
12591win32unix Win32 version of Vim, using Unix files (Cygwin)
12592win64 Win64 version of Vim (MS-Windows 64 bit).
12593win95 Win32 version for MS-Windows 95/98/ME (always false)
12594winaltkeys Compiled with 'winaltkeys' option.
12595windows Compiled with support for more than one window.
12596 (always true)
12597writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012598xattr Compiled with extended attributes support |xattr|
12599 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012600xfontset Compiled with X fontset support |xfontset|.
12601xim Compiled with X input method support |xim|.
12602xpm Compiled with pixmap support.
12603xpm_w32 Compiled with pixmap support for Win32. (Only for
12604 backward compatibility. Use "xpm" instead.)
12605xsmp Compiled with X session management support.
12606xsmp_interact Compiled with interactive X session management support.
12607xterm_clipboard Compiled with support for xterm clipboard.
12608xterm_save Compiled with support for saving and restoring the
12609 xterm screen.
12610x11 Compiled with X11 support.
12611
12612
12613==============================================================================
126144. Matching a pattern in a String *string-match*
12615
12616This is common between several functions. A regexp pattern as explained at
12617|pattern| is normally used to find a match in the buffer lines. When a
12618pattern is used to find a match in a String, almost everything works in the
12619same way. The difference is that a String is handled like it is one line.
12620When it contains a "\n" character, this is not seen as a line break for the
12621pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12622>
12623 :let a = "aaaa\nxxxx"
12624 :echo matchstr(a, "..\n..")
12625 aa
12626 xx
12627 :echo matchstr(a, "a.x")
12628 a
12629 x
12630
12631Don't forget that "^" will only match at the first character of the String and
12632"$" at the last character of the string. They don't match after or before a
12633"\n".
12634
12635 vim:tw=78:ts=8:noet:ft=help:norl: