blob: 70f3c88e3a7e76be9fef27ae21fce6ffe3f8feed [file] [log] [blame]
Girish Palya92f68e22025-04-21 11:12:41 +02001*builtin.txt* For Vim version 9.1. Last change: 2025 Apr 21
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
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 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
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Girish Palya92f68e22025-04-21 11:12:41 +0200132cmdcomplete_info() Dict get current cmdline completion
133 information
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000134col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000135complete({startcol}, {matches}) none set Insert mode completion
136complete_add({expr}) Number add completion match
137complete_check() Number check for key typed during completion
138complete_info([{what}]) Dict get current completion information
139confirm({msg} [, {choices} [, {default} [, {type}]]])
140 Number number of choice picked by user
141copy({expr}) any make a shallow copy of {expr}
142cos({expr}) Float cosine of {expr}
143cosh({expr}) Float hyperbolic cosine of {expr}
144count({comp}, {expr} [, {ic} [, {start}]])
145 Number count how many {expr} are in {comp}
146cscope_connection([{num}, {dbpath} [, {prepend}]])
147 Number checks existence of cscope connection
148cursor({lnum}, {col} [, {off}])
149 Number move cursor to {lnum}, {col}, {off}
150cursor({list}) Number move cursor to position in {list}
151debugbreak({pid}) Number interrupt process being debugged
152deepcopy({expr} [, {noref}]) any make a full copy of {expr}
153delete({fname} [, {flags}]) Number delete the file or directory {fname}
154deletebufline({buf}, {first} [, {last}])
155 Number delete lines from buffer {buf}
156did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100157diff({fromlist}, {tolist} [, {options}])
158 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000159diff_filler({lnum}) Number diff filler lines about {lnum}
160diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
161digraph_get({chars}) String get the |digraph| of {chars}
162digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200163digraph_set({chars}, {digraph}) Bool register |digraph|
164digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000165echoraw({expr}) none output {expr} as-is
166empty({expr}) Number |TRUE| if {expr} is empty
167environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100168err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000169escape({string}, {chars}) String escape {chars} in {string} with '\'
170eval({string}) any evaluate {string} into its value
171eventhandler() Number |TRUE| if inside an event handler
172executable({expr}) Number 1 if executable {expr} exists
173execute({command}) String execute {command} and get the output
174exepath({expr}) String full path of the command {expr}
175exists({expr}) Number |TRUE| if {expr} exists
176exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
177exp({expr}) Float exponential of {expr}
178expand({expr} [, {nosuf} [, {list}]])
179 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100180expandcmd({string} [, {options}])
181 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000182extend({expr1}, {expr2} [, {expr3}])
183 List/Dict insert items of {expr2} into {expr1}
184extendnew({expr1}, {expr2} [, {expr3}])
185 List/Dict like |extend()| but creates a new
186 List or Dictionary
187feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200188filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
189 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000190filereadable({file}) Number |TRUE| if {file} is a readable file
191filewritable({file}) Number |TRUE| if {file} is a writable file
192filter({expr1}, {expr2}) List/Dict/Blob/String
193 remove items from {expr1} where
194 {expr2} is 0
195finddir({name} [, {path} [, {count}]])
196 String find directory {name} in {path}
197findfile({name} [, {path} [, {count}]])
198 String find file {name} in {path}
199flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
200flattennew({list} [, {maxdepth}])
201 List flatten a copy of {list}
202float2nr({expr}) Number convert Float {expr} to a Number
203floor({expr}) Float round {expr} down
204fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
205fnameescape({fname}) String escape special characters in {fname}
206fnamemodify({fname}, {mods}) String modify file name
207foldclosed({lnum}) Number first line of fold at {lnum} if closed
208foldclosedend({lnum}) Number last line of fold at {lnum} if closed
209foldlevel({lnum}) Number fold level at {lnum}
210foldtext() String line displayed for closed fold
211foldtextresult({lnum}) String text for closed fold at {lnum}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100212foreach({expr1}, {expr2}) List/Tuple/Dict/Blob/String
Ernie Raele79e2072024-01-13 11:47:33 +0100213 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100215fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000216funcref({name} [, {arglist}] [, {dict}])
217 Funcref reference to function {name}
218function({name} [, {arglist}] [, {dict}])
219 Funcref named reference to function {name}
220garbagecollect([{atexit}]) none free memory, breaking cyclic references
221get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
222get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
223get({func}, {what}) any get property of funcref/partial {func}
224getbufinfo([{buf}]) List information about buffers
225getbufline({buf}, {lnum} [, {end}])
226 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000227getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000228getbufvar({buf}, {varname} [, {def}])
229 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100230getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000231getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100233getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000234 get one character from the user
235getcharmod() Number modifiers for the last typed character
236getcharpos({expr}) List position of cursor, mark, etc.
237getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100238getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200239getcmdcomplpat() String return the completion pattern of the
240 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100241getcmdcompltype() String return the type of the current
242 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000244getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200245getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100246getcmdscreenpos() Number return cursor screen position in
247 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000248getcmdtype() String return current command-line type
249getcmdwintype() String return current command-line window type
250getcompletion({pat}, {type} [, {filtered}])
251 List list of cmdline completion matches
252getcurpos([{winnr}]) List position of the cursor
253getcursorcharpos([{winnr}]) List character position of the cursor
254getcwd([{winnr} [, {tabnr}]]) String get the current working directory
255getenv({name}) String return environment variable
256getfontname([{name}]) String name of font being used
257getfperm({fname}) String file permissions of file {fname}
258getfsize({fname}) Number size in bytes of file {fname}
259getftime({fname}) Number last modification time of file
260getftype({fname}) String description of type of file {fname}
261getimstatus() Number |TRUE| if the IME status is active
262getjumplist([{winnr} [, {tabnr}]])
263 List list of jump list items
264getline({lnum}) String line {lnum} of current buffer
265getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
266getloclist({nr}) List list of location list items
267getloclist({nr}, {what}) Dict get specific location list properties
268getmarklist([{buf}]) List list of global/local marks
269getmatches([{win}]) List list of current matches
270getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000271getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getpid() Number process ID of Vim
273getpos({expr}) List position of cursor, mark, etc.
274getqflist() List list of quickfix items
275getqflist({what}) Dict get specific quickfix list properties
276getreg([{regname} [, 1 [, {list}]]])
277 String or List contents of a register
278getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100279getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100280 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200281getregionpos({pos1}, {pos2} [, {opts}])
282 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100284getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100285getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286gettabinfo([{expr}]) List list of tab pages
287gettabvar({nr}, {varname} [, {def}])
288 any variable {varname} in tab {nr} or {def}
289gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
290 any {name} in {winnr} in tab page {tabnr}
291gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200292gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000294getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000295getwinposx() Number X coord in pixels of the Vim window
296getwinposy() Number Y coord in pixels of the Vim window
297getwinvar({nr}, {varname} [, {def}])
298 any variable {varname} in window {nr}
299glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
300 any expand file wildcards in {expr}
301glob2regpat({expr}) String convert a glob pat into a search pat
302globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
303 String do glob({expr}) for all dirs in {path}
304has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
305has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
306haslocaldir([{winnr} [, {tabnr}]])
307 Number |TRUE| if the window executed |:lcd|
308 or |:tcd|
309hasmapto({what} [, {mode} [, {abbr}]])
310 Number |TRUE| if mapping to {what} exists
311histadd({history}, {item}) Number add an item to a history
312histdel({history} [, {item}]) Number remove an item from a history
313histget({history} [, {index}]) String get the item {index} from a history
314histnr({history}) Number highest index of a history
315hlID({name}) Number syntax ID of highlight group {name}
316hlexists({name}) Number |TRUE| if highlight group {name} exists
317hlget([{name} [, {resolve}]]) List get highlight group attributes
318hlset({list}) Number set highlight group attributes
319hostname() String name of the machine Vim is running on
320iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200321id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000322indent({lnum}) Number indent of line {lnum}
323index({object}, {expr} [, {start} [, {ic}]])
324 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100325indexof({object}, {expr} [, {opts}]])
326 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327input({prompt} [, {text} [, {completion}]])
328 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100329inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330 String like input() but in a GUI dialog
331inputlist({textlist}) Number let the user pick from a choice list
332inputrestore() Number restore typeahead
333inputsave() Number save and clear typeahead
334inputsecret({prompt} [, {text}]) String like input() but hiding the text
335insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200336instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000337interrupt() none interrupt script execution
338invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100339isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000340isdirectory({directory}) Number |TRUE| if {directory} is a directory
341isinf({expr}) Number determine if {expr} is infinity value
342 (positive or negative)
343islocked({expr}) Number |TRUE| if {expr} is locked
344isnan({expr}) Number |TRUE| if {expr} is NaN
345items({dict}) List key-value pairs in {dict}
346job_getchannel({job}) Channel get the channel handle for {job}
347job_info([{job}]) Dict get information about {job}
348job_setoptions({job}, {options}) none set options for {job}
349job_start({command} [, {options}])
350 Job start a job
351job_status({job}) String get the status of {job}
352job_stop({job} [, {how}]) Number stop {job}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100353join({expr} [, {sep}]) String join items in {expr} into one String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000354js_decode({string}) any decode JS style JSON
355js_encode({expr}) String encode JS style JSON
356json_decode({string}) any decode JSON
357json_encode({expr}) String encode JSON
358keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100359keytrans({string}) String translate internal keycodes to a form
360 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000361len({expr}) Number the length of {expr}
362libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
363libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
364line({expr} [, {winid}]) Number line nr of cursor, last line or mark
365line2byte({lnum}) Number byte count of line {lnum}
366lispindent({lnum}) Number Lisp indent for line {lnum}
367list2blob({list}) Blob turn {list} of numbers into a Blob
368list2str({list} [, {utf8}]) String turn {list} of numbers into a String
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100369list2tuple({list}) Tuple turn {list} of items into a tuple
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000370listener_add({callback} [, {buf}])
371 Number add a callback to listen to changes
372listener_flush([{buf}]) none invoke listener callbacks
373listener_remove({id}) none remove a listener callback
374localtime() Number current time
375log({expr}) Float natural logarithm (base e) of {expr}
376log10({expr}) Float logarithm of Float {expr} to base 10
377luaeval({expr} [, {expr}]) any evaluate |Lua| expression
378map({expr1}, {expr2}) List/Dict/Blob/String
379 change each item in {expr1} to {expr2}
380maparg({name} [, {mode} [, {abbr} [, {dict}]]])
381 String or Dict
382 rhs of mapping {name} in mode {mode}
383mapcheck({name} [, {mode} [, {abbr}]])
384 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100385maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000386mapnew({expr1}, {expr2}) List/Dict/Blob/String
387 like |map()| but creates a new List or
388 Dictionary
389mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
390match({expr}, {pat} [, {start} [, {count}]])
391 Number position where {pat} matches in {expr}
392matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
393 Number highlight {pattern} with {group}
394matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
395 Number highlight positions with {group}
396matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100397matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
398 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000399matchdelete({id} [, {win}]) Number delete match identified by {id}
400matchend({expr}, {pat} [, {start} [, {count}]])
401 Number position where {pat} ends in {expr}
402matchfuzzy({list}, {str} [, {dict}])
403 List fuzzy match {str} in {list}
404matchfuzzypos({list}, {str} [, {dict}])
405 List fuzzy match {str} in {list}
406matchlist({expr}, {pat} [, {start} [, {count}]])
407 List match and submatches of {pat} in {expr}
408matchstr({expr}, {pat} [, {start} [, {count}]])
409 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100410matchstrlist({list}, {pat} [, {dict})
411 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000412matchstrpos({expr}, {pat} [, {start} [, {count}]])
413 List {count}'th match of {pat} in {expr}
414max({expr}) Number maximum value of items in {expr}
415menu_info({name} [, {mode}]) Dict get menu item information
416min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000417mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000418 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200419mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000420mzeval({expr}) any evaluate |MzScheme| expression
421nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100422ngettext({single}, {plural}, {number}[, {domain}])
423 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000424nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
425or({expr}, {expr}) Number bitwise OR
426pathshorten({expr} [, {len}]) String shorten directory names in a path
427perleval({expr}) any evaluate |Perl| expression
428popup_atcursor({what}, {options}) Number create popup window near the cursor
429popup_beval({what}, {options}) Number create popup window for 'ballooneval'
430popup_clear() none close all popup windows
431popup_close({id} [, {result}]) none close popup window {id}
432popup_create({what}, {options}) Number create a popup window
433popup_dialog({what}, {options}) Number create a popup window used as a dialog
434popup_filter_menu({id}, {key}) Number filter for a menu popup window
435popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100436popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000437popup_findinfo() Number get window ID of info popup window
438popup_findpreview() Number get window ID of preview popup window
439popup_getoptions({id}) Dict get options of popup window {id}
440popup_getpos({id}) Dict get position of popup window {id}
441popup_hide({id}) none hide popup menu {id}
442popup_list() List get a list of window IDs of all popups
443popup_locate({row}, {col}) Number get window ID of popup at position
444popup_menu({what}, {options}) Number create a popup window used as a menu
445popup_move({id}, {options}) none set position of popup window {id}
446popup_notification({what}, {options})
447 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200448popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000449popup_setoptions({id}, {options})
450 none set options for popup window {id}
451popup_settext({id}, {text}) none set the text of popup window {id}
452popup_show({id}) none unhide popup window {id}
453pow({x}, {y}) Float {x} to the power of {y}
454prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
455printf({fmt}, {expr1}...) String format text
456prompt_getprompt({buf}) String get prompt text
457prompt_setcallback({buf}, {expr}) none set prompt callback function
458prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
459prompt_setprompt({buf}, {text}) none set prompt text
460prop_add({lnum}, {col}, {props}) none add one text property
461prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
462 none add multiple text properties
463prop_clear({lnum} [, {lnum-end} [, {props}]])
464 none remove all text properties
465prop_find({props} [, {direction}])
466 Dict search for a text property
467prop_list({lnum} [, {props}]) List text properties in {lnum}
468prop_remove({props} [, {lnum} [, {lnum-end}]])
469 Number remove a text property
470prop_type_add({name}, {props}) none define a new property type
471prop_type_change({name}, {props})
472 none change an existing property type
473prop_type_delete({name} [, {props}])
474 none delete a property type
475prop_type_get({name} [, {props}])
476 Dict get property type values
477prop_type_list([{props}]) List get list of property types
478pum_getpos() Dict position and size of pum if visible
479pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100480py3eval({expr} [, {locals}]) any evaluate |python3| expression
481pyeval({expr} [, {locals}]) any evaluate |Python| expression
482pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000483rand([{expr}]) Number get pseudo-random number
484range({expr} [, {max} [, {stride}]])
485 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100486readblob({fname} [, {offset} [, {size}]])
487 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000488readdir({dir} [, {expr} [, {dict}]])
489 List file names in {dir} selected by {expr}
490readdirex({dir} [, {expr} [, {dict}]])
491 List file info in {dir} selected by {expr}
492readfile({fname} [, {type} [, {max}]])
493 List get list of lines from file {fname}
494reduce({object}, {func} [, {initial}])
495 any reduce {object} using {func}
496reg_executing() String get the executing register name
497reg_recording() String get the recording register name
498reltime([{start} [, {end}]]) List get time value
499reltimefloat({time}) Float turn the time value into a Float
500reltimestr({time}) String turn time value into a String
501remote_expr({server}, {string} [, {idvar} [, {timeout}]])
502 String send expression
503remote_foreground({server}) Number bring Vim server to the foreground
504remote_peek({serverid} [, {retvar}])
505 Number check for reply string
506remote_read({serverid} [, {timeout}])
507 String read reply string
508remote_send({server}, {string} [, {idvar}])
509 String send key sequence
510remote_startserver({name}) none become server {name}
511remove({list}, {idx} [, {end}]) any/List
512 remove items {idx}-{end} from {list}
513remove({blob}, {idx} [, {end}]) Number/Blob
514 remove bytes {idx}-{end} from {blob}
515remove({dict}, {key}) any remove entry {key} from {dict}
516rename({from}, {to}) Number rename (move) file from {from} to {to}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100517repeat({expr}, {count}) List/Tuple/Blob/String
Bakudankun375141e2022-09-09 18:46:47 +0100518 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000519resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100520reverse({obj}) List/Tuple/Blob/String
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100521 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000522round({expr}) Float round off {expr}
523rubyeval({expr}) any evaluate |Ruby| expression
524screenattr({row}, {col}) Number attribute at screen position
525screenchar({row}, {col}) Number character at screen position
526screenchars({row}, {col}) List List of characters at screen position
527screencol() Number current cursor column
528screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
529screenrow() Number current cursor row
530screenstring({row}, {col}) String characters at screen position
531search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
532 Number search for {pattern}
533searchcount([{options}]) Dict get or update search stats
534searchdecl({name} [, {global} [, {thisblock}]])
535 Number search for variable declaration
536searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
537 Number search for other end of start/end pair
538searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
539 List search for other end of start/end pair
540searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
541 List search for {pattern}
542server2client({clientid}, {string})
543 Number send reply string
544serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700545setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000546 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700547 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000548setbufvar({buf}, {varname}, {val})
549 none set {varname} in buffer {buf} to {val}
550setcellwidths({list}) none set character cell width overrides
551setcharpos({expr}, {list}) Number set the {expr} position to {list}
552setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100553setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000554setcmdpos({pos}) Number set cursor position in command-line
555setcursorcharpos({list}) Number move cursor to position in {list}
556setenv({name}, {val}) none set environment variable
557setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
558setline({lnum}, {line}) Number set line {lnum} to {line}
559setloclist({nr}, {list} [, {action}])
560 Number modify location list using {list}
561setloclist({nr}, {list}, {action}, {what})
562 Number modify specific location list props
563setmatches({list} [, {win}]) Number restore a list of matches
564setpos({expr}, {list}) Number set the {expr} position to {list}
565setqflist({list} [, {action}]) Number modify quickfix list using {list}
566setqflist({list}, {action}, {what})
567 Number modify specific quickfix list props
568setreg({n}, {v} [, {opt}]) Number set register to value and type
569settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
570settabwinvar({tabnr}, {winnr}, {varname}, {val})
571 none set {varname} in window {winnr} in tab
572 page {tabnr} to {val}
573settagstack({nr}, {dict} [, {action}])
574 Number modify tag stack using {dict}
575setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
576sha256({string}) String SHA256 checksum of {string}
577shellescape({string} [, {special}])
578 String escape {string} for use as shell
579 command argument
580shiftwidth([{col}]) Number effective value of 'shiftwidth'
581sign_define({name} [, {dict}]) Number define or update a sign
582sign_define({list}) List define or update a list of signs
583sign_getdefined([{name}]) List get a list of defined signs
584sign_getplaced([{buf} [, {dict}]])
585 List get a list of placed signs
586sign_jump({id}, {group}, {buf})
587 Number jump to a sign
588sign_place({id}, {group}, {name}, {buf} [, {dict}])
589 Number place a sign
590sign_placelist({list}) List place a list of signs
591sign_undefine([{name}]) Number undefine a sign
592sign_undefine({list}) List undefine a list of signs
593sign_unplace({group} [, {dict}])
594 Number unplace a sign
595sign_unplacelist({list}) List unplace a list of signs
596simplify({filename}) String simplify filename as much as possible
597sin({expr}) Float sine of {expr}
598sinh({expr}) Float hyperbolic sine of {expr}
599slice({expr}, {start} [, {end}]) String, List or Blob
600 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000601sort({list} [, {how} [, {dict}]])
602 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000603sound_clear() none stop playing all sounds
604sound_playevent({name} [, {callback}])
605 Number play an event sound
606sound_playfile({path} [, {callback}])
607 Number play sound file {path}
608sound_stop({id}) none stop playing sound {id}
609soundfold({word}) String sound-fold {word}
610spellbadword() String badly spelled word at cursor
611spellsuggest({word} [, {max} [, {capital}]])
612 List spelling suggestions
613split({expr} [, {pat} [, {keepempty}]])
614 List make |List| from {pat} separated {expr}
615sqrt({expr}) Float square root of {expr}
616srand([{expr}]) List get seed for |rand()|
617state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100618str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000619str2float({expr} [, {quoted}]) Float convert String to Float
620str2list({expr} [, {utf8}]) List convert each character of {expr} to
621 ASCII/UTF-8 value
622str2nr({expr} [, {base} [, {quoted}]])
623 Number convert String to Number
624strcharlen({expr}) Number character length of the String {expr}
625strcharpart({str}, {start} [, {len} [, {skipcc}]])
626 String {len} characters of {str} at
627 character {start}
628strchars({expr} [, {skipcc}]) Number character count of the String {expr}
629strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
630strftime({format} [, {time}]) String format time with a specified format
631strgetchar({str}, {index}) Number get char {index} from {str}
632stridx({haystack}, {needle} [, {start}])
633 Number index of {needle} in {haystack}
634string({expr}) String String representation of {expr} value
635strlen({expr}) Number length of the String {expr}
636strpart({str}, {start} [, {len} [, {chars}]])
637 String {len} bytes/chars of {str} at
638 byte {start}
639strptime({format}, {timestring})
640 Number Convert {timestring} to unix timestamp
641strridx({haystack}, {needle} [, {start}])
642 Number last index of {needle} in {haystack}
643strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100644strutf16len({string} [, {countcc}])
645 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000646strwidth({expr}) Number display cell length of the String {expr}
647submatch({nr} [, {list}]) String or List
648 specific match in ":s" or substitute()
649substitute({expr}, {pat}, {sub}, {flags})
650 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000651swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000652swapinfo({fname}) Dict information about swap file {fname}
653swapname({buf}) String swap file of buffer {buf}
654synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
655synIDattr({synID}, {what} [, {mode}])
656 String attribute {what} of syntax ID {synID}
657synIDtrans({synID}) Number translated syntax ID of {synID}
658synconcealed({lnum}, {col}) List info about concealing
659synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
660system({expr} [, {input}]) String output of shell command/filter {expr}
661systemlist({expr} [, {input}]) List output of shell command/filter {expr}
662tabpagebuflist([{arg}]) List list of buffer numbers in tab page
663tabpagenr([{arg}]) Number number of current or last tab page
664tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
665tagfiles() List tags files used
666taglist({expr} [, {filename}]) List list of tags matching {expr}
667tan({expr}) Float tangent of {expr}
668tanh({expr}) Float hyperbolic tangent of {expr}
669tempname() String name for a temporary file
670term_dumpdiff({filename}, {filename} [, {options}])
671 Number display difference between two dumps
672term_dumpload({filename} [, {options}])
673 Number displaying a screen dump
674term_dumpwrite({buf}, {filename} [, {options}])
675 none dump terminal window contents
676term_getaltscreen({buf}) Number get the alternate screen flag
677term_getansicolors({buf}) List get ANSI palette in GUI color mode
678term_getattr({attr}, {what}) Number get the value of attribute {what}
679term_getcursor({buf}) List get the cursor position of a terminal
680term_getjob({buf}) Job get the job associated with a terminal
681term_getline({buf}, {row}) String get a line of text from a terminal
682term_getscrolled({buf}) Number get the scroll count of a terminal
683term_getsize({buf}) List get the size of a terminal
684term_getstatus({buf}) String get the status of a terminal
685term_gettitle({buf}) String get the title of a terminal
686term_gettty({buf}, [{input}]) String get the tty name of a terminal
687term_list() List get the list of terminal buffers
688term_scrape({buf}, {row}) List get row of a terminal screen
689term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
690term_setansicolors({buf}, {colors})
691 none set ANSI palette in GUI color mode
692term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
693term_setkill({buf}, {how}) none set signal to stop job in terminal
694term_setrestore({buf}, {command}) none set command to restore terminal
695term_setsize({buf}, {rows}, {cols})
696 none set the size of a terminal
697term_start({cmd} [, {options}]) Number open a terminal window and run a job
698term_wait({buf} [, {time}]) Number wait for screen to be updated
699terminalprops() Dict properties of the terminal
700test_alloc_fail({id}, {countdown}, {repeat})
701 none make memory allocation fail
702test_autochdir() none enable 'autochdir' during startup
703test_feedinput({string}) none add key sequence to input buffer
704test_garbagecollect_now() none free memory right now for testing
705test_garbagecollect_soon() none free memory soon for testing
706test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000707test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000709test_mswin_event({event}, {args})
710 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_null_blob() Blob null value for testing
712test_null_channel() Channel null value for testing
713test_null_dict() Dict null value for testing
714test_null_function() Funcref null value for testing
715test_null_job() Job null value for testing
716test_null_list() List null value for testing
717test_null_partial() Funcref null value for testing
718test_null_string() String null value for testing
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100719test_null_tuple() Tuple null value for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000720test_option_not_set({name}) none reset flag indicating option was set
721test_override({expr}, {val}) none test with Vim internal overrides
722test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000723test_setmouse({row}, {col}) none set the mouse position for testing
724test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200725test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726test_unknown() any unknown value for testing
727test_void() any void value for testing
728timer_info([{id}]) List information about timers
729timer_pause({id}, {pause}) none pause or unpause a timer
730timer_start({time}, {callback} [, {options}])
731 Number create a timer
732timer_stop({timer}) none stop a timer
733timer_stopall() none stop all timers
734tolower({expr}) String the String {expr} switched to lowercase
735toupper({expr}) String the String {expr} switched to uppercase
736tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
737 to chars in {tostr}
738trim({text} [, {mask} [, {dir}]])
739 String trim characters in {mask} from {text}
740trunc({expr}) Float truncate Float {expr}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100741tuple2list({tuple}) List turn {tuple} of items into a list
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000742type({expr}) Number type of value {expr}
743typename({expr}) String representation of the type of {expr}
744undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500745undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000746uniq({list} [, {func} [, {dict}]])
747 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100748utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
749 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000750values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200751virtcol({expr} [, {list} [, {winid}])
752 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100753 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100754virtcol2col({winid}, {lnum}, {col})
755 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200756visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000757wildmenumode() Number whether 'wildmenu' mode is active
758win_execute({id}, {command} [, {silent}])
759 String execute {command} in window {id}
760win_findbuf({bufnr}) List find windows containing {bufnr}
761win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
762win_gettype([{nr}]) String type of window {nr}
763win_gotoid({expr}) Number go to window with ID {expr}
764win_id2tabwin({expr}) List get tab and window nr from window ID
765win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000766win_move_separator({nr}) Number move window vertical separator
767win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000768win_screenpos({nr}) List get screen position of window {nr}
769win_splitmove({nr}, {target} [, {options}])
770 Number move window {nr} to split of {target}
771winbufnr({nr}) Number buffer number of window {nr}
772wincol() Number window column of the cursor
773windowsversion() String MS-Windows OS version
774winheight({nr}) Number height of window {nr}
775winlayout([{tabnr}]) List layout of windows in tab {tabnr}
776winline() Number window line of the cursor
777winnr([{expr}]) Number number of current window
778winrestcmd() String returns command to restore window sizes
779winrestview({dict}) none restore view of current window
780winsaveview() Dict save view of current window
781winwidth({nr}) Number width of window {nr}
782wordcount() Dict get byte/char/word statistics
783writefile({object}, {fname} [, {flags}])
784 Number write |Blob| or |List| of lines to file
785xor({expr}, {expr}) Number bitwise XOR
786
787==============================================================================
7882. Details *builtin-function-details*
789
790Not all functions are here, some have been moved to a help file covering the
791specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200792Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000793
794abs({expr}) *abs()*
795 Return the absolute value of {expr}. When {expr} evaluates to
796 a |Float| abs() returns a |Float|. When {expr} can be
797 converted to a |Number| abs() returns a |Number|. Otherwise
798 abs() gives an error message and returns -1.
799 Examples: >
800 echo abs(1.456)
801< 1.456 >
802 echo abs(-5.456)
803< 5.456 >
804 echo abs(-4)
805< 4
806
807 Can also be used as a |method|: >
808 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200809<
810 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812
813acos({expr}) *acos()*
814 Return the arc cosine of {expr} measured in radians, as a
815 |Float| in the range of [0, pi].
816 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100817 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000818 Examples: >
819 :echo acos(0)
820< 1.570796 >
821 :echo acos(-0.5)
822< 2.094395
823
824 Can also be used as a |method|: >
825 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200826<
827 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000829
830add({object}, {expr}) *add()*
831 Append the item {expr} to |List| or |Blob| {object}. Returns
832 the resulting |List| or |Blob|. Examples: >
833 :let alist = add([1, 2, 3], item)
834 :call add(mylist, "woodstock")
835< Note that when {expr} is a |List| it is appended as a single
836 item. Use |extend()| to concatenate |Lists|.
837 When {object} is a |Blob| then {expr} must be a number.
838 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100839 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000840
841 Can also be used as a |method|: >
842 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200843<
844 Return type: list<{type}> (depending on the given |List|) or
845 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846
847
848and({expr}, {expr}) *and()*
849 Bitwise AND on the two arguments. The arguments are converted
850 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100851 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000852 Example: >
853 :let flag = and(bits, 0x80)
854< Can also be used as a |method|: >
855 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200856<
857 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000858
859
860append({lnum}, {text}) *append()*
861 When {text} is a |List|: Append each item of the |List| as a
862 text line below line {lnum} in the current buffer.
863 Otherwise append {text} as one text line below line {lnum} in
864 the current buffer.
865 Any type of item is accepted and converted to a String.
866 {lnum} can be zero to insert a line before the first one.
867 {lnum} is used like with |getline()|.
868 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000869 0 for success. When {text} is an empty list zero is returned,
870 no matter the value of {lnum}.
871 In |Vim9| script an invalid argument or negative number
872 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000873 :let failed = append(line('$'), "# THE END")
874 :let failed = append(0, ["Chapter 1", "the beginning"])
875
876< Can also be used as a |method| after a List, the base is
877 passed as the second argument: >
878 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200879<
880 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000881
882
883appendbufline({buf}, {lnum}, {text}) *appendbufline()*
884 Like |append()| but append the text in buffer {buf}.
885
886 This function works only for loaded buffers. First call
887 |bufload()| if needed.
888
889 For the use of {buf}, see |bufname()|.
890
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000891 {lnum} is the line number to append below. Note that using
892 |line()| would use the current buffer, not the one appending
893 to. Use "$" to append at the end of the buffer. Other string
894 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895
896 On success 0 is returned, on failure 1 is returned.
897 In |Vim9| script an error is given for an invalid {lnum}.
898
899 If {buf} is not a valid buffer or {lnum} is not valid, an
900 error message is given. Example: >
901 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000902< However, when {text} is an empty list then no error is given
903 for an invalid {lnum}, since {lnum} isn't actually used.
904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905 Can also be used as a |method| after a List, the base is
906 passed as the second argument: >
907 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200908<
909 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910
911
912argc([{winid}]) *argc()*
913 The result is the number of files in the argument list. See
914 |arglist|.
915 If {winid} is not supplied, the argument list of the current
916 window is used.
917 If {winid} is -1, the global argument list is used.
918 Otherwise {winid} specifies the window of which the argument
919 list is used: either the window number or the window ID.
920 Returns -1 if the {winid} argument is invalid.
921
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200922 Return type: |Number|
923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924 *argidx()*
925argidx() The result is the current index in the argument list. 0 is
926 the first file. argc() - 1 is the last one. See |arglist|.
927
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200928 Return type: |Number|
929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000930 *arglistid()*
931arglistid([{winnr} [, {tabnr}]])
932 Return the argument list ID. This is a number which
933 identifies the argument list being used. Zero is used for the
934 global argument list. See |arglist|.
935 Returns -1 if the arguments are invalid.
936
937 Without arguments use the current window.
938 With {winnr} only use this window in the current tab page.
939 With {winnr} and {tabnr} use the window in the specified tab
940 page.
941 {winnr} can be the window number or the |window-ID|.
942
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200943 Return type: |Number|
944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000945 *argv()*
946argv([{nr} [, {winid}]])
947 The result is the {nr}th file in the argument list. See
948 |arglist|. "argv(0)" is the first one. Example: >
949 :let i = 0
950 :while i < argc()
951 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000952 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000953 : let i = i + 1
954 :endwhile
955< Without the {nr} argument, or when {nr} is -1, a |List| with
956 the whole |arglist| is returned.
957
958 The {winid} argument specifies the window ID, see |argc()|.
959 For the Vim command line arguments see |v:argv|.
960
Bram Moolenaar016188f2022-06-06 20:52:59 +0100961 Returns an empty string if {nr}th argument is not present in
962 the argument list. Returns an empty List if the {winid}
963 argument is invalid.
964
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200965 Return type: |String|
966
967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000968asin({expr}) *asin()*
969 Return the arc sine of {expr} measured in radians, as a |Float|
970 in the range of [-pi/2, pi/2].
971 {expr} must evaluate to a |Float| or a |Number| in the range
972 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100973 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
974 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000975 Examples: >
976 :echo asin(0.8)
977< 0.927295 >
978 :echo asin(-0.5)
979< -0.523599
980
981 Can also be used as a |method|: >
982 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200983<
984 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000985
986assert_ functions are documented here: |assert-functions-details|
987
988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000989atan({expr}) *atan()*
990 Return the principal value of the arc tangent of {expr}, in
991 the range [-pi/2, +pi/2] radians, as a |Float|.
992 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100993 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000994 Examples: >
995 :echo atan(100)
996< 1.560797 >
997 :echo atan(-4.01)
998< -1.326405
999
1000 Can also be used as a |method|: >
1001 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001002<
1003 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001004
1005
1006atan2({expr1}, {expr2}) *atan2()*
1007 Return the arc tangent of {expr1} / {expr2}, measured in
1008 radians, as a |Float| in the range [-pi, pi].
1009 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001010 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1011 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001012 Examples: >
1013 :echo atan2(-1, 1)
1014< -0.785398 >
1015 :echo atan2(1, -1)
1016< 2.356194
1017
1018 Can also be used as a |method|: >
1019 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001020<
1021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001022
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001023
1024autocmd_add({acmds}) *autocmd_add()*
1025 Adds a List of autocmds and autocmd groups.
1026
1027 The {acmds} argument is a List where each item is a Dict with
1028 the following optional items:
1029 bufnr buffer number to add a buffer-local autocmd.
1030 If this item is specified, then the "pattern"
1031 item is ignored.
1032 cmd Ex command to execute for this autocmd event
1033 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001034 This can be either a String with a single
1035 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001036 group autocmd group name. Refer to |autocmd-groups|.
1037 If this group doesn't exist then it is
1038 created. If not specified or empty, then the
1039 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001040 nested boolean flag, set to v:true to add a nested
1041 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001042 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001043 which executes only once. Refer to
1044 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001045 pattern autocmd pattern string. Refer to
1046 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001047 present, then this item is ignored. This can
1048 be a String with a single pattern or a List of
1049 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001050 replace boolean flag, set to v:true to remove all the
1051 commands associated with the specified autocmd
1052 event and group and add the {cmd}. This is
1053 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001054 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001055
1056 Returns v:true on success and v:false on failure.
1057 Examples: >
1058 " Create a buffer-local autocmd for buffer 5
1059 let acmd = {}
1060 let acmd.group = 'MyGroup'
1061 let acmd.event = 'BufEnter'
1062 let acmd.bufnr = 5
1063 let acmd.cmd = 'call BufEnterFunc()'
1064 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001065<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001066 Can also be used as a |method|: >
1067 GetAutocmdList()->autocmd_add()
1068<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001069 Return type: |vim9-boolean|
1070
1071
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001072autocmd_delete({acmds}) *autocmd_delete()*
1073 Deletes a List of autocmds and autocmd groups.
1074
1075 The {acmds} argument is a List where each item is a Dict with
1076 the following optional items:
1077 bufnr buffer number to delete a buffer-local autocmd.
1078 If this item is specified, then the "pattern"
1079 item is ignored.
1080 cmd Ex command for this autocmd event
1081 event autocmd event name. Refer to |autocmd-events|.
1082 If '*' then all the autocmd events in this
1083 group are deleted.
1084 group autocmd group name. Refer to |autocmd-groups|.
1085 If not specified or empty, then the default
1086 group is used.
1087 nested set to v:true for a nested autocmd.
1088 Refer to |autocmd-nested|.
1089 once set to v:true for an autocmd which executes
1090 only once. Refer to |autocmd-once|.
1091 pattern autocmd pattern string. Refer to
1092 |autocmd-patterns|. If "bufnr" item is
1093 present, then this item is ignored.
1094
1095 If only {group} is specified in a {acmds} entry and {event},
1096 {pattern} and {cmd} are not specified, then that autocmd group
1097 is deleted.
1098
Bram Moolenaar016188f2022-06-06 20:52:59 +01001099 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001100 Examples: >
1101 " :autocmd! BufLeave *.vim
1102 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1103 call autocmd_delete([acmd]})
1104 " :autocmd! MyGroup1 BufLeave
1105 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1106 call autocmd_delete([acmd])
1107 " :autocmd! MyGroup2 BufEnter *.c
1108 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1109 \ pattern: '*.c'}
1110 " :autocmd! MyGroup2 * *.c
1111 let acmd = #{group: 'MyGroup2', event: '*',
1112 \ pattern: '*.c'}
1113 call autocmd_delete([acmd])
1114 " :autocmd! MyGroup3
1115 let acmd = #{group: 'MyGroup3'}
1116 call autocmd_delete([acmd])
1117<
1118 Can also be used as a |method|: >
1119 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001120<
1121 Return type: |vim9-boolean|
1122
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001123
1124autocmd_get([{opts}]) *autocmd_get()*
1125 Returns a |List| of autocmds. If {opts} is not supplied, then
1126 returns the autocmds for all the events in all the groups.
1127
1128 The optional {opts} Dict argument supports the following
1129 items:
1130 group Autocmd group name. If specified, returns only
1131 the autocmds defined in this group. If the
1132 specified group doesn't exist, results in an
1133 error message. If set to an empty string,
1134 then the default autocmd group is used.
1135 event Autocmd event name. If specified, returns only
1136 the autocmds defined for this event. If set
1137 to "*", then returns autocmds for all the
1138 events. If the specified event doesn't exist,
1139 results in an error message.
1140 pattern Autocmd pattern. If specified, returns only
1141 the autocmds defined for this pattern.
1142 A combination of the above three times can be supplied in
1143 {opts}.
1144
1145 Each Dict in the returned List contains the following items:
1146 bufnr For buffer-local autocmds, buffer number where
1147 the autocmd is defined.
1148 cmd Command executed for this autocmd.
1149 event Autocmd event name.
1150 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001151 nested Boolean flag, set to v:true for a nested
1152 autocmd. See |autocmd-nested|.
1153 once Boolean flag, set to v:true, if the autocmd
1154 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001155 pattern Autocmd pattern. For a buffer-local
1156 autocmd, this will be of the form "<buffer=n>".
1157 If there are multiple commands for an autocmd event in a
1158 group, then separate items are returned for each command.
1159
Bram Moolenaar016188f2022-06-06 20:52:59 +01001160 Returns an empty List if an autocmd with the specified group
1161 or event or pattern is not found.
1162
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001163 Examples: >
1164 " :autocmd MyGroup
1165 echo autocmd_get(#{group: 'Mygroup'})
1166 " :autocmd G BufUnload
1167 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1168 " :autocmd G * *.ts
1169 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1170 echo autocmd_get(acmd)
1171 " :autocmd Syntax
1172 echo autocmd_get(#{event: 'Syntax'})
1173 " :autocmd G BufEnter *.ts
1174 let acmd = #{group: 'G', event: 'BufEnter',
1175 \ pattern: '*.ts'}
1176 echo autocmd_get(acmd)
1177<
1178 Can also be used as a |method|: >
1179 Getopts()->autocmd_get()
1180<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001181 Return type: list<dict<any>>
1182
1183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001184balloon_gettext() *balloon_gettext()*
1185 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001186 not used for the List. Returns an empty string if balloon
1187 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001188
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001189 Return type: |String|
1190
1191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001192balloon_show({expr}) *balloon_show()*
1193 Show {expr} inside the balloon. For the GUI {expr} is used as
1194 a string. For a terminal {expr} can be a list, which contains
1195 the lines of the balloon. If {expr} is not a list it will be
1196 split with |balloon_split()|.
1197 If {expr} is an empty string any existing balloon is removed.
1198
1199 Example: >
1200 func GetBalloonContent()
1201 " ... initiate getting the content
1202 return ''
1203 endfunc
1204 set balloonexpr=GetBalloonContent()
1205
1206 func BalloonCallback(result)
1207 call balloon_show(a:result)
1208 endfunc
1209< Can also be used as a |method|: >
1210 GetText()->balloon_show()
1211<
1212 The intended use is that fetching the content of the balloon
1213 is initiated from 'balloonexpr'. It will invoke an
1214 asynchronous method, in which a callback invokes
1215 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001216 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001217
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001218 When showing a balloon is not possible then nothing happens,
1219 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001220 {only available when compiled with the |+balloon_eval| or
1221 |+balloon_eval_term| feature}
1222
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001223 Return type: |Number|
1224
1225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001226balloon_split({msg}) *balloon_split()*
1227 Split String {msg} into lines to be displayed in a balloon.
1228 The splits are made for the current window size and optimize
1229 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001230 Returns a |List| with the split lines. Returns an empty List
1231 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001232 Can also be used as a |method|: >
1233 GetText()->balloon_split()->balloon_show()
1234
1235< {only available when compiled with the |+balloon_eval_term|
1236 feature}
1237
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001238 Return type: list<any> or list<string>
1239
h-easte80f3452025-01-02 10:40:29 +01001240base64_decode({string}) *base64_decode()*
1241 Return a Blob containing the bytes decoded from the base64
1242 encoded characters in {string}.
1243
1244 The {string} argument should contain only base64-encoded
1245 characters and should have a length that is a multiple of 4.
1246
1247 Returns an empty blob on error.
1248
1249 Examples: >
1250 " Write the decoded contents to a binary file
1251 call writefile(base64_decode(s), 'tools.bmp')
1252 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001253 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001254<
1255 Can also be used as a |method|: >
1256 GetEncodedString()->base64_decode()
1257<
1258 Return type: |Blob|
1259
1260
1261base64_encode({blob}) *base64_encode()*
1262 Return a base64-encoded String representing the bytes in
1263 {blob}. The base64 alphabet defined in RFC 4648 is used.
1264
1265 Examples: >
1266 " Encode the contents of a binary file
1267 echo base64_encode(readblob('somefile.bin'))
1268 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001269 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001270<
1271 Can also be used as a |method|: >
1272 GetBinaryData()->base64_encode()
1273<
1274 Return type: |String|
1275
1276
Christ van Willegence0ef912024-06-20 23:41:59 +02001277bindtextdomain({package}, {path}) *bindtextdomain()*
1278 Bind a specific {package} to a {path} so that the
1279 |gettext()| function can be used to get language-specific
1280 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001281 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001282
Christ van Willegen8252ef12024-07-11 21:36:21 +02001283 Returns v:true on success and v:false on failure (out of
1284 memory).
1285
1286 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001288blob2list({blob}) *blob2list()*
1289 Return a List containing the number value of each byte in Blob
1290 {blob}. Examples: >
1291 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1292 blob2list(0z) returns []
1293< Returns an empty List on error. |list2blob()| does the
1294 opposite.
1295
1296 Can also be used as a |method|: >
1297 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001299 Return type: list<any> or list<number>
1300
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001301
1302blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001303 Return a List of Strings in the current 'encoding' by
1304 converting the bytes in {blob} into characters.
1305
1306 Each <NL> byte in the blob is interpreted as the end of a
1307 string and a new list item is added. Each <NUL> byte in the
1308 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001309
1310 If {options} is not supplied, the current 'encoding' value is
1311 used to decode the bytes in {blob}.
1312
1313 The argument {options} is a |Dict| and supports the following
1314 items:
1315 encoding Decode the bytes in {blob} using this
1316 encoding. The value is a |String|. See
Bakudankunb3854bf2025-02-23 20:29:21 +01001317 |encoding-names| for the supported values
1318 (plus the special value "none").
Christian Brabandtd5afc742025-03-18 20:55:42 +01001319 *E1515* *E1516*
Bakudankunb3854bf2025-02-23 20:29:21 +01001320 When current 'encoding' is "utf-8", an error is given and an
1321 empty List is returned if an invalid byte sequence is
1322 encountered in {blob}. To suppress this validation and get
1323 potentially invalid string, set "encoding" in {options} to
1324 "none".
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001325
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001326 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001327
1328 See also |str2blob()|
1329
1330 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +01001331 blob2str(0z6162) returns ['ab']
1332 blob2str(0zC2ABC2BB) returns ['«»']
1333 blob2str(0z610A62) returns ['a', 'b']
1334 blob2str(0z610062) returns ['a\nb']
1335 blob2str(0zABBB, {'encoding': 'latin1'}) returns ['«»']
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001336<
1337 Can also be used as a |method|: >
1338 GetBlob()->blob2str()
1339<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001340 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001341
1342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001343 *browse()*
1344browse({save}, {title}, {initdir}, {default})
1345 Put up a file requester. This only works when "has("browse")"
1346 returns |TRUE| (only in some GUI versions).
1347 The input fields are:
1348 {save} when |TRUE|, select file to write
1349 {title} title for the requester
1350 {initdir} directory to start browsing in
1351 {default} default file name
1352 An empty string is returned when the "Cancel" button is hit,
1353 something went wrong, or browsing is not possible.
1354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001355 Return type: |String|
1356
1357
1358browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001359 Put up a directory requester. This only works when
1360 "has("browse")" returns |TRUE| (only in some GUI versions).
1361 On systems where a directory browser is not supported a file
1362 browser is used. In that case: select a file in the directory
1363 to be used.
1364 The input fields are:
1365 {title} title for the requester
1366 {initdir} directory to start browsing in
1367 When the "Cancel" button is hit, something went wrong, or
1368 browsing is not possible, an empty string is returned.
1369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001370 Return type: |String|
1371
1372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001373bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001374 Add a buffer to the buffer list with name {name} (must be a
1375 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001376 If a buffer for file {name} already exists, return that buffer
1377 number. Otherwise return the buffer number of the newly
1378 created buffer. When {name} is an empty string then a new
1379 buffer is always created.
1380 The buffer will not have 'buflisted' set and not be loaded
1381 yet. To add some text to the buffer use this: >
1382 let bufnr = bufadd('someName')
1383 call bufload(bufnr)
1384 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001385< Returns 0 on error.
1386 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001387 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001388<
1389 Return type: |Number|
1390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001391
1392bufexists({buf}) *bufexists()*
1393 The result is a Number, which is |TRUE| if a buffer called
1394 {buf} exists.
1395 If the {buf} argument is a number, buffer numbers are used.
1396 Number zero is the alternate buffer for the current window.
1397
1398 If the {buf} argument is a string it must match a buffer name
1399 exactly. The name can be:
1400 - Relative to the current directory.
1401 - A full path.
1402 - The name of a buffer with 'buftype' set to "nofile".
1403 - A URL name.
1404 Unlisted buffers will be found.
1405 Note that help files are listed by their short name in the
1406 output of |:buffers|, but bufexists() requires using their
1407 long name to be able to find them.
1408 bufexists() may report a buffer exists, but to use the name
1409 with a |:buffer| command you may need to use |expand()|. Esp
1410 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1411 Use "bufexists(0)" to test for the existence of an alternate
1412 file name.
1413
1414 Can also be used as a |method|: >
1415 let exists = 'somename'->bufexists()
1416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417 Return type: |Number|
1418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001419 Obsolete name: buffer_exists(). *buffer_exists()*
1420
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001422buflisted({buf}) *buflisted()*
1423 The result is a Number, which is |TRUE| if a buffer called
1424 {buf} exists and is listed (has the 'buflisted' option set).
1425 The {buf} argument is used like with |bufexists()|.
1426
1427 Can also be used as a |method|: >
1428 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001429<
1430 Return type: |Number|
1431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001432
1433bufload({buf}) *bufload()*
1434 Ensure the buffer {buf} is loaded. When the buffer name
1435 refers to an existing file then the file is read. Otherwise
1436 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001437 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001438 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001439 If there is an existing swap file for the file of the buffer,
1440 there will be no dialog, the buffer will be loaded anyway.
1441 The {buf} argument is used like with |bufexists()|.
1442
1443 Can also be used as a |method|: >
1444 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001445<
1446 Return type: |Number|
1447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001448
1449bufloaded({buf}) *bufloaded()*
1450 The result is a Number, which is |TRUE| if a buffer called
1451 {buf} exists and is loaded (shown in a window or hidden).
1452 The {buf} argument is used like with |bufexists()|.
1453
1454 Can also be used as a |method|: >
1455 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001456<
1457 Return type: |Number|
1458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001459
1460bufname([{buf}]) *bufname()*
1461 The result is the name of a buffer. Mostly as it is displayed
1462 by the `:ls` command, but not using special names such as
1463 "[No Name]".
1464 If {buf} is omitted the current buffer is used.
1465 If {buf} is a Number, that buffer number's name is given.
1466 Number zero is the alternate buffer for the current window.
1467 If {buf} is a String, it is used as a |file-pattern| to match
1468 with the buffer names. This is always done like 'magic' is
1469 set and 'cpoptions' is empty. When there is more than one
1470 match an empty string is returned.
1471 "" or "%" can be used for the current buffer, "#" for the
1472 alternate buffer.
1473 A full match is preferred, otherwise a match at the start, end
1474 or middle of the buffer name is accepted. If you only want a
1475 full match then put "^" at the start and "$" at the end of the
1476 pattern.
1477 Listed buffers are found first. If there is a single match
1478 with a listed buffer, that one is returned. Next unlisted
1479 buffers are searched for.
1480 If the {buf} is a String, but you want to use it as a buffer
1481 number, force it to be a Number by adding zero to it: >
1482 :echo bufname("3" + 0)
1483< Can also be used as a |method|: >
1484 echo bufnr->bufname()
1485
1486< If the buffer doesn't exist, or doesn't have a name, an empty
1487 string is returned. >
1488 bufname("#") alternate buffer name
1489 bufname(3) name of buffer 3
1490 bufname("%") name of current buffer
1491 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001492<
1493 Return type: |String|
1494 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001495 Obsolete name: buffer_name().
1496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001497
1498bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499 The result is the number of a buffer, as it is displayed by
1500 the `:ls` command. For the use of {buf}, see |bufname()|
1501 above.
1502
1503 If the buffer doesn't exist, -1 is returned. Or, if the
1504 {create} argument is present and TRUE, a new, unlisted,
1505 buffer is created and its number is returned. Example: >
1506 let newbuf = bufnr('Scratch001', 1)
1507< Using an empty name uses the current buffer. To create a new
1508 buffer with an empty name use |bufadd()|.
1509
1510 bufnr("$") is the last buffer: >
1511 :let last_buffer = bufnr("$")
1512< The result is a Number, which is the highest buffer number
1513 of existing buffers. Note that not all buffers with a smaller
1514 number necessarily exist, because ":bwipeout" may have removed
1515 them. Use bufexists() to test for the existence of a buffer.
1516
1517 Can also be used as a |method|: >
1518 echo bufref->bufnr()
1519<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001520 Return type: |Number|
1521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522 Obsolete name: buffer_number(). *buffer_number()*
1523 *last_buffer_nr()*
1524 Obsolete name for bufnr("$"): last_buffer_nr().
1525
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001527bufwinid({buf}) *bufwinid()*
1528 The result is a Number, which is the |window-ID| of the first
1529 window associated with buffer {buf}. For the use of {buf},
1530 see |bufname()| above. If buffer {buf} doesn't exist or
1531 there is no such window, -1 is returned. Example: >
1532
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001533 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001534<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001535 Only deals with the current tab page. See |win_findbuf()| for
1536 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001537
1538 Can also be used as a |method|: >
1539 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001540<
1541 Return type: |Number|
1542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001543
1544bufwinnr({buf}) *bufwinnr()*
1545 Like |bufwinid()| but return the window number instead of the
1546 |window-ID|.
1547 If buffer {buf} doesn't exist or there is no such window, -1
1548 is returned. Example: >
1549
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001550 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001551
1552< The number can be used with |CTRL-W_w| and ":wincmd w"
1553 |:wincmd|.
1554
1555 Can also be used as a |method|: >
1556 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001557<
1558 Return type: |Number|
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560
1561byte2line({byte}) *byte2line()*
1562 Return the line number that contains the character at byte
1563 count {byte} in the current buffer. This includes the
1564 end-of-line character, depending on the 'fileformat' option
1565 for the current buffer. The first character has byte count
1566 one.
1567 Also see |line2byte()|, |go| and |:goto|.
1568
Bram Moolenaar016188f2022-06-06 20:52:59 +01001569 Returns -1 if the {byte} value is invalid.
1570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001571 Can also be used as a |method|: >
1572 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001573<
1574 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001576 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577 feature}
1578
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001579
Christian Brabandt67672ef2023-04-24 21:09:54 +01001580byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581 Return byte index of the {nr}'th character in the String
1582 {expr}. Use zero for the first character, it then returns
1583 zero.
1584 If there are no multibyte characters the returned value is
1585 equal to {nr}.
1586 Composing characters are not counted separately, their byte
1587 length is added to the preceding base character. See
1588 |byteidxcomp()| below for counting composing characters
1589 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001590 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1591 index in the String {expr} instead of as the character index.
1592 The UTF-16 index is the index in the string when it is encoded
1593 with 16-bit words. If the specified UTF-16 index is in the
1594 middle of a character (e.g. in a 4-byte character), then the
1595 byte index of the first byte in the character is returned.
1596 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001597 Example : >
1598 echo matchstr(str, ".", byteidx(str, 3))
1599< will display the fourth character. Another way to do the
1600 same: >
1601 let s = strpart(str, byteidx(str, 3))
1602 echo strpart(s, 0, byteidx(s, 1))
1603< Also see |strgetchar()| and |strcharpart()|.
1604
1605 If there are less than {nr} characters -1 is returned.
1606 If there are exactly {nr} characters the length of the string
1607 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001608 See |charidx()| and |utf16idx()| for getting the character and
1609 UTF-16 index respectively from the byte index.
1610 Examples: >
1611 echo byteidx('a😊😊', 2) returns 5
1612 echo byteidx('a😊😊', 2, 1) returns 1
1613 echo byteidx('a😊😊', 3, 1) returns 5
1614<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001615 Can also be used as a |method|: >
1616 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001617<
1618 Return type: |Number|
1619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620
Christian Brabandt67672ef2023-04-24 21:09:54 +01001621byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622 Like byteidx(), except that a composing character is counted
1623 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001624 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001625 echo byteidx(s, 1)
1626 echo byteidxcomp(s, 1)
1627 echo byteidxcomp(s, 2)
1628< The first and third echo result in 3 ('e' plus composing
1629 character is 3 bytes), the second echo results in 1 ('e' is
1630 one byte).
1631 Only works differently from byteidx() when 'encoding' is set
1632 to a Unicode encoding.
1633
1634 Can also be used as a |method|: >
1635 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001636<
1637 Return type: |Number|
1638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001639
1640call({func}, {arglist} [, {dict}]) *call()* *E699*
1641 Call function {func} with the items in |List| {arglist} as
1642 arguments.
1643 {func} can either be a |Funcref| or the name of a function.
1644 a:firstline and a:lastline are set to the cursor line.
1645 Returns the return value of the called function.
1646 {dict} is for functions with the "dict" attribute. It will be
1647 used to set the local variable "self". |Dictionary-function|
1648
1649 Can also be used as a |method|: >
1650 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001651<
1652 Return type: any, depending on {func}
1653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001654
1655ceil({expr}) *ceil()*
1656 Return the smallest integral value greater than or equal to
1657 {expr} as a |Float| (round up).
1658 {expr} must evaluate to a |Float| or a |Number|.
1659 Examples: >
1660 echo ceil(1.456)
1661< 2.0 >
1662 echo ceil(-5.456)
1663< -5.0 >
1664 echo ceil(4.0)
1665< 4.0
1666
Bram Moolenaar016188f2022-06-06 20:52:59 +01001667 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 Can also be used as a |method|: >
1670 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001671<
1672 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
1674
1675ch_ functions are documented here: |channel-functions-details|
1676
1677
1678changenr() *changenr()*
1679 Return the number of the most recent change. This is the same
1680 number as what is displayed with |:undolist| and can be used
1681 with the |:undo| command.
1682 When a change was made it is the number of that change. After
1683 redo it is the number of the redone change. After undo it is
1684 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001685 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001687 Return type: |Number|
1688
1689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001691 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001692 Examples: >
1693 char2nr(" ") returns 32
1694 char2nr("ABC") returns 65
1695< When {utf8} is omitted or zero, the current 'encoding' is used.
1696 Example for "utf-8": >
1697 char2nr("á") returns 225
1698 char2nr("á"[0]) returns 195
1699< When {utf8} is TRUE, always treat as UTF-8 characters.
1700 A combining character is a separate character.
1701 |nr2char()| does the opposite.
1702 To turn a string into a list of character numbers: >
1703 let str = "ABC"
1704 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1705< Result: [65, 66, 67]
1706
Bram Moolenaar016188f2022-06-06 20:52:59 +01001707 Returns 0 if {string} is not a |String|.
1708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709 Can also be used as a |method|: >
1710 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001711<
1712 Return type: |Number|
1713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715charclass({string}) *charclass()*
1716 Return the character class of the first character in {string}.
1717 The character class is one of:
1718 0 blank
1719 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001720 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001721 3 emoji
1722 other specific Unicode class
1723 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001724 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001726 Return type: |Number|
1727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001728
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001729charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730 Same as |col()| but returns the character index of the column
1731 position given with {expr} instead of the byte position.
1732
1733 Example:
1734 With the cursor on '세' in line 5 with text "여보세요": >
1735 charcol('.') returns 3
1736 col('.') returns 7
1737
1738< Can also be used as a |method|: >
1739 GetPos()->col()
1740<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001741 Return type: |Number|
1742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001743 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001744charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Return the character index of the byte at {idx} in {string}.
1746 The index of the first character is zero.
1747 If there are no multibyte characters the returned value is
1748 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001750 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001751 are not counted separately, their byte length is added to the
1752 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001753 When {countcc} is |TRUE|, then composing characters are
1754 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001755
1756 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1757 index in the String {expr} instead of as the byte index.
1758
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001759 Returns -1 if the arguments are invalid or if there are less
1760 than {idx} bytes. If there are exactly {idx} bytes the length
1761 of the string in characters is returned.
1762
1763 An error is given and -1 is returned if the first argument is
1764 not a string, the second argument is not a number or when the
1765 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001767 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001768 from the character index and |utf16idx()| for getting the
1769 UTF-16 index from the character index.
1770 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771 Examples: >
1772 echo charidx('áb́ć', 3) returns 1
1773 echo charidx('áb́ć', 6, 1) returns 4
1774 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001775 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001776<
1777 Can also be used as a |method|: >
1778 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001779<
1780 Return type: |Number|
1781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001782
1783chdir({dir}) *chdir()*
1784 Change the current working directory to {dir}. The scope of
1785 the directory change depends on the directory of the current
1786 window:
1787 - If the current window has a window-local directory
1788 (|:lcd|), then changes the window local directory.
1789 - Otherwise, if the current tabpage has a local
1790 directory (|:tcd|) then changes the tabpage local
1791 directory.
1792 - Otherwise, changes the global directory.
1793 {dir} must be a String.
1794 If successful, returns the previous working directory. Pass
1795 this to another chdir() to restore the directory.
1796 On failure, returns an empty string.
1797
1798 Example: >
1799 let save_dir = chdir(newdir)
1800 if save_dir != ""
1801 " ... do some work
1802 call chdir(save_dir)
1803 endif
1804
1805< Can also be used as a |method|: >
1806 GetDir()->chdir()
1807<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001808 Return type: |String|
1809
1810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811cindent({lnum}) *cindent()*
1812 Get the amount of indent for line {lnum} according the C
1813 indenting rules, as with 'cindent'.
1814 The indent is counted in spaces, the value of 'tabstop' is
1815 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001816 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001817 See |C-indenting|.
1818
1819 Can also be used as a |method|: >
1820 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821<
1822 Return type: |Number|
1823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001824
1825clearmatches([{win}]) *clearmatches()*
1826 Clears all matches previously defined for the current window
1827 by |matchadd()| and the |:match| commands.
1828 If {win} is specified, use the window with this number or
1829 window ID instead of the current window.
1830
1831 Can also be used as a |method|: >
1832 GetWin()->clearmatches()
1833<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001834 Return type: |Number|
1835
1836
Girish Palya92f68e22025-04-21 11:12:41 +02001837cmdcomplete_info([{what}]) *cmdcomplete_info()*
1838 Returns a |Dictionary| with information about cmdline
1839 completion. See |cmdline-completion|.
1840 The items are:
1841 cmdline_orig The original command-line string before
1842 completion began.
1843 pum_visible |TRUE| if popup menu is visible.
1844 See |pumvisible()|.
1845 matches List of all completion candidates. Each item
1846 is a string.
1847 selected Selected item index. First index is zero.
1848 Index is -1 if no item is selected (showing
1849 typed text only, or the last completion after
1850 no item is selected when using the <Up> or
1851 <Down> keys)
1852
1853 Returns an empty |Dictionary| if no completion was attempted,
1854 if there was only one candidate and it was fully completed, or
1855 if an error occurred.
1856
1857 Return type: dict<any>
1858
1859
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001860col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001861 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001862 position given with {expr}.
1863 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001864 When {expr} is "$", it means the end of the cursor line, so
1865 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001866 Additionally {expr} can be [lnum, col]: a |List| with the line
1867 and column number. Most useful when the column is "$", to get
1868 the last column of a specific line. When "lnum" or "col" is
1869 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001870
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001871 With the optional {winid} argument the values are obtained for
1872 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001874 To get the line number use |line()|. To get both use
1875 |getpos()|.
1876 For the screen column position use |virtcol()|. For the
1877 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001879 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001881 Examples: >
1882 col(".") column of cursor
1883 col("$") length of cursor line plus one
1884 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001885 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001886<
1887 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001888 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001889 For an uppercase mark the column may actually be in another
1890 buffer.
1891 For the cursor position, when 'virtualedit' is active, the
1892 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001893 line. Also, when using a <Cmd> mapping the cursor isn't
1894 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001895 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001896
1897< Can also be used as a |method|: >
1898 GetPos()->col()
1899<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001900 Return type: |Number|
1901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001902
1903complete({startcol}, {matches}) *complete()* *E785*
1904 Set the matches for Insert mode completion.
1905 Can only be used in Insert mode. You need to use a mapping
1906 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1907 or with an expression mapping.
1908 {startcol} is the byte offset in the line where the completed
1909 text start. The text up to the cursor is the original text
1910 that will be replaced by the matches. Use col('.') for an
1911 empty string. "col('.') - 1" will replace one character by a
1912 match.
1913 {matches} must be a |List|. Each |List| item is one match.
1914 See |complete-items| for the kind of items that are possible.
1915 "longest" in 'completeopt' is ignored.
1916 Note that the after calling this function you need to avoid
1917 inserting anything that would cause completion to stop.
1918 The match can be selected with CTRL-N and CTRL-P as usual with
1919 Insert mode completion. The popup menu will appear if
1920 specified, see |ins-completion-menu|.
1921 Example: >
1922 inoremap <F5> <C-R>=ListMonths()<CR>
1923
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001924 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001925 call complete(col('.'), ['January', 'February', 'March',
1926 \ 'April', 'May', 'June', 'July', 'August', 'September',
1927 \ 'October', 'November', 'December'])
1928 return ''
1929 endfunc
1930< This isn't very useful, but it shows how it works. Note that
1931 an empty string is returned to avoid a zero being inserted.
1932
1933 Can also be used as a |method|, the base is passed as the
1934 second argument: >
1935 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001936<
1937 Return type: |Number|
1938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001939
1940complete_add({expr}) *complete_add()*
1941 Add {expr} to the list of matches. Only to be used by the
1942 function specified with the 'completefunc' option.
1943 Returns 0 for failure (empty string or out of memory),
1944 1 when the match was added, 2 when the match was already in
1945 the list.
1946 See |complete-functions| for an explanation of {expr}. It is
1947 the same as one item in the list that 'omnifunc' would return.
1948
1949 Can also be used as a |method|: >
1950 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001951<
1952 Return type: |Number|
1953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954
1955complete_check() *complete_check()*
1956 Check for a key typed while looking for completion matches.
1957 This is to be used when looking for matches takes some time.
1958 Returns |TRUE| when searching for matches is to be aborted,
1959 zero otherwise.
1960 Only to be used by the function specified with the
1961 'completefunc' option.
1962
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001963 Return type: |Number|
1964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001965
1966complete_info([{what}]) *complete_info()*
1967 Returns a |Dictionary| with information about Insert mode
1968 completion. See |ins-completion|.
1969 The items are:
1970 mode Current completion mode name string.
1971 See |complete_info_mode| for the values.
1972 pum_visible |TRUE| if popup menu is visible.
1973 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001974 items List of all completion candidates. Each item
1975 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001976 "abbr", "menu", "kind", "info" and "user_data".
1977 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001978 matches Same as "items", but only returns items that
1979 are matching current query. If both "matches"
1980 and "items" are in "what", the returned list
1981 will still be named "items", but each item
1982 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001983 selected Selected item index. First index is zero.
1984 Index is -1 if no item is selected (showing
1985 typed text only, or the last completion after
1986 no item is selected when using the <Up> or
1987 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001988 completed Return a dictionary containing the entries of
1989 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990
1991 *complete_info_mode*
1992 mode values are:
1993 "" Not in completion mode
1994 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1995 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1996 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1997 |i_CTRL-X_CTRL-Y|
1998 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1999 "files" File names |i_CTRL-X_CTRL-F|
2000 "tags" Tags |i_CTRL-X_CTRL-]|
2001 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
2002 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
2003 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
2004 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
2005 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
2006 "function" User defined completion |i_CTRL-X_CTRL-U|
2007 "omni" Omni completion |i_CTRL-X_CTRL-O|
2008 "spell" Spelling suggestions |i_CTRL-X_s|
2009 "eval" |complete()| completion
2010 "unknown" Other internal modes
2011
2012 If the optional {what} list argument is supplied, then only
2013 the items listed in {what} are returned. Unsupported items in
2014 {what} are silently ignored.
2015
2016 To get the position and size of the popup menu, see
2017 |pum_getpos()|. It's also available in |v:event| during the
2018 |CompleteChanged| event.
2019
Bram Moolenaar016188f2022-06-06 20:52:59 +01002020 Returns an empty |Dictionary| on error.
2021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002022 Examples: >
2023 " Get all items
2024 call complete_info()
2025 " Get only 'mode'
2026 call complete_info(['mode'])
2027 " Get only 'mode' and 'pum_visible'
2028 call complete_info(['mode', 'pum_visible'])
2029
2030< Can also be used as a |method|: >
2031 GetItems()->complete_info()
2032<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002033 Return type: dict<any>
2034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002035 *confirm()*
2036confirm({msg} [, {choices} [, {default} [, {type}]]])
2037 confirm() offers the user a dialog, from which a choice can be
2038 made. It returns the number of the choice. For the first
2039 choice this is 1.
2040 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002041 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002042
2043 {msg} is displayed in a |dialog| with {choices} as the
2044 alternatives. When {choices} is missing or empty, "&OK" is
2045 used (and translated).
2046 {msg} is a String, use '\n' to include a newline. Only on
2047 some systems the string is wrapped when it doesn't fit.
2048
2049 {choices} is a String, with the individual choices separated
2050 by '\n', e.g. >
2051 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2052< The letter after the '&' is the shortcut key for that choice.
2053 Thus you can type 'c' to select "Cancel". The shortcut does
2054 not need to be the first letter: >
2055 confirm("file has been modified", "&Save\nSave &All")
2056< For the console, the first letter of each choice is used as
2057 the default shortcut key. Case is ignored.
2058
2059 The optional {default} argument is the number of the choice
2060 that is made if the user hits <CR>. Use 1 to make the first
2061 choice the default one. Use 0 to not set a default. If
2062 {default} is omitted, 1 is used.
2063
2064 The optional {type} String argument gives the type of dialog.
2065 This is only used for the icon of the GTK, Mac, Motif and
2066 Win32 GUI. It can be one of these values: "Error",
2067 "Question", "Info", "Warning" or "Generic". Only the first
2068 character is relevant. When {type} is omitted, "Generic" is
2069 used.
2070
2071 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2072 or another valid interrupt key, confirm() returns 0.
2073
2074 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002075 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002076 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002077 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002078 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002079 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002080 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002081 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002082 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002083 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002084< In a GUI dialog, buttons are used. The layout of the buttons
2085 depends on the 'v' flag in 'guioptions'. If it is included,
2086 the buttons are always put vertically. Otherwise, confirm()
2087 tries to put the buttons in one horizontal line. If they
2088 don't fit, a vertical layout is used anyway. For some systems
2089 the horizontal layout is always used.
2090
2091 Can also be used as a |method|in: >
2092 BuildMessage()->confirm("&Yes\n&No")
2093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002094 Return type: |Number|
2095
2096
2097copy({expr}) *copy()*
2098 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002099 different from using {expr} directly.
2100 When {expr} is a |List| a shallow copy is created. This means
2101 that the original |List| can be changed without changing the
2102 copy, and vice versa. But the items are identical, thus
2103 changing an item changes the contents of both |Lists|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002104 A |Tuple| or |Dictionary| is copied in a similar way as a
2105 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002106 Also see |deepcopy()|.
2107 Can also be used as a |method|: >
2108 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002109<
2110 Return type: any, depending on {expr}
2111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002112
2113cos({expr}) *cos()*
2114 Return the cosine of {expr}, measured in radians, as a |Float|.
2115 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002116 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002117 Examples: >
2118 :echo cos(100)
2119< 0.862319 >
2120 :echo cos(-4.01)
2121< -0.646043
2122
2123 Can also be used as a |method|: >
2124 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002125<
2126 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002127
2128
2129cosh({expr}) *cosh()*
2130 Return the hyperbolic cosine of {expr} as a |Float| in the range
2131 [1, inf].
2132 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002133 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002134 Examples: >
2135 :echo cosh(0.5)
2136< 1.127626 >
2137 :echo cosh(-0.5)
2138< -1.127626
2139
2140 Can also be used as a |method|: >
2141 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002142<
2143 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002144
2145
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002146count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002147 Return the number of times an item with value {expr} appears
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002148 in |String|, |List|, |Tuple| or |Dictionary| {comp}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002149
2150 If {start} is given then start with the item with this index.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002151 {start} can only be used with a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002152
2153 When {ic} is given and it's |TRUE| then case is ignored.
2154
2155 When {comp} is a string then the number of not overlapping
2156 occurrences of {expr} is returned. Zero is returned when
2157 {expr} is an empty string.
2158
2159 Can also be used as a |method|: >
2160 mylist->count(val)
2161<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002162 Return type: |Number|
2163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002164 *cscope_connection()*
2165cscope_connection([{num} , {dbpath} [, {prepend}]])
2166 Checks for the existence of a |cscope| connection. If no
2167 parameters are specified, then the function returns:
2168 0, if cscope was not available (not compiled in), or
2169 if there are no cscope connections;
2170 1, if there is at least one cscope connection.
2171
2172 If parameters are specified, then the value of {num}
2173 determines how existence of a cscope connection is checked:
2174
2175 {num} Description of existence check
2176 ----- ------------------------------
2177 0 Same as no parameters (e.g., "cscope_connection()").
2178 1 Ignore {prepend}, and use partial string matches for
2179 {dbpath}.
2180 2 Ignore {prepend}, and use exact string matches for
2181 {dbpath}.
2182 3 Use {prepend}, use partial string matches for both
2183 {dbpath} and {prepend}.
2184 4 Use {prepend}, use exact string matches for both
2185 {dbpath} and {prepend}.
2186
2187 Note: All string comparisons are case sensitive!
2188
2189 Examples. Suppose we had the following (from ":cs show"): >
2190
2191 # pid database name prepend path
2192 0 27664 cscope.out /usr/local
2193<
2194 Invocation Return Val ~
2195 ---------- ---------- >
2196 cscope_connection() 1
2197 cscope_connection(1, "out") 1
2198 cscope_connection(2, "out") 0
2199 cscope_connection(3, "out") 0
2200 cscope_connection(3, "out", "local") 1
2201 cscope_connection(4, "out") 0
2202 cscope_connection(4, "out", "local") 0
2203 cscope_connection(4, "cscope.out", "/usr/local") 1
2204<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002205 Return type: |Number|
2206
2207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002208cursor({lnum}, {col} [, {off}]) *cursor()*
2209cursor({list})
2210 Positions the cursor at the column (byte count) {col} in the
2211 line {lnum}. The first column is one.
2212
2213 When there is one argument {list} this is used as a |List|
2214 with two, three or four item:
2215 [{lnum}, {col}]
2216 [{lnum}, {col}, {off}]
2217 [{lnum}, {col}, {off}, {curswant}]
2218 This is like the return value of |getpos()| or |getcurpos()|,
2219 but without the first item.
2220
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002221 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002222 |setcursorcharpos()|.
2223
2224 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002225 {lnum} is used like with |getline()|, except that if {lnum} is
2226 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002227 If {lnum} is greater than the number of lines in the buffer,
2228 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002229 If {col} is greater than the number of bytes in the line,
2230 the cursor will be positioned at the last character in the
2231 line.
2232 If {col} is zero, the cursor will stay in the current column.
2233 If {curswant} is given it is used to set the preferred column
2234 for vertical movement. Otherwise {col} is used.
2235
2236 When 'virtualedit' is used {off} specifies the offset in
2237 screen columns from the start of the character. E.g., a
2238 position within a <Tab> or after the last character.
2239 Returns 0 when the position could be set, -1 otherwise.
2240
2241 Can also be used as a |method|: >
2242 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002243<
2244 Return type: |Number|
2245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002246
2247debugbreak({pid}) *debugbreak()*
2248 Specifically used to interrupt a program being debugged. It
2249 will cause process {pid} to get a SIGTRAP. Behavior for other
2250 processes is undefined. See |terminal-debugger|.
2251 {only available on MS-Windows}
2252
Bram Moolenaar016188f2022-06-06 20:52:59 +01002253 Returns |TRUE| if successfully interrupted the program.
2254 Otherwise returns |FALSE|.
2255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002256 Can also be used as a |method|: >
2257 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002258<
2259 Return type: |Number|
2260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002261
2262deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2263 Make a copy of {expr}. For Numbers and Strings this isn't
2264 different from using {expr} directly.
2265 When {expr} is a |List| a full copy is created. This means
2266 that the original |List| can be changed without changing the
2267 copy, and vice versa. When an item is a |List| or
2268 |Dictionary|, a copy for it is made, recursively. Thus
2269 changing an item in the copy does not change the contents of
2270 the original |List|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002271 A |Tuple| or |Dictionary| is copied in a similar way as a
2272 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002273
2274 When {noref} is omitted or zero a contained |List| or
2275 |Dictionary| is only copied once. All references point to
2276 this single copy. With {noref} set to 1 every occurrence of a
2277 |List| or |Dictionary| results in a new copy. This also means
2278 that a cyclic reference causes deepcopy() to fail.
2279 *E724*
2280 Nesting is possible up to 100 levels. When there is an item
2281 that refers back to a higher level making a deep copy with
2282 {noref} set to 1 will fail.
2283 Also see |copy()|.
2284
2285 Can also be used as a |method|: >
2286 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002287<
2288 Return type: any, depending on {expr}
2289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002290
2291delete({fname} [, {flags}]) *delete()*
2292 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002293 name {fname}.
2294
2295 This also works when {fname} is a symbolic link. The symbolic
2296 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002297
2298 When {flags} is "d": Deletes the directory by the name
2299 {fname}. This fails when directory {fname} is not empty.
2300
2301 When {flags} is "rf": Deletes the directory by the name
2302 {fname} and everything in it, recursively. BE CAREFUL!
2303 Note: on MS-Windows it is not possible to delete a directory
2304 that is being used.
2305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002306 The result is a Number, which is 0/false if the delete
2307 operation was successful and -1/true when the deletion failed
2308 or partly failed.
2309
2310 Use |remove()| to delete an item from a |List|.
2311 To delete a line from the buffer use |:delete| or
2312 |deletebufline()|.
2313
2314 Can also be used as a |method|: >
2315 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002316<
2317 Return type: |Number|
2318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002319
2320deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2321 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2322 If {last} is omitted then delete line {first} only.
2323 On success 0 is returned, on failure 1 is returned.
2324
2325 This function works only for loaded buffers. First call
2326 |bufload()| if needed.
2327
2328 For the use of {buf}, see |bufname()| above.
2329
2330 {first} and {last} are used like with |getline()|. Note that
2331 when using |line()| this refers to the current buffer. Use "$"
2332 to refer to the last line in buffer {buf}.
2333
2334 Can also be used as a |method|: >
2335 GetBuffer()->deletebufline(1)
2336<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002337 Return type: |Number|
2338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002339 *did_filetype()*
2340did_filetype() Returns |TRUE| when autocommands are being executed and the
2341 FileType event has been triggered at least once. Can be used
2342 to avoid triggering the FileType event again in the scripts
2343 that detect the file type. |FileType|
2344 Returns |FALSE| when `:setf FALLBACK` was used.
2345 When editing another file, the counter is reset, thus this
2346 really checks if the FileType event has been triggered for the
2347 current buffer. This allows an autocommand that starts
2348 editing another buffer to set 'filetype' and load a syntax
2349 file.
2350
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002351 Return type: |Number|
2352
2353
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002354diff({fromlist}, {tolist} [, {options}]) *diff()*
2355 Returns a String or a List containing the diff between the
2356 strings in {fromlist} and {tolist}. Uses the Vim internal
2357 diff library to compute the diff.
2358
2359 *E106*
2360 The optional "output" item in {options} specifies the returned
2361 diff format. The following values are supported:
2362 indices Return a List of the starting and ending
2363 indices and a count of the strings in each
2364 diff hunk.
2365 unified Return the unified diff output as a String.
2366 This is the default.
2367
2368 If the "output" item in {options} is "indices", then a List is
2369 returned. Each List item contains a Dict with the following
2370 items for each diff hunk:
2371 from_idx start index in {fromlist} for this diff hunk.
2372 from_count number of strings in {fromlist} that are
2373 added/removed/modified in this diff hunk.
2374 to_idx start index in {tolist} for this diff hunk.
2375 to_count number of strings in {tolist} that are
2376 added/removed/modified in this diff hunk.
2377
2378 The {options} Dict argument also specifies diff options
2379 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002380 algorithm Dict specifying the diff algorithm to
2381 use. Supported boolean items are
2382 "myers", "minimal", "patience" and
2383 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002384 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002385 iblank ignore changes where lines are all
2386 blank.
2387 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002388 indent-heuristic use the indent heuristic for the
2389 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002390 iwhite ignore changes in amount of white
2391 space.
2392 iwhiteall ignore all white space changes.
2393 iwhiteeol ignore white space changes at end of
2394 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002395 For more information about these options, refer to 'diffopt'.
2396
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002397 To compute the unified diff, all the items in {fromlist} are
2398 concatenated into a string using a newline separator and the
2399 same for {tolist}. The unified diff output uses line numbers.
2400
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002401 Returns an empty List or String if {fromlist} and {tolist} are
2402 identical.
2403
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002404 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002405 :echo diff(['abc'], ['xxx'])
2406 @@ -1 +1 @@
2407 -abc
2408 +xxx
2409
2410 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2411 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2412 :echo diff(readfile('oldfile'), readfile('newfile'))
2413 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002414<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002415 For more examples, refer to |diff-func-examples|
2416
2417 Can also be used as a |method|: >
2418 GetFromList->diff(to_list)
2419<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002420 Return type: |String| or list<dict<number>> or list<any>
2421 depending on {options}
2422
2423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002424diff_filler({lnum}) *diff_filler()*
2425 Returns the number of filler lines above line {lnum}.
2426 These are the lines that were inserted at this point in
2427 another diff'ed window. These filler lines are shown in the
2428 display but don't exist in the buffer.
2429 {lnum} is used like with |getline()|. Thus "." is the current
2430 line, "'m" mark m, etc.
2431 Returns 0 if the current window is not in diff mode.
2432
2433 Can also be used as a |method|: >
2434 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002435<
2436 Return type: |Number|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438
2439diff_hlID({lnum}, {col}) *diff_hlID()*
2440 Returns the highlight ID for diff mode at line {lnum} column
2441 {col} (byte index). When the current line does not have a
2442 diff change zero is returned.
2443 {lnum} is used like with |getline()|. Thus "." is the current
2444 line, "'m" mark m, etc.
2445 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2446 line.
2447 The highlight ID can be used with |synIDattr()| to obtain
2448 syntax information about the highlighting.
2449
2450 Can also be used as a |method|: >
2451 GetLnum()->diff_hlID(col)
2452<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002453 Return type: |Number|
2454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002455
2456digraph_get({chars}) *digraph_get()* *E1214*
2457 Return the digraph of {chars}. This should be a string with
2458 exactly two characters. If {chars} are not just two
2459 characters, or the digraph of {chars} does not exist, an error
2460 is given and an empty string is returned.
2461
2462 The character will be converted from Unicode to 'encoding'
2463 when needed. This does require the conversion to be
2464 available, it might fail.
2465
2466 Also see |digraph_getlist()|.
2467
2468 Examples: >
2469 " Get a built-in digraph
2470 :echo digraph_get('00') " Returns '∞'
2471
2472 " Get a user-defined digraph
2473 :call digraph_set('aa', 'あ')
2474 :echo digraph_get('aa') " Returns 'あ'
2475<
2476 Can also be used as a |method|: >
2477 GetChars()->digraph_get()
2478<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002479 Return type: |String|
2480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002481 This function works only when compiled with the |+digraphs|
2482 feature. If this feature is disabled, this function will
2483 display an error message.
2484
2485
2486digraph_getlist([{listall}]) *digraph_getlist()*
2487 Return a list of digraphs. If the {listall} argument is given
2488 and it is TRUE, return all digraphs, including the default
2489 digraphs. Otherwise, return only user-defined digraphs.
2490
2491 The characters will be converted from Unicode to 'encoding'
2492 when needed. This does require the conservation to be
2493 available, it might fail.
2494
2495 Also see |digraph_get()|.
2496
2497 Examples: >
2498 " Get user-defined digraphs
2499 :echo digraph_getlist()
2500
2501 " Get all the digraphs, including default digraphs
2502 :echo digraph_getlist(1)
2503<
2504 Can also be used as a |method|: >
2505 GetNumber()->digraph_getlist()
2506<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002507 Return type: list<list<string>>
2508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002509 This function works only when compiled with the |+digraphs|
2510 feature. If this feature is disabled, this function will
2511 display an error message.
2512
2513
Bram Moolenaara2baa732022-02-04 16:09:54 +00002514digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002515 Add digraph {chars} to the list. {chars} must be a string
2516 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002517 encoded character. *E1215*
2518 Be careful, composing characters are NOT ignored. This
2519 function is similar to |:digraphs| command, but useful to add
2520 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002522 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002523 this fails an error message is given and v:false is returned.
2524
2525 If you want to define multiple digraphs at once, you can use
2526 |digraph_setlist()|.
2527
2528 Example: >
2529 call digraph_set(' ', 'あ')
2530<
2531 Can be used as a |method|: >
2532 GetString()->digraph_set('あ')
2533<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002534 Return type: |vim9-boolean|
2535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002536 This function works only when compiled with the |+digraphs|
2537 feature. If this feature is disabled, this function will
2538 display an error message.
2539
2540
2541digraph_setlist({digraphlist}) *digraph_setlist()*
2542 Similar to |digraph_set()| but this function can add multiple
2543 digraphs at once. {digraphlist} is a list composed of lists,
2544 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002545 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002546 Example: >
2547 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2548<
2549 It is similar to the following: >
2550 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2551 call digraph_set(chars, digraph)
2552 endfor
2553< Except that the function returns after the first error,
2554 following digraphs will not be added.
2555
2556 Can be used as a |method|: >
2557 GetList()->digraph_setlist()
2558<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002559 Return type: |vim9-boolean|
2560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002561 This function works only when compiled with the |+digraphs|
2562 feature. If this feature is disabled, this function will
2563 display an error message.
2564
2565
2566echoraw({string}) *echoraw()*
2567 Output {string} as-is, including unprintable characters.
2568 This can be used to output a terminal code. For example, to
2569 disable modifyOtherKeys: >
2570 call echoraw(&t_TE)
2571< and to enable it again: >
2572 call echoraw(&t_TI)
2573< Use with care, you can mess up the terminal this way.
2574
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002575 Return type: |Number|
2576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002577
2578empty({expr}) *empty()*
2579 Return the Number 1 if {expr} is empty, zero otherwise.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002580 - A |List|, |Tuple| or |Dictionary| is empty when it does
2581 not have any items.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582 - A |String| is empty when its length is zero.
2583 - A |Number| and |Float| are empty when their value is zero.
2584 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2585 - A |Job| is empty when it failed to start.
2586 - A |Channel| is empty when it is closed.
2587 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002588 - An |Object| is empty, when the empty() method in the object
2589 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002590
2591 For a long |List| this is much faster than comparing the
2592 length with zero.
2593
2594 Can also be used as a |method|: >
2595 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002596<
2597 Return type: |Number|
2598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002599
2600environ() *environ()*
2601 Return all of environment variables as dictionary. You can
2602 check if an environment variable exists like this: >
2603 :echo has_key(environ(), 'HOME')
2604< Note that the variable name may be CamelCase; to ignore case
2605 use this: >
2606 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002607<
2608 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002609
Bram Moolenaar416bd912023-07-07 23:19:18 +01002610
2611err_teapot([{expr}]) *err_teapot()*
2612 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002613 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002614 If {expr} is present and it is TRUE error 503 is given,
2615 indicating that coffee is temporarily not available.
2616 If {expr} is present it must be a String.
2617
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002618 Return type: |Number|
2619
Bram Moolenaar416bd912023-07-07 23:19:18 +01002620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621escape({string}, {chars}) *escape()*
2622 Escape the characters in {chars} that occur in {string} with a
2623 backslash. Example: >
2624 :echo escape('c:\program files\vim', ' \')
2625< results in: >
2626 c:\\program\ files\\vim
2627< Also see |shellescape()| and |fnameescape()|.
2628
2629 Can also be used as a |method|: >
2630 GetText()->escape(' \')
2631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002632 Return type: |String|
2633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002634 *eval()*
2635eval({string}) Evaluate {string} and return the result. Especially useful to
2636 turn the result of |string()| back into the original value.
2637 This works for Numbers, Floats, Strings, Blobs and composites
2638 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002639 functions. In |Vim9| script, it can be used to obtain |enum|
2640 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002641
2642 Can also be used as a |method|: >
2643 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002644<
2645 Return type: any, depending on {string}
2646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002647
2648eventhandler() *eventhandler()*
2649 Returns 1 when inside an event handler. That is that Vim got
2650 interrupted while waiting for the user to type a character,
2651 e.g., when dropping a file on Vim. This means interactive
2652 commands cannot be used. Otherwise zero is returned.
2653
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002654 Return type: |Number|
2655
2656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657executable({expr}) *executable()*
2658 This function checks if an executable with the name {expr}
2659 exists. {expr} must be the name of the program without any
2660 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002662 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002663 searchpath for programs.
2664 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002665 On MS-Windows the ".exe", ".bat", etc. can optionally be
2666 included. Then the extensions in $PATHEXT are tried. Thus if
2667 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2668 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2669 by itself can be used in $PATHEXT to try using the name
2670 without an extension. When 'shell' looks like a Unix shell,
2671 then the name is also tried without adding an extension.
2672 On MS-Windows it only checks if the file exists and is not a
2673 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002674 On MS-Windows an executable in the same directory as the Vim
2675 executable is always found. Since this directory is added to
2676 $PATH it should also work to execute it |win32-PATH|.
2677 *NoDefaultCurrentDirectoryInExePath*
2678 On MS-Windows an executable in Vim's current working directory
2679 is also normally found, but this can be disabled by setting
2680 the $NoDefaultCurrentDirectoryInExePath environment variable.
2681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002682 The result is a Number:
2683 1 exists
2684 0 does not exist
2685 -1 not implemented on this system
2686 |exepath()| can be used to get the full path of an executable.
2687
2688 Can also be used as a |method|: >
2689 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002690<
2691 Return type: |Number|
2692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002693
2694execute({command} [, {silent}]) *execute()*
2695 Execute an Ex command or commands and return the output as a
2696 string.
2697 {command} can be a string or a List. In case of a List the
2698 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002699 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002700 redir => var
2701 {command}
2702 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002703< Except that line continuation in {command} is not recognized.
2704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002705 The optional {silent} argument can have these values:
2706 "" no `:silent` used
2707 "silent" `:silent` used
2708 "silent!" `:silent!` used
2709 The default is "silent". Note that with "silent!", unlike
2710 `:redir`, error messages are dropped. When using an external
2711 command the screen may be messed up, use `system()` instead.
2712 *E930*
2713 It is not possible to use `:redir` anywhere in {command}.
2714
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002715 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002716 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002717
2718< To execute a command in another window than the current one
2719 use `win_execute()`.
2720
2721 When used recursively the output of the recursive call is not
2722 included in the output of the higher level call.
2723
2724 Can also be used as a |method|: >
2725 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002726<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002727 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002729
2730exepath({expr}) *exepath()*
2731 If {expr} is an executable and is either an absolute path, a
2732 relative path or found in $PATH, return the full path.
2733 Note that the current directory is used when {expr} starts
2734 with "./", which may be a problem for Vim: >
2735 echo exepath(v:progpath)
2736< If {expr} cannot be found in $PATH or is not executable then
2737 an empty string is returned.
2738
2739 Can also be used as a |method|: >
2740 GetCommand()->exepath()
2741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002742 Return type: |String|
2743
2744
2745exists({expr}) *exists()*
2746 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002747 zero otherwise.
2748
2749 Note: In a compiled |:def| function the evaluation is done at
2750 runtime. Use `exists_compiled()` to evaluate the expression
2751 at compile time.
2752
2753 For checking for a supported feature use |has()|.
2754 For checking if a file exists use |filereadable()|.
2755
2756 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002757 varname internal variable (see
2758 dict.key |internal-variables|). Also works
2759 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002760 import.Func entries, |List| items, class and
2761 class.Func object methods, imported items, etc.
2762 object.Func Does not work for local variables in a
2763 class.varname compiled `:def` function.
2764 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002765 script, since it can be used as a
2766 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002767 Beware that evaluating an index may
2768 cause an error message for an invalid
2769 expression. E.g.: >
2770 :let l = [1, 2, 3]
2771 :echo exists("l[5]")
2772< 0 >
2773 :echo exists("l[xx]")
2774< E121: Undefined variable: xx
2775 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002776 &option-name Vim option (only checks if it exists,
2777 not if it really works)
2778 +option-name Vim option that works.
2779 $ENVNAME environment variable (could also be
2780 done by comparing with an empty
2781 string)
2782 *funcname built-in function (see |functions|)
2783 or user defined function (see
2784 |user-functions|) that is implemented.
2785 Also works for a variable that is a
2786 Funcref.
2787 ?funcname built-in function that could be
2788 implemented; to be used to check if
2789 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002790 :cmdname Ex command: built-in command, user
2791 command or command modifier |:command|.
2792 Returns:
2793 1 for match with start of a command
2794 2 full match with a command
2795 3 matches several user commands
2796 To check for a supported command
2797 always check the return value to be 2.
2798 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002799 :3match The |:3match| command (but you
2800 probably should not use it, it is
2801 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002802 #event autocommand defined for this event
2803 #event#pattern autocommand defined for this event and
2804 pattern (the pattern is taken
2805 literally and compared to the
2806 autocommand patterns character by
2807 character)
2808 #group autocommand group exists
2809 #group#event autocommand defined for this group and
2810 event.
2811 #group#event#pattern
2812 autocommand defined for this group,
2813 event and pattern.
2814 ##event autocommand for this event is
2815 supported.
2816
2817 Examples: >
2818 exists("&shortname")
2819 exists("$HOSTNAME")
2820 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002821 exists("*s:MyFunc") " only for legacy script
2822 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002823 exists("bufcount")
2824 exists(":Make")
2825 exists("#CursorHold")
2826 exists("#BufReadPre#*.gz")
2827 exists("#filetypeindent")
2828 exists("#filetypeindent#FileType")
2829 exists("#filetypeindent#FileType#*")
2830 exists("##ColorScheme")
2831< There must be no space between the symbol (&/$/*/#) and the
2832 name.
2833 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002834 a few cases this is ignored. That may become stricter in the
2835 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002836 Working example: >
2837 exists(":make")
2838< NOT working example: >
2839 exists(":make install")
2840
2841< Note that the argument must be a string, not the name of the
2842 variable itself. For example: >
2843 exists(bufcount)
2844< This doesn't check for existence of the "bufcount" variable,
2845 but gets the value of "bufcount", and checks if that exists.
2846
2847 Can also be used as a |method|: >
2848 Varname()->exists()
2849<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002850 Return type: |String|
2851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002852
2853exists_compiled({expr}) *exists_compiled()*
2854 Like `exists()` but evaluated at compile time. This is useful
2855 to skip a block where a function is used that would otherwise
2856 give an error: >
2857 if exists_compiled('*ThatFunction')
2858 ThatFunction('works')
2859 endif
2860< If `exists()` were used then a compilation error would be
2861 given if ThatFunction() is not defined.
2862
2863 {expr} must be a literal string. *E1232*
2864 Can only be used in a |:def| function. *E1233*
2865 This does not work to check for arguments or local variables.
2866
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002867 Return type: |String|
2868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002869
2870exp({expr}) *exp()*
2871 Return the exponential of {expr} as a |Float| in the range
2872 [0, inf].
2873 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002874 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002875 Examples: >
2876 :echo exp(2)
2877< 7.389056 >
2878 :echo exp(-1)
2879< 0.367879
2880
2881 Can also be used as a |method|: >
2882 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002883<
2884 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002885
2886
2887expand({string} [, {nosuf} [, {list}]]) *expand()*
2888 Expand wildcards and the following special keywords in
2889 {string}. 'wildignorecase' applies.
2890
2891 If {list} is given and it is |TRUE|, a List will be returned.
2892 Otherwise the result is a String and when there are several
2893 matches, they are separated by <NL> characters. [Note: in
2894 version 5.0 a space was used, which caused problems when a
2895 file name contains a space]
2896
2897 If the expansion fails, the result is an empty string. A name
2898 for a non-existing file is not included, unless {string} does
2899 not start with '%', '#' or '<', see below.
2900
Christian Brabandtec9c3262024-02-21 20:40:05 +01002901 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002902 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002904 When {string} starts with '%', '#' or '<', the expansion is
2905 done like for the |cmdline-special| variables with their
2906 associated modifiers. Here is a short overview:
2907
2908 % current file name
2909 # alternate file name
2910 #n alternate file name n
2911 <cfile> file name under the cursor
2912 <afile> autocmd file name
2913 <abuf> autocmd buffer number (as a String!)
2914 <amatch> autocmd matched name
2915 <cexpr> C expression under the cursor
2916 <sfile> sourced script file or function name
2917 <slnum> sourced script line number or function
2918 line number
2919 <sflnum> script file line number, also when in
2920 a function
2921 <SID> "<SNR>123_" where "123" is the
2922 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002923 <script> sourced script file, or script file
2924 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002925 <stack> call stack
2926 <cword> word under the cursor
2927 <cWORD> WORD under the cursor
2928 <client> the {clientid} of the last received
2929 message |server2client()|
2930 Modifiers:
2931 :p expand to full path
2932 :h head (last path component removed)
2933 :t tail (last path component only)
2934 :r root (one extension removed)
2935 :e extension only
2936
2937 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002938 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002939< Note that when expanding a string that starts with '%', '#' or
2940 '<', any following text is ignored. This does NOT work: >
2941 :let doesntwork = expand("%:h.bak")
2942< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002943 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002944< Also note that expanding "<cfile>" and others only returns the
2945 referenced file name without further expansion. If "<cfile>"
2946 is "~/.cshrc", you need to do another expand() to have the
2947 "~/" expanded into the path of the home directory: >
2948 :echo expand(expand("<cfile>"))
2949<
2950 There cannot be white space between the variables and the
2951 following modifier. The |fnamemodify()| function can be used
2952 to modify normal file names.
2953
2954 When using '%' or '#', and the current or alternate file name
2955 is not defined, an empty string is used. Using "%:p" in a
2956 buffer with no name, results in the current directory, with a
2957 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002958 When 'verbose' is set then expanding '%', '#' and <> items
2959 will result in an error message if the argument cannot be
2960 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002961
2962 When {string} does not start with '%', '#' or '<', it is
2963 expanded like a file name is expanded on the command line.
2964 'suffixes' and 'wildignore' are used, unless the optional
2965 {nosuf} argument is given and it is |TRUE|.
2966 Names for non-existing files are included. The "**" item can
2967 be used to search in a directory tree. For example, to find
2968 all "README" files in the current directory and below: >
2969 :echo expand("**/README")
2970<
2971 expand() can also be used to expand variables and environment
2972 variables that are only known in a shell. But this can be
2973 slow, because a shell may be used to do the expansion. See
2974 |expr-env-expand|.
2975 The expanded variable is still handled like a list of file
2976 names. When an environment variable cannot be expanded, it is
2977 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2978 "$FOOBAR".
2979
2980 See |glob()| for finding existing files. See |system()| for
2981 getting the raw output of an external command.
2982
2983 Can also be used as a |method|: >
2984 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002985<
2986 Return type: |String| or list<string> depending on {list}
2987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002988
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002989expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002990 Expand special items in String {string} like what is done for
2991 an Ex command such as `:edit`. This expands special keywords,
2992 like with |expand()|, and environment variables, anywhere in
2993 {string}. "~user" and "~/path" are only expanded at the
2994 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002995
2996 The following items are supported in the {options} Dict
2997 argument:
2998 errmsg If set to TRUE, error messages are displayed
2999 if an error is encountered during expansion.
3000 By default, error messages are not displayed.
3001
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003002 Returns the expanded string. If an error is encountered
3003 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003004
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003005 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003006 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003007 make /path/runtime/doc/builtin.o
3008 :echo expandcmd('make %<.o', {'errmsg': v:true})
3009<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003010 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003011 GetCommand()->expandcmd()
3012<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003013 Return type: |String| or list<string> depending on {list}
3014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003015extend({expr1}, {expr2} [, {expr3}]) *extend()*
3016 {expr1} and {expr2} must be both |Lists| or both
3017 |Dictionaries|.
3018
3019 If they are |Lists|: Append {expr2} to {expr1}.
3020 If {expr3} is given insert the items of {expr2} before the
3021 item with index {expr3} in {expr1}. When {expr3} is zero
3022 insert before the first item. When {expr3} is equal to
3023 len({expr1}) then {expr2} is appended.
3024 Examples: >
3025 :echo sort(extend(mylist, [7, 5]))
3026 :call extend(mylist, [2, 3], 1)
3027< When {expr1} is the same List as {expr2} then the number of
3028 items copied is equal to the original length of the List.
3029 E.g., when {expr3} is 1 you get N new copies of the first item
3030 (where N is the original length of the List).
3031 Use |add()| to concatenate one item to a list. To concatenate
3032 two lists into a new list use the + operator: >
3033 :let newlist = [1, 2, 3] + [4, 5]
3034<
3035 If they are |Dictionaries|:
3036 Add all entries from {expr2} to {expr1}.
3037 If a key exists in both {expr1} and {expr2} then {expr3} is
3038 used to decide what to do:
3039 {expr3} = "keep": keep the value of {expr1}
3040 {expr3} = "force": use the value of {expr2}
3041 {expr3} = "error": give an error message *E737*
3042 When {expr3} is omitted then "force" is assumed.
3043
3044 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003045 make a copy of {expr1} first or use |extendnew()| to return a
3046 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003047 {expr2} remains unchanged.
3048 When {expr1} is locked and {expr2} is not empty the operation
3049 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003050 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051
3052 Can also be used as a |method|: >
3053 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003054<
3055 Return type: list<{type}> or dict<{type}> depending on {expr1}
3056 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003057
3058
3059extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3060 Like |extend()| but instead of adding items to {expr1} a new
3061 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003062 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003063
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003064 Return type: list<{type}> or dict<{type}> depending on {expr1}
3065 and {expr2}, in case of error: |Number|
3066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003067
3068feedkeys({string} [, {mode}]) *feedkeys()*
3069 Characters in {string} are queued for processing as if they
3070 come from a mapping or were typed by the user.
3071
3072 By default the string is added to the end of the typeahead
3073 buffer, thus if a mapping is still being executed the
3074 characters come after them. Use the 'i' flag to insert before
3075 other characters, they will be executed next, before any
3076 characters from a mapping.
3077
3078 The function does not wait for processing of keys contained in
3079 {string}.
3080
3081 To include special keys into {string}, use double-quotes
3082 and "\..." notation |expr-quote|. For example,
3083 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3084 feedkeys('\<CR>') pushes 5 characters.
3085 A special code that might be useful is <Ignore>, it exits the
3086 wait for a character without doing anything. *<Ignore>*
3087
3088 {mode} is a String, which can contain these character flags:
3089 'm' Remap keys. This is default. If {mode} is absent,
3090 keys are remapped.
3091 'n' Do not remap keys.
3092 't' Handle keys as if typed; otherwise they are handled as
3093 if coming from a mapping. This matters for undo,
3094 opening folds, etc.
3095 'L' Lowlevel input. Only works for Unix or when using the
3096 GUI. Keys are used as if they were coming from the
3097 terminal. Other flags are not used. *E980*
3098 When a CTRL-C interrupts and 't' is included it sets
3099 the internal "got_int" flag.
3100 'i' Insert the string instead of appending (see above).
3101 'x' Execute commands until typeahead is empty. This is
3102 similar to using ":normal!". You can call feedkeys()
3103 several times without 'x' and then one time with 'x'
3104 (possibly with an empty {string}) to execute all the
3105 typeahead. Note that when Vim ends in Insert mode it
3106 will behave as if <Esc> is typed, to avoid getting
3107 stuck, waiting for a character to be typed before the
3108 script continues.
3109 Note that if you manage to call feedkeys() while
3110 executing commands, thus calling it recursively, then
3111 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003112 'c' Remove any script context when executing, so that
3113 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003114 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003115 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003116 '!' When used with 'x' will not end Insert mode. Can be
3117 used in a test when a timer is set to exit Insert mode
3118 a little later. Useful for testing CursorHoldI.
3119
3120 Return value is always 0.
3121
3122 Can also be used as a |method|: >
3123 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003124<
3125 Return type: |String| or list<string> depending on {list}
3126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003127
Shougo Matsushita60c87432024-06-03 22:59:27 +02003128filecopy({from}, {to}) *filecopy()*
3129 Copy the file pointed to by the name {from} to {to}. The
3130 result is a Number, which is |TRUE| if the file was copied
3131 successfully, and |FALSE| when it failed.
3132 If a file with name {to} already exists, it will fail.
3133 Note that it does not handle directories (yet).
3134
3135 This function is not available in the |sandbox|.
3136
3137 Can also be used as a |method|: >
3138 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003139<
3140 Return type: |Number|
3141
Shougo Matsushita60c87432024-06-03 22:59:27 +02003142
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003143filereadable({file}) *filereadable()*
3144 The result is a Number, which is |TRUE| when a file with the
3145 name {file} exists, and can be read. If {file} doesn't exist,
3146 or is a directory, the result is |FALSE|. {file} is any
3147 expression, which is used as a String.
3148 If you don't care about the file being readable you can use
3149 |glob()|.
3150 {file} is used as-is, you may want to expand wildcards first: >
3151 echo filereadable('~/.vimrc')
3152 0
3153 echo filereadable(expand('~/.vimrc'))
3154 1
3155
3156< Can also be used as a |method|: >
3157 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003158<
3159 Return type: |Number|
3160
3161 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003162 Obsolete name: file_readable().
3163
3164
3165filewritable({file}) *filewritable()*
3166 The result is a Number, which is 1 when a file with the
3167 name {file} exists, and can be written. If {file} doesn't
3168 exist, or is not writable, the result is 0. If {file} is a
3169 directory, and we can write to it, the result is 2.
3170
3171 Can also be used as a |method|: >
3172 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003173<
3174 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003175
3176
3177filter({expr1}, {expr2}) *filter()*
3178 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3179 For each item in {expr1} evaluate {expr2} and when the result
3180 is zero or false remove the item from the |List| or
3181 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003182 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183
3184 {expr2} must be a |string| or |Funcref|.
3185
3186 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3187 of the current item. For a |Dictionary| |v:key| has the key
3188 of the current item and for a |List| |v:key| has the index of
3189 the current item. For a |Blob| |v:key| has the index of the
3190 current byte. For a |String| |v:key| has the index of the
3191 current character.
3192 Examples: >
3193 call filter(mylist, 'v:val !~ "OLD"')
3194< Removes the items where "OLD" appears. >
3195 call filter(mydict, 'v:key >= 8')
3196< Removes the items with a key below 8. >
3197 call filter(var, 0)
3198< Removes all the items, thus clears the |List| or |Dictionary|.
3199
3200 Note that {expr2} is the result of expression and is then
3201 used as an expression again. Often it is good to use a
3202 |literal-string| to avoid having to double backslashes.
3203
3204 If {expr2} is a |Funcref| it must take two arguments:
3205 1. the key or the index of the current item.
3206 2. the value of the current item.
3207 The function must return |TRUE| if the item should be kept.
3208 Example that keeps the odd items of a list: >
3209 func Odd(idx, val)
3210 return a:idx % 2 == 1
3211 endfunc
3212 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003213< It is shorter when using a |lambda|. In |Vim9| syntax: >
3214 call filter(myList, (idx, val) => idx * val <= 42)
3215< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216 call filter(myList, {idx, val -> idx * val <= 42})
3217< If you do not use "val" you can leave it out: >
3218 call filter(myList, {idx -> idx % 2 == 1})
3219<
3220 In |Vim9| script the result must be true, false, zero or one.
3221 Other values will result in a type error.
3222
3223 For a |List| and a |Dictionary| the operation is done
3224 in-place. If you want it to remain unmodified make a copy
3225 first: >
3226 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3227
3228< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003229 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003230 When an error is encountered while evaluating {expr2} no
3231 further items in {expr1} are processed.
3232 When {expr2} is a Funcref errors inside a function are ignored,
3233 unless it was defined with the "abort" flag.
3234
3235 Can also be used as a |method|: >
3236 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003237<
3238 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3239 depending on {expr1}
3240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003241
3242finddir({name} [, {path} [, {count}]]) *finddir()*
3243 Find directory {name} in {path}. Supports both downwards and
3244 upwards recursive directory searches. See |file-searching|
3245 for the syntax of {path}.
3246
3247 Returns the path of the first found match. When the found
3248 directory is below the current directory a relative path is
3249 returned. Otherwise a full path is returned.
3250 If {path} is omitted or empty then 'path' is used.
3251
3252 If the optional {count} is given, find {count}'s occurrence of
3253 {name} in {path} instead of the first one.
3254 When {count} is negative return all the matches in a |List|.
3255
Bram Moolenaar016188f2022-06-06 20:52:59 +01003256 Returns an empty string if the directory is not found.
3257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003258 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003259
3260 Can also be used as a |method|: >
3261 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003262<
Christian Brabandtb753d802025-04-21 11:31:58 +02003263 Return type: list<string> if {count} is negative, |String|
3264 otherwise
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003266
3267findfile({name} [, {path} [, {count}]]) *findfile()*
3268 Just like |finddir()|, but find a file instead of a directory.
3269 Uses 'suffixesadd'.
3270 Example: >
3271 :echo findfile("tags.vim", ".;")
3272< Searches from the directory of the current file upwards until
3273 it finds the file "tags.vim".
3274
3275 Can also be used as a |method|: >
3276 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003277<
Christian Brabandtb753d802025-04-21 11:31:58 +02003278 Return type: list<string> if {count} is negative, |String|
3279 otherwise
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003281
3282flatten({list} [, {maxdepth}]) *flatten()*
3283 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3284 the result is a |List| without nesting, as if {maxdepth} is
3285 a very large number.
3286 The {list} is changed in place, use |flattennew()| if you do
3287 not want that.
3288 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003289 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003290 *E900*
3291 {maxdepth} means how deep in nested lists changes are made.
3292 {list} is not modified when {maxdepth} is 0.
3293 {maxdepth} must be positive number.
3294
3295 If there is an error the number zero is returned.
3296
3297 Example: >
3298 :echo flatten([1, [2, [3, 4]], 5])
3299< [1, 2, 3, 4, 5] >
3300 :echo flatten([1, [2, [3, 4]], 5], 1)
3301< [1, 2, [3, 4], 5]
3302
3303 Can also be used as a |method|: >
3304 mylist->flatten()
3305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003306 Return type: list<{type}>
3307
3308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003309flattennew({list} [, {maxdepth}]) *flattennew()*
3310 Like |flatten()| but first make a copy of {list}.
3311
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003312 Return type: list<{type}>
3313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003314
3315float2nr({expr}) *float2nr()*
3316 Convert {expr} to a Number by omitting the part after the
3317 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003318 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003319 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003320 When the value of {expr} is out of range for a |Number| the
3321 result is truncated to 0x7fffffff or -0x7fffffff (or when
3322 64-bit Number support is enabled, 0x7fffffffffffffff or
3323 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3324 64-bit Number support is enabled, -0x8000000000000000).
3325 Examples: >
3326 echo float2nr(3.95)
3327< 3 >
3328 echo float2nr(-23.45)
3329< -23 >
3330 echo float2nr(1.0e100)
3331< 2147483647 (or 9223372036854775807) >
3332 echo float2nr(-1.0e150)
3333< -2147483647 (or -9223372036854775807) >
3334 echo float2nr(1.0e-100)
3335< 0
3336
3337 Can also be used as a |method|: >
3338 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003339<
3340 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003341
3342
3343floor({expr}) *floor()*
3344 Return the largest integral value less than or equal to
3345 {expr} as a |Float| (round down).
3346 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003347 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003348 Examples: >
3349 echo floor(1.856)
3350< 1.0 >
3351 echo floor(-5.456)
3352< -6.0 >
3353 echo floor(4.0)
3354< 4.0
3355
3356 Can also be used as a |method|: >
3357 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003358<
3359 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003360
3361
3362fmod({expr1}, {expr2}) *fmod()*
3363 Return the remainder of {expr1} / {expr2}, even if the
3364 division is not representable. Returns {expr1} - i * {expr2}
3365 for some integer i such that if {expr2} is non-zero, the
3366 result has the same sign as {expr1} and magnitude less than
3367 the magnitude of {expr2}. If {expr2} is zero, the value
3368 returned is zero. The value returned is a |Float|.
3369 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003370 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3371 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003372 Examples: >
3373 :echo fmod(12.33, 1.22)
3374< 0.13 >
3375 :echo fmod(-12.33, 1.22)
3376< -0.13
3377
3378 Can also be used as a |method|: >
3379 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003380<
3381 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003382
3383
3384fnameescape({string}) *fnameescape()*
3385 Escape {string} for use as file name command argument. All
3386 characters that have a special meaning, such as '%' and '|'
3387 are escaped with a backslash.
3388 For most systems the characters escaped are
3389 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3390 appears in a filename, it depends on the value of 'isfname'.
3391 A leading '+' and '>' is also escaped (special after |:edit|
3392 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003393 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003394 Example: >
3395 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003396 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003397< results in executing: >
3398 edit \+some\ str\%nge\|name
3399<
3400 Can also be used as a |method|: >
3401 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003402<
3403 Return type: |String|
3404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003405
3406fnamemodify({fname}, {mods}) *fnamemodify()*
3407 Modify file name {fname} according to {mods}. {mods} is a
3408 string of characters like it is used for file names on the
3409 command line. See |filename-modifiers|.
3410 Example: >
3411 :echo fnamemodify("main.c", ":p:h")
3412< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003413 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003414< If {mods} is empty or an unsupported modifier is used then
3415 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003416 When {fname} is empty then with {mods} ":h" returns ".", so
3417 that `:cd` can be used with it. This is different from
3418 expand('%:h') without a buffer name, which returns an empty
3419 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003420 Note: Environment variables don't work in {fname}, use
3421 |expand()| first then.
3422
3423 Can also be used as a |method|: >
3424 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003425<
3426 Return type: |String|
3427
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003428
3429foldclosed({lnum}) *foldclosed()*
3430 The result is a Number. If the line {lnum} is in a closed
3431 fold, the result is the number of the first line in that fold.
3432 If the line {lnum} is not in a closed fold, -1 is returned.
3433 {lnum} is used like with |getline()|. Thus "." is the current
3434 line, "'m" mark m, etc.
3435
3436 Can also be used as a |method|: >
3437 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003438<
3439 Return type: |Number|
3440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003441
3442foldclosedend({lnum}) *foldclosedend()*
3443 The result is a Number. If the line {lnum} is in a closed
3444 fold, the result is the number of the last line in that fold.
3445 If the line {lnum} is not in a closed fold, -1 is returned.
3446 {lnum} is used like with |getline()|. Thus "." is the current
3447 line, "'m" mark m, etc.
3448
3449 Can also be used as a |method|: >
3450 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003451<
3452 Return type: |Number|
3453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003454
3455foldlevel({lnum}) *foldlevel()*
3456 The result is a Number, which is the foldlevel of line {lnum}
3457 in the current buffer. For nested folds the deepest level is
3458 returned. If there is no fold at line {lnum}, zero is
3459 returned. It doesn't matter if the folds are open or closed.
3460 When used while updating folds (from 'foldexpr') -1 is
3461 returned for lines where folds are still to be updated and the
3462 foldlevel is unknown. As a special case the level of the
3463 previous line is usually available.
3464 {lnum} is used like with |getline()|. Thus "." is the current
3465 line, "'m" mark m, etc.
3466
3467 Can also be used as a |method|: >
3468 GetLnum()->foldlevel()
3469<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003470 Return type: |Number|
3471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003472 *foldtext()*
3473foldtext() Returns a String, to be displayed for a closed fold. This is
3474 the default function used for the 'foldtext' option and should
3475 only be called from evaluating 'foldtext'. It uses the
3476 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3477 The returned string looks like this: >
3478 +-- 45 lines: abcdef
3479< The number of leading dashes depends on the foldlevel. The
3480 "45" is the number of lines in the fold. "abcdef" is the text
3481 in the first non-blank line of the fold. Leading white space,
3482 "//" or "/*" and the text from the 'foldmarker' and
3483 'commentstring' options is removed.
3484 When used to draw the actual foldtext, the rest of the line
3485 will be filled with the fold char from the 'fillchars'
3486 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003487 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003488
3489 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003490 {not available when compiled without the |+folding| feature}
3491
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003493foldtextresult({lnum}) *foldtextresult()*
3494 Returns the text that is displayed for the closed fold at line
3495 {lnum}. Evaluates 'foldtext' in the appropriate context.
3496 When there is no closed fold at {lnum} an empty string is
3497 returned.
3498 {lnum} is used like with |getline()|. Thus "." is the current
3499 line, "'m" mark m, etc.
3500 Useful when exporting folded text, e.g., to HTML.
3501 {not available when compiled without the |+folding| feature}
3502
3503
3504 Can also be used as a |method|: >
3505 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003506<
3507 Return type: |String|
3508
Ernie Raele79e2072024-01-13 11:47:33 +01003509
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003510foreach({expr1}, {expr2}) *foreach()* *E1525*
3511 {expr1} must be a |List|, |Tuple|, |String|, |Blob| or
3512 |Dictionary|.
Ernie Raele79e2072024-01-13 11:47:33 +01003513 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003514 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003515 See |map()| and |filter()| to modify {expr1}.
3516
3517 {expr2} must be a |string| or |Funcref|.
3518
3519 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3520 of the current item. For a |Dictionary| |v:key| has the key
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003521 of the current item and for a |List| or a |Tuple| |v:key| has
3522 the index of the current item. For a |Blob| |v:key| has the
3523 index of the current byte. For a |String| |v:key| has the
3524 index of the current character.
Ernie Raele79e2072024-01-13 11:47:33 +01003525 Examples: >
3526 call foreach(mylist, 'used[v:val] = true')
3527< This records the items that are in the {expr1} list.
3528
3529 Note that {expr2} is the result of expression and is then used
3530 as a command. Often it is good to use a |literal-string| to
3531 avoid having to double backslashes.
3532
3533 If {expr2} is a |Funcref| it must take two arguments:
3534 1. the key or the index of the current item.
3535 2. the value of the current item.
3536 With a legacy script lambda you don't get an error if it only
3537 accepts one argument, but with a Vim9 lambda you get "E1106:
3538 One argument too many", the number of arguments must match.
3539 If the function returns a value, it is ignored.
3540
3541 Returns {expr1} in all cases.
3542 When an error is encountered while executing {expr2} no
3543 further items in {expr1} are processed.
3544 When {expr2} is a Funcref errors inside a function are ignored,
3545 unless it was defined with the "abort" flag.
3546
3547 Can also be used as a |method|: >
3548 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003549<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003550 Return type: |String|, |Blob|, list<{type}>, tuple<{type}> or
3551 dict<{type}> depending on {expr1}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003553 *foreground()*
3554foreground() Move the Vim window to the foreground. Useful when sent from
3555 a client to a Vim server. |remote_send()|
3556 On Win32 systems this might not work, the OS does not always
3557 allow a window to bring itself to the foreground. Use
3558 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003559
3560 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003561 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003562 Win32 console version}
3563
Bram Moolenaaraa534142022-09-15 21:46:02 +01003564fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003565 Get the full command name from a short abbreviated command
3566 name; see |20.2| for details on command abbreviations.
3567
3568 The string argument {name} may start with a `:` and can
3569 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003570 Returns an empty string if a command doesn't exist, if it's
3571 ambiguous (for user-defined commands) or cannot be shortened
3572 this way. |vim9-no-shorten|
3573
3574 Without the {vim9} argument uses the current script version.
3575 If {vim9} is present and FALSE then legacy script rules are
3576 used. When {vim9} is present and TRUE then Vim9 rules are
3577 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003578
3579 For example `fullcommand('s')`, `fullcommand('sub')`,
3580 `fullcommand(':%substitute')` all return "substitute".
3581
3582 Can also be used as a |method|: >
3583 GetName()->fullcommand()
3584<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003585 Return type: |String|
3586
3587
3588funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003589 Just like |function()|, but the returned Funcref will lookup
3590 the function by reference, not by name. This matters when the
3591 function {name} is redefined later.
3592
3593 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003594 It only works for an autoloaded function if it has already
3595 been loaded (to avoid mistakenly loading the autoload script
3596 when only intending to use the function name, use |function()|
3597 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003598 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003599
3600 Can also be used as a |method|: >
3601 GetFuncname()->funcref([arg])
3602<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003603 Return type: func(...): any or |Number| on error
3604
Dominique Pellee764d1b2023-03-12 21:20:59 +00003605 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003606function({name} [, {arglist}] [, {dict}])
3607 Return a |Funcref| variable that refers to function {name}.
3608 {name} can be the name of a user defined function or an
3609 internal function.
3610
3611 {name} can also be a Funcref or a partial. When it is a
3612 partial the dict stored in it will be used and the {dict}
3613 argument is not allowed. E.g.: >
3614 let FuncWithArg = function(dict.Func, [arg])
3615 let Broken = function(dict.Func, [arg], dict)
3616<
3617 When using the Funcref the function will be found by {name},
3618 also when it was redefined later. Use |funcref()| to keep the
3619 same function.
3620
3621 When {arglist} or {dict} is present this creates a partial.
3622 That means the argument list and/or the dictionary is stored in
3623 the Funcref and will be used when the Funcref is called.
3624
3625 The arguments are passed to the function in front of other
3626 arguments, but after any argument from |method|. Example: >
3627 func Callback(arg1, arg2, name)
3628 ...
3629 let Partial = function('Callback', ['one', 'two'])
3630 ...
3631 call Partial('name')
3632< Invokes the function as with: >
3633 call Callback('one', 'two', 'name')
3634
3635< With a |method|: >
3636 func Callback(one, two, three)
3637 ...
3638 let Partial = function('Callback', ['two'])
3639 ...
3640 eval 'one'->Partial('three')
3641< Invokes the function as with: >
3642 call Callback('one', 'two', 'three')
3643
3644< The function() call can be nested to add more arguments to the
3645 Funcref. The extra arguments are appended to the list of
3646 arguments. Example: >
3647 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003648 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003649 let Func = function('Callback', ['one'])
3650 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003651 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003652 call Func2('name')
3653< Invokes the function as with: >
3654 call Callback('one', 'two', 'name')
3655
3656< The Dictionary is only useful when calling a "dict" function.
3657 In that case the {dict} is passed in as "self". Example: >
3658 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003659 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003660 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003661 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003662 let context = {"name": "example"}
3663 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003664 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003665 call Func() " will echo: called for example
3666< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003667 arguments, these two are equivalent, if Callback() is defined
3668 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003669 let Func = function('Callback', context)
3670 let Func = context.Callback
3671
3672< The argument list and the Dictionary can be combined: >
3673 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003674 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003675 let context = {"name": "example"}
3676 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003677 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003678 call Func(500)
3679< Invokes the function as with: >
3680 call context.Callback('one', 500)
3681<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003682 Returns 0 on error.
3683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003684 Can also be used as a |method|: >
3685 GetFuncname()->function([arg])
3686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003687<
3688 Return type: func(...): any or |Number| on error
3689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003690
3691garbagecollect([{atexit}]) *garbagecollect()*
3692 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3693 that have circular references.
3694
3695 There is hardly ever a need to invoke this function, as it is
3696 automatically done when Vim runs out of memory or is waiting
3697 for the user to press a key after 'updatetime'. Items without
3698 circular references are always freed when they become unused.
3699 This is useful if you have deleted a very big |List| and/or
3700 |Dictionary| with circular references in a script that runs
3701 for a long time.
3702
3703 When the optional {atexit} argument is one, garbage
3704 collection will also be done when exiting Vim, if it wasn't
3705 done before. This is useful when checking for memory leaks.
3706
3707 The garbage collection is not done immediately but only when
3708 it's safe to perform. This is when waiting for the user to
3709 type a character. To force garbage collection immediately use
3710 |test_garbagecollect_now()|.
3711
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003712 Return type: |String|
3713
3714
LemonBoy48b7d052024-07-09 18:24:59 +02003715get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003716 Get item {idx} from |List| {list}. When this item is not
3717 available return {default}. Return zero when {default} is
3718 omitted.
3719 Preferably used as a |method|: >
3720 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003721<
3722 Return type: any, depending on {list}
3723
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003724get({tuple}, {idx} [, {default}]) *get()-tuple*
3725 Get item {idx} from |Tuple| {tuple}. When this item is not
3726 available return {default}. Return zero when {default} is
3727 omitted.
3728 Preferably used as a |method|: >
3729 mytuple->get(idx)
3730<
3731 Return type: any, depending on {tuple}
3732
LemonBoy48b7d052024-07-09 18:24:59 +02003733get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003734 Get byte {idx} from |Blob| {blob}. When this byte is not
3735 available return {default}. Return -1 when {default} is
3736 omitted.
3737 Preferably used as a |method|: >
3738 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003739<
3740 Return type: |Number|
3741
LemonBoy48b7d052024-07-09 18:24:59 +02003742get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003743 Get item with key {key} from |Dictionary| {dict}. When this
3744 item is not available return {default}. Return zero when
3745 {default} is omitted. Useful example: >
3746 let val = get(g:, 'var_name', 'default')
3747< This gets the value of g:var_name if it exists, and uses
3748 'default' when it does not exist.
3749 Preferably used as a |method|: >
3750 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003751<
h-east84ac2122024-06-17 18:12:30 +02003752 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003753
LemonBoy48b7d052024-07-09 18:24:59 +02003754get({func}, {what}) *get()-func*
3755 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003756 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003757 "name" The function name
3758 "func" The function
3759 "dict" The dictionary
3760 "args" The list with arguments
3761 "arity" A dictionary with information about the number of
3762 arguments accepted by the function (minus the
3763 {arglist}) with the following fields:
3764 required the number of positional arguments
3765 optional the number of optional arguments,
3766 in addition to the required ones
3767 varargs |TRUE| if the function accepts a
3768 variable number of arguments |...|
3769
3770 Note: There is no error, if the {arglist} of
3771 the Funcref contains more arguments than the
3772 Funcref expects, it's not validated.
3773
Bram Moolenaar016188f2022-06-06 20:52:59 +01003774 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003776 Preferably used as a |method|: >
3777 myfunc->get(what)
3778<
LemonBoy48b7d052024-07-09 18:24:59 +02003779 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003781 *getbufinfo()*
3782getbufinfo([{buf}])
3783getbufinfo([{dict}])
3784 Get information about buffers as a List of Dictionaries.
3785
3786 Without an argument information about all the buffers is
3787 returned.
3788
3789 When the argument is a |Dictionary| only the buffers matching
3790 the specified criteria are returned. The following keys can
3791 be specified in {dict}:
3792 buflisted include only listed buffers.
3793 bufloaded include only loaded buffers.
3794 bufmodified include only modified buffers.
3795
3796 Otherwise, {buf} specifies a particular buffer to return
3797 information for. For the use of {buf}, see |bufname()|
3798 above. If the buffer is found the returned List has one item.
3799 Otherwise the result is an empty list.
3800
3801 Each returned List item is a dictionary with the following
3802 entries:
3803 bufnr Buffer number.
3804 changed TRUE if the buffer is modified.
3805 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003806 command TRUE if the buffer belongs to the
3807 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003808 hidden TRUE if the buffer is hidden.
3809 lastused Timestamp in seconds, like
3810 |localtime()|, when the buffer was
3811 last used.
3812 {only with the |+viminfo| feature}
3813 listed TRUE if the buffer is listed.
3814 lnum Line number used for the buffer when
3815 opened in the current window.
3816 Only valid if the buffer has been
3817 displayed in the window in the past.
3818 If you want the line number of the
3819 last known cursor position in a given
3820 window, use |line()|: >
3821 :echo line('.', {winid})
3822<
3823 linecount Number of lines in the buffer (only
3824 valid when loaded)
3825 loaded TRUE if the buffer is loaded.
3826 name Full path to the file in the buffer.
3827 signs List of signs placed in the buffer.
3828 Each list item is a dictionary with
3829 the following fields:
3830 id sign identifier
3831 lnum line number
3832 name sign name
3833 variables A reference to the dictionary with
3834 buffer-local variables.
3835 windows List of |window-ID|s that display this
3836 buffer
3837 popups List of popup |window-ID|s that
3838 display this buffer
3839
3840 Examples: >
3841 for buf in getbufinfo()
3842 echo buf.name
3843 endfor
3844 for buf in getbufinfo({'buflisted':1})
3845 if buf.changed
3846 ....
3847 endif
3848 endfor
3849<
3850 To get buffer-local options use: >
3851 getbufvar({bufnr}, '&option_name')
3852<
3853 Can also be used as a |method|: >
3854 GetBufnr()->getbufinfo()
3855<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003856 Return type: list<dict<any>>
3857
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003858
3859 *getbufline()*
3860getbufline({buf}, {lnum} [, {end}])
3861 Return a |List| with the lines starting from {lnum} to {end}
3862 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003863 |List| with only the line {lnum} is returned. See
3864 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003865
3866 For the use of {buf}, see |bufname()| above.
3867
3868 For {lnum} and {end} "$" can be used for the last line of the
3869 buffer. Otherwise a number must be used.
3870
3871 When {lnum} is smaller than 1 or bigger than the number of
3872 lines in the buffer, an empty |List| is returned.
3873
3874 When {end} is greater than the number of lines in the buffer,
3875 it is treated as {end} is set to the number of lines in the
3876 buffer. When {end} is before {lnum} an empty |List| is
3877 returned.
3878
3879 This function works only for loaded buffers. For unloaded and
3880 non-existing buffers, an empty |List| is returned.
3881
3882 Example: >
3883 :let lines = getbufline(bufnr("myfile"), 1, "$")
3884
3885< Can also be used as a |method|: >
3886 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003887<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003888 Return type: list<string>
3889
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003890 *getbufoneline()*
3891getbufoneline({buf}, {lnum})
3892 Just like `getbufline()` but only get one line and return it
3893 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003894
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003895 Return type: |String|
3896
3897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003898getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3899 The result is the value of option or local buffer variable
3900 {varname} in buffer {buf}. Note that the name without "b:"
3901 must be used.
3902 The {varname} argument is a string.
3903 When {varname} is empty returns a |Dictionary| with all the
3904 buffer-local variables.
3905 When {varname} is equal to "&" returns a |Dictionary| with all
3906 the buffer-local options.
3907 Otherwise, when {varname} starts with "&" returns the value of
3908 a buffer-local option.
3909 This also works for a global or buffer-local option, but it
3910 doesn't work for a global variable, window-local variable or
3911 window-local option.
3912 For the use of {buf}, see |bufname()| above.
3913 When the buffer or variable doesn't exist {def} or an empty
3914 string is returned, there is no error message.
3915 Examples: >
3916 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003917 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918
3919< Can also be used as a |method|: >
3920 GetBufnr()->getbufvar(varname)
3921<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003922 Return type: any, depending on {varname}
3923
3924
mikoto20001083cae2024-11-11 21:24:14 +01003925getcellpixels() *getcellpixels()*
3926 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003927 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003928
3929 Only works on Unix (terminal and gVim) and Windows (gVim only).
3930 Returns [] on other systems or on failure.
3931 Note that there could be variations across different terminals.
3932 On macOS, system Terminal.app returns sizes in points (before
3933 Retina scaling), whereas third-party terminals return raw pixel
3934 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003935
mikoto2000de094dc2024-11-14 22:13:48 +01003936 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003937
3938
Kota Kato66bb9ae2023-01-17 18:31:56 +00003939getcellwidths() *getcellwidths()*
3940 Returns a |List| of cell widths of character ranges overridden
3941 by |setcellwidths()|. The format is equal to the argument of
3942 |setcellwidths()|. If no character ranges have their cell
3943 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003944
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003945 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003946
3947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003948getchangelist([{buf}]) *getchangelist()*
3949 Returns the |changelist| for the buffer {buf}. For the use
3950 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3951 exist, an empty list is returned.
3952
3953 The returned list contains two entries: a list with the change
3954 locations and the current position in the list. Each
3955 entry in the change list is a dictionary with the following
3956 entries:
3957 col column number
3958 coladd column offset for 'virtualedit'
3959 lnum line number
3960 If buffer {buf} is the current buffer, then the current
3961 position refers to the position in the list. For other
3962 buffers, it is set to the length of the list.
3963
3964 Can also be used as a |method|: >
3965 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003966<
3967 Return type: list<any>
3968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969
zeertzjqe0a2ab32025-02-02 09:14:35 +01003970getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003971 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003972 If {expr} is omitted or is -1, wait until a character is
3973 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003974 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003975 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003976 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003977 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003978 If you prefer always getting a string use |getcharstr()|, or
3979 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003980
Doug Kearns9cd9e752024-04-07 17:42:17 +02003981 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003982 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003983 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003984 Otherwise a String is returned with the encoded character.
3985 For a special key it's a String with a sequence of bytes
3986 starting with 0x80 (decimal: 128). This is the same value as
3987 the String "\<Key>", e.g., "\<Left>". The returned value is
3988 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01003989 that is not included in the character. |keytrans()| can also
3990 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003991
Doug Kearns9cd9e752024-04-07 17:42:17 +02003992 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003993 while Vim waits to see if this is the start of an escape
3994 sequence.
3995
Doug Kearns9cd9e752024-04-07 17:42:17 +02003996 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003997 one-byte character it is the character itself as a number.
3998 Use nr2char() to convert it to a String.
3999
4000 Use getcharmod() to obtain any additional modifiers.
4001
zeertzjqe0a2ab32025-02-02 09:14:35 +01004002 The optional argument {opts} is a Dict and supports the
4003 following items:
4004
zeertzjqedf0f7d2025-02-02 19:01:01 +01004005 cursor A String specifying cursor behavior
4006 when waiting for a character.
4007 "hide": hide the cursor.
4008 "keep": keep current cursor unchanged.
4009 "msg": move cursor to message area.
4010 (default: "msg")
4011
zeertzjqe0a2ab32025-02-02 09:14:35 +01004012 number If |TRUE|, return a Number when getting
4013 a single character.
4014 If |FALSE|, the return value is always
4015 converted to a String, and an empty
4016 String (instead of 0) is returned when
4017 no character is available.
4018 (default: |TRUE|)
4019
4020 simplify If |TRUE|, include modifiers in the
4021 character if possible. E.g., return
4022 the same value for CTRL-I and <Tab>.
4023 If |FALSE|, don't include modifiers in
4024 the character.
4025 (default: |TRUE|)
4026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004027 When the user clicks a mouse button, the mouse event will be
4028 returned. The position can then be found in |v:mouse_col|,
4029 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
4030 |getmousepos()| can also be used. Mouse move events will be
4031 ignored.
4032 This example positions the mouse as it would normally happen: >
4033 let c = getchar()
4034 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004035 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004036 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004037 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038 endif
4039<
4040 When using bracketed paste only the first character is
4041 returned, the rest of the pasted text is dropped.
4042 |xterm-bracketed-paste|.
4043
4044 There is no prompt, you will somehow have to make clear to the
4045 user that a character has to be typed. The screen is not
4046 redrawn, e.g. when resizing the window. When using a popup
4047 window it should work better with a |popup-filter|.
4048
4049 There is no mapping for the character.
4050 Key codes are replaced, thus when the user presses the <Del>
4051 key you get the code for the <Del> key, not the raw character
4052 sequence. Examples: >
4053 getchar() == "\<Del>"
4054 getchar() == "\<S-Left>"
4055< This example redefines "f" to ignore case: >
4056 :nmap f :call FindChar()<CR>
4057 :function FindChar()
4058 : let c = nr2char(getchar())
4059 : while col('.') < col('$') - 1
4060 : normal l
4061 : if getline('.')[col('.') - 1] ==? c
4062 : break
4063 : endif
4064 : endwhile
4065 :endfunction
4066<
4067 You may also receive synthetic characters, such as
4068 |<CursorHold>|. Often you will want to ignore this and get
4069 another character: >
4070 :function GetKey()
4071 : let c = getchar()
4072 : while c == "\<CursorHold>"
4073 : let c = getchar()
4074 : endwhile
4075 : return c
4076 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004077<
4078 Return type: |Number| or |String|
4079
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004080
4081getcharmod() *getcharmod()*
4082 The result is a Number which is the state of the modifiers for
4083 the last obtained character with getchar() or in another way.
4084 These values are added together:
4085 2 shift
4086 4 control
4087 8 alt (meta)
4088 16 meta (when it's different from ALT)
4089 32 mouse double click
4090 64 mouse triple click
4091 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004092 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004093 Only the modifiers that have not been included in the
4094 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004095 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004096
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004097 Return type: |Number|
4098
4099
4100getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004101 Get the position for String {expr}. Same as |getpos()| but the
4102 column number in the returned List is a character index
4103 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004104 If |getpos()| returns a very large column number, equal to
4105 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004106 of the last character.
4107
4108 Example:
4109 With the cursor on '세' in line 5 with text "여보세요": >
4110 getcharpos('.') returns [0, 5, 3, 0]
4111 getpos('.') returns [0, 5, 7, 0]
4112<
4113 Can also be used as a |method|: >
4114 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004115<
4116 Return type: list<number>
4117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004118
4119getcharsearch() *getcharsearch()*
4120 Return the current character search information as a {dict}
4121 with the following entries:
4122
4123 char character previously used for a character
4124 search (|t|, |f|, |T|, or |F|); empty string
4125 if no character search has been performed
4126 forward direction of character search; 1 for forward,
4127 0 for backward
4128 until type of character search; 1 for a |t| or |T|
4129 character search, 0 for an |f| or |F|
4130 character search
4131
4132 This can be useful to always have |;| and |,| search
4133 forward/backward regardless of the direction of the previous
4134 character search: >
4135 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4136 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4137< Also see |setcharsearch()|.
4138
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004139 Return type: dict<any>
4140
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004141
zeertzjqe0a2ab32025-02-02 09:14:35 +01004142getcharstr([{expr} [, {opts}]]) *getcharstr()*
4143 The same as |getchar()|, except that this always returns a
4144 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004145
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004146 Return type: |String|
4147
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004148getcmdcomplpat() *getcmdcomplpat()*
4149 Return completion pattern of the current command-line.
4150 Only works when the command line is being edited, thus
4151 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4152 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4153 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4154 Returns an empty string when completion is not defined.
4155
4156 Return type: |String|
4157
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004158
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004159getcmdcompltype() *getcmdcompltype()*
4160 Return the type of the current command-line completion.
4161 Only works when the command line is being edited, thus
4162 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004163 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004164 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004165 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004166 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004167
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004168 Return type: |String|
4169
4170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004171getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004172 Return the current command-line input. Only works when the
4173 command line is being edited, thus requires use of
4174 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004175 Example: >
4176 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004177< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4178 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004179 Returns an empty string when entering a password or using
4180 |inputsecret()|.
4181
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004182 Return type: |String|
4183
4184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004185getcmdpos() *getcmdpos()*
4186 Return the position of the cursor in the command line as a
4187 byte count. The first column is 1.
4188 Only works when editing the command line, thus requires use of
4189 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4190 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004191 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4192 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004193
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004194 Return type: |Number|
4195
4196
Shougo Matsushita69084282024-09-23 20:34:47 +02004197getcmdprompt() *getcmdprompt()*
4198 Return the current command-line prompt when using functions
4199 like |input()| or |confirm()|.
4200 Only works when the command line is being edited, thus
4201 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4202 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4203 |setcmdpos()| and |setcmdline()|.
4204
4205 Return type: |String|
4206
4207
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004208getcmdscreenpos() *getcmdscreenpos()*
4209 Return the screen position of the cursor in the command line
4210 as a byte count. The first column is 1.
4211 Instead of |getcmdpos()|, it adds the prompt position.
4212 Only works when editing the command line, thus requires use of
4213 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4214 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004215 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4216 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004218 Return type: |Number|
4219
4220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004221getcmdtype() *getcmdtype()*
4222 Return the current command-line type. Possible return values
4223 are:
4224 : normal Ex command
4225 > debug mode command |debug-mode|
4226 / forward search command
4227 ? backward search command
4228 @ |input()| command
4229 - |:insert| or |:append| command
4230 = |i_CTRL-R_=|
4231 Only works when editing the command line, thus requires use of
4232 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4233 Returns an empty string otherwise.
4234 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4235
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004236 Return type: |String|
4237
4238
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004239getcmdwintype() *getcmdwintype()*
4240 Return the current |command-line-window| type. Possible return
4241 values are the same as |getcmdtype()|. Returns an empty string
4242 when not in the command-line window.
4243
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004244 Return type: |String|
4245
4246
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004247getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4248 Return a list of command-line completion matches. The String
4249 {type} argument specifies what for. The following completion
4250 types are supported:
4251
4252 arglist file names in argument list
4253 augroup autocmd groups
4254 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004255 behave |:behave| suboptions
4256 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004257 color color schemes
4258 command Ex command
4259 cmdline |cmdline-completion| result
4260 compiler compilers
4261 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004262 custom,{func} custom completion, defined via {func}
4263 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004264 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004265 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004266 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004267 environment environment variable names
4268 event autocommand events
4269 expression Vim expression
4270 file file and directory names
4271 file_in_path file and directory names in |'path'|
4272 filetype filetype names |'filetype'|
4273 function function name
4274 help help subjects
4275 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004276 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004277 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004278 locale locale names (as output of locale -a)
4279 mapclear buffer argument
4280 mapping mapping name
4281 menu menus
4282 messages |:messages| suboptions
4283 option options
4284 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004285 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004286 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004287 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004288 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004289 sign |:sign| suboptions
4290 syntax syntax file names |'syntax'|
4291 syntime |:syntime| suboptions
4292 tag tags
4293 tag_listfiles tags, file names
4294 user user names
4295 var user variables
4296
4297 If {pat} is an empty string, then all the matches are
4298 returned. Otherwise only items matching {pat} are returned.
4299 See |wildcards| for the use of special characters in {pat}.
4300
4301 If the optional {filtered} flag is set to 1, then 'wildignore'
4302 is applied to filter the results. Otherwise all the matches
4303 are returned. The 'wildignorecase' option always applies.
4304
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004305 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4306 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004307 regular expression matching is used. Thus this function
4308 follows the user preference, what happens on the command line.
4309 If you do not want this you can make 'wildoptions' empty
4310 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004312 If {type} is "cmdline", then the |cmdline-completion| result is
4313 returned. For example, to complete the possible values after
4314 a ":call" command: >
4315 echo getcompletion('call ', 'cmdline')
4316<
4317 If there are no matches, an empty list is returned. An
4318 invalid value for {type} produces an error.
4319
4320 Can also be used as a |method|: >
4321 GetPattern()->getcompletion('color')
4322<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004323 Return type: list<string>
4324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004325 *getcurpos()*
4326getcurpos([{winid}])
4327 Get the position of the cursor. This is like getpos('.'), but
4328 includes an extra "curswant" item in the list:
4329 [0, lnum, col, off, curswant] ~
4330 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004331 cursor vertically. After |$| command it will be a very large
4332 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004333 |getpos()|.
4334 The first "bufnum" item is always zero. The byte position of
4335 the cursor is returned in 'col'. To get the character
4336 position, use |getcursorcharpos()|.
4337
4338 The optional {winid} argument can specify the window. It can
4339 be the window number or the |window-ID|. The last known
4340 cursor position is returned, this may be invalid for the
4341 current value of the buffer if it is not the current window.
4342 If {winid} is invalid a list with zeroes is returned.
4343
4344 This can be used to save and restore the cursor position: >
4345 let save_cursor = getcurpos()
4346 MoveTheCursorAround
4347 call setpos('.', save_cursor)
4348< Note that this only works within the window. See
4349 |winrestview()| for restoring more state.
4350
4351 Can also be used as a |method|: >
4352 GetWinid()->getcurpos()
4353<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004354 Return type: list<number>
4355
4356
4357getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004358 Same as |getcurpos()| but the column number in the returned
4359 List is a character index instead of a byte index.
4360
4361 Example:
4362 With the cursor on '보' in line 3 with text "여보세요": >
4363 getcursorcharpos() returns [0, 3, 2, 0, 3]
4364 getcurpos() returns [0, 3, 4, 0, 3]
4365<
4366 Can also be used as a |method|: >
4367 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004368<
4369 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004370
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004371
4372getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004373 The result is a String, which is the name of the current
4374 working directory. 'autochdir' is ignored.
4375
4376 With {winnr} return the local current directory of this window
4377 in the current tab page. {winnr} can be the window number or
4378 the |window-ID|.
4379 If {winnr} is -1 return the name of the global working
4380 directory. See also |haslocaldir()|.
4381
4382 With {winnr} and {tabnr} return the local current directory of
4383 the window in the specified tab page. If {winnr} is -1 return
4384 the working directory of the tabpage.
4385 If {winnr} is zero use the current window, if {tabnr} is zero
4386 use the current tabpage.
4387 Without any arguments, return the actual working directory of
4388 the current window.
4389 Return an empty string if the arguments are invalid.
4390
4391 Examples: >
4392 " Get the working directory of the current window
4393 :echo getcwd()
4394 :echo getcwd(0)
4395 :echo getcwd(0, 0)
4396 " Get the working directory of window 3 in tabpage 2
4397 :echo getcwd(3, 2)
4398 " Get the global working directory
4399 :echo getcwd(-1)
4400 " Get the working directory of tabpage 3
4401 :echo getcwd(-1, 3)
4402 " Get the working directory of current tabpage
4403 :echo getcwd(-1, 0)
4404
4405< Can also be used as a |method|: >
4406 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004407<
4408 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004409
4410getenv({name}) *getenv()*
4411 Return the value of environment variable {name}. The {name}
4412 argument is a string, without a leading '$'. Example: >
4413 myHome = getenv('HOME')
4414
4415< When the variable does not exist |v:null| is returned. That
4416 is different from a variable set to an empty string, although
4417 some systems interpret the empty value as the variable being
4418 deleted. See also |expr-env|.
4419
4420 Can also be used as a |method|: >
4421 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004422<
4423 Return type: |String| or |Number|
4424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004425
4426getfontname([{name}]) *getfontname()*
4427 Without an argument returns the name of the normal font being
4428 used. Like what is used for the Normal highlight group
4429 |hl-Normal|.
4430 With an argument a check is done whether String {name} is a
4431 valid font name. If not then an empty string is returned.
4432 Otherwise the actual font name is returned, or {name} if the
4433 GUI does not support obtaining the real name.
4434 Only works when the GUI is running, thus not in your vimrc or
4435 gvimrc file. Use the |GUIEnter| autocommand to use this
4436 function just after the GUI has started.
4437 Note that the GTK GUI accepts any font name, thus checking for
4438 a valid name does not work.
4439
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004440 Return type: |String|
4441
4442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004443getfperm({fname}) *getfperm()*
4444 The result is a String, which is the read, write, and execute
4445 permissions of the given file {fname}.
4446 If {fname} does not exist or its directory cannot be read, an
4447 empty string is returned.
4448 The result is of the form "rwxrwxrwx", where each group of
4449 "rwx" flags represent, in turn, the permissions of the owner
4450 of the file, the group the file belongs to, and other users.
4451 If a user does not have a given permission the flag for this
4452 is replaced with the string "-". Examples: >
4453 :echo getfperm("/etc/passwd")
4454 :echo getfperm(expand("~/.vimrc"))
4455< This will hopefully (from a security point of view) display
4456 the string "rw-r--r--" or even "rw-------".
4457
4458 Can also be used as a |method|: >
4459 GetFilename()->getfperm()
4460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004461 Return type: |String|
4462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004463 For setting permissions use |setfperm()|.
4464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004466getfsize({fname}) *getfsize()*
4467 The result is a Number, which is the size in bytes of the
4468 given file {fname}.
4469 If {fname} is a directory, 0 is returned.
4470 If the file {fname} can't be found, -1 is returned.
4471 If the size of {fname} is too big to fit in a Number then -2
4472 is returned.
4473
4474 Can also be used as a |method|: >
4475 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004476<
4477 Return type: |Number|
4478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004479
4480getftime({fname}) *getftime()*
4481 The result is a Number, which is the last modification time of
4482 the given file {fname}. The value is measured as seconds
4483 since 1st Jan 1970, and may be passed to strftime(). See also
4484 |localtime()| and |strftime()|.
4485 If the file {fname} can't be found -1 is returned.
4486
4487 Can also be used as a |method|: >
4488 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004489<
4490 Return type: |Number|
4491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004492
4493getftype({fname}) *getftype()*
4494 The result is a String, which is a description of the kind of
4495 file of the given file {fname}.
4496 If {fname} does not exist an empty string is returned.
4497 Here is a table over different kinds of files and their
4498 results:
4499 Normal file "file"
4500 Directory "dir"
4501 Symbolic link "link"
4502 Block device "bdev"
4503 Character device "cdev"
4504 Socket "socket"
4505 FIFO "fifo"
4506 All other "other"
4507 Example: >
4508 getftype("/home")
4509< Note that a type such as "link" will only be returned on
4510 systems that support it. On some systems only "dir" and
4511 "file" are returned. On MS-Windows a symbolic link to a
4512 directory returns "dir" instead of "link".
4513
4514 Can also be used as a |method|: >
4515 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004516<
4517 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004518
4519getimstatus() *getimstatus()*
4520 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004521 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004522 See 'imstatusfunc'.
4523
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004524 Return type: |Number|
4525
4526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004527getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4528 Returns the |jumplist| for the specified window.
4529
4530 Without arguments use the current window.
4531 With {winnr} only use this window in the current tab page.
4532 {winnr} can also be a |window-ID|.
4533 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004534 page. If {winnr} or {tabnr} is invalid, an empty list is
4535 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004536
4537 The returned list contains two entries: a list with the jump
4538 locations and the last used jump position number in the list.
4539 Each entry in the jump location list is a dictionary with
4540 the following entries:
4541 bufnr buffer number
4542 col column number
4543 coladd column offset for 'virtualedit'
4544 filename filename if available
4545 lnum line number
4546
4547 Can also be used as a |method|: >
4548 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004549<
4550 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004551
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004552 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004553getline({lnum} [, {end}])
4554 Without {end} the result is a String, which is line {lnum}
4555 from the current buffer. Example: >
4556 getline(1)
4557< When {lnum} is a String that doesn't start with a
4558 digit, |line()| is called to translate the String into a Number.
4559 To get the line under the cursor: >
4560 getline(".")
4561< When {lnum} is a number smaller than 1 or bigger than the
4562 number of lines in the buffer, an empty string is returned.
4563
4564 When {end} is given the result is a |List| where each item is
4565 a line from the current buffer in the range {lnum} to {end},
4566 including line {end}.
4567 {end} is used in the same way as {lnum}.
4568 Non-existing lines are silently omitted.
4569 When {end} is before {lnum} an empty |List| is returned.
4570 Example: >
4571 :let start = line('.')
4572 :let end = search("^$") - 1
4573 :let lines = getline(start, end)
4574
4575< Can also be used as a |method|: >
4576 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004577<
4578 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004579
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004580 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004581 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004582
4583getloclist({nr} [, {what}]) *getloclist()*
4584 Returns a |List| with all the entries in the location list for
4585 window {nr}. {nr} can be the window number or the |window-ID|.
4586 When {nr} is zero the current window is used.
4587
4588 For a location list window, the displayed location list is
4589 returned. For an invalid window number {nr}, an empty list is
4590 returned. Otherwise, same as |getqflist()|.
4591
4592 If the optional {what} dictionary argument is supplied, then
4593 returns the items listed in {what} as a dictionary. Refer to
4594 |getqflist()| for the supported items in {what}.
4595
4596 In addition to the items supported by |getqflist()| in {what},
4597 the following item is supported by |getloclist()|:
4598
4599 filewinid id of the window used to display files
4600 from the location list. This field is
4601 applicable only when called from a
4602 location list window. See
4603 |location-list-file-window| for more
4604 details.
4605
4606 Returns a |Dictionary| with default values if there is no
4607 location list for the window {nr}.
4608 Returns an empty Dictionary if window {nr} does not exist.
4609
4610 Examples (See also |getqflist-examples|): >
4611 :echo getloclist(3, {'all': 0})
4612 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004613<
4614 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004615
4616
4617getmarklist([{buf}]) *getmarklist()*
4618 Without the {buf} argument returns a |List| with information
4619 about all the global marks. |mark|
4620
4621 If the optional {buf} argument is specified, returns the
4622 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004623 see |bufname()|. If {buf} is invalid, an empty list is
4624 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004625
4626 Each item in the returned List is a |Dict| with the following:
4627 mark name of the mark prefixed by "'"
4628 pos a |List| with the position of the mark:
4629 [bufnum, lnum, col, off]
4630 Refer to |getpos()| for more information.
4631 file file name
4632
4633 Refer to |getpos()| for getting information about a specific
4634 mark.
4635
4636 Can also be used as a |method|: >
4637 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004638<
4639 Return type: list<dict<any>> or list<any>
4640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004641
4642getmatches([{win}]) *getmatches()*
4643 Returns a |List| with all matches previously defined for the
4644 current window by |matchadd()| and the |:match| commands.
4645 |getmatches()| is useful in combination with |setmatches()|,
4646 as |setmatches()| can restore a list of matches saved by
4647 |getmatches()|.
4648 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004649 window ID instead of the current window. If {win} is invalid,
4650 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004651 Example: >
4652 :echo getmatches()
4653< [{'group': 'MyGroup1', 'pattern': 'TODO',
4654 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4655 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4656 :let m = getmatches()
4657 :call clearmatches()
4658 :echo getmatches()
4659< [] >
4660 :call setmatches(m)
4661 :echo getmatches()
4662< [{'group': 'MyGroup1', 'pattern': 'TODO',
4663 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4664 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4665 :unlet m
4666<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004667 Return type: list<dict<any>> or list<any>
4668
4669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004670getmousepos() *getmousepos()*
4671 Returns a |Dictionary| with the last known position of the
4672 mouse. This can be used in a mapping for a mouse click or in
4673 a filter of a popup window. The items are:
4674 screenrow screen row
4675 screencol screen column
4676 winid Window ID of the click
4677 winrow row inside "winid"
4678 wincol column inside "winid"
4679 line text line inside "winid"
4680 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004681 coladd offset (in screen columns) from the
4682 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004683 All numbers are 1-based.
4684
4685 If not over a window, e.g. when in the command line, then only
4686 "screenrow" and "screencol" are valid, the others are zero.
4687
4688 When on the status line below a window or the vertical
4689 separator right of a window, the "line" and "column" values
4690 are zero.
4691
4692 When the position is after the text then "column" is the
4693 length of the text in bytes plus one.
4694
4695 If the mouse is over a popup window then that window is used.
4696
4697 When using |getchar()| the Vim variables |v:mouse_lnum|,
4698 |v:mouse_col| and |v:mouse_winid| also provide these values.
4699
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004700 Return type: dict<number>
4701
4702
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004703getmouseshape() *getmouseshape()*
4704 Returns the name of the currently showing mouse pointer.
4705 When the |+mouseshape| feature is not supported or the shape
4706 is unknown an empty string is returned.
4707 This function is mainly intended for testing.
4708
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004709 Return type: |String|
4710
4711
4712getpid() *getpid()*
4713 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004714 On Unix and MS-Windows this is a unique number, until Vim
4715 exits.
4716
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004717 Return type: |Number|
4718
4719
4720getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004721 Get the position for String {expr}.
4722 The accepted values for {expr} are: *E1209*
4723 . The cursor position.
4724 $ The last line in the current buffer.
4725 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004726 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004727 w0 First line visible in current window (one if the
4728 display isn't updated, e.g. in silent Ex mode).
4729 w$ Last line visible in current window (this is one
4730 less than "w0" if no lines are visible).
4731 v When not in Visual mode, returns the cursor
4732 position. In Visual mode, returns the other end
4733 of the Visual area. A good way to think about
4734 this is that in Visual mode "v" and "." complement
4735 each other. While "." refers to the cursor
4736 position, "v" refers to where |v_o| would move the
4737 cursor. As a result, you can use "v" and "."
4738 together to work on all of a selection in
4739 characterwise Visual mode. If the cursor is at
4740 the end of a characterwise Visual area, "v" refers
4741 to the start of the same Visual area. And if the
4742 cursor is at the start of a characterwise Visual
4743 area, "v" refers to the end of the same Visual
4744 area. "v" differs from |'<| and |'>| in that it's
4745 updated right away.
4746 Note that a mark in another file can be used. The line number
4747 then applies to another buffer.
4748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004749 The result is a |List| with four numbers:
4750 [bufnum, lnum, col, off]
4751 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4752 is the buffer number of the mark.
4753 "lnum" and "col" are the position in the buffer. The first
4754 column is 1.
4755 The "off" number is zero, unless 'virtualedit' is used. Then
4756 it is the offset in screen columns from the start of the
4757 character. E.g., a position within a <Tab> or after the last
4758 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004759
4760 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004761 The column number in the returned List is the byte position
4762 within the line. To get the character position in the line,
4763 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004764
4765 Note that for '< and '> Visual mode matters: when it is "V"
4766 (visual line mode) the column of '< is zero and the column of
4767 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004768 A very large column number equal to |v:maxcol| can be returned,
4769 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004770 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004772 This can be used to save and restore the position of a mark: >
4773 let save_a_mark = getpos("'a")
4774 ...
4775 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004776<
4777 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004778
4779 Can also be used as a |method|: >
4780 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004781<
4782 Return type: list<number>
4783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004784
4785getqflist([{what}]) *getqflist()*
4786 Returns a |List| with all the current quickfix errors. Each
4787 list item is a dictionary with these entries:
4788 bufnr number of buffer that has the file name, use
4789 bufname() to get the name
4790 module module name
4791 lnum line number in the buffer (first line is 1)
4792 end_lnum
4793 end of line number if the item is multiline
4794 col column number (first column is 1)
4795 end_col end of column number if the item has range
4796 vcol |TRUE|: "col" is visual column
4797 |FALSE|: "col" is byte index
4798 nr error number
h-east84ac2122024-06-17 18:12:30 +02004799 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004800 text description of the error
4801 type type of the error, 'E', '1', etc.
4802 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004803 user_data
4804 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004805 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004806
4807 When there is no error list or it's empty, an empty list is
4808 returned. Quickfix list entries with a non-existing buffer
4809 number are returned with "bufnr" set to zero (Note: some
4810 functions accept buffer number zero for the alternate buffer,
4811 you may need to explicitly check for zero).
4812
4813 Useful application: Find pattern matches in multiple files and
4814 do something with them: >
4815 :vimgrep /theword/jg *.c
4816 :for d in getqflist()
4817 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4818 :endfor
4819<
4820 If the optional {what} dictionary argument is supplied, then
4821 returns only the items listed in {what} as a dictionary. The
4822 following string items are supported in {what}:
4823 changedtick get the total number of changes made
4824 to the list |quickfix-changedtick|
4825 context get the |quickfix-context|
4826 efm errorformat to use when parsing "lines". If
4827 not present, then the 'errorformat' option
4828 value is used.
4829 id get information for the quickfix list with
4830 |quickfix-ID|; zero means the id for the
4831 current list or the list specified by "nr"
4832 idx get information for the quickfix entry at this
4833 index in the list specified by 'id' or 'nr'.
4834 If set to zero, then uses the current entry.
4835 See |quickfix-index|
4836 items quickfix list entries
4837 lines parse a list of lines using 'efm' and return
4838 the resulting entries. Only a |List| type is
4839 accepted. The current quickfix list is not
4840 modified. See |quickfix-parse|.
4841 nr get information for this quickfix list; zero
4842 means the current quickfix list and "$" means
4843 the last quickfix list
4844 qfbufnr number of the buffer displayed in the quickfix
4845 window. Returns 0 if the quickfix buffer is
4846 not present. See |quickfix-buffer|.
4847 size number of entries in the quickfix list
4848 title get the list title |quickfix-title|
4849 winid get the quickfix |window-ID|
4850 all all of the above quickfix properties
4851 Non-string items in {what} are ignored. To get the value of a
4852 particular item, set it to zero.
4853 If "nr" is not present then the current quickfix list is used.
4854 If both "nr" and a non-zero "id" are specified, then the list
4855 specified by "id" is used.
4856 To get the number of lists in the quickfix stack, set "nr" to
4857 "$" in {what}. The "nr" value in the returned dictionary
4858 contains the quickfix stack size.
4859 When "lines" is specified, all the other items except "efm"
4860 are ignored. The returned dictionary contains the entry
4861 "items" with the list of entries.
4862
4863 The returned dictionary contains the following entries:
4864 changedtick total number of changes made to the
4865 list |quickfix-changedtick|
4866 context quickfix list context. See |quickfix-context|
4867 If not present, set to "".
4868 id quickfix list ID |quickfix-ID|. If not
4869 present, set to 0.
4870 idx index of the quickfix entry in the list. If not
4871 present, set to 0.
4872 items quickfix list entries. If not present, set to
4873 an empty list.
4874 nr quickfix list number. If not present, set to 0
4875 qfbufnr number of the buffer displayed in the quickfix
4876 window. If not present, set to 0.
4877 size number of entries in the quickfix list. If not
4878 present, set to 0.
4879 title quickfix list title text. If not present, set
4880 to "".
4881 winid quickfix |window-ID|. If not present, set to 0
4882
4883 Examples (See also |getqflist-examples|): >
4884 :echo getqflist({'all': 1})
4885 :echo getqflist({'nr': 2, 'title': 1})
4886 :echo getqflist({'lines' : ["F1:10:L10"]})
4887<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004888 Return type: list<dict<any>> or list<any>
4889
4890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004891getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4892 The result is a String, which is the contents of register
4893 {regname}. Example: >
4894 :let cliptext = getreg('*')
4895< When register {regname} was not set the result is an empty
4896 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004897 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004898
4899 getreg('=') returns the last evaluated value of the expression
4900 register. (For use in maps.)
4901 getreg('=', 1) returns the expression itself, so that it can
4902 be restored with |setreg()|. For other registers the extra
4903 argument is ignored, thus you can always give it.
4904
4905 If {list} is present and |TRUE|, the result type is changed
4906 to |List|. Each list item is one text line. Use it if you care
4907 about zero bytes possibly present inside register: without
4908 third argument both NLs and zero bytes are represented as NLs
4909 (see |NL-used-for-Nul|).
4910 When the register was not set an empty list is returned.
4911
4912 If {regname} is "", the unnamed register '"' is used.
4913 If {regname} is not specified, |v:register| is used.
4914 In |Vim9-script| {regname} must be one character.
4915
4916 Can also be used as a |method|: >
4917 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004918<
4919 Return type: |String|
4920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004921
4922getreginfo([{regname}]) *getreginfo()*
4923 Returns detailed information about register {regname} as a
4924 Dictionary with the following entries:
4925 regcontents List of lines contained in register
4926 {regname}, like
4927 |getreg|({regname}, 1, 1).
4928 regtype the type of register {regname}, as in
4929 |getregtype()|.
4930 isunnamed Boolean flag, v:true if this register
4931 is currently pointed to by the unnamed
4932 register.
4933 points_to for the unnamed register, gives the
4934 single letter name of the register
4935 currently pointed to (see |quotequote|).
4936 For example, after deleting a line
4937 with `dd`, this field will be "1",
4938 which is the register that got the
4939 deleted text.
4940
4941 The {regname} argument is a string. If {regname} is invalid
4942 or not set, an empty Dictionary will be returned.
4943 If {regname} is "" or "@", the unnamed register '"' is used.
4944 If {regname} is not specified, |v:register| is used.
4945 The returned Dictionary can be passed to |setreg()|.
4946 In |Vim9-script| {regname} must be one character.
4947
4948 Can also be used as a |method|: >
4949 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004950<
4951 Return type: dict<any>
4952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004953
Shougo Matsushita19b71882024-02-28 22:48:12 +01004954getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004955 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004956 buffer.
4957
4958 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004959 See |getpos()| for the format of the list. It's possible
4960 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004961 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004962
4963 The optional argument {opts} is a Dict and supports the
4964 following items:
4965
zeertzjqafc22952024-05-24 19:07:12 +02004966 type Specify the region's selection type.
4967 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004968 except that the width can be omitted
4969 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004970 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004971
zeertzjq87410ab2024-03-02 06:00:23 +08004972 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004973 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004974 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004975
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004976 You can get the last selection type by |visualmode()|.
4977 If Visual mode is active, use |mode()| to get the Visual mode
4978 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004979 This function is useful to get text starting and ending in
4980 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004981
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004982 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004983 Note that:
4984 - Order of {pos1} and {pos2} doesn't matter, it will always
4985 return content from the upper left position to the lower
4986 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004987 - If 'virtualedit' is enabled and the region is past the end
4988 of the lines, resulting lines are padded with spaces.
4989 - If the region is blockwise and it starts or ends in the
4990 middle of a multi-cell character, it is not included but
4991 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004992 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004993 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004994 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004995 - It is evaluated in current window context, which makes a
4996 difference if the buffer is displayed in a window with
4997 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004998
4999 Examples: >
5000 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01005001 \ <Cmd>echow getregion(
5002 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005003<
5004 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01005005 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02005006<
5007 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005008
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005009
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005010getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
5011 Same as |getregion()|, but returns a list of positions
5012 describing the buffer text segments bound by {pos1} and
5013 {pos2}.
5014 The segments are a pair of positions for every line: >
5015 [[{start_pos}, {end_pos}], ...]
5016<
5017 The position is a |List| with four numbers:
5018 [bufnum, lnum, col, off]
5019 "bufnum" is the buffer number.
5020 "lnum" and "col" are the position in the buffer. The first
5021 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02005022 If the "off" number of a starting position is non-zero, it is
5023 the offset in screen columns from the start of the character.
5024 E.g., a position within a <Tab> or after the last character.
5025 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02005026 the offset of the character's first cell not included in the
5027 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005028
zeertzjq2b09de92024-05-24 07:48:51 +02005029 Apart from the options supported by |getregion()|, {opts} also
5030 supports the following:
5031
5032 eol If |TRUE|, indicate positions beyond
5033 the end of a line with "col" values
5034 one more than the length of the line.
5035 If |FALSE|, positions are limited
5036 within their lines, and if a line is
5037 empty or the selection is entirely
5038 beyond the end of a line, a "col"
5039 value of 0 is used for both positions.
5040 (default: |FALSE|)
5041
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005042 Can also be used as a |method|: >
5043 getpos('.')->getregionpos(getpos("'a"))
5044<
Christian Brabandt83d74402025-03-19 21:55:59 +01005045 For an example, see the highlight-yank plugin |52.6|
5046
zeertzjqd4d12072024-07-16 20:34:16 +02005047 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005048
5049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005050getregtype([{regname}]) *getregtype()*
5051 The result is a String, which is type of register {regname}.
5052 The value will be one of:
5053 "v" for |characterwise| text
5054 "V" for |linewise| text
5055 "<CTRL-V>{width}" for |blockwise-visual| text
5056 "" for an empty or unknown register
5057 <CTRL-V> is one character with value 0x16.
5058 The {regname} argument is a string. If {regname} is "", the
5059 unnamed register '"' is used. If {regname} is not specified,
5060 |v:register| is used.
5061 In |Vim9-script| {regname} must be one character.
5062
5063 Can also be used as a |method|: >
5064 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005065<
5066 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005067
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005068
Bram Moolenaar71badf92023-04-22 22:40:14 +01005069getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005070 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005071 scripts in the order they were sourced, like what
5072 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005073
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005074 The optional Dict argument {opts} supports the following
5075 optional items:
5076 name Script name match pattern. If specified,
5077 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005078 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005079 "name" are returned.
5080 sid Script ID |<SID>|. If specified, only
5081 information about the script with ID "sid" is
5082 returned and "name" is ignored.
5083
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005084 Each item in the returned List is a |Dict| with the following
5085 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005086 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005087 `import autoload` but was not actually sourced
5088 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005089 functions List of script-local function names defined in
5090 the script. Present only when a particular
5091 script is specified using the "sid" item in
5092 {opts}.
5093 name Vim script file name.
5094 sid Script ID |<SID>|.
5095 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005096 this script name links to, if any, otherwise
5097 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005098 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005099 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005100 specified using the "sid" item in {opts}.
5101 Note that this is a copy, the value of
5102 script-local variables cannot be changed using
5103 this dictionary.
h_east59858792023-10-25 22:47:05 +09005104 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005105
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005106 Examples: >
5107 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005108 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005109<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005110 Return type: list<dict<any>>
5111
5112
ichizok663d18d2025-01-02 18:06:00 +01005113getstacktrace() *getstacktrace()*
5114 Returns the current stack trace of Vim scripts.
5115 Stack trace is a |List|, of which each item is a |Dictionary|
5116 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005117 funcref The funcref if the stack is at a function,
5118 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005119 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005120 stack is at an autocmd event, otherwise this
5121 item is omitted.
5122 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005123 filepath The file path of the script on the stack.
5124
5125 Return type: list<dict<any>>
5126
5127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005128gettabinfo([{tabnr}]) *gettabinfo()*
5129 If {tabnr} is not specified, then information about all the
5130 tab pages is returned as a |List|. Each List item is a
5131 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5132 number and information about that one is returned. If the tab
5133 page does not exist an empty List is returned.
5134
5135 Each List item is a |Dictionary| with the following entries:
5136 tabnr tab page number.
5137 variables a reference to the dictionary with
5138 tabpage-local variables
5139 windows List of |window-ID|s in the tab page.
5140
5141 Can also be used as a |method|: >
5142 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005143<
5144 Return type: list<dict<any>>
5145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005146
5147gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5148 Get the value of a tab-local variable {varname} in tab page
5149 {tabnr}. |t:var|
5150 Tabs are numbered starting with one.
5151 The {varname} argument is a string. When {varname} is empty a
5152 dictionary with all tab-local variables is returned.
5153 Note that the name without "t:" must be used.
5154 When the tab or variable doesn't exist {def} or an empty
5155 string is returned, there is no error message.
5156
5157 Can also be used as a |method|: >
5158 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005159<
5160 Return type: any, depending on {varname}
5161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005162
5163gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5164 Get the value of window-local variable {varname} in window
5165 {winnr} in tab page {tabnr}.
5166 The {varname} argument is a string. When {varname} is empty a
5167 dictionary with all window-local variables is returned.
5168 When {varname} is equal to "&" get the values of all
5169 window-local options in a |Dictionary|.
5170 Otherwise, when {varname} starts with "&" get the value of a
5171 window-local option.
5172 Note that {varname} must be the name without "w:".
5173 Tabs are numbered starting with one. For the current tabpage
5174 use |getwinvar()|.
5175 {winnr} can be the window number or the |window-ID|.
5176 When {winnr} is zero the current window is used.
5177 This also works for a global option, buffer-local option and
5178 window-local option, but it doesn't work for a global variable
5179 or buffer-local variable.
5180 When the tab, window or variable doesn't exist {def} or an
5181 empty string is returned, there is no error message.
5182 Examples: >
5183 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005184 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005185<
5186 To obtain all window-local variables use: >
5187 gettabwinvar({tabnr}, {winnr}, '&')
5188
5189< Can also be used as a |method|: >
5190 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005191<
5192 Return type: any, depending on {varname}
5193
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005194
5195gettagstack([{winnr}]) *gettagstack()*
5196 The result is a Dict, which is the tag stack of window {winnr}.
5197 {winnr} can be the window number or the |window-ID|.
5198 When {winnr} is not specified, the current window is used.
5199 When window {winnr} doesn't exist, an empty Dict is returned.
5200
5201 The returned dictionary contains the following entries:
5202 curidx Current index in the stack. When at
5203 top of the stack, set to (length + 1).
5204 Index of bottom of the stack is 1.
5205 items List of items in the stack. Each item
5206 is a dictionary containing the
5207 entries described below.
5208 length Number of entries in the stack.
5209
5210 Each item in the stack is a dictionary with the following
5211 entries:
5212 bufnr buffer number of the current jump
5213 from cursor position before the tag jump.
5214 See |getpos()| for the format of the
5215 returned list.
5216 matchnr current matching tag number. Used when
5217 multiple matching tags are found for a
5218 name.
5219 tagname name of the tag
5220
5221 See |tagstack| for more information about the tag stack.
5222
5223 Can also be used as a |method|: >
5224 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005225<
5226 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005227
5228
Christ van Willegence0ef912024-06-20 23:41:59 +02005229gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005230 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005231 This is intended for use in Vim scripts. When generating
5232 message translations the {text} is extracted by `xgettext`,
5233 the translator can add translated messages into the .po file
5234 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005235 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005236 `xgettext` does not support single quoted escaped text.
5237
Christ van Willegence0ef912024-06-20 23:41:59 +02005238 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005239 for that specific package. This is mainly required for
5240 third-party Vim scripts. You need to specify a path to the
5241 translations with the |bindtextdomain()| function before
5242 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005243
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005244 Return type: |String|
5245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005246
5247getwininfo([{winid}]) *getwininfo()*
5248 Returns information about windows as a |List| with Dictionaries.
5249
5250 If {winid} is given Information about the window with that ID
5251 is returned, as a |List| with one item. If the window does not
5252 exist the result is an empty list.
5253
5254 Without {winid} information about all the windows in all the
5255 tab pages is returned.
5256
5257 Each List item is a |Dictionary| with the following entries:
5258 botline last complete displayed buffer line
5259 bufnr number of buffer in the window
5260 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005261 leftcol first column displayed; only used when
5262 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005263 loclist 1 if showing a location list
5264 {only with the +quickfix feature}
5265 quickfix 1 if quickfix or location list window
5266 {only with the +quickfix feature}
5267 terminal 1 if a terminal window
5268 {only with the +terminal feature}
5269 tabnr tab page number
5270 topline first displayed buffer line
5271 variables a reference to the dictionary with
5272 window-local variables
5273 width window width
5274 winbar 1 if the window has a toolbar, 0
5275 otherwise
5276 wincol leftmost screen column of the window;
5277 "col" from |win_screenpos()|
5278 textoff number of columns occupied by any
5279 'foldcolumn', 'signcolumn' and line
5280 number in front of the text
5281 winid |window-ID|
5282 winnr window number
5283 winrow topmost screen line of the window;
5284 "row" from |win_screenpos()|
5285
5286 Can also be used as a |method|: >
5287 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005288<
5289 Return type: list<dict<any>>
5290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005291
5292getwinpos([{timeout}]) *getwinpos()*
5293 The result is a |List| with two numbers, the result of
5294 |getwinposx()| and |getwinposy()| combined:
5295 [x-pos, y-pos]
5296 {timeout} can be used to specify how long to wait in msec for
5297 a response from the terminal. When omitted 100 msec is used.
5298 Use a longer time for a remote terminal.
5299 When using a value less than 10 and no response is received
5300 within that time, a previously reported position is returned,
5301 if available. This can be used to poll for the position and
5302 do some work in the meantime: >
5303 while 1
5304 let res = getwinpos(1)
5305 if res[0] >= 0
5306 break
5307 endif
5308 " Do some work here
5309 endwhile
5310<
5311
5312 Can also be used as a |method|: >
5313 GetTimeout()->getwinpos()
5314<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005315 Return type: list<number>
5316
5317
5318getwinposx() *getwinposx()*
5319 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005320 the left hand side of the GUI Vim window. Also works for an
5321 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005322 The result will be -1 if the information is not available
5323 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005324 The value can be used with `:winpos`.
5325
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005326 Return type: |Number|
5327
5328
5329getwinposy() *getwinposy()*
5330 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005331 the top of the GUI Vim window. Also works for an xterm (uses
5332 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005333 The result will be -1 if the information is not available
5334 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005335 The value can be used with `:winpos`.
5336
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005337 Return type: |Number|
5338
5339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005340getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5341 Like |gettabwinvar()| for the current tabpage.
5342 Examples: >
5343 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005344 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005345
5346< Can also be used as a |method|: >
5347 GetWinnr()->getwinvar(varname)
5348<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005349 Return type: any, depending on {varname}
5350
5351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005352glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5353 Expand the file wildcards in {expr}. See |wildcards| for the
5354 use of special characters.
5355
5356 Unless the optional {nosuf} argument is given and is |TRUE|,
5357 the 'suffixes' and 'wildignore' options apply: Names matching
5358 one of the patterns in 'wildignore' will be skipped and
5359 'suffixes' affect the ordering of matches.
5360 'wildignorecase' always applies.
5361
5362 When {list} is present and it is |TRUE| the result is a |List|
5363 with all matching files. The advantage of using a List is,
5364 you also get filenames containing newlines correctly.
5365 Otherwise the result is a String and when there are several
5366 matches, they are separated by <NL> characters.
5367
5368 If the expansion fails, the result is an empty String or List.
5369
5370 You can also use |readdir()| if you need to do complicated
5371 things, such as limiting the number of matches.
5372
5373 A name for a non-existing file is not included. A symbolic
5374 link is only included if it points to an existing file.
5375 However, when the {alllinks} argument is present and it is
5376 |TRUE| then all symbolic links are included.
5377
5378 For most systems backticks can be used to get files names from
5379 any external command. Example: >
5380 :let tagfiles = glob("`find . -name tags -print`")
5381 :let &tags = substitute(tagfiles, "\n", ",", "g")
5382< The result of the program inside the backticks should be one
5383 item per line. Spaces inside an item are allowed.
5384
5385 See |expand()| for expanding special Vim variables. See
5386 |system()| for getting the raw output of an external command.
5387
5388 Can also be used as a |method|: >
5389 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005390<
5391 Return type: |String| or list<string> or list<any> depending
5392 on {list}
5393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005394
h-east624bb832024-11-09 18:37:32 +01005395glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005396 Convert a file pattern, as used by glob(), into a search
5397 pattern. The result can be used to match with a string that
5398 is a file name. E.g. >
5399 if filename =~ glob2regpat('Make*.mak')
5400< This is equivalent to: >
5401 if filename =~ '^Make.*\.mak$'
5402< When {string} is an empty string the result is "^$", match an
5403 empty string.
5404 Note that the result depends on the system. On MS-Windows
5405 a backslash usually means a path separator.
5406
5407 Can also be used as a |method|: >
5408 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005409<
5410 Return type: |String|
5411
5412 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005413globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5414 Perform glob() for String {expr} on all directories in {path}
5415 and concatenate the results. Example: >
5416 :echo globpath(&rtp, "syntax/c.vim")
5417<
5418 {path} is a comma-separated list of directory names. Each
5419 directory name is prepended to {expr} and expanded like with
5420 |glob()|. A path separator is inserted when needed.
5421 To add a comma inside a directory name escape it with a
5422 backslash. Note that on MS-Windows a directory may have a
5423 trailing backslash, remove it if you put a comma after it.
5424 If the expansion fails for one of the directories, there is no
5425 error message.
5426
5427 Unless the optional {nosuf} argument is given and is |TRUE|,
5428 the 'suffixes' and 'wildignore' options apply: Names matching
5429 one of the patterns in 'wildignore' will be skipped and
5430 'suffixes' affect the ordering of matches.
5431
5432 When {list} is present and it is |TRUE| the result is a |List|
5433 with all matching files. The advantage of using a List is, you
5434 also get filenames containing newlines correctly. Otherwise
5435 the result is a String and when there are several matches,
5436 they are separated by <NL> characters. Example: >
5437 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5438<
5439 {alllinks} is used as with |glob()|.
5440
5441 The "**" item can be used to search in a directory tree.
5442 For example, to find all "README.txt" files in the directories
5443 in 'runtimepath' and below: >
5444 :echo globpath(&rtp, "**/README.txt")
5445< Upwards search and limiting the depth of "**" is not
5446 supported, thus using 'path' will not always work properly.
5447
5448 Can also be used as a |method|, the base is passed as the
5449 second argument: >
5450 GetExpr()->globpath(&rtp)
5451<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005452 Return type: |String| or list<string> or list<any> depending
5453 on {list}
5454
5455
5456has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005457 When {check} is omitted or is zero: The result is a Number,
5458 which is 1 if the feature {feature} is supported, zero
5459 otherwise. The {feature} argument is a string, case is
5460 ignored. See |feature-list| below.
5461
5462 When {check} is present and not zero: The result is a Number,
5463 which is 1 if the feature {feature} could ever be supported,
5464 zero otherwise. This is useful to check for a typo in
5465 {feature} and to detect dead code. Keep in mind that an older
5466 Vim version will not know about a feature added later and
5467 features that have been abandoned will not be known by the
5468 current Vim version.
5469
5470 Also see |exists()| and |exists_compiled()|.
5471
5472 Note that to skip code that has a syntax error when the
5473 feature is not available, Vim may skip the rest of the line
5474 and miss a following `endif`. Therefore put the `endif` on a
5475 separate line: >
5476 if has('feature')
5477 let x = this->breaks->without->the->feature
5478 endif
5479< If the `endif` would be moved to the second line as "| endif" it
5480 would not be found.
5481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005482 Return type: |Number|
5483
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005484
5485has_key({dict}, {key}) *has_key()*
5486 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005487 has an entry with key {key}. FALSE otherwise.
5488 The {key} argument is a string. In |Vim9| script a number is
5489 also accepted (and converted to a string) but no other types.
5490 In legacy script the usual automatic conversion to string is
5491 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005492
5493 Can also be used as a |method|: >
5494 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005495<
5496 Return type: |Number|
5497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005498
5499haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5500 The result is a Number:
5501 1 when the window has set a local directory via |:lcd|
5502 2 when the tab-page has set a local directory via |:tcd|
5503 0 otherwise.
5504
5505 Without arguments use the current window.
5506 With {winnr} use this window in the current tab page.
5507 With {winnr} and {tabnr} use the window in the specified tab
5508 page.
5509 {winnr} can be the window number or the |window-ID|.
5510 If {winnr} is -1 it is ignored and only the tabpage is used.
5511 Return 0 if the arguments are invalid.
5512 Examples: >
5513 if haslocaldir() == 1
5514 " window local directory case
5515 elseif haslocaldir() == 2
5516 " tab-local directory case
5517 else
5518 " global directory case
5519 endif
5520
5521 " current window
5522 :echo haslocaldir()
5523 :echo haslocaldir(0)
5524 :echo haslocaldir(0, 0)
5525 " window n in current tab page
5526 :echo haslocaldir(n)
5527 :echo haslocaldir(n, 0)
5528 " window n in tab page m
5529 :echo haslocaldir(n, m)
5530 " tab page m
5531 :echo haslocaldir(-1, m)
5532<
5533 Can also be used as a |method|: >
5534 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005535<
5536 Return type: |Number|
5537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005538
5539hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5540 The result is a Number, which is TRUE if there is a mapping
5541 that contains {what} in somewhere in the rhs (what it is
5542 mapped to) and this mapping exists in one of the modes
5543 indicated by {mode}.
5544 The arguments {what} and {mode} are strings.
5545 When {abbr} is there and it is |TRUE| use abbreviations
5546 instead of mappings. Don't forget to specify Insert and/or
5547 Command-line mode.
5548 Both the global mappings and the mappings local to the current
5549 buffer are checked for a match.
5550 If no matching mapping is found FALSE is returned.
5551 The following characters are recognized in {mode}:
5552 n Normal mode
5553 v Visual and Select mode
5554 x Visual mode
5555 s Select mode
5556 o Operator-pending mode
5557 i Insert mode
5558 l Language-Argument ("r", "f", "t", etc.)
5559 c Command-line mode
5560 When {mode} is omitted, "nvo" is used.
5561
5562 This function is useful to check if a mapping already exists
5563 to a function in a Vim script. Example: >
5564 :if !hasmapto('\ABCdoit')
5565 : map <Leader>d \ABCdoit
5566 :endif
5567< This installs the mapping to "\ABCdoit" only if there isn't
5568 already a mapping to "\ABCdoit".
5569
5570 Can also be used as a |method|: >
5571 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005572<
5573 Return type: |Number|
5574
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005575
5576histadd({history}, {item}) *histadd()*
5577 Add the String {item} to the history {history} which can be
5578 one of: *hist-names*
5579 "cmd" or ":" command line history
5580 "search" or "/" search pattern history
5581 "expr" or "=" typed expression history
5582 "input" or "@" input line history
5583 "debug" or ">" debug command history
5584 empty the current or last used history
5585 The {history} string does not need to be the whole name, one
5586 character is sufficient.
5587 If {item} does already exist in the history, it will be
5588 shifted to become the newest entry.
5589 The result is a Number: TRUE if the operation was successful,
5590 otherwise FALSE is returned.
5591
5592 Example: >
5593 :call histadd("input", strftime("%Y %b %d"))
5594 :let date=input("Enter date: ")
5595< This function is not available in the |sandbox|.
5596
5597 Can also be used as a |method|, the base is passed as the
5598 second argument: >
5599 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005600<
5601 Return type: |Number|
5602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005603
5604histdel({history} [, {item}]) *histdel()*
5605 Clear {history}, i.e. delete all its entries. See |hist-names|
5606 for the possible values of {history}.
5607
5608 If the parameter {item} evaluates to a String, it is used as a
5609 regular expression. All entries matching that expression will
5610 be removed from the history (if there are any).
5611 Upper/lowercase must match, unless "\c" is used |/\c|.
5612 If {item} evaluates to a Number, it will be interpreted as
5613 an index, see |:history-indexing|. The respective entry will
5614 be removed if it exists.
5615
5616 The result is TRUE for a successful operation, otherwise FALSE
5617 is returned.
5618
5619 Examples:
5620 Clear expression register history: >
5621 :call histdel("expr")
5622<
5623 Remove all entries starting with "*" from the search history: >
5624 :call histdel("/", '^\*')
5625<
5626 The following three are equivalent: >
5627 :call histdel("search", histnr("search"))
5628 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005629 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005630<
5631 To delete the last search pattern and use the last-but-one for
5632 the "n" command and 'hlsearch': >
5633 :call histdel("search", -1)
5634 :let @/ = histget("search", -1)
5635<
5636 Can also be used as a |method|: >
5637 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005638<
5639 Return type: |Number|
5640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005641
5642histget({history} [, {index}]) *histget()*
5643 The result is a String, the entry with Number {index} from
5644 {history}. See |hist-names| for the possible values of
5645 {history}, and |:history-indexing| for {index}. If there is
5646 no such entry, an empty String is returned. When {index} is
5647 omitted, the most recent item from the history is used.
5648
5649 Examples:
5650 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005651 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005652
5653< Define an Ex command ":H {num}" that supports re-execution of
5654 the {num}th entry from the output of |:history|. >
5655 :command -nargs=1 H execute histget("cmd", 0+<args>)
5656<
5657 Can also be used as a |method|: >
5658 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005659<
5660 Return type: |String|
5661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005662
5663histnr({history}) *histnr()*
5664 The result is the Number of the current entry in {history}.
5665 See |hist-names| for the possible values of {history}.
5666 If an error occurred, -1 is returned.
5667
5668 Example: >
5669 :let inp_index = histnr("expr")
5670
5671< Can also be used as a |method|: >
5672 GetHistory()->histnr()
5673<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005674 Return type: |Number|
5675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005676hlexists({name}) *hlexists()*
5677 The result is a Number, which is TRUE if a highlight group
5678 called {name} exists. This is when the group has been
5679 defined in some way. Not necessarily when highlighting has
5680 been defined for it, it may also have been used for a syntax
5681 item.
5682 *highlight_exists()*
5683 Obsolete name: highlight_exists().
5684
5685 Can also be used as a |method|: >
5686 GetName()->hlexists()
5687<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005688 Return type: |Number|
5689
5690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005691hlget([{name} [, {resolve}]]) *hlget()*
5692 Returns a List of all the highlight group attributes. If the
5693 optional {name} is specified, then returns a List with only
5694 the attributes of the specified highlight group. Returns an
5695 empty List if the highlight group {name} is not present.
5696
5697 If the optional {resolve} argument is set to v:true and the
5698 highlight group {name} is linked to another group, then the
5699 link is resolved recursively and the attributes of the
5700 resolved highlight group are returned.
5701
5702 Each entry in the returned List is a Dictionary with the
5703 following items:
5704 cleared boolean flag, set to v:true if the highlight
5705 group attributes are cleared or not yet
5706 specified. See |highlight-clear|.
5707 cterm cterm attributes. See |highlight-cterm|.
5708 ctermbg cterm background color.
5709 See |highlight-ctermbg|.
5710 ctermfg cterm foreground color.
5711 See |highlight-ctermfg|.
5712 ctermul cterm underline color. See |highlight-ctermul|.
5713 default boolean flag, set to v:true if the highlight
5714 group link is a default link. See
5715 |highlight-default|.
5716 font highlight group font. See |highlight-font|.
5717 gui gui attributes. See |highlight-gui|.
5718 guibg gui background color. See |highlight-guibg|.
5719 guifg gui foreground color. See |highlight-guifg|.
5720 guisp gui special color. See |highlight-guisp|.
5721 id highlight group ID.
5722 linksto linked highlight group name.
5723 See |:highlight-link|.
5724 name highlight group name. See |group-name|.
5725 start start terminal keycode. See |highlight-start|.
5726 stop stop terminal keycode. See |highlight-stop|.
5727 term term attributes. See |highlight-term|.
5728
5729 The 'term', 'cterm' and 'gui' items in the above Dictionary
5730 have a dictionary value with the following optional boolean
5731 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5732 'reverse', 'inverse' and 'strikethrough'.
5733
5734 Example(s): >
5735 :echo hlget()
5736 :echo hlget('ModeMsg')
5737 :echo hlget('Number', v:true)
5738<
5739 Can also be used as a |method|: >
5740 GetName()->hlget()
5741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005742 Return type: list<dict<any>>
5743
5744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005745hlset({list}) *hlset()*
5746 Creates or modifies the attributes of a List of highlight
5747 groups. Each item in {list} is a dictionary containing the
5748 attributes of a highlight group. See |hlget()| for the list of
5749 supported items in this dictionary.
5750
5751 In addition to the items described in |hlget()|, the following
5752 additional items are supported in the dictionary:
5753
5754 force boolean flag to force the creation of
5755 a link for an existing highlight group
5756 with attributes.
5757
5758 The highlight group is identified using the 'name' item and
5759 the 'id' item (if supplied) is ignored. If a highlight group
5760 with a specified name doesn't exist, then it is created.
5761 Otherwise the attributes of an existing highlight group are
5762 modified.
5763
5764 If an empty dictionary value is used for the 'term' or 'cterm'
5765 or 'gui' entries, then the corresponding attributes are
5766 cleared. If the 'cleared' item is set to v:true, then all the
5767 attributes of the highlight group are cleared.
5768
5769 The 'linksto' item can be used to link a highlight group to
5770 another highlight group. See |:highlight-link|.
5771
5772 Returns zero for success, -1 for failure.
5773
5774 Example(s): >
5775 " add bold attribute to the Visual highlight group
5776 :call hlset([#{name: 'Visual',
5777 \ term: #{reverse: 1 , bold: 1}}])
5778 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5779 :let l = hlget()
5780 :call hlset(l)
5781 " clear the Search highlight group
5782 :call hlset([#{name: 'Search', cleared: v:true}])
5783 " clear the 'term' attributes for a highlight group
5784 :call hlset([#{name: 'Title', term: {}}])
5785 " create the MyHlg group linking it to DiffAdd
5786 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5787 " remove the MyHlg group link
5788 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5789 " clear the attributes and a link
5790 :call hlset([#{name: 'MyHlg', cleared: v:true,
5791 \ linksto: 'NONE'}])
5792<
5793 Can also be used as a |method|: >
5794 GetAttrList()->hlset()
5795<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005796 Return type: |Number|
5797
5798hlID({name}) *hlID()*
5799 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005800 with name {name}. When the highlight group doesn't exist,
5801 zero is returned.
5802 This can be used to retrieve information about the highlight
5803 group. For example, to get the background color of the
5804 "Comment" group: >
5805 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5806< *highlightID()*
5807 Obsolete name: highlightID().
5808
5809 Can also be used as a |method|: >
5810 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005811<
5812 Return type: |Number|
5813
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005814
5815hostname() *hostname()*
5816 The result is a String, which is the name of the machine on
5817 which Vim is currently running. Machine names greater than
5818 256 characters long are truncated.
5819
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005820 Return type: |String|
5821
5822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005823iconv({string}, {from}, {to}) *iconv()*
5824 The result is a String, which is the text {string} converted
5825 from encoding {from} to encoding {to}.
5826 When the conversion completely fails an empty string is
5827 returned. When some characters could not be converted they
5828 are replaced with "?".
5829 The encoding names are whatever the iconv() library function
5830 can accept, see ":!man 3 iconv".
5831 Most conversions require Vim to be compiled with the |+iconv|
5832 feature. Otherwise only UTF-8 to latin1 conversion and back
5833 can be done.
5834 This can be used to display messages with special characters,
5835 no matter what 'encoding' is set to. Write the message in
5836 UTF-8 and use: >
5837 echo iconv(utf8_str, "utf-8", &enc)
5838< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5839 from/to UCS-2 is automatically changed to use UTF-8. You
5840 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5841
5842 Can also be used as a |method|: >
5843 GetText()->iconv('latin1', 'utf-8')
5844<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005845 Return type: |String|
5846
5847
h-east624bb832024-11-09 18:37:32 +01005848id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005849 The result is a unique String associated with the {item} and
5850 not with the {item}'s contents. It is only valid while the
5851 {item} exists and is referenced. It is valid only in the
5852 instance of vim that produces the result. The whole idea is
5853 that `id({item})` does not change if the contents of {item}
5854 changes. This is useful as a `key` for creating an identity
5855 dictionary, rather than one based on equals.
5856
5857 This operation does not reference {item} and there is no
5858 function to convert the `id` to the {item}. It may be useful to
5859 have a map of `id` to {item}. The following >
5860 var referenceMap: dict<any>
5861 var id = item->id()
5862 referenceMap[id] = item
5863< prevents {item} from being garbage collected and provides a
5864 way to get the {item} from the `id`.
5865
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005866 {item} may be a List, Tuple, Dictionary, Object, Job, Channel
5867 or Blob. If the item is not a permitted type, or it is a null
Ernie Raelc8e158b2024-07-09 18:39:52 +02005868 value, then an empty String is returned.
5869
5870 Can also be used as a |method|: >
5871 GetItem()->id()
5872<
5873 Return type: |String|
5874
5875
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005876indent({lnum}) *indent()*
5877 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005878 current buffer. The indent is counted in spaces, the value
5879 of 'tabstop' is relevant. {lnum} is used just like in
5880 |getline()|.
5881 When {lnum} is invalid -1 is returned. In |Vim9| script an
5882 error is given.
5883
5884 Can also be used as a |method|: >
5885 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005886<
5887 Return type: |Number|
5888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005889
5890index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005891 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005892 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005893
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005894 If {object} is a |List| or a |Tuple| return the lowest index
5895 where the item has a value equal to {expr}. There is no
5896 automatic conversion, so the String "4" is different from the
5897 Number 4. And the number 4 is different from the Float 4.0.
5898 The value of 'ignorecase' is not used here, case matters as
5899 indicated by the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005900
5901 If {object} is |Blob| return the lowest index where the byte
5902 value is equal to {expr}.
5903
5904 If {start} is given then start looking at the item with index
5905 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005907 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5908 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005910 -1 is returned when {expr} is not found in {object}.
5911 Example: >
5912 :let idx = index(words, "the")
5913 :if index(numbers, 123) >= 0
5914
5915< Can also be used as a |method|: >
5916 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005917<
5918 Return type: |Number|
5919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005920
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005921indexof({object}, {expr} [, {opts}]) *indexof()*
5922 Returns the index of an item in {object} where {expr} is
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005923 v:true. {object} must be a |List|, a |Tuple| or a |Blob|.
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005924
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005925 If {object} is a |List| or a |Tuple|, evaluate {expr} for each
Christ van Willegen92e109f2025-03-24 20:12:37 +01005926 item in the List or Tuple until the expression is v:true
5927 and return the index of this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005928
5929 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005930 Blob until the expression is v:true and return the index of
5931 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005932
5933 {expr} must be a |string| or |Funcref|.
5934
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005935 If {expr} is a |string|: If {object} is a |List| or a |Tuple|,
5936 inside {expr} |v:key| has the index of the current List or
5937 Tuple item and |v:val| has the value of the item. If {object}
5938 is a |Blob|, inside {expr} |v:key| has the index of the
5939 current byte and |v:val| has the byte value.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005940
5941 If {expr} is a |Funcref| it must take two arguments:
5942 1. the key or the index of the current item.
5943 2. the value of the current item.
5944 The function must return |TRUE| if the item is found and the
5945 search should stop.
5946
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005947 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005948 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005949 startidx start evaluating {expr} at the item with this
5950 index; may be negative for an item relative to
5951 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005952 Returns -1 when {expr} evaluates to v:false for all the items.
5953 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005954 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5955 :echo indexof(l, "v:val.n == 20")
5956 :echo indexof(l, {i, v -> v.n == 30})
5957 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005958
5959< Can also be used as a |method|: >
5960 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005961<
5962 Return type: |Number|
5963
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005965input({prompt} [, {text} [, {completion}]]) *input()*
5966 The result is a String, which is whatever the user typed on
5967 the command-line. The {prompt} argument is either a prompt
5968 string, or a blank string (for no prompt). A '\n' can be used
5969 in the prompt to start a new line.
5970 The highlighting set with |:echohl| is used for the prompt.
5971 The input is entered just like a command-line, with the same
5972 editing commands and mappings. There is a separate history
5973 for lines typed for input().
5974 Example: >
5975 :if input("Coffee or beer? ") == "beer"
5976 : echo "Cheers!"
5977 :endif
5978<
5979 If the optional {text} argument is present and not empty, this
5980 is used for the default reply, as if the user typed this.
5981 Example: >
5982 :let color = input("Color? ", "white")
5983
5984< The optional {completion} argument specifies the type of
5985 completion supported for the input. Without it completion is
5986 not performed. The supported completion types are the same as
5987 that can be supplied to a user-defined command using the
5988 "-complete=" argument. Refer to |:command-completion| for
5989 more information. Example: >
5990 let fname = input("File: ", "", "file")
5991<
5992 NOTE: This function must not be used in a startup file, for
5993 the versions that only run in GUI mode (e.g., the Win32 GUI).
5994 Note: When input() is called from within a mapping it will
5995 consume remaining characters from that mapping, because a
5996 mapping is handled like the characters were typed.
5997 Use |inputsave()| before input() and |inputrestore()|
5998 after input() to avoid that. Another solution is to avoid
5999 that further characters follow in the mapping, e.g., by using
6000 |:execute| or |:normal|.
6001
6002 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006003 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006004 :function GetFoo()
6005 : call inputsave()
6006 : let g:Foo = input("enter search pattern: ")
6007 : call inputrestore()
6008 :endfunction
6009
6010< Can also be used as a |method|: >
6011 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006012<
6013 Return type: |String|
6014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006015
6016inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
6017 Like |input()|, but when the GUI is running and text dialogs
6018 are supported, a dialog window pops up to input the text.
6019 Example: >
6020 :let n = inputdialog("value for shiftwidth", shiftwidth())
6021 :if n != ""
6022 : let &sw = n
6023 :endif
6024< When the dialog is cancelled {cancelreturn} is returned. When
6025 omitted an empty string is returned.
6026 Hitting <Enter> works like pressing the OK button. Hitting
6027 <Esc> works like pressing the Cancel button.
6028 NOTE: Command-line completion is not supported.
6029
6030 Can also be used as a |method|: >
6031 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006032<
6033 Return type: |String|
6034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006035
6036inputlist({textlist}) *inputlist()*
6037 {textlist} must be a |List| of strings. This |List| is
6038 displayed, one string per line. The user will be prompted to
6039 enter a number, which is returned.
6040 The user can also select an item by clicking on it with the
6041 mouse, if the mouse is enabled in the command line ('mouse' is
6042 "a" or includes "c"). For the first string 0 is returned.
6043 When clicking above the first item a negative number is
6044 returned. When clicking on the prompt one more than the
6045 length of {textlist} is returned.
6046 Make sure {textlist} has less than 'lines' entries, otherwise
6047 it won't work. It's a good idea to put the entry number at
6048 the start of the string. And put a prompt in the first item.
6049 Example: >
6050 let color = inputlist(['Select color:', '1. red',
6051 \ '2. green', '3. blue'])
6052
6053< Can also be used as a |method|: >
6054 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006055<
6056 Return type: |Number|
6057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006058
6059inputrestore() *inputrestore()*
6060 Restore typeahead that was saved with a previous |inputsave()|.
6061 Should be called the same number of times inputsave() is
6062 called. Calling it more often is harmless though.
6063 Returns TRUE when there is nothing to restore, FALSE otherwise.
6064
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006065 Return type: |Number|
6066
6067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006068inputsave() *inputsave()*
6069 Preserve typeahead (also from mappings) and clear it, so that
6070 a following prompt gets input from the user. Should be
6071 followed by a matching inputrestore() after the prompt. Can
6072 be used several times, in which case there must be just as
6073 many inputrestore() calls.
6074 Returns TRUE when out of memory, FALSE otherwise.
6075
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006076 Return type: |Number|
6077
6078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006079inputsecret({prompt} [, {text}]) *inputsecret()*
6080 This function acts much like the |input()| function with but
6081 two exceptions:
6082 a) the user's response will be displayed as a sequence of
6083 asterisks ("*") thereby keeping the entry secret, and
6084 b) the user's response will not be recorded on the input
6085 |history| stack.
6086 The result is a String, which is whatever the user actually
6087 typed on the command-line in response to the issued prompt.
6088 NOTE: Command-line completion is not supported.
6089
6090 Can also be used as a |method|: >
6091 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006092<
6093 Return type: |String|
6094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006095
6096insert({object}, {item} [, {idx}]) *insert()*
6097 When {object} is a |List| or a |Blob| insert {item} at the start
6098 of it.
6099
6100 If {idx} is specified insert {item} before the item with index
6101 {idx}. If {idx} is zero it goes before the first item, just
6102 like omitting {idx}. A negative {idx} is also possible, see
6103 |list-index|. -1 inserts just before the last item.
6104
6105 Returns the resulting |List| or |Blob|. Examples: >
6106 :let mylist = insert([2, 3, 5], 1)
6107 :call insert(mylist, 4, -1)
6108 :call insert(mylist, 6, len(mylist))
6109< The last example can be done simpler with |add()|.
6110 Note that when {item} is a |List| it is inserted as a single
6111 item. Use |extend()| to concatenate |Lists|.
6112
6113 Can also be used as a |method|: >
6114 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006115<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006116 Return type: |Number|
6117
6118
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006119 *instanceof()* *E614* *E616* *E693*
6120instanceof({object}, {class})
6121 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006122 argument is a direct or indirect instance of a |Class|,
6123 |Interface|, or class |:type| alias specified by {class}.
6124 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006125 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006126 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006127 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006128
6129< Can also be used as a |method|: >
6130 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006131<
6132 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006134interrupt() *interrupt()*
6135 Interrupt script execution. It works more or less like the
6136 user typing CTRL-C, most commands won't execute and control
6137 returns to the user. This is useful to abort execution
6138 from lower down, e.g. in an autocommand. Example: >
6139 :function s:check_typoname(file)
6140 : if fnamemodify(a:file, ':t') == '['
6141 : echomsg 'Maybe typo'
6142 : call interrupt()
6143 : endif
6144 :endfunction
6145 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006146<
6147 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006148
6149invert({expr}) *invert()*
6150 Bitwise invert. The argument is converted to a number. A
6151 List, Dict or Float argument causes an error. Example: >
6152 :let bits = invert(bits)
6153< Can also be used as a |method|: >
6154 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006155<
6156 Return type: |Number|
6157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006158
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006159isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006160 The result is a Number, which is |TRUE| when {path} is an
6161 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006162 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006163 On MS-Windows, it is considered absolute when it starts with an
6164 optional drive prefix and is followed by a '\' or '/'. UNC paths
6165 are always absolute.
6166 Example: >
6167 echo isabsolutepath('/usr/share/') " 1
6168 echo isabsolutepath('./foobar') " 0
6169 echo isabsolutepath('C:\Windows') " 1
6170 echo isabsolutepath('foobar') " 0
6171 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006172<
LemonBoydca1d402022-04-28 15:26:33 +01006173 Can also be used as a |method|: >
6174 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006175<
6176 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006177
6178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006179isdirectory({directory}) *isdirectory()*
6180 The result is a Number, which is |TRUE| when a directory
6181 with the name {directory} exists. If {directory} doesn't
6182 exist, or isn't a directory, the result is |FALSE|. {directory}
6183 is any expression, which is used as a String.
6184
6185 Can also be used as a |method|: >
6186 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006187<
6188 Return type: |Number|
6189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006190
6191isinf({expr}) *isinf()*
6192 Return 1 if {expr} is a positive infinity, or -1 a negative
6193 infinity, otherwise 0. >
6194 :echo isinf(1.0 / 0.0)
6195< 1 >
6196 :echo isinf(-1.0 / 0.0)
6197< -1
6198
6199 Can also be used as a |method|: >
6200 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006201<
6202 Return type: |Number|
6203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006204
6205islocked({expr}) *islocked()* *E786*
6206 The result is a Number, which is |TRUE| when {expr} is the
6207 name of a locked variable.
6208 The string argument {expr} must be the name of a variable,
6209 |List| item or |Dictionary| entry, not the variable itself!
6210 Example: >
6211 :let alist = [0, ['a', 'b'], 2, 3]
6212 :lockvar 1 alist
6213 :echo islocked('alist') " 1
6214 :echo islocked('alist[1]') " 0
6215
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006216< When {expr} is a variable that does not exist -1 is returned.
6217 If {expr} uses a range, list or dict index that is out of
6218 range or does not exist you get an error message. Use
6219 |exists()| to check for existence.
6220 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006221
6222 Can also be used as a |method|: >
6223 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006224<
6225 Return type: |Number|
6226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006227
6228isnan({expr}) *isnan()*
6229 Return |TRUE| if {expr} is a float with value NaN. >
6230 echo isnan(0.0 / 0.0)
6231< 1
6232
6233 Can also be used as a |method|: >
6234 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006235<
6236 Return type: |Number|
6237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238
6239items({dict}) *items()*
6240 Return a |List| with all the key-value pairs of {dict}. Each
6241 |List| item is a list with two items: the key of a {dict}
6242 entry and the value of this entry. The |List| is in arbitrary
6243 order. Also see |keys()| and |values()|.
6244 Example: >
6245 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006246 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006247 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006248<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006249 A |List|, a |Tuple| or a |String| argument is also supported.
6250 In these cases, items() returns a List with the index and the
6251 value at the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006253 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006254 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006255<
6256 Return type: list<list<any>> or list<any>
6257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006258
6259job_ functions are documented here: |job-functions-details|
6260
6261
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006262join({expr} [, {sep}]) *join()*
6263 Join the items in {expr} together into one String. {expr} can
6264 be a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006265 When {sep} is specified it is put in between the items. If
6266 {sep} is omitted a single space is used.
6267 Note that {sep} is not added at the end. You might want to
6268 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006269 let lines = join(mylist, "\n") .. "\n"
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006270< String items are used as-is. |Lists|, |Tuples| and
6271 |Dictionaries| are converted into a string like with
6272 |string()|. The opposite function is |split()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006273
6274 Can also be used as a |method|: >
6275 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006276<
6277 Return type: |String|
6278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006279
6280js_decode({string}) *js_decode()*
6281 This is similar to |json_decode()| with these differences:
6282 - Object key names do not have to be in quotes.
6283 - Strings can be in single quotes.
6284 - Empty items in an array (between two commas) are allowed and
6285 result in v:none items.
6286
6287 Can also be used as a |method|: >
6288 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006289<
6290 Return type: any, depending on {varname}
6291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006292
6293js_encode({expr}) *js_encode()*
6294 This is similar to |json_encode()| with these differences:
6295 - Object key names are not in quotes.
6296 - v:none items in an array result in an empty item between
6297 commas.
6298 For example, the Vim object:
6299 [1,v:none,{"one":1},v:none] ~
6300 Will be encoded as:
6301 [1,,{one:1},,] ~
6302 While json_encode() would produce:
6303 [1,null,{"one":1},null] ~
6304 This encoding is valid for JavaScript. It is more efficient
6305 than JSON, especially when using an array with optional items.
6306
6307 Can also be used as a |method|: >
6308 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006309<
6310 Return type: |String|
6311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006312
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006313json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006314 This parses a JSON formatted string and returns the equivalent
6315 in Vim values. See |json_encode()| for the relation between
6316 JSON and Vim values.
6317 The decoding is permissive:
6318 - A trailing comma in an array and object is ignored, e.g.
6319 "[1, 2, ]" is the same as "[1, 2]".
6320 - Integer keys are accepted in objects, e.g. {1:2} is the
6321 same as {"1":2}.
6322 - More floating point numbers are recognized, e.g. "1." for
6323 "1.0", or "001.2" for "1.2". Special floating point values
6324 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6325 are accepted.
6326 - Leading zeroes in integer numbers are ignored, e.g. "012"
6327 for "12" or "-012" for "-12".
6328 - Capitalization is ignored in literal names null, true or
6329 false, e.g. "NULL" for "null", "True" for "true".
6330 - Control characters U+0000 through U+001F which are not
6331 escaped in strings are accepted, e.g. " " (tab
6332 character in string) for "\t".
6333 - An empty JSON expression or made of only spaces is accepted
6334 and results in v:none.
6335 - Backslash in an invalid 2-character sequence escape is
6336 ignored, e.g. "\a" is decoded as "a".
6337 - A correct surrogate pair in JSON strings should normally be
6338 a 12 character sequence such as "\uD834\uDD1E", but
6339 json_decode() silently accepts truncated surrogate pairs
6340 such as "\uD834" or "\uD834\u"
6341 *E938*
6342 A duplicate key in an object, valid in rfc7159, is not
6343 accepted by json_decode() as the result must be a valid Vim
6344 type, e.g. this fails: {"a":"b", "a":"c"}
6345
6346 Can also be used as a |method|: >
6347 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006348<
6349 Return type: any, depending on {varname}
6350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006351
6352json_encode({expr}) *json_encode()*
6353 Encode {expr} as JSON and return this as a string.
6354 The encoding is specified in:
6355 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006356 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006357 |Number| decimal number
6358 |Float| floating point number
6359 Float nan "NaN"
6360 Float inf "Infinity"
6361 Float -inf "-Infinity"
6362 |String| in double quotes (possibly null)
6363 |Funcref| not possible, error
6364 |List| as an array (possibly null); when
6365 used recursively: []
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006366 |Tuple| as an array (possibly null); when
6367 used recursively: []
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006368 |Dict| as an object (possibly null); when
6369 used recursively: {}
6370 |Blob| as an array of the individual bytes
6371 v:false "false"
6372 v:true "true"
6373 v:none "null"
6374 v:null "null"
6375 Note that NaN and Infinity are passed on as values. This is
6376 missing in the JSON standard, but several implementations do
6377 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006378 If a string contains an illegal character then the replacement
6379 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006380
6381 Can also be used as a |method|: >
6382 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006383<
6384 Return type: |String|
6385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006386
6387keys({dict}) *keys()*
6388 Return a |List| with all the keys of {dict}. The |List| is in
6389 arbitrary order. Also see |items()| and |values()|.
6390
6391 Can also be used as a |method|: >
6392 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006393<
6394 Return type: list<string>
6395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006396
zeertzjqcdc83932022-09-12 13:38:41 +01006397keytrans({string}) *keytrans()*
6398 Turn the internal byte representation of keys into a form that
6399 can be used for |:map|. E.g. >
6400 :let xx = "\<C-Home>"
6401 :echo keytrans(xx)
6402< <C-Home>
6403
6404 Can also be used as a |method|: >
6405 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006406<
6407 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006408
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006409
6410len({expr}) *len()* *E701*
6411 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006412 When {expr} is a String or a Number the length in bytes is
6413 used, as with |strlen()|.
6414 When {expr} is a |List| the number of items in the |List| is
6415 returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006416 When {expr} is a |Tuple| the number of items in the |Tuple| is
6417 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006418 When {expr} is a |Blob| the number of bytes is returned.
6419 When {expr} is a |Dictionary| the number of entries in the
6420 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006421 When {expr} is an |Object|, invokes the len() method in the
6422 object (if present) to get the length (|object-len()|).
6423 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006424
6425 Can also be used as a |method|: >
6426 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006427<
6428 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006429
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006430
6431 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006432libcall({libname}, {funcname}, {argument})
6433 Call function {funcname} in the run-time library {libname}
6434 with single argument {argument}.
6435 This is useful to call functions in a library that you
6436 especially made to be used with Vim. Since only one argument
6437 is possible, calling standard library functions is rather
6438 limited.
6439 The result is the String returned by the function. If the
6440 function returns NULL, this will appear as an empty string ""
6441 to Vim.
6442 If the function returns a number, use libcallnr()!
6443 If {argument} is a number, it is passed to the function as an
6444 int; if {argument} is a string, it is passed as a
6445 null-terminated string.
6446 This function will fail in |restricted-mode|.
6447
6448 libcall() allows you to write your own 'plug-in' extensions to
6449 Vim without having to recompile the program. It is NOT a
6450 means to call system functions! If you try to do so Vim will
6451 very probably crash.
6452
6453 For Win32, the functions you write must be placed in a DLL
6454 and use the normal C calling convention (NOT Pascal which is
6455 used in Windows System DLLs). The function must take exactly
6456 one parameter, either a character pointer or a long integer,
6457 and must return a character pointer or NULL. The character
6458 pointer returned must point to memory that will remain valid
6459 after the function has returned (e.g. in static data in the
6460 DLL). If it points to allocated memory, that memory will
6461 leak away. Using a static buffer in the function should work,
6462 it's then freed when the DLL is unloaded.
6463
6464 WARNING: If the function returns a non-valid pointer, Vim may
6465 crash! This also happens if the function returns a number,
6466 because Vim thinks it's a pointer.
6467 For Win32 systems, {libname} should be the filename of the DLL
6468 without the ".DLL" suffix. A full path is only required if
6469 the DLL is not in the usual places.
6470 For Unix: When compiling your own plugins, remember that the
6471 object code must be compiled as position-independent ('PIC').
6472 {only in Win32 and some Unix versions, when the |+libcall|
6473 feature is present}
6474 Examples: >
6475 :echo libcall("libc.so", "getenv", "HOME")
6476
6477< Can also be used as a |method|, the base is passed as the
6478 third argument: >
6479 GetValue()->libcall("libc.so", "getenv")
6480<
6481 *libcallnr()*
6482libcallnr({libname}, {funcname}, {argument})
6483 Just like |libcall()|, but used for a function that returns an
6484 int instead of a string.
6485 {only in Win32 on some Unix versions, when the |+libcall|
6486 feature is present}
6487 Examples: >
6488 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6489 :call libcallnr("libc.so", "printf", "Hello World!\n")
6490 :call libcallnr("libc.so", "sleep", 10)
6491<
6492 Can also be used as a |method|, the base is passed as the
6493 third argument: >
6494 GetValue()->libcallnr("libc.so", "printf")
6495<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006496 Return type: |String|
6497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006498
6499line({expr} [, {winid}]) *line()*
6500 The result is a Number, which is the line number of the file
6501 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006502 See |getpos()| for accepted positions.
6503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006504 To get the column number use |col()|. To get both use
6505 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006507 With the optional {winid} argument the values are obtained for
6508 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006509
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006510 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006512 Examples: >
6513 line(".") line number of the cursor
6514 line(".", winid) idem, in window "winid"
6515 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006516 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006517<
6518 To jump to the last known position when opening a file see
6519 |last-position-jump|.
6520
6521 Can also be used as a |method|: >
6522 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006523<
6524 Return type: |Number|
6525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006526
6527line2byte({lnum}) *line2byte()*
6528 Return the byte count from the start of the buffer for line
6529 {lnum}. This includes the end-of-line character, depending on
6530 the 'fileformat' option for the current buffer. The first
6531 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6532 This can also be used to get the byte count for the line just
6533 below the last line: >
6534 line2byte(line("$") + 1)
6535< This is the buffer size plus one. If 'fileencoding' is empty
6536 it is the file size plus one. {lnum} is used like with
6537 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6538 feature has been disabled at compile time, -1 is returned.
6539 Also see |byte2line()|, |go| and |:goto|.
6540
6541 Can also be used as a |method|: >
6542 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006543<
6544 Return type: |Number|
6545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006546
6547lispindent({lnum}) *lispindent()*
6548 Get the amount of indent for line {lnum} according the lisp
6549 indenting rules, as with 'lisp'.
6550 The indent is counted in spaces, the value of 'tabstop' is
6551 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006552 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006553 error is given.
6554
6555 Can also be used as a |method|: >
6556 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006557<
6558 Return type: |Number|
6559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006560
6561list2blob({list}) *list2blob()*
6562 Return a Blob concatenating all the number values in {list}.
6563 Examples: >
6564 list2blob([1, 2, 3, 4]) returns 0z01020304
6565 list2blob([]) returns 0z
6566< Returns an empty Blob on error. If one of the numbers is
6567 negative or more than 255 error *E1239* is given.
6568
6569 |blob2list()| does the opposite.
6570
6571 Can also be used as a |method|: >
6572 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006573<
6574 Return type: |Blob|
6575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006576
6577list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006578 Convert each number in {list} to a character string and
6579 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006580 list2str([32]) returns " "
6581 list2str([65, 66, 67]) returns "ABC"
6582< The same can be done (slowly) with: >
6583 join(map(list, {nr, val -> nr2char(val)}), '')
6584< |str2list()| does the opposite.
6585
6586 When {utf8} is omitted or zero, the current 'encoding' is used.
6587 When {utf8} is TRUE, always return UTF-8 characters.
6588 With UTF-8 composing characters work as expected: >
6589 list2str([97, 769]) returns "á"
6590<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006591 Returns an empty string on error.
6592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006593 Can also be used as a |method|: >
6594 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006595<
6596 Return type: |String|
6597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006598
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006599list2tuple({list}) *list2tuple()*
6600 Create a Tuple from a shallow copy of the list items.
6601 Examples: >
6602 list2tuple([1, 2, 3]) returns (1, 2, 3)
6603< |tuple2list()| does the opposite.
6604
6605 This function doesn't recursively convert all the List items
6606 in {list} to a Tuple. Note that the items are identical
6607 between the list and the tuple, changing an item changes the
6608 contents of both the tuple and the list.
6609
6610 Returns an empty tuple on error.
6611
6612 Can also be used as a |method|: >
6613 GetList()->list2tuple()
6614<
6615 Return type: tuple<{type}> (depending on the given |List|)
6616
6617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006618listener_add({callback} [, {buf}]) *listener_add()*
6619 Add a callback function that will be invoked when changes have
6620 been made to buffer {buf}.
6621 {buf} refers to a buffer name or number. For the accepted
6622 values, see |bufname()|. When {buf} is omitted the current
6623 buffer is used.
6624 Returns a unique ID that can be passed to |listener_remove()|.
6625
6626 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006627 bufnr the buffer that was changed
6628 start first changed line number
6629 end first line number below the change
6630 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006631 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006632 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006633
6634 Example: >
6635 func Listener(bufnr, start, end, added, changes)
6636 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6637 endfunc
6638 call listener_add('Listener', bufnr)
6639
Bram Moolenaar944697a2022-02-20 19:48:20 +00006640< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006641 dictionary with these entries:
6642 lnum the first line number of the change
6643 end the first line below the change
6644 added number of lines added; negative if lines were
6645 deleted
6646 col first column in "lnum" that was affected by
6647 the change; one if unknown or the whole line
6648 was affected; this is a byte index, first
6649 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006650 When lines are inserted (not when a line is split, e.g. by
6651 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006652 lnum line above which the new line is added
6653 end equal to "lnum"
6654 added number of lines inserted
6655 col 1
6656 When lines are deleted the values are:
6657 lnum the first deleted line
6658 end the line below the first deleted line, before
6659 the deletion was done
6660 added negative, number of lines deleted
6661 col 1
6662 When lines are changed:
6663 lnum the first changed line
6664 end the line below the last changed line
6665 added 0
6666 col first column with a change or 1
6667
6668 The entries are in the order the changes were made, thus the
6669 most recent change is at the end. The line numbers are valid
6670 when the callback is invoked, but later changes may make them
6671 invalid, thus keeping a copy for later might not work.
6672
6673 The {callback} is invoked just before the screen is updated,
6674 when |listener_flush()| is called or when a change is being
6675 made that changes the line count in a way it causes a line
6676 number in the list of changes to become invalid.
6677
6678 The {callback} is invoked with the text locked, see
6679 |textlock|. If you do need to make changes to the buffer, use
6680 a timer to do this later |timer_start()|.
6681
6682 The {callback} is not invoked when the buffer is first loaded.
6683 Use the |BufReadPost| autocmd event to handle the initial text
6684 of a buffer.
6685 The {callback} is also not invoked when the buffer is
6686 unloaded, use the |BufUnload| autocmd event for that.
6687
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006688 Returns zero if {callback} or {buf} is invalid.
6689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006690 Can also be used as a |method|, the base is passed as the
6691 second argument: >
6692 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006693<
6694 Return type: |Number|
6695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006696
6697listener_flush([{buf}]) *listener_flush()*
6698 Invoke listener callbacks for buffer {buf}. If there are no
6699 pending changes then no callbacks are invoked.
6700
6701 {buf} refers to a buffer name or number. For the accepted
6702 values, see |bufname()|. When {buf} is omitted the current
6703 buffer is used.
6704
6705 Can also be used as a |method|: >
6706 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006707<
6708 Return type: |Number|
6709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006710
6711listener_remove({id}) *listener_remove()*
6712 Remove a listener previously added with listener_add().
6713 Returns FALSE when {id} could not be found, TRUE when {id} was
6714 removed.
6715
6716 Can also be used as a |method|: >
6717 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006718<
6719 Return type: |Number|
6720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006721
6722localtime() *localtime()*
6723 Return the current time, measured as seconds since 1st Jan
6724 1970. See also |strftime()|, |strptime()| and |getftime()|.
6725
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006726 Return type: |Number|
6727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006728
6729log({expr}) *log()*
6730 Return the natural logarithm (base e) of {expr} as a |Float|.
6731 {expr} must evaluate to a |Float| or a |Number| in the range
6732 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006733 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006734 Examples: >
6735 :echo log(10)
6736< 2.302585 >
6737 :echo log(exp(5))
6738< 5.0
6739
6740 Can also be used as a |method|: >
6741 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006742<
6743 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006744
6745
6746log10({expr}) *log10()*
6747 Return the logarithm of Float {expr} to base 10 as a |Float|.
6748 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006749 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006750 Examples: >
6751 :echo log10(1000)
6752< 3.0 >
6753 :echo log10(0.01)
6754< -2.0
6755
6756 Can also be used as a |method|: >
6757 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006758<
6759 Return type: |Float|
6760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006761
6762luaeval({expr} [, {expr}]) *luaeval()*
6763 Evaluate Lua expression {expr} and return its result converted
6764 to Vim data structures. Second {expr} may hold additional
6765 argument accessible as _A inside first {expr}.
6766 Strings are returned as they are.
6767 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006768 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006769 Dictionaries and lists obtained by vim.eval() are returned
6770 as-is.
6771 Other objects are returned as zero without any errors.
6772 See |lua-luaeval| for more details.
6773 Note that in a `:def` function local variables are not visible
6774 to {expr}.
6775
6776 Can also be used as a |method|: >
6777 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006778<
6779 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006780
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006781 {only available when compiled with the |+lua| feature}
6782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006783
6784map({expr1}, {expr2}) *map()*
6785 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006786 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006787 item in {expr1} with the result of evaluating {expr2}.
6788 For a |Blob| each byte is replaced.
6789 For a |String|, each character, including composing
6790 characters, is replaced.
6791 If the item type changes you may want to use |mapnew()| to
6792 create a new List or Dictionary. This is required when using
6793 Vim9 script.
6794
6795 {expr2} must be a |String| or |Funcref|.
6796
6797 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6798 of the current item. For a |Dictionary| |v:key| has the key
6799 of the current item and for a |List| |v:key| has the index of
6800 the current item. For a |Blob| |v:key| has the index of the
6801 current byte. For a |String| |v:key| has the index of the
6802 current character.
6803 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006804 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006805< This puts "> " before and " <" after each item in "mylist".
6806
6807 Note that {expr2} is the result of an expression and is then
6808 used as an expression again. Often it is good to use a
6809 |literal-string| to avoid having to double backslashes. You
6810 still have to double ' quotes
6811
6812 If {expr2} is a |Funcref| it is called with two arguments:
6813 1. The key or the index of the current item.
6814 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006815 With a legacy script lambda you don't get an error if it only
6816 accepts one argument, but with a Vim9 lambda you get "E1106:
6817 One argument too many", the number of arguments must match.
6818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006819 The function must return the new value of the item. Example
6820 that changes each value by "key-value": >
6821 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006822 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006823 endfunc
6824 call map(myDict, function('KeyValue'))
6825< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006826 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006827< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006828 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006829< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006830 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006831<
6832 The operation is done in-place for a |List| and |Dictionary|.
6833 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006834 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006835
6836< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6837 or a new |Blob| or |String|.
6838 When an error is encountered while evaluating {expr2} no
6839 further items in {expr1} are processed.
6840 When {expr2} is a Funcref errors inside a function are ignored,
6841 unless it was defined with the "abort" flag.
6842
6843 Can also be used as a |method|: >
6844 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006845<
6846 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6847 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006848
6849
6850maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6851 When {dict} is omitted or zero: Return the rhs of mapping
6852 {name} in mode {mode}. The returned String has special
6853 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006854 listing. When {dict} is TRUE a dictionary is returned, see
6855 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006856
6857 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006858 returned if {dict} is FALSE, otherwise returns an empty Dict.
6859 When the mapping for {name} is empty, then "<Nop>" is
6860 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006861
6862 The {name} can have special key names, like in the ":map"
6863 command.
6864
6865 {mode} can be one of these strings:
6866 "n" Normal
6867 "v" Visual (including Select)
6868 "o" Operator-pending
6869 "i" Insert
6870 "c" Cmd-line
6871 "s" Select
6872 "x" Visual
6873 "l" langmap |language-mapping|
6874 "t" Terminal-Job
6875 "" Normal, Visual and Operator-pending
6876 When {mode} is omitted, the modes for "" are used.
6877
6878 When {abbr} is there and it is |TRUE| use abbreviations
6879 instead of mappings.
6880
6881 When {dict} is there and it is |TRUE| return a dictionary
6882 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006883 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006884 "lhs" The {lhs} of the mapping as it would be typed
6885 "lhsraw" The {lhs} of the mapping as raw bytes
6886 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6887 form, only present when it differs from "lhsraw"
6888 "rhs" The {rhs} of the mapping as typed.
6889 "silent" 1 for a |:map-silent| mapping, else 0.
6890 "noremap" 1 if the {rhs} of the mapping is not remappable.
6891 "script" 1 if mapping was defined with <script>.
6892 "expr" 1 for an expression mapping (|:map-<expr>|).
6893 "buffer" 1 for a buffer local mapping (|:map-local|).
6894 "mode" Modes for which the mapping is defined. In
6895 addition to the modes mentioned above, these
6896 characters will be used:
6897 " " Normal, Visual and Operator-pending
6898 "!" Insert and Commandline mode
6899 (|mapmode-ic|)
6900 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006901 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006902 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006903 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006904 "lnum" The line number in "sid", zero if unknown.
6905 "nowait" Do not wait for other, longer mappings.
6906 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006907 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006908 "mode_bits" Vim's internal binary representation of "mode".
6909 |mapset()| ignores this; only "mode" is used.
6910 See |maplist()| for usage examples. The values
6911 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006912
6913 The dictionary can be used to restore a mapping with
6914 |mapset()|.
6915
6916 The mappings local to the current buffer are checked first,
6917 then the global mappings.
6918 This function can be used to map a key even when it's already
6919 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006920 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006921
6922< Can also be used as a |method|: >
6923 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006924<
6925 Return type: |String| or dict<any> depending on {dict}
6926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006927
6928mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6929 Check if there is a mapping that matches with {name} in mode
6930 {mode}. See |maparg()| for {mode} and special names in
6931 {name}.
6932 When {abbr} is there and it is |TRUE| use abbreviations
6933 instead of mappings.
6934 A match happens with a mapping that starts with {name} and
6935 with a mapping which is equal to the start of {name}.
6936
6937 matches mapping "a" "ab" "abc" ~
6938 mapcheck("a") yes yes yes
6939 mapcheck("abc") yes yes yes
6940 mapcheck("ax") yes no no
6941 mapcheck("b") no no no
6942
6943 The difference with maparg() is that mapcheck() finds a
6944 mapping that matches with {name}, while maparg() only finds a
6945 mapping for {name} exactly.
6946 When there is no mapping that starts with {name}, an empty
6947 String is returned. If there is one, the RHS of that mapping
6948 is returned. If there are several mappings that start with
6949 {name}, the RHS of one of them is returned. This will be
6950 "<Nop>" if the RHS is empty.
6951 The mappings local to the current buffer are checked first,
6952 then the global mappings.
6953 This function can be used to check if a mapping can be added
6954 without being ambiguous. Example: >
6955 :if mapcheck("_vv") == ""
6956 : map _vv :set guifont=7x13<CR>
6957 :endif
6958< This avoids adding the "_vv" mapping when there already is a
6959 mapping for "_v" or for "_vvv".
6960
6961 Can also be used as a |method|: >
6962 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006963<
6964 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006965
6966
Ernie Rael09661202022-04-25 14:40:44 +01006967maplist([{abbr}]) *maplist()*
6968 Returns a |List| of all mappings. Each List item is a |Dict|,
6969 the same as what is returned by |maparg()|, see
6970 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6971 abbreviations instead of mappings.
6972
6973 Example to show all mappings with 'MultiMatch' in rhs: >
6974 vim9script
6975 echo maplist()->filter(
6976 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006977< It can be tricky to find mappings for particular |:map-modes|.
6978 |mapping-dict|'s "mode_bits" can simplify this. For example,
6979 the mode_bits for Normal, Insert or Command-line modes are
6980 0x19. To find all the mappings available in those modes you
6981 can do: >
6982 vim9script
6983 var saved_maps = []
6984 for m in maplist()
6985 if and(m.mode_bits, 0x19) != 0
6986 saved_maps->add(m)
6987 endif
6988 endfor
6989 echo saved_maps->mapnew((_, m) => m.lhs)
6990< The values of the mode_bits are defined in Vim's src/vim.h
6991 file and they can be discovered at runtime using
6992 |:map-commands| and "maplist()". Example: >
6993 vim9script
6994 omap xyzzy <Nop>
6995 var op_bit = maplist()->filter(
6996 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6997 ounmap xyzzy
6998 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006999<
7000 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01007001
7002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007003mapnew({expr1}, {expr2}) *mapnew()*
7004 Like |map()| but instead of replacing items in {expr1} a new
7005 List or Dictionary is created and returned. {expr1} remains
7006 unchanged. Items can still be changed by {expr2}, if you
7007 don't want that use |deepcopy()| first.
7008
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007009 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
7010 depending on {expr1}
7011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007012
7013mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01007014mapset({dict})
7015 Restore a mapping from a dictionary, possibly returned by
7016 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
7017 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01007018 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01007019 feature allows copying mappings from one buffer to another.
7020 The dict.mode value may restore a single mapping that covers
7021 more than one mode, like with mode values of '!', ' ', 'nox',
7022 or 'v'. *E1276*
7023
7024 In the first form, {mode} and {abbr} should be the same as
7025 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007026 {mode} is used to define the mode in which the mapping is set,
7027 not the "mode" entry in {dict}.
7028 Example for saving and restoring a mapping: >
7029 let save_map = maparg('K', 'n', 0, 1)
7030 nnoremap K somethingelse
7031 ...
7032 call mapset('n', 0, save_map)
7033< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01007034 e.g. with `:map!`, you need to save/restore the mapping for
7035 all of them, when they might differ.
7036
7037 In the second form, with {dict} as the only argument, mode
7038 and abbr are taken from the dict.
7039 Example: >
7040 vim9script
7041 var save_maps = maplist()->filter(
7042 (_, m) => m.lhs == 'K')
7043 nnoremap K somethingelse
7044 cnoremap K somethingelse2
7045 # ...
7046 unmap K
7047 for d in save_maps
7048 mapset(d)
7049 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007050<
7051 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007052
7053
7054match({expr}, {pat} [, {start} [, {count}]]) *match()*
7055 When {expr} is a |List| then this returns the index of the
7056 first item where {pat} matches. Each item is used as a
7057 String, |Lists| and |Dictionaries| are used as echoed.
7058
7059 Otherwise, {expr} is used as a String. The result is a
7060 Number, which gives the index (byte offset) in {expr} where
7061 {pat} matches.
7062
7063 A match at the first character or |List| item returns zero.
7064 If there is no match -1 is returned.
7065
7066 For getting submatches see |matchlist()|.
7067 Example: >
7068 :echo match("testing", "ing") " results in 4
7069 :echo match([1, 'x'], '\a') " results in 1
7070< See |string-match| for how {pat} is used.
7071 *strpbrk()*
7072 Vim doesn't have a strpbrk() function. But you can do: >
7073 :let sepidx = match(line, '[.,;: \t]')
7074< *strcasestr()*
7075 Vim doesn't have a strcasestr() function. But you can add
7076 "\c" to the pattern to ignore case: >
7077 :let idx = match(haystack, '\cneedle')
7078<
7079 If {start} is given, the search starts from byte index
7080 {start} in a String or item {start} in a |List|.
7081 The result, however, is still the index counted from the
7082 first character/item. Example: >
7083 :echo match("testing", "ing", 2)
7084< result is again "4". >
7085 :echo match("testing", "ing", 4)
7086< result is again "4". >
7087 :echo match("testing", "t", 2)
7088< result is "3".
7089 For a String, if {start} > 0 then it is like the string starts
7090 {start} bytes later, thus "^" will match at {start}. Except
7091 when {count} is given, then it's like matches before the
7092 {start} byte are ignored (this is a bit complicated to keep it
7093 backwards compatible).
7094 For a String, if {start} < 0, it will be set to 0. For a list
7095 the index is counted from the end.
7096 If {start} is out of range ({start} > strlen({expr}) for a
7097 String or {start} > len({expr}) for a |List|) -1 is returned.
7098
7099 When {count} is given use the {count}'th match. When a match
7100 is found in a String the search for the next one starts one
7101 character further. Thus this example results in 1: >
7102 echo match("testing", "..", 0, 2)
7103< In a |List| the search continues in the next item.
7104 Note that when {count} is added the way {start} works changes,
7105 see above.
7106
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007107 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007108 See |pattern| for the patterns that are accepted.
7109 The 'ignorecase' option is used to set the ignore-caseness of
7110 the pattern. 'smartcase' is NOT used. The matching is always
7111 done like 'magic' is set and 'cpoptions' is empty.
7112 Note that a match at the start is preferred, thus when the
7113 pattern is using "*" (any number of matches) it tends to find
7114 zero matches at the start instead of a number of matches
7115 further down in the text.
7116
7117 Can also be used as a |method|: >
7118 GetText()->match('word')
7119 GetList()->match('word')
7120<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007121 Return type: |Number|
7122
7123
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007124 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007125matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7126 Defines a pattern to be highlighted in the current window (a
7127 "match"). It will be highlighted with {group}. Returns an
7128 identification number (ID), which can be used to delete the
7129 match using |matchdelete()|. The ID is bound to the window.
7130 Matching is case sensitive and magic, unless case sensitivity
7131 or magicness are explicitly overridden in {pattern}. The
7132 'magic', 'smartcase' and 'ignorecase' options are not used.
7133 The "Conceal" value is special, it causes the match to be
7134 concealed.
7135
7136 The optional {priority} argument assigns a priority to the
7137 match. A match with a high priority will have its
7138 highlighting overrule that of a match with a lower priority.
7139 A priority is specified as an integer (negative numbers are no
7140 exception). If the {priority} argument is not specified, the
7141 default priority is 10. The priority of 'hlsearch' is zero,
7142 hence all matches with a priority greater than zero will
7143 overrule it. Syntax highlighting (see 'syntax') is a separate
7144 mechanism, and regardless of the chosen priority a match will
7145 always overrule syntax highlighting.
7146
7147 The optional {id} argument allows the request for a specific
7148 match ID. If a specified ID is already taken, an error
7149 message will appear and the match will not be added. An ID
7150 is specified as a positive integer (zero excluded). IDs 1, 2
7151 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007152 respectively. 3 is reserved for use by the |matchparen|
7153 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007154 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007155 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007156
7157 The optional {dict} argument allows for further custom
7158 values. Currently this is used to specify a match specific
7159 conceal character that will be shown for |hl-Conceal|
7160 highlighted matches. The dict can have the following members:
7161
7162 conceal Special character to show instead of the
7163 match (only for |hl-Conceal| highlighted
7164 matches, see |:syn-cchar|)
7165 window Instead of the current window use the
7166 window with this number or window ID.
7167
7168 The number of matches is not limited, as it is the case with
7169 the |:match| commands.
7170
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007171 Returns -1 on error.
7172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007173 Example: >
7174 :highlight MyGroup ctermbg=green guibg=green
7175 :let m = matchadd("MyGroup", "TODO")
7176< Deletion of the pattern: >
7177 :call matchdelete(m)
7178
7179< A list of matches defined by |matchadd()| and |:match| are
7180 available from |getmatches()|. All matches can be deleted in
7181 one operation by |clearmatches()|.
7182
7183 Can also be used as a |method|: >
7184 GetGroup()->matchadd('TODO')
7185<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007186 Return type: |Number|
7187
7188
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007189 *matchaddpos()*
7190matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7191 Same as |matchadd()|, but requires a list of positions {pos}
7192 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007193 because it does not handle regular expressions and it sets
7194 buffer line boundaries to redraw screen. It is supposed to be
7195 used when fast match additions and deletions are required, for
7196 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007197
7198 {pos} is a list of positions. Each position can be one of
7199 these:
7200 - A number. This whole line will be highlighted. The first
7201 line has number 1.
7202 - A list with one number, e.g., [23]. The whole line with this
7203 number will be highlighted.
7204 - A list with two numbers, e.g., [23, 11]. The first number is
7205 the line number, the second one is the column number (first
7206 column is 1, the value must correspond to the byte index as
7207 |col()| would return). The character at this position will
7208 be highlighted.
7209 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7210 the third number gives the length of the highlight in bytes.
7211
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007212 Returns -1 on error.
7213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007214 Example: >
7215 :highlight MyGroup ctermbg=green guibg=green
7216 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7217< Deletion of the pattern: >
7218 :call matchdelete(m)
7219
7220< Matches added by |matchaddpos()| are returned by
7221 |getmatches()|.
7222
7223 Can also be used as a |method|: >
7224 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007225<
7226 Return type: |Number|
7227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007228
7229matcharg({nr}) *matcharg()*
7230 Selects the {nr} match item, as set with a |:match|,
7231 |:2match| or |:3match| command.
7232 Return a |List| with two elements:
7233 The name of the highlight group used
7234 The pattern used.
7235 When {nr} is not 1, 2 or 3 returns an empty |List|.
7236 When there is no match item set returns ['', ''].
7237 This is useful to save and restore a |:match|.
7238 Highlighting matches using the |:match| commands are limited
7239 to three matches. |matchadd()| does not have this limitation.
7240
7241 Can also be used as a |method|: >
7242 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007243<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007244 Return type: list<string>
7245
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007246 *matchbufline()*
7247matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7248 Returns the |List| of matches in lines from {lnum} to {end} in
7249 buffer {buf} where {pat} matches.
7250
7251 {lnum} and {end} can either be a line number or the string "$"
7252 to refer to the last line in {buf}.
7253
7254 The {dict} argument supports following items:
7255 submatches include submatch information (|/\(|)
7256
7257 For each match, a |Dict| with the following items is returned:
7258 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007259 lnum line number where there is a match
7260 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007261 Note that there can be multiple matches in a single line.
7262
7263 This function works only for loaded buffers. First call
7264 |bufload()| if needed.
7265
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007266 See |match-pattern| for information about the effect of some
7267 option settings on the pattern.
7268
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007269 When {buf} is not a valid buffer, the buffer is not loaded or
7270 {lnum} or {end} is not valid then an error is given and an
7271 empty |List| is returned.
7272
7273 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007274 " Assuming line 3 in buffer 5 contains "a"
7275 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7276 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7277 " Assuming line 4 in buffer 10 contains "tik tok"
7278 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7279 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007280<
7281 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007282 "\1", "\2", etc. are also returned. Example: >
7283 " Assuming line 2 in buffer 2 contains "acd"
7284 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007285 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007286 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007287< The "submatches" List always contains 9 items. If a submatch
7288 is not found, then an empty string is returned for that
7289 submatch.
7290
7291 Can also be used as a |method|: >
7292 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007293<
7294 Return type: list<dict<any>> or list<any>
7295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007296
h-east624bb832024-11-09 18:37:32 +01007297matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007298 Deletes a match with ID {id} previously defined by |matchadd()|
7299 or one of the |:match| commands. Returns 0 if successful,
7300 otherwise -1. See example for |matchadd()|. All matches can
7301 be deleted in one operation by |clearmatches()|.
7302 If {win} is specified, use the window with this number or
7303 window ID instead of the current window.
7304
7305 Can also be used as a |method|: >
7306 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007307<
7308 Return type: |Number|
7309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007310
7311matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7312 Same as |match()|, but return the index of first character
7313 after the match. Example: >
7314 :echo matchend("testing", "ing")
7315< results in "7".
7316 *strspn()* *strcspn()*
7317 Vim doesn't have a strspn() or strcspn() function, but you can
7318 do it with matchend(): >
7319 :let span = matchend(line, '[a-zA-Z]')
7320 :let span = matchend(line, '[^a-zA-Z]')
7321< Except that -1 is returned when there are no matches.
7322
7323 The {start}, if given, has the same meaning as for |match()|. >
7324 :echo matchend("testing", "ing", 2)
7325< results in "7". >
7326 :echo matchend("testing", "ing", 5)
7327< result is "-1".
7328 When {expr} is a |List| the result is equal to |match()|.
7329
7330 Can also be used as a |method|: >
7331 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007332<
7333 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007334
7335
7336matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7337 If {list} is a list of strings, then returns a |List| with all
7338 the strings in {list} that fuzzy match {str}. The strings in
7339 the returned list are sorted based on the matching score.
7340
7341 The optional {dict} argument always supports the following
7342 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007343 matchseq When this item is present return only matches
7344 that contain the characters in {str} in the
7345 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007346 limit Maximum number of matches in {list} to be
7347 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007348 camelcase Use enhanced camel case scoring making results
7349 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007350 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007351
7352 If {list} is a list of dictionaries, then the optional {dict}
7353 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007354 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007355 {str}. The value of this item should be a
7356 string.
7357 text_cb |Funcref| that will be called for every item
7358 in {list} to get the text for fuzzy matching.
7359 This should accept a dictionary item as the
7360 argument and return the text for that item to
7361 use for fuzzy matching.
7362
7363 {str} is treated as a literal string and regular expression
7364 matching is NOT supported. The maximum supported {str} length
7365 is 256.
7366
7367 When {str} has multiple words each separated by white space,
7368 then the list of strings that have all the words is returned.
7369
7370 If there are no matching strings or there is an error, then an
7371 empty list is returned. If length of {str} is greater than
7372 256, then returns an empty list.
7373
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007374 When {limit} is given, matchfuzzy() will find up to this
7375 number of matches in {list} and return them in sorted order.
7376
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007377 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007378 matching strings.
7379
7380 Example: >
7381 :echo matchfuzzy(["clay", "crow"], "cay")
7382< results in ["clay"]. >
7383 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7384< results in a list of buffer names fuzzy matching "ndl". >
7385 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7386< results in a list of buffer information dicts with buffer
7387 names fuzzy matching "ndl". >
7388 :echo getbufinfo()->matchfuzzy("spl",
7389 \ {'text_cb' : {v -> v.name}})
7390< results in a list of buffer information dicts with buffer
7391 names fuzzy matching "spl". >
7392 :echo v:oldfiles->matchfuzzy("test")
7393< results in a list of file names fuzzy matching "test". >
7394 :let l = readfile("buffer.c")->matchfuzzy("str")
7395< results in a list of lines in "buffer.c" fuzzy matching "str". >
7396 :echo ['one two', 'two one']->matchfuzzy('two one')
7397< results in ['two one', 'one two']. >
7398 :echo ['one two', 'two one']->matchfuzzy('two one',
7399 \ {'matchseq': 1})
7400< results in ['two one'].
7401
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007402 Return type: list<string> or list<any>
7403
7404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007405matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7406 Same as |matchfuzzy()|, but returns the list of matched
7407 strings, the list of character positions where characters
7408 in {str} matches and a list of matching scores. You can
7409 use |byteidx()| to convert a character position to a byte
7410 position.
7411
7412 If {str} matches multiple times in a string, then only the
7413 positions for the best match is returned.
7414
7415 If there are no matching strings or there is an error, then a
7416 list with three empty list items is returned.
7417
7418 Example: >
7419 :echo matchfuzzypos(['testing'], 'tsg')
7420< results in [['testing'], [[0, 2, 6]], [99]] >
7421 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7422< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7423 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7424< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7425
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007426 Return type: list<list<any>>
7427
7428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007429matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7430 Same as |match()|, but return a |List|. The first item in the
7431 list is the matched string, same as what matchstr() would
7432 return. Following items are submatches, like "\1", "\2", etc.
7433 in |:substitute|. When an optional submatch didn't match an
7434 empty string is used. Example: >
7435 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7436< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7437 When there is no match an empty list is returned.
7438
7439 You can pass in a List, but that is not very useful.
7440
7441 Can also be used as a |method|: >
7442 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007443<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007444 Return type: list<string> or list<any>
7445
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007446 *matchstrlist()*
7447matchstrlist({list}, {pat} [, {dict}])
7448 Returns the |List| of matches in {list} where {pat} matches.
7449 {list} is a |List| of strings. {pat} is matched against each
7450 string in {list}.
7451
7452 The {dict} argument supports following items:
7453 submatches include submatch information (|/\(|)
7454
7455 For each match, a |Dict| with the following items is returned:
7456 byteidx starting byte index of the match.
7457 idx index in {list} of the match.
7458 text matched string
7459 submatches a List of submatches. Present only if
7460 "submatches" is set to v:true in {dict}.
7461
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007462 See |match-pattern| for information about the effect of some
7463 option settings on the pattern.
7464
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007465 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007466 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7467 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7468 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7469 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007470<
7471 If "submatches" is present and is v:true, then submatches like
7472 "\1", "\2", etc. are also returned. Example: >
7473 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7474 \ #{submatches: v:true})
7475 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7476< The "submatches" List always contains 9 items. If a submatch
7477 is not found, then an empty string is returned for that
7478 submatch.
7479
7480 Can also be used as a |method|: >
7481 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007482<
7483 Return type: list<dict<any>> or list<any>
7484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007485
7486matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7487 Same as |match()|, but return the matched string. Example: >
7488 :echo matchstr("testing", "ing")
7489< results in "ing".
7490 When there is no match "" is returned.
7491 The {start}, if given, has the same meaning as for |match()|. >
7492 :echo matchstr("testing", "ing", 2)
7493< results in "ing". >
7494 :echo matchstr("testing", "ing", 5)
7495< result is "".
7496 When {expr} is a |List| then the matching item is returned.
7497 The type isn't changed, it's not necessarily a String.
7498
7499 Can also be used as a |method|: >
7500 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007501<
7502 Return type: |String|
7503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007504
7505matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7506 Same as |matchstr()|, but return the matched string, the start
7507 position and the end position of the match. Example: >
7508 :echo matchstrpos("testing", "ing")
7509< results in ["ing", 4, 7].
7510 When there is no match ["", -1, -1] is returned.
7511 The {start}, if given, has the same meaning as for |match()|. >
7512 :echo matchstrpos("testing", "ing", 2)
7513< results in ["ing", 4, 7]. >
7514 :echo matchstrpos("testing", "ing", 5)
7515< result is ["", -1, -1].
7516 When {expr} is a |List| then the matching item, the index
7517 of first item where {pat} matches, the start position and the
7518 end position of the match are returned. >
7519 :echo matchstrpos([1, '__x'], '\a')
7520< result is ["x", 1, 2, 3].
7521 The type isn't changed, it's not necessarily a String.
7522
7523 Can also be used as a |method|: >
7524 GetText()->matchstrpos('word')
7525<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007526 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007527
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007528
7529max({expr}) *max()*
7530 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007531 echo max([apples, pears, oranges])
7532
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007533< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7534 Dictionary, it returns the maximum of all values in the
7535 Dictionary. If {expr} is neither a List nor a Tuple nor a
7536 Dictionary, or one of the items in {expr} cannot be used as a
7537 Number this results in an error. An empty |List|, |Tuple|
7538 or |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007539
7540 Can also be used as a |method|: >
7541 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007542<
7543 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007544
7545
7546menu_info({name} [, {mode}]) *menu_info()*
7547 Return information about the specified menu {name} in
7548 mode {mode}. The menu name should be specified without the
7549 shortcut character ('&'). If {name} is "", then the top-level
7550 menu names are returned.
7551
7552 {mode} can be one of these strings:
7553 "n" Normal
7554 "v" Visual (including Select)
7555 "o" Operator-pending
7556 "i" Insert
7557 "c" Cmd-line
7558 "s" Select
7559 "x" Visual
7560 "t" Terminal-Job
7561 "" Normal, Visual and Operator-pending
7562 "!" Insert and Cmd-line
7563 When {mode} is omitted, the modes for "" are used.
7564
7565 Returns a |Dictionary| containing the following items:
7566 accel menu item accelerator text |menu-text|
7567 display display name (name without '&')
7568 enabled v:true if this menu item is enabled
7569 Refer to |:menu-enable|
7570 icon name of the icon file (for toolbar)
7571 |toolbar-icon|
7572 iconidx index of a built-in icon
7573 modes modes for which the menu is defined. In
7574 addition to the modes mentioned above, these
7575 characters will be used:
7576 " " Normal, Visual and Operator-pending
7577 name menu item name.
7578 noremenu v:true if the {rhs} of the menu item is not
7579 remappable else v:false.
7580 priority menu order priority |menu-priority|
7581 rhs right-hand-side of the menu item. The returned
7582 string has special characters translated like
7583 in the output of the ":menu" command listing.
7584 When the {rhs} of a menu item is empty, then
7585 "<Nop>" is returned.
7586 script v:true if script-local remapping of {rhs} is
7587 allowed else v:false. See |:menu-script|.
7588 shortcut shortcut key (character after '&' in
7589 the menu name) |menu-shortcut|
7590 silent v:true if the menu item is created
7591 with <silent> argument |:menu-silent|
7592 submenus |List| containing the names of
7593 all the submenus. Present only if the menu
7594 item has submenus.
7595
7596 Returns an empty dictionary if the menu item is not found.
7597
7598 Examples: >
7599 :echo menu_info('Edit.Cut')
7600 :echo menu_info('File.Save', 'n')
7601
7602 " Display the entire menu hierarchy in a buffer
7603 func ShowMenu(name, pfx)
7604 let m = menu_info(a:name)
7605 call append(line('$'), a:pfx .. m.display)
7606 for child in m->get('submenus', [])
7607 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7608 \ a:pfx .. ' ')
7609 endfor
7610 endfunc
7611 new
7612 for topmenu in menu_info('').submenus
7613 call ShowMenu(topmenu, '')
7614 endfor
7615<
7616 Can also be used as a |method|: >
7617 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007618<
7619 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007620
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007621min({expr}) *min()*
7622 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007623 echo min([apples, pears, oranges])
7624
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007625< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7626 Dictionary, it returns the minimum of all values in the
7627 Dictionary. If {expr} is neither a List nor a Tuple nor a
7628 Dictionary, or one of the items in {expr} cannot be used as a
7629 Number this results in an error. An empty |List|, |Tuple| or
7630 |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007631
7632 Can also be used as a |method|: >
7633 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007634<
7635 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007636
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007637
7638mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007639 Create directory {name}.
7640
Bram Moolenaar938ae282023-02-20 20:44:55 +00007641 When {flags} is present it must be a string. An empty string
7642 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007643
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007644 {flags} can contain these character flags:
7645 "p" intermediate directories will be created as necessary
7646 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007647 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007648 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007649 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007650
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007651 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007652 some directories may already exist. Only the first one that
7653 is created and what it contains is scheduled to be deleted.
7654 E.g. when using: >
7655 call mkdir('subdir/tmp/autoload', 'pR')
7656< and "subdir" already exists then "subdir/tmp" will be
7657 scheduled for deletion, like with: >
7658 defer delete('subdir/tmp', 'rf')
7659< Note that if scheduling the defer fails the directory is not
7660 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007661
7662 If {prot} is given it is used to set the protection bits of
7663 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7664 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007665 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007666 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007667 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007668 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007669
7670< This function is not available in the |sandbox|.
7671
7672 There is no error if the directory already exists and the "p"
7673 flag is passed (since patch 8.0.1708). However, without the
7674 "p" option the call will fail.
7675
7676 The function result is a Number, which is TRUE if the call was
7677 successful or FALSE if the directory creation failed or partly
7678 failed.
7679
7680 Not available on all systems. To check use: >
7681 :if exists("*mkdir")
7682
7683< Can also be used as a |method|: >
7684 GetName()->mkdir()
7685<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007686 Return type: |Number|
7687
7688
7689mode([{expr}]) *mode()*
7690 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007691 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007692 a non-empty String (|non-zero-arg|), then the full mode is
7693 returned, otherwise only the first letter is returned.
7694 Also see |state()|.
7695
7696 n Normal
7697 no Operator-pending
7698 nov Operator-pending (forced characterwise |o_v|)
7699 noV Operator-pending (forced linewise |o_V|)
7700 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7701 CTRL-V is one character
7702 niI Normal using |i_CTRL-O| in |Insert-mode|
7703 niR Normal using |i_CTRL-O| in |Replace-mode|
7704 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7705 nt Terminal-Normal (insert goes to Terminal-Job mode)
7706 v Visual by character
7707 vs Visual by character using |v_CTRL-O| in Select mode
7708 V Visual by line
7709 Vs Visual by line using |v_CTRL-O| in Select mode
7710 CTRL-V Visual blockwise
7711 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7712 s Select by character
7713 S Select by line
7714 CTRL-S Select blockwise
7715 i Insert
7716 ic Insert mode completion |compl-generic|
7717 ix Insert mode |i_CTRL-X| completion
7718 R Replace |R|
7719 Rc Replace mode completion |compl-generic|
7720 Rx Replace mode |i_CTRL-X| completion
7721 Rv Virtual Replace |gR|
7722 Rvc Virtual Replace mode completion |compl-generic|
7723 Rvx Virtual Replace mode |i_CTRL-X| completion
7724 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007725 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007726 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007727 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007728 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007729 ce Normal Ex mode |Q|
7730 r Hit-enter prompt
7731 rm The -- more -- prompt
7732 r? A |:confirm| query of some sort
7733 ! Shell or external command is executing
7734 t Terminal-Job mode: keys go to the job
7735
7736 This is useful in the 'statusline' option or when used
7737 with |remote_expr()| In most other places it always returns
7738 "c" or "n".
7739 Note that in the future more modes and more specific modes may
7740 be added. It's better not to compare the whole string but only
7741 the leading character(s).
7742 Also see |visualmode()|.
7743
7744 Can also be used as a |method|: >
7745 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007746<
7747 Return type: |String|
7748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007749
7750mzeval({expr}) *mzeval()*
7751 Evaluate MzScheme expression {expr} and return its result
7752 converted to Vim data structures.
7753 Numbers and strings are returned as they are.
7754 Pairs (including lists and improper lists) and vectors are
7755 returned as Vim |Lists|.
7756 Hash tables are represented as Vim |Dictionary| type with keys
7757 converted to strings.
7758 All other types are converted to string with display function.
7759 Examples: >
7760 :mz (define l (list 1 2 3))
7761 :mz (define h (make-hash)) (hash-set! h "list" l)
7762 :echo mzeval("l")
7763 :echo mzeval("h")
7764<
7765 Note that in a `:def` function local variables are not visible
7766 to {expr}.
7767
7768 Can also be used as a |method|: >
7769 GetExpr()->mzeval()
7770<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007771 Return type: any, depending on {expr}
7772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007773 {only available when compiled with the |+mzscheme| feature}
7774
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007775
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007776nextnonblank({lnum}) *nextnonblank()*
7777 Return the line number of the first line at or below {lnum}
7778 that is not blank. Example: >
7779 if getline(nextnonblank(1)) =~ "Java"
7780< When {lnum} is invalid or there is no non-blank line at or
7781 below it, zero is returned.
7782 {lnum} is used like with |getline()|.
7783 See also |prevnonblank()|.
7784
7785 Can also be used as a |method|: >
7786 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007787<
7788 Return type: |Number|
7789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007790
Christ van Willegenc0786752025-02-01 15:42:16 +01007791ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7792 Return a string that contains the correct value for a
7793 message based on the rules for plural form(s) in
7794 a language. Examples: >
7795 ngettext("File", "Files", 2) # returns "Files"
7796<
7797 Can be used as a |method|: >
7798 1->ngettext("File", "Files") # returns "File"
7799<
7800 See |gettext()| for information on the domain parameter.
7801
7802 Return type: |String|
7803
7804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007805nr2char({expr} [, {utf8}]) *nr2char()*
7806 Return a string with a single character, which has the number
7807 value {expr}. Examples: >
7808 nr2char(64) returns "@"
7809 nr2char(32) returns " "
7810< When {utf8} is omitted or zero, the current 'encoding' is used.
7811 Example for "utf-8": >
7812 nr2char(300) returns I with bow character
7813< When {utf8} is TRUE, always return UTF-8 characters.
7814 Note that a NUL character in the file is specified with
7815 nr2char(10), because NULs are represented with newline
7816 characters. nr2char(0) is a real NUL and terminates the
7817 string, thus results in an empty string.
7818 To turn a list of character numbers into a string: >
7819 let list = [65, 66, 67]
7820 let str = join(map(list, {_, val -> nr2char(val)}), '')
7821< Result: "ABC"
7822
7823 Can also be used as a |method|: >
7824 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007825<
7826 Return type: |String|
7827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007828
7829or({expr}, {expr}) *or()*
7830 Bitwise OR on the two arguments. The arguments are converted
7831 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007832 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007833 Example: >
7834 :let bits = or(bits, 0x80)
7835< Can also be used as a |method|: >
7836 :let bits = bits->or(0x80)
7837
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007838< Rationale: The reason this is a function and not using the "|"
7839 character like many languages, is that Vi has always used "|"
7840 to separate commands. In many places it would not be clear if
7841 "|" is an operator or a command separator.
7842
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007843 Return type: |Number|
7844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007845
7846pathshorten({path} [, {len}]) *pathshorten()*
7847 Shorten directory names in the path {path} and return the
7848 result. The tail, the file name, is kept as-is. The other
7849 components in the path are reduced to {len} letters in length.
7850 If {len} is omitted or smaller than 1 then 1 is used (single
7851 letters). Leading '~' and '.' characters are kept. Examples: >
7852 :echo pathshorten('~/.vim/autoload/myfile.vim')
7853< ~/.v/a/myfile.vim ~
7854>
7855 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7856< ~/.vi/au/myfile.vim ~
7857 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007858 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007859
7860 Can also be used as a |method|: >
7861 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007862<
7863 Return type: |String|
7864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007865
7866perleval({expr}) *perleval()*
7867 Evaluate Perl expression {expr} in scalar context and return
7868 its result converted to Vim data structures. If value can't be
7869 converted, it is returned as a string Perl representation.
7870 Note: If you want an array or hash, {expr} must return a
7871 reference to it.
7872 Example: >
7873 :echo perleval('[1 .. 4]')
7874< [1, 2, 3, 4]
7875
7876 Note that in a `:def` function local variables are not visible
7877 to {expr}.
7878
7879 Can also be used as a |method|: >
7880 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007881<
7882 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007883
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007884 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007885
7886
7887popup_ functions are documented here: |popup-functions|
7888
7889
7890pow({x}, {y}) *pow()*
7891 Return the power of {x} to the exponent {y} as a |Float|.
7892 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007893 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007894 Examples: >
7895 :echo pow(3, 3)
7896< 27.0 >
7897 :echo pow(2, 16)
7898< 65536.0 >
7899 :echo pow(32, 0.20)
7900< 2.0
7901
7902 Can also be used as a |method|: >
7903 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007904<
7905 Return type: |Number|
7906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007907
7908prevnonblank({lnum}) *prevnonblank()*
7909 Return the line number of the first line at or above {lnum}
7910 that is not blank. Example: >
7911 let ind = indent(prevnonblank(v:lnum - 1))
7912< When {lnum} is invalid or there is no non-blank line at or
7913 above it, zero is returned.
7914 {lnum} is used like with |getline()|.
7915 Also see |nextnonblank()|.
7916
7917 Can also be used as a |method|: >
7918 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007919<
7920 Return type: |Number|
7921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007922
7923printf({fmt}, {expr1} ...) *printf()*
7924 Return a String with {fmt}, where "%" items are replaced by
7925 the formatted form of their respective arguments. Example: >
7926 printf("%4d: E%d %.30s", lnum, errno, msg)
7927< May result in:
7928 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7929
7930 When used as a |method| the base is passed as the second
7931 argument: >
7932 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007933<
7934 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007935
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007936 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007937 %s string
7938 %6S string right-aligned in 6 display cells
7939 %6s string right-aligned in 6 bytes
7940 %.9s string truncated to 9 bytes
7941 %c single byte
7942 %d decimal number
7943 %5d decimal number padded with spaces to 5 characters
7944 %x hex number
7945 %04x hex number padded with zeros to at least 4 characters
7946 %X hex number using upper case letters
7947 %o octal number
7948 %08b binary number padded with zeros to at least 8 chars
7949 %f floating point number as 12.23, inf, -inf or nan
7950 %F floating point number as 12.23, INF, -INF or NAN
7951 %e floating point number as 1.23e3, inf, -inf or nan
7952 %E floating point number as 1.23E3, INF, -INF or NAN
7953 %g floating point number, as %f or %e depending on value
7954 %G floating point number, as %F or %E depending on value
7955 %% the % character itself
7956
7957 Conversion specifications start with '%' and end with the
7958 conversion type. All other characters are copied unchanged to
7959 the result.
7960
7961 The "%" starts a conversion specification. The following
7962 arguments appear in sequence:
7963
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007964 % [pos-argument] [flags] [field-width] [.precision] type
7965
7966 pos-argument
7967 At most one positional argument specifier. These
7968 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007969
7970 flags
7971 Zero or more of the following flags:
7972
7973 # The value should be converted to an "alternate
7974 form". For c, d, and s conversions, this option
7975 has no effect. For o conversions, the precision
7976 of the number is increased to force the first
7977 character of the output string to a zero (except
7978 if a zero value is printed with an explicit
7979 precision of zero).
7980 For b and B conversions, a non-zero result has
7981 the string "0b" (or "0B" for B conversions)
7982 prepended to it.
7983 For x and X conversions, a non-zero result has
7984 the string "0x" (or "0X" for X conversions)
7985 prepended to it.
7986
7987 0 (zero) Zero padding. For all conversions the converted
7988 value is padded on the left with zeros rather
7989 than blanks. If a precision is given with a
7990 numeric conversion (d, b, B, o, x, and X), the 0
7991 flag is ignored.
7992
7993 - A negative field width flag; the converted value
7994 is to be left adjusted on the field boundary.
7995 The converted value is padded on the right with
7996 blanks, rather than on the left with blanks or
7997 zeros. A - overrides a 0 if both are given.
7998
7999 ' ' (space) A blank should be left before a positive
8000 number produced by a signed conversion (d).
8001
8002 + A sign must always be placed before a number
8003 produced by a signed conversion. A + overrides
8004 a space if both are used.
8005
8006 field-width
8007 An optional decimal digit string specifying a minimum
8008 field width. If the converted value has fewer bytes
8009 than the field width, it will be padded with spaces on
8010 the left (or right, if the left-adjustment flag has
8011 been given) to fill out the field width. For the S
8012 conversion the count is in cells.
8013
8014 .precision
8015 An optional precision, in the form of a period '.'
8016 followed by an optional digit string. If the digit
8017 string is omitted, the precision is taken as zero.
8018 This gives the minimum number of digits to appear for
8019 d, o, x, and X conversions, the maximum number of
8020 bytes to be printed from a string for s conversions,
8021 or the maximum number of cells to be printed from a
8022 string for S conversions.
8023 For floating point it is the number of digits after
8024 the decimal point.
8025
8026 type
8027 A character that specifies the type of conversion to
8028 be applied, see below.
8029
8030 A field width or precision, or both, may be indicated by an
8031 asterisk '*' instead of a digit string. In this case, a
8032 Number argument supplies the field width or precision. A
8033 negative field width is treated as a left adjustment flag
8034 followed by a positive field width; a negative precision is
8035 treated as though it were missing. Example: >
8036 :echo printf("%d: %.*s", nr, width, line)
8037< This limits the length of the text used from "line" to
8038 "width" bytes.
8039
Dominique Pellé17dca3c2023-12-14 20:36:32 +01008040 If the argument to be formatted is specified using a
8041 positional argument specifier, and a '*' is used to indicate
8042 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008043 precision, the argument(s) to be used must also be specified
8044 using a {n$} positional argument specifier. See |printf-$|.
8045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008046 The conversion specifiers and their meanings are:
8047
8048 *printf-d* *printf-b* *printf-B* *printf-o*
8049 *printf-x* *printf-X*
8050 dbBoxX The Number argument is converted to signed decimal
8051 (d), unsigned binary (b and B), unsigned octal (o), or
8052 unsigned hexadecimal (x and X) notation. The letters
8053 "abcdef" are used for x conversions; the letters
8054 "ABCDEF" are used for X conversions.
8055 The precision, if any, gives the minimum number of
8056 digits that must appear; if the converted value
8057 requires fewer digits, it is padded on the left with
8058 zeros.
8059 In no case does a non-existent or small field width
8060 cause truncation of a numeric field; if the result of
8061 a conversion is wider than the field width, the field
8062 is expanded to contain the conversion result.
8063 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02008064 The 'l' modifier indicates the argument is a long
8065 integer. The size will be 32 bits or 64 bits
8066 depending on your platform.
8067 The "ll" modifier indicates the argument is 64 bits.
8068 The b and B conversion specifiers never take a width
8069 modifier and always assume their argument is a 64 bit
8070 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008071 Generally, these modifiers are not useful. They are
8072 ignored when type is known from the argument.
8073
8074 i alias for d
8075 D alias for ld
8076 U alias for lu
8077 O alias for lo
8078
8079 *printf-c*
8080 c The Number argument is converted to a byte, and the
8081 resulting character is written.
8082
8083 *printf-s*
8084 s The text of the String argument is used. If a
8085 precision is specified, no more bytes than the number
8086 specified are used.
8087 If the argument is not a String type, it is
8088 automatically converted to text with the same format
8089 as ":echo".
8090 *printf-S*
8091 S The text of the String argument is used. If a
8092 precision is specified, no more display cells than the
8093 number specified are used.
8094
8095 *printf-f* *E807*
8096 f F The Float argument is converted into a string of the
8097 form 123.456. The precision specifies the number of
8098 digits after the decimal point. When the precision is
8099 zero the decimal point is omitted. When the precision
8100 is not specified 6 is used. A really big number
8101 (out of range or dividing by zero) results in "inf"
8102 or "-inf" with %f (INF or -INF with %F).
8103 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8104 Example: >
8105 echo printf("%.2f", 12.115)
8106< 12.12
8107 Note that roundoff depends on the system libraries.
8108 Use |round()| when in doubt.
8109
8110 *printf-e* *printf-E*
8111 e E The Float argument is converted into a string of the
8112 form 1.234e+03 or 1.234E+03 when using 'E'. The
8113 precision specifies the number of digits after the
8114 decimal point, like with 'f'.
8115
8116 *printf-g* *printf-G*
8117 g G The Float argument is converted like with 'f' if the
8118 value is between 0.001 (inclusive) and 10000000.0
8119 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8120 for 'G'. When no precision is specified superfluous
8121 zeroes and '+' signs are removed, except for the zero
8122 immediately after the decimal point. Thus 10000000.0
8123 results in 1.0e7.
8124
8125 *printf-%*
8126 % A '%' is written. No argument is converted. The
8127 complete conversion specification is "%%".
8128
8129 When a Number argument is expected a String argument is also
8130 accepted and automatically converted.
8131 When a Float or String argument is expected a Number argument
8132 is also accepted and automatically converted.
8133 Any other argument type results in an error message.
8134
8135 *E766* *E767*
8136 The number of {exprN} arguments must exactly match the number
8137 of "%" items. If there are not sufficient or too many
8138 arguments an error is given. Up to 18 arguments can be used.
8139
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008140 *printf-$*
8141 In certain languages, error and informative messages are
8142 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008143 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008144 having a different word order, positional arguments may be
8145 used to indicate this. For instance: >
8146
h_east596a9f22023-11-21 21:24:23 +09008147 #, c-format
8148 msgid "%s returning %s"
8149 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008150<
h_east596a9f22023-11-21 21:24:23 +09008151 In this example, the sentence has its 2 string arguments
8152 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008153
h_east596a9f22023-11-21 21:24:23 +09008154 echo printf(
8155 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8156 "Bram", "Moolenaar")
8157< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008158
h_east596a9f22023-11-21 21:24:23 +09008159 echo printf(
8160 "In Belgium, vim's creator's name is: %2$s %1$s",
8161 "Bram", "Moolenaar")
8162< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008163
8164 Width (and precision) can be specified using the '*' specifier.
8165 In this case, you must specify the field width position in the
8166 argument list. >
8167
h_east596a9f22023-11-21 21:24:23 +09008168 echo printf("%1$*2$.*3$d", 1, 2, 3)
8169< 001 >
8170 echo printf("%2$*3$.*1$d", 1, 2, 3)
8171< 2 >
8172 echo printf("%3$*1$.*2$d", 1, 2, 3)
8173< 03 >
8174 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8175< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008176
8177 You can mix specifying the width and/or precision directly
8178 and via positional arguments: >
8179
h_east596a9f22023-11-21 21:24:23 +09008180 echo printf("%1$4.*2$f", 1.4142135, 6)
8181< 1.414214 >
8182 echo printf("%1$*2$.4f", 1.4142135, 6)
8183< 1.4142 >
8184 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8185< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008186
Christ van Willegenc35fc032024-03-14 18:30:41 +01008187 You will get an overflow error |E1510|, when the field-width
Hirohito Higashi0ed11ba2025-04-18 18:45:31 +02008188 or precision will result in a string longer than 1 MiB
zeertzjqe9a27ef2025-04-18 10:45:45 +02008189 (1024*1024 = 1048576) chars.
Christ van Willegenc35fc032024-03-14 18:30:41 +01008190
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008191 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008192 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008193 echo printf("%s%1$s", "One", "Two")
8194< E1500: Cannot mix positional and non-positional arguments:
8195 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008196
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008197 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008198 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008199 echo printf("%3$s%1$s", "One", "Two", "Three")
8200< E1501: format argument 2 unused in $-style format:
8201 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008202
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008203 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008204 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008205 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8206< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008207
8208 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008209 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8210< E1502: Positional argument 2 used as field width reused as
8211 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008212
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008213 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008214 When a positional argument is used, but not the correct number
8215 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008216 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8217< E1503: Positional argument 3 out of bounds: %1$d at width
8218 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008219
8220 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008221 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8222< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8223 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008224
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008225 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008226 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008227 echo printf("%1$s %2$s %1$s", "One", "Two")
8228< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008229
8230 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008231 echo printf("%1$s %2$s %1$d", "One", "Two")
8232< E1504: Positional argument 1 type used inconsistently:
8233 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008234
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008235 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008236 Various other errors that lead to a format string being
8237 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008238 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8239< E1505: Invalid format specifier: %1$d at width %2$d is:
8240 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008241
Christ van Willegenea746f92023-10-05 20:48:36 +02008242 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008243 This internal error indicates that the logic to parse a
8244 positional format argument ran into a problem that couldn't be
8245 otherwise reported. Please file a bug against Vim if you run
8246 into this, copying the exact format string and parameters that
8247 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008248
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008249 Return type: |String|
8250
Christ van Willegenea746f92023-10-05 20:48:36 +02008251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008252prompt_getprompt({buf}) *prompt_getprompt()*
8253 Returns the effective prompt text for buffer {buf}. {buf} can
8254 be a buffer name or number. See |prompt-buffer|.
8255
8256 If the buffer doesn't exist or isn't a prompt buffer, an empty
8257 string is returned.
8258
8259 Can also be used as a |method|: >
8260 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008261<
8262 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008263
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008264 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008265
8266
8267prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8268 Set prompt callback for buffer {buf} to {expr}. When {expr}
8269 is an empty string the callback is removed. This has only
8270 effect if {buf} has 'buftype' set to "prompt".
8271
8272 The callback is invoked when pressing Enter. The current
8273 buffer will always be the prompt buffer. A new line for a
8274 prompt is added before invoking the callback, thus the prompt
8275 for which the callback was invoked will be in the last but one
8276 line.
8277 If the callback wants to add text to the buffer, it must
8278 insert it above the last line, since that is where the current
8279 prompt is. This can also be done asynchronously.
8280 The callback is invoked with one argument, which is the text
8281 that was entered at the prompt. This can be an empty string
8282 if the user only typed Enter.
8283 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008284 func s:TextEntered(text)
8285 if a:text == 'exit' || a:text == 'quit'
8286 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008287 " Reset 'modified' to allow the buffer to be closed.
8288 " We assume there is nothing useful to be saved.
8289 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008290 close
8291 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008292 " Do something useful with "a:text". In this example
8293 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008294 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008295 endif
8296 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008297 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008298
8299< Can also be used as a |method|: >
8300 GetBuffer()->prompt_setcallback(callback)
8301
8302< {only available when compiled with the |+channel| feature}
8303
8304prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8305 Set a callback for buffer {buf} to {expr}. When {expr} is an
8306 empty string the callback is removed. This has only effect if
8307 {buf} has 'buftype' set to "prompt".
8308
8309 This callback will be invoked when pressing CTRL-C in Insert
8310 mode. Without setting a callback Vim will exit Insert mode,
8311 as in any buffer.
8312
8313 Can also be used as a |method|: >
8314 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008315<
8316 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008317
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008318 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008319
8320prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8321 Set prompt for buffer {buf} to {text}. You most likely want
8322 {text} to end in a space.
8323 The result is only visible if {buf} has 'buftype' set to
8324 "prompt". Example: >
8325 call prompt_setprompt(bufnr(), 'command: ')
8326<
8327 Can also be used as a |method|: >
8328 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008329<
8330 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008331
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008332 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008333
8334prop_ functions are documented here: |text-prop-functions|
8335
8336pum_getpos() *pum_getpos()*
8337 If the popup menu (see |ins-completion-menu|) is not visible,
8338 returns an empty |Dictionary|, otherwise, returns a
8339 |Dictionary| with the following keys:
8340 height nr of items visible
8341 width screen cells
8342 row top screen row (0 first row)
8343 col leftmost screen column (0 first col)
8344 size total nr of items
8345 scrollbar |TRUE| if scrollbar is visible
8346
8347 The values are the same as in |v:event| during
8348 |CompleteChanged|.
8349
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008350 Return type: dict<any>
8351
8352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008353pumvisible() *pumvisible()*
8354 Returns non-zero when the popup menu is visible, zero
8355 otherwise. See |ins-completion-menu|.
8356 This can be used to avoid some things that would remove the
8357 popup menu.
8358
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008359 Return type: |Number|
8360
8361
zeertzjq7c515282024-11-10 20:26:12 +01008362py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008363 Evaluate Python expression {expr} and return its result
8364 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008365 If a {locals} |Dictionary| is given, it defines set of local
8366 variables available in the expression. The keys are variable
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008367 names and the values are the variable values. |Dictionary|,
8368 |List| and |Tuple| values are referenced, and may be updated
8369 by the expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008370 Numbers and strings are returned as they are (strings are
8371 copied though, Unicode strings are additionally converted to
8372 'encoding').
8373 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008374 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008375 Dictionaries are represented as Vim |Dictionary| type with
8376 keys converted to strings.
8377 Note that in a `:def` function local variables are not visible
8378 to {expr}.
8379
8380 Can also be used as a |method|: >
8381 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008382 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008383<
8384 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008385
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008386 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008387
8388 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008389pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008390 Evaluate Python expression {expr} and return its result
8391 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008392 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008393 Numbers and strings are returned as they are (strings are
8394 copied though).
8395 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008396 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008397 Dictionaries are represented as Vim |Dictionary| type,
8398 non-string keys result in error.
8399 Note that in a `:def` function local variables are not visible
8400 to {expr}.
8401
8402 Can also be used as a |method|: >
8403 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008404<
8405 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008406
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008407 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008408
zeertzjq7c515282024-11-10 20:26:12 +01008409pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008410 Evaluate Python expression {expr} and return its result
8411 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008412 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008413 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8414 See also: |pyeval()|, |py3eval()|
8415
8416 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008417 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008418<
8419 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008420
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008421 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008422 |+python3| feature}
8423
8424rand([{expr}]) *rand()* *random*
8425 Return a pseudo-random Number generated with an xoshiro128**
8426 algorithm using seed {expr}. The returned number is 32 bits,
8427 also on 64 bits systems, for consistency.
8428 {expr} can be initialized by |srand()| and will be updated by
8429 rand(). If {expr} is omitted, an internal seed value is used
8430 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008431 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008432
8433 Examples: >
8434 :echo rand()
8435 :let seed = srand()
8436 :echo rand(seed)
8437 :echo rand(seed) % 16 " random number 0 - 15
8438<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008439 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008440
8441 *E726* *E727*
8442range({expr} [, {max} [, {stride}]]) *range()*
8443 Returns a |List| with Numbers:
8444 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8445 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8446 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8447 {max}] (increasing {expr} with {stride} each time, not
8448 producing a value past {max}).
8449 When the maximum is one before the start the result is an
8450 empty list. When the maximum is more than one before the
8451 start this is an error.
8452 Examples: >
8453 range(4) " [0, 1, 2, 3]
8454 range(2, 4) " [2, 3, 4]
8455 range(2, 9, 3) " [2, 5, 8]
8456 range(2, -2, -1) " [2, 1, 0, -1, -2]
8457 range(0) " []
8458 range(2, 0) " error!
8459<
8460 Can also be used as a |method|: >
8461 GetExpr()->range()
8462<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008463 Return type: list<number>
8464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008465
K.Takata11df3ae2022-10-19 14:02:40 +01008466readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008467 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008468 If {offset} is specified, read the file from the specified
8469 offset. If it is a negative value, it is used as an offset
8470 from the end of the file. E.g., to read the last 12 bytes: >
8471 readblob('file.bin', -12)
8472< If {size} is specified, only the specified size will be read.
8473 E.g. to read the first 100 bytes of a file: >
8474 readblob('file.bin', 0, 100)
8475< If {size} is -1 or omitted, the whole data starting from
8476 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008477 This can be also used to read the data from a character device
8478 on Unix when {size} is explicitly set. Only if the device
8479 supports seeking {offset} can be used. Otherwise it should be
8480 zero. E.g. to read 10 bytes from a serial console: >
8481 readblob('/dev/ttyS0', 0, 10)
8482< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008483 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008484 When the offset is beyond the end of the file the result is an
8485 empty blob.
8486 When trying to read more bytes than are available the result
8487 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008488 Also see |readfile()| and |writefile()|.
8489
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008490 Return type: |Blob|
8491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008492
8493readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8494 Return a list with file and directory names in {directory}.
8495 You can also use |glob()| if you don't need to do complicated
8496 things, such as limiting the number of matches.
8497 The list will be sorted (case sensitive), see the {dict}
8498 argument below for changing the sort order.
8499
8500 When {expr} is omitted all entries are included.
8501 When {expr} is given, it is evaluated to check what to do:
8502 If {expr} results in -1 then no further entries will
8503 be handled.
8504 If {expr} results in 0 then this entry will not be
8505 added to the list.
8506 If {expr} results in 1 then this entry will be added
8507 to the list.
8508 The entries "." and ".." are always excluded.
8509 Each time {expr} is evaluated |v:val| is set to the entry name.
8510 When {expr} is a function the name is passed as the argument.
8511 For example, to get a list of files ending in ".txt": >
8512 readdir(dirname, {n -> n =~ '.txt$'})
8513< To skip hidden and backup files: >
8514 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008515< *E857*
8516 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008517 values. Currently this is used to specify if and how sorting
8518 should be performed. The dict can have the following members:
8519
8520 sort How to sort the result returned from the system.
8521 Valid values are:
8522 "none" do not sort (fastest method)
8523 "case" sort case sensitive (byte value of
8524 each character, technically, using
8525 strcmp()) (default)
8526 "icase" sort case insensitive (technically
8527 using strcasecmp())
8528 "collate" sort using the collation order
8529 of the "POSIX" or "C" |locale|
8530 (technically using strcoll())
8531 Other values are silently ignored.
8532
8533 For example, to get a list of all files in the current
8534 directory without sorting the individual entries: >
8535 readdir('.', '1', #{sort: 'none'})
8536< If you want to get a directory tree: >
8537 function! s:tree(dir)
8538 return {a:dir : map(readdir(a:dir),
8539 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008540 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008541 endfunction
8542 echo s:tree(".")
8543<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008544 Returns an empty List on error.
8545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008546 Can also be used as a |method|: >
8547 GetDirName()->readdir()
8548<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008549 Return type: list<string> or list<any>
8550
8551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008552readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8553 Extended version of |readdir()|.
8554 Return a list of Dictionaries with file and directory
8555 information in {directory}.
8556 This is useful if you want to get the attributes of file and
8557 directory at the same time as getting a list of a directory.
8558 This is much faster than calling |readdir()| then calling
8559 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8560 each file and directory especially on MS-Windows.
8561 The list will by default be sorted by name (case sensitive),
8562 the sorting can be changed by using the optional {dict}
8563 argument, see |readdir()|.
8564
8565 The Dictionary for file and directory information has the
8566 following items:
8567 group Group name of the entry. (Only on Unix)
8568 name Name of the entry.
8569 perm Permissions of the entry. See |getfperm()|.
8570 size Size of the entry. See |getfsize()|.
8571 time Timestamp of the entry. See |getftime()|.
8572 type Type of the entry.
8573 On Unix, almost same as |getftype()| except:
8574 Symlink to a dir "linkd"
8575 Other symlink "link"
8576 On MS-Windows:
8577 Normal file "file"
8578 Directory "dir"
8579 Junction "junction"
8580 Symlink to a dir "linkd"
8581 Other symlink "link"
8582 Other reparse point "reparse"
8583 user User name of the entry's owner. (Only on Unix)
8584 On Unix, if the entry is a symlink, the Dictionary includes
8585 the information of the target (except the "type" item).
8586 On MS-Windows, it includes the information of the symlink
8587 itself because of performance reasons.
8588
8589 When {expr} is omitted all entries are included.
8590 When {expr} is given, it is evaluated to check what to do:
8591 If {expr} results in -1 then no further entries will
8592 be handled.
8593 If {expr} results in 0 then this entry will not be
8594 added to the list.
8595 If {expr} results in 1 then this entry will be added
8596 to the list.
8597 The entries "." and ".." are always excluded.
8598 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8599 of the entry.
8600 When {expr} is a function the entry is passed as the argument.
8601 For example, to get a list of files ending in ".txt": >
8602 readdirex(dirname, {e -> e.name =~ '.txt$'})
8603<
8604 For example, to get a list of all files in the current
8605 directory without sorting the individual entries: >
8606 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008607<
8608 Can also be used as a |method|: >
8609 GetDirName()->readdirex()
8610<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008611 Return type: list<dict<any>> or list<any>
8612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008613
8614 *readfile()*
8615readfile({fname} [, {type} [, {max}]])
8616 Read file {fname} and return a |List|, each line of the file
8617 as an item. Lines are broken at NL characters. Macintosh
8618 files separated with CR will result in a single long line
8619 (unless a NL appears somewhere).
8620 All NUL characters are replaced with a NL character.
8621 When {type} contains "b" binary mode is used:
8622 - When the last line ends in a NL an extra empty list item is
8623 added.
8624 - No CR characters are removed.
8625 Otherwise:
8626 - CR characters that appear before a NL are removed.
8627 - Whether the last line ends in a NL or not does not matter.
8628 - When 'encoding' is Unicode any UTF-8 byte order mark is
8629 removed from the text.
8630 When {max} is given this specifies the maximum number of lines
8631 to be read. Useful if you only want to check the first ten
8632 lines of a file: >
8633 :for line in readfile(fname, '', 10)
8634 : if line =~ 'Date' | echo line | endif
8635 :endfor
8636< When {max} is negative -{max} lines from the end of the file
8637 are returned, or as many as there are.
8638 When {max} is zero the result is an empty list.
8639 Note that without {max} the whole file is read into memory.
8640 Also note that there is no recognition of encoding. Read a
8641 file into a buffer if you need to.
8642 Deprecated (use |readblob()| instead): When {type} contains
8643 "B" a |Blob| is returned with the binary data of the file
8644 unmodified.
8645 When the file can't be opened an error message is given and
8646 the result is an empty list.
8647 Also see |writefile()|.
8648
8649 Can also be used as a |method|: >
8650 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008651<
8652 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008653
8654reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8655 {func} is called for every item in {object}, which can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008656 |String|, |List|, |Tuple| or a |Blob|. {func} is called with
8657 two arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008658 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008659
8660 {initial} is the initial result. When omitted, the first item
8661 in {object} is used and {func} is first called for the second
8662 item. If {initial} is not given and {object} is empty no
8663 result can be computed, an E998 error is given.
8664
8665 Examples: >
8666 echo reduce([1, 3, 5], { acc, val -> acc + val })
8667 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8668 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8669 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8670<
8671 Can also be used as a |method|: >
8672 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008673<
8674 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8675 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008676
8677
8678reg_executing() *reg_executing()*
8679 Returns the single letter name of the register being executed.
8680 Returns an empty string when no register is being executed.
8681 See |@|.
8682
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008683 Return type: |String|
8684
8685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008686reg_recording() *reg_recording()*
8687 Returns the single letter name of the register being recorded.
8688 Returns an empty string when not recording. See |q|.
8689
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008690 Return type: |String|
8691
8692
8693reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008694reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008695reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008696 Return an item that represents a time value. The item is a
8697 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008698 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008700 string or |reltimefloat()| to convert to a Float. For
8701 example, to see the time spent in function Work(): >
8702 var startTime = reltime()
8703 Work()
8704 echo startTime->reltime()->reltimestr()
8705<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008706 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008707 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008708 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008709 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008710 specified in the argument.
8711 With two arguments it returns the time passed between {start}
8712 and {end}.
8713
8714 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008715 reltime(). If there is an error an empty List is returned in
8716 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008717
8718 Can also be used as a |method|: >
8719 GetStart()->reltime()
8720<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008721 Return type: list<number>
8722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008723 {only available when compiled with the |+reltime| feature}
8724
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008726reltimefloat({time}) *reltimefloat()*
8727 Return a Float that represents the time value of {time}.
8728 Example: >
8729 let start = reltime()
8730 call MyFunction()
8731 let seconds = reltimefloat(reltime(start))
8732< See the note of reltimestr() about overhead.
8733 Also see |profiling|.
8734 If there is an error 0.0 is returned in legacy script, in Vim9
8735 script an error is given.
8736
8737 Can also be used as a |method|: >
8738 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008739<
8740 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008741
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008742 {only available when compiled with the |+reltime| feature}
8743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008744
8745reltimestr({time}) *reltimestr()*
8746 Return a String that represents the time value of {time}.
8747 This is the number of seconds, a dot and the number of
8748 microseconds. Example: >
8749 let start = reltime()
8750 call MyFunction()
8751 echo reltimestr(reltime(start))
8752< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008753 The accuracy depends on the system. Use reltimefloat() for the
8754 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008755 Leading spaces are used to make the string align nicely. You
8756 can use split() to remove it. >
8757 echo split(reltimestr(reltime(start)))[0]
8758< Also see |profiling|.
8759 If there is an error an empty string is returned in legacy
8760 script, in Vim9 script an error is given.
8761
8762 Can also be used as a |method|: >
8763 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008764<
8765 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008766
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008767 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008768
8769 *remote_expr()* *E449*
8770remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008771 Send the {string} to {server}. The {server} argument is a
8772 string, also see |{server}|.
8773
8774 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008775 after evaluation. The result must be a String or a |List|
8776 other types will be converted to String. A |List| is turned
8777 into a String by joining the items with a line break in
8778 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008780 If {idvar} is present and not empty, it is taken as the name
8781 of a variable and a {serverid} for later use with
8782 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008784 If {timeout} is given the read times out after this many
8785 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008787 See also |clientserver| |RemoteReply|.
8788 This function is not available in the |sandbox|.
8789 {only available when compiled with the |+clientserver| feature}
8790 Note: Any errors will cause a local error message to be issued
8791 and the result will be the empty string.
8792
8793 Variables will be evaluated in the global namespace,
8794 independent of a function currently being active. Except
8795 when in debug mode, then local function variables and
8796 arguments can be evaluated.
8797
8798 Examples: >
8799 :echo remote_expr("gvim", "2+2")
8800 :echo remote_expr("gvim1", "b:current_syntax")
8801<
8802 Can also be used as a |method|: >
8803 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008804<
8805 Return type: |String| or list<{type}>
8806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008807
8808remote_foreground({server}) *remote_foreground()*
8809 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008810 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008811 This works like: >
8812 remote_expr({server}, "foreground()")
8813< Except that on Win32 systems the client does the work, to work
8814 around the problem that the OS doesn't always allow the server
8815 to bring itself to the foreground.
8816 Note: This does not restore the window if it was minimized,
8817 like foreground() does.
8818 This function is not available in the |sandbox|.
8819
8820 Can also be used as a |method|: >
8821 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008822<
8823 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008824
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008825 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008826 Win32 console version}
8827
8828
8829remote_peek({serverid} [, {retvar}]) *remote_peek()*
8830 Returns a positive number if there are available strings
8831 from {serverid}. Copies any reply string into the variable
8832 {retvar} if specified. {retvar} must be a string with the
8833 name of a variable.
8834 Returns zero if none are available.
8835 Returns -1 if something is wrong.
8836 See also |clientserver|.
8837 This function is not available in the |sandbox|.
8838 {only available when compiled with the |+clientserver| feature}
8839 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008840 :let repl = ""
8841 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008842
8843< Can also be used as a |method|: >
8844 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008845<
8846 Return type: |Number|
8847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008848
8849remote_read({serverid}, [{timeout}]) *remote_read()*
8850 Return the oldest available reply from {serverid} and consume
8851 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008852 reply is available. Returns an empty string, if a reply is
8853 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008854 See also |clientserver|.
8855 This function is not available in the |sandbox|.
8856 {only available when compiled with the |+clientserver| feature}
8857 Example: >
8858 :echo remote_read(id)
8859
8860< Can also be used as a |method|: >
8861 ServerId()->remote_read()
8862<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008863 Return type: |String|
8864
8865
8866remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008867 Send the {string} to {server}. The {server} argument is a
8868 string, also see |{server}|.
8869
8870 The string is sent as input keys and the function returns
8871 immediately. At the Vim server the keys are not mapped
8872 |:map|.
8873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008874 If {idvar} is present, it is taken as the name of a variable
8875 and a {serverid} for later use with remote_read() is stored
8876 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008878 See also |clientserver| |RemoteReply|.
8879 This function is not available in the |sandbox|.
8880 {only available when compiled with the |+clientserver| feature}
8881
8882 Note: Any errors will be reported in the server and may mess
8883 up the display.
8884 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008885 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008886 \ remote_read(serverid)
8887
8888 :autocmd NONE RemoteReply *
8889 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008890 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008891 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8892<
8893 Can also be used as a |method|: >
8894 ServerName()->remote_send(keys)
8895<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008896 Return type: |String|
8897
8898
8899remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008900 Become the server {name}. {name} must be a non-empty string.
8901 This fails if already running as a server, when |v:servername|
8902 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008903
8904 Can also be used as a |method|: >
8905 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008906<
8907 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008908
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008909 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008910
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008911
8912remove({list}, {idx}) *remove()*
8913remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008914 Without {end}: Remove the item at {idx} from |List| {list} and
8915 return the item.
8916 With {end}: Remove items from {idx} to {end} (inclusive) and
8917 return a |List| with these items. When {idx} points to the same
8918 item as {end} a list with one item is returned. When {end}
8919 points to an item before {idx} this is an error.
8920 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008921 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008922 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008923 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008924 :call remove(mylist, 0, 9)
8925<
8926 Use |delete()| to remove a file.
8927
8928 Can also be used as a |method|: >
8929 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008930<
8931 Return type: any, depending on {list}
8932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008933
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008934remove({blob}, {idx})
8935remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008936 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8937 return the byte.
8938 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8939 return a |Blob| with these bytes. When {idx} points to the same
8940 byte as {end} a |Blob| with one byte is returned. When {end}
8941 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008942 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008943 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008944 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008945 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008946<
8947 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008948
8949remove({dict}, {key})
8950 Remove the entry from {dict} with key {key} and return it.
8951 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008952 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008953< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008954 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008955
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008956 Return type: any, depending on {dict}
8957
8958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008959rename({from}, {to}) *rename()*
8960 Rename the file by the name {from} to the name {to}. This
8961 should also work to move files across file systems. The
8962 result is a Number, which is 0 if the file was renamed
8963 successfully, and non-zero when the renaming failed.
8964 NOTE: If {to} exists it is overwritten without warning.
8965 This function is not available in the |sandbox|.
8966
8967 Can also be used as a |method|: >
8968 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008969<
8970 Return type: |Number|
8971
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008972
8973repeat({expr}, {count}) *repeat()*
8974 Repeat {expr} {count} times and return the concatenated
8975 result. Example: >
8976 :let separator = repeat('-', 80)
8977< When {count} is zero or negative the result is empty.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008978 When {expr} is a |List|, a |Tuple| or a |Blob| the result is
8979 {expr} concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008980 :let longlist = repeat(['a', 'b'], 3)
8981< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8982
8983 Can also be used as a |method|: >
8984 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008985<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008986 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
8987 depending on {expr}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008989
8990resolve({filename}) *resolve()* *E655*
8991 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8992 returns the path the shortcut points to in a simplified form.
8993 When {filename} is a symbolic link or junction point, return
8994 the full path to the target. If the target of junction is
8995 removed, return {filename}.
8996 On Unix, repeat resolving symbolic links in all path
8997 components of {filename} and return the simplified result.
8998 To cope with link cycles, resolving of symbolic links is
8999 stopped after 100 iterations.
9000 On other systems, return the simplified {filename}.
9001 The simplification step is done as by |simplify()|.
9002 resolve() keeps a leading path component specifying the
9003 current directory (provided the result is still a relative
9004 path name) and also keeps a trailing path separator.
9005
9006 Can also be used as a |method|: >
9007 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009008<
9009 Return type: |String|
9010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009011
9012reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009013 Reverse the order of items in {object}. {object} can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009014 |List|, a |Tuple|, a |Blob| or a |String|. For a List and a
9015 Blob the items are reversed in-place and {object} is returned.
9016 For a Tuple, a new Tuple is returned.
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009017 For a String a new String is returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009018 Returns zero if {object} is not a List, Tuple, Blob or a
9019 String. If you want a List or Blob to remain unmodified make
9020 a copy first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009021 :let revlist = reverse(copy(mylist))
9022< Can also be used as a |method|: >
9023 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009024<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009025 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
9026 depending on {object}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009028
9029round({expr}) *round()*
9030 Round off {expr} to the nearest integral value and return it
9031 as a |Float|. If {expr} lies halfway between two integral
9032 values, then use the larger one (away from zero).
9033 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009034 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009035 Examples: >
9036 echo round(0.456)
9037< 0.0 >
9038 echo round(4.5)
9039< 5.0 >
9040 echo round(-4.5)
9041< -5.0
9042
9043 Can also be used as a |method|: >
9044 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009045<
9046 Return type: |Float|
9047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009048
9049rubyeval({expr}) *rubyeval()*
9050 Evaluate Ruby expression {expr} and return its result
9051 converted to Vim data structures.
9052 Numbers, floats and strings are returned as they are (strings
9053 are copied though).
9054 Arrays are represented as Vim |List| type.
9055 Hashes are represented as Vim |Dictionary| type.
9056 Other objects are represented as strings resulted from their
9057 "Object#to_s" method.
9058 Note that in a `:def` function local variables are not visible
9059 to {expr}.
9060
9061 Can also be used as a |method|: >
9062 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009063<
9064 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009065
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009066 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009067
9068screenattr({row}, {col}) *screenattr()*
9069 Like |screenchar()|, but return the attribute. This is a rather
9070 arbitrary number that can only be used to compare to the
9071 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009072 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009073
9074 Can also be used as a |method|: >
9075 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009076<
9077 Return type: |Number|
9078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009079
9080screenchar({row}, {col}) *screenchar()*
9081 The result is a Number, which is the character at position
9082 [row, col] on the screen. This works for every possible
9083 screen position, also status lines, window separators and the
9084 command line. The top left position is row one, column one
9085 The character excludes composing characters. For double-byte
9086 encodings it may only be the first byte.
9087 This is mainly to be used for testing.
9088 Returns -1 when row or col is out of range.
9089
9090 Can also be used as a |method|: >
9091 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009092<
9093 Return type: |Number|
9094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009095
9096screenchars({row}, {col}) *screenchars()*
9097 The result is a |List| of Numbers. The first number is the same
9098 as what |screenchar()| returns. Further numbers are
9099 composing characters on top of the base character.
9100 This is mainly to be used for testing.
9101 Returns an empty List when row or col is out of range.
9102
9103 Can also be used as a |method|: >
9104 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009105<
9106 Return type: list<number> or list<any>
9107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009108
9109screencol() *screencol()*
9110 The result is a Number, which is the current screen column of
9111 the cursor. The leftmost column has number 1.
9112 This function is mainly used for testing.
9113
9114 Note: Always returns the current screen column, thus if used
9115 in a command (e.g. ":echo screencol()") it will return the
9116 column inside the command line, which is 1 when the command is
9117 executed. To get the cursor position in the file use one of
9118 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009119 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009120 nnoremap <silent> GG :echom screencol()<CR>
9121 nnoremap GG <Cmd>echom screencol()<CR>
9122<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009123 Return type: |Number|
9124
9125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009126screenpos({winid}, {lnum}, {col}) *screenpos()*
9127 The result is a Dict with the screen position of the text
9128 character in window {winid} at buffer line {lnum} and column
9129 {col}. {col} is a one-based byte index.
9130 The Dict has these members:
9131 row screen row
9132 col first screen column
9133 endcol last screen column
9134 curscol cursor screen column
9135 If the specified position is not visible, all values are zero.
9136 The "endcol" value differs from "col" when the character
9137 occupies more than one screen cell. E.g. for a Tab "col" can
9138 be 1 and "endcol" can be 8.
9139 The "curscol" value is where the cursor would be placed. For
9140 a Tab it would be the same as "endcol", while for a double
9141 width character it would be the same as "col".
9142 The |conceal| feature is ignored here, the column numbers are
9143 as if 'conceallevel' is zero. You can set the cursor to the
9144 right position and use |screencol()| to get the value with
9145 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009146 If the position is in a closed fold the screen position of the
9147 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009148 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009149
9150 Can also be used as a |method|: >
9151 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009152<
9153 Return type: dict<number> or dict<any>
9154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009155
9156screenrow() *screenrow()*
9157 The result is a Number, which is the current screen row of the
9158 cursor. The top line has number one.
9159 This function is mainly used for testing.
9160 Alternatively you can use |winline()|.
9161
9162 Note: Same restrictions as with |screencol()|.
9163
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009164 Return type: |Number|
9165
9166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009167screenstring({row}, {col}) *screenstring()*
9168 The result is a String that contains the base character and
9169 any composing characters at position [row, col] on the screen.
9170 This is like |screenchars()| but returning a String with the
9171 characters.
9172 This is mainly to be used for testing.
9173 Returns an empty String when row or col is out of range.
9174
9175 Can also be used as a |method|: >
9176 GetRow()->screenstring(col)
9177<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009178 Return type: |String|
9179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009180 *search()*
9181search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9182 Search for regexp pattern {pattern}. The search starts at the
9183 cursor position (you can use |cursor()| to set it).
9184
9185 When a match has been found its line number is returned.
9186 If there is no match a 0 is returned and the cursor doesn't
9187 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009188 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009189
9190 {flags} is a String, which can contain these character flags:
9191 'b' search Backward instead of forward
9192 'c' accept a match at the Cursor position
9193 'e' move to the End of the match
9194 'n' do Not move the cursor
9195 'p' return number of matching sub-Pattern (see below)
9196 's' Set the ' mark at the previous location of the cursor
9197 'w' Wrap around the end of the file
9198 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009199 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009200 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9201
9202 If the 's' flag is supplied, the ' mark is set, only if the
9203 cursor is moved. The 's' flag cannot be combined with the 'n'
9204 flag.
9205
9206 'ignorecase', 'smartcase' and 'magic' are used.
9207
9208 When the 'z' flag is not given, forward searching always
9209 starts in column zero and then matches before the cursor are
9210 skipped. When the 'c' flag is present in 'cpo' the next
9211 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009212 search starts one column after the start of the match. This
9213 matters for overlapping matches. See |cpo-c|. You can also
9214 insert "\ze" to change where the match ends, see |/\ze|.
9215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009216 When searching backwards and the 'z' flag is given then the
9217 search starts in column zero, thus no match in the current
9218 line will be found (unless wrapping around the end of the
9219 file).
9220
9221 When the {stopline} argument is given then the search stops
9222 after searching this line. This is useful to restrict the
9223 search to a range of lines. Examples: >
9224 let match = search('(', 'b', line("w0"))
9225 let end = search('END', '', line("w$"))
9226< When {stopline} is used and it is not zero this also implies
9227 that the search does not wrap around the end of the file.
9228 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009229 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009230 When the {timeout} argument is given the search stops when
9231 more than this many milliseconds have passed. Thus when
9232 {timeout} is 500 the search stops after half a second.
9233 The value must not be negative. A zero value is like not
9234 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009235
9236 Note: the timeout is only considered when searching, not
9237 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009238 {only available when compiled with the |+reltime| feature}
9239
9240 If the {skip} expression is given it is evaluated with the
9241 cursor positioned on the start of a match. If it evaluates to
9242 non-zero this match is skipped. This can be used, for
9243 example, to skip a match in a comment or a string.
9244 {skip} can be a string, which is evaluated as an expression, a
9245 function reference or a lambda.
9246 When {skip} is omitted or empty, every match is accepted.
9247 When evaluating {skip} causes an error the search is aborted
9248 and -1 returned.
9249 *search()-sub-match*
9250 With the 'p' flag the returned value is one more than the
9251 first sub-match in \(\). One if none of them matched but the
9252 whole pattern did match.
9253 To get the column number too use |searchpos()|.
9254
9255 The cursor will be positioned at the match, unless the 'n'
9256 flag is used.
9257
9258 Example (goes over all files in the argument list): >
9259 :let n = 1
9260 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009261 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009262 : " start at the last char in the file and wrap for the
9263 : " first search to find match at start of file
9264 : normal G$
9265 : let flags = "w"
9266 : while search("foo", flags) > 0
9267 : s/foo/bar/g
9268 : let flags = "W"
9269 : endwhile
9270 : update " write the file if modified
9271 : let n = n + 1
9272 :endwhile
9273<
9274 Example for using some flags: >
9275 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9276< This will search for the keywords "if", "else", and "endif"
9277 under or after the cursor. Because of the 'p' flag, it
9278 returns 1, 2, or 3 depending on which keyword is found, or 0
9279 if the search fails. With the cursor on the first word of the
9280 line:
9281 if (foo == 0) | let foo = foo + 1 | endif ~
9282 the function returns 1. Without the 'c' flag, the function
9283 finds the "endif" and returns 3. The same thing happens
9284 without the 'e' flag if the cursor is on the "f" of "if".
9285 The 'n' flag tells the function not to move the cursor.
9286
9287 Can also be used as a |method|: >
9288 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009289<
9290 Return type: |Number|
9291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009292
9293searchcount([{options}]) *searchcount()*
9294 Get or update the last search count, like what is displayed
9295 without the "S" flag in 'shortmess'. This works even if
9296 'shortmess' does contain the "S" flag.
9297
9298 This returns a |Dictionary|. The dictionary is empty if the
9299 previous pattern was not set and "pattern" was not specified.
9300
9301 key type meaning ~
9302 current |Number| current position of match;
9303 0 if the cursor position is
9304 before the first match
9305 exact_match |Boolean| 1 if "current" is matched on
9306 "pos", otherwise 0
9307 total |Number| total count of matches found
9308 incomplete |Number| 0: search was fully completed
9309 1: recomputing was timed out
9310 2: max count exceeded
9311
9312 For {options} see further down.
9313
9314 To get the last search count when |n| or |N| was pressed, call
9315 this function with `recompute: 0` . This sometimes returns
9316 wrong information because |n| and |N|'s maximum count is 99.
9317 If it exceeded 99 the result must be max count + 1 (100). If
9318 you want to get correct information, specify `recompute: 1`: >
9319
9320 " result == maxcount + 1 (100) when many matches
9321 let result = searchcount(#{recompute: 0})
9322
9323 " Below returns correct result (recompute defaults
9324 " to 1)
9325 let result = searchcount()
9326<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009327 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009328 function! LastSearchCount() abort
9329 let result = searchcount(#{recompute: 0})
9330 if empty(result)
9331 return ''
9332 endif
9333 if result.incomplete ==# 1 " timed out
9334 return printf(' /%s [?/??]', @/)
9335 elseif result.incomplete ==# 2 " max count exceeded
9336 if result.total > result.maxcount &&
9337 \ result.current > result.maxcount
9338 return printf(' /%s [>%d/>%d]', @/,
9339 \ result.current, result.total)
9340 elseif result.total > result.maxcount
9341 return printf(' /%s [%d/>%d]', @/,
9342 \ result.current, result.total)
9343 endif
9344 endif
9345 return printf(' /%s [%d/%d]', @/,
9346 \ result.current, result.total)
9347 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009348 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009349
9350 " Or if you want to show the count only when
9351 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009352 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009353 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9354<
9355 You can also update the search count, which can be useful in a
9356 |CursorMoved| or |CursorMovedI| autocommand: >
9357
9358 autocmd CursorMoved,CursorMovedI *
9359 \ let s:searchcount_timer = timer_start(
9360 \ 200, function('s:update_searchcount'))
9361 function! s:update_searchcount(timer) abort
9362 if a:timer ==# s:searchcount_timer
9363 call searchcount(#{
9364 \ recompute: 1, maxcount: 0, timeout: 100})
9365 redrawstatus
9366 endif
9367 endfunction
9368<
9369 This can also be used to count matched texts with specified
9370 pattern in the current buffer using "pattern": >
9371
9372 " Count '\<foo\>' in this buffer
9373 " (Note that it also updates search count)
9374 let result = searchcount(#{pattern: '\<foo\>'})
9375
9376 " To restore old search count by old pattern,
9377 " search again
9378 call searchcount()
9379<
9380 {options} must be a |Dictionary|. It can contain:
9381 key type meaning ~
9382 recompute |Boolean| if |TRUE|, recompute the count
9383 like |n| or |N| was executed.
9384 otherwise returns the last
9385 computed result (when |n| or
9386 |N| was used when "S" is not
9387 in 'shortmess', or this
9388 function was called).
9389 (default: |TRUE|)
9390 pattern |String| recompute if this was given
9391 and different with |@/|.
9392 this works as same as the
9393 below command is executed
9394 before calling this function >
9395 let @/ = pattern
9396< (default: |@/|)
9397 timeout |Number| 0 or negative number is no
9398 timeout. timeout milliseconds
9399 for recomputing the result
9400 (default: 0)
9401 maxcount |Number| 0 or negative number is no
9402 limit. max count of matched
9403 text while recomputing the
9404 result. if search exceeded
9405 total count, "total" value
9406 becomes `maxcount + 1`
9407 (default: 99)
9408 pos |List| `[lnum, col, off]` value
9409 when recomputing the result.
9410 this changes "current" result
9411 value. see |cursor()|,
9412 |getpos()|
9413 (default: cursor's position)
9414
9415 Can also be used as a |method|: >
9416 GetSearchOpts()->searchcount()
9417<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009418 Return type: dict<number>
9419
9420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009421searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9422 Search for the declaration of {name}.
9423
9424 With a non-zero {global} argument it works like |gD|, find
9425 first match in the file. Otherwise it works like |gd|, find
9426 first match in the function.
9427
9428 With a non-zero {thisblock} argument matches in a {} block
9429 that ends before the cursor position are ignored. Avoids
9430 finding variable declarations only valid in another scope.
9431
9432 Moves the cursor to the found match.
9433 Returns zero for success, non-zero for failure.
9434 Example: >
9435 if searchdecl('myvar') == 0
9436 echo getline('.')
9437 endif
9438<
9439 Can also be used as a |method|: >
9440 GetName()->searchdecl()
9441<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009442 Return type: |Number|
9443
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009444 *searchpair()*
9445searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9446 [, {stopline} [, {timeout}]]]])
9447 Search for the match of a nested start-end pair. This can be
9448 used to find the "endif" that matches an "if", while other
9449 if/endif pairs in between are ignored.
9450 The search starts at the cursor. The default is to search
9451 forward, include 'b' in {flags} to search backward.
9452 If a match is found, the cursor is positioned at it and the
9453 line number is returned. If no match is found 0 or -1 is
9454 returned and the cursor doesn't move. No error message is
9455 given.
9456
9457 {start}, {middle} and {end} are patterns, see |pattern|. They
9458 must not contain \( \) pairs. Use of \%( \) is allowed. When
9459 {middle} is not empty, it is found when searching from either
9460 direction, but only when not in a nested start-end pair. A
9461 typical use is: >
9462 searchpair('\<if\>', '\<else\>', '\<endif\>')
9463< By leaving {middle} empty the "else" is skipped.
9464
9465 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9466 |search()|. Additionally:
9467 'r' Repeat until no more matches found; will find the
9468 outer pair. Implies the 'W' flag.
9469 'm' Return number of matches instead of line number with
9470 the match; will be > 1 when 'r' is used.
9471 Note: it's nearly always a good idea to use the 'W' flag, to
9472 avoid wrapping around the end of the file.
9473
9474 When a match for {start}, {middle} or {end} is found, the
9475 {skip} expression is evaluated with the cursor positioned on
9476 the start of the match. It should return non-zero if this
9477 match is to be skipped. E.g., because it is inside a comment
9478 or a string.
9479 When {skip} is omitted or empty, every match is accepted.
9480 When evaluating {skip} causes an error the search is aborted
9481 and -1 returned.
9482 {skip} can be a string, a lambda, a funcref or a partial.
9483 Anything else makes the function fail.
9484 In a `:def` function when the {skip} argument is a string
9485 constant it is compiled into instructions.
9486
9487 For {stopline} and {timeout} see |search()|.
9488
9489 The value of 'ignorecase' is used. 'magic' is ignored, the
9490 patterns are used like it's on.
9491
9492 The search starts exactly at the cursor. A match with
9493 {start}, {middle} or {end} at the next character, in the
9494 direction of searching, is the first one found. Example: >
9495 if 1
9496 if 2
9497 endif 2
9498 endif 1
9499< When starting at the "if 2", with the cursor on the "i", and
9500 searching forwards, the "endif 2" is found. When starting on
9501 the character just before the "if 2", the "endif 1" will be
9502 found. That's because the "if 2" will be found first, and
9503 then this is considered to be a nested if/endif from "if 2" to
9504 "endif 2".
9505 When searching backwards and {end} is more than one character,
9506 it may be useful to put "\zs" at the end of the pattern, so
9507 that when the cursor is inside a match with the end it finds
9508 the matching start.
9509
9510 Example, to find the "endif" command in a Vim script: >
9511
9512 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9513 \ 'getline(".") =~ "^\\s*\""')
9514
9515< The cursor must be at or after the "if" for which a match is
9516 to be found. Note that single-quote strings are used to avoid
9517 having to double the backslashes. The skip expression only
9518 catches comments at the start of a line, not after a command.
9519 Also, a word "en" or "if" halfway a line is considered a
9520 match.
9521 Another example, to search for the matching "{" of a "}": >
9522
9523 :echo searchpair('{', '', '}', 'bW')
9524
9525< This works when the cursor is at or before the "}" for which a
9526 match is to be found. To reject matches that syntax
9527 highlighting recognized as strings: >
9528
9529 :echo searchpair('{', '', '}', 'bW',
9530 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9531<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009532 Return type: |Number|
9533
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009534 *searchpairpos()*
9535searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9536 [, {stopline} [, {timeout}]]]])
9537 Same as |searchpair()|, but returns a |List| with the line and
9538 column position of the match. The first element of the |List|
9539 is the line number and the second element is the byte index of
9540 the column position of the match. If no match is found,
9541 returns [0, 0]. >
9542
9543 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9544<
9545 See |match-parens| for a bigger and more useful example.
9546
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009547 Return type: list<number>
9548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009549 *searchpos()*
9550searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9551 Same as |search()|, but returns a |List| with the line and
9552 column position of the match. The first element of the |List|
9553 is the line number and the second element is the byte index of
9554 the column position of the match. If no match is found,
9555 returns [0, 0].
9556 Example: >
9557 :let [lnum, col] = searchpos('mypattern', 'n')
9558
9559< When the 'p' flag is given then there is an extra item with
9560 the sub-pattern match number |search()-sub-match|. Example: >
9561 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9562< In this example "submatch" is 2 when a lowercase letter is
9563 found |/\l|, 3 when an uppercase letter is found |/\u|.
9564
9565 Can also be used as a |method|: >
9566 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009567<
9568 Return type: list<number>
9569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009570
9571server2client({clientid}, {string}) *server2client()*
9572 Send a reply string to {clientid}. The most recent {clientid}
9573 that sent a string can be retrieved with expand("<client>").
9574 {only available when compiled with the |+clientserver| feature}
9575 Returns zero for success, -1 for failure.
9576 Note:
9577 This id has to be stored before the next command can be
9578 received. I.e. before returning from the received command and
9579 before calling any commands that waits for input.
9580 See also |clientserver|.
9581 Example: >
9582 :echo server2client(expand("<client>"), "HELLO")
9583
9584< Can also be used as a |method|: >
9585 GetClientId()->server2client(string)
9586<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009587 Return type: |Number|
9588
9589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009590serverlist() *serverlist()*
9591 Return a list of available server names, one per line.
9592 When there are no servers or the information is not available
9593 an empty string is returned. See also |clientserver|.
9594 {only available when compiled with the |+clientserver| feature}
9595 Example: >
9596 :echo serverlist()
9597<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009598 Return type: |String|
9599
9600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009601setbufline({buf}, {lnum}, {text}) *setbufline()*
9602 Set line {lnum} to {text} in buffer {buf}. This works like
9603 |setline()| for the specified buffer.
9604
9605 This function works only for loaded buffers. First call
9606 |bufload()| if needed.
9607
9608 To insert lines use |appendbufline()|.
9609 Any text properties in {lnum} are cleared.
9610
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009611 {text} can be a string to set one line, or a List of strings
9612 to set multiple lines. If the List extends below the last
9613 line then those lines are added. If the List is empty then
9614 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009615
9616 For the use of {buf}, see |bufname()| above.
9617
9618 {lnum} is used like with |setline()|.
9619 Use "$" to refer to the last line in buffer {buf}.
9620 When {lnum} is just below the last line the {text} will be
9621 added below the last line.
9622
9623 When {buf} is not a valid buffer, the buffer is not loaded or
9624 {lnum} is not valid then 1 is returned. In |Vim9| script an
9625 error is given.
9626 On success 0 is returned.
9627
9628 Can also be used as a |method|, the base is passed as the
9629 third argument: >
9630 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009631<
9632 Return type: |Number|
9633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009634
9635setbufvar({buf}, {varname}, {val}) *setbufvar()*
9636 Set option or local variable {varname} in buffer {buf} to
9637 {val}.
9638 This also works for a global or local window option, but it
9639 doesn't work for a global or local window variable.
9640 For a local window option the global value is unchanged.
9641 For the use of {buf}, see |bufname()| above.
9642 The {varname} argument is a string.
9643 Note that the variable name without "b:" must be used.
9644 Examples: >
9645 :call setbufvar(1, "&mod", 1)
9646 :call setbufvar("todo", "myvar", "foobar")
9647< This function is not available in the |sandbox|.
9648
9649 Can also be used as a |method|, the base is passed as the
9650 third argument: >
9651 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009652<
9653 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009654
9655
9656setcellwidths({list}) *setcellwidths()*
9657 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009658 tells Vim how wide characters are when displayed in the
9659 terminal, counted in screen cells. The values override
9660 'ambiwidth'. Example: >
9661 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009662 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009663 \ [0x2194, 0x2199, 2],
9664 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009665
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009666< The {list} argument is a List of Lists with each three
9667 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9668 {low} and {high} can be the same, in which case this refers to
9669 one character. Otherwise it is the range of characters from
9670 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009671 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009672
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009673 {width} must be either 1 or 2, indicating the character width
9674 in screen cells. *E1112*
9675 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009676 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009678 If the new value causes 'fillchars' or 'listchars' to become
9679 invalid it is rejected and an error is given.
9680
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009681 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009682 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009684< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009685 the effect for known emoji characters. Move the cursor
9686 through the text to check if the cell widths of your terminal
9687 match with what Vim knows about each emoji. If it doesn't
9688 look right you need to adjust the {list} argument.
9689
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009690 Return type: |Number|
9691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009692
9693setcharpos({expr}, {list}) *setcharpos()*
9694 Same as |setpos()| but uses the specified column number as the
9695 character index instead of the byte index in the line.
9696
9697 Example:
9698 With the text "여보세요" in line 8: >
9699 call setcharpos('.', [0, 8, 4, 0])
9700< positions the cursor on the fourth character '요'. >
9701 call setpos('.', [0, 8, 4, 0])
9702< positions the cursor on the second character '보'.
9703
9704 Can also be used as a |method|: >
9705 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009706<
9707 Return type: |Number|
9708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009709
9710setcharsearch({dict}) *setcharsearch()*
9711 Set the current character search information to {dict},
9712 which contains one or more of the following entries:
9713
9714 char character which will be used for a subsequent
9715 |,| or |;| command; an empty string clears the
9716 character search
9717 forward direction of character search; 1 for forward,
9718 0 for backward
9719 until type of character search; 1 for a |t| or |T|
9720 character search, 0 for an |f| or |F|
9721 character search
9722
9723 This can be useful to save/restore a user's character search
9724 from a script: >
9725 :let prevsearch = getcharsearch()
9726 :" Perform a command which clobbers user's search
9727 :call setcharsearch(prevsearch)
9728< Also see |getcharsearch()|.
9729
9730 Can also be used as a |method|: >
9731 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009732<
9733 Return type: dict<any>
9734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009735
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009736setcmdline({str} [, {pos}]) *setcmdline()*
9737 Set the command line to {str} and set the cursor position to
9738 {pos}.
9739 If {pos} is omitted, the cursor is positioned after the text.
9740 Returns 0 when successful, 1 when not editing the command
9741 line.
9742
9743 Can also be used as a |method|: >
9744 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009745<
9746 Return type: |Number|
9747
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009749setcmdpos({pos}) *setcmdpos()*
9750 Set the cursor position in the command line to byte position
9751 {pos}. The first position is 1.
9752 Use |getcmdpos()| to obtain the current position.
9753 Only works while editing the command line, thus you must use
9754 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9755 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9756 set after the command line is set to the expression. For
9757 |c_CTRL-R_=| it is set after evaluating the expression but
9758 before inserting the resulting text.
9759 When the number is too big the cursor is put at the end of the
9760 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009761 Returns 0 when successful, 1 when not editing the command
9762 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009763
9764 Can also be used as a |method|: >
9765 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009766<
9767 Return type: |Number|
9768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009769
9770setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9771setcursorcharpos({list})
9772 Same as |cursor()| but uses the specified column number as the
9773 character index instead of the byte index in the line.
9774
9775 Example:
9776 With the text "여보세요" in line 4: >
9777 call setcursorcharpos(4, 3)
9778< positions the cursor on the third character '세'. >
9779 call cursor(4, 3)
9780< positions the cursor on the first character '여'.
9781
9782 Can also be used as a |method|: >
9783 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009784<
9785 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009786
9787
9788setenv({name}, {val}) *setenv()*
9789 Set environment variable {name} to {val}. Example: >
9790 call setenv('HOME', '/home/myhome')
9791
9792< When {val} is |v:null| the environment variable is deleted.
9793 See also |expr-env|.
9794
9795 Can also be used as a |method|, the base is passed as the
9796 second argument: >
9797 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009798<
9799 Return type: |Number|
9800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009801
9802setfperm({fname}, {mode}) *setfperm()* *chmod*
9803 Set the file permissions for {fname} to {mode}.
9804 {mode} must be a string with 9 characters. It is of the form
9805 "rwxrwxrwx", where each group of "rwx" flags represent, in
9806 turn, the permissions of the owner of the file, the group the
9807 file belongs to, and other users. A '-' character means the
9808 permission is off, any other character means on. Multi-byte
9809 characters are not supported.
9810
9811 For example "rw-r-----" means read-write for the user,
9812 readable by the group, not accessible by others. "xx-x-----"
9813 would do the same thing.
9814
9815 Returns non-zero for success, zero for failure.
9816
9817 Can also be used as a |method|: >
9818 GetFilename()->setfperm(mode)
9819<
9820 To read permissions see |getfperm()|.
9821
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009822 Return type: |Number|
9823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009824
9825setline({lnum}, {text}) *setline()*
9826 Set line {lnum} of the current buffer to {text}. To insert
9827 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009828 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009829 Any text properties in {lnum} are cleared. See
9830 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009831
9832 {lnum} is used like with |getline()|.
9833 When {lnum} is just below the last line the {text} will be
9834 added below the last line.
9835 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009836 converted to a String. When {text} is an empty List then
9837 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009838
9839 If this succeeds, FALSE is returned. If this fails (most likely
9840 because {lnum} is invalid) TRUE is returned.
9841 In |Vim9| script an error is given if {lnum} is invalid.
9842
9843 Example: >
9844 :call setline(5, strftime("%c"))
9845
9846< When {text} is a |List| then line {lnum} and following lines
9847 will be set to the items in the list. Example: >
9848 :call setline(5, ['aaa', 'bbb', 'ccc'])
9849< This is equivalent to: >
9850 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9851 : call setline(n, l)
9852 :endfor
9853
9854< Note: The '[ and '] marks are not set.
9855
9856 Can also be used as a |method|, the base is passed as the
9857 second argument: >
9858 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009859<
9860 Return type: |Number|
9861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009862
9863setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9864 Create or replace or add to the location list for window {nr}.
9865 {nr} can be the window number or the |window-ID|.
9866 When {nr} is zero the current window is used.
9867
9868 For a location list window, the displayed location list is
9869 modified. For an invalid window number {nr}, -1 is returned.
9870 Otherwise, same as |setqflist()|.
9871 Also see |location-list|.
9872
9873 For {action} see |setqflist-action|.
9874
9875 If the optional {what} dictionary argument is supplied, then
9876 only the items listed in {what} are set. Refer to |setqflist()|
9877 for the list of supported keys in {what}.
9878
9879 Can also be used as a |method|, the base is passed as the
9880 second argument: >
9881 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009882<
9883 Return type: |Number|
9884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009885
9886setmatches({list} [, {win}]) *setmatches()*
9887 Restores a list of matches saved by |getmatches()| for the
9888 current window. Returns 0 if successful, otherwise -1. All
9889 current matches are cleared before the list is restored. See
9890 example for |getmatches()|.
9891 If {win} is specified, use the window with this number or
9892 window ID instead of the current window.
9893
9894 Can also be used as a |method|: >
9895 GetMatches()->setmatches()
9896<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009897 Return type: |Number|
9898
9899
9900setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009901 Set the position for String {expr}. Possible values:
9902 . the cursor
9903 'x mark x
9904
9905 {list} must be a |List| with four or five numbers:
9906 [bufnum, lnum, col, off]
9907 [bufnum, lnum, col, off, curswant]
9908
9909 "bufnum" is the buffer number. Zero can be used for the
9910 current buffer. When setting an uppercase mark "bufnum" is
9911 used for the mark position. For other marks it specifies the
9912 buffer to set the mark in. You can use the |bufnr()| function
9913 to turn a file name into a buffer number.
9914 For setting the cursor and the ' mark "bufnum" is ignored,
9915 since these are associated with a window, not a buffer.
9916 Does not change the jumplist.
9917
9918 "lnum" and "col" are the position in the buffer. The first
9919 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9920 smaller than 1 then 1 is used. To use the character count
9921 instead of the byte count, use |setcharpos()|.
9922
9923 The "off" number is only used when 'virtualedit' is set. Then
9924 it is the offset in screen columns from the start of the
9925 character. E.g., a position within a <Tab> or after the last
9926 character.
9927
9928 The "curswant" number is only used when setting the cursor
9929 position. It sets the preferred column for when moving the
9930 cursor vertically. When the "curswant" number is missing the
9931 preferred column is not set. When it is present and setting a
9932 mark position it is not used.
9933
9934 Note that for '< and '> changing the line number may result in
9935 the marks to be effectively be swapped, so that '< is always
9936 before '>.
9937
9938 Returns 0 when the position could be set, -1 otherwise.
9939 An error message is given if {expr} is invalid.
9940
9941 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9942
9943 This does not restore the preferred column for moving
9944 vertically; if you set the cursor position with this, |j| and
9945 |k| motions will jump to previous columns! Use |cursor()| to
9946 also set the preferred column. Also see the "curswant" key in
9947 |winrestview()|.
9948
9949 Can also be used as a |method|: >
9950 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009951<
9952 Return type: |Number|
9953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009954
9955setqflist({list} [, {action} [, {what}]]) *setqflist()*
9956 Create or replace or add to the quickfix list.
9957
9958 If the optional {what} dictionary argument is supplied, then
9959 only the items listed in {what} are set. The first {list}
9960 argument is ignored. See below for the supported items in
9961 {what}.
9962 *setqflist-what*
9963 When {what} is not present, the items in {list} are used. Each
9964 item must be a dictionary. Non-dictionary items in {list} are
9965 ignored. Each dictionary item can contain the following
9966 entries:
9967
9968 bufnr buffer number; must be the number of a valid
9969 buffer
9970 filename name of a file; only used when "bufnr" is not
9971 present or it is invalid.
9972 module name of a module; if given it will be used in
9973 quickfix error window instead of the filename.
9974 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009975 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009976 pattern search pattern used to locate the error
9977 col column number
9978 vcol when non-zero: "col" is visual column
9979 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009980 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009981 nr error number
9982 text description of the error
9983 type single-character error type, 'E', 'W', etc.
9984 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009985 user_data custom data associated with the item, can be
9986 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009987
9988 The "col", "vcol", "nr", "type" and "text" entries are
9989 optional. Either "lnum" or "pattern" entry can be used to
9990 locate a matching error line.
9991 If the "filename" and "bufnr" entries are not present or
9992 neither the "lnum" or "pattern" entries are present, then the
9993 item will not be handled as an error line.
9994 If both "pattern" and "lnum" are present then "pattern" will
9995 be used.
9996 If the "valid" entry is not supplied, then the valid flag is
9997 set when "bufnr" is a valid buffer or "filename" exists.
9998 If you supply an empty {list}, the quickfix list will be
9999 cleared.
10000 Note that the list is not exactly the same as what
10001 |getqflist()| returns.
10002
10003 {action} values: *setqflist-action* *E927*
10004 'a' The items from {list} are added to the existing
10005 quickfix list. If there is no existing list, then a
10006 new list is created.
10007
10008 'r' The items from the current quickfix list are replaced
10009 with the items from {list}. This can also be used to
10010 clear the list: >
10011 :call setqflist([], 'r')
10012<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +020010013 'u' Like 'r', but tries to preserve the current selection
10014 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010015 'f' All the quickfix lists in the quickfix stack are
10016 freed.
10017
10018 If {action} is not present or is set to ' ', then a new list
10019 is created. The new quickfix list is added after the current
10020 quickfix list in the stack and all the following lists are
10021 freed. To add a new quickfix list at the end of the stack,
10022 set "nr" in {what} to "$".
10023
10024 The following items can be specified in dictionary {what}:
10025 context quickfix list context. See |quickfix-context|
10026 efm errorformat to use when parsing text from
10027 "lines". If this is not present, then the
10028 'errorformat' option value is used.
10029 See |quickfix-parse|
10030 id quickfix list identifier |quickfix-ID|
10031 idx index of the current entry in the quickfix
10032 list specified by 'id' or 'nr'. If set to '$',
10033 then the last entry in the list is set as the
10034 current entry. See |quickfix-index|
10035 items list of quickfix entries. Same as the {list}
10036 argument.
10037 lines use 'errorformat' to parse a list of lines and
10038 add the resulting entries to the quickfix list
10039 {nr} or {id}. Only a |List| value is supported.
10040 See |quickfix-parse|
10041 nr list number in the quickfix stack; zero
10042 means the current quickfix list and "$" means
10043 the last quickfix list.
10044 quickfixtextfunc
10045 function to get the text to display in the
10046 quickfix window. The value can be the name of
10047 a function or a funcref or a lambda. Refer to
10048 |quickfix-window-function| for an explanation
10049 of how to write the function and an example.
10050 title quickfix list title text. See |quickfix-title|
10051 Unsupported keys in {what} are ignored.
10052 If the "nr" item is not present, then the current quickfix list
10053 is modified. When creating a new quickfix list, "nr" can be
10054 set to a value one greater than the quickfix stack size.
10055 When modifying a quickfix list, to guarantee that the correct
10056 list is modified, "id" should be used instead of "nr" to
10057 specify the list.
10058
10059 Examples (See also |setqflist-examples|): >
10060 :call setqflist([], 'r', {'title': 'My search'})
10061 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
10062 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
10063<
10064 Returns zero for success, -1 for failure.
10065
10066 This function can be used to create a quickfix list
10067 independent of the 'errorformat' setting. Use a command like
10068 `:cc 1` to jump to the first position.
10069
10070 Can also be used as a |method|, the base is passed as the
10071 second argument: >
10072 GetErrorlist()->setqflist()
10073<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010074 Return type: |Number|
10075
10076
10077setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010078 Set the register {regname} to {value}.
10079 If {regname} is "" or "@", the unnamed register '"' is used.
10080 The {regname} argument is a string. In |Vim9-script|
10081 {regname} must be one character.
10082
10083 {value} may be any value returned by |getreg()| or
10084 |getreginfo()|, including a |List| or |Dict|.
10085 If {options} contains "a" or {regname} is upper case,
10086 then the value is appended.
10087
10088 {options} can also contain a register type specification:
10089 "c" or "v" |characterwise| mode
10090 "l" or "V" |linewise| mode
10091 "b" or "<CTRL-V>" |blockwise-visual| mode
10092 If a number immediately follows "b" or "<CTRL-V>" then this is
10093 used as the width of the selection - if it is not specified
10094 then the width of the block is set to the number of characters
10095 in the longest line (counting a <Tab> as 1 character).
10096
10097 If {options} contains no register settings, then the default
10098 is to use character mode unless {value} ends in a <NL> for
10099 string {value} and linewise mode for list {value}. Blockwise
10100 mode is never selected automatically.
10101 Returns zero for success, non-zero for failure.
10102
10103 *E883*
10104 Note: you may not use |List| containing more than one item to
10105 set search and expression registers. Lists containing no
10106 items act like empty strings.
10107
10108 Examples: >
10109 :call setreg(v:register, @*)
10110 :call setreg('*', @%, 'ac')
10111 :call setreg('a', "1\n2\n3", 'b5')
10112 :call setreg('"', { 'points_to': 'a'})
10113
10114< This example shows using the functions to save and restore a
10115 register: >
10116 :let var_a = getreginfo()
10117 :call setreg('a', var_a)
10118< or: >
10119 :let var_a = getreg('a', 1, 1)
10120 :let var_amode = getregtype('a')
10121 ....
10122 :call setreg('a', var_a, var_amode)
10123< Note: you may not reliably restore register value
10124 without using the third argument to |getreg()| as without it
10125 newlines are represented as newlines AND Nul bytes are
10126 represented as newlines as well, see |NL-used-for-Nul|.
10127
10128 You can also change the type of a register by appending
10129 nothing: >
10130 :call setreg('a', '', 'al')
10131
10132< Can also be used as a |method|, the base is passed as the
10133 second argument: >
10134 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010135<
10136 Return type: |Number|
10137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010138
10139settabvar({tabnr}, {varname}, {val}) *settabvar()*
10140 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10141 |t:var|
10142 The {varname} argument is a string.
10143 Note that autocommands are blocked, side effects may not be
10144 triggered, e.g. when setting 'filetype'.
10145 Note that the variable name without "t:" must be used.
10146 Tabs are numbered starting with one.
10147 This function is not available in the |sandbox|.
10148
10149 Can also be used as a |method|, the base is passed as the
10150 third argument: >
10151 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010152<
10153 Return type: |Number|
10154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010155
10156settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10157 Set option or local variable {varname} in window {winnr} to
10158 {val}.
10159 Tabs are numbered starting with one. For the current tabpage
10160 use |setwinvar()|.
10161 {winnr} can be the window number or the |window-ID|.
10162 When {winnr} is zero the current window is used.
10163 Note that autocommands are blocked, side effects may not be
10164 triggered, e.g. when setting 'filetype' or 'syntax'.
10165 This also works for a global or local buffer option, but it
10166 doesn't work for a global or local buffer variable.
10167 For a local buffer option the global value is unchanged.
10168 Note that the variable name without "w:" must be used.
10169 Examples: >
10170 :call settabwinvar(1, 1, "&list", 0)
10171 :call settabwinvar(3, 2, "myvar", "foobar")
10172< This function is not available in the |sandbox|.
10173
10174 Can also be used as a |method|, the base is passed as the
10175 fourth argument: >
10176 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010177<
10178 Return type: |Number|
10179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010180
10181settagstack({nr}, {dict} [, {action}]) *settagstack()*
10182 Modify the tag stack of the window {nr} using {dict}.
10183 {nr} can be the window number or the |window-ID|.
10184
10185 For a list of supported items in {dict}, refer to
10186 |gettagstack()|. "curidx" takes effect before changing the tag
10187 stack.
10188 *E962*
10189 How the tag stack is modified depends on the {action}
10190 argument:
10191 - If {action} is not present or is set to 'r', then the tag
10192 stack is replaced.
10193 - If {action} is set to 'a', then new entries from {dict} are
10194 pushed (added) onto the tag stack.
10195 - If {action} is set to 't', then all the entries from the
10196 current entry in the tag stack or "curidx" in {dict} are
10197 removed and then new entries are pushed to the stack.
10198
10199 The current index is set to one after the length of the tag
10200 stack after the modification.
10201
10202 Returns zero for success, -1 for failure.
10203
10204 Examples (for more examples see |tagstack-examples|):
10205 Empty the tag stack of window 3: >
10206 call settagstack(3, {'items' : []})
10207
10208< Save and restore the tag stack: >
10209 let stack = gettagstack(1003)
10210 " do something else
10211 call settagstack(1003, stack)
10212 unlet stack
10213<
10214 Can also be used as a |method|, the base is passed as the
10215 second argument: >
10216 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010217<
10218 Return type: |Number|
10219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010220
10221setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10222 Like |settabwinvar()| for the current tab page.
10223 Examples: >
10224 :call setwinvar(1, "&list", 0)
10225 :call setwinvar(2, "myvar", "foobar")
10226
10227< Can also be used as a |method|, the base is passed as the
10228 third argument: >
10229 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010230<
10231 Return type: |Number|
10232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010233
10234sha256({string}) *sha256()*
10235 Returns a String with 64 hex characters, which is the SHA256
10236 checksum of {string}.
10237
10238 Can also be used as a |method|: >
10239 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010240<
10241 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010242
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010243 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010244
10245shellescape({string} [, {special}]) *shellescape()*
10246 Escape {string} for use as a shell command argument.
10247 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010248 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010249 in single quotes and will double up all internal single
10250 quotes.
10251 On MS-Windows, when 'shellslash' is not set, it will enclose
10252 {string} in double quotes and double all double quotes within
10253 {string}.
10254 Otherwise it will enclose {string} in single quotes and
10255 replace all "'" with "'\''".
10256
Enno5faeb602024-05-15 21:54:19 +020010257 The {special} argument adds additional escaping of keywords
10258 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010259 number or a non-empty String (|non-zero-arg|), then special
10260 items such as "!", "%", "#" and "<cword>" (as listed in
10261 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010262 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010263
10264 The "!" character will be escaped (again with a |non-zero-arg|
10265 {special}) when 'shell' contains "csh" in the tail. That is
10266 because for csh and tcsh "!" is used for history replacement
10267 even when inside single quotes.
10268
10269 With a |non-zero-arg| {special} the <NL> character is also
10270 escaped. When 'shell' containing "csh" in the tail it's
10271 escaped a second time.
10272
10273 The "\" character will be escaped when 'shell' contains "fish"
10274 in the tail. That is because for fish "\" is used as an escape
10275 character inside single quotes.
10276
10277 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010278 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010279< This results in a directory listing for the file under the
10280 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010281 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010282< See also |::S|.
10283
10284 Can also be used as a |method|: >
10285 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010286<
10287 Return type: |String|
10288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010289
10290shiftwidth([{col}]) *shiftwidth()*
10291 Returns the effective value of 'shiftwidth'. This is the
10292 'shiftwidth' value unless it is zero, in which case it is the
10293 'tabstop' value. This function was introduced with patch
10294 7.3.694 in 2012, everybody should have it by now (however it
10295 did not allow for the optional {col} argument until 8.1.542).
10296
10297 When there is one argument {col} this is used as column number
10298 for which to return the 'shiftwidth' value. This matters for the
10299 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10300 no {col} argument is given, column 1 will be assumed.
10301
10302 Can also be used as a |method|: >
10303 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010304<
10305 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010306
10307sign_ functions are documented here: |sign-functions-details|
10308
10309
10310simplify({filename}) *simplify()*
10311 Simplify the file name as much as possible without changing
10312 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10313 Unix) are not resolved. If the first path component in
10314 {filename} designates the current directory, this will be
10315 valid for the result as well. A trailing path separator is
10316 not removed either. On Unix "//path" is unchanged, but
10317 "///path" is simplified to "/path" (this follows the Posix
10318 standard).
10319 Example: >
10320 simplify("./dir/.././/file/") == "./file/"
10321< Note: The combination "dir/.." is only removed if "dir" is
10322 a searchable directory or does not exist. On Unix, it is also
10323 removed when "dir" is a symbolic link within the same
10324 directory. In order to resolve all the involved symbolic
10325 links before simplifying the path name, use |resolve()|.
10326
10327 Can also be used as a |method|: >
10328 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010329<
10330 Return type: |String|
10331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010332
10333sin({expr}) *sin()*
10334 Return the sine of {expr}, measured in radians, as a |Float|.
10335 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010336 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010337 Examples: >
10338 :echo sin(100)
10339< -0.506366 >
10340 :echo sin(-4.01)
10341< 0.763301
10342
10343 Can also be used as a |method|: >
10344 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010345<
10346 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010347
10348
10349sinh({expr}) *sinh()*
10350 Return the hyperbolic sine of {expr} as a |Float| in the range
10351 [-inf, inf].
10352 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010353 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010354 Examples: >
10355 :echo sinh(0.5)
10356< 0.521095 >
10357 :echo sinh(-0.9)
10358< -1.026517
10359
10360 Can also be used as a |method|: >
10361 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010362<
10363 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010364
10365
10366slice({expr}, {start} [, {end}]) *slice()*
10367 Similar to using a |slice| "expr[start : end]", but "end" is
10368 used exclusive. And for a string the indexes are used as
10369 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010370 |vim9script|. Also, composing characters are treated as a
10371 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010372 When {end} is omitted the slice continues to the last item.
10373 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010374 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010375
10376 Can also be used as a |method|: >
10377 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010378<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010379 Return type: list<{type}> or tuple<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010380
10381
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010382sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010383 Sort the items in {list} in-place. Returns {list}.
10384
10385 If you want a list to remain unmodified make a copy first: >
10386 :let sortedlist = sort(copy(mylist))
10387
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010388< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010389 string representation of each item to sort on. Numbers sort
10390 after Strings, |Lists| after Numbers. For sorting text in the
10391 current buffer use |:sort|.
10392
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010393 When {how} is given and it is 'i' then case is ignored.
10394 In legacy script, for backwards compatibility, the value one
10395 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010396
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010397 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398 locale is used for ordering. Implementation details: strcoll()
10399 is used to compare strings. See |:language| check or set the
10400 collation locale. |v:collate| can also be used to check the
10401 current locale. Sorting using the locale typically ignores
10402 case. Example: >
10403 " ö is sorted similarly to o with English locale.
10404 :language collate en_US.UTF8
10405 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10406< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10407>
10408 " ö is sorted after z with Swedish locale.
10409 :language collate sv_SE.UTF8
10410 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10411< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10412 This does not work properly on Mac.
10413
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010414 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010415 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010416 strtod() function to parse numbers. Strings, Lists, Dicts and
10417 Funcrefs will be considered as being 0). Note that this won't
10418 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010419
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010420 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010421 sorted numerical. This is like 'n' but a string containing
10422 digits will be used as the number they represent.
10423
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010424 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010425 sorted numerical. All values must be a Number or a Float.
10426
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010427 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010428 is called to compare items. The function is invoked with two
10429 items as argument and must return zero if they are equal, 1 or
10430 bigger if the first one sorts after the second one, -1 or
10431 smaller if the first one sorts before the second one.
10432
10433 {dict} is for functions with the "dict" attribute. It will be
10434 used to set the local variable "self". |Dictionary-function|
10435
10436 The sort is stable, items which compare equal (as number or as
10437 string) will keep their relative position. E.g., when sorting
10438 on numbers, text strings will sort next to each other, in the
10439 same order as they were originally.
10440
10441 Can also be used as a |method|: >
10442 mylist->sort()
10443
10444< Also see |uniq()|.
10445
10446 Example: >
10447 func MyCompare(i1, i2)
10448 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10449 endfunc
10450 eval mylist->sort("MyCompare")
10451< A shorter compare version for this specific simple case, which
10452 ignores overflow: >
10453 func MyCompare(i1, i2)
10454 return a:i1 - a:i2
10455 endfunc
10456< For a simple expression you can use a lambda: >
10457 eval mylist->sort({i1, i2 -> i1 - i2})
10458<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010459 Return type: list<{type}>
10460
10461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010462sound_clear() *sound_clear()*
10463 Stop playing all sounds.
10464
10465 On some Linux systems you may need the libcanberra-pulse
10466 package, otherwise sound may not stop.
10467
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010468 Return type: |Number|
10469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010470 {only available when compiled with the |+sound| feature}
10471
10472 *sound_playevent()*
10473sound_playevent({name} [, {callback}])
10474 Play a sound identified by {name}. Which event names are
10475 supported depends on the system. Often the XDG sound names
10476 are used. On Ubuntu they may be found in
10477 /usr/share/sounds/freedesktop/stereo. Example: >
10478 call sound_playevent('bell')
10479< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10480 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10481 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010482 On macOS, {name} refers to files located in
10483 /System/Library/Sounds (e.g. "Tink"). It will also work for
10484 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010485
10486 When {callback} is specified it is invoked when the sound is
10487 finished. The first argument is the sound ID, the second
10488 argument is the status:
10489 0 sound was played to the end
10490 1 sound was interrupted
10491 2 error occurred after sound started
10492 Example: >
10493 func Callback(id, status)
10494 echomsg "sound " .. a:id .. " finished with " .. a:status
10495 endfunc
10496 call sound_playevent('bell', 'Callback')
10497
10498< MS-Windows: {callback} doesn't work for this function.
10499
10500 Returns the sound ID, which can be passed to `sound_stop()`.
10501 Returns zero if the sound could not be played.
10502
10503 Can also be used as a |method|: >
10504 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010505<
10506 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010507
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010508 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010509
10510 *sound_playfile()*
10511sound_playfile({path} [, {callback}])
10512 Like `sound_playevent()` but play sound file {path}. {path}
10513 must be a full path. On Ubuntu you may find files to play
10514 with this command: >
10515 :!find /usr/share/sounds -type f | grep -v index.theme
10516
10517< Can also be used as a |method|: >
10518 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010519<
10520 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010521
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010522 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010523
10524
10525sound_stop({id}) *sound_stop()*
10526 Stop playing sound {id}. {id} must be previously returned by
10527 `sound_playevent()` or `sound_playfile()`.
10528
10529 On some Linux systems you may need the libcanberra-pulse
10530 package, otherwise sound may not stop.
10531
10532 On MS-Windows, this does not work for event sound started by
10533 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10534
10535 Can also be used as a |method|: >
10536 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010537<
10538 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010539
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010540 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010541
10542 *soundfold()*
10543soundfold({word})
10544 Return the sound-folded equivalent of {word}. Uses the first
10545 language in 'spelllang' for the current window that supports
10546 soundfolding. 'spell' must be set. When no sound folding is
10547 possible the {word} is returned unmodified.
10548 This can be used for making spelling suggestions. Note that
10549 the method can be quite slow.
10550
10551 Can also be used as a |method|: >
10552 GetWord()->soundfold()
10553<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010554 Return type: |String|
10555
10556
10557spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010558 Without argument: The result is the badly spelled word under
10559 or after the cursor. The cursor is moved to the start of the
10560 bad word. When no bad word is found in the cursor line the
10561 result is an empty string and the cursor doesn't move.
10562
10563 With argument: The result is the first word in {sentence} that
10564 is badly spelled. If there are no spelling mistakes the
10565 result is an empty string.
10566
10567 The return value is a list with two items:
10568 - The badly spelled word or an empty string.
10569 - The type of the spelling error:
10570 "bad" spelling mistake
10571 "rare" rare word
10572 "local" word only valid in another region
10573 "caps" word should start with Capital
10574 Example: >
10575 echo spellbadword("the quik brown fox")
10576< ['quik', 'bad'] ~
10577
10578 The spelling information for the current window and the value
10579 of 'spelllang' are used.
10580
10581 Can also be used as a |method|: >
10582 GetText()->spellbadword()
10583<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010584 Return type: list<string>
10585
10586
10587spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010588 Return a |List| with spelling suggestions to replace {word}.
10589 When {max} is given up to this number of suggestions are
10590 returned. Otherwise up to 25 suggestions are returned.
10591
10592 When the {capital} argument is given and it's non-zero only
10593 suggestions with a leading capital will be given. Use this
10594 after a match with 'spellcapcheck'.
10595
10596 {word} can be a badly spelled word followed by other text.
10597 This allows for joining two words that were split. The
10598 suggestions also include the following text, thus you can
10599 replace a line.
10600
10601 {word} may also be a good word. Similar words will then be
10602 returned. {word} itself is not included in the suggestions,
10603 although it may appear capitalized.
10604
10605 The spelling information for the current window is used. The
10606 values of 'spelllang' and 'spellsuggest' are used.
10607
10608 Can also be used as a |method|: >
10609 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010610<
10611 Return type: list<string> or list<any>
10612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010613
10614split({string} [, {pattern} [, {keepempty}]]) *split()*
10615 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010616 empty each white space separated sequence of characters
10617 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010618 Otherwise the string is split where {pattern} matches,
10619 removing the matched characters. 'ignorecase' is not used
10620 here, add \c to ignore case. |/\c|
10621 When the first or last item is empty it is omitted, unless the
10622 {keepempty} argument is given and it's non-zero.
10623 Other empty items are kept when {pattern} matches at least one
10624 character or when {keepempty} is non-zero.
10625 Example: >
10626 :let words = split(getline('.'), '\W\+')
10627< To split a string in individual characters: >
10628 :for c in split(mystring, '\zs')
10629< If you want to keep the separator you can also use '\zs' at
10630 the end of the pattern: >
10631 :echo split('abc:def:ghi', ':\zs')
10632< ['abc:', 'def:', 'ghi'] ~
10633 Splitting a table where the first element can be empty: >
10634 :let items = split(line, ':', 1)
10635< The opposite function is |join()|.
10636
10637 Can also be used as a |method|: >
10638 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010639<
10640 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010641
10642sqrt({expr}) *sqrt()*
10643 Return the non-negative square root of Float {expr} as a
10644 |Float|.
10645 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010646 is negative the result is NaN (Not a Number). Returns 0.0 if
10647 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010648 Examples: >
10649 :echo sqrt(100)
10650< 10.0 >
10651 :echo sqrt(-4.01)
10652< nan
10653 "nan" may be different, it depends on system libraries.
10654
10655 Can also be used as a |method|: >
10656 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010657<
10658 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010659
10660
10661srand([{expr}]) *srand()*
10662 Initialize seed used by |rand()|:
10663 - If {expr} is not given, seed values are initialized by
10664 reading from /dev/urandom, if possible, or using time(NULL)
10665 a.k.a. epoch time otherwise; this only has second accuracy.
10666 - If {expr} is given it must be a Number. It is used to
10667 initialize the seed values. This is useful for testing or
10668 when a predictable sequence is intended.
10669
10670 Examples: >
10671 :let seed = srand()
10672 :let seed = srand(userinput)
10673 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010674<
10675 Return type: list<number>
10676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010677
10678state([{what}]) *state()*
10679 Return a string which contains characters indicating the
10680 current state. Mostly useful in callbacks that want to do
10681 work that may not always be safe. Roughly this works like:
10682 - callback uses state() to check if work is safe to do.
10683 Yes: then do it right away.
10684 No: add to work queue and add a |SafeState| and/or
10685 |SafeStateAgain| autocommand (|SafeState| triggers at
10686 toplevel, |SafeStateAgain| triggers after handling
10687 messages and callbacks).
10688 - When SafeState or SafeStateAgain is triggered and executes
10689 your autocommand, check with `state()` if the work can be
10690 done now, and if yes remove it from the queue and execute.
10691 Remove the autocommand if the queue is now empty.
10692 Also see |mode()|.
10693
10694 When {what} is given only characters in this string will be
10695 added. E.g, this checks if the screen has scrolled: >
10696 if state('s') == ''
10697 " screen has not scrolled
10698<
10699 These characters indicate the state, generally indicating that
10700 something is busy:
10701 m halfway a mapping, :normal command, feedkeys() or
10702 stuffed command
10703 o operator pending, e.g. after |d|
10704 a Insert mode autocomplete active
10705 x executing an autocommand
10706 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10707 ch_readraw() when reading json
10708 S not triggering SafeState or SafeStateAgain, e.g. after
10709 |f| or a count
10710 c callback invoked, including timer (repeats for
10711 recursiveness up to "ccc")
10712 s screen has scrolled for messages
10713
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010714 Return type: |String|
10715
10716
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010717str2blob({list} [, {options}]) *str2blob()*
10718 Return a Blob by converting the characters in the List of
10719 strings in {list} into bytes.
10720
10721 A <NL> byte is added to the blob after each list item. A
10722 newline character in the string is translated into a <NUL>
10723 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010724
10725 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010726 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010727
10728 The argument {options} is a |Dict| and supports the following
10729 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010730 encoding Convert the characters using this encoding
10731 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010732 The value is a |String|. See |encoding-names|
10733 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010734
10735 An error is given and an empty blob is returned if the
10736 character encoding fails.
10737
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010738 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010739
10740 See also |blob2str()|
10741
10742 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010743 str2blob(["ab"]) returns 0z6162
10744 str2blob(["«»"]) returns 0zC2ABC2BB
10745 str2blob(["a\nb"]) returns 0z610062
10746 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010747 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010748 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010749<
10750 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010751 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010752<
10753 Return type: |Blob|
10754
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010755str2float({string} [, {quoted}]) *str2float()*
10756 Convert String {string} to a Float. This mostly works the
10757 same as when using a floating point number in an expression,
10758 see |floating-point-format|. But it's a bit more permissive.
10759 E.g., "1e40" is accepted, while in an expression you need to
10760 write "1.0e40". The hexadecimal form "0x123" is also
10761 accepted, but not others, like binary or octal.
10762 When {quoted} is present and non-zero then embedded single
10763 quotes before the dot are ignored, thus "1'000.0" is a
10764 thousand.
10765 Text after the number is silently ignored.
10766 The decimal point is always '.', no matter what the locale is
10767 set to. A comma ends the number: "12,345.67" is converted to
10768 12.0. You can strip out thousands separators with
10769 |substitute()|: >
10770 let f = str2float(substitute(text, ',', '', 'g'))
10771<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010772 Returns 0.0 if the conversion fails.
10773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010774 Can also be used as a |method|: >
10775 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010776<
10777 Return type: |Float|
10778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010779
10780str2list({string} [, {utf8}]) *str2list()*
10781 Return a list containing the number values which represent
10782 each character in String {string}. Examples: >
10783 str2list(" ") returns [32]
10784 str2list("ABC") returns [65, 66, 67]
10785< |list2str()| does the opposite.
10786
10787 When {utf8} is omitted or zero, the current 'encoding' is used.
10788 When {utf8} is TRUE, always treat the String as UTF-8
10789 characters. With UTF-8 composing characters are handled
10790 properly: >
10791 str2list("á") returns [97, 769]
10792
10793< Can also be used as a |method|: >
10794 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010795<
10796 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010797
10798
10799str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10800 Convert string {string} to a number.
10801 {base} is the conversion base, it can be 2, 8, 10 or 16.
10802 When {quoted} is present and non-zero then embedded single
10803 quotes are ignored, thus "1'000'000" is a million.
10804
10805 When {base} is omitted base 10 is used. This also means that
10806 a leading zero doesn't cause octal conversion to be used, as
10807 with the default String to Number conversion. Example: >
10808 let nr = str2nr('0123')
10809<
10810 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10811 different base the result will be zero. Similarly, when
10812 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10813 {base} is 2 a leading "0b" or "0B" is ignored.
10814 Text after the number is silently ignored.
10815
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010816 Returns 0 if {string} is empty or on error.
10817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010818 Can also be used as a |method|: >
10819 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010820<
10821 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010822
10823
10824strcharlen({string}) *strcharlen()*
10825 The result is a Number, which is the number of characters
10826 in String {string}. Composing characters are ignored.
10827 |strchars()| can count the number of characters, counting
10828 composing characters separately.
10829
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010830 Returns 0 if {string} is empty or on error.
10831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010832 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10833
10834 Can also be used as a |method|: >
10835 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010836<
10837 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010838
10839
10840strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10841 Like |strpart()| but using character index and length instead
10842 of byte index and length.
10843 When {skipcc} is omitted or zero, composing characters are
10844 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010845 When {skipcc} set to 1, composing characters are treated as a
10846 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010847 When a character index is used where a character does not
10848 exist it is omitted and counted as one character. For
10849 example: >
10850 strcharpart('abc', -1, 2)
10851< results in 'a'.
10852
Bram Moolenaard592deb2022-06-17 15:42:40 +010010853 Returns an empty string on error.
10854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010855 Can also be used as a |method|: >
10856 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010857<
10858 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010859
10860
10861strchars({string} [, {skipcc}]) *strchars()*
10862 The result is a Number, which is the number of characters
10863 in String {string}.
10864 When {skipcc} is omitted or zero, composing characters are
10865 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010866 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010867 |strcharlen()| always does this.
10868
Bram Moolenaard592deb2022-06-17 15:42:40 +010010869 Returns zero on error.
10870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010871 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10872
10873 {skipcc} is only available after 7.4.755. For backward
10874 compatibility, you can define a wrapper function: >
10875 if has("patch-7.4.755")
10876 function s:strchars(str, skipcc)
10877 return strchars(a:str, a:skipcc)
10878 endfunction
10879 else
10880 function s:strchars(str, skipcc)
10881 if a:skipcc
10882 return strlen(substitute(a:str, ".", "x", "g"))
10883 else
10884 return strchars(a:str)
10885 endif
10886 endfunction
10887 endif
10888<
10889 Can also be used as a |method|: >
10890 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010891<
10892 Return type: |Number|
10893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010894
10895strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10896 The result is a Number, which is the number of display cells
10897 String {string} occupies on the screen when it starts at {col}
10898 (first column is zero). When {col} is omitted zero is used.
10899 Otherwise it is the screen column where to start. This
10900 matters for Tab characters.
10901 The option settings of the current window are used. This
10902 matters for anything that's displayed differently, such as
10903 'tabstop' and 'display'.
10904 When {string} contains characters with East Asian Width Class
10905 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010906 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010907 Also see |strlen()|, |strwidth()| and |strchars()|.
10908
10909 Can also be used as a |method|: >
10910 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010911<
10912 Return type: |Number|
10913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010914
10915strftime({format} [, {time}]) *strftime()*
10916 The result is a String, which is a formatted date and time, as
10917 specified by the {format} string. The given {time} is used,
10918 or the current time if no time is given. The accepted
10919 {format} depends on your system, thus this is not portable!
10920 See the manual page of the C function strftime() for the
10921 format. The maximum length of the result is 80 characters.
10922 See also |localtime()|, |getftime()| and |strptime()|.
10923 The language can be changed with the |:language| command.
10924 Examples: >
10925 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10926 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10927 :echo strftime("%y%m%d %T") 970427 11:53:55
10928 :echo strftime("%H:%M") 11:55
10929 :echo strftime("%c", getftime("file.c"))
10930 Show mod time of file.c.
10931< Not available on all systems. To check use: >
10932 :if exists("*strftime")
10933
10934< Can also be used as a |method|: >
10935 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010936<
10937 Return type: |String|
10938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010939
10940strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010941 Get a Number corresponding to the character at {index} in
10942 {str}. This uses a zero-based character index, not a byte
10943 index. Composing characters are considered separate
10944 characters here. Use |nr2char()| to convert the Number to a
10945 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010946 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010947 Also see |strcharpart()| and |strchars()|.
10948
10949 Can also be used as a |method|: >
10950 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010951<
10952 Return type: |Number|
10953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010954
10955stridx({haystack}, {needle} [, {start}]) *stridx()*
10956 The result is a Number, which gives the byte index in
10957 {haystack} of the first occurrence of the String {needle}.
10958 If {start} is specified, the search starts at index {start}.
10959 This can be used to find a second match: >
10960 :let colon1 = stridx(line, ":")
10961 :let colon2 = stridx(line, ":", colon1 + 1)
10962< The search is done case-sensitive.
10963 For pattern searches use |match()|.
10964 -1 is returned if the {needle} does not occur in {haystack}.
10965 See also |strridx()|.
10966 Examples: >
10967 :echo stridx("An Example", "Example") 3
10968 :echo stridx("Starting point", "Start") 0
10969 :echo stridx("Starting point", "start") -1
10970< *strstr()* *strchr()*
10971 stridx() works similar to the C function strstr(). When used
10972 with a single character it works similar to strchr().
10973
10974 Can also be used as a |method|: >
10975 GetHaystack()->stridx(needle)
10976<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010977 Return type: |Number|
10978
10979
10980string({expr}) *string()*
10981 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010982 Float, String, Blob or a composition of them, then the result
10983 can be parsed back with |eval()|.
10984 {expr} type result ~
10985 String 'string' (single quotes are doubled)
10986 Number 123
10987 Float 123.123456 or 1.123456e8
10988 Funcref function('name')
10989 Blob 0z00112233.44556677.8899
10990 List [item, item]
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010991 Tuple (item, item)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010992 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010993 Class class SomeName
10994 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010995 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010996 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010997
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010998 When a |List|, |Tuple| or |Dictionary| has a recursive
10999 reference it is replaced by "[...]" or "(...)" or "{...}".
11000 Using eval() on the result will then fail.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011001
mityu7f0bba22024-03-29 10:14:41 +010011002 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011003 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010011004 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011006 Can also be used as a |method|: >
11007 mylist->string()
11008
11009< Also see |strtrans()|.
11010
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011011 Return type: |String|
11012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011013
11014strlen({string}) *strlen()*
11015 The result is a Number, which is the length of the String
11016 {string} in bytes.
11017 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011018 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011019 If you want to count the number of multibyte characters use
11020 |strchars()|.
11021 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
11022
11023 Can also be used as a |method|: >
11024 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011025<
11026 Return type: |Number|
11027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011028
11029strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
11030 The result is a String, which is part of {src}, starting from
11031 byte {start}, with the byte length {len}.
11032 When {chars} is present and TRUE then {len} is the number of
11033 characters positions (composing characters are not counted
11034 separately, thus "1" means one base character and any
11035 following composing characters).
11036 To count {start} as characters instead of bytes use
11037 |strcharpart()|.
11038
11039 When bytes are selected which do not exist, this doesn't
11040 result in an error, the bytes are simply omitted.
11041 If {len} is missing, the copy continues from {start} till the
11042 end of the {src}. >
11043 strpart("abcdefg", 3, 2) == "de"
11044 strpart("abcdefg", -2, 4) == "ab"
11045 strpart("abcdefg", 5, 4) == "fg"
11046 strpart("abcdefg", 3) == "defg"
11047
11048< Note: To get the first character, {start} must be 0. For
11049 example, to get the character under the cursor: >
11050 strpart(getline("."), col(".") - 1, 1, v:true)
11051<
Bram Moolenaard592deb2022-06-17 15:42:40 +010011052 Returns an empty string on error.
11053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011054 Can also be used as a |method|: >
11055 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011056<
11057 Return type: |String|
11058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011059
11060strptime({format}, {timestring}) *strptime()*
11061 The result is a Number, which is a unix timestamp representing
11062 the date and time in {timestring}, which is expected to match
11063 the format specified in {format}.
11064
11065 The accepted {format} depends on your system, thus this is not
11066 portable! See the manual page of the C function strptime()
11067 for the format. Especially avoid "%c". The value of $TZ also
11068 matters.
11069
11070 If the {timestring} cannot be parsed with {format} zero is
11071 returned. If you do not know the format of {timestring} you
11072 can try different {format} values until you get a non-zero
11073 result.
11074
11075 See also |strftime()|.
11076 Examples: >
11077 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11078< 862156163 >
11079 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11080< Sun Apr 27 11:53:55 1997 >
11081 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11082< Sun Apr 27 12:53:55 1997
11083
11084 Can also be used as a |method|: >
11085 GetFormat()->strptime(timestring)
11086<
11087 Not available on all systems. To check use: >
11088 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011089<
11090 Return type: |Number|
11091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011092
11093strridx({haystack}, {needle} [, {start}]) *strridx()*
11094 The result is a Number, which gives the byte index in
11095 {haystack} of the last occurrence of the String {needle}.
11096 When {start} is specified, matches beyond this index are
11097 ignored. This can be used to find a match before a previous
11098 match: >
11099 :let lastcomma = strridx(line, ",")
11100 :let comma2 = strridx(line, ",", lastcomma - 1)
11101< The search is done case-sensitive.
11102 For pattern searches use |match()|.
11103 -1 is returned if the {needle} does not occur in {haystack}.
11104 If the {needle} is empty the length of {haystack} is returned.
11105 See also |stridx()|. Examples: >
11106 :echo strridx("an angry armadillo", "an") 3
11107< *strrchr()*
11108 When used with a single character it works similar to the C
11109 function strrchr().
11110
11111 Can also be used as a |method|: >
11112 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011113<
11114 Return type: |Number|
11115
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011116
11117strtrans({string}) *strtrans()*
11118 The result is a String, which is {string} with all unprintable
11119 characters translated into printable characters |'isprint'|.
11120 Like they are shown in a window. Example: >
11121 echo strtrans(@a)
11122< This displays a newline in register a as "^@" instead of
11123 starting a new line.
11124
Bram Moolenaard592deb2022-06-17 15:42:40 +010011125 Returns an empty string on error.
11126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011127 Can also be used as a |method|: >
11128 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011129<
11130 Return type: |String|
11131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011132
Christian Brabandt67672ef2023-04-24 21:09:54 +010011133strutf16len({string} [, {countcc}]) *strutf16len()*
11134 The result is a Number, which is the number of UTF-16 code
11135 units in String {string} (after converting it to UTF-16).
11136
11137 When {countcc} is TRUE, composing characters are counted
11138 separately.
11139 When {countcc} is omitted or FALSE, composing characters are
11140 ignored.
11141
11142 Returns zero on error.
11143
11144 Also see |strlen()| and |strcharlen()|.
11145 Examples: >
11146 echo strutf16len('a') returns 1
11147 echo strutf16len('©') returns 1
11148 echo strutf16len('😊') returns 2
11149 echo strutf16len('ą́') returns 1
11150 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011151<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011152 Can also be used as a |method|: >
11153 GetText()->strutf16len()
11154<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011155 Return type: |Number|
11156
11157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011158strwidth({string}) *strwidth()*
11159 The result is a Number, which is the number of display cells
11160 String {string} occupies. A Tab character is counted as one
11161 cell, alternatively use |strdisplaywidth()|.
11162 When {string} contains characters with East Asian Width Class
11163 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011164 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011165 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11166
11167 Can also be used as a |method|: >
11168 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011169<
11170 Return type: |Number|
11171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011172
11173submatch({nr} [, {list}]) *submatch()* *E935*
11174 Only for an expression in a |:substitute| command or
11175 substitute() function.
11176 Returns the {nr}'th submatch of the matched text. When {nr}
11177 is 0 the whole matched text is returned.
11178 Note that a NL in the string can stand for a line break of a
11179 multi-line match or a NUL character in the text.
11180 Also see |sub-replace-expression|.
11181
11182 If {list} is present and non-zero then submatch() returns
11183 a list of strings, similar to |getline()| with two arguments.
11184 NL characters in the text represent NUL characters in the
11185 text.
11186 Only returns more than one item for |:substitute|, inside
11187 |substitute()| this list will always contain one or zero
11188 items, since there are no real line breaks.
11189
11190 When substitute() is used recursively only the submatches in
11191 the current (deepest) call can be obtained.
11192
Bram Moolenaard592deb2022-06-17 15:42:40 +010011193 Returns an empty string or list on error.
11194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011195 Examples: >
11196 :s/\d\+/\=submatch(0) + 1/
11197 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11198< This finds the first number in the line and adds one to it.
11199 A line break is included as a newline character.
11200
11201 Can also be used as a |method|: >
11202 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011203<
11204 Return type: |String| or list<string> depending on {list}
11205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011206
11207substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11208 The result is a String, which is a copy of {string}, in which
11209 the first match of {pat} is replaced with {sub}.
11210 When {flags} is "g", all matches of {pat} in {string} are
11211 replaced. Otherwise {flags} should be "".
11212
11213 This works like the ":substitute" command (without any flags).
11214 But the matching with {pat} is always done like the 'magic'
11215 option is set and 'cpoptions' is empty (to make scripts
11216 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11217 if you want to ignore or match case and ignore 'ignorecase'.
11218 'smartcase' is not used. See |string-match| for how {pat} is
11219 used.
11220
11221 A "~" in {sub} is not replaced with the previous {sub}.
11222 Note that some codes in {sub} have a special meaning
11223 |sub-replace-special|. For example, to replace something with
11224 "\n" (two characters), use "\\\\n" or '\\n'.
11225
11226 When {pat} does not match in {string}, {string} is returned
11227 unmodified.
11228
11229 Example: >
11230 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11231< This removes the last component of the 'path' option. >
11232 :echo substitute("testing", ".*", "\\U\\0", "")
11233< results in "TESTING".
11234
11235 When {sub} starts with "\=", the remainder is interpreted as
11236 an expression. See |sub-replace-expression|. Example: >
11237 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011238 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011239
11240< When {sub} is a Funcref that function is called, with one
11241 optional argument. Example: >
11242 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11243< The optional argument is a list which contains the whole
11244 matched string and up to nine submatches, like what
11245 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011246 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011247
Bram Moolenaard592deb2022-06-17 15:42:40 +010011248< Returns an empty string on error.
11249
11250 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011251 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011252<
11253 Return type: |String|
11254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011255
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011256swapfilelist() *swapfilelist()*
11257 Returns a list of swap file names, like what "vim -r" shows.
11258 See the |-r| command argument. The 'directory' option is used
11259 for the directories to inspect. If you only want to get a
11260 list of swap files in the current directory then temporarily
11261 set 'directory' to a dot: >
11262 let save_dir = &directory
11263 let &directory = '.'
11264 let swapfiles = swapfilelist()
11265 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011266<
11267 Return type: list<string>
11268
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011270swapinfo({fname}) *swapinfo()*
11271 The result is a dictionary, which holds information about the
11272 swapfile {fname}. The available fields are:
11273 version Vim version
11274 user user name
11275 host host name
11276 fname original file name
11277 pid PID of the Vim process that created the swap
11278 file
11279 mtime last modification time in seconds
11280 inode Optional: INODE number of the file
11281 dirty 1 if file was modified, 0 if not
11282 Note that "user" and "host" are truncated to at most 39 bytes.
11283 In case of failure an "error" item is added with the reason:
11284 Cannot open file: file not found or in accessible
11285 Cannot read file: cannot read first block
11286 Not a swap file: does not contain correct block ID
11287 Magic number mismatch: Info in first block is invalid
11288
11289 Can also be used as a |method|: >
11290 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011291<
11292 Return type: dict<any> or dict<string>
11293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011294
11295swapname({buf}) *swapname()*
11296 The result is the swap file path of the buffer {expr}.
11297 For the use of {buf}, see |bufname()| above.
11298 If buffer {buf} is the current buffer, the result is equal to
11299 |:swapname| (unless there is no swap file).
11300 If buffer {buf} has no swap file, returns an empty string.
11301
11302 Can also be used as a |method|: >
11303 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011304<
11305 Return type: |String|
11306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011307
11308synID({lnum}, {col}, {trans}) *synID()*
11309 The result is a Number, which is the syntax ID at the position
11310 {lnum} and {col} in the current window.
11311 The syntax ID can be used with |synIDattr()| and
11312 |synIDtrans()| to obtain syntax information about text.
11313
11314 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11315 line. 'synmaxcol' applies, in a longer line zero is returned.
11316 Note that when the position is after the last character,
11317 that's where the cursor can be in Insert mode, synID() returns
11318 zero. {lnum} is used like with |getline()|.
11319
11320 When {trans} is |TRUE|, transparent items are reduced to the
11321 item that they reveal. This is useful when wanting to know
11322 the effective color. When {trans} is |FALSE|, the transparent
11323 item is returned. This is useful when wanting to know which
11324 syntax item is effective (e.g. inside parens).
11325 Warning: This function can be very slow. Best speed is
11326 obtained by going through the file in forward direction.
11327
Bram Moolenaard592deb2022-06-17 15:42:40 +010011328 Returns zero on error.
11329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011330 Example (echoes the name of the syntax item under the cursor): >
11331 :echo synIDattr(synID(line("."), col("."), 1), "name")
11332<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011333 Return type: |Number|
11334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011335
11336synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11337 The result is a String, which is the {what} attribute of
11338 syntax ID {synID}. This can be used to obtain information
11339 about a syntax item.
11340 {mode} can be "gui", "cterm" or "term", to get the attributes
11341 for that mode. When {mode} is omitted, or an invalid value is
11342 used, the attributes for the currently active highlighting are
11343 used (GUI, cterm or term).
11344 Use synIDtrans() to follow linked highlight groups.
11345 {what} result
11346 "name" the name of the syntax item
11347 "fg" foreground color (GUI: color name used to set
11348 the color, cterm: color number as a string,
11349 term: empty string)
11350 "bg" background color (as with "fg")
11351 "font" font name (only available in the GUI)
11352 |highlight-font|
11353 "sp" special color for the GUI (as with "fg")
11354 |highlight-guisp|
11355 "ul" underline color for cterm: number as a string
11356 "fg#" like "fg", but for the GUI and the GUI is
11357 running the name in "#RRGGBB" form
11358 "bg#" like "fg#" for "bg"
11359 "sp#" like "fg#" for "sp"
11360 "bold" "1" if bold
11361 "italic" "1" if italic
11362 "reverse" "1" if reverse
11363 "inverse" "1" if inverse (= reverse)
11364 "standout" "1" if standout
11365 "underline" "1" if underlined
11366 "undercurl" "1" if undercurled
11367 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011368 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011369
Bram Moolenaard592deb2022-06-17 15:42:40 +010011370 Returns an empty string on error.
11371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011372 Example (echoes the color of the syntax item under the
11373 cursor): >
11374 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11375<
11376 Can also be used as a |method|: >
11377 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011378<
11379 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011380
11381
11382synIDtrans({synID}) *synIDtrans()*
11383 The result is a Number, which is the translated syntax ID of
11384 {synID}. This is the syntax group ID of what is being used to
11385 highlight the character. Highlight links given with
11386 ":highlight link" are followed.
11387
Bram Moolenaard592deb2022-06-17 15:42:40 +010011388 Returns zero on error.
11389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011390 Can also be used as a |method|: >
11391 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011392<
11393 Return type: |Number|
11394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011395
11396synconcealed({lnum}, {col}) *synconcealed()*
11397 The result is a |List| with currently three items:
11398 1. The first item in the list is 0 if the character at the
11399 position {lnum} and {col} is not part of a concealable
11400 region, 1 if it is. {lnum} is used like with |getline()|.
11401 2. The second item in the list is a string. If the first item
11402 is 1, the second item contains the text which will be
11403 displayed in place of the concealed text, depending on the
11404 current setting of 'conceallevel' and 'listchars'.
11405 3. The third and final item in the list is a number
11406 representing the specific syntax region matched in the
11407 line. When the character is not concealed the value is
11408 zero. This allows detection of the beginning of a new
11409 concealable region if there are two consecutive regions
11410 with the same replacement character. For an example, if
11411 the text is "123456" and both "23" and "45" are concealed
11412 and replaced by the character "X", then:
11413 call returns ~
11414 synconcealed(lnum, 1) [0, '', 0]
11415 synconcealed(lnum, 2) [1, 'X', 1]
11416 synconcealed(lnum, 3) [1, 'X', 1]
11417 synconcealed(lnum, 4) [1, 'X', 2]
11418 synconcealed(lnum, 5) [1, 'X', 2]
11419 synconcealed(lnum, 6) [0, '', 0]
11420
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011421 Note: Doesn't consider |matchadd()| highlighting items,
11422 since syntax and matching highlighting are two different
11423 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011424
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011425 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011427
11428synstack({lnum}, {col}) *synstack()*
11429 Return a |List|, which is the stack of syntax items at the
11430 position {lnum} and {col} in the current window. {lnum} is
11431 used like with |getline()|. Each item in the List is an ID
11432 like what |synID()| returns.
11433 The first item in the List is the outer region, following are
11434 items contained in that one. The last one is what |synID()|
11435 returns, unless not the whole item is highlighted or it is a
11436 transparent item.
11437 This function is useful for debugging a syntax file.
11438 Example that shows the syntax stack under the cursor: >
11439 for id in synstack(line("."), col("."))
11440 echo synIDattr(id, "name")
11441 endfor
11442< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011443 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011444 character in a line and the first column in an empty line are
11445 valid positions.
11446
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011447 Return type: list<number> or list<any>
11448
11449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011450system({expr} [, {input}]) *system()* *E677*
11451 Get the output of the shell command {expr} as a |String|. See
11452 |systemlist()| to get the output as a |List|.
11453
11454 When {input} is given and is a |String| this string is written
11455 to a file and passed as stdin to the command. The string is
11456 written as-is, you need to take care of using the correct line
11457 separators yourself.
11458 If {input} is given and is a |List| it is written to the file
11459 in a way |writefile()| does with {binary} set to "b" (i.e.
11460 with a newline between each list item with newlines inside
11461 list items converted to NULs).
11462 When {input} is given and is a number that is a valid id for
11463 an existing buffer then the content of the buffer is written
11464 to the file line by line, each line terminated by a NL and
11465 NULs characters where the text has a NL.
11466
11467 Pipes are not used, the 'shelltemp' option is not used.
11468
11469 When prepended by |:silent| the terminal will not be set to
11470 cooked mode. This is meant to be used for commands that do
11471 not need the user to type. It avoids stray characters showing
11472 up on the screen which require |CTRL-L| to remove. >
11473 :silent let f = system('ls *.vim')
11474<
11475 Note: Use |shellescape()| or |::S| with |expand()| or
11476 |fnamemodify()| to escape special characters in a command
11477 argument. Newlines in {expr} may cause the command to fail.
11478 The characters in 'shellquote' and 'shellxquote' may also
11479 cause trouble.
11480 This is not to be used for interactive commands.
11481
11482 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011483 :let files = system('ls ' .. shellescape(expand('%:h')))
11484 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011485
11486< To make the result more system-independent, the shell output
11487 is filtered to replace <CR> with <NL> for Macintosh, and
11488 <CR><NL> with <NL> for DOS-like systems.
11489 To avoid the string being truncated at a NUL, all NUL
11490 characters are replaced with SOH (0x01).
11491
11492 The command executed is constructed using several options:
11493 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11494 ({tmp} is an automatically generated file name).
11495 For Unix, braces are put around {expr} to allow for
11496 concatenated commands.
11497
11498 The command will be executed in "cooked" mode, so that a
11499 CTRL-C will interrupt the command (on Unix at least).
11500
11501 The resulting error code can be found in |v:shell_error|.
11502 This function will fail in |restricted-mode|.
11503
11504 Note that any wrong value in the options mentioned above may
11505 make the function fail. It has also been reported to fail
11506 when using a security agent application.
11507 Unlike ":!cmd" there is no automatic check for changed files.
11508 Use |:checktime| to force a check.
11509
11510 Can also be used as a |method|: >
11511 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011512<
11513 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011514
11515
11516systemlist({expr} [, {input}]) *systemlist()*
11517 Same as |system()|, but returns a |List| with lines (parts of
11518 output separated by NL) with NULs transformed into NLs. Output
11519 is the same as |readfile()| will output with {binary} argument
11520 set to "b", except that there is no extra empty item when the
11521 result ends in a NL.
11522 Note that on MS-Windows you may get trailing CR characters.
11523
11524 To see the difference between "echo hello" and "echo -n hello"
11525 use |system()| and |split()|: >
11526 echo system('echo hello')->split('\n', 1)
11527<
11528 Returns an empty string on error.
11529
11530 Can also be used as a |method|: >
11531 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011532<
11533 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011534
11535
11536tabpagebuflist([{arg}]) *tabpagebuflist()*
11537 The result is a |List|, where each item is the number of the
11538 buffer associated with each window in the current tab page.
11539 {arg} specifies the number of the tab page to be used. When
11540 omitted the current tab page is used.
11541 When {arg} is invalid the number zero is returned.
11542 To get a list of all buffers in all tabs use this: >
11543 let buflist = []
11544 for i in range(tabpagenr('$'))
11545 call extend(buflist, tabpagebuflist(i + 1))
11546 endfor
11547< Note that a buffer may appear in more than one window.
11548
11549 Can also be used as a |method|: >
11550 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011551<
11552 Return type: list<number>
11553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011554
11555tabpagenr([{arg}]) *tabpagenr()*
11556 The result is a Number, which is the number of the current
11557 tab page. The first tab page has number 1.
11558
11559 The optional argument {arg} supports the following values:
11560 $ the number of the last tab page (the tab page
11561 count).
11562 # the number of the last accessed tab page
11563 (where |g<Tab>| goes to). if there is no
11564 previous tab page 0 is returned.
11565 The number can be used with the |:tab| command.
11566
Bram Moolenaard592deb2022-06-17 15:42:40 +010011567 Returns zero on error.
11568
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011569 Return type: |Number|
11570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011571
11572tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11573 Like |winnr()| but for tab page {tabarg}.
11574 {tabarg} specifies the number of tab page to be used.
11575 {arg} is used like with |winnr()|:
11576 - When omitted the current window number is returned. This is
11577 the window which will be used when going to this tab page.
11578 - When "$" the number of windows is returned.
11579 - When "#" the previous window nr is returned.
11580 Useful examples: >
11581 tabpagewinnr(1) " current window of tab page 1
11582 tabpagewinnr(4, '$') " number of windows in tab page 4
11583< When {tabarg} is invalid zero is returned.
11584
11585 Can also be used as a |method|: >
11586 GetTabpage()->tabpagewinnr()
11587<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011588 Return type: |Number|
11589
11590
11591tagfiles() *tagfiles()*
11592 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011593 for the current buffer. This is the 'tags' option expanded.
11594
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011595 Return type: list<string> or list<any>
11596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011597
11598taglist({expr} [, {filename}]) *taglist()*
11599 Returns a |List| of tags matching the regular expression {expr}.
11600
11601 If {filename} is passed it is used to prioritize the results
11602 in the same way that |:tselect| does. See |tag-priority|.
11603 {filename} should be the full path of the file.
11604
11605 Each list item is a dictionary with at least the following
11606 entries:
11607 name Name of the tag.
11608 filename Name of the file where the tag is
11609 defined. It is either relative to the
11610 current directory or a full path.
11611 cmd Ex command used to locate the tag in
11612 the file.
11613 kind Type of the tag. The value for this
11614 entry depends on the language specific
11615 kind values. Only available when
11616 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011617 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011618 static A file specific tag. Refer to
11619 |static-tag| for more information.
11620 More entries may be present, depending on the content of the
11621 tags file: access, implementation, inherits and signature.
11622 Refer to the ctags documentation for information about these
11623 fields. For C code the fields "struct", "class" and "enum"
11624 may appear, they give the name of the entity the tag is
11625 contained in.
11626
11627 The ex-command "cmd" can be either an ex search pattern, a
11628 line number or a line number followed by a byte number.
11629
11630 If there are no matching tags, then an empty list is returned.
11631
11632 To get an exact tag match, the anchors '^' and '$' should be
11633 used in {expr}. This also make the function work faster.
11634 Refer to |tag-regexp| for more information about the tag
11635 search regular expression pattern.
11636
11637 Refer to |'tags'| for information about how the tags file is
11638 located by Vim. Refer to |tags-file-format| for the format of
11639 the tags file generated by the different ctags tools.
11640
11641 Can also be used as a |method|: >
11642 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011643<
11644 Return type: list<dict<any>> or list<any>
11645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011646
11647tan({expr}) *tan()*
11648 Return the tangent of {expr}, measured in radians, as a |Float|
11649 in the range [-inf, inf].
11650 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011651 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011652 Examples: >
11653 :echo tan(10)
11654< 0.648361 >
11655 :echo tan(-4.01)
11656< -1.181502
11657
11658 Can also be used as a |method|: >
11659 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011660<
11661 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011662
11663
11664tanh({expr}) *tanh()*
11665 Return the hyperbolic tangent of {expr} as a |Float| in the
11666 range [-1, 1].
11667 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011668 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011669 Examples: >
11670 :echo tanh(0.5)
11671< 0.462117 >
11672 :echo tanh(-1)
11673< -0.761594
11674
11675 Can also be used as a |method|: >
11676 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011677<
11678 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011679
11680
11681tempname() *tempname()* *temp-file-name*
11682 The result is a String, which is the name of a file that
11683 doesn't exist. It can be used for a temporary file. The name
11684 is different for at least 26 consecutive calls. Example: >
11685 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011686 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011687< For Unix, the file will be in a private directory |tempfile|
11688 that is recursively deleted when Vim exits, on other systems
11689 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011690 For MS-Windows forward slashes are used when the 'shellslash'
11691 option is set, or when 'shellcmdflag' starts with '-' and
11692 'shell' does not contain powershell or pwsh.
11693
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011694 Return type: |String|
11695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011696
11697term_ functions are documented here: |terminal-function-details|
11698
11699
11700terminalprops() *terminalprops()*
11701 Returns a |Dictionary| with properties of the terminal that Vim
11702 detected from the response to |t_RV| request. See
11703 |v:termresponse| for the response itself. If |v:termresponse|
11704 is empty most values here will be 'u' for unknown.
11705 cursor_style whether sending |t_RS| works **
11706 cursor_blink_mode whether sending |t_RC| works **
11707 underline_rgb whether |t_8u| works **
11708 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011709 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011710
11711 ** value 'u' for unknown, 'y' for yes, 'n' for no
11712
11713 If the |+termresponse| feature is missing then the result is
11714 an empty dictionary.
11715
11716 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11717 current cursor style.
11718 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11719 request the cursor blink status.
11720 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11721 is not empty, Vim will detect the working of sending |t_RS|
11722 and |t_RC| on startup.
11723
11724 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11725 This avoids sending it to xterm, which would clear the colors.
11726
11727 For "mouse" the value 'u' is unknown
11728
11729 Also see:
11730 - 'ambiwidth' - detected by using |t_u7|.
11731 - |v:termstyleresp| and |v:termblinkresp| for the response to
11732 |t_RS| and |t_RC|.
11733
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011734 Return type: dict<string>
11735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011736
11737test_ functions are documented here: |test-functions-details|
11738
11739
11740 *timer_info()*
11741timer_info([{id}])
11742 Return a list with information about timers.
11743 When {id} is given only information about this timer is
11744 returned. When timer {id} does not exist an empty list is
11745 returned.
11746 When {id} is omitted information about all timers is returned.
11747
11748 For each timer the information is stored in a |Dictionary| with
11749 these items:
11750 "id" the timer ID
11751 "time" time the timer was started with
11752 "remaining" time until the timer fires
11753 "repeat" number of times the timer will still fire;
11754 -1 means forever
11755 "callback" the callback
11756 "paused" 1 if the timer is paused, 0 otherwise
11757
11758 Can also be used as a |method|: >
11759 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011760<
11761 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011762
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011763 {only available when compiled with the |+timers| feature}
11764
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011765
11766timer_pause({timer}, {paused}) *timer_pause()*
11767 Pause or unpause a timer. A paused timer does not invoke its
11768 callback when its time expires. Unpausing a timer may cause
11769 the callback to be invoked almost immediately if enough time
11770 has passed.
11771
11772 Pausing a timer is useful to avoid the callback to be called
11773 for a short time.
11774
11775 If {paused} evaluates to a non-zero Number or a non-empty
11776 String, then the timer is paused, otherwise it is unpaused.
11777 See |non-zero-arg|.
11778
11779 Can also be used as a |method|: >
11780 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011781<
11782 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011783
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011784 {only available when compiled with the |+timers| feature}
11785
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011786
11787 *timer_start()* *timer* *timers*
11788timer_start({time}, {callback} [, {options}])
11789 Create a timer and return the timer ID.
11790
11791 {time} is the waiting time in milliseconds. This is the
11792 minimum time before invoking the callback. When the system is
11793 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011794 Zero can be used to execute the callback when Vim is back in
11795 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011796
11797 {callback} is the function to call. It can be the name of a
11798 function or a |Funcref|. It is called with one argument, which
11799 is the timer ID. The callback is only invoked when Vim is
11800 waiting for input.
11801 If you want to show a message look at |popup_notification()|
11802 to avoid interfering with what the user is doing.
11803
11804 {options} is a dictionary. Supported entries:
11805 "repeat" Number of times to repeat calling the
11806 callback. -1 means forever. When not present
11807 the callback will be called once.
11808 If the timer causes an error three times in a
11809 row the repeat is cancelled. This avoids that
11810 Vim becomes unusable because of all the error
11811 messages.
11812
Bram Moolenaard592deb2022-06-17 15:42:40 +010011813 Returns -1 on error.
11814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011815 Example: >
11816 func MyHandler(timer)
11817 echo 'Handler called'
11818 endfunc
11819 let timer = timer_start(500, 'MyHandler',
11820 \ {'repeat': 3})
11821< This will invoke MyHandler() three times at 500 msec
11822 intervals.
11823
11824 Can also be used as a |method|: >
11825 GetMsec()->timer_start(callback)
11826
11827< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011828
11829 Return type: |Number|
11830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011831 {only available when compiled with the |+timers| feature}
11832
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011834timer_stop({timer}) *timer_stop()*
11835 Stop a timer. The timer callback will no longer be invoked.
11836 {timer} is an ID returned by timer_start(), thus it must be a
11837 Number. If {timer} does not exist there is no error.
11838
11839 Can also be used as a |method|: >
11840 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011841<
11842 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011843
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011844 {only available when compiled with the |+timers| feature}
11845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011846
11847timer_stopall() *timer_stopall()*
11848 Stop all timers. The timer callbacks will no longer be
11849 invoked. Useful if a timer is misbehaving. If there are no
11850 timers there is no error.
11851
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011852 Return type: |Number|
11853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011854 {only available when compiled with the |+timers| feature}
11855
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011857tolower({expr}) *tolower()*
11858 The result is a copy of the String given, with all uppercase
11859 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011860 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011861
11862 Can also be used as a |method|: >
11863 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011864<
11865 Return type: |String|
11866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011867
11868toupper({expr}) *toupper()*
11869 The result is a copy of the String given, with all lowercase
11870 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011871 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011872
11873 Can also be used as a |method|: >
11874 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011875<
11876 Return type: |String|
11877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011878
11879tr({src}, {fromstr}, {tostr}) *tr()*
11880 The result is a copy of the {src} string with all characters
11881 which appear in {fromstr} replaced by the character in that
11882 position in the {tostr} string. Thus the first character in
11883 {fromstr} is translated into the first character in {tostr}
11884 and so on. Exactly like the unix "tr" command.
11885 This code also deals with multibyte characters properly.
11886
Bram Moolenaard592deb2022-06-17 15:42:40 +010011887 Returns an empty string on error.
11888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011889 Examples: >
11890 echo tr("hello there", "ht", "HT")
11891< returns "Hello THere" >
11892 echo tr("<blob>", "<>", "{}")
11893< returns "{blob}"
11894
11895 Can also be used as a |method|: >
11896 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011897<
11898 Return type: |String|
11899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011900
11901trim({text} [, {mask} [, {dir}]]) *trim()*
11902 Return {text} as a String where any character in {mask} is
11903 removed from the beginning and/or end of {text}.
11904
Illia Bobyr80799172023-10-17 18:00:50 +020011905 If {mask} is not given, or is an empty string, {mask} is all
11906 characters up to 0x20, which includes Tab, space, NL and CR,
11907 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011908
11909 The optional {dir} argument specifies where to remove the
11910 characters:
11911 0 remove from the beginning and end of {text}
11912 1 remove only at the beginning of {text}
11913 2 remove only at the end of {text}
11914 When omitted both ends are trimmed.
11915
11916 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011917 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011918
11919 Examples: >
11920 echo trim(" some text ")
11921< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011922 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011923< returns "RESERVE_TAIL" >
11924 echo trim("rm<Xrm<>X>rrm", "rm<>")
11925< returns "Xrm<>X" (characters in the middle are not removed) >
11926 echo trim(" vim ", " ", 2)
11927< returns " vim"
11928
11929 Can also be used as a |method|: >
11930 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011931<
11932 Return type: |String|
11933
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011934
11935trunc({expr}) *trunc()*
11936 Return the largest integral value with magnitude less than or
11937 equal to {expr} as a |Float| (truncate towards zero).
11938 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011939 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011940 Examples: >
11941 echo trunc(1.456)
11942< 1.0 >
11943 echo trunc(-5.456)
11944< -5.0 >
11945 echo trunc(4.0)
11946< 4.0
11947
11948 Can also be used as a |method|: >
11949 Compute()->trunc()
11950<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011951 Return type: |Float|
11952
11953
Yegappan Lakshmanan1c2f4752025-03-30 15:37:24 +020011954tuple2list({tuple}) *tuple2list()*
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011955 Create a List from a shallow copy of the tuple items.
11956 Examples: >
11957 tuple2list((1, 2, 3)) returns [1, 2, 3]
11958< |list2tuple()| does the opposite.
11959
11960 This function doesn't recursively convert all the Tuple items
11961 in {tuple} to a List. Note that the items are identical
11962 between the list and the tuple, changing an item changes the
11963 contents of both the tuple and the list.
11964
11965 Returns an empty list on error.
11966
11967 Can also be used as a |method|: >
11968 GetTuple()->tuple2list()
11969<
11970 Return type: list<{type}> (depending on the given |Tuple|)
11971
11972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011973 *type()*
11974type({expr}) The result is a Number representing the type of {expr}.
11975 Instead of using the number directly, it is better to use the
11976 v:t_ variable that has the value:
11977 Number: 0 |v:t_number|
11978 String: 1 |v:t_string|
11979 Funcref: 2 |v:t_func|
11980 List: 3 |v:t_list|
11981 Dictionary: 4 |v:t_dict|
11982 Float: 5 |v:t_float|
11983 Boolean: 6 |v:t_bool| (v:false and v:true)
11984 None: 7 |v:t_none| (v:null and v:none)
11985 Job: 8 |v:t_job|
11986 Channel: 9 |v:t_channel|
11987 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011988 Class: 12 |v:t_class|
11989 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011990 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011991 Enum: 15 |v:t_enum|
11992 EnumValue: 16 |v:t_enumvalue|
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011993 Tuple: 17 |v:t_tuple|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011994 For backward compatibility, this method can be used: >
11995 :if type(myvar) == type(0)
11996 :if type(myvar) == type("")
11997 :if type(myvar) == type(function("tr"))
11998 :if type(myvar) == type([])
11999 :if type(myvar) == type({})
12000 :if type(myvar) == type(0.0)
12001 :if type(myvar) == type(v:false)
12002 :if type(myvar) == type(v:none)
12003< To check if the v:t_ variables exist use this: >
12004 :if exists('v:t_number')
12005
12006< Can also be used as a |method|: >
12007 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012008<
12009 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012010
12011
12012typename({expr}) *typename()*
12013 Return a string representation of the type of {expr}.
12014 Example: >
12015 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000012016< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012017
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012018 Return type: |String|
12019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012020
12021undofile({name}) *undofile()*
12022 Return the name of the undo file that would be used for a file
12023 with name {name} when writing. This uses the 'undodir'
12024 option, finding directories that exist. It does not check if
12025 the undo file exists.
12026 {name} is always expanded to the full path, since that is what
12027 is used internally.
12028 If {name} is empty undofile() returns an empty string, since a
12029 buffer without a file name will not write an undo file.
12030 Useful in combination with |:wundo| and |:rundo|.
12031 When compiled without the |+persistent_undo| option this always
12032 returns an empty string.
12033
12034 Can also be used as a |method|: >
12035 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012036<
12037 Return type: |String|
12038
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012039
Devin J. Pohly5fee1112023-04-23 20:26:59 -050012040undotree([{buf}]) *undotree()*
12041 Return the current state of the undo tree for the current
12042 buffer, or for a specific buffer if {buf} is given. The
12043 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012044 "seq_last" The highest undo sequence number used.
12045 "seq_cur" The sequence number of the current position in
12046 the undo tree. This differs from "seq_last"
12047 when some changes were undone.
12048 "time_cur" Time last used for |:earlier| and related
12049 commands. Use |strftime()| to convert to
12050 something readable.
12051 "save_last" Number of the last file write. Zero when no
12052 write yet.
12053 "save_cur" Number of the current position in the undo
12054 tree.
12055 "synced" Non-zero when the last undo block was synced.
12056 This happens when waiting from input from the
12057 user. See |undo-blocks|.
12058 "entries" A list of dictionaries with information about
12059 undo blocks.
12060
12061 The first item in the "entries" list is the oldest undo item.
12062 Each List item is a |Dictionary| with these items:
12063 "seq" Undo sequence number. Same as what appears in
12064 |:undolist|.
12065 "time" Timestamp when the change happened. Use
12066 |strftime()| to convert to something readable.
12067 "newhead" Only appears in the item that is the last one
12068 that was added. This marks the last change
12069 and where further changes will be added.
12070 "curhead" Only appears in the item that is the last one
12071 that was undone. This marks the current
12072 position in the undo tree, the block that will
12073 be used by a redo command. When nothing was
12074 undone after the last change this item will
12075 not appear anywhere.
12076 "save" Only appears on the last block before a file
12077 write. The number is the write count. The
12078 first write has number 1, the last one the
12079 "save_last" mentioned above.
12080 "alt" Alternate entry. This is again a List of undo
12081 blocks. Each item may again have an "alt"
12082 item.
12083
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012084 Return type: dict<any>
12085
12086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012087uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
12088 Remove second and succeeding copies of repeated adjacent
12089 {list} items in-place. Returns {list}. If you want a list
12090 to remain unmodified make a copy first: >
12091 :let newlist = uniq(copy(mylist))
12092< The default compare function uses the string representation of
12093 each item. For the use of {func} and {dict} see |sort()|.
12094
Bram Moolenaard592deb2022-06-17 15:42:40 +010012095 Returns zero if {list} is not a |List|.
12096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012097 Can also be used as a |method|: >
12098 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012099<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012100 Return type: list<{type}>
12101
12102
Christian Brabandt67672ef2023-04-24 21:09:54 +010012103 *utf16idx()*
12104utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012105 Same as |charidx()| but returns the UTF-16 code unit index of
12106 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012107
12108 When {charidx} is present and TRUE, {idx} is used as the
12109 character index in the String {string} instead of as the byte
12110 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012111 An {idx} in the middle of a UTF-8 sequence is rounded
12112 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012113
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012114 Returns -1 if the arguments are invalid or if there are less
12115 than {idx} bytes in {string}. If there are exactly {idx} bytes
12116 the length of the string in UTF-16 code units is returned.
12117
Christian Brabandt67672ef2023-04-24 21:09:54 +010012118 See |byteidx()| and |byteidxcomp()| for getting the byte index
12119 from the UTF-16 index and |charidx()| for getting the
12120 character index from the UTF-16 index.
12121 Refer to |string-offset-encoding| for more information.
12122 Examples: >
12123 echo utf16idx('a😊😊', 3) returns 2
12124 echo utf16idx('a😊😊', 7) returns 4
12125 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12126 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12127 echo utf16idx('aą́c', 6) returns 2
12128 echo utf16idx('aą́c', 6, 1) returns 4
12129 echo utf16idx('a😊😊', 9) returns -1
12130<
12131 Can also be used as a |method|: >
12132 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012133<
12134 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012135
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012136
12137values({dict}) *values()*
12138 Return a |List| with all the values of {dict}. The |List| is
12139 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012140 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012141
12142 Can also be used as a |method|: >
12143 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012144<
12145 Return type: list<any>
12146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012147
zeertzjq825cf812023-08-17 22:55:25 +020012148virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012149 The result is a Number, which is the screen column of the file
12150 position given with {expr}. That is, the last screen position
12151 occupied by the character at that position, when the screen
12152 would be of unlimited width. When there is a <Tab> at the
12153 position, the returned Number will be the column at the end of
12154 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12155 set to 8, it returns 8. |conceal| is ignored.
12156 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012157
zeertzjq02f3eba2024-06-12 20:45:24 +020012158 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012159 When {expr} is "$", it means the end of the cursor line, so
12160 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012161
12162 When 'virtualedit' is used {expr} can be [lnum, col, off],
12163 where "off" is the offset in screen columns from the start of
12164 the character. E.g., a position within a <Tab> or after the
12165 last character. When "off" is omitted zero is used. When
12166 Virtual editing is active in the current mode, a position
12167 beyond the end of the line can be returned. Also see
12168 |'virtualedit'|
12169
zeertzjq825cf812023-08-17 22:55:25 +020012170 If {list} is present and non-zero then virtcol() returns a
12171 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012172 character.
12173
zeertzjq825cf812023-08-17 22:55:25 +020012174 With the optional {winid} argument the values are obtained for
12175 that window instead of the current window.
12176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012177 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012179 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012180 " With text "foo^Lbar" and cursor on the "^L":
12181
12182 virtcol(".") " returns 5
12183 virtcol(".", 1) " returns [4, 5]
12184 virtcol("$") " returns 9
12185
12186 " With text " there", with 't at 'h':
12187
12188 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012189<
12190 The first column is 1. 0 or [0, 0] is returned for an error.
12191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012192 A more advanced example that echoes the maximum length of
12193 all lines: >
12194 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12195
12196< Can also be used as a |method|: >
12197 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012198<
12199 Return type: |Number|
12200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012201
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012202virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12203 The result is a Number, which is the byte index of the
12204 character in window {winid} at buffer line {lnum} and virtual
12205 column {col}.
12206
zeertzjqb583eda2023-10-14 11:32:28 +020012207 If buffer line {lnum} is an empty line, 0 is returned.
12208
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012209 If {col} is greater than the last virtual column in line
12210 {lnum}, then the byte index of the character at the last
12211 virtual column is returned.
12212
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012213 For a multi-byte character, the column number of the first
12214 byte in the character is returned.
12215
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012216 The {winid} argument can be the window number or the
12217 |window-ID|. If this is zero, then the current window is used.
12218
12219 Returns -1 if the window {winid} doesn't exist or the buffer
12220 line {lnum} or virtual column {col} is invalid.
12221
12222 See also |screenpos()|, |virtcol()| and |col()|.
12223
12224 Can also be used as a |method|: >
12225 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012226<
12227 Return type: |Number|
12228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012229
12230visualmode([{expr}]) *visualmode()*
12231 The result is a String, which describes the last Visual mode
12232 used in the current buffer. Initially it returns an empty
12233 string, but once Visual mode has been used, it returns "v",
12234 "V", or "<CTRL-V>" (a single CTRL-V character) for
12235 character-wise, line-wise, or block-wise Visual mode
12236 respectively.
12237 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012238 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012239< This enters the same Visual mode as before. It is also useful
12240 in scripts if you wish to act differently depending on the
12241 Visual mode that was used.
12242 If Visual mode is active, use |mode()| to get the Visual mode
12243 (e.g., in a |:vmap|).
12244 If {expr} is supplied and it evaluates to a non-zero Number or
12245 a non-empty String, then the Visual mode will be cleared and
12246 the old value is returned. See |non-zero-arg|.
12247
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012248 Return type: |String|
12249
12250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012251wildmenumode() *wildmenumode()*
12252 Returns |TRUE| when the wildmenu is active and |FALSE|
12253 otherwise. See 'wildmenu' and 'wildmode'.
12254 This can be used in mappings to handle the 'wildcharm' option
12255 gracefully. (Makes only sense with |mapmode-c| mappings).
12256
12257 For example to make <c-j> work like <down> in wildmode, use: >
12258 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12259<
Milly6c2fc372024-10-16 22:11:17 +020012260 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012261
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012262 Return type: |Number|
12263
12264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012265win_execute({id}, {command} [, {silent}]) *win_execute()*
12266 Like `execute()` but in the context of window {id}.
12267 The window will temporarily be made the current window,
12268 without triggering autocommands or changing directory. When
12269 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012270 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012271 Example: >
12272 call win_execute(winid, 'set syntax=python')
12273< Doing the same with `setwinvar()` would not trigger
12274 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012275 *E994*
12276 Not all commands are allowed in popup windows.
12277 When window {id} does not exist then no error is given and
12278 an empty string is returned.
12279
12280 Can also be used as a |method|, the base is passed as the
12281 second argument: >
12282 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012283<
12284 Return type: |String|
12285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012286
12287win_findbuf({bufnr}) *win_findbuf()*
12288 Returns a |List| with |window-ID|s for windows that contain
12289 buffer {bufnr}. When there is none the list is empty.
12290
12291 Can also be used as a |method|: >
12292 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012293<
12294 Return type: list<number> or list<any>
12295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012296
12297win_getid([{win} [, {tab}]]) *win_getid()*
12298 Get the |window-ID| for the specified window.
12299 When {win} is missing use the current window.
12300 With {win} this is the window number. The top window has
12301 number 1.
12302 Without {tab} use the current tab, otherwise the tab with
12303 number {tab}. The first tab has number one.
12304 Return zero if the window cannot be found.
12305
12306 Can also be used as a |method|: >
12307 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012308<
12309 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012310
12311
12312win_gettype([{nr}]) *win_gettype()*
12313 Return the type of the window:
12314 "autocmd" autocommand window. Temporary window
12315 used to execute autocommands.
12316 "command" command-line window |cmdwin|
12317 (empty) normal window
12318 "loclist" |location-list-window|
12319 "popup" popup window |popup|
12320 "preview" preview window |preview-window|
12321 "quickfix" |quickfix-window|
12322 "unknown" window {nr} not found
12323
12324 When {nr} is omitted return the type of the current window.
12325 When {nr} is given return the type of this window by number or
12326 |window-ID|.
12327
12328 Also see the 'buftype' option. When running a terminal in a
12329 popup window then 'buftype' is "terminal" and win_gettype()
12330 returns "popup".
12331
12332 Can also be used as a |method|: >
12333 GetWinid()->win_gettype()
12334<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012335 Return type: |String|
12336
12337
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012338win_gotoid({expr}) *win_gotoid()*
12339 Go to window with ID {expr}. This may also change the current
12340 tabpage.
12341 Return TRUE if successful, FALSE if the window cannot be found.
12342
12343 Can also be used as a |method|: >
12344 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012345<
12346 Return type: |Number|
12347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012348
12349win_id2tabwin({expr}) *win_id2tabwin()*
12350 Return a list with the tab number and window number of window
12351 with ID {expr}: [tabnr, winnr].
12352 Return [0, 0] if the window cannot be found.
12353
12354 Can also be used as a |method|: >
12355 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012356<
12357 Return type: list<number>
12358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012359
12360win_id2win({expr}) *win_id2win()*
12361 Return the window number of window with ID {expr}.
12362 Return 0 if the window cannot be found in the current tabpage.
12363
12364 Can also be used as a |method|: >
12365 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012366<
12367 Return type: |Number|
12368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012369
Daniel Steinbergee630312022-01-10 13:36:34 +000012370win_move_separator({nr}, {offset}) *win_move_separator()*
12371 Move window {nr}'s vertical separator (i.e., the right border)
12372 by {offset} columns, as if being dragged by the mouse. {nr}
12373 can be a window number or |window-ID|. A positive {offset}
12374 moves right and a negative {offset} moves left. Moving a
12375 window's vertical separator will change the width of the
12376 window and the width of other windows adjacent to the vertical
12377 separator. The magnitude of movement may be smaller than
12378 specified (e.g., as a consequence of maintaining
12379 'winminwidth'). Returns TRUE if the window can be found and
12380 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012381 This will fail for the rightmost window and a full-width
12382 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012383 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012384
12385 Can also be used as a |method|: >
12386 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012387<
12388 Return type: |Number|
12389
Daniel Steinbergee630312022-01-10 13:36:34 +000012390
12391win_move_statusline({nr}, {offset}) *win_move_statusline()*
12392 Move window {nr}'s status line (i.e., the bottom border) by
12393 {offset} rows, as if being dragged by the mouse. {nr} can be a
12394 window number or |window-ID|. A positive {offset} moves down
12395 and a negative {offset} moves up. Moving a window's status
12396 line will change the height of the window and the height of
12397 other windows adjacent to the status line. The magnitude of
12398 movement may be smaller than specified (e.g., as a consequence
12399 of maintaining 'winminheight'). Returns TRUE if the window can
12400 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012401 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012402
12403 Can also be used as a |method|: >
12404 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012405<
12406 Return type: |Number|
12407
Daniel Steinbergee630312022-01-10 13:36:34 +000012408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012409win_screenpos({nr}) *win_screenpos()*
12410 Return the screen position of window {nr} as a list with two
12411 numbers: [row, col]. The first window always has position
12412 [1, 1], unless there is a tabline, then it is [2, 1].
12413 {nr} can be the window number or the |window-ID|. Use zero
12414 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012415 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012416
12417 Can also be used as a |method|: >
12418 GetWinid()->win_screenpos()
12419<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012420 Return type: list<number>
12421
12422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012423win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012424 Temporarily switch to window {target}, then move window {nr}
12425 to a new split adjacent to {target}.
12426 Unlike commands such as |:split|, no new windows are created
12427 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012428
12429 Both {nr} and {target} can be window numbers or |window-ID|s.
12430 Both must be in the current tab page.
12431
12432 Returns zero for success, non-zero for failure.
12433
12434 {options} is a |Dictionary| with the following optional entries:
12435 "vertical" When TRUE, the split is created vertically,
12436 like with |:vsplit|.
12437 "rightbelow" When TRUE, the split is made below or to the
12438 right (if vertical). When FALSE, it is done
12439 above or to the left (if vertical). When not
12440 present, the values of 'splitbelow' and
12441 'splitright' are used.
12442
12443 Can also be used as a |method|: >
12444 GetWinid()->win_splitmove(target)
12445<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012446 Return type: |Number|
12447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012448
12449 *winbufnr()*
12450winbufnr({nr}) The result is a Number, which is the number of the buffer
12451 associated with window {nr}. {nr} can be the window number or
12452 the |window-ID|.
12453 When {nr} is zero, the number of the buffer in the current
12454 window is returned.
12455 When window {nr} doesn't exist, -1 is returned.
12456 Example: >
12457 :echo "The file in the current window is " . bufname(winbufnr(0))
12458<
12459 Can also be used as a |method|: >
12460 FindWindow()->winbufnr()->bufname()
12461<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012462 Return type: |Number|
12463
12464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012465 *wincol()*
12466wincol() The result is a Number, which is the virtual column of the
12467 cursor in the window. This is counting screen cells from the
12468 left side of the window. The leftmost column is one.
12469
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012470 Return type: |Number|
12471
12472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012473 *windowsversion()*
12474windowsversion()
12475 The result is a String. For MS-Windows it indicates the OS
12476 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12477 Windows XP is "5.1". For non-MS-Windows systems the result is
12478 an empty string.
12479
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012480 Return type: |String|
12481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012482winheight({nr}) *winheight()*
12483 The result is a Number, which is the height of window {nr}.
12484 {nr} can be the window number or the |window-ID|.
12485 When {nr} is zero, the height of the current window is
12486 returned. When window {nr} doesn't exist, -1 is returned.
12487 An existing window always has a height of zero or more.
12488 This excludes any window toolbar line.
12489 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012490 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012491
12492< Can also be used as a |method|: >
12493 GetWinid()->winheight()
12494<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012495 Return type: |Number|
12496
12497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012498winlayout([{tabnr}]) *winlayout()*
12499 The result is a nested List containing the layout of windows
12500 in a tabpage.
12501
12502 Without {tabnr} use the current tabpage, otherwise the tabpage
12503 with number {tabnr}. If the tabpage {tabnr} is not found,
12504 returns an empty list.
12505
12506 For a leaf window, it returns:
12507 ['leaf', {winid}]
12508 For horizontally split windows, which form a column, it
12509 returns:
12510 ['col', [{nested list of windows}]]
12511 For vertically split windows, which form a row, it returns:
12512 ['row', [{nested list of windows}]]
12513
12514 Example: >
12515 " Only one window in the tab page
12516 :echo winlayout()
12517 ['leaf', 1000]
12518 " Two horizontally split windows
12519 :echo winlayout()
12520 ['col', [['leaf', 1000], ['leaf', 1001]]]
12521 " The second tab page, with three horizontally split
12522 " windows, with two vertically split windows in the
12523 " middle window
12524 :echo winlayout(2)
12525 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12526 ['leaf', 1001]]], ['leaf', 1000]]]
12527<
12528 Can also be used as a |method|: >
12529 GetTabnr()->winlayout()
12530<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012531 Return type: list<any>
12532
12533
12534winline() *winline()*
12535 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012536 in the window. This is counting screen lines from the top of
12537 the window. The first line is one.
12538 If the cursor was moved the view on the file will be updated
12539 first, this may cause a scroll.
12540
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012541 Return type: |Number|
12542
12543
12544winnr([{arg}]) *winnr()*
12545 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012546 window. The top window has number 1.
12547 Returns zero for a popup window.
12548
12549 The optional argument {arg} supports the following values:
12550 $ the number of the last window (the window
12551 count).
12552 # the number of the last accessed window (where
12553 |CTRL-W_p| goes to). If there is no previous
12554 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012555 returned. May refer to the current window in
12556 some cases (e.g. when evaluating 'statusline'
12557 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012558 {N}j the number of the Nth window below the
12559 current window (where |CTRL-W_j| goes to).
12560 {N}k the number of the Nth window above the current
12561 window (where |CTRL-W_k| goes to).
12562 {N}h the number of the Nth window left of the
12563 current window (where |CTRL-W_h| goes to).
12564 {N}l the number of the Nth window right of the
12565 current window (where |CTRL-W_l| goes to).
12566 The number can be used with |CTRL-W_w| and ":wincmd w"
12567 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012568 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012569 Also see |tabpagewinnr()| and |win_getid()|.
12570 Examples: >
12571 let window_count = winnr('$')
12572 let prev_window = winnr('#')
12573 let wnum = winnr('3k')
12574
12575< Can also be used as a |method|: >
12576 GetWinval()->winnr()
12577<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012578 Return type: |Number|
12579
12580
12581winrestcmd() *winrestcmd()*
12582 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012583 the current window sizes. Only works properly when no windows
12584 are opened or closed and the current window and tab page is
12585 unchanged.
12586 Example: >
12587 :let cmd = winrestcmd()
12588 :call MessWithWindowSizes()
12589 :exe cmd
12590<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012591 Return type: |String|
12592
12593
12594winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012595 Uses the |Dictionary| returned by |winsaveview()| to restore
12596 the view of the current window.
12597 Note: The {dict} does not have to contain all values, that are
12598 returned by |winsaveview()|. If values are missing, those
12599 settings won't be restored. So you can use: >
12600 :call winrestview({'curswant': 4})
12601<
12602 This will only set the curswant value (the column the cursor
12603 wants to move on vertical movements) of the cursor to column 5
12604 (yes, that is 5), while all other settings will remain the
12605 same. This is useful, if you set the cursor position manually.
12606
12607 If you have changed the values the result is unpredictable.
12608 If the window size changed the result won't be the same.
12609
12610 Can also be used as a |method|: >
12611 GetView()->winrestview()
12612<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012613 Return type: |Number|
12614
12615
12616winsaveview() *winsaveview()*
12617 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012618 the view of the current window. Use |winrestview()| to
12619 restore the view.
12620 This is useful if you have a mapping that jumps around in the
12621 buffer and you want to go back to the original view.
12622 This does not save fold information. Use the 'foldenable'
12623 option to temporarily switch off folding, so that folds are
12624 not opened when moving around. This may have side effects.
12625 The return value includes:
12626 lnum cursor line number
12627 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012628 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012629 returns)
12630 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012631 curswant column for vertical movement (Note:
12632 the first column is zero, as opposed
12633 to what |getcurpos()| returns). After
12634 |$| command it will be a very large
12635 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012636 topline first line in the window
12637 topfill filler lines, only in diff mode
12638 leftcol first column displayed; only used when
12639 'wrap' is off
12640 skipcol columns skipped
12641 Note that no option values are saved.
12642
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012643 Return type: dict<number>
12644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012645
12646winwidth({nr}) *winwidth()*
12647 The result is a Number, which is the width of window {nr}.
12648 {nr} can be the window number or the |window-ID|.
12649 When {nr} is zero, the width of the current window is
12650 returned. When window {nr} doesn't exist, -1 is returned.
12651 An existing window always has a width of zero or more.
12652 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012653 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012654 :if winwidth(0) <= 50
12655 : 50 wincmd |
12656 :endif
12657< For getting the terminal or screen size, see the 'columns'
12658 option.
12659
12660 Can also be used as a |method|: >
12661 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012662<
12663 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012664
12665
12666wordcount() *wordcount()*
12667 The result is a dictionary of byte/chars/word statistics for
12668 the current buffer. This is the same info as provided by
12669 |g_CTRL-G|
12670 The return value includes:
12671 bytes Number of bytes in the buffer
12672 chars Number of chars in the buffer
12673 words Number of words in the buffer
12674 cursor_bytes Number of bytes before cursor position
12675 (not in Visual mode)
12676 cursor_chars Number of chars before cursor position
12677 (not in Visual mode)
12678 cursor_words Number of words before cursor position
12679 (not in Visual mode)
12680 visual_bytes Number of bytes visually selected
12681 (only in Visual mode)
12682 visual_chars Number of chars visually selected
12683 (only in Visual mode)
12684 visual_words Number of words visually selected
12685 (only in Visual mode)
12686
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012687 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012688
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012689
12690writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012691 When {object} is a |List| write it to file {fname}. Each list
12692 item is separated with a NL. Each list item must be a String
12693 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012694 All NL characters are replaced with a NUL character.
12695 Inserting CR characters needs to be done before passing {list}
12696 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012697
12698 When {object} is a |Blob| write the bytes to file {fname}
12699 unmodified, also when binary mode is not specified.
12700
12701 {flags} must be a String. These characters are recognized:
12702
12703 'b' Binary mode is used: There will not be a NL after the
12704 last list item. An empty item at the end does cause the
12705 last line in the file to end in a NL.
12706
12707 'a' Append mode is used, lines are appended to the file: >
12708 :call writefile(["foo"], "event.log", "a")
12709 :call writefile(["bar"], "event.log", "a")
12710<
12711 'D' Delete the file when the current function ends. This
12712 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012713 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012714< Fails when not in a function. Also see |:defer|.
12715
12716 's' fsync() is called after writing the file. This flushes
12717 the file to disk, if possible. This takes more time but
12718 avoids losing the file if the system crashes.
12719
12720 'S' fsync() is not called, even when 'fsync' is set.
12721
12722 When {flags} does not contain "S" or "s" then fsync() is
12723 called if the 'fsync' option is set.
12724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012725 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012727 When the write fails -1 is returned, otherwise 0. There is an
12728 error message if the file can't be created or when writing
12729 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012731 Also see |readfile()|.
12732 To copy a file byte for byte: >
12733 :let fl = readfile("foo", "b")
12734 :call writefile(fl, "foocopy", "b")
12735
12736< Can also be used as a |method|: >
12737 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012738<
12739 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012740
12741
12742xor({expr}, {expr}) *xor()*
12743 Bitwise XOR on the two arguments. The arguments are converted
12744 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012745 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012746 Example: >
12747 :let bits = xor(bits, 0x80)
12748<
12749 Can also be used as a |method|: >
12750 :let bits = bits->xor(0x80)
12751<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012752 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012753
12754==============================================================================
127553. Feature list *feature-list*
12756
12757There are three types of features:
127581. Features that are only supported when they have been enabled when Vim
12759 was compiled |+feature-list|. Example: >
12760 :if has("cindent")
12761< *gui_running*
127622. Features that are only supported when certain conditions have been met.
12763 Example: >
12764 :if has("gui_running")
12765< *has-patch*
127663. Beyond a certain version or at a certain version and including a specific
12767 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12768 later, or it is version 7.4 and patch 248 was included. Example: >
12769 :if has("patch-7.4.248")
12770< Note that it's possible for patch 248 to be omitted even though 249 is
12771 included. Only happens when cherry-picking patches.
12772 Note that this form only works for patch 7.4.237 and later, before that
12773 you need to check for the patch and the v:version. Example (checking
12774 version 6.2.148 or later): >
12775 :if v:version > 602 || (v:version == 602 && has("patch148"))
12776
12777Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12778use: `if exists('+shellslash')`
12779
12780
12781acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012782all_builtin_terms Compiled with all builtin terminals enabled. (always
12783 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012784amiga Amiga version of Vim.
12785arabic Compiled with Arabic support |Arabic|.
12786arp Compiled with ARP support (Amiga).
12787autocmd Compiled with autocommand support. (always true)
12788autochdir Compiled with support for 'autochdir'
12789autoservername Automatically enable |clientserver|
12790balloon_eval Compiled with |balloon-eval| support.
12791balloon_multiline GUI supports multiline balloons.
12792beos BeOS version of Vim.
12793browse Compiled with |:browse| support, and browse() will
12794 work.
12795browsefilter Compiled with support for |browsefilter|.
12796bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012797builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012798byte_offset Compiled with support for 'o' in 'statusline'
12799channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012800cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012801clientserver Compiled with remote invocation support |clientserver|.
12802clipboard Compiled with 'clipboard' support.
12803clipboard_working Compiled with 'clipboard' support and it can be used.
12804cmdline_compl Compiled with |cmdline-completion| support.
12805cmdline_hist Compiled with |cmdline-history| support.
12806cmdline_info Compiled with 'showcmd' and 'ruler' support.
12807comments Compiled with |'comments'| support.
12808compatible Compiled to be very Vi compatible.
12809conpty Platform where |ConPTY| can be used.
12810cryptv Compiled with encryption support |encryption|.
12811cscope Compiled with |cscope| support.
12812cursorbind Compiled with |'cursorbind'| (always true)
12813debug Compiled with "DEBUG" defined.
12814dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012815dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012816dialog_gui Compiled with GUI dialog support.
12817diff Compiled with |vimdiff| and 'diff' support.
12818digraphs Compiled with support for digraphs.
12819directx Compiled with support for DirectX and 'renderoptions'.
12820dnd Compiled with support for the "~ register |quote_~|.
12821drop_file Compiled with |drop_file| support.
12822ebcdic Compiled on a machine with ebcdic character set.
12823emacs_tags Compiled with support for Emacs tags.
12824eval Compiled with expression evaluation support. Always
12825 true, of course!
12826ex_extra |+ex_extra| (always true)
12827extra_search Compiled with support for |'incsearch'| and
12828 |'hlsearch'|
12829farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012830file_in_path Compiled with support for |gf| and |<cfile>| (always
12831 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012832filterpipe When 'shelltemp' is off pipes are used for shell
12833 read/write/filter commands
12834find_in_path Compiled with support for include file searches
12835 |+find_in_path|.
12836float Compiled with support for |Float|.
12837fname_case Case in file names matters (for Amiga and MS-Windows
12838 this is not present).
12839folding Compiled with |folding| support.
12840footer Compiled with GUI footer support. |gui-footer|
12841fork Compiled to use fork()/exec() instead of system().
12842gettext Compiled with message translation |multi-lang|
12843gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012844gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012845gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12846gui_gtk Compiled with GTK+ GUI (any version).
12847gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12848gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12849gui_haiku Compiled with Haiku GUI.
12850gui_mac Compiled with Macintosh GUI.
12851gui_motif Compiled with Motif GUI.
12852gui_photon Compiled with Photon GUI.
12853gui_running Vim is running in the GUI, or it will start soon.
12854gui_win32 Compiled with MS-Windows Win32 GUI.
12855gui_win32s idem, and Win32s system being used (Windows 3.1)
12856haiku Haiku version of Vim.
12857hangul_input Compiled with Hangul input support. |hangul|
12858hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012859hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012860iconv Can use iconv() for conversion.
12861insert_expand Compiled with support for CTRL-X expansion commands in
12862 Insert mode. (always true)
12863job Compiled with support for |channel| and |job|
12864ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012865jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012866keymap Compiled with 'keymap' support.
12867lambda Compiled with |lambda| support.
12868langmap Compiled with 'langmap' support.
12869libcall Compiled with |libcall()| support.
12870linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12871 'breakindent' support.
12872linux Linux version of Vim.
12873lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012874 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012875listcmds Compiled with commands for the buffer list |:files|
12876 and the argument list |arglist|.
12877localmap Compiled with local mappings and abbr. |:map-local|
12878lua Compiled with Lua interface |Lua|.
12879mac Any Macintosh version of Vim cf. osx
12880macunix Synonym for osxdarwin
12881menu Compiled with support for |:menu|.
12882mksession Compiled with support for |:mksession|.
12883modify_fname Compiled with file name modifiers. |filename-modifiers|
12884 (always true)
12885mouse Compiled with support for mouse.
12886mouse_dec Compiled with support for Dec terminal mouse.
12887mouse_gpm Compiled with support for gpm (Linux console mouse)
12888mouse_gpm_enabled GPM mouse is working
12889mouse_netterm Compiled with support for netterm mouse.
12890mouse_pterm Compiled with support for qnx pterm mouse.
12891mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12892mouse_sgr Compiled with support for sgr mouse.
12893mouse_urxvt Compiled with support for urxvt mouse.
12894mouse_xterm Compiled with support for xterm mouse.
12895mouseshape Compiled with support for 'mouseshape'.
12896multi_byte Compiled with support for 'encoding' (always true)
12897multi_byte_encoding 'encoding' is set to a multibyte encoding.
12898multi_byte_ime Compiled with support for IME input method.
12899multi_lang Compiled with support for multiple languages.
12900mzscheme Compiled with MzScheme interface |mzscheme|.
12901nanotime Compiled with sub-second time stamp checks.
12902netbeans_enabled Compiled with support for |netbeans| and connected.
12903netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012904num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012905ole Compiled with OLE automation support for Win32.
12906osx Compiled for macOS cf. mac
12907osxdarwin Compiled for macOS, with |mac-darwin-feature|
12908packages Compiled with |packages| support.
12909path_extra Compiled with up/downwards search in 'path' and 'tags'
12910perl Compiled with Perl interface.
12911persistent_undo Compiled with support for persistent undo history.
12912postscript Compiled with PostScript file printing.
12913printer Compiled with |:hardcopy| support.
12914profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012915prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012916python Python 2.x interface available. |has-python|
12917python_compiled Compiled with Python 2.x interface. |has-python|
12918python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12919python3 Python 3.x interface available. |has-python|
12920python3_compiled Compiled with Python 3.x interface. |has-python|
12921python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012922python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012923pythonx Python 2.x and/or 3.x interface available. |python_x|
12924qnx QNX version of Vim.
12925quickfix Compiled with |quickfix| support.
12926reltime Compiled with |reltime()| support.
12927rightleft Compiled with 'rightleft' support.
12928ruby Compiled with Ruby interface |ruby|.
12929scrollbind Compiled with 'scrollbind' support. (always true)
12930showcmd Compiled with 'showcmd' support.
12931signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012932smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012933sodium Compiled with libsodium for better crypt support
12934sound Compiled with sound support, e.g. `sound_playevent()`
12935spell Compiled with spell checking support |spell|.
12936startuptime Compiled with |--startuptime| support.
12937statusline Compiled with support for 'statusline', 'rulerformat'
12938 and special formats of 'titlestring' and 'iconstring'.
12939sun SunOS version of Vim.
12940sun_workshop Support for Sun |workshop| has been removed.
12941syntax Compiled with syntax highlighting support |syntax|.
12942syntax_items There are active syntax highlighting items for the
12943 current buffer.
12944system Compiled to use system() instead of fork()/exec().
12945tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012946 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012947tag_old_static Support for old static tags was removed, see
12948 |tag-old-static|.
12949tcl Compiled with Tcl interface.
12950termguicolors Compiled with true color in terminal support.
12951terminal Compiled with |terminal| support.
12952terminfo Compiled with terminfo instead of termcap.
12953termresponse Compiled with support for |t_RV| and |v:termresponse|.
12954textobjects Compiled with support for |text-objects|.
12955textprop Compiled with support for |text-properties|.
12956tgetent Compiled with tgetent support, able to use a termcap
12957 or terminfo file.
12958timers Compiled with |timer_start()| support.
12959title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012960 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012961toolbar Compiled with support for |gui-toolbar|.
12962ttyin input is a terminal (tty)
12963ttyout output is a terminal (tty)
12964unix Unix version of Vim. *+unix*
12965unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12966user_commands User-defined commands. (always true)
12967vartabs Compiled with variable tabstop support |'vartabstop'|.
12968vcon Win32: Virtual console support is working, can use
12969 'termguicolors'. Also see |+vtp|.
12970vertsplit Compiled with vertically split windows |:vsplit|.
12971 (always true)
12972vim_starting True while initial source'ing takes place. |startup|
12973 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012974vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012975viminfo Compiled with viminfo support.
12976vimscript-1 Compiled Vim script version 1 support
12977vimscript-2 Compiled Vim script version 2 support
12978vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012979vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012980virtualedit Compiled with 'virtualedit' option. (always true)
12981visual Compiled with Visual mode. (always true)
12982visualextra Compiled with extra Visual mode commands. (always
12983 true) |blockwise-operators|.
12984vms VMS version of Vim.
12985vreplace Compiled with |gR| and |gr| commands. (always true)
12986vtp Compiled for vcon support |+vtp| (check vcon to find
12987 out if it works in the current console).
12988wildignore Compiled with 'wildignore' option.
12989wildmenu Compiled with 'wildmenu' option.
12990win16 old version for MS-Windows 3.1 (always false)
12991win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12992 64 bits)
12993win32unix Win32 version of Vim, using Unix files (Cygwin)
12994win64 Win64 version of Vim (MS-Windows 64 bit).
12995win95 Win32 version for MS-Windows 95/98/ME (always false)
12996winaltkeys Compiled with 'winaltkeys' option.
12997windows Compiled with support for more than one window.
12998 (always true)
12999writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020013000xattr Compiled with extended attributes support |xattr|
13001 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013002xfontset Compiled with X fontset support |xfontset|.
13003xim Compiled with X input method support |xim|.
13004xpm Compiled with pixmap support.
13005xpm_w32 Compiled with pixmap support for Win32. (Only for
13006 backward compatibility. Use "xpm" instead.)
13007xsmp Compiled with X session management support.
13008xsmp_interact Compiled with interactive X session management support.
13009xterm_clipboard Compiled with support for xterm clipboard.
13010xterm_save Compiled with support for saving and restoring the
13011 xterm screen.
13012x11 Compiled with X11 support.
13013
13014
13015==============================================================================
130164. Matching a pattern in a String *string-match*
13017
13018This is common between several functions. A regexp pattern as explained at
13019|pattern| is normally used to find a match in the buffer lines. When a
13020pattern is used to find a match in a String, almost everything works in the
13021same way. The difference is that a String is handled like it is one line.
13022When it contains a "\n" character, this is not seen as a line break for the
13023pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
13024>
13025 :let a = "aaaa\nxxxx"
13026 :echo matchstr(a, "..\n..")
13027 aa
13028 xx
13029 :echo matchstr(a, "a.x")
13030 a
13031 x
13032
13033Don't forget that "^" will only match at the first character of the String and
13034"$" at the last character of the string. They don't match after or before a
13035"\n".
13036
13037 vim:tw=78:ts=8:noet:ft=help:norl: