blob: 9d010150a6a6574b6f934aaaa8fa854ae2cd7caa [file] [log] [blame]
glepnird4088ed2024-12-31 10:55:22 +01001*builtin.txt* For Vim version 9.1. Last change: 2024 Dec 31
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}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{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
Yegappan Lakshmanan810785c2024-12-30 10:29:44 +010070base64_decode({string}) Blob base-64 decode {string} characters
71base64_encode({blob}) String base-64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
75browse({save}, {title}, {initdir}, {default})
76 String put up a file requester
77browsedir({title}, {initdir}) String put up a directory requester
78bufadd({name}) Number add a buffer to the buffer list
79bufexists({buf}) Number |TRUE| if buffer {buf} exists
80buflisted({buf}) Number |TRUE| if buffer {buf} is listed
81bufload({buf}) Number load buffer {buf} if not loaded yet
82bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
83bufname([{buf}]) String Name of the buffer {buf}
84bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
85bufwinid({buf}) Number window ID of buffer {buf}
86bufwinnr({buf}) Number window number of buffer {buf}
87byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010088byteidx({expr}, {nr} [, {utf16}])
89 Number byte index of {nr}'th char in {expr}
90byteidxcomp({expr}, {nr} [, {utf16}])
91 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000092call({func}, {arglist} [, {dict}])
93 any call {func} with arguments {arglist}
94ceil({expr}) Float round {expr} up
95ch_canread({handle}) Number check if there is something to read
96ch_close({handle}) none close {handle}
97ch_close_in({handle}) none close in part of {handle}
98ch_evalexpr({handle}, {expr} [, {options}])
99 any evaluate {expr} on JSON {handle}
100ch_evalraw({handle}, {string} [, {options}])
101 any evaluate {string} on raw {handle}
102ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
103ch_getjob({channel}) Job get the Job of {channel}
104ch_info({handle}) String info about channel {handle}
105ch_log({msg} [, {handle}]) none write {msg} in the channel log file
106ch_logfile({fname} [, {mode}]) none start logging channel activity
107ch_open({address} [, {options}])
108 Channel open a channel to {address}
109ch_read({handle} [, {options}]) String read from {handle}
110ch_readblob({handle} [, {options}])
111 Blob read Blob from {handle}
112ch_readraw({handle} [, {options}])
113 String read raw from {handle}
114ch_sendexpr({handle}, {expr} [, {options}])
115 any send {expr} over JSON {handle}
116ch_sendraw({handle}, {expr} [, {options}])
117 any send {expr} over raw {handle}
118ch_setoptions({handle}, {options})
119 none set options for {handle}
120ch_status({handle} [, {options}])
121 String status of channel {handle}
122changenr() Number current change number
123char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
124charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000125charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100126charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000127 Number char index of byte {idx} in {string}
128chdir({dir}) String change current working directory
129cindent({lnum}) Number C indent for line {lnum}
130clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000131col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000132complete({startcol}, {matches}) none set Insert mode completion
133complete_add({expr}) Number add completion match
134complete_check() Number check for key typed during completion
135complete_info([{what}]) Dict get current completion information
136confirm({msg} [, {choices} [, {default} [, {type}]]])
137 Number number of choice picked by user
138copy({expr}) any make a shallow copy of {expr}
139cos({expr}) Float cosine of {expr}
140cosh({expr}) Float hyperbolic cosine of {expr}
141count({comp}, {expr} [, {ic} [, {start}]])
142 Number count how many {expr} are in {comp}
143cscope_connection([{num}, {dbpath} [, {prepend}]])
144 Number checks existence of cscope connection
145cursor({lnum}, {col} [, {off}])
146 Number move cursor to {lnum}, {col}, {off}
147cursor({list}) Number move cursor to position in {list}
148debugbreak({pid}) Number interrupt process being debugged
149deepcopy({expr} [, {noref}]) any make a full copy of {expr}
150delete({fname} [, {flags}]) Number delete the file or directory {fname}
151deletebufline({buf}, {first} [, {last}])
152 Number delete lines from buffer {buf}
153did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100154diff({fromlist}, {tolist} [, {options}])
155 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000156diff_filler({lnum}) Number diff filler lines about {lnum}
157diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
158digraph_get({chars}) String get the |digraph| of {chars}
159digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200160digraph_set({chars}, {digraph}) Bool register |digraph|
161digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000162echoraw({expr}) none output {expr} as-is
163empty({expr}) Number |TRUE| if {expr} is empty
164environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100165err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000166escape({string}, {chars}) String escape {chars} in {string} with '\'
167eval({string}) any evaluate {string} into its value
168eventhandler() Number |TRUE| if inside an event handler
169executable({expr}) Number 1 if executable {expr} exists
170execute({command}) String execute {command} and get the output
171exepath({expr}) String full path of the command {expr}
172exists({expr}) Number |TRUE| if {expr} exists
173exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
174exp({expr}) Float exponential of {expr}
175expand({expr} [, {nosuf} [, {list}]])
176 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100177expandcmd({string} [, {options}])
178 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000179extend({expr1}, {expr2} [, {expr3}])
180 List/Dict insert items of {expr2} into {expr1}
181extendnew({expr1}, {expr2} [, {expr3}])
182 List/Dict like |extend()| but creates a new
183 List or Dictionary
184feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200185filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
186 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000187filereadable({file}) Number |TRUE| if {file} is a readable file
188filewritable({file}) Number |TRUE| if {file} is a writable file
189filter({expr1}, {expr2}) List/Dict/Blob/String
190 remove items from {expr1} where
191 {expr2} is 0
192finddir({name} [, {path} [, {count}]])
193 String find directory {name} in {path}
194findfile({name} [, {path} [, {count}]])
195 String find file {name} in {path}
196flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
197flattennew({list} [, {maxdepth}])
198 List flatten a copy of {list}
199float2nr({expr}) Number convert Float {expr} to a Number
200floor({expr}) Float round {expr} down
201fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
202fnameescape({fname}) String escape special characters in {fname}
203fnamemodify({fname}, {mods}) String modify file name
204foldclosed({lnum}) Number first line of fold at {lnum} if closed
205foldclosedend({lnum}) Number last line of fold at {lnum} if closed
206foldlevel({lnum}) Number fold level at {lnum}
207foldtext() String line displayed for closed fold
208foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100209foreach({expr1}, {expr2}) List/Dict/Blob/String
210 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000211foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100212fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000213funcref({name} [, {arglist}] [, {dict}])
214 Funcref reference to function {name}
215function({name} [, {arglist}] [, {dict}])
216 Funcref named reference to function {name}
217garbagecollect([{atexit}]) none free memory, breaking cyclic references
218get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
219get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
220get({func}, {what}) any get property of funcref/partial {func}
221getbufinfo([{buf}]) List information about buffers
222getbufline({buf}, {lnum} [, {end}])
223 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000224getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000225getbufvar({buf}, {varname} [, {def}])
226 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100227getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000228getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000229getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200230getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000231 get one character from the user
232getcharmod() Number modifiers for the last typed character
233getcharpos({expr}) List position of cursor, mark, etc.
234getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200235getcharstr([{expr}]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200236getcmdcomplpat() String return the completion pattern of the
237 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100238getcmdcompltype() String return the type of the current
239 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200240getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000241getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200242getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100243getcmdscreenpos() Number return cursor screen position in
244 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000245getcmdtype() String return current command-line type
246getcmdwintype() String return current command-line window type
247getcompletion({pat}, {type} [, {filtered}])
248 List list of cmdline completion matches
249getcurpos([{winnr}]) List position of the cursor
250getcursorcharpos([{winnr}]) List character position of the cursor
251getcwd([{winnr} [, {tabnr}]]) String get the current working directory
252getenv({name}) String return environment variable
253getfontname([{name}]) String name of font being used
254getfperm({fname}) String file permissions of file {fname}
255getfsize({fname}) Number size in bytes of file {fname}
256getftime({fname}) Number last modification time of file
257getftype({fname}) String description of type of file {fname}
258getimstatus() Number |TRUE| if the IME status is active
259getjumplist([{winnr} [, {tabnr}]])
260 List list of jump list items
261getline({lnum}) String line {lnum} of current buffer
262getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
263getloclist({nr}) List list of location list items
264getloclist({nr}, {what}) Dict get specific location list properties
265getmarklist([{buf}]) List list of global/local marks
266getmatches([{win}]) List list of current matches
267getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000268getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000269getpid() Number process ID of Vim
270getpos({expr}) List position of cursor, mark, etc.
271getqflist() List list of quickfix items
272getqflist({what}) Dict get specific quickfix list properties
273getreg([{regname} [, 1 [, {list}]]])
274 String or List contents of a register
275getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100276getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100277 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200278getregionpos({pos1}, {pos2} [, {opts}])
279 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000280getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100281getscriptinfo([{opts}]) List list of sourced scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000282gettabinfo([{expr}]) List list of tab pages
283gettabvar({nr}, {varname} [, {def}])
284 any variable {varname} in tab {nr} or {def}
285gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
286 any {name} in {winnr} in tab page {tabnr}
287gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200288gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000289getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000290getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwinposx() Number X coord in pixels of the Vim window
292getwinposy() Number Y coord in pixels of the Vim window
293getwinvar({nr}, {varname} [, {def}])
294 any variable {varname} in window {nr}
295glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
296 any expand file wildcards in {expr}
297glob2regpat({expr}) String convert a glob pat into a search pat
298globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
299 String do glob({expr}) for all dirs in {path}
300has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
301has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
302haslocaldir([{winnr} [, {tabnr}]])
303 Number |TRUE| if the window executed |:lcd|
304 or |:tcd|
305hasmapto({what} [, {mode} [, {abbr}]])
306 Number |TRUE| if mapping to {what} exists
307histadd({history}, {item}) Number add an item to a history
308histdel({history} [, {item}]) Number remove an item from a history
309histget({history} [, {index}]) String get the item {index} from a history
310histnr({history}) Number highest index of a history
311hlID({name}) Number syntax ID of highlight group {name}
312hlexists({name}) Number |TRUE| if highlight group {name} exists
313hlget([{name} [, {resolve}]]) List get highlight group attributes
314hlset({list}) Number set highlight group attributes
315hostname() String name of the machine Vim is running on
316iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200317id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000318indent({lnum}) Number indent of line {lnum}
319index({object}, {expr} [, {start} [, {ic}]])
320 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100321indexof({object}, {expr} [, {opts}]])
322 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000323input({prompt} [, {text} [, {completion}]])
324 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100325inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000326 String like input() but in a GUI dialog
327inputlist({textlist}) Number let the user pick from a choice list
328inputrestore() Number restore typeahead
329inputsave() Number save and clear typeahead
330inputsecret({prompt} [, {text}]) String like input() but hiding the text
331insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200332instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000333interrupt() none interrupt script execution
334invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100335isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000336isdirectory({directory}) Number |TRUE| if {directory} is a directory
337isinf({expr}) Number determine if {expr} is infinity value
338 (positive or negative)
339islocked({expr}) Number |TRUE| if {expr} is locked
340isnan({expr}) Number |TRUE| if {expr} is NaN
341items({dict}) List key-value pairs in {dict}
342job_getchannel({job}) Channel get the channel handle for {job}
343job_info([{job}]) Dict get information about {job}
344job_setoptions({job}, {options}) none set options for {job}
345job_start({command} [, {options}])
346 Job start a job
347job_status({job}) String get the status of {job}
348job_stop({job} [, {how}]) Number stop {job}
349join({list} [, {sep}]) String join {list} items into one String
350js_decode({string}) any decode JS style JSON
351js_encode({expr}) String encode JS style JSON
352json_decode({string}) any decode JSON
353json_encode({expr}) String encode JSON
354keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100355keytrans({string}) String translate internal keycodes to a form
356 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000357len({expr}) Number the length of {expr}
358libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
359libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
360line({expr} [, {winid}]) Number line nr of cursor, last line or mark
361line2byte({lnum}) Number byte count of line {lnum}
362lispindent({lnum}) Number Lisp indent for line {lnum}
363list2blob({list}) Blob turn {list} of numbers into a Blob
364list2str({list} [, {utf8}]) String turn {list} of numbers into a String
365listener_add({callback} [, {buf}])
366 Number add a callback to listen to changes
367listener_flush([{buf}]) none invoke listener callbacks
368listener_remove({id}) none remove a listener callback
369localtime() Number current time
370log({expr}) Float natural logarithm (base e) of {expr}
371log10({expr}) Float logarithm of Float {expr} to base 10
372luaeval({expr} [, {expr}]) any evaluate |Lua| expression
373map({expr1}, {expr2}) List/Dict/Blob/String
374 change each item in {expr1} to {expr2}
375maparg({name} [, {mode} [, {abbr} [, {dict}]]])
376 String or Dict
377 rhs of mapping {name} in mode {mode}
378mapcheck({name} [, {mode} [, {abbr}]])
379 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100380maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000381mapnew({expr1}, {expr2}) List/Dict/Blob/String
382 like |map()| but creates a new List or
383 Dictionary
384mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
385match({expr}, {pat} [, {start} [, {count}]])
386 Number position where {pat} matches in {expr}
387matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
388 Number highlight {pattern} with {group}
389matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
390 Number highlight positions with {group}
391matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100392matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
393 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000394matchdelete({id} [, {win}]) Number delete match identified by {id}
395matchend({expr}, {pat} [, {start} [, {count}]])
396 Number position where {pat} ends in {expr}
397matchfuzzy({list}, {str} [, {dict}])
398 List fuzzy match {str} in {list}
399matchfuzzypos({list}, {str} [, {dict}])
400 List fuzzy match {str} in {list}
401matchlist({expr}, {pat} [, {start} [, {count}]])
402 List match and submatches of {pat} in {expr}
403matchstr({expr}, {pat} [, {start} [, {count}]])
404 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100405matchstrlist({list}, {pat} [, {dict})
406 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000407matchstrpos({expr}, {pat} [, {start} [, {count}]])
408 List {count}'th match of {pat} in {expr}
409max({expr}) Number maximum value of items in {expr}
410menu_info({name} [, {mode}]) Dict get menu item information
411min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000412mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000413 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200414mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000415mzeval({expr}) any evaluate |MzScheme| expression
416nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
417nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
418or({expr}, {expr}) Number bitwise OR
419pathshorten({expr} [, {len}]) String shorten directory names in a path
420perleval({expr}) any evaluate |Perl| expression
421popup_atcursor({what}, {options}) Number create popup window near the cursor
422popup_beval({what}, {options}) Number create popup window for 'ballooneval'
423popup_clear() none close all popup windows
424popup_close({id} [, {result}]) none close popup window {id}
425popup_create({what}, {options}) Number create a popup window
426popup_dialog({what}, {options}) Number create a popup window used as a dialog
427popup_filter_menu({id}, {key}) Number filter for a menu popup window
428popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100429popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000430popup_findinfo() Number get window ID of info popup window
431popup_findpreview() Number get window ID of preview popup window
432popup_getoptions({id}) Dict get options of popup window {id}
433popup_getpos({id}) Dict get position of popup window {id}
434popup_hide({id}) none hide popup menu {id}
435popup_list() List get a list of window IDs of all popups
436popup_locate({row}, {col}) Number get window ID of popup at position
437popup_menu({what}, {options}) Number create a popup window used as a menu
438popup_move({id}, {options}) none set position of popup window {id}
439popup_notification({what}, {options})
440 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200441popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000442popup_setoptions({id}, {options})
443 none set options for popup window {id}
444popup_settext({id}, {text}) none set the text of popup window {id}
445popup_show({id}) none unhide popup window {id}
446pow({x}, {y}) Float {x} to the power of {y}
447prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
448printf({fmt}, {expr1}...) String format text
449prompt_getprompt({buf}) String get prompt text
450prompt_setcallback({buf}, {expr}) none set prompt callback function
451prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
452prompt_setprompt({buf}, {text}) none set prompt text
453prop_add({lnum}, {col}, {props}) none add one text property
454prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
455 none add multiple text properties
456prop_clear({lnum} [, {lnum-end} [, {props}]])
457 none remove all text properties
458prop_find({props} [, {direction}])
459 Dict search for a text property
460prop_list({lnum} [, {props}]) List text properties in {lnum}
461prop_remove({props} [, {lnum} [, {lnum-end}]])
462 Number remove a text property
463prop_type_add({name}, {props}) none define a new property type
464prop_type_change({name}, {props})
465 none change an existing property type
466prop_type_delete({name} [, {props}])
467 none delete a property type
468prop_type_get({name} [, {props}])
469 Dict get property type values
470prop_type_list([{props}]) List get list of property types
471pum_getpos() Dict position and size of pum if visible
472pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100473py3eval({expr} [, {locals}]) any evaluate |python3| expression
474pyeval({expr} [, {locals}]) any evaluate |Python| expression
475pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000476rand([{expr}]) Number get pseudo-random number
477range({expr} [, {max} [, {stride}]])
478 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100479readblob({fname} [, {offset} [, {size}]])
480 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000481readdir({dir} [, {expr} [, {dict}]])
482 List file names in {dir} selected by {expr}
483readdirex({dir} [, {expr} [, {dict}]])
484 List file info in {dir} selected by {expr}
485readfile({fname} [, {type} [, {max}]])
486 List get list of lines from file {fname}
487reduce({object}, {func} [, {initial}])
488 any reduce {object} using {func}
489reg_executing() String get the executing register name
490reg_recording() String get the recording register name
491reltime([{start} [, {end}]]) List get time value
492reltimefloat({time}) Float turn the time value into a Float
493reltimestr({time}) String turn time value into a String
494remote_expr({server}, {string} [, {idvar} [, {timeout}]])
495 String send expression
496remote_foreground({server}) Number bring Vim server to the foreground
497remote_peek({serverid} [, {retvar}])
498 Number check for reply string
499remote_read({serverid} [, {timeout}])
500 String read reply string
501remote_send({server}, {string} [, {idvar}])
502 String send key sequence
503remote_startserver({name}) none become server {name}
504remove({list}, {idx} [, {end}]) any/List
505 remove items {idx}-{end} from {list}
506remove({blob}, {idx} [, {end}]) Number/Blob
507 remove bytes {idx}-{end} from {blob}
508remove({dict}, {key}) any remove entry {key} from {dict}
509rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100510repeat({expr}, {count}) List/Blob/String
511 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000512resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100513reverse({obj}) List/Blob/String
514 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000515round({expr}) Float round off {expr}
516rubyeval({expr}) any evaluate |Ruby| expression
517screenattr({row}, {col}) Number attribute at screen position
518screenchar({row}, {col}) Number character at screen position
519screenchars({row}, {col}) List List of characters at screen position
520screencol() Number current cursor column
521screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
522screenrow() Number current cursor row
523screenstring({row}, {col}) String characters at screen position
524search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
525 Number search for {pattern}
526searchcount([{options}]) Dict get or update search stats
527searchdecl({name} [, {global} [, {thisblock}]])
528 Number search for variable declaration
529searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
530 Number search for other end of start/end pair
531searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
532 List search for other end of start/end pair
533searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
534 List search for {pattern}
535server2client({clientid}, {string})
536 Number send reply string
537serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700538setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000539 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700540 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000541setbufvar({buf}, {varname}, {val})
542 none set {varname} in buffer {buf} to {val}
543setcellwidths({list}) none set character cell width overrides
544setcharpos({expr}, {list}) Number set the {expr} position to {list}
545setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100546setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000547setcmdpos({pos}) Number set cursor position in command-line
548setcursorcharpos({list}) Number move cursor to position in {list}
549setenv({name}, {val}) none set environment variable
550setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
551setline({lnum}, {line}) Number set line {lnum} to {line}
552setloclist({nr}, {list} [, {action}])
553 Number modify location list using {list}
554setloclist({nr}, {list}, {action}, {what})
555 Number modify specific location list props
556setmatches({list} [, {win}]) Number restore a list of matches
557setpos({expr}, {list}) Number set the {expr} position to {list}
558setqflist({list} [, {action}]) Number modify quickfix list using {list}
559setqflist({list}, {action}, {what})
560 Number modify specific quickfix list props
561setreg({n}, {v} [, {opt}]) Number set register to value and type
562settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
563settabwinvar({tabnr}, {winnr}, {varname}, {val})
564 none set {varname} in window {winnr} in tab
565 page {tabnr} to {val}
566settagstack({nr}, {dict} [, {action}])
567 Number modify tag stack using {dict}
568setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
569sha256({string}) String SHA256 checksum of {string}
570shellescape({string} [, {special}])
571 String escape {string} for use as shell
572 command argument
573shiftwidth([{col}]) Number effective value of 'shiftwidth'
574sign_define({name} [, {dict}]) Number define or update a sign
575sign_define({list}) List define or update a list of signs
576sign_getdefined([{name}]) List get a list of defined signs
577sign_getplaced([{buf} [, {dict}]])
578 List get a list of placed signs
579sign_jump({id}, {group}, {buf})
580 Number jump to a sign
581sign_place({id}, {group}, {name}, {buf} [, {dict}])
582 Number place a sign
583sign_placelist({list}) List place a list of signs
584sign_undefine([{name}]) Number undefine a sign
585sign_undefine({list}) List undefine a list of signs
586sign_unplace({group} [, {dict}])
587 Number unplace a sign
588sign_unplacelist({list}) List unplace a list of signs
589simplify({filename}) String simplify filename as much as possible
590sin({expr}) Float sine of {expr}
591sinh({expr}) Float hyperbolic sine of {expr}
592slice({expr}, {start} [, {end}]) String, List or Blob
593 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000594sort({list} [, {how} [, {dict}]])
595 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000596sound_clear() none stop playing all sounds
597sound_playevent({name} [, {callback}])
598 Number play an event sound
599sound_playfile({path} [, {callback}])
600 Number play sound file {path}
601sound_stop({id}) none stop playing sound {id}
602soundfold({word}) String sound-fold {word}
603spellbadword() String badly spelled word at cursor
604spellsuggest({word} [, {max} [, {capital}]])
605 List spelling suggestions
606split({expr} [, {pat} [, {keepempty}]])
607 List make |List| from {pat} separated {expr}
608sqrt({expr}) Float square root of {expr}
609srand([{expr}]) List get seed for |rand()|
610state([{what}]) String current state of Vim
611str2float({expr} [, {quoted}]) Float convert String to Float
612str2list({expr} [, {utf8}]) List convert each character of {expr} to
613 ASCII/UTF-8 value
614str2nr({expr} [, {base} [, {quoted}]])
615 Number convert String to Number
616strcharlen({expr}) Number character length of the String {expr}
617strcharpart({str}, {start} [, {len} [, {skipcc}]])
618 String {len} characters of {str} at
619 character {start}
620strchars({expr} [, {skipcc}]) Number character count of the String {expr}
621strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
622strftime({format} [, {time}]) String format time with a specified format
623strgetchar({str}, {index}) Number get char {index} from {str}
624stridx({haystack}, {needle} [, {start}])
625 Number index of {needle} in {haystack}
626string({expr}) String String representation of {expr} value
627strlen({expr}) Number length of the String {expr}
628strpart({str}, {start} [, {len} [, {chars}]])
629 String {len} bytes/chars of {str} at
630 byte {start}
631strptime({format}, {timestring})
632 Number Convert {timestring} to unix timestamp
633strridx({haystack}, {needle} [, {start}])
634 Number last index of {needle} in {haystack}
635strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100636strutf16len({string} [, {countcc}])
637 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000638strwidth({expr}) Number display cell length of the String {expr}
639submatch({nr} [, {list}]) String or List
640 specific match in ":s" or substitute()
641substitute({expr}, {pat}, {sub}, {flags})
642 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000643swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000644swapinfo({fname}) Dict information about swap file {fname}
645swapname({buf}) String swap file of buffer {buf}
646synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
647synIDattr({synID}, {what} [, {mode}])
648 String attribute {what} of syntax ID {synID}
649synIDtrans({synID}) Number translated syntax ID of {synID}
650synconcealed({lnum}, {col}) List info about concealing
651synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
652system({expr} [, {input}]) String output of shell command/filter {expr}
653systemlist({expr} [, {input}]) List output of shell command/filter {expr}
654tabpagebuflist([{arg}]) List list of buffer numbers in tab page
655tabpagenr([{arg}]) Number number of current or last tab page
656tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
657tagfiles() List tags files used
658taglist({expr} [, {filename}]) List list of tags matching {expr}
659tan({expr}) Float tangent of {expr}
660tanh({expr}) Float hyperbolic tangent of {expr}
661tempname() String name for a temporary file
662term_dumpdiff({filename}, {filename} [, {options}])
663 Number display difference between two dumps
664term_dumpload({filename} [, {options}])
665 Number displaying a screen dump
666term_dumpwrite({buf}, {filename} [, {options}])
667 none dump terminal window contents
668term_getaltscreen({buf}) Number get the alternate screen flag
669term_getansicolors({buf}) List get ANSI palette in GUI color mode
670term_getattr({attr}, {what}) Number get the value of attribute {what}
671term_getcursor({buf}) List get the cursor position of a terminal
672term_getjob({buf}) Job get the job associated with a terminal
673term_getline({buf}, {row}) String get a line of text from a terminal
674term_getscrolled({buf}) Number get the scroll count of a terminal
675term_getsize({buf}) List get the size of a terminal
676term_getstatus({buf}) String get the status of a terminal
677term_gettitle({buf}) String get the title of a terminal
678term_gettty({buf}, [{input}]) String get the tty name of a terminal
679term_list() List get the list of terminal buffers
680term_scrape({buf}, {row}) List get row of a terminal screen
681term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
682term_setansicolors({buf}, {colors})
683 none set ANSI palette in GUI color mode
684term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
685term_setkill({buf}, {how}) none set signal to stop job in terminal
686term_setrestore({buf}, {command}) none set command to restore terminal
687term_setsize({buf}, {rows}, {cols})
688 none set the size of a terminal
689term_start({cmd} [, {options}]) Number open a terminal window and run a job
690term_wait({buf} [, {time}]) Number wait for screen to be updated
691terminalprops() Dict properties of the terminal
692test_alloc_fail({id}, {countdown}, {repeat})
693 none make memory allocation fail
694test_autochdir() none enable 'autochdir' during startup
695test_feedinput({string}) none add key sequence to input buffer
696test_garbagecollect_now() none free memory right now for testing
697test_garbagecollect_soon() none free memory soon for testing
698test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000699test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000700test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000701test_mswin_event({event}, {args})
702 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000703test_null_blob() Blob null value for testing
704test_null_channel() Channel null value for testing
705test_null_dict() Dict null value for testing
706test_null_function() Funcref null value for testing
707test_null_job() Job null value for testing
708test_null_list() List null value for testing
709test_null_partial() Funcref null value for testing
710test_null_string() String null value for testing
711test_option_not_set({name}) none reset flag indicating option was set
712test_override({expr}, {val}) none test with Vim internal overrides
713test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000714test_setmouse({row}, {col}) none set the mouse position for testing
715test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200716test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000717test_unknown() any unknown value for testing
718test_void() any void value for testing
719timer_info([{id}]) List information about timers
720timer_pause({id}, {pause}) none pause or unpause a timer
721timer_start({time}, {callback} [, {options}])
722 Number create a timer
723timer_stop({timer}) none stop a timer
724timer_stopall() none stop all timers
725tolower({expr}) String the String {expr} switched to lowercase
726toupper({expr}) String the String {expr} switched to uppercase
727tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
728 to chars in {tostr}
729trim({text} [, {mask} [, {dir}]])
730 String trim characters in {mask} from {text}
731trunc({expr}) Float truncate Float {expr}
732type({expr}) Number type of value {expr}
733typename({expr}) String representation of the type of {expr}
734undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500735undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000736uniq({list} [, {func} [, {dict}]])
737 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100738utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
739 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000740values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200741virtcol({expr} [, {list} [, {winid}])
742 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100743 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100744virtcol2col({winid}, {lnum}, {col})
745 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200746visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000747wildmenumode() Number whether 'wildmenu' mode is active
748win_execute({id}, {command} [, {silent}])
749 String execute {command} in window {id}
750win_findbuf({bufnr}) List find windows containing {bufnr}
751win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
752win_gettype([{nr}]) String type of window {nr}
753win_gotoid({expr}) Number go to window with ID {expr}
754win_id2tabwin({expr}) List get tab and window nr from window ID
755win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000756win_move_separator({nr}) Number move window vertical separator
757win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000758win_screenpos({nr}) List get screen position of window {nr}
759win_splitmove({nr}, {target} [, {options}])
760 Number move window {nr} to split of {target}
761winbufnr({nr}) Number buffer number of window {nr}
762wincol() Number window column of the cursor
763windowsversion() String MS-Windows OS version
764winheight({nr}) Number height of window {nr}
765winlayout([{tabnr}]) List layout of windows in tab {tabnr}
766winline() Number window line of the cursor
767winnr([{expr}]) Number number of current window
768winrestcmd() String returns command to restore window sizes
769winrestview({dict}) none restore view of current window
770winsaveview() Dict save view of current window
771winwidth({nr}) Number width of window {nr}
772wordcount() Dict get byte/char/word statistics
773writefile({object}, {fname} [, {flags}])
774 Number write |Blob| or |List| of lines to file
775xor({expr}, {expr}) Number bitwise XOR
776
777==============================================================================
7782. Details *builtin-function-details*
779
780Not all functions are here, some have been moved to a help file covering the
781specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200782Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000783
784abs({expr}) *abs()*
785 Return the absolute value of {expr}. When {expr} evaluates to
786 a |Float| abs() returns a |Float|. When {expr} can be
787 converted to a |Number| abs() returns a |Number|. Otherwise
788 abs() gives an error message and returns -1.
789 Examples: >
790 echo abs(1.456)
791< 1.456 >
792 echo abs(-5.456)
793< 5.456 >
794 echo abs(-4)
795< 4
796
797 Can also be used as a |method|: >
798 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200799<
800 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000802
803acos({expr}) *acos()*
804 Return the arc cosine of {expr} measured in radians, as a
805 |Float| in the range of [0, pi].
806 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100807 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000808 Examples: >
809 :echo acos(0)
810< 1.570796 >
811 :echo acos(-0.5)
812< 2.094395
813
814 Can also be used as a |method|: >
815 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200816<
817 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000819
820add({object}, {expr}) *add()*
821 Append the item {expr} to |List| or |Blob| {object}. Returns
822 the resulting |List| or |Blob|. Examples: >
823 :let alist = add([1, 2, 3], item)
824 :call add(mylist, "woodstock")
825< Note that when {expr} is a |List| it is appended as a single
826 item. Use |extend()| to concatenate |Lists|.
827 When {object} is a |Blob| then {expr} must be a number.
828 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100829 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000830
831 Can also be used as a |method|: >
832 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200833<
834 Return type: list<{type}> (depending on the given |List|) or
835 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000836
837
838and({expr}, {expr}) *and()*
839 Bitwise AND on the two arguments. The arguments are converted
840 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100841 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000842 Example: >
843 :let flag = and(bits, 0x80)
844< Can also be used as a |method|: >
845 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200846<
847 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000848
849
850append({lnum}, {text}) *append()*
851 When {text} is a |List|: Append each item of the |List| as a
852 text line below line {lnum} in the current buffer.
853 Otherwise append {text} as one text line below line {lnum} in
854 the current buffer.
855 Any type of item is accepted and converted to a String.
856 {lnum} can be zero to insert a line before the first one.
857 {lnum} is used like with |getline()|.
858 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000859 0 for success. When {text} is an empty list zero is returned,
860 no matter the value of {lnum}.
861 In |Vim9| script an invalid argument or negative number
862 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000863 :let failed = append(line('$'), "# THE END")
864 :let failed = append(0, ["Chapter 1", "the beginning"])
865
866< Can also be used as a |method| after a List, the base is
867 passed as the second argument: >
868 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200869<
870 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000871
872
873appendbufline({buf}, {lnum}, {text}) *appendbufline()*
874 Like |append()| but append the text in buffer {buf}.
875
876 This function works only for loaded buffers. First call
877 |bufload()| if needed.
878
879 For the use of {buf}, see |bufname()|.
880
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000881 {lnum} is the line number to append below. Note that using
882 |line()| would use the current buffer, not the one appending
883 to. Use "$" to append at the end of the buffer. Other string
884 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000885
886 On success 0 is returned, on failure 1 is returned.
887 In |Vim9| script an error is given for an invalid {lnum}.
888
889 If {buf} is not a valid buffer or {lnum} is not valid, an
890 error message is given. Example: >
891 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000892< However, when {text} is an empty list then no error is given
893 for an invalid {lnum}, since {lnum} isn't actually used.
894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895 Can also be used as a |method| after a List, the base is
896 passed as the second argument: >
897 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200898<
899 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000900
901
902argc([{winid}]) *argc()*
903 The result is the number of files in the argument list. See
904 |arglist|.
905 If {winid} is not supplied, the argument list of the current
906 window is used.
907 If {winid} is -1, the global argument list is used.
908 Otherwise {winid} specifies the window of which the argument
909 list is used: either the window number or the window ID.
910 Returns -1 if the {winid} argument is invalid.
911
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200912 Return type: |Number|
913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000914 *argidx()*
915argidx() The result is the current index in the argument list. 0 is
916 the first file. argc() - 1 is the last one. See |arglist|.
917
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200918 Return type: |Number|
919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000920 *arglistid()*
921arglistid([{winnr} [, {tabnr}]])
922 Return the argument list ID. This is a number which
923 identifies the argument list being used. Zero is used for the
924 global argument list. See |arglist|.
925 Returns -1 if the arguments are invalid.
926
927 Without arguments use the current window.
928 With {winnr} only use this window in the current tab page.
929 With {winnr} and {tabnr} use the window in the specified tab
930 page.
931 {winnr} can be the window number or the |window-ID|.
932
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200933 Return type: |Number|
934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000935 *argv()*
936argv([{nr} [, {winid}]])
937 The result is the {nr}th file in the argument list. See
938 |arglist|. "argv(0)" is the first one. Example: >
939 :let i = 0
940 :while i < argc()
941 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000942 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000943 : let i = i + 1
944 :endwhile
945< Without the {nr} argument, or when {nr} is -1, a |List| with
946 the whole |arglist| is returned.
947
948 The {winid} argument specifies the window ID, see |argc()|.
949 For the Vim command line arguments see |v:argv|.
950
Bram Moolenaar016188f2022-06-06 20:52:59 +0100951 Returns an empty string if {nr}th argument is not present in
952 the argument list. Returns an empty List if the {winid}
953 argument is invalid.
954
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200955 Return type: |String|
956
957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000958asin({expr}) *asin()*
959 Return the arc sine of {expr} measured in radians, as a |Float|
960 in the range of [-pi/2, pi/2].
961 {expr} must evaluate to a |Float| or a |Number| in the range
962 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100963 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
964 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000965 Examples: >
966 :echo asin(0.8)
967< 0.927295 >
968 :echo asin(-0.5)
969< -0.523599
970
971 Can also be used as a |method|: >
972 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200973<
974 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000975
976assert_ functions are documented here: |assert-functions-details|
977
978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000979atan({expr}) *atan()*
980 Return the principal value of the arc tangent of {expr}, in
981 the range [-pi/2, +pi/2] radians, as a |Float|.
982 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100983 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984 Examples: >
985 :echo atan(100)
986< 1.560797 >
987 :echo atan(-4.01)
988< -1.326405
989
990 Can also be used as a |method|: >
991 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200992<
993 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000994
995
996atan2({expr1}, {expr2}) *atan2()*
997 Return the arc tangent of {expr1} / {expr2}, measured in
998 radians, as a |Float| in the range [-pi, pi].
999 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001000 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1001 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001002 Examples: >
1003 :echo atan2(-1, 1)
1004< -0.785398 >
1005 :echo atan2(1, -1)
1006< 2.356194
1007
1008 Can also be used as a |method|: >
1009 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001010<
1011 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001012
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001013
1014autocmd_add({acmds}) *autocmd_add()*
1015 Adds a List of autocmds and autocmd groups.
1016
1017 The {acmds} argument is a List where each item is a Dict with
1018 the following optional items:
1019 bufnr buffer number to add a buffer-local autocmd.
1020 If this item is specified, then the "pattern"
1021 item is ignored.
1022 cmd Ex command to execute for this autocmd event
1023 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001024 This can be either a String with a single
1025 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001026 group autocmd group name. Refer to |autocmd-groups|.
1027 If this group doesn't exist then it is
1028 created. If not specified or empty, then the
1029 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001030 nested boolean flag, set to v:true to add a nested
1031 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001032 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001033 which executes only once. Refer to
1034 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001035 pattern autocmd pattern string. Refer to
1036 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001037 present, then this item is ignored. This can
1038 be a String with a single pattern or a List of
1039 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001040 replace boolean flag, set to v:true to remove all the
1041 commands associated with the specified autocmd
1042 event and group and add the {cmd}. This is
1043 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001044 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001045
1046 Returns v:true on success and v:false on failure.
1047 Examples: >
1048 " Create a buffer-local autocmd for buffer 5
1049 let acmd = {}
1050 let acmd.group = 'MyGroup'
1051 let acmd.event = 'BufEnter'
1052 let acmd.bufnr = 5
1053 let acmd.cmd = 'call BufEnterFunc()'
1054 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001055<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001056 Can also be used as a |method|: >
1057 GetAutocmdList()->autocmd_add()
1058<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001059 Return type: |vim9-boolean|
1060
1061
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001062autocmd_delete({acmds}) *autocmd_delete()*
1063 Deletes a List of autocmds and autocmd groups.
1064
1065 The {acmds} argument is a List where each item is a Dict with
1066 the following optional items:
1067 bufnr buffer number to delete a buffer-local autocmd.
1068 If this item is specified, then the "pattern"
1069 item is ignored.
1070 cmd Ex command for this autocmd event
1071 event autocmd event name. Refer to |autocmd-events|.
1072 If '*' then all the autocmd events in this
1073 group are deleted.
1074 group autocmd group name. Refer to |autocmd-groups|.
1075 If not specified or empty, then the default
1076 group is used.
1077 nested set to v:true for a nested autocmd.
1078 Refer to |autocmd-nested|.
1079 once set to v:true for an autocmd which executes
1080 only once. Refer to |autocmd-once|.
1081 pattern autocmd pattern string. Refer to
1082 |autocmd-patterns|. If "bufnr" item is
1083 present, then this item is ignored.
1084
1085 If only {group} is specified in a {acmds} entry and {event},
1086 {pattern} and {cmd} are not specified, then that autocmd group
1087 is deleted.
1088
Bram Moolenaar016188f2022-06-06 20:52:59 +01001089 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001090 Examples: >
1091 " :autocmd! BufLeave *.vim
1092 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1093 call autocmd_delete([acmd]})
1094 " :autocmd! MyGroup1 BufLeave
1095 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1096 call autocmd_delete([acmd])
1097 " :autocmd! MyGroup2 BufEnter *.c
1098 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1099 \ pattern: '*.c'}
1100 " :autocmd! MyGroup2 * *.c
1101 let acmd = #{group: 'MyGroup2', event: '*',
1102 \ pattern: '*.c'}
1103 call autocmd_delete([acmd])
1104 " :autocmd! MyGroup3
1105 let acmd = #{group: 'MyGroup3'}
1106 call autocmd_delete([acmd])
1107<
1108 Can also be used as a |method|: >
1109 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001110<
1111 Return type: |vim9-boolean|
1112
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001113
1114autocmd_get([{opts}]) *autocmd_get()*
1115 Returns a |List| of autocmds. If {opts} is not supplied, then
1116 returns the autocmds for all the events in all the groups.
1117
1118 The optional {opts} Dict argument supports the following
1119 items:
1120 group Autocmd group name. If specified, returns only
1121 the autocmds defined in this group. If the
1122 specified group doesn't exist, results in an
1123 error message. If set to an empty string,
1124 then the default autocmd group is used.
1125 event Autocmd event name. If specified, returns only
1126 the autocmds defined for this event. If set
1127 to "*", then returns autocmds for all the
1128 events. If the specified event doesn't exist,
1129 results in an error message.
1130 pattern Autocmd pattern. If specified, returns only
1131 the autocmds defined for this pattern.
1132 A combination of the above three times can be supplied in
1133 {opts}.
1134
1135 Each Dict in the returned List contains the following items:
1136 bufnr For buffer-local autocmds, buffer number where
1137 the autocmd is defined.
1138 cmd Command executed for this autocmd.
1139 event Autocmd event name.
1140 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001141 nested Boolean flag, set to v:true for a nested
1142 autocmd. See |autocmd-nested|.
1143 once Boolean flag, set to v:true, if the autocmd
1144 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001145 pattern Autocmd pattern. For a buffer-local
1146 autocmd, this will be of the form "<buffer=n>".
1147 If there are multiple commands for an autocmd event in a
1148 group, then separate items are returned for each command.
1149
Bram Moolenaar016188f2022-06-06 20:52:59 +01001150 Returns an empty List if an autocmd with the specified group
1151 or event or pattern is not found.
1152
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001153 Examples: >
1154 " :autocmd MyGroup
1155 echo autocmd_get(#{group: 'Mygroup'})
1156 " :autocmd G BufUnload
1157 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1158 " :autocmd G * *.ts
1159 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1160 echo autocmd_get(acmd)
1161 " :autocmd Syntax
1162 echo autocmd_get(#{event: 'Syntax'})
1163 " :autocmd G BufEnter *.ts
1164 let acmd = #{group: 'G', event: 'BufEnter',
1165 \ pattern: '*.ts'}
1166 echo autocmd_get(acmd)
1167<
1168 Can also be used as a |method|: >
1169 Getopts()->autocmd_get()
1170<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001171 Return type: list<dict<any>>
1172
1173
Yegappan Lakshmanan810785c2024-12-30 10:29:44 +01001174base64_decode({string}) *base64_decode()*
1175 Return a Blob containing the bytes decoded from the base64
1176 characters in {string}.
1177
1178 The {string} argument should contain only base64-encoded
1179 characters and should have a length that is a multiple of 4.
1180
1181 Returns an empty blob on error.
1182
1183 Examples: >
1184 " Write the decoded contents to a binary file
1185 call writefile(base64_decode(s), 'tools.bmp')
1186 " Decode a base64-encoded string
1187 echo list2str(blob2list(base64_decode(encodedstr)))
1188<
1189 Can also be used as a |method|: >
1190 GetEncodedString()->base64_decode()
1191<
1192 Return type: |Blob|
1193
1194
1195base64_encode({blob}) *base64_encode()*
1196 Return a base64-encoded String representing the bytes in
1197 {blob}. The base64 alphabet defined in RFC 4648 is used.
1198
1199 Examples: >
1200 " Encode the contents of a binary file
1201 echo base64_encode(readblob('somefile.bin'))
1202 " Encode a string
1203 echo base64_encode(list2blob(str2list(somestr)))
1204<
1205 Can also be used as a |method|: >
1206 GetBinaryData()->base64_encode()
1207<
1208 Return type: |String|
1209
1210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001211balloon_gettext() *balloon_gettext()*
1212 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001213 not used for the List. Returns an empty string if balloon
1214 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001216 Return type: |String|
1217
1218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001219balloon_show({expr}) *balloon_show()*
1220 Show {expr} inside the balloon. For the GUI {expr} is used as
1221 a string. For a terminal {expr} can be a list, which contains
1222 the lines of the balloon. If {expr} is not a list it will be
1223 split with |balloon_split()|.
1224 If {expr} is an empty string any existing balloon is removed.
1225
1226 Example: >
1227 func GetBalloonContent()
1228 " ... initiate getting the content
1229 return ''
1230 endfunc
1231 set balloonexpr=GetBalloonContent()
1232
1233 func BalloonCallback(result)
1234 call balloon_show(a:result)
1235 endfunc
1236< Can also be used as a |method|: >
1237 GetText()->balloon_show()
1238<
1239 The intended use is that fetching the content of the balloon
1240 is initiated from 'balloonexpr'. It will invoke an
1241 asynchronous method, in which a callback invokes
1242 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001243 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001244
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001245 When showing a balloon is not possible then nothing happens,
1246 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001247 {only available when compiled with the |+balloon_eval| or
1248 |+balloon_eval_term| feature}
1249
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001250 Return type: |Number|
1251
1252
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001253balloon_split({msg}) *balloon_split()*
1254 Split String {msg} into lines to be displayed in a balloon.
1255 The splits are made for the current window size and optimize
1256 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001257 Returns a |List| with the split lines. Returns an empty List
1258 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001259 Can also be used as a |method|: >
1260 GetText()->balloon_split()->balloon_show()
1261
1262< {only available when compiled with the |+balloon_eval_term|
1263 feature}
1264
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001265 Return type: list<any> or list<string>
1266
Christ van Willegence0ef912024-06-20 23:41:59 +02001267bindtextdomain({package}, {path}) *bindtextdomain()*
1268 Bind a specific {package} to a {path} so that the
1269 |gettext()| function can be used to get language-specific
1270 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001271 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001272
Christ van Willegen8252ef12024-07-11 21:36:21 +02001273 Returns v:true on success and v:false on failure (out of
1274 memory).
1275
1276 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001278blob2list({blob}) *blob2list()*
1279 Return a List containing the number value of each byte in Blob
1280 {blob}. Examples: >
1281 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1282 blob2list(0z) returns []
1283< Returns an empty List on error. |list2blob()| does the
1284 opposite.
1285
1286 Can also be used as a |method|: >
1287 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001288<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001289 Return type: list<any> or list<number>
1290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001291 *browse()*
1292browse({save}, {title}, {initdir}, {default})
1293 Put up a file requester. This only works when "has("browse")"
1294 returns |TRUE| (only in some GUI versions).
1295 The input fields are:
1296 {save} when |TRUE|, select file to write
1297 {title} title for the requester
1298 {initdir} directory to start browsing in
1299 {default} default file name
1300 An empty string is returned when the "Cancel" button is hit,
1301 something went wrong, or browsing is not possible.
1302
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001303 Return type: |String|
1304
1305
1306browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001307 Put up a directory requester. This only works when
1308 "has("browse")" returns |TRUE| (only in some GUI versions).
1309 On systems where a directory browser is not supported a file
1310 browser is used. In that case: select a file in the directory
1311 to be used.
1312 The input fields are:
1313 {title} title for the requester
1314 {initdir} directory to start browsing in
1315 When the "Cancel" button is hit, something went wrong, or
1316 browsing is not possible, an empty string is returned.
1317
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001318 Return type: |String|
1319
1320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001321bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001322 Add a buffer to the buffer list with name {name} (must be a
1323 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001324 If a buffer for file {name} already exists, return that buffer
1325 number. Otherwise return the buffer number of the newly
1326 created buffer. When {name} is an empty string then a new
1327 buffer is always created.
1328 The buffer will not have 'buflisted' set and not be loaded
1329 yet. To add some text to the buffer use this: >
1330 let bufnr = bufadd('someName')
1331 call bufload(bufnr)
1332 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001333< Returns 0 on error.
1334 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001335 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001336<
1337 Return type: |Number|
1338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001339
1340bufexists({buf}) *bufexists()*
1341 The result is a Number, which is |TRUE| if a buffer called
1342 {buf} exists.
1343 If the {buf} argument is a number, buffer numbers are used.
1344 Number zero is the alternate buffer for the current window.
1345
1346 If the {buf} argument is a string it must match a buffer name
1347 exactly. The name can be:
1348 - Relative to the current directory.
1349 - A full path.
1350 - The name of a buffer with 'buftype' set to "nofile".
1351 - A URL name.
1352 Unlisted buffers will be found.
1353 Note that help files are listed by their short name in the
1354 output of |:buffers|, but bufexists() requires using their
1355 long name to be able to find them.
1356 bufexists() may report a buffer exists, but to use the name
1357 with a |:buffer| command you may need to use |expand()|. Esp
1358 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1359 Use "bufexists(0)" to test for the existence of an alternate
1360 file name.
1361
1362 Can also be used as a |method|: >
1363 let exists = 'somename'->bufexists()
1364<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001365 Return type: |Number|
1366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001367 Obsolete name: buffer_exists(). *buffer_exists()*
1368
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001370buflisted({buf}) *buflisted()*
1371 The result is a Number, which is |TRUE| if a buffer called
1372 {buf} exists and is listed (has the 'buflisted' option set).
1373 The {buf} argument is used like with |bufexists()|.
1374
1375 Can also be used as a |method|: >
1376 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001377<
1378 Return type: |Number|
1379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001380
1381bufload({buf}) *bufload()*
1382 Ensure the buffer {buf} is loaded. When the buffer name
1383 refers to an existing file then the file is read. Otherwise
1384 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001385 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001386 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001387 If there is an existing swap file for the file of the buffer,
1388 there will be no dialog, the buffer will be loaded anyway.
1389 The {buf} argument is used like with |bufexists()|.
1390
1391 Can also be used as a |method|: >
1392 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001393<
1394 Return type: |Number|
1395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001396
1397bufloaded({buf}) *bufloaded()*
1398 The result is a Number, which is |TRUE| if a buffer called
1399 {buf} exists and is loaded (shown in a window or hidden).
1400 The {buf} argument is used like with |bufexists()|.
1401
1402 Can also be used as a |method|: >
1403 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001404<
1405 Return type: |Number|
1406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001407
1408bufname([{buf}]) *bufname()*
1409 The result is the name of a buffer. Mostly as it is displayed
1410 by the `:ls` command, but not using special names such as
1411 "[No Name]".
1412 If {buf} is omitted the current buffer is used.
1413 If {buf} is a Number, that buffer number's name is given.
1414 Number zero is the alternate buffer for the current window.
1415 If {buf} is a String, it is used as a |file-pattern| to match
1416 with the buffer names. This is always done like 'magic' is
1417 set and 'cpoptions' is empty. When there is more than one
1418 match an empty string is returned.
1419 "" or "%" can be used for the current buffer, "#" for the
1420 alternate buffer.
1421 A full match is preferred, otherwise a match at the start, end
1422 or middle of the buffer name is accepted. If you only want a
1423 full match then put "^" at the start and "$" at the end of the
1424 pattern.
1425 Listed buffers are found first. If there is a single match
1426 with a listed buffer, that one is returned. Next unlisted
1427 buffers are searched for.
1428 If the {buf} is a String, but you want to use it as a buffer
1429 number, force it to be a Number by adding zero to it: >
1430 :echo bufname("3" + 0)
1431< Can also be used as a |method|: >
1432 echo bufnr->bufname()
1433
1434< If the buffer doesn't exist, or doesn't have a name, an empty
1435 string is returned. >
1436 bufname("#") alternate buffer name
1437 bufname(3) name of buffer 3
1438 bufname("%") name of current buffer
1439 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001440<
1441 Return type: |String|
1442 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001443 Obsolete name: buffer_name().
1444
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001445
1446bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001447 The result is the number of a buffer, as it is displayed by
1448 the `:ls` command. For the use of {buf}, see |bufname()|
1449 above.
1450
1451 If the buffer doesn't exist, -1 is returned. Or, if the
1452 {create} argument is present and TRUE, a new, unlisted,
1453 buffer is created and its number is returned. Example: >
1454 let newbuf = bufnr('Scratch001', 1)
1455< Using an empty name uses the current buffer. To create a new
1456 buffer with an empty name use |bufadd()|.
1457
1458 bufnr("$") is the last buffer: >
1459 :let last_buffer = bufnr("$")
1460< The result is a Number, which is the highest buffer number
1461 of existing buffers. Note that not all buffers with a smaller
1462 number necessarily exist, because ":bwipeout" may have removed
1463 them. Use bufexists() to test for the existence of a buffer.
1464
1465 Can also be used as a |method|: >
1466 echo bufref->bufnr()
1467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001468 Return type: |Number|
1469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001470 Obsolete name: buffer_number(). *buffer_number()*
1471 *last_buffer_nr()*
1472 Obsolete name for bufnr("$"): last_buffer_nr().
1473
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001475bufwinid({buf}) *bufwinid()*
1476 The result is a Number, which is the |window-ID| of the first
1477 window associated with buffer {buf}. For the use of {buf},
1478 see |bufname()| above. If buffer {buf} doesn't exist or
1479 there is no such window, -1 is returned. Example: >
1480
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001481 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001482<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001483 Only deals with the current tab page. See |win_findbuf()| for
1484 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001485
1486 Can also be used as a |method|: >
1487 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001488<
1489 Return type: |Number|
1490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001491
1492bufwinnr({buf}) *bufwinnr()*
1493 Like |bufwinid()| but return the window number instead of the
1494 |window-ID|.
1495 If buffer {buf} doesn't exist or there is no such window, -1
1496 is returned. Example: >
1497
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001498 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499
1500< The number can be used with |CTRL-W_w| and ":wincmd w"
1501 |:wincmd|.
1502
1503 Can also be used as a |method|: >
1504 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001505<
1506 Return type: |Number|
1507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001508
1509byte2line({byte}) *byte2line()*
1510 Return the line number that contains the character at byte
1511 count {byte} in the current buffer. This includes the
1512 end-of-line character, depending on the 'fileformat' option
1513 for the current buffer. The first character has byte count
1514 one.
1515 Also see |line2byte()|, |go| and |:goto|.
1516
Bram Moolenaar016188f2022-06-06 20:52:59 +01001517 Returns -1 if the {byte} value is invalid.
1518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001519 Can also be used as a |method|: >
1520 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001521<
1522 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001524 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525 feature}
1526
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001527
Christian Brabandt67672ef2023-04-24 21:09:54 +01001528byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001529 Return byte index of the {nr}'th character in the String
1530 {expr}. Use zero for the first character, it then returns
1531 zero.
1532 If there are no multibyte characters the returned value is
1533 equal to {nr}.
1534 Composing characters are not counted separately, their byte
1535 length is added to the preceding base character. See
1536 |byteidxcomp()| below for counting composing characters
1537 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001538 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1539 index in the String {expr} instead of as the character index.
1540 The UTF-16 index is the index in the string when it is encoded
1541 with 16-bit words. If the specified UTF-16 index is in the
1542 middle of a character (e.g. in a 4-byte character), then the
1543 byte index of the first byte in the character is returned.
1544 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001545 Example : >
1546 echo matchstr(str, ".", byteidx(str, 3))
1547< will display the fourth character. Another way to do the
1548 same: >
1549 let s = strpart(str, byteidx(str, 3))
1550 echo strpart(s, 0, byteidx(s, 1))
1551< Also see |strgetchar()| and |strcharpart()|.
1552
1553 If there are less than {nr} characters -1 is returned.
1554 If there are exactly {nr} characters the length of the string
1555 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001556 See |charidx()| and |utf16idx()| for getting the character and
1557 UTF-16 index respectively from the byte index.
1558 Examples: >
1559 echo byteidx('a😊😊', 2) returns 5
1560 echo byteidx('a😊😊', 2, 1) returns 1
1561 echo byteidx('a😊😊', 3, 1) returns 5
1562<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001563 Can also be used as a |method|: >
1564 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001565<
1566 Return type: |Number|
1567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001568
Christian Brabandt67672ef2023-04-24 21:09:54 +01001569byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001570 Like byteidx(), except that a composing character is counted
1571 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001572 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001573 echo byteidx(s, 1)
1574 echo byteidxcomp(s, 1)
1575 echo byteidxcomp(s, 2)
1576< The first and third echo result in 3 ('e' plus composing
1577 character is 3 bytes), the second echo results in 1 ('e' is
1578 one byte).
1579 Only works differently from byteidx() when 'encoding' is set
1580 to a Unicode encoding.
1581
1582 Can also be used as a |method|: >
1583 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001584<
1585 Return type: |Number|
1586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001587
1588call({func}, {arglist} [, {dict}]) *call()* *E699*
1589 Call function {func} with the items in |List| {arglist} as
1590 arguments.
1591 {func} can either be a |Funcref| or the name of a function.
1592 a:firstline and a:lastline are set to the cursor line.
1593 Returns the return value of the called function.
1594 {dict} is for functions with the "dict" attribute. It will be
1595 used to set the local variable "self". |Dictionary-function|
1596
1597 Can also be used as a |method|: >
1598 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001599<
1600 Return type: any, depending on {func}
1601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001602
1603ceil({expr}) *ceil()*
1604 Return the smallest integral value greater than or equal to
1605 {expr} as a |Float| (round up).
1606 {expr} must evaluate to a |Float| or a |Number|.
1607 Examples: >
1608 echo ceil(1.456)
1609< 2.0 >
1610 echo ceil(-5.456)
1611< -5.0 >
1612 echo ceil(4.0)
1613< 4.0
1614
Bram Moolenaar016188f2022-06-06 20:52:59 +01001615 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617 Can also be used as a |method|: >
1618 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001619<
1620 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001621
1622
1623ch_ functions are documented here: |channel-functions-details|
1624
1625
1626changenr() *changenr()*
1627 Return the number of the most recent change. This is the same
1628 number as what is displayed with |:undolist| and can be used
1629 with the |:undo| command.
1630 When a change was made it is the number of that change. After
1631 redo it is the number of the redone change. After undo it is
1632 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001633 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001635 Return type: |Number|
1636
1637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001638char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001639 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001640 Examples: >
1641 char2nr(" ") returns 32
1642 char2nr("ABC") returns 65
1643< When {utf8} is omitted or zero, the current 'encoding' is used.
1644 Example for "utf-8": >
1645 char2nr("á") returns 225
1646 char2nr("á"[0]) returns 195
1647< When {utf8} is TRUE, always treat as UTF-8 characters.
1648 A combining character is a separate character.
1649 |nr2char()| does the opposite.
1650 To turn a string into a list of character numbers: >
1651 let str = "ABC"
1652 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1653< Result: [65, 66, 67]
1654
Bram Moolenaar016188f2022-06-06 20:52:59 +01001655 Returns 0 if {string} is not a |String|.
1656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001657 Can also be used as a |method|: >
1658 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001659<
1660 Return type: |Number|
1661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001663charclass({string}) *charclass()*
1664 Return the character class of the first character in {string}.
1665 The character class is one of:
1666 0 blank
1667 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001668 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 3 emoji
1670 other specific Unicode class
1671 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001672 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001674 Return type: |Number|
1675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001676
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001677charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001678 Same as |col()| but returns the character index of the column
1679 position given with {expr} instead of the byte position.
1680
1681 Example:
1682 With the cursor on '세' in line 5 with text "여보세요": >
1683 charcol('.') returns 3
1684 col('.') returns 7
1685
1686< Can also be used as a |method|: >
1687 GetPos()->col()
1688<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001689 Return type: |Number|
1690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001691 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001692charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001693 Return the character index of the byte at {idx} in {string}.
1694 The index of the first character is zero.
1695 If there are no multibyte characters the returned value is
1696 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001698 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001699 are not counted separately, their byte length is added to the
1700 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001701 When {countcc} is |TRUE|, then composing characters are
1702 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001703
1704 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1705 index in the String {expr} instead of as the byte index.
1706
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001707 Returns -1 if the arguments are invalid or if there are less
1708 than {idx} bytes. If there are exactly {idx} bytes the length
1709 of the string in characters is returned.
1710
1711 An error is given and -1 is returned if the first argument is
1712 not a string, the second argument is not a number or when the
1713 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001716 from the character index and |utf16idx()| for getting the
1717 UTF-16 index from the character index.
1718 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 Examples: >
1720 echo charidx('áb́ć', 3) returns 1
1721 echo charidx('áb́ć', 6, 1) returns 4
1722 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001723 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001724<
1725 Can also be used as a |method|: >
1726 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001727<
1728 Return type: |Number|
1729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730
1731chdir({dir}) *chdir()*
1732 Change the current working directory to {dir}. The scope of
1733 the directory change depends on the directory of the current
1734 window:
1735 - If the current window has a window-local directory
1736 (|:lcd|), then changes the window local directory.
1737 - Otherwise, if the current tabpage has a local
1738 directory (|:tcd|) then changes the tabpage local
1739 directory.
1740 - Otherwise, changes the global directory.
1741 {dir} must be a String.
1742 If successful, returns the previous working directory. Pass
1743 this to another chdir() to restore the directory.
1744 On failure, returns an empty string.
1745
1746 Example: >
1747 let save_dir = chdir(newdir)
1748 if save_dir != ""
1749 " ... do some work
1750 call chdir(save_dir)
1751 endif
1752
1753< Can also be used as a |method|: >
1754 GetDir()->chdir()
1755<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001756 Return type: |String|
1757
1758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759cindent({lnum}) *cindent()*
1760 Get the amount of indent for line {lnum} according the C
1761 indenting rules, as with 'cindent'.
1762 The indent is counted in spaces, the value of 'tabstop' is
1763 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001764 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765 See |C-indenting|.
1766
1767 Can also be used as a |method|: >
1768 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001769<
1770 Return type: |Number|
1771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001772
1773clearmatches([{win}]) *clearmatches()*
1774 Clears all matches previously defined for the current window
1775 by |matchadd()| and the |:match| commands.
1776 If {win} is specified, use the window with this number or
1777 window ID instead of the current window.
1778
1779 Can also be used as a |method|: >
1780 GetWin()->clearmatches()
1781<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001782 Return type: |Number|
1783
1784
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001785col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001786 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001787 position given with {expr}.
1788 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001789 When {expr} is "$", it means the end of the cursor line, so
1790 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001791 Additionally {expr} can be [lnum, col]: a |List| with the line
1792 and column number. Most useful when the column is "$", to get
1793 the last column of a specific line. When "lnum" or "col" is
1794 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001795
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001796 With the optional {winid} argument the values are obtained for
1797 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001799 To get the line number use |line()|. To get both use
1800 |getpos()|.
1801 For the screen column position use |virtcol()|. For the
1802 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001806 Examples: >
1807 col(".") column of cursor
1808 col("$") length of cursor line plus one
1809 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001810 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001811<
1812 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001813 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001814 For an uppercase mark the column may actually be in another
1815 buffer.
1816 For the cursor position, when 'virtualedit' is active, the
1817 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001818 line. Also, when using a <Cmd> mapping the cursor isn't
1819 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001820 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001821
1822< Can also be used as a |method|: >
1823 GetPos()->col()
1824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001825 Return type: |Number|
1826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001827
1828complete({startcol}, {matches}) *complete()* *E785*
1829 Set the matches for Insert mode completion.
1830 Can only be used in Insert mode. You need to use a mapping
1831 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1832 or with an expression mapping.
1833 {startcol} is the byte offset in the line where the completed
1834 text start. The text up to the cursor is the original text
1835 that will be replaced by the matches. Use col('.') for an
1836 empty string. "col('.') - 1" will replace one character by a
1837 match.
1838 {matches} must be a |List|. Each |List| item is one match.
1839 See |complete-items| for the kind of items that are possible.
1840 "longest" in 'completeopt' is ignored.
1841 Note that the after calling this function you need to avoid
1842 inserting anything that would cause completion to stop.
1843 The match can be selected with CTRL-N and CTRL-P as usual with
1844 Insert mode completion. The popup menu will appear if
1845 specified, see |ins-completion-menu|.
1846 Example: >
1847 inoremap <F5> <C-R>=ListMonths()<CR>
1848
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001849 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850 call complete(col('.'), ['January', 'February', 'March',
1851 \ 'April', 'May', 'June', 'July', 'August', 'September',
1852 \ 'October', 'November', 'December'])
1853 return ''
1854 endfunc
1855< This isn't very useful, but it shows how it works. Note that
1856 an empty string is returned to avoid a zero being inserted.
1857
1858 Can also be used as a |method|, the base is passed as the
1859 second argument: >
1860 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001861<
1862 Return type: |Number|
1863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001864
1865complete_add({expr}) *complete_add()*
1866 Add {expr} to the list of matches. Only to be used by the
1867 function specified with the 'completefunc' option.
1868 Returns 0 for failure (empty string or out of memory),
1869 1 when the match was added, 2 when the match was already in
1870 the list.
1871 See |complete-functions| for an explanation of {expr}. It is
1872 the same as one item in the list that 'omnifunc' would return.
1873
1874 Can also be used as a |method|: >
1875 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001876<
1877 Return type: |Number|
1878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001879
1880complete_check() *complete_check()*
1881 Check for a key typed while looking for completion matches.
1882 This is to be used when looking for matches takes some time.
1883 Returns |TRUE| when searching for matches is to be aborted,
1884 zero otherwise.
1885 Only to be used by the function specified with the
1886 'completefunc' option.
1887
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001888 Return type: |Number|
1889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001890
1891complete_info([{what}]) *complete_info()*
1892 Returns a |Dictionary| with information about Insert mode
1893 completion. See |ins-completion|.
1894 The items are:
1895 mode Current completion mode name string.
1896 See |complete_info_mode| for the values.
1897 pum_visible |TRUE| if popup menu is visible.
1898 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001899 items List of all completion candidates. Each item
1900 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001901 "abbr", "menu", "kind", "info" and "user_data".
1902 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001903 matches Same as "items", but only returns items that
1904 are matching current query. If both "matches"
1905 and "items" are in "what", the returned list
1906 will still be named "items", but each item
1907 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001908 selected Selected item index. First index is zero.
1909 Index is -1 if no item is selected (showing
1910 typed text only, or the last completion after
1911 no item is selected when using the <Up> or
1912 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001913 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001914
1915 *complete_info_mode*
1916 mode values are:
1917 "" Not in completion mode
1918 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1919 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1920 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1921 |i_CTRL-X_CTRL-Y|
1922 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1923 "files" File names |i_CTRL-X_CTRL-F|
1924 "tags" Tags |i_CTRL-X_CTRL-]|
1925 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1926 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1927 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1928 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1929 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1930 "function" User defined completion |i_CTRL-X_CTRL-U|
1931 "omni" Omni completion |i_CTRL-X_CTRL-O|
1932 "spell" Spelling suggestions |i_CTRL-X_s|
1933 "eval" |complete()| completion
1934 "unknown" Other internal modes
1935
1936 If the optional {what} list argument is supplied, then only
1937 the items listed in {what} are returned. Unsupported items in
1938 {what} are silently ignored.
1939
1940 To get the position and size of the popup menu, see
1941 |pum_getpos()|. It's also available in |v:event| during the
1942 |CompleteChanged| event.
1943
Bram Moolenaar016188f2022-06-06 20:52:59 +01001944 Returns an empty |Dictionary| on error.
1945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001946 Examples: >
1947 " Get all items
1948 call complete_info()
1949 " Get only 'mode'
1950 call complete_info(['mode'])
1951 " Get only 'mode' and 'pum_visible'
1952 call complete_info(['mode', 'pum_visible'])
1953
1954< Can also be used as a |method|: >
1955 GetItems()->complete_info()
1956<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001957 Return type: dict<any>
1958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001959 *confirm()*
1960confirm({msg} [, {choices} [, {default} [, {type}]]])
1961 confirm() offers the user a dialog, from which a choice can be
1962 made. It returns the number of the choice. For the first
1963 choice this is 1.
1964 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02001965 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001966
1967 {msg} is displayed in a |dialog| with {choices} as the
1968 alternatives. When {choices} is missing or empty, "&OK" is
1969 used (and translated).
1970 {msg} is a String, use '\n' to include a newline. Only on
1971 some systems the string is wrapped when it doesn't fit.
1972
1973 {choices} is a String, with the individual choices separated
1974 by '\n', e.g. >
1975 confirm("Save changes?", "&Yes\n&No\n&Cancel")
1976< The letter after the '&' is the shortcut key for that choice.
1977 Thus you can type 'c' to select "Cancel". The shortcut does
1978 not need to be the first letter: >
1979 confirm("file has been modified", "&Save\nSave &All")
1980< For the console, the first letter of each choice is used as
1981 the default shortcut key. Case is ignored.
1982
1983 The optional {default} argument is the number of the choice
1984 that is made if the user hits <CR>. Use 1 to make the first
1985 choice the default one. Use 0 to not set a default. If
1986 {default} is omitted, 1 is used.
1987
1988 The optional {type} String argument gives the type of dialog.
1989 This is only used for the icon of the GTK, Mac, Motif and
1990 Win32 GUI. It can be one of these values: "Error",
1991 "Question", "Info", "Warning" or "Generic". Only the first
1992 character is relevant. When {type} is omitted, "Generic" is
1993 used.
1994
1995 If the user aborts the dialog by pressing <Esc>, CTRL-C,
1996 or another valid interrupt key, confirm() returns 0.
1997
1998 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01001999 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002000 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002001 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002002 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002003 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002004 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002005 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002006 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002007 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002008< In a GUI dialog, buttons are used. The layout of the buttons
2009 depends on the 'v' flag in 'guioptions'. If it is included,
2010 the buttons are always put vertically. Otherwise, confirm()
2011 tries to put the buttons in one horizontal line. If they
2012 don't fit, a vertical layout is used anyway. For some systems
2013 the horizontal layout is always used.
2014
2015 Can also be used as a |method|in: >
2016 BuildMessage()->confirm("&Yes\n&No")
2017<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002018 Return type: |Number|
2019
2020
2021copy({expr}) *copy()*
2022 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002023 different from using {expr} directly.
2024 When {expr} is a |List| a shallow copy is created. This means
2025 that the original |List| can be changed without changing the
2026 copy, and vice versa. But the items are identical, thus
2027 changing an item changes the contents of both |Lists|.
2028 A |Dictionary| is copied in a similar way as a |List|.
2029 Also see |deepcopy()|.
2030 Can also be used as a |method|: >
2031 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002032<
2033 Return type: any, depending on {expr}
2034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002035
2036cos({expr}) *cos()*
2037 Return the cosine of {expr}, measured in radians, as a |Float|.
2038 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002039 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002040 Examples: >
2041 :echo cos(100)
2042< 0.862319 >
2043 :echo cos(-4.01)
2044< -0.646043
2045
2046 Can also be used as a |method|: >
2047 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002048<
2049 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002050
2051
2052cosh({expr}) *cosh()*
2053 Return the hyperbolic cosine of {expr} as a |Float| in the range
2054 [1, inf].
2055 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002056 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002057 Examples: >
2058 :echo cosh(0.5)
2059< 1.127626 >
2060 :echo cosh(-0.5)
2061< -1.127626
2062
2063 Can also be used as a |method|: >
2064 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002065<
2066 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002067
2068
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002069count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002070 Return the number of times an item with value {expr} appears
2071 in |String|, |List| or |Dictionary| {comp}.
2072
2073 If {start} is given then start with the item with this index.
2074 {start} can only be used with a |List|.
2075
2076 When {ic} is given and it's |TRUE| then case is ignored.
2077
2078 When {comp} is a string then the number of not overlapping
2079 occurrences of {expr} is returned. Zero is returned when
2080 {expr} is an empty string.
2081
2082 Can also be used as a |method|: >
2083 mylist->count(val)
2084<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002085 Return type: |Number|
2086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002087 *cscope_connection()*
2088cscope_connection([{num} , {dbpath} [, {prepend}]])
2089 Checks for the existence of a |cscope| connection. If no
2090 parameters are specified, then the function returns:
2091 0, if cscope was not available (not compiled in), or
2092 if there are no cscope connections;
2093 1, if there is at least one cscope connection.
2094
2095 If parameters are specified, then the value of {num}
2096 determines how existence of a cscope connection is checked:
2097
2098 {num} Description of existence check
2099 ----- ------------------------------
2100 0 Same as no parameters (e.g., "cscope_connection()").
2101 1 Ignore {prepend}, and use partial string matches for
2102 {dbpath}.
2103 2 Ignore {prepend}, and use exact string matches for
2104 {dbpath}.
2105 3 Use {prepend}, use partial string matches for both
2106 {dbpath} and {prepend}.
2107 4 Use {prepend}, use exact string matches for both
2108 {dbpath} and {prepend}.
2109
2110 Note: All string comparisons are case sensitive!
2111
2112 Examples. Suppose we had the following (from ":cs show"): >
2113
2114 # pid database name prepend path
2115 0 27664 cscope.out /usr/local
2116<
2117 Invocation Return Val ~
2118 ---------- ---------- >
2119 cscope_connection() 1
2120 cscope_connection(1, "out") 1
2121 cscope_connection(2, "out") 0
2122 cscope_connection(3, "out") 0
2123 cscope_connection(3, "out", "local") 1
2124 cscope_connection(4, "out") 0
2125 cscope_connection(4, "out", "local") 0
2126 cscope_connection(4, "cscope.out", "/usr/local") 1
2127<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002128 Return type: |Number|
2129
2130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002131cursor({lnum}, {col} [, {off}]) *cursor()*
2132cursor({list})
2133 Positions the cursor at the column (byte count) {col} in the
2134 line {lnum}. The first column is one.
2135
2136 When there is one argument {list} this is used as a |List|
2137 with two, three or four item:
2138 [{lnum}, {col}]
2139 [{lnum}, {col}, {off}]
2140 [{lnum}, {col}, {off}, {curswant}]
2141 This is like the return value of |getpos()| or |getcurpos()|,
2142 but without the first item.
2143
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002144 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002145 |setcursorcharpos()|.
2146
2147 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002148 {lnum} is used like with |getline()|, except that if {lnum} is
2149 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002150 If {lnum} is greater than the number of lines in the buffer,
2151 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002152 If {col} is greater than the number of bytes in the line,
2153 the cursor will be positioned at the last character in the
2154 line.
2155 If {col} is zero, the cursor will stay in the current column.
2156 If {curswant} is given it is used to set the preferred column
2157 for vertical movement. Otherwise {col} is used.
2158
2159 When 'virtualedit' is used {off} specifies the offset in
2160 screen columns from the start of the character. E.g., a
2161 position within a <Tab> or after the last character.
2162 Returns 0 when the position could be set, -1 otherwise.
2163
2164 Can also be used as a |method|: >
2165 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002166<
2167 Return type: |Number|
2168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002169
2170debugbreak({pid}) *debugbreak()*
2171 Specifically used to interrupt a program being debugged. It
2172 will cause process {pid} to get a SIGTRAP. Behavior for other
2173 processes is undefined. See |terminal-debugger|.
2174 {only available on MS-Windows}
2175
Bram Moolenaar016188f2022-06-06 20:52:59 +01002176 Returns |TRUE| if successfully interrupted the program.
2177 Otherwise returns |FALSE|.
2178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002179 Can also be used as a |method|: >
2180 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002181<
2182 Return type: |Number|
2183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002184
2185deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2186 Make a copy of {expr}. For Numbers and Strings this isn't
2187 different from using {expr} directly.
2188 When {expr} is a |List| a full copy is created. This means
2189 that the original |List| can be changed without changing the
2190 copy, and vice versa. When an item is a |List| or
2191 |Dictionary|, a copy for it is made, recursively. Thus
2192 changing an item in the copy does not change the contents of
2193 the original |List|.
2194 A |Dictionary| is copied in a similar way as a |List|.
2195
2196 When {noref} is omitted or zero a contained |List| or
2197 |Dictionary| is only copied once. All references point to
2198 this single copy. With {noref} set to 1 every occurrence of a
2199 |List| or |Dictionary| results in a new copy. This also means
2200 that a cyclic reference causes deepcopy() to fail.
2201 *E724*
2202 Nesting is possible up to 100 levels. When there is an item
2203 that refers back to a higher level making a deep copy with
2204 {noref} set to 1 will fail.
2205 Also see |copy()|.
2206
2207 Can also be used as a |method|: >
2208 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002209<
2210 Return type: any, depending on {expr}
2211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002212
2213delete({fname} [, {flags}]) *delete()*
2214 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002215 name {fname}.
2216
2217 This also works when {fname} is a symbolic link. The symbolic
2218 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002219
2220 When {flags} is "d": Deletes the directory by the name
2221 {fname}. This fails when directory {fname} is not empty.
2222
2223 When {flags} is "rf": Deletes the directory by the name
2224 {fname} and everything in it, recursively. BE CAREFUL!
2225 Note: on MS-Windows it is not possible to delete a directory
2226 that is being used.
2227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002228 The result is a Number, which is 0/false if the delete
2229 operation was successful and -1/true when the deletion failed
2230 or partly failed.
2231
2232 Use |remove()| to delete an item from a |List|.
2233 To delete a line from the buffer use |:delete| or
2234 |deletebufline()|.
2235
2236 Can also be used as a |method|: >
2237 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002238<
2239 Return type: |Number|
2240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002241
2242deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2243 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2244 If {last} is omitted then delete line {first} only.
2245 On success 0 is returned, on failure 1 is returned.
2246
2247 This function works only for loaded buffers. First call
2248 |bufload()| if needed.
2249
2250 For the use of {buf}, see |bufname()| above.
2251
2252 {first} and {last} are used like with |getline()|. Note that
2253 when using |line()| this refers to the current buffer. Use "$"
2254 to refer to the last line in buffer {buf}.
2255
2256 Can also be used as a |method|: >
2257 GetBuffer()->deletebufline(1)
2258<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002259 Return type: |Number|
2260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002261 *did_filetype()*
2262did_filetype() Returns |TRUE| when autocommands are being executed and the
2263 FileType event has been triggered at least once. Can be used
2264 to avoid triggering the FileType event again in the scripts
2265 that detect the file type. |FileType|
2266 Returns |FALSE| when `:setf FALLBACK` was used.
2267 When editing another file, the counter is reset, thus this
2268 really checks if the FileType event has been triggered for the
2269 current buffer. This allows an autocommand that starts
2270 editing another buffer to set 'filetype' and load a syntax
2271 file.
2272
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002273 Return type: |Number|
2274
2275
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002276diff({fromlist}, {tolist} [, {options}]) *diff()*
2277 Returns a String or a List containing the diff between the
2278 strings in {fromlist} and {tolist}. Uses the Vim internal
2279 diff library to compute the diff.
2280
2281 *E106*
2282 The optional "output" item in {options} specifies the returned
2283 diff format. The following values are supported:
2284 indices Return a List of the starting and ending
2285 indices and a count of the strings in each
2286 diff hunk.
2287 unified Return the unified diff output as a String.
2288 This is the default.
2289
2290 If the "output" item in {options} is "indices", then a List is
2291 returned. Each List item contains a Dict with the following
2292 items for each diff hunk:
2293 from_idx start index in {fromlist} for this diff hunk.
2294 from_count number of strings in {fromlist} that are
2295 added/removed/modified in this diff hunk.
2296 to_idx start index in {tolist} for this diff hunk.
2297 to_count number of strings in {tolist} that are
2298 added/removed/modified in this diff hunk.
2299
2300 The {options} Dict argument also specifies diff options
2301 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002302 algorithm Dict specifying the diff algorithm to
2303 use. Supported boolean items are
2304 "myers", "minimal", "patience" and
2305 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002306 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002307 iblank ignore changes where lines are all
2308 blank.
2309 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002310 indent-heuristic use the indent heuristic for the
2311 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002312 iwhite ignore changes in amount of white
2313 space.
2314 iwhiteall ignore all white space changes.
2315 iwhiteeol ignore white space changes at end of
2316 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002317 For more information about these options, refer to 'diffopt'.
2318
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002319 To compute the unified diff, all the items in {fromlist} are
2320 concatenated into a string using a newline separator and the
2321 same for {tolist}. The unified diff output uses line numbers.
2322
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002323 Returns an empty List or String if {fromlist} and {tolist} are
2324 identical.
2325
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002326 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002327 :echo diff(['abc'], ['xxx'])
2328 @@ -1 +1 @@
2329 -abc
2330 +xxx
2331
2332 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2333 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2334 :echo diff(readfile('oldfile'), readfile('newfile'))
2335 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002336<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002337 For more examples, refer to |diff-func-examples|
2338
2339 Can also be used as a |method|: >
2340 GetFromList->diff(to_list)
2341<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002342 Return type: |String| or list<dict<number>> or list<any>
2343 depending on {options}
2344
2345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002346diff_filler({lnum}) *diff_filler()*
2347 Returns the number of filler lines above line {lnum}.
2348 These are the lines that were inserted at this point in
2349 another diff'ed window. These filler lines are shown in the
2350 display but don't exist in the buffer.
2351 {lnum} is used like with |getline()|. Thus "." is the current
2352 line, "'m" mark m, etc.
2353 Returns 0 if the current window is not in diff mode.
2354
2355 Can also be used as a |method|: >
2356 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002357<
2358 Return type: |Number|
2359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002360
2361diff_hlID({lnum}, {col}) *diff_hlID()*
2362 Returns the highlight ID for diff mode at line {lnum} column
2363 {col} (byte index). When the current line does not have a
2364 diff change zero is returned.
2365 {lnum} is used like with |getline()|. Thus "." is the current
2366 line, "'m" mark m, etc.
2367 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2368 line.
2369 The highlight ID can be used with |synIDattr()| to obtain
2370 syntax information about the highlighting.
2371
2372 Can also be used as a |method|: >
2373 GetLnum()->diff_hlID(col)
2374<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002375 Return type: |Number|
2376
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002377
2378digraph_get({chars}) *digraph_get()* *E1214*
2379 Return the digraph of {chars}. This should be a string with
2380 exactly two characters. If {chars} are not just two
2381 characters, or the digraph of {chars} does not exist, an error
2382 is given and an empty string is returned.
2383
2384 The character will be converted from Unicode to 'encoding'
2385 when needed. This does require the conversion to be
2386 available, it might fail.
2387
2388 Also see |digraph_getlist()|.
2389
2390 Examples: >
2391 " Get a built-in digraph
2392 :echo digraph_get('00') " Returns '∞'
2393
2394 " Get a user-defined digraph
2395 :call digraph_set('aa', 'あ')
2396 :echo digraph_get('aa') " Returns 'あ'
2397<
2398 Can also be used as a |method|: >
2399 GetChars()->digraph_get()
2400<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002401 Return type: |String|
2402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002403 This function works only when compiled with the |+digraphs|
2404 feature. If this feature is disabled, this function will
2405 display an error message.
2406
2407
2408digraph_getlist([{listall}]) *digraph_getlist()*
2409 Return a list of digraphs. If the {listall} argument is given
2410 and it is TRUE, return all digraphs, including the default
2411 digraphs. Otherwise, return only user-defined digraphs.
2412
2413 The characters will be converted from Unicode to 'encoding'
2414 when needed. This does require the conservation to be
2415 available, it might fail.
2416
2417 Also see |digraph_get()|.
2418
2419 Examples: >
2420 " Get user-defined digraphs
2421 :echo digraph_getlist()
2422
2423 " Get all the digraphs, including default digraphs
2424 :echo digraph_getlist(1)
2425<
2426 Can also be used as a |method|: >
2427 GetNumber()->digraph_getlist()
2428<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002429 Return type: list<list<string>>
2430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002431 This function works only when compiled with the |+digraphs|
2432 feature. If this feature is disabled, this function will
2433 display an error message.
2434
2435
Bram Moolenaara2baa732022-02-04 16:09:54 +00002436digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002437 Add digraph {chars} to the list. {chars} must be a string
2438 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002439 encoded character. *E1215*
2440 Be careful, composing characters are NOT ignored. This
2441 function is similar to |:digraphs| command, but useful to add
2442 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002443
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002444 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002445 this fails an error message is given and v:false is returned.
2446
2447 If you want to define multiple digraphs at once, you can use
2448 |digraph_setlist()|.
2449
2450 Example: >
2451 call digraph_set(' ', 'あ')
2452<
2453 Can be used as a |method|: >
2454 GetString()->digraph_set('あ')
2455<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002456 Return type: |vim9-boolean|
2457
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002458 This function works only when compiled with the |+digraphs|
2459 feature. If this feature is disabled, this function will
2460 display an error message.
2461
2462
2463digraph_setlist({digraphlist}) *digraph_setlist()*
2464 Similar to |digraph_set()| but this function can add multiple
2465 digraphs at once. {digraphlist} is a list composed of lists,
2466 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002467 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002468 Example: >
2469 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2470<
2471 It is similar to the following: >
2472 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2473 call digraph_set(chars, digraph)
2474 endfor
2475< Except that the function returns after the first error,
2476 following digraphs will not be added.
2477
2478 Can be used as a |method|: >
2479 GetList()->digraph_setlist()
2480<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002481 Return type: |vim9-boolean|
2482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002483 This function works only when compiled with the |+digraphs|
2484 feature. If this feature is disabled, this function will
2485 display an error message.
2486
2487
2488echoraw({string}) *echoraw()*
2489 Output {string} as-is, including unprintable characters.
2490 This can be used to output a terminal code. For example, to
2491 disable modifyOtherKeys: >
2492 call echoraw(&t_TE)
2493< and to enable it again: >
2494 call echoraw(&t_TI)
2495< Use with care, you can mess up the terminal this way.
2496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002497 Return type: |Number|
2498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002499
2500empty({expr}) *empty()*
2501 Return the Number 1 if {expr} is empty, zero otherwise.
2502 - A |List| or |Dictionary| is empty when it does not have any
2503 items.
2504 - A |String| is empty when its length is zero.
2505 - A |Number| and |Float| are empty when their value is zero.
2506 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2507 - A |Job| is empty when it failed to start.
2508 - A |Channel| is empty when it is closed.
2509 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002510 - An |Object| is empty, when the empty() method in the object
2511 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002512
2513 For a long |List| this is much faster than comparing the
2514 length with zero.
2515
2516 Can also be used as a |method|: >
2517 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002518<
2519 Return type: |Number|
2520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521
2522environ() *environ()*
2523 Return all of environment variables as dictionary. You can
2524 check if an environment variable exists like this: >
2525 :echo has_key(environ(), 'HOME')
2526< Note that the variable name may be CamelCase; to ignore case
2527 use this: >
2528 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002529<
2530 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002531
Bram Moolenaar416bd912023-07-07 23:19:18 +01002532
2533err_teapot([{expr}]) *err_teapot()*
2534 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002535 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002536 If {expr} is present and it is TRUE error 503 is given,
2537 indicating that coffee is temporarily not available.
2538 If {expr} is present it must be a String.
2539
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002540 Return type: |Number|
2541
Bram Moolenaar416bd912023-07-07 23:19:18 +01002542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002543escape({string}, {chars}) *escape()*
2544 Escape the characters in {chars} that occur in {string} with a
2545 backslash. Example: >
2546 :echo escape('c:\program files\vim', ' \')
2547< results in: >
2548 c:\\program\ files\\vim
2549< Also see |shellescape()| and |fnameescape()|.
2550
2551 Can also be used as a |method|: >
2552 GetText()->escape(' \')
2553<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002554 Return type: |String|
2555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002556 *eval()*
2557eval({string}) Evaluate {string} and return the result. Especially useful to
2558 turn the result of |string()| back into the original value.
2559 This works for Numbers, Floats, Strings, Blobs and composites
2560 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002561 functions. In |Vim9| script, it can be used to obtain |enum|
2562 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002563
2564 Can also be used as a |method|: >
2565 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002566<
2567 Return type: any, depending on {string}
2568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002569
2570eventhandler() *eventhandler()*
2571 Returns 1 when inside an event handler. That is that Vim got
2572 interrupted while waiting for the user to type a character,
2573 e.g., when dropping a file on Vim. This means interactive
2574 commands cannot be used. Otherwise zero is returned.
2575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002576 Return type: |Number|
2577
2578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002579executable({expr}) *executable()*
2580 This function checks if an executable with the name {expr}
2581 exists. {expr} must be the name of the program without any
2582 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002583
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002584 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002585 searchpath for programs.
2586 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002587 On MS-Windows the ".exe", ".bat", etc. can optionally be
2588 included. Then the extensions in $PATHEXT are tried. Thus if
2589 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2590 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2591 by itself can be used in $PATHEXT to try using the name
2592 without an extension. When 'shell' looks like a Unix shell,
2593 then the name is also tried without adding an extension.
2594 On MS-Windows it only checks if the file exists and is not a
2595 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002596 On MS-Windows an executable in the same directory as the Vim
2597 executable is always found. Since this directory is added to
2598 $PATH it should also work to execute it |win32-PATH|.
2599 *NoDefaultCurrentDirectoryInExePath*
2600 On MS-Windows an executable in Vim's current working directory
2601 is also normally found, but this can be disabled by setting
2602 the $NoDefaultCurrentDirectoryInExePath environment variable.
2603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002604 The result is a Number:
2605 1 exists
2606 0 does not exist
2607 -1 not implemented on this system
2608 |exepath()| can be used to get the full path of an executable.
2609
2610 Can also be used as a |method|: >
2611 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002612<
2613 Return type: |Number|
2614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002615
2616execute({command} [, {silent}]) *execute()*
2617 Execute an Ex command or commands and return the output as a
2618 string.
2619 {command} can be a string or a List. In case of a List the
2620 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002621 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002622 redir => var
2623 {command}
2624 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002625< Except that line continuation in {command} is not recognized.
2626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002627 The optional {silent} argument can have these values:
2628 "" no `:silent` used
2629 "silent" `:silent` used
2630 "silent!" `:silent!` used
2631 The default is "silent". Note that with "silent!", unlike
2632 `:redir`, error messages are dropped. When using an external
2633 command the screen may be messed up, use `system()` instead.
2634 *E930*
2635 It is not possible to use `:redir` anywhere in {command}.
2636
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002637 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002638 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002639
2640< To execute a command in another window than the current one
2641 use `win_execute()`.
2642
2643 When used recursively the output of the recursive call is not
2644 included in the output of the higher level call.
2645
2646 Can also be used as a |method|: >
2647 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002648<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002649 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002651
2652exepath({expr}) *exepath()*
2653 If {expr} is an executable and is either an absolute path, a
2654 relative path or found in $PATH, return the full path.
2655 Note that the current directory is used when {expr} starts
2656 with "./", which may be a problem for Vim: >
2657 echo exepath(v:progpath)
2658< If {expr} cannot be found in $PATH or is not executable then
2659 an empty string is returned.
2660
2661 Can also be used as a |method|: >
2662 GetCommand()->exepath()
2663<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002664 Return type: |String|
2665
2666
2667exists({expr}) *exists()*
2668 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002669 zero otherwise.
2670
2671 Note: In a compiled |:def| function the evaluation is done at
2672 runtime. Use `exists_compiled()` to evaluate the expression
2673 at compile time.
2674
2675 For checking for a supported feature use |has()|.
2676 For checking if a file exists use |filereadable()|.
2677
2678 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002679 varname internal variable (see
2680 dict.key |internal-variables|). Also works
2681 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002682 import.Func entries, |List| items, class and
2683 class.Func object methods, imported items, etc.
2684 object.Func Does not work for local variables in a
2685 class.varname compiled `:def` function.
2686 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002687 script, since it can be used as a
2688 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002689 Beware that evaluating an index may
2690 cause an error message for an invalid
2691 expression. E.g.: >
2692 :let l = [1, 2, 3]
2693 :echo exists("l[5]")
2694< 0 >
2695 :echo exists("l[xx]")
2696< E121: Undefined variable: xx
2697 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002698 &option-name Vim option (only checks if it exists,
2699 not if it really works)
2700 +option-name Vim option that works.
2701 $ENVNAME environment variable (could also be
2702 done by comparing with an empty
2703 string)
2704 *funcname built-in function (see |functions|)
2705 or user defined function (see
2706 |user-functions|) that is implemented.
2707 Also works for a variable that is a
2708 Funcref.
2709 ?funcname built-in function that could be
2710 implemented; to be used to check if
2711 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002712 :cmdname Ex command: built-in command, user
2713 command or command modifier |:command|.
2714 Returns:
2715 1 for match with start of a command
2716 2 full match with a command
2717 3 matches several user commands
2718 To check for a supported command
2719 always check the return value to be 2.
2720 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002721 :3match The |:3match| command (but you
2722 probably should not use it, it is
2723 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002724 #event autocommand defined for this event
2725 #event#pattern autocommand defined for this event and
2726 pattern (the pattern is taken
2727 literally and compared to the
2728 autocommand patterns character by
2729 character)
2730 #group autocommand group exists
2731 #group#event autocommand defined for this group and
2732 event.
2733 #group#event#pattern
2734 autocommand defined for this group,
2735 event and pattern.
2736 ##event autocommand for this event is
2737 supported.
2738
2739 Examples: >
2740 exists("&shortname")
2741 exists("$HOSTNAME")
2742 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002743 exists("*s:MyFunc") " only for legacy script
2744 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002745 exists("bufcount")
2746 exists(":Make")
2747 exists("#CursorHold")
2748 exists("#BufReadPre#*.gz")
2749 exists("#filetypeindent")
2750 exists("#filetypeindent#FileType")
2751 exists("#filetypeindent#FileType#*")
2752 exists("##ColorScheme")
2753< There must be no space between the symbol (&/$/*/#) and the
2754 name.
2755 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002756 a few cases this is ignored. That may become stricter in the
2757 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002758 Working example: >
2759 exists(":make")
2760< NOT working example: >
2761 exists(":make install")
2762
2763< Note that the argument must be a string, not the name of the
2764 variable itself. For example: >
2765 exists(bufcount)
2766< This doesn't check for existence of the "bufcount" variable,
2767 but gets the value of "bufcount", and checks if that exists.
2768
2769 Can also be used as a |method|: >
2770 Varname()->exists()
2771<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002772 Return type: |String|
2773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002774
2775exists_compiled({expr}) *exists_compiled()*
2776 Like `exists()` but evaluated at compile time. This is useful
2777 to skip a block where a function is used that would otherwise
2778 give an error: >
2779 if exists_compiled('*ThatFunction')
2780 ThatFunction('works')
2781 endif
2782< If `exists()` were used then a compilation error would be
2783 given if ThatFunction() is not defined.
2784
2785 {expr} must be a literal string. *E1232*
2786 Can only be used in a |:def| function. *E1233*
2787 This does not work to check for arguments or local variables.
2788
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002789 Return type: |String|
2790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002791
2792exp({expr}) *exp()*
2793 Return the exponential of {expr} as a |Float| in the range
2794 [0, inf].
2795 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002796 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002797 Examples: >
2798 :echo exp(2)
2799< 7.389056 >
2800 :echo exp(-1)
2801< 0.367879
2802
2803 Can also be used as a |method|: >
2804 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002805<
2806 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002807
2808
2809expand({string} [, {nosuf} [, {list}]]) *expand()*
2810 Expand wildcards and the following special keywords in
2811 {string}. 'wildignorecase' applies.
2812
2813 If {list} is given and it is |TRUE|, a List will be returned.
2814 Otherwise the result is a String and when there are several
2815 matches, they are separated by <NL> characters. [Note: in
2816 version 5.0 a space was used, which caused problems when a
2817 file name contains a space]
2818
2819 If the expansion fails, the result is an empty string. A name
2820 for a non-existing file is not included, unless {string} does
2821 not start with '%', '#' or '<', see below.
2822
Christian Brabandtec9c3262024-02-21 20:40:05 +01002823 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002824 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002826 When {string} starts with '%', '#' or '<', the expansion is
2827 done like for the |cmdline-special| variables with their
2828 associated modifiers. Here is a short overview:
2829
2830 % current file name
2831 # alternate file name
2832 #n alternate file name n
2833 <cfile> file name under the cursor
2834 <afile> autocmd file name
2835 <abuf> autocmd buffer number (as a String!)
2836 <amatch> autocmd matched name
2837 <cexpr> C expression under the cursor
2838 <sfile> sourced script file or function name
2839 <slnum> sourced script line number or function
2840 line number
2841 <sflnum> script file line number, also when in
2842 a function
2843 <SID> "<SNR>123_" where "123" is the
2844 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002845 <script> sourced script file, or script file
2846 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002847 <stack> call stack
2848 <cword> word under the cursor
2849 <cWORD> WORD under the cursor
2850 <client> the {clientid} of the last received
2851 message |server2client()|
2852 Modifiers:
2853 :p expand to full path
2854 :h head (last path component removed)
2855 :t tail (last path component only)
2856 :r root (one extension removed)
2857 :e extension only
2858
2859 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002860 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002861< Note that when expanding a string that starts with '%', '#' or
2862 '<', any following text is ignored. This does NOT work: >
2863 :let doesntwork = expand("%:h.bak")
2864< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002865 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002866< Also note that expanding "<cfile>" and others only returns the
2867 referenced file name without further expansion. If "<cfile>"
2868 is "~/.cshrc", you need to do another expand() to have the
2869 "~/" expanded into the path of the home directory: >
2870 :echo expand(expand("<cfile>"))
2871<
2872 There cannot be white space between the variables and the
2873 following modifier. The |fnamemodify()| function can be used
2874 to modify normal file names.
2875
2876 When using '%' or '#', and the current or alternate file name
2877 is not defined, an empty string is used. Using "%:p" in a
2878 buffer with no name, results in the current directory, with a
2879 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002880 When 'verbose' is set then expanding '%', '#' and <> items
2881 will result in an error message if the argument cannot be
2882 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883
2884 When {string} does not start with '%', '#' or '<', it is
2885 expanded like a file name is expanded on the command line.
2886 'suffixes' and 'wildignore' are used, unless the optional
2887 {nosuf} argument is given and it is |TRUE|.
2888 Names for non-existing files are included. The "**" item can
2889 be used to search in a directory tree. For example, to find
2890 all "README" files in the current directory and below: >
2891 :echo expand("**/README")
2892<
2893 expand() can also be used to expand variables and environment
2894 variables that are only known in a shell. But this can be
2895 slow, because a shell may be used to do the expansion. See
2896 |expr-env-expand|.
2897 The expanded variable is still handled like a list of file
2898 names. When an environment variable cannot be expanded, it is
2899 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2900 "$FOOBAR".
2901
2902 See |glob()| for finding existing files. See |system()| for
2903 getting the raw output of an external command.
2904
2905 Can also be used as a |method|: >
2906 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002907<
2908 Return type: |String| or list<string> depending on {list}
2909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002910
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002911expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002912 Expand special items in String {string} like what is done for
2913 an Ex command such as `:edit`. This expands special keywords,
2914 like with |expand()|, and environment variables, anywhere in
2915 {string}. "~user" and "~/path" are only expanded at the
2916 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002917
2918 The following items are supported in the {options} Dict
2919 argument:
2920 errmsg If set to TRUE, error messages are displayed
2921 if an error is encountered during expansion.
2922 By default, error messages are not displayed.
2923
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002924 Returns the expanded string. If an error is encountered
2925 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002926
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002927 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002928 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002929 make /path/runtime/doc/builtin.o
2930 :echo expandcmd('make %<.o', {'errmsg': v:true})
2931<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002932 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002933 GetCommand()->expandcmd()
2934<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002935 Return type: |String| or list<string> depending on {list}
2936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002937extend({expr1}, {expr2} [, {expr3}]) *extend()*
2938 {expr1} and {expr2} must be both |Lists| or both
2939 |Dictionaries|.
2940
2941 If they are |Lists|: Append {expr2} to {expr1}.
2942 If {expr3} is given insert the items of {expr2} before the
2943 item with index {expr3} in {expr1}. When {expr3} is zero
2944 insert before the first item. When {expr3} is equal to
2945 len({expr1}) then {expr2} is appended.
2946 Examples: >
2947 :echo sort(extend(mylist, [7, 5]))
2948 :call extend(mylist, [2, 3], 1)
2949< When {expr1} is the same List as {expr2} then the number of
2950 items copied is equal to the original length of the List.
2951 E.g., when {expr3} is 1 you get N new copies of the first item
2952 (where N is the original length of the List).
2953 Use |add()| to concatenate one item to a list. To concatenate
2954 two lists into a new list use the + operator: >
2955 :let newlist = [1, 2, 3] + [4, 5]
2956<
2957 If they are |Dictionaries|:
2958 Add all entries from {expr2} to {expr1}.
2959 If a key exists in both {expr1} and {expr2} then {expr3} is
2960 used to decide what to do:
2961 {expr3} = "keep": keep the value of {expr1}
2962 {expr3} = "force": use the value of {expr2}
2963 {expr3} = "error": give an error message *E737*
2964 When {expr3} is omitted then "force" is assumed.
2965
2966 {expr1} is changed when {expr2} is not empty. If necessary
2967 make a copy of {expr1} first.
2968 {expr2} remains unchanged.
2969 When {expr1} is locked and {expr2} is not empty the operation
2970 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002971 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002972
2973 Can also be used as a |method|: >
2974 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002975<
2976 Return type: list<{type}> or dict<{type}> depending on {expr1}
2977 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002978
2979
2980extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
2981 Like |extend()| but instead of adding items to {expr1} a new
2982 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00002983 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002984
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002985 Return type: list<{type}> or dict<{type}> depending on {expr1}
2986 and {expr2}, in case of error: |Number|
2987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002988
2989feedkeys({string} [, {mode}]) *feedkeys()*
2990 Characters in {string} are queued for processing as if they
2991 come from a mapping or were typed by the user.
2992
2993 By default the string is added to the end of the typeahead
2994 buffer, thus if a mapping is still being executed the
2995 characters come after them. Use the 'i' flag to insert before
2996 other characters, they will be executed next, before any
2997 characters from a mapping.
2998
2999 The function does not wait for processing of keys contained in
3000 {string}.
3001
3002 To include special keys into {string}, use double-quotes
3003 and "\..." notation |expr-quote|. For example,
3004 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3005 feedkeys('\<CR>') pushes 5 characters.
3006 A special code that might be useful is <Ignore>, it exits the
3007 wait for a character without doing anything. *<Ignore>*
3008
3009 {mode} is a String, which can contain these character flags:
3010 'm' Remap keys. This is default. If {mode} is absent,
3011 keys are remapped.
3012 'n' Do not remap keys.
3013 't' Handle keys as if typed; otherwise they are handled as
3014 if coming from a mapping. This matters for undo,
3015 opening folds, etc.
3016 'L' Lowlevel input. Only works for Unix or when using the
3017 GUI. Keys are used as if they were coming from the
3018 terminal. Other flags are not used. *E980*
3019 When a CTRL-C interrupts and 't' is included it sets
3020 the internal "got_int" flag.
3021 'i' Insert the string instead of appending (see above).
3022 'x' Execute commands until typeahead is empty. This is
3023 similar to using ":normal!". You can call feedkeys()
3024 several times without 'x' and then one time with 'x'
3025 (possibly with an empty {string}) to execute all the
3026 typeahead. Note that when Vim ends in Insert mode it
3027 will behave as if <Esc> is typed, to avoid getting
3028 stuck, waiting for a character to be typed before the
3029 script continues.
3030 Note that if you manage to call feedkeys() while
3031 executing commands, thus calling it recursively, then
3032 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003033 'c' Remove any script context when executing, so that
3034 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003035 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003036 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003037 '!' When used with 'x' will not end Insert mode. Can be
3038 used in a test when a timer is set to exit Insert mode
3039 a little later. Useful for testing CursorHoldI.
3040
3041 Return value is always 0.
3042
3043 Can also be used as a |method|: >
3044 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003045<
3046 Return type: |String| or list<string> depending on {list}
3047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003048
Shougo Matsushita60c87432024-06-03 22:59:27 +02003049filecopy({from}, {to}) *filecopy()*
3050 Copy the file pointed to by the name {from} to {to}. The
3051 result is a Number, which is |TRUE| if the file was copied
3052 successfully, and |FALSE| when it failed.
3053 If a file with name {to} already exists, it will fail.
3054 Note that it does not handle directories (yet).
3055
3056 This function is not available in the |sandbox|.
3057
3058 Can also be used as a |method|: >
3059 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003060<
3061 Return type: |Number|
3062
Shougo Matsushita60c87432024-06-03 22:59:27 +02003063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003064filereadable({file}) *filereadable()*
3065 The result is a Number, which is |TRUE| when a file with the
3066 name {file} exists, and can be read. If {file} doesn't exist,
3067 or is a directory, the result is |FALSE|. {file} is any
3068 expression, which is used as a String.
3069 If you don't care about the file being readable you can use
3070 |glob()|.
3071 {file} is used as-is, you may want to expand wildcards first: >
3072 echo filereadable('~/.vimrc')
3073 0
3074 echo filereadable(expand('~/.vimrc'))
3075 1
3076
3077< Can also be used as a |method|: >
3078 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003079<
3080 Return type: |Number|
3081
3082 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003083 Obsolete name: file_readable().
3084
3085
3086filewritable({file}) *filewritable()*
3087 The result is a Number, which is 1 when a file with the
3088 name {file} exists, and can be written. If {file} doesn't
3089 exist, or is not writable, the result is 0. If {file} is a
3090 directory, and we can write to it, the result is 2.
3091
3092 Can also be used as a |method|: >
3093 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003094<
3095 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003096
3097
3098filter({expr1}, {expr2}) *filter()*
3099 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3100 For each item in {expr1} evaluate {expr2} and when the result
3101 is zero or false remove the item from the |List| or
3102 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003103 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003104
3105 {expr2} must be a |string| or |Funcref|.
3106
3107 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3108 of the current item. For a |Dictionary| |v:key| has the key
3109 of the current item and for a |List| |v:key| has the index of
3110 the current item. For a |Blob| |v:key| has the index of the
3111 current byte. For a |String| |v:key| has the index of the
3112 current character.
3113 Examples: >
3114 call filter(mylist, 'v:val !~ "OLD"')
3115< Removes the items where "OLD" appears. >
3116 call filter(mydict, 'v:key >= 8')
3117< Removes the items with a key below 8. >
3118 call filter(var, 0)
3119< Removes all the items, thus clears the |List| or |Dictionary|.
3120
3121 Note that {expr2} is the result of expression and is then
3122 used as an expression again. Often it is good to use a
3123 |literal-string| to avoid having to double backslashes.
3124
3125 If {expr2} is a |Funcref| it must take two arguments:
3126 1. the key or the index of the current item.
3127 2. the value of the current item.
3128 The function must return |TRUE| if the item should be kept.
3129 Example that keeps the odd items of a list: >
3130 func Odd(idx, val)
3131 return a:idx % 2 == 1
3132 endfunc
3133 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003134< It is shorter when using a |lambda|. In |Vim9| syntax: >
3135 call filter(myList, (idx, val) => idx * val <= 42)
3136< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003137 call filter(myList, {idx, val -> idx * val <= 42})
3138< If you do not use "val" you can leave it out: >
3139 call filter(myList, {idx -> idx % 2 == 1})
3140<
3141 In |Vim9| script the result must be true, false, zero or one.
3142 Other values will result in a type error.
3143
3144 For a |List| and a |Dictionary| the operation is done
3145 in-place. If you want it to remain unmodified make a copy
3146 first: >
3147 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3148
3149< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003150 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003151 When an error is encountered while evaluating {expr2} no
3152 further items in {expr1} are processed.
3153 When {expr2} is a Funcref errors inside a function are ignored,
3154 unless it was defined with the "abort" flag.
3155
3156 Can also be used as a |method|: >
3157 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003158<
3159 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3160 depending on {expr1}
3161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003162
3163finddir({name} [, {path} [, {count}]]) *finddir()*
3164 Find directory {name} in {path}. Supports both downwards and
3165 upwards recursive directory searches. See |file-searching|
3166 for the syntax of {path}.
3167
3168 Returns the path of the first found match. When the found
3169 directory is below the current directory a relative path is
3170 returned. Otherwise a full path is returned.
3171 If {path} is omitted or empty then 'path' is used.
3172
3173 If the optional {count} is given, find {count}'s occurrence of
3174 {name} in {path} instead of the first one.
3175 When {count} is negative return all the matches in a |List|.
3176
Bram Moolenaar016188f2022-06-06 20:52:59 +01003177 Returns an empty string if the directory is not found.
3178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003179 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003180
3181 Can also be used as a |method|: >
3182 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003183<
3184 Return type: |String|
3185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003186
3187findfile({name} [, {path} [, {count}]]) *findfile()*
3188 Just like |finddir()|, but find a file instead of a directory.
3189 Uses 'suffixesadd'.
3190 Example: >
3191 :echo findfile("tags.vim", ".;")
3192< Searches from the directory of the current file upwards until
3193 it finds the file "tags.vim".
3194
3195 Can also be used as a |method|: >
3196 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003197<
3198 Return type: |String|
3199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003200
3201flatten({list} [, {maxdepth}]) *flatten()*
3202 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3203 the result is a |List| without nesting, as if {maxdepth} is
3204 a very large number.
3205 The {list} is changed in place, use |flattennew()| if you do
3206 not want that.
3207 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003208 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003209 *E900*
3210 {maxdepth} means how deep in nested lists changes are made.
3211 {list} is not modified when {maxdepth} is 0.
3212 {maxdepth} must be positive number.
3213
3214 If there is an error the number zero is returned.
3215
3216 Example: >
3217 :echo flatten([1, [2, [3, 4]], 5])
3218< [1, 2, 3, 4, 5] >
3219 :echo flatten([1, [2, [3, 4]], 5], 1)
3220< [1, 2, [3, 4], 5]
3221
3222 Can also be used as a |method|: >
3223 mylist->flatten()
3224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003225 Return type: list<{type}>
3226
3227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003228flattennew({list} [, {maxdepth}]) *flattennew()*
3229 Like |flatten()| but first make a copy of {list}.
3230
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003231 Return type: list<{type}>
3232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003233
3234float2nr({expr}) *float2nr()*
3235 Convert {expr} to a Number by omitting the part after the
3236 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003237 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003238 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003239 When the value of {expr} is out of range for a |Number| the
3240 result is truncated to 0x7fffffff or -0x7fffffff (or when
3241 64-bit Number support is enabled, 0x7fffffffffffffff or
3242 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3243 64-bit Number support is enabled, -0x8000000000000000).
3244 Examples: >
3245 echo float2nr(3.95)
3246< 3 >
3247 echo float2nr(-23.45)
3248< -23 >
3249 echo float2nr(1.0e100)
3250< 2147483647 (or 9223372036854775807) >
3251 echo float2nr(-1.0e150)
3252< -2147483647 (or -9223372036854775807) >
3253 echo float2nr(1.0e-100)
3254< 0
3255
3256 Can also be used as a |method|: >
3257 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003258<
3259 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003260
3261
3262floor({expr}) *floor()*
3263 Return the largest integral value less than or equal to
3264 {expr} as a |Float| (round down).
3265 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003266 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003267 Examples: >
3268 echo floor(1.856)
3269< 1.0 >
3270 echo floor(-5.456)
3271< -6.0 >
3272 echo floor(4.0)
3273< 4.0
3274
3275 Can also be used as a |method|: >
3276 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003277<
3278 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003279
3280
3281fmod({expr1}, {expr2}) *fmod()*
3282 Return the remainder of {expr1} / {expr2}, even if the
3283 division is not representable. Returns {expr1} - i * {expr2}
3284 for some integer i such that if {expr2} is non-zero, the
3285 result has the same sign as {expr1} and magnitude less than
3286 the magnitude of {expr2}. If {expr2} is zero, the value
3287 returned is zero. The value returned is a |Float|.
3288 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003289 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3290 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003291 Examples: >
3292 :echo fmod(12.33, 1.22)
3293< 0.13 >
3294 :echo fmod(-12.33, 1.22)
3295< -0.13
3296
3297 Can also be used as a |method|: >
3298 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003299<
3300 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003301
3302
3303fnameescape({string}) *fnameescape()*
3304 Escape {string} for use as file name command argument. All
3305 characters that have a special meaning, such as '%' and '|'
3306 are escaped with a backslash.
3307 For most systems the characters escaped are
3308 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3309 appears in a filename, it depends on the value of 'isfname'.
3310 A leading '+' and '>' is also escaped (special after |:edit|
3311 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003312 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003313 Example: >
3314 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003315 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003316< results in executing: >
3317 edit \+some\ str\%nge\|name
3318<
3319 Can also be used as a |method|: >
3320 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003321<
3322 Return type: |String|
3323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003324
3325fnamemodify({fname}, {mods}) *fnamemodify()*
3326 Modify file name {fname} according to {mods}. {mods} is a
3327 string of characters like it is used for file names on the
3328 command line. See |filename-modifiers|.
3329 Example: >
3330 :echo fnamemodify("main.c", ":p:h")
3331< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003332 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003333< If {mods} is empty or an unsupported modifier is used then
3334 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003335 When {fname} is empty then with {mods} ":h" returns ".", so
3336 that `:cd` can be used with it. This is different from
3337 expand('%:h') without a buffer name, which returns an empty
3338 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003339 Note: Environment variables don't work in {fname}, use
3340 |expand()| first then.
3341
3342 Can also be used as a |method|: >
3343 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003344<
3345 Return type: |String|
3346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003347
3348foldclosed({lnum}) *foldclosed()*
3349 The result is a Number. If the line {lnum} is in a closed
3350 fold, the result is the number of the first line in that fold.
3351 If the line {lnum} is not in a closed fold, -1 is returned.
3352 {lnum} is used like with |getline()|. Thus "." is the current
3353 line, "'m" mark m, etc.
3354
3355 Can also be used as a |method|: >
3356 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003357<
3358 Return type: |Number|
3359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003360
3361foldclosedend({lnum}) *foldclosedend()*
3362 The result is a Number. If the line {lnum} is in a closed
3363 fold, the result is the number of the last line in that fold.
3364 If the line {lnum} is not in a closed fold, -1 is returned.
3365 {lnum} is used like with |getline()|. Thus "." is the current
3366 line, "'m" mark m, etc.
3367
3368 Can also be used as a |method|: >
3369 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003370<
3371 Return type: |Number|
3372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003373
3374foldlevel({lnum}) *foldlevel()*
3375 The result is a Number, which is the foldlevel of line {lnum}
3376 in the current buffer. For nested folds the deepest level is
3377 returned. If there is no fold at line {lnum}, zero is
3378 returned. It doesn't matter if the folds are open or closed.
3379 When used while updating folds (from 'foldexpr') -1 is
3380 returned for lines where folds are still to be updated and the
3381 foldlevel is unknown. As a special case the level of the
3382 previous line is usually available.
3383 {lnum} is used like with |getline()|. Thus "." is the current
3384 line, "'m" mark m, etc.
3385
3386 Can also be used as a |method|: >
3387 GetLnum()->foldlevel()
3388<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003389 Return type: |Number|
3390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003391 *foldtext()*
3392foldtext() Returns a String, to be displayed for a closed fold. This is
3393 the default function used for the 'foldtext' option and should
3394 only be called from evaluating 'foldtext'. It uses the
3395 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3396 The returned string looks like this: >
3397 +-- 45 lines: abcdef
3398< The number of leading dashes depends on the foldlevel. The
3399 "45" is the number of lines in the fold. "abcdef" is the text
3400 in the first non-blank line of the fold. Leading white space,
3401 "//" or "/*" and the text from the 'foldmarker' and
3402 'commentstring' options is removed.
3403 When used to draw the actual foldtext, the rest of the line
3404 will be filled with the fold char from the 'fillchars'
3405 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003406 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003407
3408 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003409 {not available when compiled without the |+folding| feature}
3410
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003412foldtextresult({lnum}) *foldtextresult()*
3413 Returns the text that is displayed for the closed fold at line
3414 {lnum}. Evaluates 'foldtext' in the appropriate context.
3415 When there is no closed fold at {lnum} an empty string is
3416 returned.
3417 {lnum} is used like with |getline()|. Thus "." is the current
3418 line, "'m" mark m, etc.
3419 Useful when exporting folded text, e.g., to HTML.
3420 {not available when compiled without the |+folding| feature}
3421
3422
3423 Can also be used as a |method|: >
3424 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003425<
3426 Return type: |String|
3427
Ernie Raele79e2072024-01-13 11:47:33 +01003428
3429foreach({expr1}, {expr2}) *foreach()*
3430 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3431 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003432 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003433 See |map()| and |filter()| to modify {expr1}.
3434
3435 {expr2} must be a |string| or |Funcref|.
3436
3437 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3438 of the current item. For a |Dictionary| |v:key| has the key
3439 of the current item and for a |List| |v:key| has the index of
3440 the current item. For a |Blob| |v:key| has the index of the
3441 current byte. For a |String| |v:key| has the index of the
3442 current character.
3443 Examples: >
3444 call foreach(mylist, 'used[v:val] = true')
3445< This records the items that are in the {expr1} list.
3446
3447 Note that {expr2} is the result of expression and is then used
3448 as a command. Often it is good to use a |literal-string| to
3449 avoid having to double backslashes.
3450
3451 If {expr2} is a |Funcref| it must take two arguments:
3452 1. the key or the index of the current item.
3453 2. the value of the current item.
3454 With a legacy script lambda you don't get an error if it only
3455 accepts one argument, but with a Vim9 lambda you get "E1106:
3456 One argument too many", the number of arguments must match.
3457 If the function returns a value, it is ignored.
3458
3459 Returns {expr1} in all cases.
3460 When an error is encountered while executing {expr2} no
3461 further items in {expr1} are processed.
3462 When {expr2} is a Funcref errors inside a function are ignored,
3463 unless it was defined with the "abort" flag.
3464
3465 Can also be used as a |method|: >
3466 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003468 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3469 depending on {expr1}
3470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003471 *foreground()*
3472foreground() Move the Vim window to the foreground. Useful when sent from
3473 a client to a Vim server. |remote_send()|
3474 On Win32 systems this might not work, the OS does not always
3475 allow a window to bring itself to the foreground. Use
3476 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003477
3478 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003479 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003480 Win32 console version}
3481
Bram Moolenaaraa534142022-09-15 21:46:02 +01003482fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003483 Get the full command name from a short abbreviated command
3484 name; see |20.2| for details on command abbreviations.
3485
3486 The string argument {name} may start with a `:` and can
3487 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003488 Returns an empty string if a command doesn't exist, if it's
3489 ambiguous (for user-defined commands) or cannot be shortened
3490 this way. |vim9-no-shorten|
3491
3492 Without the {vim9} argument uses the current script version.
3493 If {vim9} is present and FALSE then legacy script rules are
3494 used. When {vim9} is present and TRUE then Vim9 rules are
3495 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003496
3497 For example `fullcommand('s')`, `fullcommand('sub')`,
3498 `fullcommand(':%substitute')` all return "substitute".
3499
3500 Can also be used as a |method|: >
3501 GetName()->fullcommand()
3502<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003503 Return type: |String|
3504
3505
3506funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003507 Just like |function()|, but the returned Funcref will lookup
3508 the function by reference, not by name. This matters when the
3509 function {name} is redefined later.
3510
3511 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003512 It only works for an autoloaded function if it has already
3513 been loaded (to avoid mistakenly loading the autoload script
3514 when only intending to use the function name, use |function()|
3515 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003516 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003517
3518 Can also be used as a |method|: >
3519 GetFuncname()->funcref([arg])
3520<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003521 Return type: func(...): any or |Number| on error
3522
Dominique Pellee764d1b2023-03-12 21:20:59 +00003523 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003524function({name} [, {arglist}] [, {dict}])
3525 Return a |Funcref| variable that refers to function {name}.
3526 {name} can be the name of a user defined function or an
3527 internal function.
3528
3529 {name} can also be a Funcref or a partial. When it is a
3530 partial the dict stored in it will be used and the {dict}
3531 argument is not allowed. E.g.: >
3532 let FuncWithArg = function(dict.Func, [arg])
3533 let Broken = function(dict.Func, [arg], dict)
3534<
3535 When using the Funcref the function will be found by {name},
3536 also when it was redefined later. Use |funcref()| to keep the
3537 same function.
3538
3539 When {arglist} or {dict} is present this creates a partial.
3540 That means the argument list and/or the dictionary is stored in
3541 the Funcref and will be used when the Funcref is called.
3542
3543 The arguments are passed to the function in front of other
3544 arguments, but after any argument from |method|. Example: >
3545 func Callback(arg1, arg2, name)
3546 ...
3547 let Partial = function('Callback', ['one', 'two'])
3548 ...
3549 call Partial('name')
3550< Invokes the function as with: >
3551 call Callback('one', 'two', 'name')
3552
3553< With a |method|: >
3554 func Callback(one, two, three)
3555 ...
3556 let Partial = function('Callback', ['two'])
3557 ...
3558 eval 'one'->Partial('three')
3559< Invokes the function as with: >
3560 call Callback('one', 'two', 'three')
3561
3562< The function() call can be nested to add more arguments to the
3563 Funcref. The extra arguments are appended to the list of
3564 arguments. Example: >
3565 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003566 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003567 let Func = function('Callback', ['one'])
3568 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003569 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003570 call Func2('name')
3571< Invokes the function as with: >
3572 call Callback('one', 'two', 'name')
3573
3574< The Dictionary is only useful when calling a "dict" function.
3575 In that case the {dict} is passed in as "self". Example: >
3576 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003577 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003578 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003579 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003580 let context = {"name": "example"}
3581 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003582 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003583 call Func() " will echo: called for example
3584< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003585 arguments, these two are equivalent, if Callback() is defined
3586 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003587 let Func = function('Callback', context)
3588 let Func = context.Callback
3589
3590< The argument list and the Dictionary can be combined: >
3591 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003592 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003593 let context = {"name": "example"}
3594 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003595 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003596 call Func(500)
3597< Invokes the function as with: >
3598 call context.Callback('one', 500)
3599<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003600 Returns 0 on error.
3601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003602 Can also be used as a |method|: >
3603 GetFuncname()->function([arg])
3604
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003605<
3606 Return type: func(...): any or |Number| on error
3607
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003608
3609garbagecollect([{atexit}]) *garbagecollect()*
3610 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3611 that have circular references.
3612
3613 There is hardly ever a need to invoke this function, as it is
3614 automatically done when Vim runs out of memory or is waiting
3615 for the user to press a key after 'updatetime'. Items without
3616 circular references are always freed when they become unused.
3617 This is useful if you have deleted a very big |List| and/or
3618 |Dictionary| with circular references in a script that runs
3619 for a long time.
3620
3621 When the optional {atexit} argument is one, garbage
3622 collection will also be done when exiting Vim, if it wasn't
3623 done before. This is useful when checking for memory leaks.
3624
3625 The garbage collection is not done immediately but only when
3626 it's safe to perform. This is when waiting for the user to
3627 type a character. To force garbage collection immediately use
3628 |test_garbagecollect_now()|.
3629
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003630 Return type: |String|
3631
3632
LemonBoy48b7d052024-07-09 18:24:59 +02003633get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003634 Get item {idx} from |List| {list}. When this item is not
3635 available return {default}. Return zero when {default} is
3636 omitted.
3637 Preferably used as a |method|: >
3638 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003639<
3640 Return type: any, depending on {list}
3641
LemonBoy48b7d052024-07-09 18:24:59 +02003642get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003643 Get byte {idx} from |Blob| {blob}. When this byte is not
3644 available return {default}. Return -1 when {default} is
3645 omitted.
3646 Preferably used as a |method|: >
3647 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003648<
3649 Return type: |Number|
3650
LemonBoy48b7d052024-07-09 18:24:59 +02003651get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003652 Get item with key {key} from |Dictionary| {dict}. When this
3653 item is not available return {default}. Return zero when
3654 {default} is omitted. Useful example: >
3655 let val = get(g:, 'var_name', 'default')
3656< This gets the value of g:var_name if it exists, and uses
3657 'default' when it does not exist.
3658 Preferably used as a |method|: >
3659 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003660<
h-east84ac2122024-06-17 18:12:30 +02003661 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003662
LemonBoy48b7d052024-07-09 18:24:59 +02003663get({func}, {what}) *get()-func*
3664 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003665 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003666 "name" The function name
3667 "func" The function
3668 "dict" The dictionary
3669 "args" The list with arguments
3670 "arity" A dictionary with information about the number of
3671 arguments accepted by the function (minus the
3672 {arglist}) with the following fields:
3673 required the number of positional arguments
3674 optional the number of optional arguments,
3675 in addition to the required ones
3676 varargs |TRUE| if the function accepts a
3677 variable number of arguments |...|
3678
3679 Note: There is no error, if the {arglist} of
3680 the Funcref contains more arguments than the
3681 Funcref expects, it's not validated.
3682
Bram Moolenaar016188f2022-06-06 20:52:59 +01003683 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003685 Preferably used as a |method|: >
3686 myfunc->get(what)
3687<
LemonBoy48b7d052024-07-09 18:24:59 +02003688 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003690 *getbufinfo()*
3691getbufinfo([{buf}])
3692getbufinfo([{dict}])
3693 Get information about buffers as a List of Dictionaries.
3694
3695 Without an argument information about all the buffers is
3696 returned.
3697
3698 When the argument is a |Dictionary| only the buffers matching
3699 the specified criteria are returned. The following keys can
3700 be specified in {dict}:
3701 buflisted include only listed buffers.
3702 bufloaded include only loaded buffers.
3703 bufmodified include only modified buffers.
3704
3705 Otherwise, {buf} specifies a particular buffer to return
3706 information for. For the use of {buf}, see |bufname()|
3707 above. If the buffer is found the returned List has one item.
3708 Otherwise the result is an empty list.
3709
3710 Each returned List item is a dictionary with the following
3711 entries:
3712 bufnr Buffer number.
3713 changed TRUE if the buffer is modified.
3714 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003715 command TRUE if the buffer belongs to the
3716 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003717 hidden TRUE if the buffer is hidden.
3718 lastused Timestamp in seconds, like
3719 |localtime()|, when the buffer was
3720 last used.
3721 {only with the |+viminfo| feature}
3722 listed TRUE if the buffer is listed.
3723 lnum Line number used for the buffer when
3724 opened in the current window.
3725 Only valid if the buffer has been
3726 displayed in the window in the past.
3727 If you want the line number of the
3728 last known cursor position in a given
3729 window, use |line()|: >
3730 :echo line('.', {winid})
3731<
3732 linecount Number of lines in the buffer (only
3733 valid when loaded)
3734 loaded TRUE if the buffer is loaded.
3735 name Full path to the file in the buffer.
3736 signs List of signs placed in the buffer.
3737 Each list item is a dictionary with
3738 the following fields:
3739 id sign identifier
3740 lnum line number
3741 name sign name
3742 variables A reference to the dictionary with
3743 buffer-local variables.
3744 windows List of |window-ID|s that display this
3745 buffer
3746 popups List of popup |window-ID|s that
3747 display this buffer
3748
3749 Examples: >
3750 for buf in getbufinfo()
3751 echo buf.name
3752 endfor
3753 for buf in getbufinfo({'buflisted':1})
3754 if buf.changed
3755 ....
3756 endif
3757 endfor
3758<
3759 To get buffer-local options use: >
3760 getbufvar({bufnr}, '&option_name')
3761<
3762 Can also be used as a |method|: >
3763 GetBufnr()->getbufinfo()
3764<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003765 Return type: list<dict<any>>
3766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003767
3768 *getbufline()*
3769getbufline({buf}, {lnum} [, {end}])
3770 Return a |List| with the lines starting from {lnum} to {end}
3771 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003772 |List| with only the line {lnum} is returned. See
3773 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003774
3775 For the use of {buf}, see |bufname()| above.
3776
3777 For {lnum} and {end} "$" can be used for the last line of the
3778 buffer. Otherwise a number must be used.
3779
3780 When {lnum} is smaller than 1 or bigger than the number of
3781 lines in the buffer, an empty |List| is returned.
3782
3783 When {end} is greater than the number of lines in the buffer,
3784 it is treated as {end} is set to the number of lines in the
3785 buffer. When {end} is before {lnum} an empty |List| is
3786 returned.
3787
3788 This function works only for loaded buffers. For unloaded and
3789 non-existing buffers, an empty |List| is returned.
3790
3791 Example: >
3792 :let lines = getbufline(bufnr("myfile"), 1, "$")
3793
3794< Can also be used as a |method|: >
3795 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003796<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003797 Return type: list<string>
3798
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003799 *getbufoneline()*
3800getbufoneline({buf}, {lnum})
3801 Just like `getbufline()` but only get one line and return it
3802 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003803
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003804 Return type: |String|
3805
3806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003807getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3808 The result is the value of option or local buffer variable
3809 {varname} in buffer {buf}. Note that the name without "b:"
3810 must be used.
3811 The {varname} argument is a string.
3812 When {varname} is empty returns a |Dictionary| with all the
3813 buffer-local variables.
3814 When {varname} is equal to "&" returns a |Dictionary| with all
3815 the buffer-local options.
3816 Otherwise, when {varname} starts with "&" returns the value of
3817 a buffer-local option.
3818 This also works for a global or buffer-local option, but it
3819 doesn't work for a global variable, window-local variable or
3820 window-local option.
3821 For the use of {buf}, see |bufname()| above.
3822 When the buffer or variable doesn't exist {def} or an empty
3823 string is returned, there is no error message.
3824 Examples: >
3825 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003826 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003827
3828< Can also be used as a |method|: >
3829 GetBufnr()->getbufvar(varname)
3830<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003831 Return type: any, depending on {varname}
3832
3833
mikoto20001083cae2024-11-11 21:24:14 +01003834getcellpixels() *getcellpixels()*
3835 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003836 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003837
3838 Only works on Unix (terminal and gVim) and Windows (gVim only).
3839 Returns [] on other systems or on failure.
3840 Note that there could be variations across different terminals.
3841 On macOS, system Terminal.app returns sizes in points (before
3842 Retina scaling), whereas third-party terminals return raw pixel
3843 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003844
mikoto2000de094dc2024-11-14 22:13:48 +01003845 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003846
3847
Kota Kato66bb9ae2023-01-17 18:31:56 +00003848getcellwidths() *getcellwidths()*
3849 Returns a |List| of cell widths of character ranges overridden
3850 by |setcellwidths()|. The format is equal to the argument of
3851 |setcellwidths()|. If no character ranges have their cell
3852 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003853
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003854 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003855
3856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003857getchangelist([{buf}]) *getchangelist()*
3858 Returns the |changelist| for the buffer {buf}. For the use
3859 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3860 exist, an empty list is returned.
3861
3862 The returned list contains two entries: a list with the change
3863 locations and the current position in the list. Each
3864 entry in the change list is a dictionary with the following
3865 entries:
3866 col column number
3867 coladd column offset for 'virtualedit'
3868 lnum line number
3869 If buffer {buf} is the current buffer, then the current
3870 position refers to the position in the list. For other
3871 buffers, it is set to the length of the list.
3872
3873 Can also be used as a |method|: >
3874 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003875<
3876 Return type: list<any>
3877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003878
Doug Kearns9cd9e752024-04-07 17:42:17 +02003879getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003880 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003881 If {expr} is omitted, wait until a character is available.
3882 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003883 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003884 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003885 not consumed. Return zero if no character available.
3886 If you prefer always getting a string use |getcharstr()|.
3887
Doug Kearns9cd9e752024-04-07 17:42:17 +02003888 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003889 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003890 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003891 Otherwise a String is returned with the encoded character.
3892 For a special key it's a String with a sequence of bytes
3893 starting with 0x80 (decimal: 128). This is the same value as
3894 the String "\<Key>", e.g., "\<Left>". The returned value is
3895 also a String when a modifier (shift, control, alt) was used
3896 that is not included in the character.
3897
Doug Kearns9cd9e752024-04-07 17:42:17 +02003898 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003899 while Vim waits to see if this is the start of an escape
3900 sequence.
3901
Doug Kearns9cd9e752024-04-07 17:42:17 +02003902 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003903 one-byte character it is the character itself as a number.
3904 Use nr2char() to convert it to a String.
3905
3906 Use getcharmod() to obtain any additional modifiers.
3907
3908 When the user clicks a mouse button, the mouse event will be
3909 returned. The position can then be found in |v:mouse_col|,
3910 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3911 |getmousepos()| can also be used. Mouse move events will be
3912 ignored.
3913 This example positions the mouse as it would normally happen: >
3914 let c = getchar()
3915 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003916 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003917 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003918 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003919 endif
3920<
3921 When using bracketed paste only the first character is
3922 returned, the rest of the pasted text is dropped.
3923 |xterm-bracketed-paste|.
3924
3925 There is no prompt, you will somehow have to make clear to the
3926 user that a character has to be typed. The screen is not
3927 redrawn, e.g. when resizing the window. When using a popup
3928 window it should work better with a |popup-filter|.
3929
3930 There is no mapping for the character.
3931 Key codes are replaced, thus when the user presses the <Del>
3932 key you get the code for the <Del> key, not the raw character
3933 sequence. Examples: >
3934 getchar() == "\<Del>"
3935 getchar() == "\<S-Left>"
3936< This example redefines "f" to ignore case: >
3937 :nmap f :call FindChar()<CR>
3938 :function FindChar()
3939 : let c = nr2char(getchar())
3940 : while col('.') < col('$') - 1
3941 : normal l
3942 : if getline('.')[col('.') - 1] ==? c
3943 : break
3944 : endif
3945 : endwhile
3946 :endfunction
3947<
3948 You may also receive synthetic characters, such as
3949 |<CursorHold>|. Often you will want to ignore this and get
3950 another character: >
3951 :function GetKey()
3952 : let c = getchar()
3953 : while c == "\<CursorHold>"
3954 : let c = getchar()
3955 : endwhile
3956 : return c
3957 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003958<
3959 Return type: |Number| or |String|
3960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003961
3962getcharmod() *getcharmod()*
3963 The result is a Number which is the state of the modifiers for
3964 the last obtained character with getchar() or in another way.
3965 These values are added together:
3966 2 shift
3967 4 control
3968 8 alt (meta)
3969 16 meta (when it's different from ALT)
3970 32 mouse double click
3971 64 mouse triple click
3972 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01003973 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003974 Only the modifiers that have not been included in the
3975 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01003976 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003977
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003978 Return type: |Number|
3979
3980
3981getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003982 Get the position for String {expr}. Same as |getpos()| but the
3983 column number in the returned List is a character index
3984 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00003985 If |getpos()| returns a very large column number, equal to
3986 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003987 of the last character.
3988
3989 Example:
3990 With the cursor on '세' in line 5 with text "여보세요": >
3991 getcharpos('.') returns [0, 5, 3, 0]
3992 getpos('.') returns [0, 5, 7, 0]
3993<
3994 Can also be used as a |method|: >
3995 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003996<
3997 Return type: list<number>
3998
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003999
4000getcharsearch() *getcharsearch()*
4001 Return the current character search information as a {dict}
4002 with the following entries:
4003
4004 char character previously used for a character
4005 search (|t|, |f|, |T|, or |F|); empty string
4006 if no character search has been performed
4007 forward direction of character search; 1 for forward,
4008 0 for backward
4009 until type of character search; 1 for a |t| or |T|
4010 character search, 0 for an |f| or |F|
4011 character search
4012
4013 This can be useful to always have |;| and |,| search
4014 forward/backward regardless of the direction of the previous
4015 character search: >
4016 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4017 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4018< Also see |setcharsearch()|.
4019
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004020 Return type: dict<any>
4021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004022
Doug Kearns9cd9e752024-04-07 17:42:17 +02004023getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004024 Get a single character from the user or input stream as a
4025 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004026 If {expr} is omitted, wait until a character is available.
4027 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004028 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004029 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004030 available, it is not consumed. Return an empty string
4031 if no character is available.
4032 Otherwise this works like |getchar()|, except that a number
4033 result is converted to a string.
4034
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004035 Return type: |String|
4036
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004037getcmdcomplpat() *getcmdcomplpat()*
4038 Return completion pattern of the current command-line.
4039 Only works when the command line is being edited, thus
4040 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4041 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4042 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4043 Returns an empty string when completion is not defined.
4044
4045 Return type: |String|
4046
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004047
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004048getcmdcompltype() *getcmdcompltype()*
4049 Return the type of the current command-line completion.
4050 Only works when the command line is being edited, thus
4051 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004052 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004053 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004054 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004055 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004056
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004057 Return type: |String|
4058
4059
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004060getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004061 Return the current command-line input. Only works when the
4062 command line is being edited, thus requires use of
4063 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004064 Example: >
4065 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004066< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4067 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004068 Returns an empty string when entering a password or using
4069 |inputsecret()|.
4070
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004071 Return type: |String|
4072
4073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004074getcmdpos() *getcmdpos()*
4075 Return the position of the cursor in the command line as a
4076 byte count. The first column is 1.
4077 Only works when editing the command line, thus requires use of
4078 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4079 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004080 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4081 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004082
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004083 Return type: |Number|
4084
4085
Shougo Matsushita69084282024-09-23 20:34:47 +02004086getcmdprompt() *getcmdprompt()*
4087 Return the current command-line prompt when using functions
4088 like |input()| or |confirm()|.
4089 Only works when the command line is being edited, thus
4090 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4091 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4092 |setcmdpos()| and |setcmdline()|.
4093
4094 Return type: |String|
4095
4096
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004097getcmdscreenpos() *getcmdscreenpos()*
4098 Return the screen position of the cursor in the command line
4099 as a byte count. The first column is 1.
4100 Instead of |getcmdpos()|, it adds the prompt position.
4101 Only works when editing the command line, thus requires use of
4102 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4103 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004104 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4105 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004106
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004107 Return type: |Number|
4108
4109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004110getcmdtype() *getcmdtype()*
4111 Return the current command-line type. Possible return values
4112 are:
4113 : normal Ex command
4114 > debug mode command |debug-mode|
4115 / forward search command
4116 ? backward search command
4117 @ |input()| command
4118 - |:insert| or |:append| command
4119 = |i_CTRL-R_=|
4120 Only works when editing the command line, thus requires use of
4121 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4122 Returns an empty string otherwise.
4123 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4124
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004125 Return type: |String|
4126
4127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004128getcmdwintype() *getcmdwintype()*
4129 Return the current |command-line-window| type. Possible return
4130 values are the same as |getcmdtype()|. Returns an empty string
4131 when not in the command-line window.
4132
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004133 Return type: |String|
4134
4135
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004136getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4137 Return a list of command-line completion matches. The String
4138 {type} argument specifies what for. The following completion
4139 types are supported:
4140
4141 arglist file names in argument list
4142 augroup autocmd groups
4143 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004144 behave |:behave| suboptions
4145 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004146 color color schemes
4147 command Ex command
4148 cmdline |cmdline-completion| result
4149 compiler compilers
4150 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004151 custom,{func} custom completion, defined via {func}
4152 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004153 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004154 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004155 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004156 environment environment variable names
4157 event autocommand events
4158 expression Vim expression
4159 file file and directory names
4160 file_in_path file and directory names in |'path'|
4161 filetype filetype names |'filetype'|
4162 function function name
4163 help help subjects
4164 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004165 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004166 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004167 locale locale names (as output of locale -a)
4168 mapclear buffer argument
4169 mapping mapping name
4170 menu menus
4171 messages |:messages| suboptions
4172 option options
4173 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004174 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004175 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004176 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004177 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004178 sign |:sign| suboptions
4179 syntax syntax file names |'syntax'|
4180 syntime |:syntime| suboptions
4181 tag tags
4182 tag_listfiles tags, file names
4183 user user names
4184 var user variables
4185
4186 If {pat} is an empty string, then all the matches are
4187 returned. Otherwise only items matching {pat} are returned.
4188 See |wildcards| for the use of special characters in {pat}.
4189
4190 If the optional {filtered} flag is set to 1, then 'wildignore'
4191 is applied to filter the results. Otherwise all the matches
4192 are returned. The 'wildignorecase' option always applies.
4193
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004194 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4195 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004196 regular expression matching is used. Thus this function
4197 follows the user preference, what happens on the command line.
4198 If you do not want this you can make 'wildoptions' empty
4199 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004201 If {type} is "cmdline", then the |cmdline-completion| result is
4202 returned. For example, to complete the possible values after
4203 a ":call" command: >
4204 echo getcompletion('call ', 'cmdline')
4205<
4206 If there are no matches, an empty list is returned. An
4207 invalid value for {type} produces an error.
4208
4209 Can also be used as a |method|: >
4210 GetPattern()->getcompletion('color')
4211<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004212 Return type: list<string>
4213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004214 *getcurpos()*
4215getcurpos([{winid}])
4216 Get the position of the cursor. This is like getpos('.'), but
4217 includes an extra "curswant" item in the list:
4218 [0, lnum, col, off, curswant] ~
4219 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004220 cursor vertically. After |$| command it will be a very large
4221 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004222 |getpos()|.
4223 The first "bufnum" item is always zero. The byte position of
4224 the cursor is returned in 'col'. To get the character
4225 position, use |getcursorcharpos()|.
4226
4227 The optional {winid} argument can specify the window. It can
4228 be the window number or the |window-ID|. The last known
4229 cursor position is returned, this may be invalid for the
4230 current value of the buffer if it is not the current window.
4231 If {winid} is invalid a list with zeroes is returned.
4232
4233 This can be used to save and restore the cursor position: >
4234 let save_cursor = getcurpos()
4235 MoveTheCursorAround
4236 call setpos('.', save_cursor)
4237< Note that this only works within the window. See
4238 |winrestview()| for restoring more state.
4239
4240 Can also be used as a |method|: >
4241 GetWinid()->getcurpos()
4242<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004243 Return type: list<number>
4244
4245
4246getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004247 Same as |getcurpos()| but the column number in the returned
4248 List is a character index instead of a byte index.
4249
4250 Example:
4251 With the cursor on '보' in line 3 with text "여보세요": >
4252 getcursorcharpos() returns [0, 3, 2, 0, 3]
4253 getcurpos() returns [0, 3, 4, 0, 3]
4254<
4255 Can also be used as a |method|: >
4256 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004257<
4258 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004259
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004260
4261getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004262 The result is a String, which is the name of the current
4263 working directory. 'autochdir' is ignored.
4264
4265 With {winnr} return the local current directory of this window
4266 in the current tab page. {winnr} can be the window number or
4267 the |window-ID|.
4268 If {winnr} is -1 return the name of the global working
4269 directory. See also |haslocaldir()|.
4270
4271 With {winnr} and {tabnr} return the local current directory of
4272 the window in the specified tab page. If {winnr} is -1 return
4273 the working directory of the tabpage.
4274 If {winnr} is zero use the current window, if {tabnr} is zero
4275 use the current tabpage.
4276 Without any arguments, return the actual working directory of
4277 the current window.
4278 Return an empty string if the arguments are invalid.
4279
4280 Examples: >
4281 " Get the working directory of the current window
4282 :echo getcwd()
4283 :echo getcwd(0)
4284 :echo getcwd(0, 0)
4285 " Get the working directory of window 3 in tabpage 2
4286 :echo getcwd(3, 2)
4287 " Get the global working directory
4288 :echo getcwd(-1)
4289 " Get the working directory of tabpage 3
4290 :echo getcwd(-1, 3)
4291 " Get the working directory of current tabpage
4292 :echo getcwd(-1, 0)
4293
4294< Can also be used as a |method|: >
4295 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004296<
4297 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004298
4299getenv({name}) *getenv()*
4300 Return the value of environment variable {name}. The {name}
4301 argument is a string, without a leading '$'. Example: >
4302 myHome = getenv('HOME')
4303
4304< When the variable does not exist |v:null| is returned. That
4305 is different from a variable set to an empty string, although
4306 some systems interpret the empty value as the variable being
4307 deleted. See also |expr-env|.
4308
4309 Can also be used as a |method|: >
4310 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004311<
4312 Return type: |String| or |Number|
4313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004314
4315getfontname([{name}]) *getfontname()*
4316 Without an argument returns the name of the normal font being
4317 used. Like what is used for the Normal highlight group
4318 |hl-Normal|.
4319 With an argument a check is done whether String {name} is a
4320 valid font name. If not then an empty string is returned.
4321 Otherwise the actual font name is returned, or {name} if the
4322 GUI does not support obtaining the real name.
4323 Only works when the GUI is running, thus not in your vimrc or
4324 gvimrc file. Use the |GUIEnter| autocommand to use this
4325 function just after the GUI has started.
4326 Note that the GTK GUI accepts any font name, thus checking for
4327 a valid name does not work.
4328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004329 Return type: |String|
4330
4331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004332getfperm({fname}) *getfperm()*
4333 The result is a String, which is the read, write, and execute
4334 permissions of the given file {fname}.
4335 If {fname} does not exist or its directory cannot be read, an
4336 empty string is returned.
4337 The result is of the form "rwxrwxrwx", where each group of
4338 "rwx" flags represent, in turn, the permissions of the owner
4339 of the file, the group the file belongs to, and other users.
4340 If a user does not have a given permission the flag for this
4341 is replaced with the string "-". Examples: >
4342 :echo getfperm("/etc/passwd")
4343 :echo getfperm(expand("~/.vimrc"))
4344< This will hopefully (from a security point of view) display
4345 the string "rw-r--r--" or even "rw-------".
4346
4347 Can also be used as a |method|: >
4348 GetFilename()->getfperm()
4349<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004350 Return type: |String|
4351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004352 For setting permissions use |setfperm()|.
4353
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004355getfsize({fname}) *getfsize()*
4356 The result is a Number, which is the size in bytes of the
4357 given file {fname}.
4358 If {fname} is a directory, 0 is returned.
4359 If the file {fname} can't be found, -1 is returned.
4360 If the size of {fname} is too big to fit in a Number then -2
4361 is returned.
4362
4363 Can also be used as a |method|: >
4364 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004365<
4366 Return type: |Number|
4367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004368
4369getftime({fname}) *getftime()*
4370 The result is a Number, which is the last modification time of
4371 the given file {fname}. The value is measured as seconds
4372 since 1st Jan 1970, and may be passed to strftime(). See also
4373 |localtime()| and |strftime()|.
4374 If the file {fname} can't be found -1 is returned.
4375
4376 Can also be used as a |method|: >
4377 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004378<
4379 Return type: |Number|
4380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004381
4382getftype({fname}) *getftype()*
4383 The result is a String, which is a description of the kind of
4384 file of the given file {fname}.
4385 If {fname} does not exist an empty string is returned.
4386 Here is a table over different kinds of files and their
4387 results:
4388 Normal file "file"
4389 Directory "dir"
4390 Symbolic link "link"
4391 Block device "bdev"
4392 Character device "cdev"
4393 Socket "socket"
4394 FIFO "fifo"
4395 All other "other"
4396 Example: >
4397 getftype("/home")
4398< Note that a type such as "link" will only be returned on
4399 systems that support it. On some systems only "dir" and
4400 "file" are returned. On MS-Windows a symbolic link to a
4401 directory returns "dir" instead of "link".
4402
4403 Can also be used as a |method|: >
4404 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004405<
4406 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004407
4408getimstatus() *getimstatus()*
4409 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004410 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004411 See 'imstatusfunc'.
4412
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004413 Return type: |Number|
4414
4415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004416getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4417 Returns the |jumplist| for the specified window.
4418
4419 Without arguments use the current window.
4420 With {winnr} only use this window in the current tab page.
4421 {winnr} can also be a |window-ID|.
4422 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004423 page. If {winnr} or {tabnr} is invalid, an empty list is
4424 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004425
4426 The returned list contains two entries: a list with the jump
4427 locations and the last used jump position number in the list.
4428 Each entry in the jump location list is a dictionary with
4429 the following entries:
4430 bufnr buffer number
4431 col column number
4432 coladd column offset for 'virtualedit'
4433 filename filename if available
4434 lnum line number
4435
4436 Can also be used as a |method|: >
4437 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004438<
4439 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004440
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004441 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004442getline({lnum} [, {end}])
4443 Without {end} the result is a String, which is line {lnum}
4444 from the current buffer. Example: >
4445 getline(1)
4446< When {lnum} is a String that doesn't start with a
4447 digit, |line()| is called to translate the String into a Number.
4448 To get the line under the cursor: >
4449 getline(".")
4450< When {lnum} is a number smaller than 1 or bigger than the
4451 number of lines in the buffer, an empty string is returned.
4452
4453 When {end} is given the result is a |List| where each item is
4454 a line from the current buffer in the range {lnum} to {end},
4455 including line {end}.
4456 {end} is used in the same way as {lnum}.
4457 Non-existing lines are silently omitted.
4458 When {end} is before {lnum} an empty |List| is returned.
4459 Example: >
4460 :let start = line('.')
4461 :let end = search("^$") - 1
4462 :let lines = getline(start, end)
4463
4464< Can also be used as a |method|: >
4465 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004466<
4467 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004468
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004469 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004470 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004471
4472getloclist({nr} [, {what}]) *getloclist()*
4473 Returns a |List| with all the entries in the location list for
4474 window {nr}. {nr} can be the window number or the |window-ID|.
4475 When {nr} is zero the current window is used.
4476
4477 For a location list window, the displayed location list is
4478 returned. For an invalid window number {nr}, an empty list is
4479 returned. Otherwise, same as |getqflist()|.
4480
4481 If the optional {what} dictionary argument is supplied, then
4482 returns the items listed in {what} as a dictionary. Refer to
4483 |getqflist()| for the supported items in {what}.
4484
4485 In addition to the items supported by |getqflist()| in {what},
4486 the following item is supported by |getloclist()|:
4487
4488 filewinid id of the window used to display files
4489 from the location list. This field is
4490 applicable only when called from a
4491 location list window. See
4492 |location-list-file-window| for more
4493 details.
4494
4495 Returns a |Dictionary| with default values if there is no
4496 location list for the window {nr}.
4497 Returns an empty Dictionary if window {nr} does not exist.
4498
4499 Examples (See also |getqflist-examples|): >
4500 :echo getloclist(3, {'all': 0})
4501 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004502<
4503 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004504
4505
4506getmarklist([{buf}]) *getmarklist()*
4507 Without the {buf} argument returns a |List| with information
4508 about all the global marks. |mark|
4509
4510 If the optional {buf} argument is specified, returns the
4511 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004512 see |bufname()|. If {buf} is invalid, an empty list is
4513 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004514
4515 Each item in the returned List is a |Dict| with the following:
4516 mark name of the mark prefixed by "'"
4517 pos a |List| with the position of the mark:
4518 [bufnum, lnum, col, off]
4519 Refer to |getpos()| for more information.
4520 file file name
4521
4522 Refer to |getpos()| for getting information about a specific
4523 mark.
4524
4525 Can also be used as a |method|: >
4526 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004527<
4528 Return type: list<dict<any>> or list<any>
4529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004530
4531getmatches([{win}]) *getmatches()*
4532 Returns a |List| with all matches previously defined for the
4533 current window by |matchadd()| and the |:match| commands.
4534 |getmatches()| is useful in combination with |setmatches()|,
4535 as |setmatches()| can restore a list of matches saved by
4536 |getmatches()|.
4537 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004538 window ID instead of the current window. If {win} is invalid,
4539 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004540 Example: >
4541 :echo getmatches()
4542< [{'group': 'MyGroup1', 'pattern': 'TODO',
4543 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4544 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4545 :let m = getmatches()
4546 :call clearmatches()
4547 :echo getmatches()
4548< [] >
4549 :call setmatches(m)
4550 :echo getmatches()
4551< [{'group': 'MyGroup1', 'pattern': 'TODO',
4552 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4553 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4554 :unlet m
4555<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004556 Return type: list<dict<any>> or list<any>
4557
4558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004559getmousepos() *getmousepos()*
4560 Returns a |Dictionary| with the last known position of the
4561 mouse. This can be used in a mapping for a mouse click or in
4562 a filter of a popup window. The items are:
4563 screenrow screen row
4564 screencol screen column
4565 winid Window ID of the click
4566 winrow row inside "winid"
4567 wincol column inside "winid"
4568 line text line inside "winid"
4569 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004570 coladd offset (in screen columns) from the
4571 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004572 All numbers are 1-based.
4573
4574 If not over a window, e.g. when in the command line, then only
4575 "screenrow" and "screencol" are valid, the others are zero.
4576
4577 When on the status line below a window or the vertical
4578 separator right of a window, the "line" and "column" values
4579 are zero.
4580
4581 When the position is after the text then "column" is the
4582 length of the text in bytes plus one.
4583
4584 If the mouse is over a popup window then that window is used.
4585
4586 When using |getchar()| the Vim variables |v:mouse_lnum|,
4587 |v:mouse_col| and |v:mouse_winid| also provide these values.
4588
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004589 Return type: dict<number>
4590
4591
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004592getmouseshape() *getmouseshape()*
4593 Returns the name of the currently showing mouse pointer.
4594 When the |+mouseshape| feature is not supported or the shape
4595 is unknown an empty string is returned.
4596 This function is mainly intended for testing.
4597
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004598 Return type: |String|
4599
4600
4601getpid() *getpid()*
4602 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004603 On Unix and MS-Windows this is a unique number, until Vim
4604 exits.
4605
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004606 Return type: |Number|
4607
4608
4609getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004610 Get the position for String {expr}.
4611 The accepted values for {expr} are: *E1209*
4612 . The cursor position.
4613 $ The last line in the current buffer.
4614 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004615 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004616 w0 First line visible in current window (one if the
4617 display isn't updated, e.g. in silent Ex mode).
4618 w$ Last line visible in current window (this is one
4619 less than "w0" if no lines are visible).
4620 v When not in Visual mode, returns the cursor
4621 position. In Visual mode, returns the other end
4622 of the Visual area. A good way to think about
4623 this is that in Visual mode "v" and "." complement
4624 each other. While "." refers to the cursor
4625 position, "v" refers to where |v_o| would move the
4626 cursor. As a result, you can use "v" and "."
4627 together to work on all of a selection in
4628 characterwise Visual mode. If the cursor is at
4629 the end of a characterwise Visual area, "v" refers
4630 to the start of the same Visual area. And if the
4631 cursor is at the start of a characterwise Visual
4632 area, "v" refers to the end of the same Visual
4633 area. "v" differs from |'<| and |'>| in that it's
4634 updated right away.
4635 Note that a mark in another file can be used. The line number
4636 then applies to another buffer.
4637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004638 The result is a |List| with four numbers:
4639 [bufnum, lnum, col, off]
4640 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4641 is the buffer number of the mark.
4642 "lnum" and "col" are the position in the buffer. The first
4643 column is 1.
4644 The "off" number is zero, unless 'virtualedit' is used. Then
4645 it is the offset in screen columns from the start of the
4646 character. E.g., a position within a <Tab> or after the last
4647 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004648
4649 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004650 The column number in the returned List is the byte position
4651 within the line. To get the character position in the line,
4652 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004653
4654 Note that for '< and '> Visual mode matters: when it is "V"
4655 (visual line mode) the column of '< is zero and the column of
4656 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004657 A very large column number equal to |v:maxcol| can be returned,
4658 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004659 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004660
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004661 This can be used to save and restore the position of a mark: >
4662 let save_a_mark = getpos("'a")
4663 ...
4664 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004665<
4666 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004667
4668 Can also be used as a |method|: >
4669 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004670<
4671 Return type: list<number>
4672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004673
4674getqflist([{what}]) *getqflist()*
4675 Returns a |List| with all the current quickfix errors. Each
4676 list item is a dictionary with these entries:
4677 bufnr number of buffer that has the file name, use
4678 bufname() to get the name
4679 module module name
4680 lnum line number in the buffer (first line is 1)
4681 end_lnum
4682 end of line number if the item is multiline
4683 col column number (first column is 1)
4684 end_col end of column number if the item has range
4685 vcol |TRUE|: "col" is visual column
4686 |FALSE|: "col" is byte index
4687 nr error number
h-east84ac2122024-06-17 18:12:30 +02004688 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004689 text description of the error
4690 type type of the error, 'E', '1', etc.
4691 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004692 user_data
4693 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004694 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004695
4696 When there is no error list or it's empty, an empty list is
4697 returned. Quickfix list entries with a non-existing buffer
4698 number are returned with "bufnr" set to zero (Note: some
4699 functions accept buffer number zero for the alternate buffer,
4700 you may need to explicitly check for zero).
4701
4702 Useful application: Find pattern matches in multiple files and
4703 do something with them: >
4704 :vimgrep /theword/jg *.c
4705 :for d in getqflist()
4706 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4707 :endfor
4708<
4709 If the optional {what} dictionary argument is supplied, then
4710 returns only the items listed in {what} as a dictionary. The
4711 following string items are supported in {what}:
4712 changedtick get the total number of changes made
4713 to the list |quickfix-changedtick|
4714 context get the |quickfix-context|
4715 efm errorformat to use when parsing "lines". If
4716 not present, then the 'errorformat' option
4717 value is used.
4718 id get information for the quickfix list with
4719 |quickfix-ID|; zero means the id for the
4720 current list or the list specified by "nr"
4721 idx get information for the quickfix entry at this
4722 index in the list specified by 'id' or 'nr'.
4723 If set to zero, then uses the current entry.
4724 See |quickfix-index|
4725 items quickfix list entries
4726 lines parse a list of lines using 'efm' and return
4727 the resulting entries. Only a |List| type is
4728 accepted. The current quickfix list is not
4729 modified. See |quickfix-parse|.
4730 nr get information for this quickfix list; zero
4731 means the current quickfix list and "$" means
4732 the last quickfix list
4733 qfbufnr number of the buffer displayed in the quickfix
4734 window. Returns 0 if the quickfix buffer is
4735 not present. See |quickfix-buffer|.
4736 size number of entries in the quickfix list
4737 title get the list title |quickfix-title|
4738 winid get the quickfix |window-ID|
4739 all all of the above quickfix properties
4740 Non-string items in {what} are ignored. To get the value of a
4741 particular item, set it to zero.
4742 If "nr" is not present then the current quickfix list is used.
4743 If both "nr" and a non-zero "id" are specified, then the list
4744 specified by "id" is used.
4745 To get the number of lists in the quickfix stack, set "nr" to
4746 "$" in {what}. The "nr" value in the returned dictionary
4747 contains the quickfix stack size.
4748 When "lines" is specified, all the other items except "efm"
4749 are ignored. The returned dictionary contains the entry
4750 "items" with the list of entries.
4751
4752 The returned dictionary contains the following entries:
4753 changedtick total number of changes made to the
4754 list |quickfix-changedtick|
4755 context quickfix list context. See |quickfix-context|
4756 If not present, set to "".
4757 id quickfix list ID |quickfix-ID|. If not
4758 present, set to 0.
4759 idx index of the quickfix entry in the list. If not
4760 present, set to 0.
4761 items quickfix list entries. If not present, set to
4762 an empty list.
4763 nr quickfix list number. If not present, set to 0
4764 qfbufnr number of the buffer displayed in the quickfix
4765 window. If not present, set to 0.
4766 size number of entries in the quickfix list. If not
4767 present, set to 0.
4768 title quickfix list title text. If not present, set
4769 to "".
4770 winid quickfix |window-ID|. If not present, set to 0
4771
4772 Examples (See also |getqflist-examples|): >
4773 :echo getqflist({'all': 1})
4774 :echo getqflist({'nr': 2, 'title': 1})
4775 :echo getqflist({'lines' : ["F1:10:L10"]})
4776<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004777 Return type: list<dict<any>> or list<any>
4778
4779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004780getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4781 The result is a String, which is the contents of register
4782 {regname}. Example: >
4783 :let cliptext = getreg('*')
4784< When register {regname} was not set the result is an empty
4785 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004786 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004787
4788 getreg('=') returns the last evaluated value of the expression
4789 register. (For use in maps.)
4790 getreg('=', 1) returns the expression itself, so that it can
4791 be restored with |setreg()|. For other registers the extra
4792 argument is ignored, thus you can always give it.
4793
4794 If {list} is present and |TRUE|, the result type is changed
4795 to |List|. Each list item is one text line. Use it if you care
4796 about zero bytes possibly present inside register: without
4797 third argument both NLs and zero bytes are represented as NLs
4798 (see |NL-used-for-Nul|).
4799 When the register was not set an empty list is returned.
4800
4801 If {regname} is "", the unnamed register '"' is used.
4802 If {regname} is not specified, |v:register| is used.
4803 In |Vim9-script| {regname} must be one character.
4804
4805 Can also be used as a |method|: >
4806 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004807<
4808 Return type: |String|
4809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004810
4811getreginfo([{regname}]) *getreginfo()*
4812 Returns detailed information about register {regname} as a
4813 Dictionary with the following entries:
4814 regcontents List of lines contained in register
4815 {regname}, like
4816 |getreg|({regname}, 1, 1).
4817 regtype the type of register {regname}, as in
4818 |getregtype()|.
4819 isunnamed Boolean flag, v:true if this register
4820 is currently pointed to by the unnamed
4821 register.
4822 points_to for the unnamed register, gives the
4823 single letter name of the register
4824 currently pointed to (see |quotequote|).
4825 For example, after deleting a line
4826 with `dd`, this field will be "1",
4827 which is the register that got the
4828 deleted text.
4829
4830 The {regname} argument is a string. If {regname} is invalid
4831 or not set, an empty Dictionary will be returned.
4832 If {regname} is "" or "@", the unnamed register '"' is used.
4833 If {regname} is not specified, |v:register| is used.
4834 The returned Dictionary can be passed to |setreg()|.
4835 In |Vim9-script| {regname} must be one character.
4836
4837 Can also be used as a |method|: >
4838 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004839<
4840 Return type: dict<any>
4841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004842
Shougo Matsushita19b71882024-02-28 22:48:12 +01004843getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004844 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004845 buffer.
4846
4847 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004848 See |getpos()| for the format of the list. It's possible
4849 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004850 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004851
4852 The optional argument {opts} is a Dict and supports the
4853 following items:
4854
zeertzjqafc22952024-05-24 19:07:12 +02004855 type Specify the region's selection type.
4856 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004857 except that the width can be omitted
4858 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004859 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004860
zeertzjq87410ab2024-03-02 06:00:23 +08004861 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004862 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004863 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004864
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004865 You can get the last selection type by |visualmode()|.
4866 If Visual mode is active, use |mode()| to get the Visual mode
4867 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004868 This function is useful to get text starting and ending in
4869 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004870
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004871 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004872 Note that:
4873 - Order of {pos1} and {pos2} doesn't matter, it will always
4874 return content from the upper left position to the lower
4875 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004876 - If 'virtualedit' is enabled and the region is past the end
4877 of the lines, resulting lines are padded with spaces.
4878 - If the region is blockwise and it starts or ends in the
4879 middle of a multi-cell character, it is not included but
4880 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004881 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004882 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004883 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004884 - It is evaluated in current window context, which makes a
4885 difference if the buffer is displayed in a window with
4886 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004887
4888 Examples: >
4889 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004890 \ <Cmd>echow getregion(
4891 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004892<
4893 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004894 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004895<
4896 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004897
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004898
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004899getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4900 Same as |getregion()|, but returns a list of positions
4901 describing the buffer text segments bound by {pos1} and
4902 {pos2}.
4903 The segments are a pair of positions for every line: >
4904 [[{start_pos}, {end_pos}], ...]
4905<
4906 The position is a |List| with four numbers:
4907 [bufnum, lnum, col, off]
4908 "bufnum" is the buffer number.
4909 "lnum" and "col" are the position in the buffer. The first
4910 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004911 If the "off" number of a starting position is non-zero, it is
4912 the offset in screen columns from the start of the character.
4913 E.g., a position within a <Tab> or after the last character.
4914 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004915 the offset of the character's first cell not included in the
4916 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004917
zeertzjq2b09de92024-05-24 07:48:51 +02004918 Apart from the options supported by |getregion()|, {opts} also
4919 supports the following:
4920
4921 eol If |TRUE|, indicate positions beyond
4922 the end of a line with "col" values
4923 one more than the length of the line.
4924 If |FALSE|, positions are limited
4925 within their lines, and if a line is
4926 empty or the selection is entirely
4927 beyond the end of a line, a "col"
4928 value of 0 is used for both positions.
4929 (default: |FALSE|)
4930
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004931 Can also be used as a |method|: >
4932 getpos('.')->getregionpos(getpos("'a"))
4933<
zeertzjqd4d12072024-07-16 20:34:16 +02004934 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004935
4936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004937getregtype([{regname}]) *getregtype()*
4938 The result is a String, which is type of register {regname}.
4939 The value will be one of:
4940 "v" for |characterwise| text
4941 "V" for |linewise| text
4942 "<CTRL-V>{width}" for |blockwise-visual| text
4943 "" for an empty or unknown register
4944 <CTRL-V> is one character with value 0x16.
4945 The {regname} argument is a string. If {regname} is "", the
4946 unnamed register '"' is used. If {regname} is not specified,
4947 |v:register| is used.
4948 In |Vim9-script| {regname} must be one character.
4949
4950 Can also be used as a |method|: >
4951 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004952<
4953 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004954
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004955
Bram Moolenaar71badf92023-04-22 22:40:14 +01004956getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004957 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004958 scripts in the order they were sourced, like what
4959 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004960
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004961 The optional Dict argument {opts} supports the following
4962 optional items:
4963 name Script name match pattern. If specified,
4964 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01004965 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004966 "name" are returned.
4967 sid Script ID |<SID>|. If specified, only
4968 information about the script with ID "sid" is
4969 returned and "name" is ignored.
4970
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004971 Each item in the returned List is a |Dict| with the following
4972 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004973 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01004974 `import autoload` but was not actually sourced
4975 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004976 functions List of script-local function names defined in
4977 the script. Present only when a particular
4978 script is specified using the "sid" item in
4979 {opts}.
4980 name Vim script file name.
4981 sid Script ID |<SID>|.
4982 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01004983 this script name links to, if any, otherwise
4984 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004985 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00004986 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004987 specified using the "sid" item in {opts}.
4988 Note that this is a copy, the value of
4989 script-local variables cannot be changed using
4990 this dictionary.
h_east59858792023-10-25 22:47:05 +09004991 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01004992
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004993 Examples: >
4994 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08004995 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004996<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004997 Return type: list<dict<any>>
4998
4999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005000gettabinfo([{tabnr}]) *gettabinfo()*
5001 If {tabnr} is not specified, then information about all the
5002 tab pages is returned as a |List|. Each List item is a
5003 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5004 number and information about that one is returned. If the tab
5005 page does not exist an empty List is returned.
5006
5007 Each List item is a |Dictionary| with the following entries:
5008 tabnr tab page number.
5009 variables a reference to the dictionary with
5010 tabpage-local variables
5011 windows List of |window-ID|s in the tab page.
5012
5013 Can also be used as a |method|: >
5014 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005015<
5016 Return type: list<dict<any>>
5017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005018
5019gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5020 Get the value of a tab-local variable {varname} in tab page
5021 {tabnr}. |t:var|
5022 Tabs are numbered starting with one.
5023 The {varname} argument is a string. When {varname} is empty a
5024 dictionary with all tab-local variables is returned.
5025 Note that the name without "t:" must be used.
5026 When the tab or variable doesn't exist {def} or an empty
5027 string is returned, there is no error message.
5028
5029 Can also be used as a |method|: >
5030 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005031<
5032 Return type: any, depending on {varname}
5033
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005034
5035gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5036 Get the value of window-local variable {varname} in window
5037 {winnr} in tab page {tabnr}.
5038 The {varname} argument is a string. When {varname} is empty a
5039 dictionary with all window-local variables is returned.
5040 When {varname} is equal to "&" get the values of all
5041 window-local options in a |Dictionary|.
5042 Otherwise, when {varname} starts with "&" get the value of a
5043 window-local option.
5044 Note that {varname} must be the name without "w:".
5045 Tabs are numbered starting with one. For the current tabpage
5046 use |getwinvar()|.
5047 {winnr} can be the window number or the |window-ID|.
5048 When {winnr} is zero the current window is used.
5049 This also works for a global option, buffer-local option and
5050 window-local option, but it doesn't work for a global variable
5051 or buffer-local variable.
5052 When the tab, window or variable doesn't exist {def} or an
5053 empty string is returned, there is no error message.
5054 Examples: >
5055 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005056 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005057<
5058 To obtain all window-local variables use: >
5059 gettabwinvar({tabnr}, {winnr}, '&')
5060
5061< Can also be used as a |method|: >
5062 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005063<
5064 Return type: any, depending on {varname}
5065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005066
5067gettagstack([{winnr}]) *gettagstack()*
5068 The result is a Dict, which is the tag stack of window {winnr}.
5069 {winnr} can be the window number or the |window-ID|.
5070 When {winnr} is not specified, the current window is used.
5071 When window {winnr} doesn't exist, an empty Dict is returned.
5072
5073 The returned dictionary contains the following entries:
5074 curidx Current index in the stack. When at
5075 top of the stack, set to (length + 1).
5076 Index of bottom of the stack is 1.
5077 items List of items in the stack. Each item
5078 is a dictionary containing the
5079 entries described below.
5080 length Number of entries in the stack.
5081
5082 Each item in the stack is a dictionary with the following
5083 entries:
5084 bufnr buffer number of the current jump
5085 from cursor position before the tag jump.
5086 See |getpos()| for the format of the
5087 returned list.
5088 matchnr current matching tag number. Used when
5089 multiple matching tags are found for a
5090 name.
5091 tagname name of the tag
5092
5093 See |tagstack| for more information about the tag stack.
5094
5095 Can also be used as a |method|: >
5096 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005097<
5098 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005099
5100
Christ van Willegence0ef912024-06-20 23:41:59 +02005101gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005102 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005103 This is intended for use in Vim scripts. When generating
5104 message translations the {text} is extracted by `xgettext`,
5105 the translator can add translated messages into the .po file
5106 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005107 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005108 `xgettext` does not support single quoted escaped text.
5109
Christ van Willegence0ef912024-06-20 23:41:59 +02005110 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005111 for that specific package. This is mainly required for
5112 third-party Vim scripts. You need to specify a path to the
5113 translations with the |bindtextdomain()| function before
5114 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005115
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005116 Return type: |String|
5117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005118
5119getwininfo([{winid}]) *getwininfo()*
5120 Returns information about windows as a |List| with Dictionaries.
5121
5122 If {winid} is given Information about the window with that ID
5123 is returned, as a |List| with one item. If the window does not
5124 exist the result is an empty list.
5125
5126 Without {winid} information about all the windows in all the
5127 tab pages is returned.
5128
5129 Each List item is a |Dictionary| with the following entries:
5130 botline last complete displayed buffer line
5131 bufnr number of buffer in the window
5132 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005133 leftcol first column displayed; only used when
5134 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005135 loclist 1 if showing a location list
5136 {only with the +quickfix feature}
5137 quickfix 1 if quickfix or location list window
5138 {only with the +quickfix feature}
5139 terminal 1 if a terminal window
5140 {only with the +terminal feature}
5141 tabnr tab page number
5142 topline first displayed buffer line
5143 variables a reference to the dictionary with
5144 window-local variables
5145 width window width
5146 winbar 1 if the window has a toolbar, 0
5147 otherwise
5148 wincol leftmost screen column of the window;
5149 "col" from |win_screenpos()|
5150 textoff number of columns occupied by any
5151 'foldcolumn', 'signcolumn' and line
5152 number in front of the text
5153 winid |window-ID|
5154 winnr window number
5155 winrow topmost screen line of the window;
5156 "row" from |win_screenpos()|
5157
5158 Can also be used as a |method|: >
5159 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005160<
5161 Return type: list<dict<any>>
5162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005163
5164getwinpos([{timeout}]) *getwinpos()*
5165 The result is a |List| with two numbers, the result of
5166 |getwinposx()| and |getwinposy()| combined:
5167 [x-pos, y-pos]
5168 {timeout} can be used to specify how long to wait in msec for
5169 a response from the terminal. When omitted 100 msec is used.
5170 Use a longer time for a remote terminal.
5171 When using a value less than 10 and no response is received
5172 within that time, a previously reported position is returned,
5173 if available. This can be used to poll for the position and
5174 do some work in the meantime: >
5175 while 1
5176 let res = getwinpos(1)
5177 if res[0] >= 0
5178 break
5179 endif
5180 " Do some work here
5181 endwhile
5182<
5183
5184 Can also be used as a |method|: >
5185 GetTimeout()->getwinpos()
5186<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005187 Return type: list<number>
5188
5189
5190getwinposx() *getwinposx()*
5191 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005192 the left hand side of the GUI Vim window. Also works for an
5193 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005194 The result will be -1 if the information is not available
5195 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005196 The value can be used with `:winpos`.
5197
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005198 Return type: |Number|
5199
5200
5201getwinposy() *getwinposy()*
5202 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005203 the top of the GUI Vim window. Also works for an xterm (uses
5204 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005205 The result will be -1 if the information is not available
5206 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005207 The value can be used with `:winpos`.
5208
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005209 Return type: |Number|
5210
5211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005212getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5213 Like |gettabwinvar()| for the current tabpage.
5214 Examples: >
5215 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005216 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005217
5218< Can also be used as a |method|: >
5219 GetWinnr()->getwinvar(varname)
5220<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005221 Return type: any, depending on {varname}
5222
5223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005224glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5225 Expand the file wildcards in {expr}. See |wildcards| for the
5226 use of special characters.
5227
5228 Unless the optional {nosuf} argument is given and is |TRUE|,
5229 the 'suffixes' and 'wildignore' options apply: Names matching
5230 one of the patterns in 'wildignore' will be skipped and
5231 'suffixes' affect the ordering of matches.
5232 'wildignorecase' always applies.
5233
5234 When {list} is present and it is |TRUE| the result is a |List|
5235 with all matching files. The advantage of using a List is,
5236 you also get filenames containing newlines correctly.
5237 Otherwise the result is a String and when there are several
5238 matches, they are separated by <NL> characters.
5239
5240 If the expansion fails, the result is an empty String or List.
5241
5242 You can also use |readdir()| if you need to do complicated
5243 things, such as limiting the number of matches.
5244
5245 A name for a non-existing file is not included. A symbolic
5246 link is only included if it points to an existing file.
5247 However, when the {alllinks} argument is present and it is
5248 |TRUE| then all symbolic links are included.
5249
5250 For most systems backticks can be used to get files names from
5251 any external command. Example: >
5252 :let tagfiles = glob("`find . -name tags -print`")
5253 :let &tags = substitute(tagfiles, "\n", ",", "g")
5254< The result of the program inside the backticks should be one
5255 item per line. Spaces inside an item are allowed.
5256
5257 See |expand()| for expanding special Vim variables. See
5258 |system()| for getting the raw output of an external command.
5259
5260 Can also be used as a |method|: >
5261 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005262<
5263 Return type: |String| or list<string> or list<any> depending
5264 on {list}
5265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005266
h-east624bb832024-11-09 18:37:32 +01005267glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005268 Convert a file pattern, as used by glob(), into a search
5269 pattern. The result can be used to match with a string that
5270 is a file name. E.g. >
5271 if filename =~ glob2regpat('Make*.mak')
5272< This is equivalent to: >
5273 if filename =~ '^Make.*\.mak$'
5274< When {string} is an empty string the result is "^$", match an
5275 empty string.
5276 Note that the result depends on the system. On MS-Windows
5277 a backslash usually means a path separator.
5278
5279 Can also be used as a |method|: >
5280 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005281<
5282 Return type: |String|
5283
5284 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005285globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5286 Perform glob() for String {expr} on all directories in {path}
5287 and concatenate the results. Example: >
5288 :echo globpath(&rtp, "syntax/c.vim")
5289<
5290 {path} is a comma-separated list of directory names. Each
5291 directory name is prepended to {expr} and expanded like with
5292 |glob()|. A path separator is inserted when needed.
5293 To add a comma inside a directory name escape it with a
5294 backslash. Note that on MS-Windows a directory may have a
5295 trailing backslash, remove it if you put a comma after it.
5296 If the expansion fails for one of the directories, there is no
5297 error message.
5298
5299 Unless the optional {nosuf} argument is given and is |TRUE|,
5300 the 'suffixes' and 'wildignore' options apply: Names matching
5301 one of the patterns in 'wildignore' will be skipped and
5302 'suffixes' affect the ordering of matches.
5303
5304 When {list} is present and it is |TRUE| the result is a |List|
5305 with all matching files. The advantage of using a List is, you
5306 also get filenames containing newlines correctly. Otherwise
5307 the result is a String and when there are several matches,
5308 they are separated by <NL> characters. Example: >
5309 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5310<
5311 {alllinks} is used as with |glob()|.
5312
5313 The "**" item can be used to search in a directory tree.
5314 For example, to find all "README.txt" files in the directories
5315 in 'runtimepath' and below: >
5316 :echo globpath(&rtp, "**/README.txt")
5317< Upwards search and limiting the depth of "**" is not
5318 supported, thus using 'path' will not always work properly.
5319
5320 Can also be used as a |method|, the base is passed as the
5321 second argument: >
5322 GetExpr()->globpath(&rtp)
5323<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005324 Return type: |String| or list<string> or list<any> depending
5325 on {list}
5326
5327
5328has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005329 When {check} is omitted or is zero: The result is a Number,
5330 which is 1 if the feature {feature} is supported, zero
5331 otherwise. The {feature} argument is a string, case is
5332 ignored. See |feature-list| below.
5333
5334 When {check} is present and not zero: The result is a Number,
5335 which is 1 if the feature {feature} could ever be supported,
5336 zero otherwise. This is useful to check for a typo in
5337 {feature} and to detect dead code. Keep in mind that an older
5338 Vim version will not know about a feature added later and
5339 features that have been abandoned will not be known by the
5340 current Vim version.
5341
5342 Also see |exists()| and |exists_compiled()|.
5343
5344 Note that to skip code that has a syntax error when the
5345 feature is not available, Vim may skip the rest of the line
5346 and miss a following `endif`. Therefore put the `endif` on a
5347 separate line: >
5348 if has('feature')
5349 let x = this->breaks->without->the->feature
5350 endif
5351< If the `endif` would be moved to the second line as "| endif" it
5352 would not be found.
5353
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005354 Return type: |Number|
5355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005356
5357has_key({dict}, {key}) *has_key()*
5358 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005359 has an entry with key {key}. FALSE otherwise.
5360 The {key} argument is a string. In |Vim9| script a number is
5361 also accepted (and converted to a string) but no other types.
5362 In legacy script the usual automatic conversion to string is
5363 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005364
5365 Can also be used as a |method|: >
5366 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005367<
5368 Return type: |Number|
5369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005370
5371haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5372 The result is a Number:
5373 1 when the window has set a local directory via |:lcd|
5374 2 when the tab-page has set a local directory via |:tcd|
5375 0 otherwise.
5376
5377 Without arguments use the current window.
5378 With {winnr} use this window in the current tab page.
5379 With {winnr} and {tabnr} use the window in the specified tab
5380 page.
5381 {winnr} can be the window number or the |window-ID|.
5382 If {winnr} is -1 it is ignored and only the tabpage is used.
5383 Return 0 if the arguments are invalid.
5384 Examples: >
5385 if haslocaldir() == 1
5386 " window local directory case
5387 elseif haslocaldir() == 2
5388 " tab-local directory case
5389 else
5390 " global directory case
5391 endif
5392
5393 " current window
5394 :echo haslocaldir()
5395 :echo haslocaldir(0)
5396 :echo haslocaldir(0, 0)
5397 " window n in current tab page
5398 :echo haslocaldir(n)
5399 :echo haslocaldir(n, 0)
5400 " window n in tab page m
5401 :echo haslocaldir(n, m)
5402 " tab page m
5403 :echo haslocaldir(-1, m)
5404<
5405 Can also be used as a |method|: >
5406 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005407<
5408 Return type: |Number|
5409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005410
5411hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5412 The result is a Number, which is TRUE if there is a mapping
5413 that contains {what} in somewhere in the rhs (what it is
5414 mapped to) and this mapping exists in one of the modes
5415 indicated by {mode}.
5416 The arguments {what} and {mode} are strings.
5417 When {abbr} is there and it is |TRUE| use abbreviations
5418 instead of mappings. Don't forget to specify Insert and/or
5419 Command-line mode.
5420 Both the global mappings and the mappings local to the current
5421 buffer are checked for a match.
5422 If no matching mapping is found FALSE is returned.
5423 The following characters are recognized in {mode}:
5424 n Normal mode
5425 v Visual and Select mode
5426 x Visual mode
5427 s Select mode
5428 o Operator-pending mode
5429 i Insert mode
5430 l Language-Argument ("r", "f", "t", etc.)
5431 c Command-line mode
5432 When {mode} is omitted, "nvo" is used.
5433
5434 This function is useful to check if a mapping already exists
5435 to a function in a Vim script. Example: >
5436 :if !hasmapto('\ABCdoit')
5437 : map <Leader>d \ABCdoit
5438 :endif
5439< This installs the mapping to "\ABCdoit" only if there isn't
5440 already a mapping to "\ABCdoit".
5441
5442 Can also be used as a |method|: >
5443 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005444<
5445 Return type: |Number|
5446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005447
5448histadd({history}, {item}) *histadd()*
5449 Add the String {item} to the history {history} which can be
5450 one of: *hist-names*
5451 "cmd" or ":" command line history
5452 "search" or "/" search pattern history
5453 "expr" or "=" typed expression history
5454 "input" or "@" input line history
5455 "debug" or ">" debug command history
5456 empty the current or last used history
5457 The {history} string does not need to be the whole name, one
5458 character is sufficient.
5459 If {item} does already exist in the history, it will be
5460 shifted to become the newest entry.
5461 The result is a Number: TRUE if the operation was successful,
5462 otherwise FALSE is returned.
5463
5464 Example: >
5465 :call histadd("input", strftime("%Y %b %d"))
5466 :let date=input("Enter date: ")
5467< This function is not available in the |sandbox|.
5468
5469 Can also be used as a |method|, the base is passed as the
5470 second argument: >
5471 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005472<
5473 Return type: |Number|
5474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005475
5476histdel({history} [, {item}]) *histdel()*
5477 Clear {history}, i.e. delete all its entries. See |hist-names|
5478 for the possible values of {history}.
5479
5480 If the parameter {item} evaluates to a String, it is used as a
5481 regular expression. All entries matching that expression will
5482 be removed from the history (if there are any).
5483 Upper/lowercase must match, unless "\c" is used |/\c|.
5484 If {item} evaluates to a Number, it will be interpreted as
5485 an index, see |:history-indexing|. The respective entry will
5486 be removed if it exists.
5487
5488 The result is TRUE for a successful operation, otherwise FALSE
5489 is returned.
5490
5491 Examples:
5492 Clear expression register history: >
5493 :call histdel("expr")
5494<
5495 Remove all entries starting with "*" from the search history: >
5496 :call histdel("/", '^\*')
5497<
5498 The following three are equivalent: >
5499 :call histdel("search", histnr("search"))
5500 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005501 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005502<
5503 To delete the last search pattern and use the last-but-one for
5504 the "n" command and 'hlsearch': >
5505 :call histdel("search", -1)
5506 :let @/ = histget("search", -1)
5507<
5508 Can also be used as a |method|: >
5509 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005510<
5511 Return type: |Number|
5512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005513
5514histget({history} [, {index}]) *histget()*
5515 The result is a String, the entry with Number {index} from
5516 {history}. See |hist-names| for the possible values of
5517 {history}, and |:history-indexing| for {index}. If there is
5518 no such entry, an empty String is returned. When {index} is
5519 omitted, the most recent item from the history is used.
5520
5521 Examples:
5522 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005523 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005524
5525< Define an Ex command ":H {num}" that supports re-execution of
5526 the {num}th entry from the output of |:history|. >
5527 :command -nargs=1 H execute histget("cmd", 0+<args>)
5528<
5529 Can also be used as a |method|: >
5530 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005531<
5532 Return type: |String|
5533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005534
5535histnr({history}) *histnr()*
5536 The result is the Number of the current entry in {history}.
5537 See |hist-names| for the possible values of {history}.
5538 If an error occurred, -1 is returned.
5539
5540 Example: >
5541 :let inp_index = histnr("expr")
5542
5543< Can also be used as a |method|: >
5544 GetHistory()->histnr()
5545<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005546 Return type: |Number|
5547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005548hlexists({name}) *hlexists()*
5549 The result is a Number, which is TRUE if a highlight group
5550 called {name} exists. This is when the group has been
5551 defined in some way. Not necessarily when highlighting has
5552 been defined for it, it may also have been used for a syntax
5553 item.
5554 *highlight_exists()*
5555 Obsolete name: highlight_exists().
5556
5557 Can also be used as a |method|: >
5558 GetName()->hlexists()
5559<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005560 Return type: |Number|
5561
5562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005563hlget([{name} [, {resolve}]]) *hlget()*
5564 Returns a List of all the highlight group attributes. If the
5565 optional {name} is specified, then returns a List with only
5566 the attributes of the specified highlight group. Returns an
5567 empty List if the highlight group {name} is not present.
5568
5569 If the optional {resolve} argument is set to v:true and the
5570 highlight group {name} is linked to another group, then the
5571 link is resolved recursively and the attributes of the
5572 resolved highlight group are returned.
5573
5574 Each entry in the returned List is a Dictionary with the
5575 following items:
5576 cleared boolean flag, set to v:true if the highlight
5577 group attributes are cleared or not yet
5578 specified. See |highlight-clear|.
5579 cterm cterm attributes. See |highlight-cterm|.
5580 ctermbg cterm background color.
5581 See |highlight-ctermbg|.
5582 ctermfg cterm foreground color.
5583 See |highlight-ctermfg|.
5584 ctermul cterm underline color. See |highlight-ctermul|.
5585 default boolean flag, set to v:true if the highlight
5586 group link is a default link. See
5587 |highlight-default|.
5588 font highlight group font. See |highlight-font|.
5589 gui gui attributes. See |highlight-gui|.
5590 guibg gui background color. See |highlight-guibg|.
5591 guifg gui foreground color. See |highlight-guifg|.
5592 guisp gui special color. See |highlight-guisp|.
5593 id highlight group ID.
5594 linksto linked highlight group name.
5595 See |:highlight-link|.
5596 name highlight group name. See |group-name|.
5597 start start terminal keycode. See |highlight-start|.
5598 stop stop terminal keycode. See |highlight-stop|.
5599 term term attributes. See |highlight-term|.
5600
5601 The 'term', 'cterm' and 'gui' items in the above Dictionary
5602 have a dictionary value with the following optional boolean
5603 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5604 'reverse', 'inverse' and 'strikethrough'.
5605
5606 Example(s): >
5607 :echo hlget()
5608 :echo hlget('ModeMsg')
5609 :echo hlget('Number', v:true)
5610<
5611 Can also be used as a |method|: >
5612 GetName()->hlget()
5613<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005614 Return type: list<dict<any>>
5615
5616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005617hlset({list}) *hlset()*
5618 Creates or modifies the attributes of a List of highlight
5619 groups. Each item in {list} is a dictionary containing the
5620 attributes of a highlight group. See |hlget()| for the list of
5621 supported items in this dictionary.
5622
5623 In addition to the items described in |hlget()|, the following
5624 additional items are supported in the dictionary:
5625
5626 force boolean flag to force the creation of
5627 a link for an existing highlight group
5628 with attributes.
5629
5630 The highlight group is identified using the 'name' item and
5631 the 'id' item (if supplied) is ignored. If a highlight group
5632 with a specified name doesn't exist, then it is created.
5633 Otherwise the attributes of an existing highlight group are
5634 modified.
5635
5636 If an empty dictionary value is used for the 'term' or 'cterm'
5637 or 'gui' entries, then the corresponding attributes are
5638 cleared. If the 'cleared' item is set to v:true, then all the
5639 attributes of the highlight group are cleared.
5640
5641 The 'linksto' item can be used to link a highlight group to
5642 another highlight group. See |:highlight-link|.
5643
5644 Returns zero for success, -1 for failure.
5645
5646 Example(s): >
5647 " add bold attribute to the Visual highlight group
5648 :call hlset([#{name: 'Visual',
5649 \ term: #{reverse: 1 , bold: 1}}])
5650 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5651 :let l = hlget()
5652 :call hlset(l)
5653 " clear the Search highlight group
5654 :call hlset([#{name: 'Search', cleared: v:true}])
5655 " clear the 'term' attributes for a highlight group
5656 :call hlset([#{name: 'Title', term: {}}])
5657 " create the MyHlg group linking it to DiffAdd
5658 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5659 " remove the MyHlg group link
5660 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5661 " clear the attributes and a link
5662 :call hlset([#{name: 'MyHlg', cleared: v:true,
5663 \ linksto: 'NONE'}])
5664<
5665 Can also be used as a |method|: >
5666 GetAttrList()->hlset()
5667<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005668 Return type: |Number|
5669
5670hlID({name}) *hlID()*
5671 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005672 with name {name}. When the highlight group doesn't exist,
5673 zero is returned.
5674 This can be used to retrieve information about the highlight
5675 group. For example, to get the background color of the
5676 "Comment" group: >
5677 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5678< *highlightID()*
5679 Obsolete name: highlightID().
5680
5681 Can also be used as a |method|: >
5682 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005683<
5684 Return type: |Number|
5685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005686
5687hostname() *hostname()*
5688 The result is a String, which is the name of the machine on
5689 which Vim is currently running. Machine names greater than
5690 256 characters long are truncated.
5691
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005692 Return type: |String|
5693
5694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005695iconv({string}, {from}, {to}) *iconv()*
5696 The result is a String, which is the text {string} converted
5697 from encoding {from} to encoding {to}.
5698 When the conversion completely fails an empty string is
5699 returned. When some characters could not be converted they
5700 are replaced with "?".
5701 The encoding names are whatever the iconv() library function
5702 can accept, see ":!man 3 iconv".
5703 Most conversions require Vim to be compiled with the |+iconv|
5704 feature. Otherwise only UTF-8 to latin1 conversion and back
5705 can be done.
5706 This can be used to display messages with special characters,
5707 no matter what 'encoding' is set to. Write the message in
5708 UTF-8 and use: >
5709 echo iconv(utf8_str, "utf-8", &enc)
5710< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5711 from/to UCS-2 is automatically changed to use UTF-8. You
5712 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5713
5714 Can also be used as a |method|: >
5715 GetText()->iconv('latin1', 'utf-8')
5716<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005717 Return type: |String|
5718
5719
h-east624bb832024-11-09 18:37:32 +01005720id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005721 The result is a unique String associated with the {item} and
5722 not with the {item}'s contents. It is only valid while the
5723 {item} exists and is referenced. It is valid only in the
5724 instance of vim that produces the result. The whole idea is
5725 that `id({item})` does not change if the contents of {item}
5726 changes. This is useful as a `key` for creating an identity
5727 dictionary, rather than one based on equals.
5728
5729 This operation does not reference {item} and there is no
5730 function to convert the `id` to the {item}. It may be useful to
5731 have a map of `id` to {item}. The following >
5732 var referenceMap: dict<any>
5733 var id = item->id()
5734 referenceMap[id] = item
5735< prevents {item} from being garbage collected and provides a
5736 way to get the {item} from the `id`.
5737
5738 {item} may be a List, Dictionary, Object, Job, Channel or
5739 Blob. If the item is not a permitted type, or it is a null
5740 value, then an empty String is returned.
5741
5742 Can also be used as a |method|: >
5743 GetItem()->id()
5744<
5745 Return type: |String|
5746
5747
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005748indent({lnum}) *indent()*
5749 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005750 current buffer. The indent is counted in spaces, the value
5751 of 'tabstop' is relevant. {lnum} is used just like in
5752 |getline()|.
5753 When {lnum} is invalid -1 is returned. In |Vim9| script an
5754 error is given.
5755
5756 Can also be used as a |method|: >
5757 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005758<
5759 Return type: |Number|
5760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005761
5762index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005763 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005764 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005766 If {object} is a |List| return the lowest index where the item
5767 has a value equal to {expr}. There is no automatic
5768 conversion, so the String "4" is different from the Number 4.
5769 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005770 of 'ignorecase' is not used here, case matters as indicated by
5771 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005772
5773 If {object} is |Blob| return the lowest index where the byte
5774 value is equal to {expr}.
5775
5776 If {start} is given then start looking at the item with index
5777 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005779 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5780 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005782 -1 is returned when {expr} is not found in {object}.
5783 Example: >
5784 :let idx = index(words, "the")
5785 :if index(numbers, 123) >= 0
5786
5787< Can also be used as a |method|: >
5788 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005789<
5790 Return type: |Number|
5791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005792
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005793indexof({object}, {expr} [, {opts}]) *indexof()*
5794 Returns the index of an item in {object} where {expr} is
5795 v:true. {object} must be a |List| or a |Blob|.
5796
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005797 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005798 List until the expression is v:true and return the index of
5799 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005800
5801 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005802 Blob until the expression is v:true and return the index of
5803 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005804
5805 {expr} must be a |string| or |Funcref|.
5806
5807 If {expr} is a |string|: If {object} is a |List|, inside
5808 {expr} |v:key| has the index of the current List item and
5809 |v:val| has the value of the item. If {object} is a |Blob|,
5810 inside {expr} |v:key| has the index of the current byte and
5811 |v:val| has the byte value.
5812
5813 If {expr} is a |Funcref| it must take two arguments:
5814 1. the key or the index of the current item.
5815 2. the value of the current item.
5816 The function must return |TRUE| if the item is found and the
5817 search should stop.
5818
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005819 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005820 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005821 startidx start evaluating {expr} at the item with this
5822 index; may be negative for an item relative to
5823 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005824 Returns -1 when {expr} evaluates to v:false for all the items.
5825 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005826 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5827 :echo indexof(l, "v:val.n == 20")
5828 :echo indexof(l, {i, v -> v.n == 30})
5829 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005830
5831< Can also be used as a |method|: >
5832 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005833<
5834 Return type: |Number|
5835
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005837input({prompt} [, {text} [, {completion}]]) *input()*
5838 The result is a String, which is whatever the user typed on
5839 the command-line. The {prompt} argument is either a prompt
5840 string, or a blank string (for no prompt). A '\n' can be used
5841 in the prompt to start a new line.
5842 The highlighting set with |:echohl| is used for the prompt.
5843 The input is entered just like a command-line, with the same
5844 editing commands and mappings. There is a separate history
5845 for lines typed for input().
5846 Example: >
5847 :if input("Coffee or beer? ") == "beer"
5848 : echo "Cheers!"
5849 :endif
5850<
5851 If the optional {text} argument is present and not empty, this
5852 is used for the default reply, as if the user typed this.
5853 Example: >
5854 :let color = input("Color? ", "white")
5855
5856< The optional {completion} argument specifies the type of
5857 completion supported for the input. Without it completion is
5858 not performed. The supported completion types are the same as
5859 that can be supplied to a user-defined command using the
5860 "-complete=" argument. Refer to |:command-completion| for
5861 more information. Example: >
5862 let fname = input("File: ", "", "file")
5863<
5864 NOTE: This function must not be used in a startup file, for
5865 the versions that only run in GUI mode (e.g., the Win32 GUI).
5866 Note: When input() is called from within a mapping it will
5867 consume remaining characters from that mapping, because a
5868 mapping is handled like the characters were typed.
5869 Use |inputsave()| before input() and |inputrestore()|
5870 after input() to avoid that. Another solution is to avoid
5871 that further characters follow in the mapping, e.g., by using
5872 |:execute| or |:normal|.
5873
5874 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005875 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005876 :function GetFoo()
5877 : call inputsave()
5878 : let g:Foo = input("enter search pattern: ")
5879 : call inputrestore()
5880 :endfunction
5881
5882< Can also be used as a |method|: >
5883 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005884<
5885 Return type: |String|
5886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005887
5888inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5889 Like |input()|, but when the GUI is running and text dialogs
5890 are supported, a dialog window pops up to input the text.
5891 Example: >
5892 :let n = inputdialog("value for shiftwidth", shiftwidth())
5893 :if n != ""
5894 : let &sw = n
5895 :endif
5896< When the dialog is cancelled {cancelreturn} is returned. When
5897 omitted an empty string is returned.
5898 Hitting <Enter> works like pressing the OK button. Hitting
5899 <Esc> works like pressing the Cancel button.
5900 NOTE: Command-line completion is not supported.
5901
5902 Can also be used as a |method|: >
5903 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005904<
5905 Return type: |String|
5906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005907
5908inputlist({textlist}) *inputlist()*
5909 {textlist} must be a |List| of strings. This |List| is
5910 displayed, one string per line. The user will be prompted to
5911 enter a number, which is returned.
5912 The user can also select an item by clicking on it with the
5913 mouse, if the mouse is enabled in the command line ('mouse' is
5914 "a" or includes "c"). For the first string 0 is returned.
5915 When clicking above the first item a negative number is
5916 returned. When clicking on the prompt one more than the
5917 length of {textlist} is returned.
5918 Make sure {textlist} has less than 'lines' entries, otherwise
5919 it won't work. It's a good idea to put the entry number at
5920 the start of the string. And put a prompt in the first item.
5921 Example: >
5922 let color = inputlist(['Select color:', '1. red',
5923 \ '2. green', '3. blue'])
5924
5925< Can also be used as a |method|: >
5926 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005927<
5928 Return type: |Number|
5929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005930
5931inputrestore() *inputrestore()*
5932 Restore typeahead that was saved with a previous |inputsave()|.
5933 Should be called the same number of times inputsave() is
5934 called. Calling it more often is harmless though.
5935 Returns TRUE when there is nothing to restore, FALSE otherwise.
5936
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005937 Return type: |Number|
5938
5939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005940inputsave() *inputsave()*
5941 Preserve typeahead (also from mappings) and clear it, so that
5942 a following prompt gets input from the user. Should be
5943 followed by a matching inputrestore() after the prompt. Can
5944 be used several times, in which case there must be just as
5945 many inputrestore() calls.
5946 Returns TRUE when out of memory, FALSE otherwise.
5947
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005948 Return type: |Number|
5949
5950
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005951inputsecret({prompt} [, {text}]) *inputsecret()*
5952 This function acts much like the |input()| function with but
5953 two exceptions:
5954 a) the user's response will be displayed as a sequence of
5955 asterisks ("*") thereby keeping the entry secret, and
5956 b) the user's response will not be recorded on the input
5957 |history| stack.
5958 The result is a String, which is whatever the user actually
5959 typed on the command-line in response to the issued prompt.
5960 NOTE: Command-line completion is not supported.
5961
5962 Can also be used as a |method|: >
5963 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005964<
5965 Return type: |String|
5966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005967
5968insert({object}, {item} [, {idx}]) *insert()*
5969 When {object} is a |List| or a |Blob| insert {item} at the start
5970 of it.
5971
5972 If {idx} is specified insert {item} before the item with index
5973 {idx}. If {idx} is zero it goes before the first item, just
5974 like omitting {idx}. A negative {idx} is also possible, see
5975 |list-index|. -1 inserts just before the last item.
5976
5977 Returns the resulting |List| or |Blob|. Examples: >
5978 :let mylist = insert([2, 3, 5], 1)
5979 :call insert(mylist, 4, -1)
5980 :call insert(mylist, 6, len(mylist))
5981< The last example can be done simpler with |add()|.
5982 Note that when {item} is a |List| it is inserted as a single
5983 item. Use |extend()| to concatenate |Lists|.
5984
5985 Can also be used as a |method|: >
5986 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005987<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005988 Return type: |Number|
5989
5990
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005991 *instanceof()* *E614* *E616* *E693*
5992instanceof({object}, {class})
5993 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01005994 argument is a direct or indirect instance of a |Class|,
5995 |Interface|, or class |:type| alias specified by {class}.
5996 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07005997 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02005998 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01005999 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006000
6001< Can also be used as a |method|: >
6002 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006003<
6004 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006006interrupt() *interrupt()*
6007 Interrupt script execution. It works more or less like the
6008 user typing CTRL-C, most commands won't execute and control
6009 returns to the user. This is useful to abort execution
6010 from lower down, e.g. in an autocommand. Example: >
6011 :function s:check_typoname(file)
6012 : if fnamemodify(a:file, ':t') == '['
6013 : echomsg 'Maybe typo'
6014 : call interrupt()
6015 : endif
6016 :endfunction
6017 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006018<
6019 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006020
6021invert({expr}) *invert()*
6022 Bitwise invert. The argument is converted to a number. A
6023 List, Dict or Float argument causes an error. Example: >
6024 :let bits = invert(bits)
6025< Can also be used as a |method|: >
6026 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006027<
6028 Return type: |Number|
6029
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006030
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006031isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006032 The result is a Number, which is |TRUE| when {path} is an
6033 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006034 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006035 On MS-Windows, it is considered absolute when it starts with an
6036 optional drive prefix and is followed by a '\' or '/'. UNC paths
6037 are always absolute.
6038 Example: >
6039 echo isabsolutepath('/usr/share/') " 1
6040 echo isabsolutepath('./foobar') " 0
6041 echo isabsolutepath('C:\Windows') " 1
6042 echo isabsolutepath('foobar') " 0
6043 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006044<
LemonBoydca1d402022-04-28 15:26:33 +01006045 Can also be used as a |method|: >
6046 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006047<
6048 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006049
6050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006051isdirectory({directory}) *isdirectory()*
6052 The result is a Number, which is |TRUE| when a directory
6053 with the name {directory} exists. If {directory} doesn't
6054 exist, or isn't a directory, the result is |FALSE|. {directory}
6055 is any expression, which is used as a String.
6056
6057 Can also be used as a |method|: >
6058 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006059<
6060 Return type: |Number|
6061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006062
6063isinf({expr}) *isinf()*
6064 Return 1 if {expr} is a positive infinity, or -1 a negative
6065 infinity, otherwise 0. >
6066 :echo isinf(1.0 / 0.0)
6067< 1 >
6068 :echo isinf(-1.0 / 0.0)
6069< -1
6070
6071 Can also be used as a |method|: >
6072 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006073<
6074 Return type: |Number|
6075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006076
6077islocked({expr}) *islocked()* *E786*
6078 The result is a Number, which is |TRUE| when {expr} is the
6079 name of a locked variable.
6080 The string argument {expr} must be the name of a variable,
6081 |List| item or |Dictionary| entry, not the variable itself!
6082 Example: >
6083 :let alist = [0, ['a', 'b'], 2, 3]
6084 :lockvar 1 alist
6085 :echo islocked('alist') " 1
6086 :echo islocked('alist[1]') " 0
6087
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006088< When {expr} is a variable that does not exist -1 is returned.
6089 If {expr} uses a range, list or dict index that is out of
6090 range or does not exist you get an error message. Use
6091 |exists()| to check for existence.
6092 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006093
6094 Can also be used as a |method|: >
6095 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006096<
6097 Return type: |Number|
6098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006099
6100isnan({expr}) *isnan()*
6101 Return |TRUE| if {expr} is a float with value NaN. >
6102 echo isnan(0.0 / 0.0)
6103< 1
6104
6105 Can also be used as a |method|: >
6106 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006107<
6108 Return type: |Number|
6109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006110
6111items({dict}) *items()*
6112 Return a |List| with all the key-value pairs of {dict}. Each
6113 |List| item is a list with two items: the key of a {dict}
6114 entry and the value of this entry. The |List| is in arbitrary
6115 order. Also see |keys()| and |values()|.
6116 Example: >
6117 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006118 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006119 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006120<
6121 A List or a String argument is also supported. In these
6122 cases, items() returns a List with the index and the value at
6123 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006124
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006125 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006126 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006127<
6128 Return type: list<list<any>> or list<any>
6129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006130
6131job_ functions are documented here: |job-functions-details|
6132
6133
6134join({list} [, {sep}]) *join()*
6135 Join the items in {list} together into one String.
6136 When {sep} is specified it is put in between the items. If
6137 {sep} is omitted a single space is used.
6138 Note that {sep} is not added at the end. You might want to
6139 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006140 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006141< String items are used as-is. |Lists| and |Dictionaries| are
6142 converted into a string like with |string()|.
6143 The opposite function is |split()|.
6144
6145 Can also be used as a |method|: >
6146 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006147<
6148 Return type: |String|
6149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006150
6151js_decode({string}) *js_decode()*
6152 This is similar to |json_decode()| with these differences:
6153 - Object key names do not have to be in quotes.
6154 - Strings can be in single quotes.
6155 - Empty items in an array (between two commas) are allowed and
6156 result in v:none items.
6157
6158 Can also be used as a |method|: >
6159 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006160<
6161 Return type: any, depending on {varname}
6162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006163
6164js_encode({expr}) *js_encode()*
6165 This is similar to |json_encode()| with these differences:
6166 - Object key names are not in quotes.
6167 - v:none items in an array result in an empty item between
6168 commas.
6169 For example, the Vim object:
6170 [1,v:none,{"one":1},v:none] ~
6171 Will be encoded as:
6172 [1,,{one:1},,] ~
6173 While json_encode() would produce:
6174 [1,null,{"one":1},null] ~
6175 This encoding is valid for JavaScript. It is more efficient
6176 than JSON, especially when using an array with optional items.
6177
6178 Can also be used as a |method|: >
6179 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006180<
6181 Return type: |String|
6182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006183
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006184json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006185 This parses a JSON formatted string and returns the equivalent
6186 in Vim values. See |json_encode()| for the relation between
6187 JSON and Vim values.
6188 The decoding is permissive:
6189 - A trailing comma in an array and object is ignored, e.g.
6190 "[1, 2, ]" is the same as "[1, 2]".
6191 - Integer keys are accepted in objects, e.g. {1:2} is the
6192 same as {"1":2}.
6193 - More floating point numbers are recognized, e.g. "1." for
6194 "1.0", or "001.2" for "1.2". Special floating point values
6195 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6196 are accepted.
6197 - Leading zeroes in integer numbers are ignored, e.g. "012"
6198 for "12" or "-012" for "-12".
6199 - Capitalization is ignored in literal names null, true or
6200 false, e.g. "NULL" for "null", "True" for "true".
6201 - Control characters U+0000 through U+001F which are not
6202 escaped in strings are accepted, e.g. " " (tab
6203 character in string) for "\t".
6204 - An empty JSON expression or made of only spaces is accepted
6205 and results in v:none.
6206 - Backslash in an invalid 2-character sequence escape is
6207 ignored, e.g. "\a" is decoded as "a".
6208 - A correct surrogate pair in JSON strings should normally be
6209 a 12 character sequence such as "\uD834\uDD1E", but
6210 json_decode() silently accepts truncated surrogate pairs
6211 such as "\uD834" or "\uD834\u"
6212 *E938*
6213 A duplicate key in an object, valid in rfc7159, is not
6214 accepted by json_decode() as the result must be a valid Vim
6215 type, e.g. this fails: {"a":"b", "a":"c"}
6216
6217 Can also be used as a |method|: >
6218 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006219<
6220 Return type: any, depending on {varname}
6221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006222
6223json_encode({expr}) *json_encode()*
6224 Encode {expr} as JSON and return this as a string.
6225 The encoding is specified in:
6226 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006227 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006228 |Number| decimal number
6229 |Float| floating point number
6230 Float nan "NaN"
6231 Float inf "Infinity"
6232 Float -inf "-Infinity"
6233 |String| in double quotes (possibly null)
6234 |Funcref| not possible, error
6235 |List| as an array (possibly null); when
6236 used recursively: []
6237 |Dict| as an object (possibly null); when
6238 used recursively: {}
6239 |Blob| as an array of the individual bytes
6240 v:false "false"
6241 v:true "true"
6242 v:none "null"
6243 v:null "null"
6244 Note that NaN and Infinity are passed on as values. This is
6245 missing in the JSON standard, but several implementations do
6246 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006247 If a string contains an illegal character then the replacement
6248 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006249
6250 Can also be used as a |method|: >
6251 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006252<
6253 Return type: |String|
6254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006255
6256keys({dict}) *keys()*
6257 Return a |List| with all the keys of {dict}. The |List| is in
6258 arbitrary order. Also see |items()| and |values()|.
6259
6260 Can also be used as a |method|: >
6261 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006262<
6263 Return type: list<string>
6264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265
zeertzjqcdc83932022-09-12 13:38:41 +01006266keytrans({string}) *keytrans()*
6267 Turn the internal byte representation of keys into a form that
6268 can be used for |:map|. E.g. >
6269 :let xx = "\<C-Home>"
6270 :echo keytrans(xx)
6271< <C-Home>
6272
6273 Can also be used as a |method|: >
6274 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006275<
6276 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006277
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006278
6279len({expr}) *len()* *E701*
6280 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006281 When {expr} is a String or a Number the length in bytes is
6282 used, as with |strlen()|.
6283 When {expr} is a |List| the number of items in the |List| is
6284 returned.
6285 When {expr} is a |Blob| the number of bytes is returned.
6286 When {expr} is a |Dictionary| the number of entries in the
6287 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006288 When {expr} is an |Object|, invokes the len() method in the
6289 object (if present) to get the length (|object-len()|).
6290 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006291
6292 Can also be used as a |method|: >
6293 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006294<
6295 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006296
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006297
6298 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006299libcall({libname}, {funcname}, {argument})
6300 Call function {funcname} in the run-time library {libname}
6301 with single argument {argument}.
6302 This is useful to call functions in a library that you
6303 especially made to be used with Vim. Since only one argument
6304 is possible, calling standard library functions is rather
6305 limited.
6306 The result is the String returned by the function. If the
6307 function returns NULL, this will appear as an empty string ""
6308 to Vim.
6309 If the function returns a number, use libcallnr()!
6310 If {argument} is a number, it is passed to the function as an
6311 int; if {argument} is a string, it is passed as a
6312 null-terminated string.
6313 This function will fail in |restricted-mode|.
6314
6315 libcall() allows you to write your own 'plug-in' extensions to
6316 Vim without having to recompile the program. It is NOT a
6317 means to call system functions! If you try to do so Vim will
6318 very probably crash.
6319
6320 For Win32, the functions you write must be placed in a DLL
6321 and use the normal C calling convention (NOT Pascal which is
6322 used in Windows System DLLs). The function must take exactly
6323 one parameter, either a character pointer or a long integer,
6324 and must return a character pointer or NULL. The character
6325 pointer returned must point to memory that will remain valid
6326 after the function has returned (e.g. in static data in the
6327 DLL). If it points to allocated memory, that memory will
6328 leak away. Using a static buffer in the function should work,
6329 it's then freed when the DLL is unloaded.
6330
6331 WARNING: If the function returns a non-valid pointer, Vim may
6332 crash! This also happens if the function returns a number,
6333 because Vim thinks it's a pointer.
6334 For Win32 systems, {libname} should be the filename of the DLL
6335 without the ".DLL" suffix. A full path is only required if
6336 the DLL is not in the usual places.
6337 For Unix: When compiling your own plugins, remember that the
6338 object code must be compiled as position-independent ('PIC').
6339 {only in Win32 and some Unix versions, when the |+libcall|
6340 feature is present}
6341 Examples: >
6342 :echo libcall("libc.so", "getenv", "HOME")
6343
6344< Can also be used as a |method|, the base is passed as the
6345 third argument: >
6346 GetValue()->libcall("libc.so", "getenv")
6347<
6348 *libcallnr()*
6349libcallnr({libname}, {funcname}, {argument})
6350 Just like |libcall()|, but used for a function that returns an
6351 int instead of a string.
6352 {only in Win32 on some Unix versions, when the |+libcall|
6353 feature is present}
6354 Examples: >
6355 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6356 :call libcallnr("libc.so", "printf", "Hello World!\n")
6357 :call libcallnr("libc.so", "sleep", 10)
6358<
6359 Can also be used as a |method|, the base is passed as the
6360 third argument: >
6361 GetValue()->libcallnr("libc.so", "printf")
6362<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006363 Return type: |String|
6364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006365
6366line({expr} [, {winid}]) *line()*
6367 The result is a Number, which is the line number of the file
6368 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006369 See |getpos()| for accepted positions.
6370
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006371 To get the column number use |col()|. To get both use
6372 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006374 With the optional {winid} argument the values are obtained for
6375 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006376
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006377 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006378
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006379 Examples: >
6380 line(".") line number of the cursor
6381 line(".", winid) idem, in window "winid"
6382 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006383 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006384<
6385 To jump to the last known position when opening a file see
6386 |last-position-jump|.
6387
6388 Can also be used as a |method|: >
6389 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006390<
6391 Return type: |Number|
6392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006393
6394line2byte({lnum}) *line2byte()*
6395 Return the byte count from the start of the buffer for line
6396 {lnum}. This includes the end-of-line character, depending on
6397 the 'fileformat' option for the current buffer. The first
6398 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6399 This can also be used to get the byte count for the line just
6400 below the last line: >
6401 line2byte(line("$") + 1)
6402< This is the buffer size plus one. If 'fileencoding' is empty
6403 it is the file size plus one. {lnum} is used like with
6404 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6405 feature has been disabled at compile time, -1 is returned.
6406 Also see |byte2line()|, |go| and |:goto|.
6407
6408 Can also be used as a |method|: >
6409 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006410<
6411 Return type: |Number|
6412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006413
6414lispindent({lnum}) *lispindent()*
6415 Get the amount of indent for line {lnum} according the lisp
6416 indenting rules, as with 'lisp'.
6417 The indent is counted in spaces, the value of 'tabstop' is
6418 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006419 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006420 error is given.
6421
6422 Can also be used as a |method|: >
6423 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006424<
6425 Return type: |Number|
6426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427
6428list2blob({list}) *list2blob()*
6429 Return a Blob concatenating all the number values in {list}.
6430 Examples: >
6431 list2blob([1, 2, 3, 4]) returns 0z01020304
6432 list2blob([]) returns 0z
6433< Returns an empty Blob on error. If one of the numbers is
6434 negative or more than 255 error *E1239* is given.
6435
6436 |blob2list()| does the opposite.
6437
6438 Can also be used as a |method|: >
6439 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006440<
6441 Return type: |Blob|
6442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006443
6444list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006445 Convert each number in {list} to a character string and
6446 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006447 list2str([32]) returns " "
6448 list2str([65, 66, 67]) returns "ABC"
6449< The same can be done (slowly) with: >
6450 join(map(list, {nr, val -> nr2char(val)}), '')
6451< |str2list()| does the opposite.
6452
6453 When {utf8} is omitted or zero, the current 'encoding' is used.
6454 When {utf8} is TRUE, always return UTF-8 characters.
6455 With UTF-8 composing characters work as expected: >
6456 list2str([97, 769]) returns "á"
6457<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006458 Returns an empty string on error.
6459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006460 Can also be used as a |method|: >
6461 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006462<
6463 Return type: |String|
6464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006465
6466listener_add({callback} [, {buf}]) *listener_add()*
6467 Add a callback function that will be invoked when changes have
6468 been made to buffer {buf}.
6469 {buf} refers to a buffer name or number. For the accepted
6470 values, see |bufname()|. When {buf} is omitted the current
6471 buffer is used.
6472 Returns a unique ID that can be passed to |listener_remove()|.
6473
6474 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006475 bufnr the buffer that was changed
6476 start first changed line number
6477 end first line number below the change
6478 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006479 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006480 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481
6482 Example: >
6483 func Listener(bufnr, start, end, added, changes)
6484 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6485 endfunc
6486 call listener_add('Listener', bufnr)
6487
Bram Moolenaar944697a2022-02-20 19:48:20 +00006488< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006489 dictionary with these entries:
6490 lnum the first line number of the change
6491 end the first line below the change
6492 added number of lines added; negative if lines were
6493 deleted
6494 col first column in "lnum" that was affected by
6495 the change; one if unknown or the whole line
6496 was affected; this is a byte index, first
6497 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006498 When lines are inserted (not when a line is split, e.g. by
6499 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006500 lnum line above which the new line is added
6501 end equal to "lnum"
6502 added number of lines inserted
6503 col 1
6504 When lines are deleted the values are:
6505 lnum the first deleted line
6506 end the line below the first deleted line, before
6507 the deletion was done
6508 added negative, number of lines deleted
6509 col 1
6510 When lines are changed:
6511 lnum the first changed line
6512 end the line below the last changed line
6513 added 0
6514 col first column with a change or 1
6515
6516 The entries are in the order the changes were made, thus the
6517 most recent change is at the end. The line numbers are valid
6518 when the callback is invoked, but later changes may make them
6519 invalid, thus keeping a copy for later might not work.
6520
6521 The {callback} is invoked just before the screen is updated,
6522 when |listener_flush()| is called or when a change is being
6523 made that changes the line count in a way it causes a line
6524 number in the list of changes to become invalid.
6525
6526 The {callback} is invoked with the text locked, see
6527 |textlock|. If you do need to make changes to the buffer, use
6528 a timer to do this later |timer_start()|.
6529
6530 The {callback} is not invoked when the buffer is first loaded.
6531 Use the |BufReadPost| autocmd event to handle the initial text
6532 of a buffer.
6533 The {callback} is also not invoked when the buffer is
6534 unloaded, use the |BufUnload| autocmd event for that.
6535
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006536 Returns zero if {callback} or {buf} is invalid.
6537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006538 Can also be used as a |method|, the base is passed as the
6539 second argument: >
6540 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006541<
6542 Return type: |Number|
6543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006544
6545listener_flush([{buf}]) *listener_flush()*
6546 Invoke listener callbacks for buffer {buf}. If there are no
6547 pending changes then no callbacks are invoked.
6548
6549 {buf} refers to a buffer name or number. For the accepted
6550 values, see |bufname()|. When {buf} is omitted the current
6551 buffer is used.
6552
6553 Can also be used as a |method|: >
6554 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006555<
6556 Return type: |Number|
6557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006558
6559listener_remove({id}) *listener_remove()*
6560 Remove a listener previously added with listener_add().
6561 Returns FALSE when {id} could not be found, TRUE when {id} was
6562 removed.
6563
6564 Can also be used as a |method|: >
6565 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006566<
6567 Return type: |Number|
6568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006569
6570localtime() *localtime()*
6571 Return the current time, measured as seconds since 1st Jan
6572 1970. See also |strftime()|, |strptime()| and |getftime()|.
6573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006574 Return type: |Number|
6575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006576
6577log({expr}) *log()*
6578 Return the natural logarithm (base e) of {expr} as a |Float|.
6579 {expr} must evaluate to a |Float| or a |Number| in the range
6580 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006581 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006582 Examples: >
6583 :echo log(10)
6584< 2.302585 >
6585 :echo log(exp(5))
6586< 5.0
6587
6588 Can also be used as a |method|: >
6589 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006590<
6591 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006592
6593
6594log10({expr}) *log10()*
6595 Return the logarithm of Float {expr} to base 10 as a |Float|.
6596 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006597 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006598 Examples: >
6599 :echo log10(1000)
6600< 3.0 >
6601 :echo log10(0.01)
6602< -2.0
6603
6604 Can also be used as a |method|: >
6605 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006606<
6607 Return type: |Float|
6608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006609
6610luaeval({expr} [, {expr}]) *luaeval()*
6611 Evaluate Lua expression {expr} and return its result converted
6612 to Vim data structures. Second {expr} may hold additional
6613 argument accessible as _A inside first {expr}.
6614 Strings are returned as they are.
6615 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006616 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006617 Dictionaries and lists obtained by vim.eval() are returned
6618 as-is.
6619 Other objects are returned as zero without any errors.
6620 See |lua-luaeval| for more details.
6621 Note that in a `:def` function local variables are not visible
6622 to {expr}.
6623
6624 Can also be used as a |method|: >
6625 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006626<
6627 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006629 {only available when compiled with the |+lua| feature}
6630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006631
6632map({expr1}, {expr2}) *map()*
6633 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006634 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006635 item in {expr1} with the result of evaluating {expr2}.
6636 For a |Blob| each byte is replaced.
6637 For a |String|, each character, including composing
6638 characters, is replaced.
6639 If the item type changes you may want to use |mapnew()| to
6640 create a new List or Dictionary. This is required when using
6641 Vim9 script.
6642
6643 {expr2} must be a |String| or |Funcref|.
6644
6645 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6646 of the current item. For a |Dictionary| |v:key| has the key
6647 of the current item and for a |List| |v:key| has the index of
6648 the current item. For a |Blob| |v:key| has the index of the
6649 current byte. For a |String| |v:key| has the index of the
6650 current character.
6651 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006652 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006653< This puts "> " before and " <" after each item in "mylist".
6654
6655 Note that {expr2} is the result of an expression and is then
6656 used as an expression again. Often it is good to use a
6657 |literal-string| to avoid having to double backslashes. You
6658 still have to double ' quotes
6659
6660 If {expr2} is a |Funcref| it is called with two arguments:
6661 1. The key or the index of the current item.
6662 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006663 With a legacy script lambda you don't get an error if it only
6664 accepts one argument, but with a Vim9 lambda you get "E1106:
6665 One argument too many", the number of arguments must match.
6666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006667 The function must return the new value of the item. Example
6668 that changes each value by "key-value": >
6669 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006670 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006671 endfunc
6672 call map(myDict, function('KeyValue'))
6673< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006674 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006675< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006676 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006677< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006678 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006679<
6680 The operation is done in-place for a |List| and |Dictionary|.
6681 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006682 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683
6684< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6685 or a new |Blob| or |String|.
6686 When an error is encountered while evaluating {expr2} no
6687 further items in {expr1} are processed.
6688 When {expr2} is a Funcref errors inside a function are ignored,
6689 unless it was defined with the "abort" flag.
6690
6691 Can also be used as a |method|: >
6692 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006693<
6694 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6695 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006696
6697
6698maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6699 When {dict} is omitted or zero: Return the rhs of mapping
6700 {name} in mode {mode}. The returned String has special
6701 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006702 listing. When {dict} is TRUE a dictionary is returned, see
6703 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006704
6705 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006706 returned if {dict} is FALSE, otherwise returns an empty Dict.
6707 When the mapping for {name} is empty, then "<Nop>" is
6708 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006709
6710 The {name} can have special key names, like in the ":map"
6711 command.
6712
6713 {mode} can be one of these strings:
6714 "n" Normal
6715 "v" Visual (including Select)
6716 "o" Operator-pending
6717 "i" Insert
6718 "c" Cmd-line
6719 "s" Select
6720 "x" Visual
6721 "l" langmap |language-mapping|
6722 "t" Terminal-Job
6723 "" Normal, Visual and Operator-pending
6724 When {mode} is omitted, the modes for "" are used.
6725
6726 When {abbr} is there and it is |TRUE| use abbreviations
6727 instead of mappings.
6728
6729 When {dict} is there and it is |TRUE| return a dictionary
6730 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006731 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006732 "lhs" The {lhs} of the mapping as it would be typed
6733 "lhsraw" The {lhs} of the mapping as raw bytes
6734 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6735 form, only present when it differs from "lhsraw"
6736 "rhs" The {rhs} of the mapping as typed.
6737 "silent" 1 for a |:map-silent| mapping, else 0.
6738 "noremap" 1 if the {rhs} of the mapping is not remappable.
6739 "script" 1 if mapping was defined with <script>.
6740 "expr" 1 for an expression mapping (|:map-<expr>|).
6741 "buffer" 1 for a buffer local mapping (|:map-local|).
6742 "mode" Modes for which the mapping is defined. In
6743 addition to the modes mentioned above, these
6744 characters will be used:
6745 " " Normal, Visual and Operator-pending
6746 "!" Insert and Commandline mode
6747 (|mapmode-ic|)
6748 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006749 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006750 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006751 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006752 "lnum" The line number in "sid", zero if unknown.
6753 "nowait" Do not wait for other, longer mappings.
6754 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006755 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006756 "mode_bits" Vim's internal binary representation of "mode".
6757 |mapset()| ignores this; only "mode" is used.
6758 See |maplist()| for usage examples. The values
6759 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006760
6761 The dictionary can be used to restore a mapping with
6762 |mapset()|.
6763
6764 The mappings local to the current buffer are checked first,
6765 then the global mappings.
6766 This function can be used to map a key even when it's already
6767 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006768 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006769
6770< Can also be used as a |method|: >
6771 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006772<
6773 Return type: |String| or dict<any> depending on {dict}
6774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006775
6776mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6777 Check if there is a mapping that matches with {name} in mode
6778 {mode}. See |maparg()| for {mode} and special names in
6779 {name}.
6780 When {abbr} is there and it is |TRUE| use abbreviations
6781 instead of mappings.
6782 A match happens with a mapping that starts with {name} and
6783 with a mapping which is equal to the start of {name}.
6784
6785 matches mapping "a" "ab" "abc" ~
6786 mapcheck("a") yes yes yes
6787 mapcheck("abc") yes yes yes
6788 mapcheck("ax") yes no no
6789 mapcheck("b") no no no
6790
6791 The difference with maparg() is that mapcheck() finds a
6792 mapping that matches with {name}, while maparg() only finds a
6793 mapping for {name} exactly.
6794 When there is no mapping that starts with {name}, an empty
6795 String is returned. If there is one, the RHS of that mapping
6796 is returned. If there are several mappings that start with
6797 {name}, the RHS of one of them is returned. This will be
6798 "<Nop>" if the RHS is empty.
6799 The mappings local to the current buffer are checked first,
6800 then the global mappings.
6801 This function can be used to check if a mapping can be added
6802 without being ambiguous. Example: >
6803 :if mapcheck("_vv") == ""
6804 : map _vv :set guifont=7x13<CR>
6805 :endif
6806< This avoids adding the "_vv" mapping when there already is a
6807 mapping for "_v" or for "_vvv".
6808
6809 Can also be used as a |method|: >
6810 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006811<
6812 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006813
6814
Ernie Rael09661202022-04-25 14:40:44 +01006815maplist([{abbr}]) *maplist()*
6816 Returns a |List| of all mappings. Each List item is a |Dict|,
6817 the same as what is returned by |maparg()|, see
6818 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6819 abbreviations instead of mappings.
6820
6821 Example to show all mappings with 'MultiMatch' in rhs: >
6822 vim9script
6823 echo maplist()->filter(
6824 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006825< It can be tricky to find mappings for particular |:map-modes|.
6826 |mapping-dict|'s "mode_bits" can simplify this. For example,
6827 the mode_bits for Normal, Insert or Command-line modes are
6828 0x19. To find all the mappings available in those modes you
6829 can do: >
6830 vim9script
6831 var saved_maps = []
6832 for m in maplist()
6833 if and(m.mode_bits, 0x19) != 0
6834 saved_maps->add(m)
6835 endif
6836 endfor
6837 echo saved_maps->mapnew((_, m) => m.lhs)
6838< The values of the mode_bits are defined in Vim's src/vim.h
6839 file and they can be discovered at runtime using
6840 |:map-commands| and "maplist()". Example: >
6841 vim9script
6842 omap xyzzy <Nop>
6843 var op_bit = maplist()->filter(
6844 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6845 ounmap xyzzy
6846 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006847<
6848 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006849
6850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006851mapnew({expr1}, {expr2}) *mapnew()*
6852 Like |map()| but instead of replacing items in {expr1} a new
6853 List or Dictionary is created and returned. {expr1} remains
6854 unchanged. Items can still be changed by {expr2}, if you
6855 don't want that use |deepcopy()| first.
6856
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006857 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6858 depending on {expr1}
6859
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006860
6861mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006862mapset({dict})
6863 Restore a mapping from a dictionary, possibly returned by
6864 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6865 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006866 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006867 feature allows copying mappings from one buffer to another.
6868 The dict.mode value may restore a single mapping that covers
6869 more than one mode, like with mode values of '!', ' ', 'nox',
6870 or 'v'. *E1276*
6871
6872 In the first form, {mode} and {abbr} should be the same as
6873 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006874 {mode} is used to define the mode in which the mapping is set,
6875 not the "mode" entry in {dict}.
6876 Example for saving and restoring a mapping: >
6877 let save_map = maparg('K', 'n', 0, 1)
6878 nnoremap K somethingelse
6879 ...
6880 call mapset('n', 0, save_map)
6881< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006882 e.g. with `:map!`, you need to save/restore the mapping for
6883 all of them, when they might differ.
6884
6885 In the second form, with {dict} as the only argument, mode
6886 and abbr are taken from the dict.
6887 Example: >
6888 vim9script
6889 var save_maps = maplist()->filter(
6890 (_, m) => m.lhs == 'K')
6891 nnoremap K somethingelse
6892 cnoremap K somethingelse2
6893 # ...
6894 unmap K
6895 for d in save_maps
6896 mapset(d)
6897 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006898<
6899 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006900
6901
6902match({expr}, {pat} [, {start} [, {count}]]) *match()*
6903 When {expr} is a |List| then this returns the index of the
6904 first item where {pat} matches. Each item is used as a
6905 String, |Lists| and |Dictionaries| are used as echoed.
6906
6907 Otherwise, {expr} is used as a String. The result is a
6908 Number, which gives the index (byte offset) in {expr} where
6909 {pat} matches.
6910
6911 A match at the first character or |List| item returns zero.
6912 If there is no match -1 is returned.
6913
6914 For getting submatches see |matchlist()|.
6915 Example: >
6916 :echo match("testing", "ing") " results in 4
6917 :echo match([1, 'x'], '\a') " results in 1
6918< See |string-match| for how {pat} is used.
6919 *strpbrk()*
6920 Vim doesn't have a strpbrk() function. But you can do: >
6921 :let sepidx = match(line, '[.,;: \t]')
6922< *strcasestr()*
6923 Vim doesn't have a strcasestr() function. But you can add
6924 "\c" to the pattern to ignore case: >
6925 :let idx = match(haystack, '\cneedle')
6926<
6927 If {start} is given, the search starts from byte index
6928 {start} in a String or item {start} in a |List|.
6929 The result, however, is still the index counted from the
6930 first character/item. Example: >
6931 :echo match("testing", "ing", 2)
6932< result is again "4". >
6933 :echo match("testing", "ing", 4)
6934< result is again "4". >
6935 :echo match("testing", "t", 2)
6936< result is "3".
6937 For a String, if {start} > 0 then it is like the string starts
6938 {start} bytes later, thus "^" will match at {start}. Except
6939 when {count} is given, then it's like matches before the
6940 {start} byte are ignored (this is a bit complicated to keep it
6941 backwards compatible).
6942 For a String, if {start} < 0, it will be set to 0. For a list
6943 the index is counted from the end.
6944 If {start} is out of range ({start} > strlen({expr}) for a
6945 String or {start} > len({expr}) for a |List|) -1 is returned.
6946
6947 When {count} is given use the {count}'th match. When a match
6948 is found in a String the search for the next one starts one
6949 character further. Thus this example results in 1: >
6950 echo match("testing", "..", 0, 2)
6951< In a |List| the search continues in the next item.
6952 Note that when {count} is added the way {start} works changes,
6953 see above.
6954
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01006955 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006956 See |pattern| for the patterns that are accepted.
6957 The 'ignorecase' option is used to set the ignore-caseness of
6958 the pattern. 'smartcase' is NOT used. The matching is always
6959 done like 'magic' is set and 'cpoptions' is empty.
6960 Note that a match at the start is preferred, thus when the
6961 pattern is using "*" (any number of matches) it tends to find
6962 zero matches at the start instead of a number of matches
6963 further down in the text.
6964
6965 Can also be used as a |method|: >
6966 GetText()->match('word')
6967 GetList()->match('word')
6968<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006969 Return type: |Number|
6970
6971
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006972 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006973matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
6974 Defines a pattern to be highlighted in the current window (a
6975 "match"). It will be highlighted with {group}. Returns an
6976 identification number (ID), which can be used to delete the
6977 match using |matchdelete()|. The ID is bound to the window.
6978 Matching is case sensitive and magic, unless case sensitivity
6979 or magicness are explicitly overridden in {pattern}. The
6980 'magic', 'smartcase' and 'ignorecase' options are not used.
6981 The "Conceal" value is special, it causes the match to be
6982 concealed.
6983
6984 The optional {priority} argument assigns a priority to the
6985 match. A match with a high priority will have its
6986 highlighting overrule that of a match with a lower priority.
6987 A priority is specified as an integer (negative numbers are no
6988 exception). If the {priority} argument is not specified, the
6989 default priority is 10. The priority of 'hlsearch' is zero,
6990 hence all matches with a priority greater than zero will
6991 overrule it. Syntax highlighting (see 'syntax') is a separate
6992 mechanism, and regardless of the chosen priority a match will
6993 always overrule syntax highlighting.
6994
6995 The optional {id} argument allows the request for a specific
6996 match ID. If a specified ID is already taken, an error
6997 message will appear and the match will not be added. An ID
6998 is specified as a positive integer (zero excluded). IDs 1, 2
6999 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007000 respectively. 3 is reserved for use by the |matchparen|
7001 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007002 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007003 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007004
7005 The optional {dict} argument allows for further custom
7006 values. Currently this is used to specify a match specific
7007 conceal character that will be shown for |hl-Conceal|
7008 highlighted matches. The dict can have the following members:
7009
7010 conceal Special character to show instead of the
7011 match (only for |hl-Conceal| highlighted
7012 matches, see |:syn-cchar|)
7013 window Instead of the current window use the
7014 window with this number or window ID.
7015
7016 The number of matches is not limited, as it is the case with
7017 the |:match| commands.
7018
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007019 Returns -1 on error.
7020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007021 Example: >
7022 :highlight MyGroup ctermbg=green guibg=green
7023 :let m = matchadd("MyGroup", "TODO")
7024< Deletion of the pattern: >
7025 :call matchdelete(m)
7026
7027< A list of matches defined by |matchadd()| and |:match| are
7028 available from |getmatches()|. All matches can be deleted in
7029 one operation by |clearmatches()|.
7030
7031 Can also be used as a |method|: >
7032 GetGroup()->matchadd('TODO')
7033<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007034 Return type: |Number|
7035
7036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007037 *matchaddpos()*
7038matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7039 Same as |matchadd()|, but requires a list of positions {pos}
7040 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007041 because it does not handle regular expressions and it sets
7042 buffer line boundaries to redraw screen. It is supposed to be
7043 used when fast match additions and deletions are required, for
7044 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007045
7046 {pos} is a list of positions. Each position can be one of
7047 these:
7048 - A number. This whole line will be highlighted. The first
7049 line has number 1.
7050 - A list with one number, e.g., [23]. The whole line with this
7051 number will be highlighted.
7052 - A list with two numbers, e.g., [23, 11]. The first number is
7053 the line number, the second one is the column number (first
7054 column is 1, the value must correspond to the byte index as
7055 |col()| would return). The character at this position will
7056 be highlighted.
7057 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7058 the third number gives the length of the highlight in bytes.
7059
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007060 Returns -1 on error.
7061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007062 Example: >
7063 :highlight MyGroup ctermbg=green guibg=green
7064 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7065< Deletion of the pattern: >
7066 :call matchdelete(m)
7067
7068< Matches added by |matchaddpos()| are returned by
7069 |getmatches()|.
7070
7071 Can also be used as a |method|: >
7072 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007073<
7074 Return type: |Number|
7075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007076
7077matcharg({nr}) *matcharg()*
7078 Selects the {nr} match item, as set with a |:match|,
7079 |:2match| or |:3match| command.
7080 Return a |List| with two elements:
7081 The name of the highlight group used
7082 The pattern used.
7083 When {nr} is not 1, 2 or 3 returns an empty |List|.
7084 When there is no match item set returns ['', ''].
7085 This is useful to save and restore a |:match|.
7086 Highlighting matches using the |:match| commands are limited
7087 to three matches. |matchadd()| does not have this limitation.
7088
7089 Can also be used as a |method|: >
7090 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007091<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007092 Return type: list<string>
7093
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007094 *matchbufline()*
7095matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7096 Returns the |List| of matches in lines from {lnum} to {end} in
7097 buffer {buf} where {pat} matches.
7098
7099 {lnum} and {end} can either be a line number or the string "$"
7100 to refer to the last line in {buf}.
7101
7102 The {dict} argument supports following items:
7103 submatches include submatch information (|/\(|)
7104
7105 For each match, a |Dict| with the following items is returned:
7106 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007107 lnum line number where there is a match
7108 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007109 Note that there can be multiple matches in a single line.
7110
7111 This function works only for loaded buffers. First call
7112 |bufload()| if needed.
7113
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007114 See |match-pattern| for information about the effect of some
7115 option settings on the pattern.
7116
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007117 When {buf} is not a valid buffer, the buffer is not loaded or
7118 {lnum} or {end} is not valid then an error is given and an
7119 empty |List| is returned.
7120
7121 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007122 " Assuming line 3 in buffer 5 contains "a"
7123 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7124 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7125 " Assuming line 4 in buffer 10 contains "tik tok"
7126 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7127 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007128<
7129 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007130 "\1", "\2", etc. are also returned. Example: >
7131 " Assuming line 2 in buffer 2 contains "acd"
7132 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007133 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007134 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007135< The "submatches" List always contains 9 items. If a submatch
7136 is not found, then an empty string is returned for that
7137 submatch.
7138
7139 Can also be used as a |method|: >
7140 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007141<
7142 Return type: list<dict<any>> or list<any>
7143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007144
h-east624bb832024-11-09 18:37:32 +01007145matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007146 Deletes a match with ID {id} previously defined by |matchadd()|
7147 or one of the |:match| commands. Returns 0 if successful,
7148 otherwise -1. See example for |matchadd()|. All matches can
7149 be deleted in one operation by |clearmatches()|.
7150 If {win} is specified, use the window with this number or
7151 window ID instead of the current window.
7152
7153 Can also be used as a |method|: >
7154 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007155<
7156 Return type: |Number|
7157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007158
7159matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7160 Same as |match()|, but return the index of first character
7161 after the match. Example: >
7162 :echo matchend("testing", "ing")
7163< results in "7".
7164 *strspn()* *strcspn()*
7165 Vim doesn't have a strspn() or strcspn() function, but you can
7166 do it with matchend(): >
7167 :let span = matchend(line, '[a-zA-Z]')
7168 :let span = matchend(line, '[^a-zA-Z]')
7169< Except that -1 is returned when there are no matches.
7170
7171 The {start}, if given, has the same meaning as for |match()|. >
7172 :echo matchend("testing", "ing", 2)
7173< results in "7". >
7174 :echo matchend("testing", "ing", 5)
7175< result is "-1".
7176 When {expr} is a |List| the result is equal to |match()|.
7177
7178 Can also be used as a |method|: >
7179 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007180<
7181 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007182
7183
7184matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7185 If {list} is a list of strings, then returns a |List| with all
7186 the strings in {list} that fuzzy match {str}. The strings in
7187 the returned list are sorted based on the matching score.
7188
7189 The optional {dict} argument always supports the following
7190 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007191 matchseq When this item is present return only matches
7192 that contain the characters in {str} in the
7193 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007194 limit Maximum number of matches in {list} to be
7195 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007196
7197 If {list} is a list of dictionaries, then the optional {dict}
7198 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007199 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007200 {str}. The value of this item should be a
7201 string.
7202 text_cb |Funcref| that will be called for every item
7203 in {list} to get the text for fuzzy matching.
7204 This should accept a dictionary item as the
7205 argument and return the text for that item to
7206 use for fuzzy matching.
7207
7208 {str} is treated as a literal string and regular expression
7209 matching is NOT supported. The maximum supported {str} length
7210 is 256.
7211
7212 When {str} has multiple words each separated by white space,
7213 then the list of strings that have all the words is returned.
7214
7215 If there are no matching strings or there is an error, then an
7216 empty list is returned. If length of {str} is greater than
7217 256, then returns an empty list.
7218
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007219 When {limit} is given, matchfuzzy() will find up to this
7220 number of matches in {list} and return them in sorted order.
7221
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007222 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007223 matching strings.
7224
7225 Example: >
7226 :echo matchfuzzy(["clay", "crow"], "cay")
7227< results in ["clay"]. >
7228 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7229< results in a list of buffer names fuzzy matching "ndl". >
7230 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7231< results in a list of buffer information dicts with buffer
7232 names fuzzy matching "ndl". >
7233 :echo getbufinfo()->matchfuzzy("spl",
7234 \ {'text_cb' : {v -> v.name}})
7235< results in a list of buffer information dicts with buffer
7236 names fuzzy matching "spl". >
7237 :echo v:oldfiles->matchfuzzy("test")
7238< results in a list of file names fuzzy matching "test". >
7239 :let l = readfile("buffer.c")->matchfuzzy("str")
7240< results in a list of lines in "buffer.c" fuzzy matching "str". >
7241 :echo ['one two', 'two one']->matchfuzzy('two one')
7242< results in ['two one', 'one two']. >
7243 :echo ['one two', 'two one']->matchfuzzy('two one',
7244 \ {'matchseq': 1})
7245< results in ['two one'].
7246
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007247 Return type: list<string> or list<any>
7248
7249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007250matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7251 Same as |matchfuzzy()|, but returns the list of matched
7252 strings, the list of character positions where characters
7253 in {str} matches and a list of matching scores. You can
7254 use |byteidx()| to convert a character position to a byte
7255 position.
7256
7257 If {str} matches multiple times in a string, then only the
7258 positions for the best match is returned.
7259
7260 If there are no matching strings or there is an error, then a
7261 list with three empty list items is returned.
7262
7263 Example: >
7264 :echo matchfuzzypos(['testing'], 'tsg')
7265< results in [['testing'], [[0, 2, 6]], [99]] >
7266 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7267< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7268 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7269< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7270
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007271 Return type: list<list<any>>
7272
7273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007274matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7275 Same as |match()|, but return a |List|. The first item in the
7276 list is the matched string, same as what matchstr() would
7277 return. Following items are submatches, like "\1", "\2", etc.
7278 in |:substitute|. When an optional submatch didn't match an
7279 empty string is used. Example: >
7280 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7281< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7282 When there is no match an empty list is returned.
7283
7284 You can pass in a List, but that is not very useful.
7285
7286 Can also be used as a |method|: >
7287 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007288<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007289 Return type: list<string> or list<any>
7290
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007291 *matchstrlist()*
7292matchstrlist({list}, {pat} [, {dict}])
7293 Returns the |List| of matches in {list} where {pat} matches.
7294 {list} is a |List| of strings. {pat} is matched against each
7295 string in {list}.
7296
7297 The {dict} argument supports following items:
7298 submatches include submatch information (|/\(|)
7299
7300 For each match, a |Dict| with the following items is returned:
7301 byteidx starting byte index of the match.
7302 idx index in {list} of the match.
7303 text matched string
7304 submatches a List of submatches. Present only if
7305 "submatches" is set to v:true in {dict}.
7306
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007307 See |match-pattern| for information about the effect of some
7308 option settings on the pattern.
7309
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007310 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007311 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7312 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7313 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7314 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007315<
7316 If "submatches" is present and is v:true, then submatches like
7317 "\1", "\2", etc. are also returned. Example: >
7318 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7319 \ #{submatches: v:true})
7320 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7321< The "submatches" List always contains 9 items. If a submatch
7322 is not found, then an empty string is returned for that
7323 submatch.
7324
7325 Can also be used as a |method|: >
7326 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007327<
7328 Return type: list<dict<any>> or list<any>
7329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007330
7331matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7332 Same as |match()|, but return the matched string. Example: >
7333 :echo matchstr("testing", "ing")
7334< results in "ing".
7335 When there is no match "" is returned.
7336 The {start}, if given, has the same meaning as for |match()|. >
7337 :echo matchstr("testing", "ing", 2)
7338< results in "ing". >
7339 :echo matchstr("testing", "ing", 5)
7340< result is "".
7341 When {expr} is a |List| then the matching item is returned.
7342 The type isn't changed, it's not necessarily a String.
7343
7344 Can also be used as a |method|: >
7345 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007346<
7347 Return type: |String|
7348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007349
7350matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7351 Same as |matchstr()|, but return the matched string, the start
7352 position and the end position of the match. Example: >
7353 :echo matchstrpos("testing", "ing")
7354< results in ["ing", 4, 7].
7355 When there is no match ["", -1, -1] is returned.
7356 The {start}, if given, has the same meaning as for |match()|. >
7357 :echo matchstrpos("testing", "ing", 2)
7358< results in ["ing", 4, 7]. >
7359 :echo matchstrpos("testing", "ing", 5)
7360< result is ["", -1, -1].
7361 When {expr} is a |List| then the matching item, the index
7362 of first item where {pat} matches, the start position and the
7363 end position of the match are returned. >
7364 :echo matchstrpos([1, '__x'], '\a')
7365< result is ["x", 1, 2, 3].
7366 The type isn't changed, it's not necessarily a String.
7367
7368 Can also be used as a |method|: >
7369 GetText()->matchstrpos('word')
7370<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007371 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007372
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007373
7374max({expr}) *max()*
7375 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007376 echo max([apples, pears, oranges])
7377
7378< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7379 it returns the maximum of all values in the Dictionary.
7380 If {expr} is neither a List nor a Dictionary, or one of the
7381 items in {expr} cannot be used as a Number this results in
7382 an error. An empty |List| or |Dictionary| results in zero.
7383
7384 Can also be used as a |method|: >
7385 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007386<
7387 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007388
7389
7390menu_info({name} [, {mode}]) *menu_info()*
7391 Return information about the specified menu {name} in
7392 mode {mode}. The menu name should be specified without the
7393 shortcut character ('&'). If {name} is "", then the top-level
7394 menu names are returned.
7395
7396 {mode} can be one of these strings:
7397 "n" Normal
7398 "v" Visual (including Select)
7399 "o" Operator-pending
7400 "i" Insert
7401 "c" Cmd-line
7402 "s" Select
7403 "x" Visual
7404 "t" Terminal-Job
7405 "" Normal, Visual and Operator-pending
7406 "!" Insert and Cmd-line
7407 When {mode} is omitted, the modes for "" are used.
7408
7409 Returns a |Dictionary| containing the following items:
7410 accel menu item accelerator text |menu-text|
7411 display display name (name without '&')
7412 enabled v:true if this menu item is enabled
7413 Refer to |:menu-enable|
7414 icon name of the icon file (for toolbar)
7415 |toolbar-icon|
7416 iconidx index of a built-in icon
7417 modes modes for which the menu is defined. In
7418 addition to the modes mentioned above, these
7419 characters will be used:
7420 " " Normal, Visual and Operator-pending
7421 name menu item name.
7422 noremenu v:true if the {rhs} of the menu item is not
7423 remappable else v:false.
7424 priority menu order priority |menu-priority|
7425 rhs right-hand-side of the menu item. The returned
7426 string has special characters translated like
7427 in the output of the ":menu" command listing.
7428 When the {rhs} of a menu item is empty, then
7429 "<Nop>" is returned.
7430 script v:true if script-local remapping of {rhs} is
7431 allowed else v:false. See |:menu-script|.
7432 shortcut shortcut key (character after '&' in
7433 the menu name) |menu-shortcut|
7434 silent v:true if the menu item is created
7435 with <silent> argument |:menu-silent|
7436 submenus |List| containing the names of
7437 all the submenus. Present only if the menu
7438 item has submenus.
7439
7440 Returns an empty dictionary if the menu item is not found.
7441
7442 Examples: >
7443 :echo menu_info('Edit.Cut')
7444 :echo menu_info('File.Save', 'n')
7445
7446 " Display the entire menu hierarchy in a buffer
7447 func ShowMenu(name, pfx)
7448 let m = menu_info(a:name)
7449 call append(line('$'), a:pfx .. m.display)
7450 for child in m->get('submenus', [])
7451 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7452 \ a:pfx .. ' ')
7453 endfor
7454 endfunc
7455 new
7456 for topmenu in menu_info('').submenus
7457 call ShowMenu(topmenu, '')
7458 endfor
7459<
7460 Can also be used as a |method|: >
7461 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007462<
7463 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007465min({expr}) *min()*
7466 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007467 echo min([apples, pears, oranges])
7468
7469< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7470 it returns the minimum of all values in the Dictionary.
7471 If {expr} is neither a List nor a Dictionary, or one of the
7472 items in {expr} cannot be used as a Number this results in
7473 an error. An empty |List| or |Dictionary| results in zero.
7474
7475 Can also be used as a |method|: >
7476 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007477<
7478 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007479
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007480
7481mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007482 Create directory {name}.
7483
Bram Moolenaar938ae282023-02-20 20:44:55 +00007484 When {flags} is present it must be a string. An empty string
7485 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007486
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007487 {flags} can contain these character flags:
7488 "p" intermediate directories will be created as necessary
7489 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007490 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007491 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007492 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007493
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007494 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007495 some directories may already exist. Only the first one that
7496 is created and what it contains is scheduled to be deleted.
7497 E.g. when using: >
7498 call mkdir('subdir/tmp/autoload', 'pR')
7499< and "subdir" already exists then "subdir/tmp" will be
7500 scheduled for deletion, like with: >
7501 defer delete('subdir/tmp', 'rf')
7502< Note that if scheduling the defer fails the directory is not
7503 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007504
7505 If {prot} is given it is used to set the protection bits of
7506 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7507 the user, readable for others). Use 0o700 to make it
7508 unreadable for others. This is only used for the last part of
7509 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7510 created with 0o755.
7511 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007512 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007513
7514< This function is not available in the |sandbox|.
7515
7516 There is no error if the directory already exists and the "p"
7517 flag is passed (since patch 8.0.1708). However, without the
7518 "p" option the call will fail.
7519
7520 The function result is a Number, which is TRUE if the call was
7521 successful or FALSE if the directory creation failed or partly
7522 failed.
7523
7524 Not available on all systems. To check use: >
7525 :if exists("*mkdir")
7526
7527< Can also be used as a |method|: >
7528 GetName()->mkdir()
7529<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007530 Return type: |Number|
7531
7532
7533mode([{expr}]) *mode()*
7534 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007535 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007536 a non-empty String (|non-zero-arg|), then the full mode is
7537 returned, otherwise only the first letter is returned.
7538 Also see |state()|.
7539
7540 n Normal
7541 no Operator-pending
7542 nov Operator-pending (forced characterwise |o_v|)
7543 noV Operator-pending (forced linewise |o_V|)
7544 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7545 CTRL-V is one character
7546 niI Normal using |i_CTRL-O| in |Insert-mode|
7547 niR Normal using |i_CTRL-O| in |Replace-mode|
7548 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7549 nt Terminal-Normal (insert goes to Terminal-Job mode)
7550 v Visual by character
7551 vs Visual by character using |v_CTRL-O| in Select mode
7552 V Visual by line
7553 Vs Visual by line using |v_CTRL-O| in Select mode
7554 CTRL-V Visual blockwise
7555 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7556 s Select by character
7557 S Select by line
7558 CTRL-S Select blockwise
7559 i Insert
7560 ic Insert mode completion |compl-generic|
7561 ix Insert mode |i_CTRL-X| completion
7562 R Replace |R|
7563 Rc Replace mode completion |compl-generic|
7564 Rx Replace mode |i_CTRL-X| completion
7565 Rv Virtual Replace |gR|
7566 Rvc Virtual Replace mode completion |compl-generic|
7567 Rvx Virtual Replace mode |i_CTRL-X| completion
7568 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007569 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007570 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007571 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007572 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007573 ce Normal Ex mode |Q|
7574 r Hit-enter prompt
7575 rm The -- more -- prompt
7576 r? A |:confirm| query of some sort
7577 ! Shell or external command is executing
7578 t Terminal-Job mode: keys go to the job
7579
7580 This is useful in the 'statusline' option or when used
7581 with |remote_expr()| In most other places it always returns
7582 "c" or "n".
7583 Note that in the future more modes and more specific modes may
7584 be added. It's better not to compare the whole string but only
7585 the leading character(s).
7586 Also see |visualmode()|.
7587
7588 Can also be used as a |method|: >
7589 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007590<
7591 Return type: |String|
7592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007593
7594mzeval({expr}) *mzeval()*
7595 Evaluate MzScheme expression {expr} and return its result
7596 converted to Vim data structures.
7597 Numbers and strings are returned as they are.
7598 Pairs (including lists and improper lists) and vectors are
7599 returned as Vim |Lists|.
7600 Hash tables are represented as Vim |Dictionary| type with keys
7601 converted to strings.
7602 All other types are converted to string with display function.
7603 Examples: >
7604 :mz (define l (list 1 2 3))
7605 :mz (define h (make-hash)) (hash-set! h "list" l)
7606 :echo mzeval("l")
7607 :echo mzeval("h")
7608<
7609 Note that in a `:def` function local variables are not visible
7610 to {expr}.
7611
7612 Can also be used as a |method|: >
7613 GetExpr()->mzeval()
7614<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007615 Return type: any, depending on {expr}
7616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007617 {only available when compiled with the |+mzscheme| feature}
7618
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007620nextnonblank({lnum}) *nextnonblank()*
7621 Return the line number of the first line at or below {lnum}
7622 that is not blank. Example: >
7623 if getline(nextnonblank(1)) =~ "Java"
7624< When {lnum} is invalid or there is no non-blank line at or
7625 below it, zero is returned.
7626 {lnum} is used like with |getline()|.
7627 See also |prevnonblank()|.
7628
7629 Can also be used as a |method|: >
7630 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007631<
7632 Return type: |Number|
7633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007634
7635nr2char({expr} [, {utf8}]) *nr2char()*
7636 Return a string with a single character, which has the number
7637 value {expr}. Examples: >
7638 nr2char(64) returns "@"
7639 nr2char(32) returns " "
7640< When {utf8} is omitted or zero, the current 'encoding' is used.
7641 Example for "utf-8": >
7642 nr2char(300) returns I with bow character
7643< When {utf8} is TRUE, always return UTF-8 characters.
7644 Note that a NUL character in the file is specified with
7645 nr2char(10), because NULs are represented with newline
7646 characters. nr2char(0) is a real NUL and terminates the
7647 string, thus results in an empty string.
7648 To turn a list of character numbers into a string: >
7649 let list = [65, 66, 67]
7650 let str = join(map(list, {_, val -> nr2char(val)}), '')
7651< Result: "ABC"
7652
7653 Can also be used as a |method|: >
7654 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007655<
7656 Return type: |String|
7657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007658
7659or({expr}, {expr}) *or()*
7660 Bitwise OR on the two arguments. The arguments are converted
7661 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007662 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007663 Example: >
7664 :let bits = or(bits, 0x80)
7665< Can also be used as a |method|: >
7666 :let bits = bits->or(0x80)
7667
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007668< Rationale: The reason this is a function and not using the "|"
7669 character like many languages, is that Vi has always used "|"
7670 to separate commands. In many places it would not be clear if
7671 "|" is an operator or a command separator.
7672
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007673 Return type: |Number|
7674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007675
7676pathshorten({path} [, {len}]) *pathshorten()*
7677 Shorten directory names in the path {path} and return the
7678 result. The tail, the file name, is kept as-is. The other
7679 components in the path are reduced to {len} letters in length.
7680 If {len} is omitted or smaller than 1 then 1 is used (single
7681 letters). Leading '~' and '.' characters are kept. Examples: >
7682 :echo pathshorten('~/.vim/autoload/myfile.vim')
7683< ~/.v/a/myfile.vim ~
7684>
7685 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7686< ~/.vi/au/myfile.vim ~
7687 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007688 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007689
7690 Can also be used as a |method|: >
7691 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007692<
7693 Return type: |String|
7694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007695
7696perleval({expr}) *perleval()*
7697 Evaluate Perl expression {expr} in scalar context and return
7698 its result converted to Vim data structures. If value can't be
7699 converted, it is returned as a string Perl representation.
7700 Note: If you want an array or hash, {expr} must return a
7701 reference to it.
7702 Example: >
7703 :echo perleval('[1 .. 4]')
7704< [1, 2, 3, 4]
7705
7706 Note that in a `:def` function local variables are not visible
7707 to {expr}.
7708
7709 Can also be used as a |method|: >
7710 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007711<
7712 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007713
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007714 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007715
7716
7717popup_ functions are documented here: |popup-functions|
7718
7719
7720pow({x}, {y}) *pow()*
7721 Return the power of {x} to the exponent {y} as a |Float|.
7722 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007723 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007724 Examples: >
7725 :echo pow(3, 3)
7726< 27.0 >
7727 :echo pow(2, 16)
7728< 65536.0 >
7729 :echo pow(32, 0.20)
7730< 2.0
7731
7732 Can also be used as a |method|: >
7733 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007734<
7735 Return type: |Number|
7736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007737
7738prevnonblank({lnum}) *prevnonblank()*
7739 Return the line number of the first line at or above {lnum}
7740 that is not blank. Example: >
7741 let ind = indent(prevnonblank(v:lnum - 1))
7742< When {lnum} is invalid or there is no non-blank line at or
7743 above it, zero is returned.
7744 {lnum} is used like with |getline()|.
7745 Also see |nextnonblank()|.
7746
7747 Can also be used as a |method|: >
7748 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007749<
7750 Return type: |Number|
7751
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007752
7753printf({fmt}, {expr1} ...) *printf()*
7754 Return a String with {fmt}, where "%" items are replaced by
7755 the formatted form of their respective arguments. Example: >
7756 printf("%4d: E%d %.30s", lnum, errno, msg)
7757< May result in:
7758 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7759
7760 When used as a |method| the base is passed as the second
7761 argument: >
7762 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007763<
7764 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007765
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007766 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007767 %s string
7768 %6S string right-aligned in 6 display cells
7769 %6s string right-aligned in 6 bytes
7770 %.9s string truncated to 9 bytes
7771 %c single byte
7772 %d decimal number
7773 %5d decimal number padded with spaces to 5 characters
7774 %x hex number
7775 %04x hex number padded with zeros to at least 4 characters
7776 %X hex number using upper case letters
7777 %o octal number
7778 %08b binary number padded with zeros to at least 8 chars
7779 %f floating point number as 12.23, inf, -inf or nan
7780 %F floating point number as 12.23, INF, -INF or NAN
7781 %e floating point number as 1.23e3, inf, -inf or nan
7782 %E floating point number as 1.23E3, INF, -INF or NAN
7783 %g floating point number, as %f or %e depending on value
7784 %G floating point number, as %F or %E depending on value
7785 %% the % character itself
7786
7787 Conversion specifications start with '%' and end with the
7788 conversion type. All other characters are copied unchanged to
7789 the result.
7790
7791 The "%" starts a conversion specification. The following
7792 arguments appear in sequence:
7793
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007794 % [pos-argument] [flags] [field-width] [.precision] type
7795
7796 pos-argument
7797 At most one positional argument specifier. These
7798 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007799
7800 flags
7801 Zero or more of the following flags:
7802
7803 # The value should be converted to an "alternate
7804 form". For c, d, and s conversions, this option
7805 has no effect. For o conversions, the precision
7806 of the number is increased to force the first
7807 character of the output string to a zero (except
7808 if a zero value is printed with an explicit
7809 precision of zero).
7810 For b and B conversions, a non-zero result has
7811 the string "0b" (or "0B" for B conversions)
7812 prepended to it.
7813 For x and X conversions, a non-zero result has
7814 the string "0x" (or "0X" for X conversions)
7815 prepended to it.
7816
7817 0 (zero) Zero padding. For all conversions the converted
7818 value is padded on the left with zeros rather
7819 than blanks. If a precision is given with a
7820 numeric conversion (d, b, B, o, x, and X), the 0
7821 flag is ignored.
7822
7823 - A negative field width flag; the converted value
7824 is to be left adjusted on the field boundary.
7825 The converted value is padded on the right with
7826 blanks, rather than on the left with blanks or
7827 zeros. A - overrides a 0 if both are given.
7828
7829 ' ' (space) A blank should be left before a positive
7830 number produced by a signed conversion (d).
7831
7832 + A sign must always be placed before a number
7833 produced by a signed conversion. A + overrides
7834 a space if both are used.
7835
7836 field-width
7837 An optional decimal digit string specifying a minimum
7838 field width. If the converted value has fewer bytes
7839 than the field width, it will be padded with spaces on
7840 the left (or right, if the left-adjustment flag has
7841 been given) to fill out the field width. For the S
7842 conversion the count is in cells.
7843
7844 .precision
7845 An optional precision, in the form of a period '.'
7846 followed by an optional digit string. If the digit
7847 string is omitted, the precision is taken as zero.
7848 This gives the minimum number of digits to appear for
7849 d, o, x, and X conversions, the maximum number of
7850 bytes to be printed from a string for s conversions,
7851 or the maximum number of cells to be printed from a
7852 string for S conversions.
7853 For floating point it is the number of digits after
7854 the decimal point.
7855
7856 type
7857 A character that specifies the type of conversion to
7858 be applied, see below.
7859
7860 A field width or precision, or both, may be indicated by an
7861 asterisk '*' instead of a digit string. In this case, a
7862 Number argument supplies the field width or precision. A
7863 negative field width is treated as a left adjustment flag
7864 followed by a positive field width; a negative precision is
7865 treated as though it were missing. Example: >
7866 :echo printf("%d: %.*s", nr, width, line)
7867< This limits the length of the text used from "line" to
7868 "width" bytes.
7869
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007870 If the argument to be formatted is specified using a
7871 positional argument specifier, and a '*' is used to indicate
7872 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007873 precision, the argument(s) to be used must also be specified
7874 using a {n$} positional argument specifier. See |printf-$|.
7875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007876 The conversion specifiers and their meanings are:
7877
7878 *printf-d* *printf-b* *printf-B* *printf-o*
7879 *printf-x* *printf-X*
7880 dbBoxX The Number argument is converted to signed decimal
7881 (d), unsigned binary (b and B), unsigned octal (o), or
7882 unsigned hexadecimal (x and X) notation. The letters
7883 "abcdef" are used for x conversions; the letters
7884 "ABCDEF" are used for X conversions.
7885 The precision, if any, gives the minimum number of
7886 digits that must appear; if the converted value
7887 requires fewer digits, it is padded on the left with
7888 zeros.
7889 In no case does a non-existent or small field width
7890 cause truncation of a numeric field; if the result of
7891 a conversion is wider than the field width, the field
7892 is expanded to contain the conversion result.
7893 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007894 The 'l' modifier indicates the argument is a long
7895 integer. The size will be 32 bits or 64 bits
7896 depending on your platform.
7897 The "ll" modifier indicates the argument is 64 bits.
7898 The b and B conversion specifiers never take a width
7899 modifier and always assume their argument is a 64 bit
7900 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007901 Generally, these modifiers are not useful. They are
7902 ignored when type is known from the argument.
7903
7904 i alias for d
7905 D alias for ld
7906 U alias for lu
7907 O alias for lo
7908
7909 *printf-c*
7910 c The Number argument is converted to a byte, and the
7911 resulting character is written.
7912
7913 *printf-s*
7914 s The text of the String argument is used. If a
7915 precision is specified, no more bytes than the number
7916 specified are used.
7917 If the argument is not a String type, it is
7918 automatically converted to text with the same format
7919 as ":echo".
7920 *printf-S*
7921 S The text of the String argument is used. If a
7922 precision is specified, no more display cells than the
7923 number specified are used.
7924
7925 *printf-f* *E807*
7926 f F The Float argument is converted into a string of the
7927 form 123.456. The precision specifies the number of
7928 digits after the decimal point. When the precision is
7929 zero the decimal point is omitted. When the precision
7930 is not specified 6 is used. A really big number
7931 (out of range or dividing by zero) results in "inf"
7932 or "-inf" with %f (INF or -INF with %F).
7933 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7934 Example: >
7935 echo printf("%.2f", 12.115)
7936< 12.12
7937 Note that roundoff depends on the system libraries.
7938 Use |round()| when in doubt.
7939
7940 *printf-e* *printf-E*
7941 e E The Float argument is converted into a string of the
7942 form 1.234e+03 or 1.234E+03 when using 'E'. The
7943 precision specifies the number of digits after the
7944 decimal point, like with 'f'.
7945
7946 *printf-g* *printf-G*
7947 g G The Float argument is converted like with 'f' if the
7948 value is between 0.001 (inclusive) and 10000000.0
7949 (exclusive). Otherwise 'e' is used for 'g' and 'E'
7950 for 'G'. When no precision is specified superfluous
7951 zeroes and '+' signs are removed, except for the zero
7952 immediately after the decimal point. Thus 10000000.0
7953 results in 1.0e7.
7954
7955 *printf-%*
7956 % A '%' is written. No argument is converted. The
7957 complete conversion specification is "%%".
7958
7959 When a Number argument is expected a String argument is also
7960 accepted and automatically converted.
7961 When a Float or String argument is expected a Number argument
7962 is also accepted and automatically converted.
7963 Any other argument type results in an error message.
7964
7965 *E766* *E767*
7966 The number of {exprN} arguments must exactly match the number
7967 of "%" items. If there are not sufficient or too many
7968 arguments an error is given. Up to 18 arguments can be used.
7969
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007970 *printf-$*
7971 In certain languages, error and informative messages are
7972 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02007973 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007974 having a different word order, positional arguments may be
7975 used to indicate this. For instance: >
7976
h_east596a9f22023-11-21 21:24:23 +09007977 #, c-format
7978 msgid "%s returning %s"
7979 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007980<
h_east596a9f22023-11-21 21:24:23 +09007981 In this example, the sentence has its 2 string arguments
7982 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007983
h_east596a9f22023-11-21 21:24:23 +09007984 echo printf(
7985 "In The Netherlands, vim's creator's name is: %1$s %2$s",
7986 "Bram", "Moolenaar")
7987< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007988
h_east596a9f22023-11-21 21:24:23 +09007989 echo printf(
7990 "In Belgium, vim's creator's name is: %2$s %1$s",
7991 "Bram", "Moolenaar")
7992< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007993
7994 Width (and precision) can be specified using the '*' specifier.
7995 In this case, you must specify the field width position in the
7996 argument list. >
7997
h_east596a9f22023-11-21 21:24:23 +09007998 echo printf("%1$*2$.*3$d", 1, 2, 3)
7999< 001 >
8000 echo printf("%2$*3$.*1$d", 1, 2, 3)
8001< 2 >
8002 echo printf("%3$*1$.*2$d", 1, 2, 3)
8003< 03 >
8004 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8005< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008006
8007 You can mix specifying the width and/or precision directly
8008 and via positional arguments: >
8009
h_east596a9f22023-11-21 21:24:23 +09008010 echo printf("%1$4.*2$f", 1.4142135, 6)
8011< 1.414214 >
8012 echo printf("%1$*2$.4f", 1.4142135, 6)
8013< 1.4142 >
8014 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8015< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008016
Christ van Willegenc35fc032024-03-14 18:30:41 +01008017 You will get an overflow error |E1510|, when the field-width
8018 or precision will result in a string longer than 6400 chars.
8019
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008020 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008021 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008022 echo printf("%s%1$s", "One", "Two")
8023< E1500: Cannot mix positional and non-positional arguments:
8024 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008025
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008026 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008027 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008028 echo printf("%3$s%1$s", "One", "Two", "Three")
8029< E1501: format argument 2 unused in $-style format:
8030 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008031
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008032 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008033 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008034 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8035< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008036
8037 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008038 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8039< E1502: Positional argument 2 used as field width reused as
8040 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008041
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008042 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008043 When a positional argument is used, but not the correct number
8044 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008045 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8046< E1503: Positional argument 3 out of bounds: %1$d at width
8047 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008048
8049 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008050 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8051< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8052 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008053
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008054 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008055 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008056 echo printf("%1$s %2$s %1$s", "One", "Two")
8057< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008058
8059 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008060 echo printf("%1$s %2$s %1$d", "One", "Two")
8061< E1504: Positional argument 1 type used inconsistently:
8062 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008063
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008064 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008065 Various other errors that lead to a format string being
8066 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008067 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8068< E1505: Invalid format specifier: %1$d at width %2$d is:
8069 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008070
Christ van Willegenea746f92023-10-05 20:48:36 +02008071 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008072 This internal error indicates that the logic to parse a
8073 positional format argument ran into a problem that couldn't be
8074 otherwise reported. Please file a bug against Vim if you run
8075 into this, copying the exact format string and parameters that
8076 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008077
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008078 Return type: |String|
8079
Christ van Willegenea746f92023-10-05 20:48:36 +02008080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008081prompt_getprompt({buf}) *prompt_getprompt()*
8082 Returns the effective prompt text for buffer {buf}. {buf} can
8083 be a buffer name or number. See |prompt-buffer|.
8084
8085 If the buffer doesn't exist or isn't a prompt buffer, an empty
8086 string is returned.
8087
8088 Can also be used as a |method|: >
8089 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008090<
8091 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008092
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008093 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008094
8095
8096prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8097 Set prompt callback for buffer {buf} to {expr}. When {expr}
8098 is an empty string the callback is removed. This has only
8099 effect if {buf} has 'buftype' set to "prompt".
8100
8101 The callback is invoked when pressing Enter. The current
8102 buffer will always be the prompt buffer. A new line for a
8103 prompt is added before invoking the callback, thus the prompt
8104 for which the callback was invoked will be in the last but one
8105 line.
8106 If the callback wants to add text to the buffer, it must
8107 insert it above the last line, since that is where the current
8108 prompt is. This can also be done asynchronously.
8109 The callback is invoked with one argument, which is the text
8110 that was entered at the prompt. This can be an empty string
8111 if the user only typed Enter.
8112 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008113 func s:TextEntered(text)
8114 if a:text == 'exit' || a:text == 'quit'
8115 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008116 " Reset 'modified' to allow the buffer to be closed.
8117 " We assume there is nothing useful to be saved.
8118 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008119 close
8120 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008121 " Do something useful with "a:text". In this example
8122 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008123 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008124 endif
8125 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008126 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008127
8128< Can also be used as a |method|: >
8129 GetBuffer()->prompt_setcallback(callback)
8130
8131< {only available when compiled with the |+channel| feature}
8132
8133prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8134 Set a callback for buffer {buf} to {expr}. When {expr} is an
8135 empty string the callback is removed. This has only effect if
8136 {buf} has 'buftype' set to "prompt".
8137
8138 This callback will be invoked when pressing CTRL-C in Insert
8139 mode. Without setting a callback Vim will exit Insert mode,
8140 as in any buffer.
8141
8142 Can also be used as a |method|: >
8143 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008144<
8145 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008146
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008147 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148
8149prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8150 Set prompt for buffer {buf} to {text}. You most likely want
8151 {text} to end in a space.
8152 The result is only visible if {buf} has 'buftype' set to
8153 "prompt". Example: >
8154 call prompt_setprompt(bufnr(), 'command: ')
8155<
8156 Can also be used as a |method|: >
8157 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008158<
8159 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008160
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008161 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008162
8163prop_ functions are documented here: |text-prop-functions|
8164
8165pum_getpos() *pum_getpos()*
8166 If the popup menu (see |ins-completion-menu|) is not visible,
8167 returns an empty |Dictionary|, otherwise, returns a
8168 |Dictionary| with the following keys:
8169 height nr of items visible
8170 width screen cells
8171 row top screen row (0 first row)
8172 col leftmost screen column (0 first col)
8173 size total nr of items
8174 scrollbar |TRUE| if scrollbar is visible
8175
8176 The values are the same as in |v:event| during
8177 |CompleteChanged|.
8178
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008179 Return type: dict<any>
8180
8181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008182pumvisible() *pumvisible()*
8183 Returns non-zero when the popup menu is visible, zero
8184 otherwise. See |ins-completion-menu|.
8185 This can be used to avoid some things that would remove the
8186 popup menu.
8187
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008188 Return type: |Number|
8189
8190
zeertzjq7c515282024-11-10 20:26:12 +01008191py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008192 Evaluate Python expression {expr} and return its result
8193 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008194 If a {locals} |Dictionary| is given, it defines set of local
8195 variables available in the expression. The keys are variable
8196 names and the values are the variable values. |Dictionary| and
8197 |List| values are referenced, and may be updated by the
8198 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008199 Numbers and strings are returned as they are (strings are
8200 copied though, Unicode strings are additionally converted to
8201 'encoding').
8202 Lists are represented as Vim |List| type.
8203 Dictionaries are represented as Vim |Dictionary| type with
8204 keys converted to strings.
8205 Note that in a `:def` function local variables are not visible
8206 to {expr}.
8207
8208 Can also be used as a |method|: >
8209 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008210 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008211<
8212 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008213
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008214 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008215
8216 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008217pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008218 Evaluate Python expression {expr} and return its result
8219 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008220 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008221 Numbers and strings are returned as they are (strings are
8222 copied though).
8223 Lists are represented as Vim |List| type.
8224 Dictionaries are represented as Vim |Dictionary| type,
8225 non-string keys result in error.
8226 Note that in a `:def` function local variables are not visible
8227 to {expr}.
8228
8229 Can also be used as a |method|: >
8230 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008231<
8232 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008233
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008234 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008235
zeertzjq7c515282024-11-10 20:26:12 +01008236pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008237 Evaluate Python expression {expr} and return its result
8238 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008239 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008240 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8241 See also: |pyeval()|, |py3eval()|
8242
8243 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008244 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008245<
8246 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008247
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008248 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008249 |+python3| feature}
8250
8251rand([{expr}]) *rand()* *random*
8252 Return a pseudo-random Number generated with an xoshiro128**
8253 algorithm using seed {expr}. The returned number is 32 bits,
8254 also on 64 bits systems, for consistency.
8255 {expr} can be initialized by |srand()| and will be updated by
8256 rand(). If {expr} is omitted, an internal seed value is used
8257 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008258 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008259
8260 Examples: >
8261 :echo rand()
8262 :let seed = srand()
8263 :echo rand(seed)
8264 :echo rand(seed) % 16 " random number 0 - 15
8265<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008266 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008267
8268 *E726* *E727*
8269range({expr} [, {max} [, {stride}]]) *range()*
8270 Returns a |List| with Numbers:
8271 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8272 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8273 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8274 {max}] (increasing {expr} with {stride} each time, not
8275 producing a value past {max}).
8276 When the maximum is one before the start the result is an
8277 empty list. When the maximum is more than one before the
8278 start this is an error.
8279 Examples: >
8280 range(4) " [0, 1, 2, 3]
8281 range(2, 4) " [2, 3, 4]
8282 range(2, 9, 3) " [2, 5, 8]
8283 range(2, -2, -1) " [2, 1, 0, -1, -2]
8284 range(0) " []
8285 range(2, 0) " error!
8286<
8287 Can also be used as a |method|: >
8288 GetExpr()->range()
8289<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008290 Return type: list<number>
8291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008292
K.Takata11df3ae2022-10-19 14:02:40 +01008293readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008294 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008295 If {offset} is specified, read the file from the specified
8296 offset. If it is a negative value, it is used as an offset
8297 from the end of the file. E.g., to read the last 12 bytes: >
8298 readblob('file.bin', -12)
8299< If {size} is specified, only the specified size will be read.
8300 E.g. to read the first 100 bytes of a file: >
8301 readblob('file.bin', 0, 100)
8302< If {size} is -1 or omitted, the whole data starting from
8303 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008304 This can be also used to read the data from a character device
8305 on Unix when {size} is explicitly set. Only if the device
8306 supports seeking {offset} can be used. Otherwise it should be
8307 zero. E.g. to read 10 bytes from a serial console: >
8308 readblob('/dev/ttyS0', 0, 10)
8309< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008311 When the offset is beyond the end of the file the result is an
8312 empty blob.
8313 When trying to read more bytes than are available the result
8314 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008315 Also see |readfile()| and |writefile()|.
8316
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008317 Return type: |Blob|
8318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008319
8320readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8321 Return a list with file and directory names in {directory}.
8322 You can also use |glob()| if you don't need to do complicated
8323 things, such as limiting the number of matches.
8324 The list will be sorted (case sensitive), see the {dict}
8325 argument below for changing the sort order.
8326
8327 When {expr} is omitted all entries are included.
8328 When {expr} is given, it is evaluated to check what to do:
8329 If {expr} results in -1 then no further entries will
8330 be handled.
8331 If {expr} results in 0 then this entry will not be
8332 added to the list.
8333 If {expr} results in 1 then this entry will be added
8334 to the list.
8335 The entries "." and ".." are always excluded.
8336 Each time {expr} is evaluated |v:val| is set to the entry name.
8337 When {expr} is a function the name is passed as the argument.
8338 For example, to get a list of files ending in ".txt": >
8339 readdir(dirname, {n -> n =~ '.txt$'})
8340< To skip hidden and backup files: >
8341 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008342< *E857*
8343 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008344 values. Currently this is used to specify if and how sorting
8345 should be performed. The dict can have the following members:
8346
8347 sort How to sort the result returned from the system.
8348 Valid values are:
8349 "none" do not sort (fastest method)
8350 "case" sort case sensitive (byte value of
8351 each character, technically, using
8352 strcmp()) (default)
8353 "icase" sort case insensitive (technically
8354 using strcasecmp())
8355 "collate" sort using the collation order
8356 of the "POSIX" or "C" |locale|
8357 (technically using strcoll())
8358 Other values are silently ignored.
8359
8360 For example, to get a list of all files in the current
8361 directory without sorting the individual entries: >
8362 readdir('.', '1', #{sort: 'none'})
8363< If you want to get a directory tree: >
8364 function! s:tree(dir)
8365 return {a:dir : map(readdir(a:dir),
8366 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008367 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008368 endfunction
8369 echo s:tree(".")
8370<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008371 Returns an empty List on error.
8372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008373 Can also be used as a |method|: >
8374 GetDirName()->readdir()
8375<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008376 Return type: list<string> or list<any>
8377
8378
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008379readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8380 Extended version of |readdir()|.
8381 Return a list of Dictionaries with file and directory
8382 information in {directory}.
8383 This is useful if you want to get the attributes of file and
8384 directory at the same time as getting a list of a directory.
8385 This is much faster than calling |readdir()| then calling
8386 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8387 each file and directory especially on MS-Windows.
8388 The list will by default be sorted by name (case sensitive),
8389 the sorting can be changed by using the optional {dict}
8390 argument, see |readdir()|.
8391
8392 The Dictionary for file and directory information has the
8393 following items:
8394 group Group name of the entry. (Only on Unix)
8395 name Name of the entry.
8396 perm Permissions of the entry. See |getfperm()|.
8397 size Size of the entry. See |getfsize()|.
8398 time Timestamp of the entry. See |getftime()|.
8399 type Type of the entry.
8400 On Unix, almost same as |getftype()| except:
8401 Symlink to a dir "linkd"
8402 Other symlink "link"
8403 On MS-Windows:
8404 Normal file "file"
8405 Directory "dir"
8406 Junction "junction"
8407 Symlink to a dir "linkd"
8408 Other symlink "link"
8409 Other reparse point "reparse"
8410 user User name of the entry's owner. (Only on Unix)
8411 On Unix, if the entry is a symlink, the Dictionary includes
8412 the information of the target (except the "type" item).
8413 On MS-Windows, it includes the information of the symlink
8414 itself because of performance reasons.
8415
8416 When {expr} is omitted all entries are included.
8417 When {expr} is given, it is evaluated to check what to do:
8418 If {expr} results in -1 then no further entries will
8419 be handled.
8420 If {expr} results in 0 then this entry will not be
8421 added to the list.
8422 If {expr} results in 1 then this entry will be added
8423 to the list.
8424 The entries "." and ".." are always excluded.
8425 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8426 of the entry.
8427 When {expr} is a function the entry is passed as the argument.
8428 For example, to get a list of files ending in ".txt": >
8429 readdirex(dirname, {e -> e.name =~ '.txt$'})
8430<
8431 For example, to get a list of all files in the current
8432 directory without sorting the individual entries: >
8433 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008434<
8435 Can also be used as a |method|: >
8436 GetDirName()->readdirex()
8437<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008438 Return type: list<dict<any>> or list<any>
8439
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008440
8441 *readfile()*
8442readfile({fname} [, {type} [, {max}]])
8443 Read file {fname} and return a |List|, each line of the file
8444 as an item. Lines are broken at NL characters. Macintosh
8445 files separated with CR will result in a single long line
8446 (unless a NL appears somewhere).
8447 All NUL characters are replaced with a NL character.
8448 When {type} contains "b" binary mode is used:
8449 - When the last line ends in a NL an extra empty list item is
8450 added.
8451 - No CR characters are removed.
8452 Otherwise:
8453 - CR characters that appear before a NL are removed.
8454 - Whether the last line ends in a NL or not does not matter.
8455 - When 'encoding' is Unicode any UTF-8 byte order mark is
8456 removed from the text.
8457 When {max} is given this specifies the maximum number of lines
8458 to be read. Useful if you only want to check the first ten
8459 lines of a file: >
8460 :for line in readfile(fname, '', 10)
8461 : if line =~ 'Date' | echo line | endif
8462 :endfor
8463< When {max} is negative -{max} lines from the end of the file
8464 are returned, or as many as there are.
8465 When {max} is zero the result is an empty list.
8466 Note that without {max} the whole file is read into memory.
8467 Also note that there is no recognition of encoding. Read a
8468 file into a buffer if you need to.
8469 Deprecated (use |readblob()| instead): When {type} contains
8470 "B" a |Blob| is returned with the binary data of the file
8471 unmodified.
8472 When the file can't be opened an error message is given and
8473 the result is an empty list.
8474 Also see |writefile()|.
8475
8476 Can also be used as a |method|: >
8477 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008478<
8479 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008480
8481reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8482 {func} is called for every item in {object}, which can be a
8483 |String|, |List| or a |Blob|. {func} is called with two
8484 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008485 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008486
8487 {initial} is the initial result. When omitted, the first item
8488 in {object} is used and {func} is first called for the second
8489 item. If {initial} is not given and {object} is empty no
8490 result can be computed, an E998 error is given.
8491
8492 Examples: >
8493 echo reduce([1, 3, 5], { acc, val -> acc + val })
8494 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8495 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8496 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8497<
8498 Can also be used as a |method|: >
8499 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008500<
8501 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8502 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008503
8504
8505reg_executing() *reg_executing()*
8506 Returns the single letter name of the register being executed.
8507 Returns an empty string when no register is being executed.
8508 See |@|.
8509
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008510 Return type: |String|
8511
8512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008513reg_recording() *reg_recording()*
8514 Returns the single letter name of the register being recorded.
8515 Returns an empty string when not recording. See |q|.
8516
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008517 Return type: |String|
8518
8519
8520reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008521reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008522reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008523 Return an item that represents a time value. The item is a
8524 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008525 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008526 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008527 string or |reltimefloat()| to convert to a Float. For
8528 example, to see the time spent in function Work(): >
8529 var startTime = reltime()
8530 Work()
8531 echo startTime->reltime()->reltimestr()
8532<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008533 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008534 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008535 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008536 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008537 specified in the argument.
8538 With two arguments it returns the time passed between {start}
8539 and {end}.
8540
8541 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008542 reltime(). If there is an error an empty List is returned in
8543 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008544
8545 Can also be used as a |method|: >
8546 GetStart()->reltime()
8547<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008548 Return type: list<number>
8549
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008550 {only available when compiled with the |+reltime| feature}
8551
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008553reltimefloat({time}) *reltimefloat()*
8554 Return a Float that represents the time value of {time}.
8555 Example: >
8556 let start = reltime()
8557 call MyFunction()
8558 let seconds = reltimefloat(reltime(start))
8559< See the note of reltimestr() about overhead.
8560 Also see |profiling|.
8561 If there is an error 0.0 is returned in legacy script, in Vim9
8562 script an error is given.
8563
8564 Can also be used as a |method|: >
8565 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008566<
8567 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008568
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008569 {only available when compiled with the |+reltime| feature}
8570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008571
8572reltimestr({time}) *reltimestr()*
8573 Return a String that represents the time value of {time}.
8574 This is the number of seconds, a dot and the number of
8575 microseconds. Example: >
8576 let start = reltime()
8577 call MyFunction()
8578 echo reltimestr(reltime(start))
8579< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008580 The accuracy depends on the system. Use reltimefloat() for the
8581 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582 Leading spaces are used to make the string align nicely. You
8583 can use split() to remove it. >
8584 echo split(reltimestr(reltime(start)))[0]
8585< Also see |profiling|.
8586 If there is an error an empty string is returned in legacy
8587 script, in Vim9 script an error is given.
8588
8589 Can also be used as a |method|: >
8590 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008591<
8592 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008593
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008594 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008595
8596 *remote_expr()* *E449*
8597remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008598 Send the {string} to {server}. The {server} argument is a
8599 string, also see |{server}|.
8600
8601 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008602 after evaluation. The result must be a String or a |List|
8603 other types will be converted to String. A |List| is turned
8604 into a String by joining the items with a line break in
8605 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008607 If {idvar} is present and not empty, it is taken as the name
8608 of a variable and a {serverid} for later use with
8609 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611 If {timeout} is given the read times out after this many
8612 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008614 See also |clientserver| |RemoteReply|.
8615 This function is not available in the |sandbox|.
8616 {only available when compiled with the |+clientserver| feature}
8617 Note: Any errors will cause a local error message to be issued
8618 and the result will be the empty string.
8619
8620 Variables will be evaluated in the global namespace,
8621 independent of a function currently being active. Except
8622 when in debug mode, then local function variables and
8623 arguments can be evaluated.
8624
8625 Examples: >
8626 :echo remote_expr("gvim", "2+2")
8627 :echo remote_expr("gvim1", "b:current_syntax")
8628<
8629 Can also be used as a |method|: >
8630 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008631<
8632 Return type: |String| or list<{type}>
8633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008634
8635remote_foreground({server}) *remote_foreground()*
8636 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008637 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008638 This works like: >
8639 remote_expr({server}, "foreground()")
8640< Except that on Win32 systems the client does the work, to work
8641 around the problem that the OS doesn't always allow the server
8642 to bring itself to the foreground.
8643 Note: This does not restore the window if it was minimized,
8644 like foreground() does.
8645 This function is not available in the |sandbox|.
8646
8647 Can also be used as a |method|: >
8648 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008649<
8650 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008651
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008652 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008653 Win32 console version}
8654
8655
8656remote_peek({serverid} [, {retvar}]) *remote_peek()*
8657 Returns a positive number if there are available strings
8658 from {serverid}. Copies any reply string into the variable
8659 {retvar} if specified. {retvar} must be a string with the
8660 name of a variable.
8661 Returns zero if none are available.
8662 Returns -1 if something is wrong.
8663 See also |clientserver|.
8664 This function is not available in the |sandbox|.
8665 {only available when compiled with the |+clientserver| feature}
8666 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008667 :let repl = ""
8668 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008669
8670< Can also be used as a |method|: >
8671 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008672<
8673 Return type: |Number|
8674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008675
8676remote_read({serverid}, [{timeout}]) *remote_read()*
8677 Return the oldest available reply from {serverid} and consume
8678 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008679 reply is available. Returns an empty string, if a reply is
8680 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008681 See also |clientserver|.
8682 This function is not available in the |sandbox|.
8683 {only available when compiled with the |+clientserver| feature}
8684 Example: >
8685 :echo remote_read(id)
8686
8687< Can also be used as a |method|: >
8688 ServerId()->remote_read()
8689<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008690 Return type: |String|
8691
8692
8693remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008694 Send the {string} to {server}. The {server} argument is a
8695 string, also see |{server}|.
8696
8697 The string is sent as input keys and the function returns
8698 immediately. At the Vim server the keys are not mapped
8699 |:map|.
8700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008701 If {idvar} is present, it is taken as the name of a variable
8702 and a {serverid} for later use with remote_read() is stored
8703 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008705 See also |clientserver| |RemoteReply|.
8706 This function is not available in the |sandbox|.
8707 {only available when compiled with the |+clientserver| feature}
8708
8709 Note: Any errors will be reported in the server and may mess
8710 up the display.
8711 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008712 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008713 \ remote_read(serverid)
8714
8715 :autocmd NONE RemoteReply *
8716 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008717 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008718 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8719<
8720 Can also be used as a |method|: >
8721 ServerName()->remote_send(keys)
8722<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008723 Return type: |String|
8724
8725
8726remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008727 Become the server {name}. {name} must be a non-empty string.
8728 This fails if already running as a server, when |v:servername|
8729 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008730
8731 Can also be used as a |method|: >
8732 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008733<
8734 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008735
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008736 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008737
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008738
8739remove({list}, {idx}) *remove()*
8740remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008741 Without {end}: Remove the item at {idx} from |List| {list} and
8742 return the item.
8743 With {end}: Remove items from {idx} to {end} (inclusive) and
8744 return a |List| with these items. When {idx} points to the same
8745 item as {end} a list with one item is returned. When {end}
8746 points to an item before {idx} this is an error.
8747 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008748 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008749 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008750 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008751 :call remove(mylist, 0, 9)
8752<
8753 Use |delete()| to remove a file.
8754
8755 Can also be used as a |method|: >
8756 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008757<
8758 Return type: any, depending on {list}
8759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008760
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008761remove({blob}, {idx})
8762remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008763 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8764 return the byte.
8765 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8766 return a |Blob| with these bytes. When {idx} points to the same
8767 byte as {end} a |Blob| with one byte is returned. When {end}
8768 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008769 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008770 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008771 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008772 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008773<
8774 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008775
8776remove({dict}, {key})
8777 Remove the entry from {dict} with key {key} and return it.
8778 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008779 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008780< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008781 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008782
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008783 Return type: any, depending on {dict}
8784
8785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008786rename({from}, {to}) *rename()*
8787 Rename the file by the name {from} to the name {to}. This
8788 should also work to move files across file systems. The
8789 result is a Number, which is 0 if the file was renamed
8790 successfully, and non-zero when the renaming failed.
8791 NOTE: If {to} exists it is overwritten without warning.
8792 This function is not available in the |sandbox|.
8793
8794 Can also be used as a |method|: >
8795 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008796<
8797 Return type: |Number|
8798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008799
8800repeat({expr}, {count}) *repeat()*
8801 Repeat {expr} {count} times and return the concatenated
8802 result. Example: >
8803 :let separator = repeat('-', 80)
8804< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008805 When {expr} is a |List| or a |Blob| the result is {expr}
8806 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008807 :let longlist = repeat(['a', 'b'], 3)
8808< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8809
8810 Can also be used as a |method|: >
8811 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008812<
8813 Return type: |String|, |Blob| or list<{type}> depending on
8814 {expr}
8815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008816
8817resolve({filename}) *resolve()* *E655*
8818 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8819 returns the path the shortcut points to in a simplified form.
8820 When {filename} is a symbolic link or junction point, return
8821 the full path to the target. If the target of junction is
8822 removed, return {filename}.
8823 On Unix, repeat resolving symbolic links in all path
8824 components of {filename} and return the simplified result.
8825 To cope with link cycles, resolving of symbolic links is
8826 stopped after 100 iterations.
8827 On other systems, return the simplified {filename}.
8828 The simplification step is done as by |simplify()|.
8829 resolve() keeps a leading path component specifying the
8830 current directory (provided the result is still a relative
8831 path name) and also keeps a trailing path separator.
8832
8833 Can also be used as a |method|: >
8834 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008835<
8836 Return type: |String|
8837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008838
8839reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008840 Reverse the order of items in {object}. {object} can be a
8841 |List|, a |Blob| or a |String|. For a List and a Blob the
8842 items are reversed in-place and {object} is returned.
8843 For a String a new String is returned.
8844 Returns zero if {object} is not a List, Blob or a String.
8845 If you want a List or Blob to remain unmodified make a copy
8846 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008847 :let revlist = reverse(copy(mylist))
8848< Can also be used as a |method|: >
8849 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008850<
8851 Return type: |String|, |Blob| or list<{type}> depending on
8852 {object}
8853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008854
8855round({expr}) *round()*
8856 Round off {expr} to the nearest integral value and return it
8857 as a |Float|. If {expr} lies halfway between two integral
8858 values, then use the larger one (away from zero).
8859 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008860 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008861 Examples: >
8862 echo round(0.456)
8863< 0.0 >
8864 echo round(4.5)
8865< 5.0 >
8866 echo round(-4.5)
8867< -5.0
8868
8869 Can also be used as a |method|: >
8870 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008871<
8872 Return type: |Float|
8873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008874
8875rubyeval({expr}) *rubyeval()*
8876 Evaluate Ruby expression {expr} and return its result
8877 converted to Vim data structures.
8878 Numbers, floats and strings are returned as they are (strings
8879 are copied though).
8880 Arrays are represented as Vim |List| type.
8881 Hashes are represented as Vim |Dictionary| type.
8882 Other objects are represented as strings resulted from their
8883 "Object#to_s" method.
8884 Note that in a `:def` function local variables are not visible
8885 to {expr}.
8886
8887 Can also be used as a |method|: >
8888 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008889<
8890 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008891
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008892 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008893
8894screenattr({row}, {col}) *screenattr()*
8895 Like |screenchar()|, but return the attribute. This is a rather
8896 arbitrary number that can only be used to compare to the
8897 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008898 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008899
8900 Can also be used as a |method|: >
8901 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008902<
8903 Return type: |Number|
8904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008905
8906screenchar({row}, {col}) *screenchar()*
8907 The result is a Number, which is the character at position
8908 [row, col] on the screen. This works for every possible
8909 screen position, also status lines, window separators and the
8910 command line. The top left position is row one, column one
8911 The character excludes composing characters. For double-byte
8912 encodings it may only be the first byte.
8913 This is mainly to be used for testing.
8914 Returns -1 when row or col is out of range.
8915
8916 Can also be used as a |method|: >
8917 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008918<
8919 Return type: |Number|
8920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008921
8922screenchars({row}, {col}) *screenchars()*
8923 The result is a |List| of Numbers. The first number is the same
8924 as what |screenchar()| returns. Further numbers are
8925 composing characters on top of the base character.
8926 This is mainly to be used for testing.
8927 Returns an empty List when row or col is out of range.
8928
8929 Can also be used as a |method|: >
8930 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008931<
8932 Return type: list<number> or list<any>
8933
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008934
8935screencol() *screencol()*
8936 The result is a Number, which is the current screen column of
8937 the cursor. The leftmost column has number 1.
8938 This function is mainly used for testing.
8939
8940 Note: Always returns the current screen column, thus if used
8941 in a command (e.g. ":echo screencol()") it will return the
8942 column inside the command line, which is 1 when the command is
8943 executed. To get the cursor position in the file use one of
8944 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008945 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008946 nnoremap <silent> GG :echom screencol()<CR>
8947 nnoremap GG <Cmd>echom screencol()<CR>
8948<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008949 Return type: |Number|
8950
8951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008952screenpos({winid}, {lnum}, {col}) *screenpos()*
8953 The result is a Dict with the screen position of the text
8954 character in window {winid} at buffer line {lnum} and column
8955 {col}. {col} is a one-based byte index.
8956 The Dict has these members:
8957 row screen row
8958 col first screen column
8959 endcol last screen column
8960 curscol cursor screen column
8961 If the specified position is not visible, all values are zero.
8962 The "endcol" value differs from "col" when the character
8963 occupies more than one screen cell. E.g. for a Tab "col" can
8964 be 1 and "endcol" can be 8.
8965 The "curscol" value is where the cursor would be placed. For
8966 a Tab it would be the same as "endcol", while for a double
8967 width character it would be the same as "col".
8968 The |conceal| feature is ignored here, the column numbers are
8969 as if 'conceallevel' is zero. You can set the cursor to the
8970 right position and use |screencol()| to get the value with
8971 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008972 If the position is in a closed fold the screen position of the
8973 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008974 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008975
8976 Can also be used as a |method|: >
8977 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008978<
8979 Return type: dict<number> or dict<any>
8980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008981
8982screenrow() *screenrow()*
8983 The result is a Number, which is the current screen row of the
8984 cursor. The top line has number one.
8985 This function is mainly used for testing.
8986 Alternatively you can use |winline()|.
8987
8988 Note: Same restrictions as with |screencol()|.
8989
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008990 Return type: |Number|
8991
8992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008993screenstring({row}, {col}) *screenstring()*
8994 The result is a String that contains the base character and
8995 any composing characters at position [row, col] on the screen.
8996 This is like |screenchars()| but returning a String with the
8997 characters.
8998 This is mainly to be used for testing.
8999 Returns an empty String when row or col is out of range.
9000
9001 Can also be used as a |method|: >
9002 GetRow()->screenstring(col)
9003<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009004 Return type: |String|
9005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009006 *search()*
9007search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9008 Search for regexp pattern {pattern}. The search starts at the
9009 cursor position (you can use |cursor()| to set it).
9010
9011 When a match has been found its line number is returned.
9012 If there is no match a 0 is returned and the cursor doesn't
9013 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009014 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009015
9016 {flags} is a String, which can contain these character flags:
9017 'b' search Backward instead of forward
9018 'c' accept a match at the Cursor position
9019 'e' move to the End of the match
9020 'n' do Not move the cursor
9021 'p' return number of matching sub-Pattern (see below)
9022 's' Set the ' mark at the previous location of the cursor
9023 'w' Wrap around the end of the file
9024 'W' don't Wrap around the end of the file
9025 'z' start searching at the cursor column instead of zero
9026 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9027
9028 If the 's' flag is supplied, the ' mark is set, only if the
9029 cursor is moved. The 's' flag cannot be combined with the 'n'
9030 flag.
9031
9032 'ignorecase', 'smartcase' and 'magic' are used.
9033
9034 When the 'z' flag is not given, forward searching always
9035 starts in column zero and then matches before the cursor are
9036 skipped. When the 'c' flag is present in 'cpo' the next
9037 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009038 search starts one column after the start of the match. This
9039 matters for overlapping matches. See |cpo-c|. You can also
9040 insert "\ze" to change where the match ends, see |/\ze|.
9041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009042 When searching backwards and the 'z' flag is given then the
9043 search starts in column zero, thus no match in the current
9044 line will be found (unless wrapping around the end of the
9045 file).
9046
9047 When the {stopline} argument is given then the search stops
9048 after searching this line. This is useful to restrict the
9049 search to a range of lines. Examples: >
9050 let match = search('(', 'b', line("w0"))
9051 let end = search('END', '', line("w$"))
9052< When {stopline} is used and it is not zero this also implies
9053 that the search does not wrap around the end of the file.
9054 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009055 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009056 When the {timeout} argument is given the search stops when
9057 more than this many milliseconds have passed. Thus when
9058 {timeout} is 500 the search stops after half a second.
9059 The value must not be negative. A zero value is like not
9060 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009061
9062 Note: the timeout is only considered when searching, not
9063 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009064 {only available when compiled with the |+reltime| feature}
9065
9066 If the {skip} expression is given it is evaluated with the
9067 cursor positioned on the start of a match. If it evaluates to
9068 non-zero this match is skipped. This can be used, for
9069 example, to skip a match in a comment or a string.
9070 {skip} can be a string, which is evaluated as an expression, a
9071 function reference or a lambda.
9072 When {skip} is omitted or empty, every match is accepted.
9073 When evaluating {skip} causes an error the search is aborted
9074 and -1 returned.
9075 *search()-sub-match*
9076 With the 'p' flag the returned value is one more than the
9077 first sub-match in \(\). One if none of them matched but the
9078 whole pattern did match.
9079 To get the column number too use |searchpos()|.
9080
9081 The cursor will be positioned at the match, unless the 'n'
9082 flag is used.
9083
9084 Example (goes over all files in the argument list): >
9085 :let n = 1
9086 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009087 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009088 : " start at the last char in the file and wrap for the
9089 : " first search to find match at start of file
9090 : normal G$
9091 : let flags = "w"
9092 : while search("foo", flags) > 0
9093 : s/foo/bar/g
9094 : let flags = "W"
9095 : endwhile
9096 : update " write the file if modified
9097 : let n = n + 1
9098 :endwhile
9099<
9100 Example for using some flags: >
9101 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9102< This will search for the keywords "if", "else", and "endif"
9103 under or after the cursor. Because of the 'p' flag, it
9104 returns 1, 2, or 3 depending on which keyword is found, or 0
9105 if the search fails. With the cursor on the first word of the
9106 line:
9107 if (foo == 0) | let foo = foo + 1 | endif ~
9108 the function returns 1. Without the 'c' flag, the function
9109 finds the "endif" and returns 3. The same thing happens
9110 without the 'e' flag if the cursor is on the "f" of "if".
9111 The 'n' flag tells the function not to move the cursor.
9112
9113 Can also be used as a |method|: >
9114 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009115<
9116 Return type: |Number|
9117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009118
9119searchcount([{options}]) *searchcount()*
9120 Get or update the last search count, like what is displayed
9121 without the "S" flag in 'shortmess'. This works even if
9122 'shortmess' does contain the "S" flag.
9123
9124 This returns a |Dictionary|. The dictionary is empty if the
9125 previous pattern was not set and "pattern" was not specified.
9126
9127 key type meaning ~
9128 current |Number| current position of match;
9129 0 if the cursor position is
9130 before the first match
9131 exact_match |Boolean| 1 if "current" is matched on
9132 "pos", otherwise 0
9133 total |Number| total count of matches found
9134 incomplete |Number| 0: search was fully completed
9135 1: recomputing was timed out
9136 2: max count exceeded
9137
9138 For {options} see further down.
9139
9140 To get the last search count when |n| or |N| was pressed, call
9141 this function with `recompute: 0` . This sometimes returns
9142 wrong information because |n| and |N|'s maximum count is 99.
9143 If it exceeded 99 the result must be max count + 1 (100). If
9144 you want to get correct information, specify `recompute: 1`: >
9145
9146 " result == maxcount + 1 (100) when many matches
9147 let result = searchcount(#{recompute: 0})
9148
9149 " Below returns correct result (recompute defaults
9150 " to 1)
9151 let result = searchcount()
9152<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009153 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009154 function! LastSearchCount() abort
9155 let result = searchcount(#{recompute: 0})
9156 if empty(result)
9157 return ''
9158 endif
9159 if result.incomplete ==# 1 " timed out
9160 return printf(' /%s [?/??]', @/)
9161 elseif result.incomplete ==# 2 " max count exceeded
9162 if result.total > result.maxcount &&
9163 \ result.current > result.maxcount
9164 return printf(' /%s [>%d/>%d]', @/,
9165 \ result.current, result.total)
9166 elseif result.total > result.maxcount
9167 return printf(' /%s [%d/>%d]', @/,
9168 \ result.current, result.total)
9169 endif
9170 endif
9171 return printf(' /%s [%d/%d]', @/,
9172 \ result.current, result.total)
9173 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009174 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009175
9176 " Or if you want to show the count only when
9177 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009178 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009179 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9180<
9181 You can also update the search count, which can be useful in a
9182 |CursorMoved| or |CursorMovedI| autocommand: >
9183
9184 autocmd CursorMoved,CursorMovedI *
9185 \ let s:searchcount_timer = timer_start(
9186 \ 200, function('s:update_searchcount'))
9187 function! s:update_searchcount(timer) abort
9188 if a:timer ==# s:searchcount_timer
9189 call searchcount(#{
9190 \ recompute: 1, maxcount: 0, timeout: 100})
9191 redrawstatus
9192 endif
9193 endfunction
9194<
9195 This can also be used to count matched texts with specified
9196 pattern in the current buffer using "pattern": >
9197
9198 " Count '\<foo\>' in this buffer
9199 " (Note that it also updates search count)
9200 let result = searchcount(#{pattern: '\<foo\>'})
9201
9202 " To restore old search count by old pattern,
9203 " search again
9204 call searchcount()
9205<
9206 {options} must be a |Dictionary|. It can contain:
9207 key type meaning ~
9208 recompute |Boolean| if |TRUE|, recompute the count
9209 like |n| or |N| was executed.
9210 otherwise returns the last
9211 computed result (when |n| or
9212 |N| was used when "S" is not
9213 in 'shortmess', or this
9214 function was called).
9215 (default: |TRUE|)
9216 pattern |String| recompute if this was given
9217 and different with |@/|.
9218 this works as same as the
9219 below command is executed
9220 before calling this function >
9221 let @/ = pattern
9222< (default: |@/|)
9223 timeout |Number| 0 or negative number is no
9224 timeout. timeout milliseconds
9225 for recomputing the result
9226 (default: 0)
9227 maxcount |Number| 0 or negative number is no
9228 limit. max count of matched
9229 text while recomputing the
9230 result. if search exceeded
9231 total count, "total" value
9232 becomes `maxcount + 1`
9233 (default: 99)
9234 pos |List| `[lnum, col, off]` value
9235 when recomputing the result.
9236 this changes "current" result
9237 value. see |cursor()|,
9238 |getpos()|
9239 (default: cursor's position)
9240
9241 Can also be used as a |method|: >
9242 GetSearchOpts()->searchcount()
9243<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009244 Return type: dict<number>
9245
9246
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009247searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9248 Search for the declaration of {name}.
9249
9250 With a non-zero {global} argument it works like |gD|, find
9251 first match in the file. Otherwise it works like |gd|, find
9252 first match in the function.
9253
9254 With a non-zero {thisblock} argument matches in a {} block
9255 that ends before the cursor position are ignored. Avoids
9256 finding variable declarations only valid in another scope.
9257
9258 Moves the cursor to the found match.
9259 Returns zero for success, non-zero for failure.
9260 Example: >
9261 if searchdecl('myvar') == 0
9262 echo getline('.')
9263 endif
9264<
9265 Can also be used as a |method|: >
9266 GetName()->searchdecl()
9267<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009268 Return type: |Number|
9269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009270 *searchpair()*
9271searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9272 [, {stopline} [, {timeout}]]]])
9273 Search for the match of a nested start-end pair. This can be
9274 used to find the "endif" that matches an "if", while other
9275 if/endif pairs in between are ignored.
9276 The search starts at the cursor. The default is to search
9277 forward, include 'b' in {flags} to search backward.
9278 If a match is found, the cursor is positioned at it and the
9279 line number is returned. If no match is found 0 or -1 is
9280 returned and the cursor doesn't move. No error message is
9281 given.
9282
9283 {start}, {middle} and {end} are patterns, see |pattern|. They
9284 must not contain \( \) pairs. Use of \%( \) is allowed. When
9285 {middle} is not empty, it is found when searching from either
9286 direction, but only when not in a nested start-end pair. A
9287 typical use is: >
9288 searchpair('\<if\>', '\<else\>', '\<endif\>')
9289< By leaving {middle} empty the "else" is skipped.
9290
9291 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9292 |search()|. Additionally:
9293 'r' Repeat until no more matches found; will find the
9294 outer pair. Implies the 'W' flag.
9295 'm' Return number of matches instead of line number with
9296 the match; will be > 1 when 'r' is used.
9297 Note: it's nearly always a good idea to use the 'W' flag, to
9298 avoid wrapping around the end of the file.
9299
9300 When a match for {start}, {middle} or {end} is found, the
9301 {skip} expression is evaluated with the cursor positioned on
9302 the start of the match. It should return non-zero if this
9303 match is to be skipped. E.g., because it is inside a comment
9304 or a string.
9305 When {skip} is omitted or empty, every match is accepted.
9306 When evaluating {skip} causes an error the search is aborted
9307 and -1 returned.
9308 {skip} can be a string, a lambda, a funcref or a partial.
9309 Anything else makes the function fail.
9310 In a `:def` function when the {skip} argument is a string
9311 constant it is compiled into instructions.
9312
9313 For {stopline} and {timeout} see |search()|.
9314
9315 The value of 'ignorecase' is used. 'magic' is ignored, the
9316 patterns are used like it's on.
9317
9318 The search starts exactly at the cursor. A match with
9319 {start}, {middle} or {end} at the next character, in the
9320 direction of searching, is the first one found. Example: >
9321 if 1
9322 if 2
9323 endif 2
9324 endif 1
9325< When starting at the "if 2", with the cursor on the "i", and
9326 searching forwards, the "endif 2" is found. When starting on
9327 the character just before the "if 2", the "endif 1" will be
9328 found. That's because the "if 2" will be found first, and
9329 then this is considered to be a nested if/endif from "if 2" to
9330 "endif 2".
9331 When searching backwards and {end} is more than one character,
9332 it may be useful to put "\zs" at the end of the pattern, so
9333 that when the cursor is inside a match with the end it finds
9334 the matching start.
9335
9336 Example, to find the "endif" command in a Vim script: >
9337
9338 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9339 \ 'getline(".") =~ "^\\s*\""')
9340
9341< The cursor must be at or after the "if" for which a match is
9342 to be found. Note that single-quote strings are used to avoid
9343 having to double the backslashes. The skip expression only
9344 catches comments at the start of a line, not after a command.
9345 Also, a word "en" or "if" halfway a line is considered a
9346 match.
9347 Another example, to search for the matching "{" of a "}": >
9348
9349 :echo searchpair('{', '', '}', 'bW')
9350
9351< This works when the cursor is at or before the "}" for which a
9352 match is to be found. To reject matches that syntax
9353 highlighting recognized as strings: >
9354
9355 :echo searchpair('{', '', '}', 'bW',
9356 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9357<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009358 Return type: |Number|
9359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009360 *searchpairpos()*
9361searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9362 [, {stopline} [, {timeout}]]]])
9363 Same as |searchpair()|, but returns a |List| with the line and
9364 column position of the match. The first element of the |List|
9365 is the line number and the second element is the byte index of
9366 the column position of the match. If no match is found,
9367 returns [0, 0]. >
9368
9369 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9370<
9371 See |match-parens| for a bigger and more useful example.
9372
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009373 Return type: list<number>
9374
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009375 *searchpos()*
9376searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9377 Same as |search()|, but returns a |List| with the line and
9378 column position of the match. The first element of the |List|
9379 is the line number and the second element is the byte index of
9380 the column position of the match. If no match is found,
9381 returns [0, 0].
9382 Example: >
9383 :let [lnum, col] = searchpos('mypattern', 'n')
9384
9385< When the 'p' flag is given then there is an extra item with
9386 the sub-pattern match number |search()-sub-match|. Example: >
9387 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9388< In this example "submatch" is 2 when a lowercase letter is
9389 found |/\l|, 3 when an uppercase letter is found |/\u|.
9390
9391 Can also be used as a |method|: >
9392 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009393<
9394 Return type: list<number>
9395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009396
9397server2client({clientid}, {string}) *server2client()*
9398 Send a reply string to {clientid}. The most recent {clientid}
9399 that sent a string can be retrieved with expand("<client>").
9400 {only available when compiled with the |+clientserver| feature}
9401 Returns zero for success, -1 for failure.
9402 Note:
9403 This id has to be stored before the next command can be
9404 received. I.e. before returning from the received command and
9405 before calling any commands that waits for input.
9406 See also |clientserver|.
9407 Example: >
9408 :echo server2client(expand("<client>"), "HELLO")
9409
9410< Can also be used as a |method|: >
9411 GetClientId()->server2client(string)
9412<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009413 Return type: |Number|
9414
9415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009416serverlist() *serverlist()*
9417 Return a list of available server names, one per line.
9418 When there are no servers or the information is not available
9419 an empty string is returned. See also |clientserver|.
9420 {only available when compiled with the |+clientserver| feature}
9421 Example: >
9422 :echo serverlist()
9423<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009424 Return type: |String|
9425
9426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009427setbufline({buf}, {lnum}, {text}) *setbufline()*
9428 Set line {lnum} to {text} in buffer {buf}. This works like
9429 |setline()| for the specified buffer.
9430
9431 This function works only for loaded buffers. First call
9432 |bufload()| if needed.
9433
9434 To insert lines use |appendbufline()|.
9435 Any text properties in {lnum} are cleared.
9436
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009437 {text} can be a string to set one line, or a List of strings
9438 to set multiple lines. If the List extends below the last
9439 line then those lines are added. If the List is empty then
9440 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009441
9442 For the use of {buf}, see |bufname()| above.
9443
9444 {lnum} is used like with |setline()|.
9445 Use "$" to refer to the last line in buffer {buf}.
9446 When {lnum} is just below the last line the {text} will be
9447 added below the last line.
9448
9449 When {buf} is not a valid buffer, the buffer is not loaded or
9450 {lnum} is not valid then 1 is returned. In |Vim9| script an
9451 error is given.
9452 On success 0 is returned.
9453
9454 Can also be used as a |method|, the base is passed as the
9455 third argument: >
9456 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009457<
9458 Return type: |Number|
9459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009460
9461setbufvar({buf}, {varname}, {val}) *setbufvar()*
9462 Set option or local variable {varname} in buffer {buf} to
9463 {val}.
9464 This also works for a global or local window option, but it
9465 doesn't work for a global or local window variable.
9466 For a local window option the global value is unchanged.
9467 For the use of {buf}, see |bufname()| above.
9468 The {varname} argument is a string.
9469 Note that the variable name without "b:" must be used.
9470 Examples: >
9471 :call setbufvar(1, "&mod", 1)
9472 :call setbufvar("todo", "myvar", "foobar")
9473< This function is not available in the |sandbox|.
9474
9475 Can also be used as a |method|, the base is passed as the
9476 third argument: >
9477 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009478<
9479 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009480
9481
9482setcellwidths({list}) *setcellwidths()*
9483 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009484 tells Vim how wide characters are when displayed in the
9485 terminal, counted in screen cells. The values override
9486 'ambiwidth'. Example: >
9487 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009488 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009489 \ [0x2194, 0x2199, 2],
9490 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009491
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009492< The {list} argument is a List of Lists with each three
9493 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9494 {low} and {high} can be the same, in which case this refers to
9495 one character. Otherwise it is the range of characters from
9496 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009497 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009498
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009499 {width} must be either 1 or 2, indicating the character width
9500 in screen cells. *E1112*
9501 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009502 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009504 If the new value causes 'fillchars' or 'listchars' to become
9505 invalid it is rejected and an error is given.
9506
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009507 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009508 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009510< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009511 the effect for known emoji characters. Move the cursor
9512 through the text to check if the cell widths of your terminal
9513 match with what Vim knows about each emoji. If it doesn't
9514 look right you need to adjust the {list} argument.
9515
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009516 Return type: |Number|
9517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009518
9519setcharpos({expr}, {list}) *setcharpos()*
9520 Same as |setpos()| but uses the specified column number as the
9521 character index instead of the byte index in the line.
9522
9523 Example:
9524 With the text "여보세요" in line 8: >
9525 call setcharpos('.', [0, 8, 4, 0])
9526< positions the cursor on the fourth character '요'. >
9527 call setpos('.', [0, 8, 4, 0])
9528< positions the cursor on the second character '보'.
9529
9530 Can also be used as a |method|: >
9531 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009532<
9533 Return type: |Number|
9534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009535
9536setcharsearch({dict}) *setcharsearch()*
9537 Set the current character search information to {dict},
9538 which contains one or more of the following entries:
9539
9540 char character which will be used for a subsequent
9541 |,| or |;| command; an empty string clears the
9542 character search
9543 forward direction of character search; 1 for forward,
9544 0 for backward
9545 until type of character search; 1 for a |t| or |T|
9546 character search, 0 for an |f| or |F|
9547 character search
9548
9549 This can be useful to save/restore a user's character search
9550 from a script: >
9551 :let prevsearch = getcharsearch()
9552 :" Perform a command which clobbers user's search
9553 :call setcharsearch(prevsearch)
9554< Also see |getcharsearch()|.
9555
9556 Can also be used as a |method|: >
9557 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009558<
9559 Return type: dict<any>
9560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009561
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009562setcmdline({str} [, {pos}]) *setcmdline()*
9563 Set the command line to {str} and set the cursor position to
9564 {pos}.
9565 If {pos} is omitted, the cursor is positioned after the text.
9566 Returns 0 when successful, 1 when not editing the command
9567 line.
9568
9569 Can also be used as a |method|: >
9570 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009571<
9572 Return type: |Number|
9573
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009574
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009575setcmdpos({pos}) *setcmdpos()*
9576 Set the cursor position in the command line to byte position
9577 {pos}. The first position is 1.
9578 Use |getcmdpos()| to obtain the current position.
9579 Only works while editing the command line, thus you must use
9580 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9581 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9582 set after the command line is set to the expression. For
9583 |c_CTRL-R_=| it is set after evaluating the expression but
9584 before inserting the resulting text.
9585 When the number is too big the cursor is put at the end of the
9586 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009587 Returns 0 when successful, 1 when not editing the command
9588 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009589
9590 Can also be used as a |method|: >
9591 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009592<
9593 Return type: |Number|
9594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009595
9596setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9597setcursorcharpos({list})
9598 Same as |cursor()| but uses the specified column number as the
9599 character index instead of the byte index in the line.
9600
9601 Example:
9602 With the text "여보세요" in line 4: >
9603 call setcursorcharpos(4, 3)
9604< positions the cursor on the third character '세'. >
9605 call cursor(4, 3)
9606< positions the cursor on the first character '여'.
9607
9608 Can also be used as a |method|: >
9609 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009610<
9611 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009612
9613
9614setenv({name}, {val}) *setenv()*
9615 Set environment variable {name} to {val}. Example: >
9616 call setenv('HOME', '/home/myhome')
9617
9618< When {val} is |v:null| the environment variable is deleted.
9619 See also |expr-env|.
9620
9621 Can also be used as a |method|, the base is passed as the
9622 second argument: >
9623 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009624<
9625 Return type: |Number|
9626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009627
9628setfperm({fname}, {mode}) *setfperm()* *chmod*
9629 Set the file permissions for {fname} to {mode}.
9630 {mode} must be a string with 9 characters. It is of the form
9631 "rwxrwxrwx", where each group of "rwx" flags represent, in
9632 turn, the permissions of the owner of the file, the group the
9633 file belongs to, and other users. A '-' character means the
9634 permission is off, any other character means on. Multi-byte
9635 characters are not supported.
9636
9637 For example "rw-r-----" means read-write for the user,
9638 readable by the group, not accessible by others. "xx-x-----"
9639 would do the same thing.
9640
9641 Returns non-zero for success, zero for failure.
9642
9643 Can also be used as a |method|: >
9644 GetFilename()->setfperm(mode)
9645<
9646 To read permissions see |getfperm()|.
9647
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009648 Return type: |Number|
9649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009650
9651setline({lnum}, {text}) *setline()*
9652 Set line {lnum} of the current buffer to {text}. To insert
9653 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009654 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009655 Any text properties in {lnum} are cleared. See
9656 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009657
9658 {lnum} is used like with |getline()|.
9659 When {lnum} is just below the last line the {text} will be
9660 added below the last line.
9661 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009662 converted to a String. When {text} is an empty List then
9663 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009664
9665 If this succeeds, FALSE is returned. If this fails (most likely
9666 because {lnum} is invalid) TRUE is returned.
9667 In |Vim9| script an error is given if {lnum} is invalid.
9668
9669 Example: >
9670 :call setline(5, strftime("%c"))
9671
9672< When {text} is a |List| then line {lnum} and following lines
9673 will be set to the items in the list. Example: >
9674 :call setline(5, ['aaa', 'bbb', 'ccc'])
9675< This is equivalent to: >
9676 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9677 : call setline(n, l)
9678 :endfor
9679
9680< Note: The '[ and '] marks are not set.
9681
9682 Can also be used as a |method|, the base is passed as the
9683 second argument: >
9684 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009685<
9686 Return type: |Number|
9687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009688
9689setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9690 Create or replace or add to the location list for window {nr}.
9691 {nr} can be the window number or the |window-ID|.
9692 When {nr} is zero the current window is used.
9693
9694 For a location list window, the displayed location list is
9695 modified. For an invalid window number {nr}, -1 is returned.
9696 Otherwise, same as |setqflist()|.
9697 Also see |location-list|.
9698
9699 For {action} see |setqflist-action|.
9700
9701 If the optional {what} dictionary argument is supplied, then
9702 only the items listed in {what} are set. Refer to |setqflist()|
9703 for the list of supported keys in {what}.
9704
9705 Can also be used as a |method|, the base is passed as the
9706 second argument: >
9707 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009708<
9709 Return type: |Number|
9710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009711
9712setmatches({list} [, {win}]) *setmatches()*
9713 Restores a list of matches saved by |getmatches()| for the
9714 current window. Returns 0 if successful, otherwise -1. All
9715 current matches are cleared before the list is restored. See
9716 example for |getmatches()|.
9717 If {win} is specified, use the window with this number or
9718 window ID instead of the current window.
9719
9720 Can also be used as a |method|: >
9721 GetMatches()->setmatches()
9722<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009723 Return type: |Number|
9724
9725
9726setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009727 Set the position for String {expr}. Possible values:
9728 . the cursor
9729 'x mark x
9730
9731 {list} must be a |List| with four or five numbers:
9732 [bufnum, lnum, col, off]
9733 [bufnum, lnum, col, off, curswant]
9734
9735 "bufnum" is the buffer number. Zero can be used for the
9736 current buffer. When setting an uppercase mark "bufnum" is
9737 used for the mark position. For other marks it specifies the
9738 buffer to set the mark in. You can use the |bufnr()| function
9739 to turn a file name into a buffer number.
9740 For setting the cursor and the ' mark "bufnum" is ignored,
9741 since these are associated with a window, not a buffer.
9742 Does not change the jumplist.
9743
9744 "lnum" and "col" are the position in the buffer. The first
9745 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9746 smaller than 1 then 1 is used. To use the character count
9747 instead of the byte count, use |setcharpos()|.
9748
9749 The "off" number is only used when 'virtualedit' is set. Then
9750 it is the offset in screen columns from the start of the
9751 character. E.g., a position within a <Tab> or after the last
9752 character.
9753
9754 The "curswant" number is only used when setting the cursor
9755 position. It sets the preferred column for when moving the
9756 cursor vertically. When the "curswant" number is missing the
9757 preferred column is not set. When it is present and setting a
9758 mark position it is not used.
9759
9760 Note that for '< and '> changing the line number may result in
9761 the marks to be effectively be swapped, so that '< is always
9762 before '>.
9763
9764 Returns 0 when the position could be set, -1 otherwise.
9765 An error message is given if {expr} is invalid.
9766
9767 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9768
9769 This does not restore the preferred column for moving
9770 vertically; if you set the cursor position with this, |j| and
9771 |k| motions will jump to previous columns! Use |cursor()| to
9772 also set the preferred column. Also see the "curswant" key in
9773 |winrestview()|.
9774
9775 Can also be used as a |method|: >
9776 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009777<
9778 Return type: |Number|
9779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009780
9781setqflist({list} [, {action} [, {what}]]) *setqflist()*
9782 Create or replace or add to the quickfix list.
9783
9784 If the optional {what} dictionary argument is supplied, then
9785 only the items listed in {what} are set. The first {list}
9786 argument is ignored. See below for the supported items in
9787 {what}.
9788 *setqflist-what*
9789 When {what} is not present, the items in {list} are used. Each
9790 item must be a dictionary. Non-dictionary items in {list} are
9791 ignored. Each dictionary item can contain the following
9792 entries:
9793
9794 bufnr buffer number; must be the number of a valid
9795 buffer
9796 filename name of a file; only used when "bufnr" is not
9797 present or it is invalid.
9798 module name of a module; if given it will be used in
9799 quickfix error window instead of the filename.
9800 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009801 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009802 pattern search pattern used to locate the error
9803 col column number
9804 vcol when non-zero: "col" is visual column
9805 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009806 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009807 nr error number
9808 text description of the error
9809 type single-character error type, 'E', 'W', etc.
9810 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009811 user_data custom data associated with the item, can be
9812 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009813
9814 The "col", "vcol", "nr", "type" and "text" entries are
9815 optional. Either "lnum" or "pattern" entry can be used to
9816 locate a matching error line.
9817 If the "filename" and "bufnr" entries are not present or
9818 neither the "lnum" or "pattern" entries are present, then the
9819 item will not be handled as an error line.
9820 If both "pattern" and "lnum" are present then "pattern" will
9821 be used.
9822 If the "valid" entry is not supplied, then the valid flag is
9823 set when "bufnr" is a valid buffer or "filename" exists.
9824 If you supply an empty {list}, the quickfix list will be
9825 cleared.
9826 Note that the list is not exactly the same as what
9827 |getqflist()| returns.
9828
9829 {action} values: *setqflist-action* *E927*
9830 'a' The items from {list} are added to the existing
9831 quickfix list. If there is no existing list, then a
9832 new list is created.
9833
9834 'r' The items from the current quickfix list are replaced
9835 with the items from {list}. This can also be used to
9836 clear the list: >
9837 :call setqflist([], 'r')
9838<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009839 'u' Like 'r', but tries to preserve the current selection
9840 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009841 'f' All the quickfix lists in the quickfix stack are
9842 freed.
9843
9844 If {action} is not present or is set to ' ', then a new list
9845 is created. The new quickfix list is added after the current
9846 quickfix list in the stack and all the following lists are
9847 freed. To add a new quickfix list at the end of the stack,
9848 set "nr" in {what} to "$".
9849
9850 The following items can be specified in dictionary {what}:
9851 context quickfix list context. See |quickfix-context|
9852 efm errorformat to use when parsing text from
9853 "lines". If this is not present, then the
9854 'errorformat' option value is used.
9855 See |quickfix-parse|
9856 id quickfix list identifier |quickfix-ID|
9857 idx index of the current entry in the quickfix
9858 list specified by 'id' or 'nr'. If set to '$',
9859 then the last entry in the list is set as the
9860 current entry. See |quickfix-index|
9861 items list of quickfix entries. Same as the {list}
9862 argument.
9863 lines use 'errorformat' to parse a list of lines and
9864 add the resulting entries to the quickfix list
9865 {nr} or {id}. Only a |List| value is supported.
9866 See |quickfix-parse|
9867 nr list number in the quickfix stack; zero
9868 means the current quickfix list and "$" means
9869 the last quickfix list.
9870 quickfixtextfunc
9871 function to get the text to display in the
9872 quickfix window. The value can be the name of
9873 a function or a funcref or a lambda. Refer to
9874 |quickfix-window-function| for an explanation
9875 of how to write the function and an example.
9876 title quickfix list title text. See |quickfix-title|
9877 Unsupported keys in {what} are ignored.
9878 If the "nr" item is not present, then the current quickfix list
9879 is modified. When creating a new quickfix list, "nr" can be
9880 set to a value one greater than the quickfix stack size.
9881 When modifying a quickfix list, to guarantee that the correct
9882 list is modified, "id" should be used instead of "nr" to
9883 specify the list.
9884
9885 Examples (See also |setqflist-examples|): >
9886 :call setqflist([], 'r', {'title': 'My search'})
9887 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9888 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9889<
9890 Returns zero for success, -1 for failure.
9891
9892 This function can be used to create a quickfix list
9893 independent of the 'errorformat' setting. Use a command like
9894 `:cc 1` to jump to the first position.
9895
9896 Can also be used as a |method|, the base is passed as the
9897 second argument: >
9898 GetErrorlist()->setqflist()
9899<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009900 Return type: |Number|
9901
9902
9903setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009904 Set the register {regname} to {value}.
9905 If {regname} is "" or "@", the unnamed register '"' is used.
9906 The {regname} argument is a string. In |Vim9-script|
9907 {regname} must be one character.
9908
9909 {value} may be any value returned by |getreg()| or
9910 |getreginfo()|, including a |List| or |Dict|.
9911 If {options} contains "a" or {regname} is upper case,
9912 then the value is appended.
9913
9914 {options} can also contain a register type specification:
9915 "c" or "v" |characterwise| mode
9916 "l" or "V" |linewise| mode
9917 "b" or "<CTRL-V>" |blockwise-visual| mode
9918 If a number immediately follows "b" or "<CTRL-V>" then this is
9919 used as the width of the selection - if it is not specified
9920 then the width of the block is set to the number of characters
9921 in the longest line (counting a <Tab> as 1 character).
9922
9923 If {options} contains no register settings, then the default
9924 is to use character mode unless {value} ends in a <NL> for
9925 string {value} and linewise mode for list {value}. Blockwise
9926 mode is never selected automatically.
9927 Returns zero for success, non-zero for failure.
9928
9929 *E883*
9930 Note: you may not use |List| containing more than one item to
9931 set search and expression registers. Lists containing no
9932 items act like empty strings.
9933
9934 Examples: >
9935 :call setreg(v:register, @*)
9936 :call setreg('*', @%, 'ac')
9937 :call setreg('a', "1\n2\n3", 'b5')
9938 :call setreg('"', { 'points_to': 'a'})
9939
9940< This example shows using the functions to save and restore a
9941 register: >
9942 :let var_a = getreginfo()
9943 :call setreg('a', var_a)
9944< or: >
9945 :let var_a = getreg('a', 1, 1)
9946 :let var_amode = getregtype('a')
9947 ....
9948 :call setreg('a', var_a, var_amode)
9949< Note: you may not reliably restore register value
9950 without using the third argument to |getreg()| as without it
9951 newlines are represented as newlines AND Nul bytes are
9952 represented as newlines as well, see |NL-used-for-Nul|.
9953
9954 You can also change the type of a register by appending
9955 nothing: >
9956 :call setreg('a', '', 'al')
9957
9958< Can also be used as a |method|, the base is passed as the
9959 second argument: >
9960 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009961<
9962 Return type: |Number|
9963
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009964
9965settabvar({tabnr}, {varname}, {val}) *settabvar()*
9966 Set tab-local variable {varname} to {val} in tab page {tabnr}.
9967 |t:var|
9968 The {varname} argument is a string.
9969 Note that autocommands are blocked, side effects may not be
9970 triggered, e.g. when setting 'filetype'.
9971 Note that the variable name without "t:" must be used.
9972 Tabs are numbered starting with one.
9973 This function is not available in the |sandbox|.
9974
9975 Can also be used as a |method|, the base is passed as the
9976 third argument: >
9977 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009978<
9979 Return type: |Number|
9980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009981
9982settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
9983 Set option or local variable {varname} in window {winnr} to
9984 {val}.
9985 Tabs are numbered starting with one. For the current tabpage
9986 use |setwinvar()|.
9987 {winnr} can be the window number or the |window-ID|.
9988 When {winnr} is zero the current window is used.
9989 Note that autocommands are blocked, side effects may not be
9990 triggered, e.g. when setting 'filetype' or 'syntax'.
9991 This also works for a global or local buffer option, but it
9992 doesn't work for a global or local buffer variable.
9993 For a local buffer option the global value is unchanged.
9994 Note that the variable name without "w:" must be used.
9995 Examples: >
9996 :call settabwinvar(1, 1, "&list", 0)
9997 :call settabwinvar(3, 2, "myvar", "foobar")
9998< This function is not available in the |sandbox|.
9999
10000 Can also be used as a |method|, the base is passed as the
10001 fourth argument: >
10002 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010003<
10004 Return type: |Number|
10005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010006
10007settagstack({nr}, {dict} [, {action}]) *settagstack()*
10008 Modify the tag stack of the window {nr} using {dict}.
10009 {nr} can be the window number or the |window-ID|.
10010
10011 For a list of supported items in {dict}, refer to
10012 |gettagstack()|. "curidx" takes effect before changing the tag
10013 stack.
10014 *E962*
10015 How the tag stack is modified depends on the {action}
10016 argument:
10017 - If {action} is not present or is set to 'r', then the tag
10018 stack is replaced.
10019 - If {action} is set to 'a', then new entries from {dict} are
10020 pushed (added) onto the tag stack.
10021 - If {action} is set to 't', then all the entries from the
10022 current entry in the tag stack or "curidx" in {dict} are
10023 removed and then new entries are pushed to the stack.
10024
10025 The current index is set to one after the length of the tag
10026 stack after the modification.
10027
10028 Returns zero for success, -1 for failure.
10029
10030 Examples (for more examples see |tagstack-examples|):
10031 Empty the tag stack of window 3: >
10032 call settagstack(3, {'items' : []})
10033
10034< Save and restore the tag stack: >
10035 let stack = gettagstack(1003)
10036 " do something else
10037 call settagstack(1003, stack)
10038 unlet stack
10039<
10040 Can also be used as a |method|, the base is passed as the
10041 second argument: >
10042 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010043<
10044 Return type: |Number|
10045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010046
10047setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10048 Like |settabwinvar()| for the current tab page.
10049 Examples: >
10050 :call setwinvar(1, "&list", 0)
10051 :call setwinvar(2, "myvar", "foobar")
10052
10053< Can also be used as a |method|, the base is passed as the
10054 third argument: >
10055 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010056<
10057 Return type: |Number|
10058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010059
10060sha256({string}) *sha256()*
10061 Returns a String with 64 hex characters, which is the SHA256
10062 checksum of {string}.
10063
10064 Can also be used as a |method|: >
10065 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010066<
10067 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010068
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010069 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010070
10071shellescape({string} [, {special}]) *shellescape()*
10072 Escape {string} for use as a shell command argument.
10073 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010074 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010075 in single quotes and will double up all internal single
10076 quotes.
10077 On MS-Windows, when 'shellslash' is not set, it will enclose
10078 {string} in double quotes and double all double quotes within
10079 {string}.
10080 Otherwise it will enclose {string} in single quotes and
10081 replace all "'" with "'\''".
10082
Enno5faeb602024-05-15 21:54:19 +020010083 The {special} argument adds additional escaping of keywords
10084 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010085 number or a non-empty String (|non-zero-arg|), then special
10086 items such as "!", "%", "#" and "<cword>" (as listed in
10087 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010088 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010089
10090 The "!" character will be escaped (again with a |non-zero-arg|
10091 {special}) when 'shell' contains "csh" in the tail. That is
10092 because for csh and tcsh "!" is used for history replacement
10093 even when inside single quotes.
10094
10095 With a |non-zero-arg| {special} the <NL> character is also
10096 escaped. When 'shell' containing "csh" in the tail it's
10097 escaped a second time.
10098
10099 The "\" character will be escaped when 'shell' contains "fish"
10100 in the tail. That is because for fish "\" is used as an escape
10101 character inside single quotes.
10102
10103 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010104 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010105< This results in a directory listing for the file under the
10106 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010107 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010108< See also |::S|.
10109
10110 Can also be used as a |method|: >
10111 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010112<
10113 Return type: |String|
10114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010115
10116shiftwidth([{col}]) *shiftwidth()*
10117 Returns the effective value of 'shiftwidth'. This is the
10118 'shiftwidth' value unless it is zero, in which case it is the
10119 'tabstop' value. This function was introduced with patch
10120 7.3.694 in 2012, everybody should have it by now (however it
10121 did not allow for the optional {col} argument until 8.1.542).
10122
10123 When there is one argument {col} this is used as column number
10124 for which to return the 'shiftwidth' value. This matters for the
10125 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10126 no {col} argument is given, column 1 will be assumed.
10127
10128 Can also be used as a |method|: >
10129 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010130<
10131 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010132
10133sign_ functions are documented here: |sign-functions-details|
10134
10135
10136simplify({filename}) *simplify()*
10137 Simplify the file name as much as possible without changing
10138 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10139 Unix) are not resolved. If the first path component in
10140 {filename} designates the current directory, this will be
10141 valid for the result as well. A trailing path separator is
10142 not removed either. On Unix "//path" is unchanged, but
10143 "///path" is simplified to "/path" (this follows the Posix
10144 standard).
10145 Example: >
10146 simplify("./dir/.././/file/") == "./file/"
10147< Note: The combination "dir/.." is only removed if "dir" is
10148 a searchable directory or does not exist. On Unix, it is also
10149 removed when "dir" is a symbolic link within the same
10150 directory. In order to resolve all the involved symbolic
10151 links before simplifying the path name, use |resolve()|.
10152
10153 Can also be used as a |method|: >
10154 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010155<
10156 Return type: |String|
10157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010158
10159sin({expr}) *sin()*
10160 Return the sine of {expr}, measured in radians, as a |Float|.
10161 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010162 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010163 Examples: >
10164 :echo sin(100)
10165< -0.506366 >
10166 :echo sin(-4.01)
10167< 0.763301
10168
10169 Can also be used as a |method|: >
10170 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010171<
10172 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010173
10174
10175sinh({expr}) *sinh()*
10176 Return the hyperbolic sine of {expr} as a |Float| in the range
10177 [-inf, inf].
10178 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010179 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010180 Examples: >
10181 :echo sinh(0.5)
10182< 0.521095 >
10183 :echo sinh(-0.9)
10184< -1.026517
10185
10186 Can also be used as a |method|: >
10187 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010188<
10189 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010190
10191
10192slice({expr}, {start} [, {end}]) *slice()*
10193 Similar to using a |slice| "expr[start : end]", but "end" is
10194 used exclusive. And for a string the indexes are used as
10195 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010196 |vim9script|. Also, composing characters are treated as a
10197 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010198 When {end} is omitted the slice continues to the last item.
10199 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010200 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010201
10202 Can also be used as a |method|: >
10203 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010204<
10205 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010206
10207
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010208sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010209 Sort the items in {list} in-place. Returns {list}.
10210
10211 If you want a list to remain unmodified make a copy first: >
10212 :let sortedlist = sort(copy(mylist))
10213
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010214< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010215 string representation of each item to sort on. Numbers sort
10216 after Strings, |Lists| after Numbers. For sorting text in the
10217 current buffer use |:sort|.
10218
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010219 When {how} is given and it is 'i' then case is ignored.
10220 In legacy script, for backwards compatibility, the value one
10221 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010222
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010223 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010224 locale is used for ordering. Implementation details: strcoll()
10225 is used to compare strings. See |:language| check or set the
10226 collation locale. |v:collate| can also be used to check the
10227 current locale. Sorting using the locale typically ignores
10228 case. Example: >
10229 " ö is sorted similarly to o with English locale.
10230 :language collate en_US.UTF8
10231 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10232< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10233>
10234 " ö is sorted after z with Swedish locale.
10235 :language collate sv_SE.UTF8
10236 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10237< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10238 This does not work properly on Mac.
10239
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010240 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010241 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010242 strtod() function to parse numbers. Strings, Lists, Dicts and
10243 Funcrefs will be considered as being 0). Note that this won't
10244 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010245
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010246 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010247 sorted numerical. This is like 'n' but a string containing
10248 digits will be used as the number they represent.
10249
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010250 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010251 sorted numerical. All values must be a Number or a Float.
10252
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010253 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010254 is called to compare items. The function is invoked with two
10255 items as argument and must return zero if they are equal, 1 or
10256 bigger if the first one sorts after the second one, -1 or
10257 smaller if the first one sorts before the second one.
10258
10259 {dict} is for functions with the "dict" attribute. It will be
10260 used to set the local variable "self". |Dictionary-function|
10261
10262 The sort is stable, items which compare equal (as number or as
10263 string) will keep their relative position. E.g., when sorting
10264 on numbers, text strings will sort next to each other, in the
10265 same order as they were originally.
10266
10267 Can also be used as a |method|: >
10268 mylist->sort()
10269
10270< Also see |uniq()|.
10271
10272 Example: >
10273 func MyCompare(i1, i2)
10274 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10275 endfunc
10276 eval mylist->sort("MyCompare")
10277< A shorter compare version for this specific simple case, which
10278 ignores overflow: >
10279 func MyCompare(i1, i2)
10280 return a:i1 - a:i2
10281 endfunc
10282< For a simple expression you can use a lambda: >
10283 eval mylist->sort({i1, i2 -> i1 - i2})
10284<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010285 Return type: list<{type}>
10286
10287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010288sound_clear() *sound_clear()*
10289 Stop playing all sounds.
10290
10291 On some Linux systems you may need the libcanberra-pulse
10292 package, otherwise sound may not stop.
10293
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010294 Return type: |Number|
10295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010296 {only available when compiled with the |+sound| feature}
10297
10298 *sound_playevent()*
10299sound_playevent({name} [, {callback}])
10300 Play a sound identified by {name}. Which event names are
10301 supported depends on the system. Often the XDG sound names
10302 are used. On Ubuntu they may be found in
10303 /usr/share/sounds/freedesktop/stereo. Example: >
10304 call sound_playevent('bell')
10305< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10306 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10307 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010308 On macOS, {name} refers to files located in
10309 /System/Library/Sounds (e.g. "Tink"). It will also work for
10310 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010311
10312 When {callback} is specified it is invoked when the sound is
10313 finished. The first argument is the sound ID, the second
10314 argument is the status:
10315 0 sound was played to the end
10316 1 sound was interrupted
10317 2 error occurred after sound started
10318 Example: >
10319 func Callback(id, status)
10320 echomsg "sound " .. a:id .. " finished with " .. a:status
10321 endfunc
10322 call sound_playevent('bell', 'Callback')
10323
10324< MS-Windows: {callback} doesn't work for this function.
10325
10326 Returns the sound ID, which can be passed to `sound_stop()`.
10327 Returns zero if the sound could not be played.
10328
10329 Can also be used as a |method|: >
10330 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010331<
10332 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010333
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010334 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010335
10336 *sound_playfile()*
10337sound_playfile({path} [, {callback}])
10338 Like `sound_playevent()` but play sound file {path}. {path}
10339 must be a full path. On Ubuntu you may find files to play
10340 with this command: >
10341 :!find /usr/share/sounds -type f | grep -v index.theme
10342
10343< Can also be used as a |method|: >
10344 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010345<
10346 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010347
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010348 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010349
10350
10351sound_stop({id}) *sound_stop()*
10352 Stop playing sound {id}. {id} must be previously returned by
10353 `sound_playevent()` or `sound_playfile()`.
10354
10355 On some Linux systems you may need the libcanberra-pulse
10356 package, otherwise sound may not stop.
10357
10358 On MS-Windows, this does not work for event sound started by
10359 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10360
10361 Can also be used as a |method|: >
10362 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010363<
10364 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010365
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010366 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010367
10368 *soundfold()*
10369soundfold({word})
10370 Return the sound-folded equivalent of {word}. Uses the first
10371 language in 'spelllang' for the current window that supports
10372 soundfolding. 'spell' must be set. When no sound folding is
10373 possible the {word} is returned unmodified.
10374 This can be used for making spelling suggestions. Note that
10375 the method can be quite slow.
10376
10377 Can also be used as a |method|: >
10378 GetWord()->soundfold()
10379<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010380 Return type: |String|
10381
10382
10383spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010384 Without argument: The result is the badly spelled word under
10385 or after the cursor. The cursor is moved to the start of the
10386 bad word. When no bad word is found in the cursor line the
10387 result is an empty string and the cursor doesn't move.
10388
10389 With argument: The result is the first word in {sentence} that
10390 is badly spelled. If there are no spelling mistakes the
10391 result is an empty string.
10392
10393 The return value is a list with two items:
10394 - The badly spelled word or an empty string.
10395 - The type of the spelling error:
10396 "bad" spelling mistake
10397 "rare" rare word
10398 "local" word only valid in another region
10399 "caps" word should start with Capital
10400 Example: >
10401 echo spellbadword("the quik brown fox")
10402< ['quik', 'bad'] ~
10403
10404 The spelling information for the current window and the value
10405 of 'spelllang' are used.
10406
10407 Can also be used as a |method|: >
10408 GetText()->spellbadword()
10409<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010410 Return type: list<string>
10411
10412
10413spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010414 Return a |List| with spelling suggestions to replace {word}.
10415 When {max} is given up to this number of suggestions are
10416 returned. Otherwise up to 25 suggestions are returned.
10417
10418 When the {capital} argument is given and it's non-zero only
10419 suggestions with a leading capital will be given. Use this
10420 after a match with 'spellcapcheck'.
10421
10422 {word} can be a badly spelled word followed by other text.
10423 This allows for joining two words that were split. The
10424 suggestions also include the following text, thus you can
10425 replace a line.
10426
10427 {word} may also be a good word. Similar words will then be
10428 returned. {word} itself is not included in the suggestions,
10429 although it may appear capitalized.
10430
10431 The spelling information for the current window is used. The
10432 values of 'spelllang' and 'spellsuggest' are used.
10433
10434 Can also be used as a |method|: >
10435 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010436<
10437 Return type: list<string> or list<any>
10438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010439
10440split({string} [, {pattern} [, {keepempty}]]) *split()*
10441 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010442 empty each white space separated sequence of characters
10443 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010444 Otherwise the string is split where {pattern} matches,
10445 removing the matched characters. 'ignorecase' is not used
10446 here, add \c to ignore case. |/\c|
10447 When the first or last item is empty it is omitted, unless the
10448 {keepempty} argument is given and it's non-zero.
10449 Other empty items are kept when {pattern} matches at least one
10450 character or when {keepempty} is non-zero.
10451 Example: >
10452 :let words = split(getline('.'), '\W\+')
10453< To split a string in individual characters: >
10454 :for c in split(mystring, '\zs')
10455< If you want to keep the separator you can also use '\zs' at
10456 the end of the pattern: >
10457 :echo split('abc:def:ghi', ':\zs')
10458< ['abc:', 'def:', 'ghi'] ~
10459 Splitting a table where the first element can be empty: >
10460 :let items = split(line, ':', 1)
10461< The opposite function is |join()|.
10462
10463 Can also be used as a |method|: >
10464 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010465<
10466 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010467
10468sqrt({expr}) *sqrt()*
10469 Return the non-negative square root of Float {expr} as a
10470 |Float|.
10471 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010472 is negative the result is NaN (Not a Number). Returns 0.0 if
10473 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010474 Examples: >
10475 :echo sqrt(100)
10476< 10.0 >
10477 :echo sqrt(-4.01)
10478< nan
10479 "nan" may be different, it depends on system libraries.
10480
10481 Can also be used as a |method|: >
10482 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010483<
10484 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010485
10486
10487srand([{expr}]) *srand()*
10488 Initialize seed used by |rand()|:
10489 - If {expr} is not given, seed values are initialized by
10490 reading from /dev/urandom, if possible, or using time(NULL)
10491 a.k.a. epoch time otherwise; this only has second accuracy.
10492 - If {expr} is given it must be a Number. It is used to
10493 initialize the seed values. This is useful for testing or
10494 when a predictable sequence is intended.
10495
10496 Examples: >
10497 :let seed = srand()
10498 :let seed = srand(userinput)
10499 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010500<
10501 Return type: list<number>
10502
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010503
10504state([{what}]) *state()*
10505 Return a string which contains characters indicating the
10506 current state. Mostly useful in callbacks that want to do
10507 work that may not always be safe. Roughly this works like:
10508 - callback uses state() to check if work is safe to do.
10509 Yes: then do it right away.
10510 No: add to work queue and add a |SafeState| and/or
10511 |SafeStateAgain| autocommand (|SafeState| triggers at
10512 toplevel, |SafeStateAgain| triggers after handling
10513 messages and callbacks).
10514 - When SafeState or SafeStateAgain is triggered and executes
10515 your autocommand, check with `state()` if the work can be
10516 done now, and if yes remove it from the queue and execute.
10517 Remove the autocommand if the queue is now empty.
10518 Also see |mode()|.
10519
10520 When {what} is given only characters in this string will be
10521 added. E.g, this checks if the screen has scrolled: >
10522 if state('s') == ''
10523 " screen has not scrolled
10524<
10525 These characters indicate the state, generally indicating that
10526 something is busy:
10527 m halfway a mapping, :normal command, feedkeys() or
10528 stuffed command
10529 o operator pending, e.g. after |d|
10530 a Insert mode autocomplete active
10531 x executing an autocommand
10532 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10533 ch_readraw() when reading json
10534 S not triggering SafeState or SafeStateAgain, e.g. after
10535 |f| or a count
10536 c callback invoked, including timer (repeats for
10537 recursiveness up to "ccc")
10538 s screen has scrolled for messages
10539
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010540 Return type: |String|
10541
10542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010543str2float({string} [, {quoted}]) *str2float()*
10544 Convert String {string} to a Float. This mostly works the
10545 same as when using a floating point number in an expression,
10546 see |floating-point-format|. But it's a bit more permissive.
10547 E.g., "1e40" is accepted, while in an expression you need to
10548 write "1.0e40". The hexadecimal form "0x123" is also
10549 accepted, but not others, like binary or octal.
10550 When {quoted} is present and non-zero then embedded single
10551 quotes before the dot are ignored, thus "1'000.0" is a
10552 thousand.
10553 Text after the number is silently ignored.
10554 The decimal point is always '.', no matter what the locale is
10555 set to. A comma ends the number: "12,345.67" is converted to
10556 12.0. You can strip out thousands separators with
10557 |substitute()|: >
10558 let f = str2float(substitute(text, ',', '', 'g'))
10559<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010560 Returns 0.0 if the conversion fails.
10561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010562 Can also be used as a |method|: >
10563 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010564<
10565 Return type: |Float|
10566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010567
10568str2list({string} [, {utf8}]) *str2list()*
10569 Return a list containing the number values which represent
10570 each character in String {string}. Examples: >
10571 str2list(" ") returns [32]
10572 str2list("ABC") returns [65, 66, 67]
10573< |list2str()| does the opposite.
10574
10575 When {utf8} is omitted or zero, the current 'encoding' is used.
10576 When {utf8} is TRUE, always treat the String as UTF-8
10577 characters. With UTF-8 composing characters are handled
10578 properly: >
10579 str2list("á") returns [97, 769]
10580
10581< Can also be used as a |method|: >
10582 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010583<
10584 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010585
10586
10587str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10588 Convert string {string} to a number.
10589 {base} is the conversion base, it can be 2, 8, 10 or 16.
10590 When {quoted} is present and non-zero then embedded single
10591 quotes are ignored, thus "1'000'000" is a million.
10592
10593 When {base} is omitted base 10 is used. This also means that
10594 a leading zero doesn't cause octal conversion to be used, as
10595 with the default String to Number conversion. Example: >
10596 let nr = str2nr('0123')
10597<
10598 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10599 different base the result will be zero. Similarly, when
10600 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10601 {base} is 2 a leading "0b" or "0B" is ignored.
10602 Text after the number is silently ignored.
10603
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010604 Returns 0 if {string} is empty or on error.
10605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010606 Can also be used as a |method|: >
10607 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010608<
10609 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010610
10611
10612strcharlen({string}) *strcharlen()*
10613 The result is a Number, which is the number of characters
10614 in String {string}. Composing characters are ignored.
10615 |strchars()| can count the number of characters, counting
10616 composing characters separately.
10617
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010618 Returns 0 if {string} is empty or on error.
10619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010620 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10621
10622 Can also be used as a |method|: >
10623 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010624<
10625 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010626
10627
10628strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10629 Like |strpart()| but using character index and length instead
10630 of byte index and length.
10631 When {skipcc} is omitted or zero, composing characters are
10632 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010633 When {skipcc} set to 1, composing characters are treated as a
10634 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010635 When a character index is used where a character does not
10636 exist it is omitted and counted as one character. For
10637 example: >
10638 strcharpart('abc', -1, 2)
10639< results in 'a'.
10640
Bram Moolenaard592deb2022-06-17 15:42:40 +010010641 Returns an empty string on error.
10642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010643 Can also be used as a |method|: >
10644 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010645<
10646 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010647
10648
10649strchars({string} [, {skipcc}]) *strchars()*
10650 The result is a Number, which is the number of characters
10651 in String {string}.
10652 When {skipcc} is omitted or zero, composing characters are
10653 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010654 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010655 |strcharlen()| always does this.
10656
Bram Moolenaard592deb2022-06-17 15:42:40 +010010657 Returns zero on error.
10658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010659 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10660
10661 {skipcc} is only available after 7.4.755. For backward
10662 compatibility, you can define a wrapper function: >
10663 if has("patch-7.4.755")
10664 function s:strchars(str, skipcc)
10665 return strchars(a:str, a:skipcc)
10666 endfunction
10667 else
10668 function s:strchars(str, skipcc)
10669 if a:skipcc
10670 return strlen(substitute(a:str, ".", "x", "g"))
10671 else
10672 return strchars(a:str)
10673 endif
10674 endfunction
10675 endif
10676<
10677 Can also be used as a |method|: >
10678 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010679<
10680 Return type: |Number|
10681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010682
10683strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10684 The result is a Number, which is the number of display cells
10685 String {string} occupies on the screen when it starts at {col}
10686 (first column is zero). When {col} is omitted zero is used.
10687 Otherwise it is the screen column where to start. This
10688 matters for Tab characters.
10689 The option settings of the current window are used. This
10690 matters for anything that's displayed differently, such as
10691 'tabstop' and 'display'.
10692 When {string} contains characters with East Asian Width Class
10693 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010694 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010695 Also see |strlen()|, |strwidth()| and |strchars()|.
10696
10697 Can also be used as a |method|: >
10698 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010699<
10700 Return type: |Number|
10701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010702
10703strftime({format} [, {time}]) *strftime()*
10704 The result is a String, which is a formatted date and time, as
10705 specified by the {format} string. The given {time} is used,
10706 or the current time if no time is given. The accepted
10707 {format} depends on your system, thus this is not portable!
10708 See the manual page of the C function strftime() for the
10709 format. The maximum length of the result is 80 characters.
10710 See also |localtime()|, |getftime()| and |strptime()|.
10711 The language can be changed with the |:language| command.
10712 Examples: >
10713 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10714 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10715 :echo strftime("%y%m%d %T") 970427 11:53:55
10716 :echo strftime("%H:%M") 11:55
10717 :echo strftime("%c", getftime("file.c"))
10718 Show mod time of file.c.
10719< Not available on all systems. To check use: >
10720 :if exists("*strftime")
10721
10722< Can also be used as a |method|: >
10723 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010724<
10725 Return type: |String|
10726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010727
10728strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010729 Get a Number corresponding to the character at {index} in
10730 {str}. This uses a zero-based character index, not a byte
10731 index. Composing characters are considered separate
10732 characters here. Use |nr2char()| to convert the Number to a
10733 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010734 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010735 Also see |strcharpart()| and |strchars()|.
10736
10737 Can also be used as a |method|: >
10738 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010739<
10740 Return type: |Number|
10741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010742
10743stridx({haystack}, {needle} [, {start}]) *stridx()*
10744 The result is a Number, which gives the byte index in
10745 {haystack} of the first occurrence of the String {needle}.
10746 If {start} is specified, the search starts at index {start}.
10747 This can be used to find a second match: >
10748 :let colon1 = stridx(line, ":")
10749 :let colon2 = stridx(line, ":", colon1 + 1)
10750< The search is done case-sensitive.
10751 For pattern searches use |match()|.
10752 -1 is returned if the {needle} does not occur in {haystack}.
10753 See also |strridx()|.
10754 Examples: >
10755 :echo stridx("An Example", "Example") 3
10756 :echo stridx("Starting point", "Start") 0
10757 :echo stridx("Starting point", "start") -1
10758< *strstr()* *strchr()*
10759 stridx() works similar to the C function strstr(). When used
10760 with a single character it works similar to strchr().
10761
10762 Can also be used as a |method|: >
10763 GetHaystack()->stridx(needle)
10764<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010765 Return type: |Number|
10766
10767
10768string({expr}) *string()*
10769 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010770 Float, String, Blob or a composition of them, then the result
10771 can be parsed back with |eval()|.
10772 {expr} type result ~
10773 String 'string' (single quotes are doubled)
10774 Number 123
10775 Float 123.123456 or 1.123456e8
10776 Funcref function('name')
10777 Blob 0z00112233.44556677.8899
10778 List [item, item]
10779 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010780 Class class SomeName
10781 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010782 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010783 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010784
10785 When a |List| or |Dictionary| has a recursive reference it is
10786 replaced by "[...]" or "{...}". Using eval() on the result
10787 will then fail.
10788
mityu7f0bba22024-03-29 10:14:41 +010010789 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010790 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010791 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010793 Can also be used as a |method|: >
10794 mylist->string()
10795
10796< Also see |strtrans()|.
10797
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010798 Return type: |String|
10799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010800
10801strlen({string}) *strlen()*
10802 The result is a Number, which is the length of the String
10803 {string} in bytes.
10804 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010805 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010806 If you want to count the number of multibyte characters use
10807 |strchars()|.
10808 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10809
10810 Can also be used as a |method|: >
10811 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010812<
10813 Return type: |Number|
10814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010815
10816strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10817 The result is a String, which is part of {src}, starting from
10818 byte {start}, with the byte length {len}.
10819 When {chars} is present and TRUE then {len} is the number of
10820 characters positions (composing characters are not counted
10821 separately, thus "1" means one base character and any
10822 following composing characters).
10823 To count {start} as characters instead of bytes use
10824 |strcharpart()|.
10825
10826 When bytes are selected which do not exist, this doesn't
10827 result in an error, the bytes are simply omitted.
10828 If {len} is missing, the copy continues from {start} till the
10829 end of the {src}. >
10830 strpart("abcdefg", 3, 2) == "de"
10831 strpart("abcdefg", -2, 4) == "ab"
10832 strpart("abcdefg", 5, 4) == "fg"
10833 strpart("abcdefg", 3) == "defg"
10834
10835< Note: To get the first character, {start} must be 0. For
10836 example, to get the character under the cursor: >
10837 strpart(getline("."), col(".") - 1, 1, v:true)
10838<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010839 Returns an empty string on error.
10840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010841 Can also be used as a |method|: >
10842 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010843<
10844 Return type: |String|
10845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010846
10847strptime({format}, {timestring}) *strptime()*
10848 The result is a Number, which is a unix timestamp representing
10849 the date and time in {timestring}, which is expected to match
10850 the format specified in {format}.
10851
10852 The accepted {format} depends on your system, thus this is not
10853 portable! See the manual page of the C function strptime()
10854 for the format. Especially avoid "%c". The value of $TZ also
10855 matters.
10856
10857 If the {timestring} cannot be parsed with {format} zero is
10858 returned. If you do not know the format of {timestring} you
10859 can try different {format} values until you get a non-zero
10860 result.
10861
10862 See also |strftime()|.
10863 Examples: >
10864 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10865< 862156163 >
10866 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10867< Sun Apr 27 11:53:55 1997 >
10868 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10869< Sun Apr 27 12:53:55 1997
10870
10871 Can also be used as a |method|: >
10872 GetFormat()->strptime(timestring)
10873<
10874 Not available on all systems. To check use: >
10875 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010876<
10877 Return type: |Number|
10878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010879
10880strridx({haystack}, {needle} [, {start}]) *strridx()*
10881 The result is a Number, which gives the byte index in
10882 {haystack} of the last occurrence of the String {needle}.
10883 When {start} is specified, matches beyond this index are
10884 ignored. This can be used to find a match before a previous
10885 match: >
10886 :let lastcomma = strridx(line, ",")
10887 :let comma2 = strridx(line, ",", lastcomma - 1)
10888< The search is done case-sensitive.
10889 For pattern searches use |match()|.
10890 -1 is returned if the {needle} does not occur in {haystack}.
10891 If the {needle} is empty the length of {haystack} is returned.
10892 See also |stridx()|. Examples: >
10893 :echo strridx("an angry armadillo", "an") 3
10894< *strrchr()*
10895 When used with a single character it works similar to the C
10896 function strrchr().
10897
10898 Can also be used as a |method|: >
10899 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010900<
10901 Return type: |Number|
10902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010903
10904strtrans({string}) *strtrans()*
10905 The result is a String, which is {string} with all unprintable
10906 characters translated into printable characters |'isprint'|.
10907 Like they are shown in a window. Example: >
10908 echo strtrans(@a)
10909< This displays a newline in register a as "^@" instead of
10910 starting a new line.
10911
Bram Moolenaard592deb2022-06-17 15:42:40 +010010912 Returns an empty string on error.
10913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010914 Can also be used as a |method|: >
10915 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010916<
10917 Return type: |String|
10918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010919
Christian Brabandt67672ef2023-04-24 21:09:54 +010010920strutf16len({string} [, {countcc}]) *strutf16len()*
10921 The result is a Number, which is the number of UTF-16 code
10922 units in String {string} (after converting it to UTF-16).
10923
10924 When {countcc} is TRUE, composing characters are counted
10925 separately.
10926 When {countcc} is omitted or FALSE, composing characters are
10927 ignored.
10928
10929 Returns zero on error.
10930
10931 Also see |strlen()| and |strcharlen()|.
10932 Examples: >
10933 echo strutf16len('a') returns 1
10934 echo strutf16len('©') returns 1
10935 echo strutf16len('😊') returns 2
10936 echo strutf16len('ą́') returns 1
10937 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090010938<
Christian Brabandt67672ef2023-04-24 21:09:54 +010010939 Can also be used as a |method|: >
10940 GetText()->strutf16len()
10941<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010942 Return type: |Number|
10943
10944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010945strwidth({string}) *strwidth()*
10946 The result is a Number, which is the number of display cells
10947 String {string} occupies. A Tab character is counted as one
10948 cell, alternatively use |strdisplaywidth()|.
10949 When {string} contains characters with East Asian Width Class
10950 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010951 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010952 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
10953
10954 Can also be used as a |method|: >
10955 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010956<
10957 Return type: |Number|
10958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010959
10960submatch({nr} [, {list}]) *submatch()* *E935*
10961 Only for an expression in a |:substitute| command or
10962 substitute() function.
10963 Returns the {nr}'th submatch of the matched text. When {nr}
10964 is 0 the whole matched text is returned.
10965 Note that a NL in the string can stand for a line break of a
10966 multi-line match or a NUL character in the text.
10967 Also see |sub-replace-expression|.
10968
10969 If {list} is present and non-zero then submatch() returns
10970 a list of strings, similar to |getline()| with two arguments.
10971 NL characters in the text represent NUL characters in the
10972 text.
10973 Only returns more than one item for |:substitute|, inside
10974 |substitute()| this list will always contain one or zero
10975 items, since there are no real line breaks.
10976
10977 When substitute() is used recursively only the submatches in
10978 the current (deepest) call can be obtained.
10979
Bram Moolenaard592deb2022-06-17 15:42:40 +010010980 Returns an empty string or list on error.
10981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010982 Examples: >
10983 :s/\d\+/\=submatch(0) + 1/
10984 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
10985< This finds the first number in the line and adds one to it.
10986 A line break is included as a newline character.
10987
10988 Can also be used as a |method|: >
10989 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010990<
10991 Return type: |String| or list<string> depending on {list}
10992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010993
10994substitute({string}, {pat}, {sub}, {flags}) *substitute()*
10995 The result is a String, which is a copy of {string}, in which
10996 the first match of {pat} is replaced with {sub}.
10997 When {flags} is "g", all matches of {pat} in {string} are
10998 replaced. Otherwise {flags} should be "".
10999
11000 This works like the ":substitute" command (without any flags).
11001 But the matching with {pat} is always done like the 'magic'
11002 option is set and 'cpoptions' is empty (to make scripts
11003 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11004 if you want to ignore or match case and ignore 'ignorecase'.
11005 'smartcase' is not used. See |string-match| for how {pat} is
11006 used.
11007
11008 A "~" in {sub} is not replaced with the previous {sub}.
11009 Note that some codes in {sub} have a special meaning
11010 |sub-replace-special|. For example, to replace something with
11011 "\n" (two characters), use "\\\\n" or '\\n'.
11012
11013 When {pat} does not match in {string}, {string} is returned
11014 unmodified.
11015
11016 Example: >
11017 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11018< This removes the last component of the 'path' option. >
11019 :echo substitute("testing", ".*", "\\U\\0", "")
11020< results in "TESTING".
11021
11022 When {sub} starts with "\=", the remainder is interpreted as
11023 an expression. See |sub-replace-expression|. Example: >
11024 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011025 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011026
11027< When {sub} is a Funcref that function is called, with one
11028 optional argument. Example: >
11029 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11030< The optional argument is a list which contains the whole
11031 matched string and up to nine submatches, like what
11032 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011033 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011034
Bram Moolenaard592deb2022-06-17 15:42:40 +010011035< Returns an empty string on error.
11036
11037 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011038 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011039<
11040 Return type: |String|
11041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011042
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011043swapfilelist() *swapfilelist()*
11044 Returns a list of swap file names, like what "vim -r" shows.
11045 See the |-r| command argument. The 'directory' option is used
11046 for the directories to inspect. If you only want to get a
11047 list of swap files in the current directory then temporarily
11048 set 'directory' to a dot: >
11049 let save_dir = &directory
11050 let &directory = '.'
11051 let swapfiles = swapfilelist()
11052 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011053<
11054 Return type: list<string>
11055
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011057swapinfo({fname}) *swapinfo()*
11058 The result is a dictionary, which holds information about the
11059 swapfile {fname}. The available fields are:
11060 version Vim version
11061 user user name
11062 host host name
11063 fname original file name
11064 pid PID of the Vim process that created the swap
11065 file
11066 mtime last modification time in seconds
11067 inode Optional: INODE number of the file
11068 dirty 1 if file was modified, 0 if not
11069 Note that "user" and "host" are truncated to at most 39 bytes.
11070 In case of failure an "error" item is added with the reason:
11071 Cannot open file: file not found or in accessible
11072 Cannot read file: cannot read first block
11073 Not a swap file: does not contain correct block ID
11074 Magic number mismatch: Info in first block is invalid
11075
11076 Can also be used as a |method|: >
11077 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011078<
11079 Return type: dict<any> or dict<string>
11080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011081
11082swapname({buf}) *swapname()*
11083 The result is the swap file path of the buffer {expr}.
11084 For the use of {buf}, see |bufname()| above.
11085 If buffer {buf} is the current buffer, the result is equal to
11086 |:swapname| (unless there is no swap file).
11087 If buffer {buf} has no swap file, returns an empty string.
11088
11089 Can also be used as a |method|: >
11090 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011091<
11092 Return type: |String|
11093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011094
11095synID({lnum}, {col}, {trans}) *synID()*
11096 The result is a Number, which is the syntax ID at the position
11097 {lnum} and {col} in the current window.
11098 The syntax ID can be used with |synIDattr()| and
11099 |synIDtrans()| to obtain syntax information about text.
11100
11101 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11102 line. 'synmaxcol' applies, in a longer line zero is returned.
11103 Note that when the position is after the last character,
11104 that's where the cursor can be in Insert mode, synID() returns
11105 zero. {lnum} is used like with |getline()|.
11106
11107 When {trans} is |TRUE|, transparent items are reduced to the
11108 item that they reveal. This is useful when wanting to know
11109 the effective color. When {trans} is |FALSE|, the transparent
11110 item is returned. This is useful when wanting to know which
11111 syntax item is effective (e.g. inside parens).
11112 Warning: This function can be very slow. Best speed is
11113 obtained by going through the file in forward direction.
11114
Bram Moolenaard592deb2022-06-17 15:42:40 +010011115 Returns zero on error.
11116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011117 Example (echoes the name of the syntax item under the cursor): >
11118 :echo synIDattr(synID(line("."), col("."), 1), "name")
11119<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011120 Return type: |Number|
11121
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011122
11123synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11124 The result is a String, which is the {what} attribute of
11125 syntax ID {synID}. This can be used to obtain information
11126 about a syntax item.
11127 {mode} can be "gui", "cterm" or "term", to get the attributes
11128 for that mode. When {mode} is omitted, or an invalid value is
11129 used, the attributes for the currently active highlighting are
11130 used (GUI, cterm or term).
11131 Use synIDtrans() to follow linked highlight groups.
11132 {what} result
11133 "name" the name of the syntax item
11134 "fg" foreground color (GUI: color name used to set
11135 the color, cterm: color number as a string,
11136 term: empty string)
11137 "bg" background color (as with "fg")
11138 "font" font name (only available in the GUI)
11139 |highlight-font|
11140 "sp" special color for the GUI (as with "fg")
11141 |highlight-guisp|
11142 "ul" underline color for cterm: number as a string
11143 "fg#" like "fg", but for the GUI and the GUI is
11144 running the name in "#RRGGBB" form
11145 "bg#" like "fg#" for "bg"
11146 "sp#" like "fg#" for "sp"
11147 "bold" "1" if bold
11148 "italic" "1" if italic
11149 "reverse" "1" if reverse
11150 "inverse" "1" if inverse (= reverse)
11151 "standout" "1" if standout
11152 "underline" "1" if underlined
11153 "undercurl" "1" if undercurled
11154 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011155 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011156
Bram Moolenaard592deb2022-06-17 15:42:40 +010011157 Returns an empty string on error.
11158
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011159 Example (echoes the color of the syntax item under the
11160 cursor): >
11161 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11162<
11163 Can also be used as a |method|: >
11164 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011165<
11166 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011167
11168
11169synIDtrans({synID}) *synIDtrans()*
11170 The result is a Number, which is the translated syntax ID of
11171 {synID}. This is the syntax group ID of what is being used to
11172 highlight the character. Highlight links given with
11173 ":highlight link" are followed.
11174
Bram Moolenaard592deb2022-06-17 15:42:40 +010011175 Returns zero on error.
11176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011177 Can also be used as a |method|: >
11178 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011179<
11180 Return type: |Number|
11181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011182
11183synconcealed({lnum}, {col}) *synconcealed()*
11184 The result is a |List| with currently three items:
11185 1. The first item in the list is 0 if the character at the
11186 position {lnum} and {col} is not part of a concealable
11187 region, 1 if it is. {lnum} is used like with |getline()|.
11188 2. The second item in the list is a string. If the first item
11189 is 1, the second item contains the text which will be
11190 displayed in place of the concealed text, depending on the
11191 current setting of 'conceallevel' and 'listchars'.
11192 3. The third and final item in the list is a number
11193 representing the specific syntax region matched in the
11194 line. When the character is not concealed the value is
11195 zero. This allows detection of the beginning of a new
11196 concealable region if there are two consecutive regions
11197 with the same replacement character. For an example, if
11198 the text is "123456" and both "23" and "45" are concealed
11199 and replaced by the character "X", then:
11200 call returns ~
11201 synconcealed(lnum, 1) [0, '', 0]
11202 synconcealed(lnum, 2) [1, 'X', 1]
11203 synconcealed(lnum, 3) [1, 'X', 1]
11204 synconcealed(lnum, 4) [1, 'X', 2]
11205 synconcealed(lnum, 5) [1, 'X', 2]
11206 synconcealed(lnum, 6) [0, '', 0]
11207
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011208 Note: Doesn't consider |matchadd()| highlighting items,
11209 since syntax and matching highlighting are two different
11210 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011211
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011212 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011214
11215synstack({lnum}, {col}) *synstack()*
11216 Return a |List|, which is the stack of syntax items at the
11217 position {lnum} and {col} in the current window. {lnum} is
11218 used like with |getline()|. Each item in the List is an ID
11219 like what |synID()| returns.
11220 The first item in the List is the outer region, following are
11221 items contained in that one. The last one is what |synID()|
11222 returns, unless not the whole item is highlighted or it is a
11223 transparent item.
11224 This function is useful for debugging a syntax file.
11225 Example that shows the syntax stack under the cursor: >
11226 for id in synstack(line("."), col("."))
11227 echo synIDattr(id, "name")
11228 endfor
11229< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011230 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011231 character in a line and the first column in an empty line are
11232 valid positions.
11233
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011234 Return type: list<number> or list<any>
11235
11236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011237system({expr} [, {input}]) *system()* *E677*
11238 Get the output of the shell command {expr} as a |String|. See
11239 |systemlist()| to get the output as a |List|.
11240
11241 When {input} is given and is a |String| this string is written
11242 to a file and passed as stdin to the command. The string is
11243 written as-is, you need to take care of using the correct line
11244 separators yourself.
11245 If {input} is given and is a |List| it is written to the file
11246 in a way |writefile()| does with {binary} set to "b" (i.e.
11247 with a newline between each list item with newlines inside
11248 list items converted to NULs).
11249 When {input} is given and is a number that is a valid id for
11250 an existing buffer then the content of the buffer is written
11251 to the file line by line, each line terminated by a NL and
11252 NULs characters where the text has a NL.
11253
11254 Pipes are not used, the 'shelltemp' option is not used.
11255
11256 When prepended by |:silent| the terminal will not be set to
11257 cooked mode. This is meant to be used for commands that do
11258 not need the user to type. It avoids stray characters showing
11259 up on the screen which require |CTRL-L| to remove. >
11260 :silent let f = system('ls *.vim')
11261<
11262 Note: Use |shellescape()| or |::S| with |expand()| or
11263 |fnamemodify()| to escape special characters in a command
11264 argument. Newlines in {expr} may cause the command to fail.
11265 The characters in 'shellquote' and 'shellxquote' may also
11266 cause trouble.
11267 This is not to be used for interactive commands.
11268
11269 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011270 :let files = system('ls ' .. shellescape(expand('%:h')))
11271 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011272
11273< To make the result more system-independent, the shell output
11274 is filtered to replace <CR> with <NL> for Macintosh, and
11275 <CR><NL> with <NL> for DOS-like systems.
11276 To avoid the string being truncated at a NUL, all NUL
11277 characters are replaced with SOH (0x01).
11278
11279 The command executed is constructed using several options:
11280 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11281 ({tmp} is an automatically generated file name).
11282 For Unix, braces are put around {expr} to allow for
11283 concatenated commands.
11284
11285 The command will be executed in "cooked" mode, so that a
11286 CTRL-C will interrupt the command (on Unix at least).
11287
11288 The resulting error code can be found in |v:shell_error|.
11289 This function will fail in |restricted-mode|.
11290
11291 Note that any wrong value in the options mentioned above may
11292 make the function fail. It has also been reported to fail
11293 when using a security agent application.
11294 Unlike ":!cmd" there is no automatic check for changed files.
11295 Use |:checktime| to force a check.
11296
11297 Can also be used as a |method|: >
11298 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011299<
11300 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011301
11302
11303systemlist({expr} [, {input}]) *systemlist()*
11304 Same as |system()|, but returns a |List| with lines (parts of
11305 output separated by NL) with NULs transformed into NLs. Output
11306 is the same as |readfile()| will output with {binary} argument
11307 set to "b", except that there is no extra empty item when the
11308 result ends in a NL.
11309 Note that on MS-Windows you may get trailing CR characters.
11310
11311 To see the difference between "echo hello" and "echo -n hello"
11312 use |system()| and |split()|: >
11313 echo system('echo hello')->split('\n', 1)
11314<
11315 Returns an empty string on error.
11316
11317 Can also be used as a |method|: >
11318 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011319<
11320 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011321
11322
11323tabpagebuflist([{arg}]) *tabpagebuflist()*
11324 The result is a |List|, where each item is the number of the
11325 buffer associated with each window in the current tab page.
11326 {arg} specifies the number of the tab page to be used. When
11327 omitted the current tab page is used.
11328 When {arg} is invalid the number zero is returned.
11329 To get a list of all buffers in all tabs use this: >
11330 let buflist = []
11331 for i in range(tabpagenr('$'))
11332 call extend(buflist, tabpagebuflist(i + 1))
11333 endfor
11334< Note that a buffer may appear in more than one window.
11335
11336 Can also be used as a |method|: >
11337 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011338<
11339 Return type: list<number>
11340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011341
11342tabpagenr([{arg}]) *tabpagenr()*
11343 The result is a Number, which is the number of the current
11344 tab page. The first tab page has number 1.
11345
11346 The optional argument {arg} supports the following values:
11347 $ the number of the last tab page (the tab page
11348 count).
11349 # the number of the last accessed tab page
11350 (where |g<Tab>| goes to). if there is no
11351 previous tab page 0 is returned.
11352 The number can be used with the |:tab| command.
11353
Bram Moolenaard592deb2022-06-17 15:42:40 +010011354 Returns zero on error.
11355
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011356 Return type: |Number|
11357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011358
11359tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11360 Like |winnr()| but for tab page {tabarg}.
11361 {tabarg} specifies the number of tab page to be used.
11362 {arg} is used like with |winnr()|:
11363 - When omitted the current window number is returned. This is
11364 the window which will be used when going to this tab page.
11365 - When "$" the number of windows is returned.
11366 - When "#" the previous window nr is returned.
11367 Useful examples: >
11368 tabpagewinnr(1) " current window of tab page 1
11369 tabpagewinnr(4, '$') " number of windows in tab page 4
11370< When {tabarg} is invalid zero is returned.
11371
11372 Can also be used as a |method|: >
11373 GetTabpage()->tabpagewinnr()
11374<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011375 Return type: |Number|
11376
11377
11378tagfiles() *tagfiles()*
11379 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011380 for the current buffer. This is the 'tags' option expanded.
11381
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011382 Return type: list<string> or list<any>
11383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011384
11385taglist({expr} [, {filename}]) *taglist()*
11386 Returns a |List| of tags matching the regular expression {expr}.
11387
11388 If {filename} is passed it is used to prioritize the results
11389 in the same way that |:tselect| does. See |tag-priority|.
11390 {filename} should be the full path of the file.
11391
11392 Each list item is a dictionary with at least the following
11393 entries:
11394 name Name of the tag.
11395 filename Name of the file where the tag is
11396 defined. It is either relative to the
11397 current directory or a full path.
11398 cmd Ex command used to locate the tag in
11399 the file.
11400 kind Type of the tag. The value for this
11401 entry depends on the language specific
11402 kind values. Only available when
11403 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011404 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011405 static A file specific tag. Refer to
11406 |static-tag| for more information.
11407 More entries may be present, depending on the content of the
11408 tags file: access, implementation, inherits and signature.
11409 Refer to the ctags documentation for information about these
11410 fields. For C code the fields "struct", "class" and "enum"
11411 may appear, they give the name of the entity the tag is
11412 contained in.
11413
11414 The ex-command "cmd" can be either an ex search pattern, a
11415 line number or a line number followed by a byte number.
11416
11417 If there are no matching tags, then an empty list is returned.
11418
11419 To get an exact tag match, the anchors '^' and '$' should be
11420 used in {expr}. This also make the function work faster.
11421 Refer to |tag-regexp| for more information about the tag
11422 search regular expression pattern.
11423
11424 Refer to |'tags'| for information about how the tags file is
11425 located by Vim. Refer to |tags-file-format| for the format of
11426 the tags file generated by the different ctags tools.
11427
11428 Can also be used as a |method|: >
11429 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011430<
11431 Return type: list<dict<any>> or list<any>
11432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011433
11434tan({expr}) *tan()*
11435 Return the tangent of {expr}, measured in radians, as a |Float|
11436 in the range [-inf, inf].
11437 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011438 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011439 Examples: >
11440 :echo tan(10)
11441< 0.648361 >
11442 :echo tan(-4.01)
11443< -1.181502
11444
11445 Can also be used as a |method|: >
11446 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011447<
11448 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011449
11450
11451tanh({expr}) *tanh()*
11452 Return the hyperbolic tangent of {expr} as a |Float| in the
11453 range [-1, 1].
11454 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011455 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011456 Examples: >
11457 :echo tanh(0.5)
11458< 0.462117 >
11459 :echo tanh(-1)
11460< -0.761594
11461
11462 Can also be used as a |method|: >
11463 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011464<
11465 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011466
11467
11468tempname() *tempname()* *temp-file-name*
11469 The result is a String, which is the name of a file that
11470 doesn't exist. It can be used for a temporary file. The name
11471 is different for at least 26 consecutive calls. Example: >
11472 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011473 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011474< For Unix, the file will be in a private directory |tempfile|
11475 that is recursively deleted when Vim exits, on other systems
11476 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011477 For MS-Windows forward slashes are used when the 'shellslash'
11478 option is set, or when 'shellcmdflag' starts with '-' and
11479 'shell' does not contain powershell or pwsh.
11480
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011481 Return type: |String|
11482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011483
11484term_ functions are documented here: |terminal-function-details|
11485
11486
11487terminalprops() *terminalprops()*
11488 Returns a |Dictionary| with properties of the terminal that Vim
11489 detected from the response to |t_RV| request. See
11490 |v:termresponse| for the response itself. If |v:termresponse|
11491 is empty most values here will be 'u' for unknown.
11492 cursor_style whether sending |t_RS| works **
11493 cursor_blink_mode whether sending |t_RC| works **
11494 underline_rgb whether |t_8u| works **
11495 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011496 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011497
11498 ** value 'u' for unknown, 'y' for yes, 'n' for no
11499
11500 If the |+termresponse| feature is missing then the result is
11501 an empty dictionary.
11502
11503 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11504 current cursor style.
11505 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11506 request the cursor blink status.
11507 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11508 is not empty, Vim will detect the working of sending |t_RS|
11509 and |t_RC| on startup.
11510
11511 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11512 This avoids sending it to xterm, which would clear the colors.
11513
11514 For "mouse" the value 'u' is unknown
11515
11516 Also see:
11517 - 'ambiwidth' - detected by using |t_u7|.
11518 - |v:termstyleresp| and |v:termblinkresp| for the response to
11519 |t_RS| and |t_RC|.
11520
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011521 Return type: dict<string>
11522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011523
11524test_ functions are documented here: |test-functions-details|
11525
11526
11527 *timer_info()*
11528timer_info([{id}])
11529 Return a list with information about timers.
11530 When {id} is given only information about this timer is
11531 returned. When timer {id} does not exist an empty list is
11532 returned.
11533 When {id} is omitted information about all timers is returned.
11534
11535 For each timer the information is stored in a |Dictionary| with
11536 these items:
11537 "id" the timer ID
11538 "time" time the timer was started with
11539 "remaining" time until the timer fires
11540 "repeat" number of times the timer will still fire;
11541 -1 means forever
11542 "callback" the callback
11543 "paused" 1 if the timer is paused, 0 otherwise
11544
11545 Can also be used as a |method|: >
11546 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011547<
11548 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011549
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011550 {only available when compiled with the |+timers| feature}
11551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011552
11553timer_pause({timer}, {paused}) *timer_pause()*
11554 Pause or unpause a timer. A paused timer does not invoke its
11555 callback when its time expires. Unpausing a timer may cause
11556 the callback to be invoked almost immediately if enough time
11557 has passed.
11558
11559 Pausing a timer is useful to avoid the callback to be called
11560 for a short time.
11561
11562 If {paused} evaluates to a non-zero Number or a non-empty
11563 String, then the timer is paused, otherwise it is unpaused.
11564 See |non-zero-arg|.
11565
11566 Can also be used as a |method|: >
11567 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011568<
11569 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011570
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011571 {only available when compiled with the |+timers| feature}
11572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011573
11574 *timer_start()* *timer* *timers*
11575timer_start({time}, {callback} [, {options}])
11576 Create a timer and return the timer ID.
11577
11578 {time} is the waiting time in milliseconds. This is the
11579 minimum time before invoking the callback. When the system is
11580 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011581 Zero can be used to execute the callback when Vim is back in
11582 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011583
11584 {callback} is the function to call. It can be the name of a
11585 function or a |Funcref|. It is called with one argument, which
11586 is the timer ID. The callback is only invoked when Vim is
11587 waiting for input.
11588 If you want to show a message look at |popup_notification()|
11589 to avoid interfering with what the user is doing.
11590
11591 {options} is a dictionary. Supported entries:
11592 "repeat" Number of times to repeat calling the
11593 callback. -1 means forever. When not present
11594 the callback will be called once.
11595 If the timer causes an error three times in a
11596 row the repeat is cancelled. This avoids that
11597 Vim becomes unusable because of all the error
11598 messages.
11599
Bram Moolenaard592deb2022-06-17 15:42:40 +010011600 Returns -1 on error.
11601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011602 Example: >
11603 func MyHandler(timer)
11604 echo 'Handler called'
11605 endfunc
11606 let timer = timer_start(500, 'MyHandler',
11607 \ {'repeat': 3})
11608< This will invoke MyHandler() three times at 500 msec
11609 intervals.
11610
11611 Can also be used as a |method|: >
11612 GetMsec()->timer_start(callback)
11613
11614< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011615
11616 Return type: |Number|
11617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011618 {only available when compiled with the |+timers| feature}
11619
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011621timer_stop({timer}) *timer_stop()*
11622 Stop a timer. The timer callback will no longer be invoked.
11623 {timer} is an ID returned by timer_start(), thus it must be a
11624 Number. If {timer} does not exist there is no error.
11625
11626 Can also be used as a |method|: >
11627 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011628<
11629 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011630
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011631 {only available when compiled with the |+timers| feature}
11632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011633
11634timer_stopall() *timer_stopall()*
11635 Stop all timers. The timer callbacks will no longer be
11636 invoked. Useful if a timer is misbehaving. If there are no
11637 timers there is no error.
11638
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011639 Return type: |Number|
11640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011641 {only available when compiled with the |+timers| feature}
11642
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011644tolower({expr}) *tolower()*
11645 The result is a copy of the String given, with all uppercase
11646 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011647 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011648
11649 Can also be used as a |method|: >
11650 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011651<
11652 Return type: |String|
11653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011654
11655toupper({expr}) *toupper()*
11656 The result is a copy of the String given, with all lowercase
11657 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011658 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011659
11660 Can also be used as a |method|: >
11661 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011662<
11663 Return type: |String|
11664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011665
11666tr({src}, {fromstr}, {tostr}) *tr()*
11667 The result is a copy of the {src} string with all characters
11668 which appear in {fromstr} replaced by the character in that
11669 position in the {tostr} string. Thus the first character in
11670 {fromstr} is translated into the first character in {tostr}
11671 and so on. Exactly like the unix "tr" command.
11672 This code also deals with multibyte characters properly.
11673
Bram Moolenaard592deb2022-06-17 15:42:40 +010011674 Returns an empty string on error.
11675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011676 Examples: >
11677 echo tr("hello there", "ht", "HT")
11678< returns "Hello THere" >
11679 echo tr("<blob>", "<>", "{}")
11680< returns "{blob}"
11681
11682 Can also be used as a |method|: >
11683 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011684<
11685 Return type: |String|
11686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011687
11688trim({text} [, {mask} [, {dir}]]) *trim()*
11689 Return {text} as a String where any character in {mask} is
11690 removed from the beginning and/or end of {text}.
11691
Illia Bobyr80799172023-10-17 18:00:50 +020011692 If {mask} is not given, or is an empty string, {mask} is all
11693 characters up to 0x20, which includes Tab, space, NL and CR,
11694 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011695
11696 The optional {dir} argument specifies where to remove the
11697 characters:
11698 0 remove from the beginning and end of {text}
11699 1 remove only at the beginning of {text}
11700 2 remove only at the end of {text}
11701 When omitted both ends are trimmed.
11702
11703 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011704 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011705
11706 Examples: >
11707 echo trim(" some text ")
11708< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011709 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011710< returns "RESERVE_TAIL" >
11711 echo trim("rm<Xrm<>X>rrm", "rm<>")
11712< returns "Xrm<>X" (characters in the middle are not removed) >
11713 echo trim(" vim ", " ", 2)
11714< returns " vim"
11715
11716 Can also be used as a |method|: >
11717 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011718<
11719 Return type: |String|
11720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011721
11722trunc({expr}) *trunc()*
11723 Return the largest integral value with magnitude less than or
11724 equal to {expr} as a |Float| (truncate towards zero).
11725 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011726 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011727 Examples: >
11728 echo trunc(1.456)
11729< 1.0 >
11730 echo trunc(-5.456)
11731< -5.0 >
11732 echo trunc(4.0)
11733< 4.0
11734
11735 Can also be used as a |method|: >
11736 Compute()->trunc()
11737<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011738 Return type: |Float|
11739
11740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011741 *type()*
11742type({expr}) The result is a Number representing the type of {expr}.
11743 Instead of using the number directly, it is better to use the
11744 v:t_ variable that has the value:
11745 Number: 0 |v:t_number|
11746 String: 1 |v:t_string|
11747 Funcref: 2 |v:t_func|
11748 List: 3 |v:t_list|
11749 Dictionary: 4 |v:t_dict|
11750 Float: 5 |v:t_float|
11751 Boolean: 6 |v:t_bool| (v:false and v:true)
11752 None: 7 |v:t_none| (v:null and v:none)
11753 Job: 8 |v:t_job|
11754 Channel: 9 |v:t_channel|
11755 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011756 Class: 12 |v:t_class|
11757 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011758 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011759 Enum: 15 |v:t_enum|
11760 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011761 For backward compatibility, this method can be used: >
11762 :if type(myvar) == type(0)
11763 :if type(myvar) == type("")
11764 :if type(myvar) == type(function("tr"))
11765 :if type(myvar) == type([])
11766 :if type(myvar) == type({})
11767 :if type(myvar) == type(0.0)
11768 :if type(myvar) == type(v:false)
11769 :if type(myvar) == type(v:none)
11770< To check if the v:t_ variables exist use this: >
11771 :if exists('v:t_number')
11772
11773< Can also be used as a |method|: >
11774 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011775<
11776 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011777
11778
11779typename({expr}) *typename()*
11780 Return a string representation of the type of {expr}.
11781 Example: >
11782 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011783< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011784
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011785 Return type: |String|
11786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011787
11788undofile({name}) *undofile()*
11789 Return the name of the undo file that would be used for a file
11790 with name {name} when writing. This uses the 'undodir'
11791 option, finding directories that exist. It does not check if
11792 the undo file exists.
11793 {name} is always expanded to the full path, since that is what
11794 is used internally.
11795 If {name} is empty undofile() returns an empty string, since a
11796 buffer without a file name will not write an undo file.
11797 Useful in combination with |:wundo| and |:rundo|.
11798 When compiled without the |+persistent_undo| option this always
11799 returns an empty string.
11800
11801 Can also be used as a |method|: >
11802 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011803<
11804 Return type: |String|
11805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011806
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011807undotree([{buf}]) *undotree()*
11808 Return the current state of the undo tree for the current
11809 buffer, or for a specific buffer if {buf} is given. The
11810 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011811 "seq_last" The highest undo sequence number used.
11812 "seq_cur" The sequence number of the current position in
11813 the undo tree. This differs from "seq_last"
11814 when some changes were undone.
11815 "time_cur" Time last used for |:earlier| and related
11816 commands. Use |strftime()| to convert to
11817 something readable.
11818 "save_last" Number of the last file write. Zero when no
11819 write yet.
11820 "save_cur" Number of the current position in the undo
11821 tree.
11822 "synced" Non-zero when the last undo block was synced.
11823 This happens when waiting from input from the
11824 user. See |undo-blocks|.
11825 "entries" A list of dictionaries with information about
11826 undo blocks.
11827
11828 The first item in the "entries" list is the oldest undo item.
11829 Each List item is a |Dictionary| with these items:
11830 "seq" Undo sequence number. Same as what appears in
11831 |:undolist|.
11832 "time" Timestamp when the change happened. Use
11833 |strftime()| to convert to something readable.
11834 "newhead" Only appears in the item that is the last one
11835 that was added. This marks the last change
11836 and where further changes will be added.
11837 "curhead" Only appears in the item that is the last one
11838 that was undone. This marks the current
11839 position in the undo tree, the block that will
11840 be used by a redo command. When nothing was
11841 undone after the last change this item will
11842 not appear anywhere.
11843 "save" Only appears on the last block before a file
11844 write. The number is the write count. The
11845 first write has number 1, the last one the
11846 "save_last" mentioned above.
11847 "alt" Alternate entry. This is again a List of undo
11848 blocks. Each item may again have an "alt"
11849 item.
11850
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011851 Return type: dict<any>
11852
11853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011854uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11855 Remove second and succeeding copies of repeated adjacent
11856 {list} items in-place. Returns {list}. If you want a list
11857 to remain unmodified make a copy first: >
11858 :let newlist = uniq(copy(mylist))
11859< The default compare function uses the string representation of
11860 each item. For the use of {func} and {dict} see |sort()|.
11861
Bram Moolenaard592deb2022-06-17 15:42:40 +010011862 Returns zero if {list} is not a |List|.
11863
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011864 Can also be used as a |method|: >
11865 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011866<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011867 Return type: list<{type}>
11868
11869
Christian Brabandt67672ef2023-04-24 21:09:54 +010011870 *utf16idx()*
11871utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011872 Same as |charidx()| but returns the UTF-16 code unit index of
11873 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011874
11875 When {charidx} is present and TRUE, {idx} is used as the
11876 character index in the String {string} instead of as the byte
11877 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011878 An {idx} in the middle of a UTF-8 sequence is rounded
11879 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011880
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011881 Returns -1 if the arguments are invalid or if there are less
11882 than {idx} bytes in {string}. If there are exactly {idx} bytes
11883 the length of the string in UTF-16 code units is returned.
11884
Christian Brabandt67672ef2023-04-24 21:09:54 +010011885 See |byteidx()| and |byteidxcomp()| for getting the byte index
11886 from the UTF-16 index and |charidx()| for getting the
11887 character index from the UTF-16 index.
11888 Refer to |string-offset-encoding| for more information.
11889 Examples: >
11890 echo utf16idx('a😊😊', 3) returns 2
11891 echo utf16idx('a😊😊', 7) returns 4
11892 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11893 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11894 echo utf16idx('aą́c', 6) returns 2
11895 echo utf16idx('aą́c', 6, 1) returns 4
11896 echo utf16idx('a😊😊', 9) returns -1
11897<
11898 Can also be used as a |method|: >
11899 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011900<
11901 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011903
11904values({dict}) *values()*
11905 Return a |List| with all the values of {dict}. The |List| is
11906 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011907 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011908
11909 Can also be used as a |method|: >
11910 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011911<
11912 Return type: list<any>
11913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011914
zeertzjq825cf812023-08-17 22:55:25 +020011915virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011916 The result is a Number, which is the screen column of the file
11917 position given with {expr}. That is, the last screen position
11918 occupied by the character at that position, when the screen
11919 would be of unlimited width. When there is a <Tab> at the
11920 position, the returned Number will be the column at the end of
11921 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
11922 set to 8, it returns 8. |conceal| is ignored.
11923 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011924
zeertzjq02f3eba2024-06-12 20:45:24 +020011925 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080011926 When {expr} is "$", it means the end of the cursor line, so
11927 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010011928
11929 When 'virtualedit' is used {expr} can be [lnum, col, off],
11930 where "off" is the offset in screen columns from the start of
11931 the character. E.g., a position within a <Tab> or after the
11932 last character. When "off" is omitted zero is used. When
11933 Virtual editing is active in the current mode, a position
11934 beyond the end of the line can be returned. Also see
11935 |'virtualedit'|
11936
zeertzjq825cf812023-08-17 22:55:25 +020011937 If {list} is present and non-zero then virtcol() returns a
11938 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010011939 character.
11940
zeertzjq825cf812023-08-17 22:55:25 +020011941 With the optional {winid} argument the values are obtained for
11942 that window instead of the current window.
11943
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011944 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020011945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011946 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010011947 " With text "foo^Lbar" and cursor on the "^L":
11948
11949 virtcol(".") " returns 5
11950 virtcol(".", 1) " returns [4, 5]
11951 virtcol("$") " returns 9
11952
11953 " With text " there", with 't at 'h':
11954
11955 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020011956<
11957 The first column is 1. 0 or [0, 0] is returned for an error.
11958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011959 A more advanced example that echoes the maximum length of
11960 all lines: >
11961 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
11962
11963< Can also be used as a |method|: >
11964 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011965<
11966 Return type: |Number|
11967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011968
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011969virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
11970 The result is a Number, which is the byte index of the
11971 character in window {winid} at buffer line {lnum} and virtual
11972 column {col}.
11973
zeertzjqb583eda2023-10-14 11:32:28 +020011974 If buffer line {lnum} is an empty line, 0 is returned.
11975
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011976 If {col} is greater than the last virtual column in line
11977 {lnum}, then the byte index of the character at the last
11978 virtual column is returned.
11979
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020011980 For a multi-byte character, the column number of the first
11981 byte in the character is returned.
11982
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010011983 The {winid} argument can be the window number or the
11984 |window-ID|. If this is zero, then the current window is used.
11985
11986 Returns -1 if the window {winid} doesn't exist or the buffer
11987 line {lnum} or virtual column {col} is invalid.
11988
11989 See also |screenpos()|, |virtcol()| and |col()|.
11990
11991 Can also be used as a |method|: >
11992 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011993<
11994 Return type: |Number|
11995
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011996
11997visualmode([{expr}]) *visualmode()*
11998 The result is a String, which describes the last Visual mode
11999 used in the current buffer. Initially it returns an empty
12000 string, but once Visual mode has been used, it returns "v",
12001 "V", or "<CTRL-V>" (a single CTRL-V character) for
12002 character-wise, line-wise, or block-wise Visual mode
12003 respectively.
12004 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012005 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012006< This enters the same Visual mode as before. It is also useful
12007 in scripts if you wish to act differently depending on the
12008 Visual mode that was used.
12009 If Visual mode is active, use |mode()| to get the Visual mode
12010 (e.g., in a |:vmap|).
12011 If {expr} is supplied and it evaluates to a non-zero Number or
12012 a non-empty String, then the Visual mode will be cleared and
12013 the old value is returned. See |non-zero-arg|.
12014
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012015 Return type: |String|
12016
12017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012018wildmenumode() *wildmenumode()*
12019 Returns |TRUE| when the wildmenu is active and |FALSE|
12020 otherwise. See 'wildmenu' and 'wildmode'.
12021 This can be used in mappings to handle the 'wildcharm' option
12022 gracefully. (Makes only sense with |mapmode-c| mappings).
12023
12024 For example to make <c-j> work like <down> in wildmode, use: >
12025 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12026<
Milly6c2fc372024-10-16 22:11:17 +020012027 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012028
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012029 Return type: |Number|
12030
12031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012032win_execute({id}, {command} [, {silent}]) *win_execute()*
12033 Like `execute()` but in the context of window {id}.
12034 The window will temporarily be made the current window,
12035 without triggering autocommands or changing directory. When
12036 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012037 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012038 Example: >
12039 call win_execute(winid, 'set syntax=python')
12040< Doing the same with `setwinvar()` would not trigger
12041 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012042 *E994*
12043 Not all commands are allowed in popup windows.
12044 When window {id} does not exist then no error is given and
12045 an empty string is returned.
12046
12047 Can also be used as a |method|, the base is passed as the
12048 second argument: >
12049 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012050<
12051 Return type: |String|
12052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012053
12054win_findbuf({bufnr}) *win_findbuf()*
12055 Returns a |List| with |window-ID|s for windows that contain
12056 buffer {bufnr}. When there is none the list is empty.
12057
12058 Can also be used as a |method|: >
12059 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012060<
12061 Return type: list<number> or list<any>
12062
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012063
12064win_getid([{win} [, {tab}]]) *win_getid()*
12065 Get the |window-ID| for the specified window.
12066 When {win} is missing use the current window.
12067 With {win} this is the window number. The top window has
12068 number 1.
12069 Without {tab} use the current tab, otherwise the tab with
12070 number {tab}. The first tab has number one.
12071 Return zero if the window cannot be found.
12072
12073 Can also be used as a |method|: >
12074 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012075<
12076 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012077
12078
12079win_gettype([{nr}]) *win_gettype()*
12080 Return the type of the window:
12081 "autocmd" autocommand window. Temporary window
12082 used to execute autocommands.
12083 "command" command-line window |cmdwin|
12084 (empty) normal window
12085 "loclist" |location-list-window|
12086 "popup" popup window |popup|
12087 "preview" preview window |preview-window|
12088 "quickfix" |quickfix-window|
12089 "unknown" window {nr} not found
12090
12091 When {nr} is omitted return the type of the current window.
12092 When {nr} is given return the type of this window by number or
12093 |window-ID|.
12094
12095 Also see the 'buftype' option. When running a terminal in a
12096 popup window then 'buftype' is "terminal" and win_gettype()
12097 returns "popup".
12098
12099 Can also be used as a |method|: >
12100 GetWinid()->win_gettype()
12101<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012102 Return type: |String|
12103
12104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012105win_gotoid({expr}) *win_gotoid()*
12106 Go to window with ID {expr}. This may also change the current
12107 tabpage.
12108 Return TRUE if successful, FALSE if the window cannot be found.
12109
12110 Can also be used as a |method|: >
12111 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012112<
12113 Return type: |Number|
12114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012115
12116win_id2tabwin({expr}) *win_id2tabwin()*
12117 Return a list with the tab number and window number of window
12118 with ID {expr}: [tabnr, winnr].
12119 Return [0, 0] if the window cannot be found.
12120
12121 Can also be used as a |method|: >
12122 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012123<
12124 Return type: list<number>
12125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012126
12127win_id2win({expr}) *win_id2win()*
12128 Return the window number of window with ID {expr}.
12129 Return 0 if the window cannot be found in the current tabpage.
12130
12131 Can also be used as a |method|: >
12132 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012133<
12134 Return type: |Number|
12135
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012136
Daniel Steinbergee630312022-01-10 13:36:34 +000012137win_move_separator({nr}, {offset}) *win_move_separator()*
12138 Move window {nr}'s vertical separator (i.e., the right border)
12139 by {offset} columns, as if being dragged by the mouse. {nr}
12140 can be a window number or |window-ID|. A positive {offset}
12141 moves right and a negative {offset} moves left. Moving a
12142 window's vertical separator will change the width of the
12143 window and the width of other windows adjacent to the vertical
12144 separator. The magnitude of movement may be smaller than
12145 specified (e.g., as a consequence of maintaining
12146 'winminwidth'). Returns TRUE if the window can be found and
12147 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012148 This will fail for the rightmost window and a full-width
12149 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012150 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012151
12152 Can also be used as a |method|: >
12153 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012154<
12155 Return type: |Number|
12156
Daniel Steinbergee630312022-01-10 13:36:34 +000012157
12158win_move_statusline({nr}, {offset}) *win_move_statusline()*
12159 Move window {nr}'s status line (i.e., the bottom border) by
12160 {offset} rows, as if being dragged by the mouse. {nr} can be a
12161 window number or |window-ID|. A positive {offset} moves down
12162 and a negative {offset} moves up. Moving a window's status
12163 line will change the height of the window and the height of
12164 other windows adjacent to the status line. The magnitude of
12165 movement may be smaller than specified (e.g., as a consequence
12166 of maintaining 'winminheight'). Returns TRUE if the window can
12167 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012168 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012169
12170 Can also be used as a |method|: >
12171 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012172<
12173 Return type: |Number|
12174
Daniel Steinbergee630312022-01-10 13:36:34 +000012175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012176win_screenpos({nr}) *win_screenpos()*
12177 Return the screen position of window {nr} as a list with two
12178 numbers: [row, col]. The first window always has position
12179 [1, 1], unless there is a tabline, then it is [2, 1].
12180 {nr} can be the window number or the |window-ID|. Use zero
12181 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012182 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012183
12184 Can also be used as a |method|: >
12185 GetWinid()->win_screenpos()
12186<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012187 Return type: list<number>
12188
12189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012190win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012191 Temporarily switch to window {target}, then move window {nr}
12192 to a new split adjacent to {target}.
12193 Unlike commands such as |:split|, no new windows are created
12194 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012195
12196 Both {nr} and {target} can be window numbers or |window-ID|s.
12197 Both must be in the current tab page.
12198
12199 Returns zero for success, non-zero for failure.
12200
12201 {options} is a |Dictionary| with the following optional entries:
12202 "vertical" When TRUE, the split is created vertically,
12203 like with |:vsplit|.
12204 "rightbelow" When TRUE, the split is made below or to the
12205 right (if vertical). When FALSE, it is done
12206 above or to the left (if vertical). When not
12207 present, the values of 'splitbelow' and
12208 'splitright' are used.
12209
12210 Can also be used as a |method|: >
12211 GetWinid()->win_splitmove(target)
12212<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012213 Return type: |Number|
12214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012215
12216 *winbufnr()*
12217winbufnr({nr}) The result is a Number, which is the number of the buffer
12218 associated with window {nr}. {nr} can be the window number or
12219 the |window-ID|.
12220 When {nr} is zero, the number of the buffer in the current
12221 window is returned.
12222 When window {nr} doesn't exist, -1 is returned.
12223 Example: >
12224 :echo "The file in the current window is " . bufname(winbufnr(0))
12225<
12226 Can also be used as a |method|: >
12227 FindWindow()->winbufnr()->bufname()
12228<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012229 Return type: |Number|
12230
12231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012232 *wincol()*
12233wincol() The result is a Number, which is the virtual column of the
12234 cursor in the window. This is counting screen cells from the
12235 left side of the window. The leftmost column is one.
12236
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012237 Return type: |Number|
12238
12239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012240 *windowsversion()*
12241windowsversion()
12242 The result is a String. For MS-Windows it indicates the OS
12243 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12244 Windows XP is "5.1". For non-MS-Windows systems the result is
12245 an empty string.
12246
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012247 Return type: |String|
12248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012249winheight({nr}) *winheight()*
12250 The result is a Number, which is the height of window {nr}.
12251 {nr} can be the window number or the |window-ID|.
12252 When {nr} is zero, the height of the current window is
12253 returned. When window {nr} doesn't exist, -1 is returned.
12254 An existing window always has a height of zero or more.
12255 This excludes any window toolbar line.
12256 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012257 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012258
12259< Can also be used as a |method|: >
12260 GetWinid()->winheight()
12261<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012262 Return type: |Number|
12263
12264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012265winlayout([{tabnr}]) *winlayout()*
12266 The result is a nested List containing the layout of windows
12267 in a tabpage.
12268
12269 Without {tabnr} use the current tabpage, otherwise the tabpage
12270 with number {tabnr}. If the tabpage {tabnr} is not found,
12271 returns an empty list.
12272
12273 For a leaf window, it returns:
12274 ['leaf', {winid}]
12275 For horizontally split windows, which form a column, it
12276 returns:
12277 ['col', [{nested list of windows}]]
12278 For vertically split windows, which form a row, it returns:
12279 ['row', [{nested list of windows}]]
12280
12281 Example: >
12282 " Only one window in the tab page
12283 :echo winlayout()
12284 ['leaf', 1000]
12285 " Two horizontally split windows
12286 :echo winlayout()
12287 ['col', [['leaf', 1000], ['leaf', 1001]]]
12288 " The second tab page, with three horizontally split
12289 " windows, with two vertically split windows in the
12290 " middle window
12291 :echo winlayout(2)
12292 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12293 ['leaf', 1001]]], ['leaf', 1000]]]
12294<
12295 Can also be used as a |method|: >
12296 GetTabnr()->winlayout()
12297<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012298 Return type: list<any>
12299
12300
12301winline() *winline()*
12302 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012303 in the window. This is counting screen lines from the top of
12304 the window. The first line is one.
12305 If the cursor was moved the view on the file will be updated
12306 first, this may cause a scroll.
12307
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012308 Return type: |Number|
12309
12310
12311winnr([{arg}]) *winnr()*
12312 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012313 window. The top window has number 1.
12314 Returns zero for a popup window.
12315
12316 The optional argument {arg} supports the following values:
12317 $ the number of the last window (the window
12318 count).
12319 # the number of the last accessed window (where
12320 |CTRL-W_p| goes to). If there is no previous
12321 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012322 returned. May refer to the current window in
12323 some cases (e.g. when evaluating 'statusline'
12324 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012325 {N}j the number of the Nth window below the
12326 current window (where |CTRL-W_j| goes to).
12327 {N}k the number of the Nth window above the current
12328 window (where |CTRL-W_k| goes to).
12329 {N}h the number of the Nth window left of the
12330 current window (where |CTRL-W_h| goes to).
12331 {N}l the number of the Nth window right of the
12332 current window (where |CTRL-W_l| goes to).
12333 The number can be used with |CTRL-W_w| and ":wincmd w"
12334 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012335 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012336 Also see |tabpagewinnr()| and |win_getid()|.
12337 Examples: >
12338 let window_count = winnr('$')
12339 let prev_window = winnr('#')
12340 let wnum = winnr('3k')
12341
12342< Can also be used as a |method|: >
12343 GetWinval()->winnr()
12344<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012345 Return type: |Number|
12346
12347
12348winrestcmd() *winrestcmd()*
12349 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012350 the current window sizes. Only works properly when no windows
12351 are opened or closed and the current window and tab page is
12352 unchanged.
12353 Example: >
12354 :let cmd = winrestcmd()
12355 :call MessWithWindowSizes()
12356 :exe cmd
12357<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012358 Return type: |String|
12359
12360
12361winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012362 Uses the |Dictionary| returned by |winsaveview()| to restore
12363 the view of the current window.
12364 Note: The {dict} does not have to contain all values, that are
12365 returned by |winsaveview()|. If values are missing, those
12366 settings won't be restored. So you can use: >
12367 :call winrestview({'curswant': 4})
12368<
12369 This will only set the curswant value (the column the cursor
12370 wants to move on vertical movements) of the cursor to column 5
12371 (yes, that is 5), while all other settings will remain the
12372 same. This is useful, if you set the cursor position manually.
12373
12374 If you have changed the values the result is unpredictable.
12375 If the window size changed the result won't be the same.
12376
12377 Can also be used as a |method|: >
12378 GetView()->winrestview()
12379<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012380 Return type: |Number|
12381
12382
12383winsaveview() *winsaveview()*
12384 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012385 the view of the current window. Use |winrestview()| to
12386 restore the view.
12387 This is useful if you have a mapping that jumps around in the
12388 buffer and you want to go back to the original view.
12389 This does not save fold information. Use the 'foldenable'
12390 option to temporarily switch off folding, so that folds are
12391 not opened when moving around. This may have side effects.
12392 The return value includes:
12393 lnum cursor line number
12394 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012395 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012396 returns)
12397 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012398 curswant column for vertical movement (Note:
12399 the first column is zero, as opposed
12400 to what |getcurpos()| returns). After
12401 |$| command it will be a very large
12402 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012403 topline first line in the window
12404 topfill filler lines, only in diff mode
12405 leftcol first column displayed; only used when
12406 'wrap' is off
12407 skipcol columns skipped
12408 Note that no option values are saved.
12409
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012410 Return type: dict<number>
12411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012412
12413winwidth({nr}) *winwidth()*
12414 The result is a Number, which is the width of window {nr}.
12415 {nr} can be the window number or the |window-ID|.
12416 When {nr} is zero, the width of the current window is
12417 returned. When window {nr} doesn't exist, -1 is returned.
12418 An existing window always has a width of zero or more.
12419 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012420 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012421 :if winwidth(0) <= 50
12422 : 50 wincmd |
12423 :endif
12424< For getting the terminal or screen size, see the 'columns'
12425 option.
12426
12427 Can also be used as a |method|: >
12428 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012429<
12430 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012431
12432
12433wordcount() *wordcount()*
12434 The result is a dictionary of byte/chars/word statistics for
12435 the current buffer. This is the same info as provided by
12436 |g_CTRL-G|
12437 The return value includes:
12438 bytes Number of bytes in the buffer
12439 chars Number of chars in the buffer
12440 words Number of words in the buffer
12441 cursor_bytes Number of bytes before cursor position
12442 (not in Visual mode)
12443 cursor_chars Number of chars before cursor position
12444 (not in Visual mode)
12445 cursor_words Number of words before cursor position
12446 (not in Visual mode)
12447 visual_bytes Number of bytes visually selected
12448 (only in Visual mode)
12449 visual_chars Number of chars visually selected
12450 (only in Visual mode)
12451 visual_words Number of words visually selected
12452 (only in Visual mode)
12453
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012454 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012455
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012456
12457writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012458 When {object} is a |List| write it to file {fname}. Each list
12459 item is separated with a NL. Each list item must be a String
12460 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012461 All NL characters are replaced with a NUL character.
12462 Inserting CR characters needs to be done before passing {list}
12463 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012464
12465 When {object} is a |Blob| write the bytes to file {fname}
12466 unmodified, also when binary mode is not specified.
12467
12468 {flags} must be a String. These characters are recognized:
12469
12470 'b' Binary mode is used: There will not be a NL after the
12471 last list item. An empty item at the end does cause the
12472 last line in the file to end in a NL.
12473
12474 'a' Append mode is used, lines are appended to the file: >
12475 :call writefile(["foo"], "event.log", "a")
12476 :call writefile(["bar"], "event.log", "a")
12477<
12478 'D' Delete the file when the current function ends. This
12479 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012480 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012481< Fails when not in a function. Also see |:defer|.
12482
12483 's' fsync() is called after writing the file. This flushes
12484 the file to disk, if possible. This takes more time but
12485 avoids losing the file if the system crashes.
12486
12487 'S' fsync() is not called, even when 'fsync' is set.
12488
12489 When {flags} does not contain "S" or "s" then fsync() is
12490 called if the 'fsync' option is set.
12491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012492 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012494 When the write fails -1 is returned, otherwise 0. There is an
12495 error message if the file can't be created or when writing
12496 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012498 Also see |readfile()|.
12499 To copy a file byte for byte: >
12500 :let fl = readfile("foo", "b")
12501 :call writefile(fl, "foocopy", "b")
12502
12503< Can also be used as a |method|: >
12504 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012505<
12506 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012507
12508
12509xor({expr}, {expr}) *xor()*
12510 Bitwise XOR on the two arguments. The arguments are converted
12511 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012512 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012513 Example: >
12514 :let bits = xor(bits, 0x80)
12515<
12516 Can also be used as a |method|: >
12517 :let bits = bits->xor(0x80)
12518<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012519 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012520
12521==============================================================================
125223. Feature list *feature-list*
12523
12524There are three types of features:
125251. Features that are only supported when they have been enabled when Vim
12526 was compiled |+feature-list|. Example: >
12527 :if has("cindent")
12528< *gui_running*
125292. Features that are only supported when certain conditions have been met.
12530 Example: >
12531 :if has("gui_running")
12532< *has-patch*
125333. Beyond a certain version or at a certain version and including a specific
12534 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12535 later, or it is version 7.4 and patch 248 was included. Example: >
12536 :if has("patch-7.4.248")
12537< Note that it's possible for patch 248 to be omitted even though 249 is
12538 included. Only happens when cherry-picking patches.
12539 Note that this form only works for patch 7.4.237 and later, before that
12540 you need to check for the patch and the v:version. Example (checking
12541 version 6.2.148 or later): >
12542 :if v:version > 602 || (v:version == 602 && has("patch148"))
12543
12544Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12545use: `if exists('+shellslash')`
12546
12547
12548acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012549all_builtin_terms Compiled with all builtin terminals enabled. (always
12550 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012551amiga Amiga version of Vim.
12552arabic Compiled with Arabic support |Arabic|.
12553arp Compiled with ARP support (Amiga).
12554autocmd Compiled with autocommand support. (always true)
12555autochdir Compiled with support for 'autochdir'
12556autoservername Automatically enable |clientserver|
12557balloon_eval Compiled with |balloon-eval| support.
12558balloon_multiline GUI supports multiline balloons.
12559beos BeOS version of Vim.
12560browse Compiled with |:browse| support, and browse() will
12561 work.
12562browsefilter Compiled with support for |browsefilter|.
12563bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012564builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012565byte_offset Compiled with support for 'o' in 'statusline'
12566channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012567cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012568clientserver Compiled with remote invocation support |clientserver|.
12569clipboard Compiled with 'clipboard' support.
12570clipboard_working Compiled with 'clipboard' support and it can be used.
12571cmdline_compl Compiled with |cmdline-completion| support.
12572cmdline_hist Compiled with |cmdline-history| support.
12573cmdline_info Compiled with 'showcmd' and 'ruler' support.
12574comments Compiled with |'comments'| support.
12575compatible Compiled to be very Vi compatible.
12576conpty Platform where |ConPTY| can be used.
12577cryptv Compiled with encryption support |encryption|.
12578cscope Compiled with |cscope| support.
12579cursorbind Compiled with |'cursorbind'| (always true)
12580debug Compiled with "DEBUG" defined.
12581dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012582dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012583dialog_gui Compiled with GUI dialog support.
12584diff Compiled with |vimdiff| and 'diff' support.
12585digraphs Compiled with support for digraphs.
12586directx Compiled with support for DirectX and 'renderoptions'.
12587dnd Compiled with support for the "~ register |quote_~|.
12588drop_file Compiled with |drop_file| support.
12589ebcdic Compiled on a machine with ebcdic character set.
12590emacs_tags Compiled with support for Emacs tags.
12591eval Compiled with expression evaluation support. Always
12592 true, of course!
12593ex_extra |+ex_extra| (always true)
12594extra_search Compiled with support for |'incsearch'| and
12595 |'hlsearch'|
12596farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012597file_in_path Compiled with support for |gf| and |<cfile>| (always
12598 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012599filterpipe When 'shelltemp' is off pipes are used for shell
12600 read/write/filter commands
12601find_in_path Compiled with support for include file searches
12602 |+find_in_path|.
12603float Compiled with support for |Float|.
12604fname_case Case in file names matters (for Amiga and MS-Windows
12605 this is not present).
12606folding Compiled with |folding| support.
12607footer Compiled with GUI footer support. |gui-footer|
12608fork Compiled to use fork()/exec() instead of system().
12609gettext Compiled with message translation |multi-lang|
12610gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012611gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012612gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12613gui_gtk Compiled with GTK+ GUI (any version).
12614gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12615gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12616gui_haiku Compiled with Haiku GUI.
12617gui_mac Compiled with Macintosh GUI.
12618gui_motif Compiled with Motif GUI.
12619gui_photon Compiled with Photon GUI.
12620gui_running Vim is running in the GUI, or it will start soon.
12621gui_win32 Compiled with MS-Windows Win32 GUI.
12622gui_win32s idem, and Win32s system being used (Windows 3.1)
12623haiku Haiku version of Vim.
12624hangul_input Compiled with Hangul input support. |hangul|
12625hpux HP-UX version of Vim.
12626iconv Can use iconv() for conversion.
12627insert_expand Compiled with support for CTRL-X expansion commands in
12628 Insert mode. (always true)
12629job Compiled with support for |channel| and |job|
12630ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012631jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012632keymap Compiled with 'keymap' support.
12633lambda Compiled with |lambda| support.
12634langmap Compiled with 'langmap' support.
12635libcall Compiled with |libcall()| support.
12636linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12637 'breakindent' support.
12638linux Linux version of Vim.
12639lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012640 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012641listcmds Compiled with commands for the buffer list |:files|
12642 and the argument list |arglist|.
12643localmap Compiled with local mappings and abbr. |:map-local|
12644lua Compiled with Lua interface |Lua|.
12645mac Any Macintosh version of Vim cf. osx
12646macunix Synonym for osxdarwin
12647menu Compiled with support for |:menu|.
12648mksession Compiled with support for |:mksession|.
12649modify_fname Compiled with file name modifiers. |filename-modifiers|
12650 (always true)
12651mouse Compiled with support for mouse.
12652mouse_dec Compiled with support for Dec terminal mouse.
12653mouse_gpm Compiled with support for gpm (Linux console mouse)
12654mouse_gpm_enabled GPM mouse is working
12655mouse_netterm Compiled with support for netterm mouse.
12656mouse_pterm Compiled with support for qnx pterm mouse.
12657mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12658mouse_sgr Compiled with support for sgr mouse.
12659mouse_urxvt Compiled with support for urxvt mouse.
12660mouse_xterm Compiled with support for xterm mouse.
12661mouseshape Compiled with support for 'mouseshape'.
12662multi_byte Compiled with support for 'encoding' (always true)
12663multi_byte_encoding 'encoding' is set to a multibyte encoding.
12664multi_byte_ime Compiled with support for IME input method.
12665multi_lang Compiled with support for multiple languages.
12666mzscheme Compiled with MzScheme interface |mzscheme|.
12667nanotime Compiled with sub-second time stamp checks.
12668netbeans_enabled Compiled with support for |netbeans| and connected.
12669netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012670num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012671ole Compiled with OLE automation support for Win32.
12672osx Compiled for macOS cf. mac
12673osxdarwin Compiled for macOS, with |mac-darwin-feature|
12674packages Compiled with |packages| support.
12675path_extra Compiled with up/downwards search in 'path' and 'tags'
12676perl Compiled with Perl interface.
12677persistent_undo Compiled with support for persistent undo history.
12678postscript Compiled with PostScript file printing.
12679printer Compiled with |:hardcopy| support.
12680profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012681prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012682python Python 2.x interface available. |has-python|
12683python_compiled Compiled with Python 2.x interface. |has-python|
12684python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12685python3 Python 3.x interface available. |has-python|
12686python3_compiled Compiled with Python 3.x interface. |has-python|
12687python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012688python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012689pythonx Python 2.x and/or 3.x interface available. |python_x|
12690qnx QNX version of Vim.
12691quickfix Compiled with |quickfix| support.
12692reltime Compiled with |reltime()| support.
12693rightleft Compiled with 'rightleft' support.
12694ruby Compiled with Ruby interface |ruby|.
12695scrollbind Compiled with 'scrollbind' support. (always true)
12696showcmd Compiled with 'showcmd' support.
12697signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012698smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012699sodium Compiled with libsodium for better crypt support
12700sound Compiled with sound support, e.g. `sound_playevent()`
12701spell Compiled with spell checking support |spell|.
12702startuptime Compiled with |--startuptime| support.
12703statusline Compiled with support for 'statusline', 'rulerformat'
12704 and special formats of 'titlestring' and 'iconstring'.
12705sun SunOS version of Vim.
12706sun_workshop Support for Sun |workshop| has been removed.
12707syntax Compiled with syntax highlighting support |syntax|.
12708syntax_items There are active syntax highlighting items for the
12709 current buffer.
12710system Compiled to use system() instead of fork()/exec().
12711tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012712 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012713tag_old_static Support for old static tags was removed, see
12714 |tag-old-static|.
12715tcl Compiled with Tcl interface.
12716termguicolors Compiled with true color in terminal support.
12717terminal Compiled with |terminal| support.
12718terminfo Compiled with terminfo instead of termcap.
12719termresponse Compiled with support for |t_RV| and |v:termresponse|.
12720textobjects Compiled with support for |text-objects|.
12721textprop Compiled with support for |text-properties|.
12722tgetent Compiled with tgetent support, able to use a termcap
12723 or terminfo file.
12724timers Compiled with |timer_start()| support.
12725title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012726 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012727toolbar Compiled with support for |gui-toolbar|.
12728ttyin input is a terminal (tty)
12729ttyout output is a terminal (tty)
12730unix Unix version of Vim. *+unix*
12731unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12732user_commands User-defined commands. (always true)
12733vartabs Compiled with variable tabstop support |'vartabstop'|.
12734vcon Win32: Virtual console support is working, can use
12735 'termguicolors'. Also see |+vtp|.
12736vertsplit Compiled with vertically split windows |:vsplit|.
12737 (always true)
12738vim_starting True while initial source'ing takes place. |startup|
12739 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012740vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012741viminfo Compiled with viminfo support.
12742vimscript-1 Compiled Vim script version 1 support
12743vimscript-2 Compiled Vim script version 2 support
12744vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012745vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012746virtualedit Compiled with 'virtualedit' option. (always true)
12747visual Compiled with Visual mode. (always true)
12748visualextra Compiled with extra Visual mode commands. (always
12749 true) |blockwise-operators|.
12750vms VMS version of Vim.
12751vreplace Compiled with |gR| and |gr| commands. (always true)
12752vtp Compiled for vcon support |+vtp| (check vcon to find
12753 out if it works in the current console).
12754wildignore Compiled with 'wildignore' option.
12755wildmenu Compiled with 'wildmenu' option.
12756win16 old version for MS-Windows 3.1 (always false)
12757win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12758 64 bits)
12759win32unix Win32 version of Vim, using Unix files (Cygwin)
12760win64 Win64 version of Vim (MS-Windows 64 bit).
12761win95 Win32 version for MS-Windows 95/98/ME (always false)
12762winaltkeys Compiled with 'winaltkeys' option.
12763windows Compiled with support for more than one window.
12764 (always true)
12765writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012766xattr Compiled with extended attributes support |xattr|
12767 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012768xfontset Compiled with X fontset support |xfontset|.
12769xim Compiled with X input method support |xim|.
12770xpm Compiled with pixmap support.
12771xpm_w32 Compiled with pixmap support for Win32. (Only for
12772 backward compatibility. Use "xpm" instead.)
12773xsmp Compiled with X session management support.
12774xsmp_interact Compiled with interactive X session management support.
12775xterm_clipboard Compiled with support for xterm clipboard.
12776xterm_save Compiled with support for saving and restoring the
12777 xterm screen.
12778x11 Compiled with X11 support.
12779
12780
12781==============================================================================
127824. Matching a pattern in a String *string-match*
12783
12784This is common between several functions. A regexp pattern as explained at
12785|pattern| is normally used to find a match in the buffer lines. When a
12786pattern is used to find a match in a String, almost everything works in the
12787same way. The difference is that a String is handled like it is one line.
12788When it contains a "\n" character, this is not seen as a line break for the
12789pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12790>
12791 :let a = "aaaa\nxxxx"
12792 :echo matchstr(a, "..\n..")
12793 aa
12794 xx
12795 :echo matchstr(a, "a.x")
12796 a
12797 x
12798
12799Don't forget that "^" will only match at the first character of the String and
12800"$" at the last character of the string. They don't match after or before a
12801"\n".
12802
12803 vim:tw=78:ts=8:noet:ft=help:norl: