blob: 8f9c7baa21076e9a8c5618c7c6da33788e85ae5b [file] [log] [blame]
Shougo Matsushita5d2354f2025-07-03 19:57:00 +02001*builtin.txt* For Vim version 9.1. Last change: 2025 Jul 03
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
glepnirbcd59952025-04-24 21:48:35 +0200139complete_match([{lnum}, {col}]) List get completion column and trigger text
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000140confirm({msg} [, {choices} [, {default} [, {type}]]])
141 Number number of choice picked by user
142copy({expr}) any make a shallow copy of {expr}
143cos({expr}) Float cosine of {expr}
144cosh({expr}) Float hyperbolic cosine of {expr}
145count({comp}, {expr} [, {ic} [, {start}]])
146 Number count how many {expr} are in {comp}
147cscope_connection([{num}, {dbpath} [, {prepend}]])
148 Number checks existence of cscope connection
149cursor({lnum}, {col} [, {off}])
150 Number move cursor to {lnum}, {col}, {off}
151cursor({list}) Number move cursor to position in {list}
152debugbreak({pid}) Number interrupt process being debugged
153deepcopy({expr} [, {noref}]) any make a full copy of {expr}
154delete({fname} [, {flags}]) Number delete the file or directory {fname}
155deletebufline({buf}, {first} [, {last}])
156 Number delete lines from buffer {buf}
157did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100158diff({fromlist}, {tolist} [, {options}])
159 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160diff_filler({lnum}) Number diff filler lines about {lnum}
161diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
162digraph_get({chars}) String get the |digraph| of {chars}
163digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200164digraph_set({chars}, {digraph}) Bool register |digraph|
165digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000166echoraw({expr}) none output {expr} as-is
167empty({expr}) Number |TRUE| if {expr} is empty
168environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100169err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000170escape({string}, {chars}) String escape {chars} in {string} with '\'
171eval({string}) any evaluate {string} into its value
172eventhandler() Number |TRUE| if inside an event handler
173executable({expr}) Number 1 if executable {expr} exists
174execute({command}) String execute {command} and get the output
175exepath({expr}) String full path of the command {expr}
176exists({expr}) Number |TRUE| if {expr} exists
177exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
178exp({expr}) Float exponential of {expr}
179expand({expr} [, {nosuf} [, {list}]])
180 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100181expandcmd({string} [, {options}])
182 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000183extend({expr1}, {expr2} [, {expr3}])
184 List/Dict insert items of {expr2} into {expr1}
185extendnew({expr1}, {expr2} [, {expr3}])
186 List/Dict like |extend()| but creates a new
187 List or Dictionary
188feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200189filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
190 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000191filereadable({file}) Number |TRUE| if {file} is a readable file
192filewritable({file}) Number |TRUE| if {file} is a writable file
193filter({expr1}, {expr2}) List/Dict/Blob/String
194 remove items from {expr1} where
195 {expr2} is 0
196finddir({name} [, {path} [, {count}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000197findfile({name} [, {path} [, {count}]])
Christian Brabandt17ad8522025-05-09 00:03:20 +0200198 String/List find dir/file {name} in {path}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000199flatten({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 Matsushita5d2354f2025-07-03 19:57:00 +0200241getcmdcompltype({pat}) String return the type of command-line
242 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 Palya5c3d1e32025-04-22 19:52:16 +02001837cmdcomplete_info() *cmdcomplete_info()*
Girish Palya92f68e22025-04-21 11:12:41 +02001838 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
glepnir49864ae2025-05-28 20:39:34 +02002010 "register" Words from registers |i_CTRL-X_CTRL-R|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002011 "unknown" Other internal modes
2012
2013 If the optional {what} list argument is supplied, then only
2014 the items listed in {what} are returned. Unsupported items in
2015 {what} are silently ignored.
2016
2017 To get the position and size of the popup menu, see
2018 |pum_getpos()|. It's also available in |v:event| during the
2019 |CompleteChanged| event.
2020
Bram Moolenaar016188f2022-06-06 20:52:59 +01002021 Returns an empty |Dictionary| on error.
2022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002023 Examples: >
2024 " Get all items
2025 call complete_info()
2026 " Get only 'mode'
2027 call complete_info(['mode'])
2028 " Get only 'mode' and 'pum_visible'
2029 call complete_info(['mode', 'pum_visible'])
2030
2031< Can also be used as a |method|: >
2032 GetItems()->complete_info()
2033<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002034 Return type: dict<any>
2035
glepnirbcd59952025-04-24 21:48:35 +02002036complete_match([{lnum}, {col}]) *complete_match()*
glepnirffc89e42025-04-27 14:59:17 +02002037 Searches backward from the given position and returns a List
2038 of matches according to the 'isexpand' option. When no
2039 arguments are provided, uses the current cursor position.
2040
2041 Each match is represented as a List containing
glepnirbcd59952025-04-24 21:48:35 +02002042 [startcol, trigger_text] where:
2043 - startcol: column position where completion should start,
2044 or -1 if no trigger position is found. For multi-character
2045 triggers, returns the column of the first character.
2046 - trigger_text: the matching trigger string from 'isexpand',
2047 or empty string if no match was found or when using the
2048 default 'iskeyword' pattern.
2049
Hirohito Higashi8f7256a2025-06-07 18:31:42 +02002050 When 'isexpand' is empty, uses the 'iskeyword' pattern "\k\+$"
2051 to find the start of the current keyword.
glepnirbcd59952025-04-24 21:48:35 +02002052
glepnirbcd59952025-04-24 21:48:35 +02002053 Examples: >
2054 set isexpand=.,->,/,/*,abc
2055 func CustomComplete()
2056 let res = complete_match()
2057 if res->len() == 0 | return | endif
2058 let [col, trigger] = res[0]
2059 let items = []
2060 if trigger == '/*'
2061 let items = ['/** */']
2062 elseif trigger == '/'
2063 let items = ['/*! */', '// TODO:', '// fixme:']
2064 elseif trigger == '.'
2065 let items = ['length()']
2066 elseif trigger =~ '^\->'
2067 let items = ['map()', 'reduce()']
2068 elseif trigger =~ '^\abc'
2069 let items = ['def', 'ghk']
2070 endif
2071 if items->len() > 0
2072 let startcol = trigger =~ '^/' ? col : col + len(trigger)
2073 call complete(startcol, items)
2074 endif
2075 endfunc
2076 inoremap <Tab> <Cmd>call CustomComplete()<CR>
2077<
2078 Return type: list<list<any>>
2079
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002080 *confirm()*
2081confirm({msg} [, {choices} [, {default} [, {type}]]])
2082 confirm() offers the user a dialog, from which a choice can be
2083 made. It returns the number of the choice. For the first
2084 choice this is 1.
2085 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002086 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002087
2088 {msg} is displayed in a |dialog| with {choices} as the
2089 alternatives. When {choices} is missing or empty, "&OK" is
2090 used (and translated).
2091 {msg} is a String, use '\n' to include a newline. Only on
2092 some systems the string is wrapped when it doesn't fit.
2093
2094 {choices} is a String, with the individual choices separated
2095 by '\n', e.g. >
2096 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2097< The letter after the '&' is the shortcut key for that choice.
2098 Thus you can type 'c' to select "Cancel". The shortcut does
2099 not need to be the first letter: >
2100 confirm("file has been modified", "&Save\nSave &All")
2101< For the console, the first letter of each choice is used as
2102 the default shortcut key. Case is ignored.
2103
2104 The optional {default} argument is the number of the choice
2105 that is made if the user hits <CR>. Use 1 to make the first
2106 choice the default one. Use 0 to not set a default. If
2107 {default} is omitted, 1 is used.
2108
2109 The optional {type} String argument gives the type of dialog.
2110 This is only used for the icon of the GTK, Mac, Motif and
2111 Win32 GUI. It can be one of these values: "Error",
2112 "Question", "Info", "Warning" or "Generic". Only the first
2113 character is relevant. When {type} is omitted, "Generic" is
2114 used.
2115
2116 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2117 or another valid interrupt key, confirm() returns 0.
2118
2119 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002120 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002121 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002122 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002123 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002124 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002125 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002126 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002127 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002128 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002129< In a GUI dialog, buttons are used. The layout of the buttons
2130 depends on the 'v' flag in 'guioptions'. If it is included,
2131 the buttons are always put vertically. Otherwise, confirm()
2132 tries to put the buttons in one horizontal line. If they
2133 don't fit, a vertical layout is used anyway. For some systems
2134 the horizontal layout is always used.
2135
2136 Can also be used as a |method|in: >
2137 BuildMessage()->confirm("&Yes\n&No")
2138<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002139 Return type: |Number|
2140
2141
2142copy({expr}) *copy()*
2143 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002144 different from using {expr} directly.
2145 When {expr} is a |List| a shallow copy is created. This means
2146 that the original |List| can be changed without changing the
2147 copy, and vice versa. But the items are identical, thus
2148 changing an item changes the contents of both |Lists|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002149 A |Tuple| or |Dictionary| is copied in a similar way as a
2150 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002151 Also see |deepcopy()|.
2152 Can also be used as a |method|: >
2153 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002154<
2155 Return type: any, depending on {expr}
2156
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002157
2158cos({expr}) *cos()*
2159 Return the cosine of {expr}, measured in radians, as a |Float|.
2160 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002161 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002162 Examples: >
2163 :echo cos(100)
2164< 0.862319 >
2165 :echo cos(-4.01)
2166< -0.646043
2167
2168 Can also be used as a |method|: >
2169 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002170<
2171 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002172
2173
2174cosh({expr}) *cosh()*
2175 Return the hyperbolic cosine of {expr} as a |Float| in the range
2176 [1, inf].
2177 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002178 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002179 Examples: >
2180 :echo cosh(0.5)
2181< 1.127626 >
2182 :echo cosh(-0.5)
2183< -1.127626
2184
2185 Can also be used as a |method|: >
2186 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002187<
2188 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002189
2190
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002191count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002192 Return the number of times an item with value {expr} appears
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002193 in |String|, |List|, |Tuple| or |Dictionary| {comp}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002194
2195 If {start} is given then start with the item with this index.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002196 {start} can only be used with a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002197
2198 When {ic} is given and it's |TRUE| then case is ignored.
2199
2200 When {comp} is a string then the number of not overlapping
2201 occurrences of {expr} is returned. Zero is returned when
2202 {expr} is an empty string.
2203
2204 Can also be used as a |method|: >
2205 mylist->count(val)
2206<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002207 Return type: |Number|
2208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002209 *cscope_connection()*
2210cscope_connection([{num} , {dbpath} [, {prepend}]])
2211 Checks for the existence of a |cscope| connection. If no
2212 parameters are specified, then the function returns:
2213 0, if cscope was not available (not compiled in), or
2214 if there are no cscope connections;
2215 1, if there is at least one cscope connection.
2216
2217 If parameters are specified, then the value of {num}
2218 determines how existence of a cscope connection is checked:
2219
2220 {num} Description of existence check
2221 ----- ------------------------------
2222 0 Same as no parameters (e.g., "cscope_connection()").
2223 1 Ignore {prepend}, and use partial string matches for
2224 {dbpath}.
2225 2 Ignore {prepend}, and use exact string matches for
2226 {dbpath}.
2227 3 Use {prepend}, use partial string matches for both
2228 {dbpath} and {prepend}.
2229 4 Use {prepend}, use exact string matches for both
2230 {dbpath} and {prepend}.
2231
2232 Note: All string comparisons are case sensitive!
2233
2234 Examples. Suppose we had the following (from ":cs show"): >
2235
2236 # pid database name prepend path
2237 0 27664 cscope.out /usr/local
2238<
2239 Invocation Return Val ~
2240 ---------- ---------- >
2241 cscope_connection() 1
2242 cscope_connection(1, "out") 1
2243 cscope_connection(2, "out") 0
2244 cscope_connection(3, "out") 0
2245 cscope_connection(3, "out", "local") 1
2246 cscope_connection(4, "out") 0
2247 cscope_connection(4, "out", "local") 0
2248 cscope_connection(4, "cscope.out", "/usr/local") 1
2249<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002250 Return type: |Number|
2251
2252
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002253cursor({lnum}, {col} [, {off}]) *cursor()*
2254cursor({list})
2255 Positions the cursor at the column (byte count) {col} in the
2256 line {lnum}. The first column is one.
2257
2258 When there is one argument {list} this is used as a |List|
2259 with two, three or four item:
2260 [{lnum}, {col}]
2261 [{lnum}, {col}, {off}]
2262 [{lnum}, {col}, {off}, {curswant}]
2263 This is like the return value of |getpos()| or |getcurpos()|,
2264 but without the first item.
2265
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002266 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002267 |setcursorcharpos()|.
2268
2269 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002270 {lnum} is used like with |getline()|, except that if {lnum} is
2271 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002272 If {lnum} is greater than the number of lines in the buffer,
2273 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002274 If {col} is greater than the number of bytes in the line,
2275 the cursor will be positioned at the last character in the
2276 line.
2277 If {col} is zero, the cursor will stay in the current column.
2278 If {curswant} is given it is used to set the preferred column
2279 for vertical movement. Otherwise {col} is used.
2280
2281 When 'virtualedit' is used {off} specifies the offset in
2282 screen columns from the start of the character. E.g., a
2283 position within a <Tab> or after the last character.
2284 Returns 0 when the position could be set, -1 otherwise.
2285
2286 Can also be used as a |method|: >
2287 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002288<
2289 Return type: |Number|
2290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002291
2292debugbreak({pid}) *debugbreak()*
2293 Specifically used to interrupt a program being debugged. It
2294 will cause process {pid} to get a SIGTRAP. Behavior for other
2295 processes is undefined. See |terminal-debugger|.
2296 {only available on MS-Windows}
2297
Bram Moolenaar016188f2022-06-06 20:52:59 +01002298 Returns |TRUE| if successfully interrupted the program.
2299 Otherwise returns |FALSE|.
2300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002301 Can also be used as a |method|: >
2302 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002303<
2304 Return type: |Number|
2305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002306
2307deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2308 Make a copy of {expr}. For Numbers and Strings this isn't
2309 different from using {expr} directly.
2310 When {expr} is a |List| a full copy is created. This means
2311 that the original |List| can be changed without changing the
2312 copy, and vice versa. When an item is a |List| or
2313 |Dictionary|, a copy for it is made, recursively. Thus
2314 changing an item in the copy does not change the contents of
2315 the original |List|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002316 A |Tuple| or |Dictionary| is copied in a similar way as a
2317 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002318
2319 When {noref} is omitted or zero a contained |List| or
2320 |Dictionary| is only copied once. All references point to
2321 this single copy. With {noref} set to 1 every occurrence of a
2322 |List| or |Dictionary| results in a new copy. This also means
2323 that a cyclic reference causes deepcopy() to fail.
2324 *E724*
2325 Nesting is possible up to 100 levels. When there is an item
2326 that refers back to a higher level making a deep copy with
2327 {noref} set to 1 will fail.
2328 Also see |copy()|.
2329
2330 Can also be used as a |method|: >
2331 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002332<
2333 Return type: any, depending on {expr}
2334
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002335
2336delete({fname} [, {flags}]) *delete()*
2337 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002338 name {fname}.
2339
2340 This also works when {fname} is a symbolic link. The symbolic
2341 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002342
2343 When {flags} is "d": Deletes the directory by the name
2344 {fname}. This fails when directory {fname} is not empty.
2345
2346 When {flags} is "rf": Deletes the directory by the name
2347 {fname} and everything in it, recursively. BE CAREFUL!
2348 Note: on MS-Windows it is not possible to delete a directory
2349 that is being used.
2350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002351 The result is a Number, which is 0/false if the delete
2352 operation was successful and -1/true when the deletion failed
2353 or partly failed.
2354
2355 Use |remove()| to delete an item from a |List|.
2356 To delete a line from the buffer use |:delete| or
2357 |deletebufline()|.
2358
2359 Can also be used as a |method|: >
2360 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002361<
2362 Return type: |Number|
2363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002364
2365deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2366 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2367 If {last} is omitted then delete line {first} only.
2368 On success 0 is returned, on failure 1 is returned.
2369
2370 This function works only for loaded buffers. First call
2371 |bufload()| if needed.
2372
2373 For the use of {buf}, see |bufname()| above.
2374
2375 {first} and {last} are used like with |getline()|. Note that
2376 when using |line()| this refers to the current buffer. Use "$"
2377 to refer to the last line in buffer {buf}.
2378
2379 Can also be used as a |method|: >
2380 GetBuffer()->deletebufline(1)
2381<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002382 Return type: |Number|
2383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002384 *did_filetype()*
2385did_filetype() Returns |TRUE| when autocommands are being executed and the
2386 FileType event has been triggered at least once. Can be used
2387 to avoid triggering the FileType event again in the scripts
2388 that detect the file type. |FileType|
2389 Returns |FALSE| when `:setf FALLBACK` was used.
2390 When editing another file, the counter is reset, thus this
2391 really checks if the FileType event has been triggered for the
2392 current buffer. This allows an autocommand that starts
2393 editing another buffer to set 'filetype' and load a syntax
2394 file.
2395
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002396 Return type: |Number|
2397
2398
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002399diff({fromlist}, {tolist} [, {options}]) *diff()*
2400 Returns a String or a List containing the diff between the
2401 strings in {fromlist} and {tolist}. Uses the Vim internal
2402 diff library to compute the diff.
2403
2404 *E106*
2405 The optional "output" item in {options} specifies the returned
2406 diff format. The following values are supported:
2407 indices Return a List of the starting and ending
2408 indices and a count of the strings in each
2409 diff hunk.
2410 unified Return the unified diff output as a String.
2411 This is the default.
2412
2413 If the "output" item in {options} is "indices", then a List is
2414 returned. Each List item contains a Dict with the following
2415 items for each diff hunk:
2416 from_idx start index in {fromlist} for this diff hunk.
2417 from_count number of strings in {fromlist} that are
2418 added/removed/modified in this diff hunk.
2419 to_idx start index in {tolist} for this diff hunk.
2420 to_count number of strings in {tolist} that are
2421 added/removed/modified in this diff hunk.
2422
2423 The {options} Dict argument also specifies diff options
2424 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002425 algorithm Dict specifying the diff algorithm to
2426 use. Supported boolean items are
2427 "myers", "minimal", "patience" and
2428 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002429 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002430 iblank ignore changes where lines are all
2431 blank.
2432 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002433 indent-heuristic use the indent heuristic for the
2434 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002435 iwhite ignore changes in amount of white
2436 space.
2437 iwhiteall ignore all white space changes.
2438 iwhiteeol ignore white space changes at end of
2439 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002440 For more information about these options, refer to 'diffopt'.
2441
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002442 To compute the unified diff, all the items in {fromlist} are
2443 concatenated into a string using a newline separator and the
2444 same for {tolist}. The unified diff output uses line numbers.
2445
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002446 Returns an empty List or String if {fromlist} and {tolist} are
2447 identical.
2448
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002449 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002450 :echo diff(['abc'], ['xxx'])
2451 @@ -1 +1 @@
2452 -abc
2453 +xxx
2454
2455 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2456 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2457 :echo diff(readfile('oldfile'), readfile('newfile'))
2458 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002459<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002460 For more examples, refer to |diff-func-examples|
2461
2462 Can also be used as a |method|: >
2463 GetFromList->diff(to_list)
2464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002465 Return type: |String| or list<dict<number>> or list<any>
2466 depending on {options}
2467
2468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002469diff_filler({lnum}) *diff_filler()*
2470 Returns the number of filler lines above line {lnum}.
2471 These are the lines that were inserted at this point in
2472 another diff'ed window. These filler lines are shown in the
2473 display but don't exist in the buffer.
2474 {lnum} is used like with |getline()|. Thus "." is the current
2475 line, "'m" mark m, etc.
2476 Returns 0 if the current window is not in diff mode.
2477
2478 Can also be used as a |method|: >
2479 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002480<
2481 Return type: |Number|
2482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002483
2484diff_hlID({lnum}, {col}) *diff_hlID()*
2485 Returns the highlight ID for diff mode at line {lnum} column
2486 {col} (byte index). When the current line does not have a
2487 diff change zero is returned.
2488 {lnum} is used like with |getline()|. Thus "." is the current
2489 line, "'m" mark m, etc.
2490 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2491 line.
2492 The highlight ID can be used with |synIDattr()| to obtain
2493 syntax information about the highlighting.
2494
2495 Can also be used as a |method|: >
2496 GetLnum()->diff_hlID(col)
2497<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002498 Return type: |Number|
2499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002500
2501digraph_get({chars}) *digraph_get()* *E1214*
2502 Return the digraph of {chars}. This should be a string with
2503 exactly two characters. If {chars} are not just two
2504 characters, or the digraph of {chars} does not exist, an error
2505 is given and an empty string is returned.
2506
2507 The character will be converted from Unicode to 'encoding'
2508 when needed. This does require the conversion to be
2509 available, it might fail.
2510
2511 Also see |digraph_getlist()|.
2512
2513 Examples: >
2514 " Get a built-in digraph
2515 :echo digraph_get('00') " Returns '∞'
2516
2517 " Get a user-defined digraph
2518 :call digraph_set('aa', 'あ')
2519 :echo digraph_get('aa') " Returns 'あ'
2520<
2521 Can also be used as a |method|: >
2522 GetChars()->digraph_get()
2523<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002524 Return type: |String|
2525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002526 This function works only when compiled with the |+digraphs|
2527 feature. If this feature is disabled, this function will
2528 display an error message.
2529
2530
2531digraph_getlist([{listall}]) *digraph_getlist()*
2532 Return a list of digraphs. If the {listall} argument is given
2533 and it is TRUE, return all digraphs, including the default
2534 digraphs. Otherwise, return only user-defined digraphs.
2535
2536 The characters will be converted from Unicode to 'encoding'
2537 when needed. This does require the conservation to be
2538 available, it might fail.
2539
2540 Also see |digraph_get()|.
2541
2542 Examples: >
2543 " Get user-defined digraphs
2544 :echo digraph_getlist()
2545
2546 " Get all the digraphs, including default digraphs
2547 :echo digraph_getlist(1)
2548<
2549 Can also be used as a |method|: >
2550 GetNumber()->digraph_getlist()
2551<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002552 Return type: list<list<string>>
2553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002554 This function works only when compiled with the |+digraphs|
2555 feature. If this feature is disabled, this function will
2556 display an error message.
2557
2558
Bram Moolenaara2baa732022-02-04 16:09:54 +00002559digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002560 Add digraph {chars} to the list. {chars} must be a string
2561 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002562 encoded character. *E1215*
2563 Be careful, composing characters are NOT ignored. This
2564 function is similar to |:digraphs| command, but useful to add
2565 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002566
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002567 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002568 this fails an error message is given and v:false is returned.
2569
2570 If you want to define multiple digraphs at once, you can use
2571 |digraph_setlist()|.
2572
2573 Example: >
2574 call digraph_set(' ', 'あ')
2575<
2576 Can be used as a |method|: >
2577 GetString()->digraph_set('あ')
2578<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002579 Return type: |vim9-boolean|
2580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002581 This function works only when compiled with the |+digraphs|
2582 feature. If this feature is disabled, this function will
2583 display an error message.
2584
2585
2586digraph_setlist({digraphlist}) *digraph_setlist()*
2587 Similar to |digraph_set()| but this function can add multiple
2588 digraphs at once. {digraphlist} is a list composed of lists,
2589 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002590 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002591 Example: >
2592 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2593<
2594 It is similar to the following: >
2595 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2596 call digraph_set(chars, digraph)
2597 endfor
2598< Except that the function returns after the first error,
2599 following digraphs will not be added.
2600
2601 Can be used as a |method|: >
2602 GetList()->digraph_setlist()
2603<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002604 Return type: |vim9-boolean|
2605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002606 This function works only when compiled with the |+digraphs|
2607 feature. If this feature is disabled, this function will
2608 display an error message.
2609
2610
2611echoraw({string}) *echoraw()*
2612 Output {string} as-is, including unprintable characters.
2613 This can be used to output a terminal code. For example, to
2614 disable modifyOtherKeys: >
2615 call echoraw(&t_TE)
2616< and to enable it again: >
2617 call echoraw(&t_TI)
2618< Use with care, you can mess up the terminal this way.
2619
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002620 Return type: |Number|
2621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002622
2623empty({expr}) *empty()*
2624 Return the Number 1 if {expr} is empty, zero otherwise.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002625 - A |List|, |Tuple| or |Dictionary| is empty when it does
2626 not have any items.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002627 - A |String| is empty when its length is zero.
2628 - A |Number| and |Float| are empty when their value is zero.
2629 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2630 - A |Job| is empty when it failed to start.
2631 - A |Channel| is empty when it is closed.
2632 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002633 - An |Object| is empty, when the empty() method in the object
2634 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002635
2636 For a long |List| this is much faster than comparing the
2637 length with zero.
2638
2639 Can also be used as a |method|: >
2640 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002641<
2642 Return type: |Number|
2643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002644
2645environ() *environ()*
2646 Return all of environment variables as dictionary. You can
2647 check if an environment variable exists like this: >
2648 :echo has_key(environ(), 'HOME')
2649< Note that the variable name may be CamelCase; to ignore case
2650 use this: >
2651 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002652<
2653 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002654
Bram Moolenaar416bd912023-07-07 23:19:18 +01002655
2656err_teapot([{expr}]) *err_teapot()*
2657 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002658 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002659 If {expr} is present and it is TRUE error 503 is given,
2660 indicating that coffee is temporarily not available.
2661 If {expr} is present it must be a String.
2662
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002663 Return type: |Number|
2664
Bram Moolenaar416bd912023-07-07 23:19:18 +01002665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002666escape({string}, {chars}) *escape()*
2667 Escape the characters in {chars} that occur in {string} with a
2668 backslash. Example: >
2669 :echo escape('c:\program files\vim', ' \')
2670< results in: >
2671 c:\\program\ files\\vim
2672< Also see |shellescape()| and |fnameescape()|.
2673
2674 Can also be used as a |method|: >
2675 GetText()->escape(' \')
2676<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002677 Return type: |String|
2678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679 *eval()*
2680eval({string}) Evaluate {string} and return the result. Especially useful to
2681 turn the result of |string()| back into the original value.
2682 This works for Numbers, Floats, Strings, Blobs and composites
2683 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002684 functions. In |Vim9| script, it can be used to obtain |enum|
2685 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002686
2687 Can also be used as a |method|: >
2688 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002689<
2690 Return type: any, depending on {string}
2691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002692
2693eventhandler() *eventhandler()*
2694 Returns 1 when inside an event handler. That is that Vim got
2695 interrupted while waiting for the user to type a character,
2696 e.g., when dropping a file on Vim. This means interactive
2697 commands cannot be used. Otherwise zero is returned.
2698
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002699 Return type: |Number|
2700
2701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002702executable({expr}) *executable()*
2703 This function checks if an executable with the name {expr}
2704 exists. {expr} must be the name of the program without any
2705 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002707 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002708 searchpath for programs.
2709 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002710 On MS-Windows the ".exe", ".bat", etc. can optionally be
2711 included. Then the extensions in $PATHEXT are tried. Thus if
2712 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2713 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2714 by itself can be used in $PATHEXT to try using the name
2715 without an extension. When 'shell' looks like a Unix shell,
2716 then the name is also tried without adding an extension.
2717 On MS-Windows it only checks if the file exists and is not a
2718 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002719 On MS-Windows an executable in the same directory as the Vim
2720 executable is always found. Since this directory is added to
2721 $PATH it should also work to execute it |win32-PATH|.
2722 *NoDefaultCurrentDirectoryInExePath*
2723 On MS-Windows an executable in Vim's current working directory
2724 is also normally found, but this can be disabled by setting
2725 the $NoDefaultCurrentDirectoryInExePath environment variable.
2726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002727 The result is a Number:
2728 1 exists
2729 0 does not exist
2730 -1 not implemented on this system
2731 |exepath()| can be used to get the full path of an executable.
2732
2733 Can also be used as a |method|: >
2734 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002735<
2736 Return type: |Number|
2737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002738
2739execute({command} [, {silent}]) *execute()*
2740 Execute an Ex command or commands and return the output as a
2741 string.
2742 {command} can be a string or a List. In case of a List the
2743 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002744 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002745 redir => var
2746 {command}
2747 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002748< Except that line continuation in {command} is not recognized.
2749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002750 The optional {silent} argument can have these values:
2751 "" no `:silent` used
2752 "silent" `:silent` used
2753 "silent!" `:silent!` used
2754 The default is "silent". Note that with "silent!", unlike
2755 `:redir`, error messages are dropped. When using an external
2756 command the screen may be messed up, use `system()` instead.
2757 *E930*
2758 It is not possible to use `:redir` anywhere in {command}.
2759
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002760 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002761 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002762
2763< To execute a command in another window than the current one
2764 use `win_execute()`.
2765
2766 When used recursively the output of the recursive call is not
2767 included in the output of the higher level call.
2768
2769 Can also be used as a |method|: >
2770 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002771<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002772 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002774
2775exepath({expr}) *exepath()*
2776 If {expr} is an executable and is either an absolute path, a
2777 relative path or found in $PATH, return the full path.
2778 Note that the current directory is used when {expr} starts
2779 with "./", which may be a problem for Vim: >
2780 echo exepath(v:progpath)
2781< If {expr} cannot be found in $PATH or is not executable then
2782 an empty string is returned.
2783
2784 Can also be used as a |method|: >
2785 GetCommand()->exepath()
2786<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002787 Return type: |String|
2788
2789
2790exists({expr}) *exists()*
2791 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002792 zero otherwise.
2793
2794 Note: In a compiled |:def| function the evaluation is done at
2795 runtime. Use `exists_compiled()` to evaluate the expression
2796 at compile time.
2797
2798 For checking for a supported feature use |has()|.
2799 For checking if a file exists use |filereadable()|.
2800
2801 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002802 varname internal variable (see
2803 dict.key |internal-variables|). Also works
2804 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002805 import.Func entries, |List| items, class and
2806 class.Func object methods, imported items, etc.
2807 object.Func Does not work for local variables in a
2808 class.varname compiled `:def` function.
2809 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002810 script, since it can be used as a
2811 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002812 Beware that evaluating an index may
2813 cause an error message for an invalid
2814 expression. E.g.: >
2815 :let l = [1, 2, 3]
2816 :echo exists("l[5]")
2817< 0 >
2818 :echo exists("l[xx]")
2819< E121: Undefined variable: xx
2820 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002821 &option-name Vim option (only checks if it exists,
2822 not if it really works)
2823 +option-name Vim option that works.
2824 $ENVNAME environment variable (could also be
2825 done by comparing with an empty
2826 string)
2827 *funcname built-in function (see |functions|)
2828 or user defined function (see
2829 |user-functions|) that is implemented.
2830 Also works for a variable that is a
2831 Funcref.
2832 ?funcname built-in function that could be
2833 implemented; to be used to check if
2834 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002835 :cmdname Ex command: built-in command, user
2836 command or command modifier |:command|.
2837 Returns:
2838 1 for match with start of a command
2839 2 full match with a command
2840 3 matches several user commands
2841 To check for a supported command
2842 always check the return value to be 2.
2843 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002844 :3match The |:3match| command (but you
2845 probably should not use it, it is
2846 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002847 #event autocommand defined for this event
2848 #event#pattern autocommand defined for this event and
2849 pattern (the pattern is taken
2850 literally and compared to the
2851 autocommand patterns character by
2852 character)
2853 #group autocommand group exists
2854 #group#event autocommand defined for this group and
2855 event.
2856 #group#event#pattern
2857 autocommand defined for this group,
2858 event and pattern.
2859 ##event autocommand for this event is
2860 supported.
2861
2862 Examples: >
2863 exists("&shortname")
2864 exists("$HOSTNAME")
2865 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002866 exists("*s:MyFunc") " only for legacy script
2867 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002868 exists("bufcount")
2869 exists(":Make")
2870 exists("#CursorHold")
2871 exists("#BufReadPre#*.gz")
2872 exists("#filetypeindent")
2873 exists("#filetypeindent#FileType")
2874 exists("#filetypeindent#FileType#*")
2875 exists("##ColorScheme")
2876< There must be no space between the symbol (&/$/*/#) and the
2877 name.
2878 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002879 a few cases this is ignored. That may become stricter in the
2880 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002881 Working example: >
2882 exists(":make")
2883< NOT working example: >
2884 exists(":make install")
2885
2886< Note that the argument must be a string, not the name of the
2887 variable itself. For example: >
2888 exists(bufcount)
2889< This doesn't check for existence of the "bufcount" variable,
2890 but gets the value of "bufcount", and checks if that exists.
2891
2892 Can also be used as a |method|: >
2893 Varname()->exists()
2894<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002895 Return type: |String|
2896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002897
2898exists_compiled({expr}) *exists_compiled()*
2899 Like `exists()` but evaluated at compile time. This is useful
2900 to skip a block where a function is used that would otherwise
2901 give an error: >
2902 if exists_compiled('*ThatFunction')
2903 ThatFunction('works')
2904 endif
2905< If `exists()` were used then a compilation error would be
2906 given if ThatFunction() is not defined.
2907
2908 {expr} must be a literal string. *E1232*
2909 Can only be used in a |:def| function. *E1233*
2910 This does not work to check for arguments or local variables.
2911
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002912 Return type: |String|
2913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002914
2915exp({expr}) *exp()*
2916 Return the exponential of {expr} as a |Float| in the range
2917 [0, inf].
2918 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002919 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002920 Examples: >
2921 :echo exp(2)
2922< 7.389056 >
2923 :echo exp(-1)
2924< 0.367879
2925
2926 Can also be used as a |method|: >
2927 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002928<
2929 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002930
2931
2932expand({string} [, {nosuf} [, {list}]]) *expand()*
2933 Expand wildcards and the following special keywords in
2934 {string}. 'wildignorecase' applies.
2935
2936 If {list} is given and it is |TRUE|, a List will be returned.
2937 Otherwise the result is a String and when there are several
2938 matches, they are separated by <NL> characters. [Note: in
2939 version 5.0 a space was used, which caused problems when a
2940 file name contains a space]
2941
2942 If the expansion fails, the result is an empty string. A name
2943 for a non-existing file is not included, unless {string} does
2944 not start with '%', '#' or '<', see below.
2945
Christian Brabandtec9c3262024-02-21 20:40:05 +01002946 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002947 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002948
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002949 When {string} starts with '%', '#' or '<', the expansion is
2950 done like for the |cmdline-special| variables with their
2951 associated modifiers. Here is a short overview:
2952
2953 % current file name
2954 # alternate file name
2955 #n alternate file name n
2956 <cfile> file name under the cursor
2957 <afile> autocmd file name
2958 <abuf> autocmd buffer number (as a String!)
2959 <amatch> autocmd matched name
2960 <cexpr> C expression under the cursor
2961 <sfile> sourced script file or function name
2962 <slnum> sourced script line number or function
2963 line number
2964 <sflnum> script file line number, also when in
2965 a function
2966 <SID> "<SNR>123_" where "123" is the
2967 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002968 <script> sourced script file, or script file
2969 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002970 <stack> call stack
2971 <cword> word under the cursor
2972 <cWORD> WORD under the cursor
2973 <client> the {clientid} of the last received
2974 message |server2client()|
2975 Modifiers:
2976 :p expand to full path
2977 :h head (last path component removed)
2978 :t tail (last path component only)
2979 :r root (one extension removed)
2980 :e extension only
2981
2982 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002983 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002984< Note that when expanding a string that starts with '%', '#' or
2985 '<', any following text is ignored. This does NOT work: >
2986 :let doesntwork = expand("%:h.bak")
2987< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002988 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002989< Also note that expanding "<cfile>" and others only returns the
2990 referenced file name without further expansion. If "<cfile>"
2991 is "~/.cshrc", you need to do another expand() to have the
2992 "~/" expanded into the path of the home directory: >
2993 :echo expand(expand("<cfile>"))
2994<
2995 There cannot be white space between the variables and the
2996 following modifier. The |fnamemodify()| function can be used
2997 to modify normal file names.
2998
2999 When using '%' or '#', and the current or alternate file name
3000 is not defined, an empty string is used. Using "%:p" in a
3001 buffer with no name, results in the current directory, with a
3002 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01003003 When 'verbose' is set then expanding '%', '#' and <> items
3004 will result in an error message if the argument cannot be
3005 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003006
3007 When {string} does not start with '%', '#' or '<', it is
3008 expanded like a file name is expanded on the command line.
3009 'suffixes' and 'wildignore' are used, unless the optional
3010 {nosuf} argument is given and it is |TRUE|.
3011 Names for non-existing files are included. The "**" item can
3012 be used to search in a directory tree. For example, to find
3013 all "README" files in the current directory and below: >
3014 :echo expand("**/README")
3015<
3016 expand() can also be used to expand variables and environment
3017 variables that are only known in a shell. But this can be
3018 slow, because a shell may be used to do the expansion. See
3019 |expr-env-expand|.
3020 The expanded variable is still handled like a list of file
3021 names. When an environment variable cannot be expanded, it is
3022 left unchanged. Thus ":echo expand('$FOOBAR')" results in
3023 "$FOOBAR".
3024
3025 See |glob()| for finding existing files. See |system()| for
3026 getting the raw output of an external command.
3027
3028 Can also be used as a |method|: >
3029 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003030<
3031 Return type: |String| or list<string> depending on {list}
3032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003033
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003034expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003035 Expand special items in String {string} like what is done for
3036 an Ex command such as `:edit`. This expands special keywords,
3037 like with |expand()|, and environment variables, anywhere in
3038 {string}. "~user" and "~/path" are only expanded at the
3039 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003040
3041 The following items are supported in the {options} Dict
3042 argument:
3043 errmsg If set to TRUE, error messages are displayed
3044 if an error is encountered during expansion.
3045 By default, error messages are not displayed.
3046
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003047 Returns the expanded string. If an error is encountered
3048 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003049
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003050 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003052 make /path/runtime/doc/builtin.o
3053 :echo expandcmd('make %<.o', {'errmsg': v:true})
3054<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003055 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003056 GetCommand()->expandcmd()
3057<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003058 Return type: |String| or list<string> depending on {list}
3059
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003060extend({expr1}, {expr2} [, {expr3}]) *extend()*
3061 {expr1} and {expr2} must be both |Lists| or both
3062 |Dictionaries|.
3063
3064 If they are |Lists|: Append {expr2} to {expr1}.
3065 If {expr3} is given insert the items of {expr2} before the
3066 item with index {expr3} in {expr1}. When {expr3} is zero
3067 insert before the first item. When {expr3} is equal to
3068 len({expr1}) then {expr2} is appended.
3069 Examples: >
3070 :echo sort(extend(mylist, [7, 5]))
3071 :call extend(mylist, [2, 3], 1)
3072< When {expr1} is the same List as {expr2} then the number of
3073 items copied is equal to the original length of the List.
3074 E.g., when {expr3} is 1 you get N new copies of the first item
3075 (where N is the original length of the List).
3076 Use |add()| to concatenate one item to a list. To concatenate
3077 two lists into a new list use the + operator: >
3078 :let newlist = [1, 2, 3] + [4, 5]
3079<
3080 If they are |Dictionaries|:
3081 Add all entries from {expr2} to {expr1}.
3082 If a key exists in both {expr1} and {expr2} then {expr3} is
3083 used to decide what to do:
3084 {expr3} = "keep": keep the value of {expr1}
3085 {expr3} = "force": use the value of {expr2}
3086 {expr3} = "error": give an error message *E737*
3087 When {expr3} is omitted then "force" is assumed.
3088
3089 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003090 make a copy of {expr1} first or use |extendnew()| to return a
3091 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003092 {expr2} remains unchanged.
3093 When {expr1} is locked and {expr2} is not empty the operation
3094 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003095 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003096
3097 Can also be used as a |method|: >
3098 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003099<
3100 Return type: list<{type}> or dict<{type}> depending on {expr1}
3101 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003102
3103
3104extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3105 Like |extend()| but instead of adding items to {expr1} a new
3106 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003107 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003108
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003109 Return type: list<{type}> or dict<{type}> depending on {expr1}
3110 and {expr2}, in case of error: |Number|
3111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003112
3113feedkeys({string} [, {mode}]) *feedkeys()*
3114 Characters in {string} are queued for processing as if they
3115 come from a mapping or were typed by the user.
3116
3117 By default the string is added to the end of the typeahead
3118 buffer, thus if a mapping is still being executed the
3119 characters come after them. Use the 'i' flag to insert before
3120 other characters, they will be executed next, before any
3121 characters from a mapping.
3122
3123 The function does not wait for processing of keys contained in
3124 {string}.
3125
3126 To include special keys into {string}, use double-quotes
3127 and "\..." notation |expr-quote|. For example,
3128 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3129 feedkeys('\<CR>') pushes 5 characters.
3130 A special code that might be useful is <Ignore>, it exits the
3131 wait for a character without doing anything. *<Ignore>*
3132
3133 {mode} is a String, which can contain these character flags:
3134 'm' Remap keys. This is default. If {mode} is absent,
3135 keys are remapped.
3136 'n' Do not remap keys.
3137 't' Handle keys as if typed; otherwise they are handled as
3138 if coming from a mapping. This matters for undo,
3139 opening folds, etc.
3140 'L' Lowlevel input. Only works for Unix or when using the
3141 GUI. Keys are used as if they were coming from the
3142 terminal. Other flags are not used. *E980*
3143 When a CTRL-C interrupts and 't' is included it sets
3144 the internal "got_int" flag.
3145 'i' Insert the string instead of appending (see above).
3146 'x' Execute commands until typeahead is empty. This is
3147 similar to using ":normal!". You can call feedkeys()
3148 several times without 'x' and then one time with 'x'
3149 (possibly with an empty {string}) to execute all the
3150 typeahead. Note that when Vim ends in Insert mode it
3151 will behave as if <Esc> is typed, to avoid getting
3152 stuck, waiting for a character to be typed before the
3153 script continues.
3154 Note that if you manage to call feedkeys() while
3155 executing commands, thus calling it recursively, then
3156 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003157 'c' Remove any script context when executing, so that
3158 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003159 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003160 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003161 '!' When used with 'x' will not end Insert mode. Can be
3162 used in a test when a timer is set to exit Insert mode
3163 a little later. Useful for testing CursorHoldI.
3164
3165 Return value is always 0.
3166
3167 Can also be used as a |method|: >
3168 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003169<
Christian Brabandt17ad8522025-05-09 00:03:20 +02003170 Return type: |Number|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003172
Shougo Matsushita60c87432024-06-03 22:59:27 +02003173filecopy({from}, {to}) *filecopy()*
3174 Copy the file pointed to by the name {from} to {to}. The
3175 result is a Number, which is |TRUE| if the file was copied
3176 successfully, and |FALSE| when it failed.
3177 If a file with name {to} already exists, it will fail.
3178 Note that it does not handle directories (yet).
3179
3180 This function is not available in the |sandbox|.
3181
3182 Can also be used as a |method|: >
3183 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003184<
3185 Return type: |Number|
3186
Shougo Matsushita60c87432024-06-03 22:59:27 +02003187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003188filereadable({file}) *filereadable()*
3189 The result is a Number, which is |TRUE| when a file with the
3190 name {file} exists, and can be read. If {file} doesn't exist,
3191 or is a directory, the result is |FALSE|. {file} is any
3192 expression, which is used as a String.
3193 If you don't care about the file being readable you can use
3194 |glob()|.
3195 {file} is used as-is, you may want to expand wildcards first: >
3196 echo filereadable('~/.vimrc')
3197 0
3198 echo filereadable(expand('~/.vimrc'))
3199 1
3200
3201< Can also be used as a |method|: >
3202 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003203<
3204 Return type: |Number|
3205
3206 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003207 Obsolete name: file_readable().
3208
3209
3210filewritable({file}) *filewritable()*
3211 The result is a Number, which is 1 when a file with the
3212 name {file} exists, and can be written. If {file} doesn't
3213 exist, or is not writable, the result is 0. If {file} is a
3214 directory, and we can write to it, the result is 2.
3215
3216 Can also be used as a |method|: >
3217 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003218<
3219 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003220
3221
3222filter({expr1}, {expr2}) *filter()*
3223 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3224 For each item in {expr1} evaluate {expr2} and when the result
3225 is zero or false remove the item from the |List| or
3226 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003227 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003228
3229 {expr2} must be a |string| or |Funcref|.
3230
3231 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3232 of the current item. For a |Dictionary| |v:key| has the key
3233 of the current item and for a |List| |v:key| has the index of
3234 the current item. For a |Blob| |v:key| has the index of the
3235 current byte. For a |String| |v:key| has the index of the
3236 current character.
3237 Examples: >
3238 call filter(mylist, 'v:val !~ "OLD"')
3239< Removes the items where "OLD" appears. >
3240 call filter(mydict, 'v:key >= 8')
3241< Removes the items with a key below 8. >
3242 call filter(var, 0)
3243< Removes all the items, thus clears the |List| or |Dictionary|.
3244
3245 Note that {expr2} is the result of expression and is then
3246 used as an expression again. Often it is good to use a
3247 |literal-string| to avoid having to double backslashes.
3248
3249 If {expr2} is a |Funcref| it must take two arguments:
3250 1. the key or the index of the current item.
3251 2. the value of the current item.
3252 The function must return |TRUE| if the item should be kept.
3253 Example that keeps the odd items of a list: >
3254 func Odd(idx, val)
3255 return a:idx % 2 == 1
3256 endfunc
3257 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003258< It is shorter when using a |lambda|. In |Vim9| syntax: >
3259 call filter(myList, (idx, val) => idx * val <= 42)
3260< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003261 call filter(myList, {idx, val -> idx * val <= 42})
3262< If you do not use "val" you can leave it out: >
3263 call filter(myList, {idx -> idx % 2 == 1})
3264<
3265 In |Vim9| script the result must be true, false, zero or one.
3266 Other values will result in a type error.
3267
3268 For a |List| and a |Dictionary| the operation is done
3269 in-place. If you want it to remain unmodified make a copy
3270 first: >
3271 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3272
3273< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003274 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003275 When an error is encountered while evaluating {expr2} no
3276 further items in {expr1} are processed.
3277 When {expr2} is a Funcref errors inside a function are ignored,
3278 unless it was defined with the "abort" flag.
3279
3280 Can also be used as a |method|: >
3281 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003282<
3283 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3284 depending on {expr1}
3285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003286
3287finddir({name} [, {path} [, {count}]]) *finddir()*
3288 Find directory {name} in {path}. Supports both downwards and
3289 upwards recursive directory searches. See |file-searching|
3290 for the syntax of {path}.
3291
3292 Returns the path of the first found match. When the found
3293 directory is below the current directory a relative path is
3294 returned. Otherwise a full path is returned.
3295 If {path} is omitted or empty then 'path' is used.
3296
3297 If the optional {count} is given, find {count}'s occurrence of
3298 {name} in {path} instead of the first one.
3299 When {count} is negative return all the matches in a |List|.
3300
Bram Moolenaar016188f2022-06-06 20:52:59 +01003301 Returns an empty string if the directory is not found.
3302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003303 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003304
3305 Can also be used as a |method|: >
3306 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003307<
Christian Brabandtb753d802025-04-21 11:31:58 +02003308 Return type: list<string> if {count} is negative, |String|
3309 otherwise
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003311
3312findfile({name} [, {path} [, {count}]]) *findfile()*
3313 Just like |finddir()|, but find a file instead of a directory.
3314 Uses 'suffixesadd'.
3315 Example: >
3316 :echo findfile("tags.vim", ".;")
3317< Searches from the directory of the current file upwards until
3318 it finds the file "tags.vim".
3319
3320 Can also be used as a |method|: >
3321 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003322<
Christian Brabandtb753d802025-04-21 11:31:58 +02003323 Return type: list<string> if {count} is negative, |String|
3324 otherwise
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003326
3327flatten({list} [, {maxdepth}]) *flatten()*
3328 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3329 the result is a |List| without nesting, as if {maxdepth} is
3330 a very large number.
3331 The {list} is changed in place, use |flattennew()| if you do
3332 not want that.
3333 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003334 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003335 *E900*
3336 {maxdepth} means how deep in nested lists changes are made.
3337 {list} is not modified when {maxdepth} is 0.
3338 {maxdepth} must be positive number.
3339
3340 If there is an error the number zero is returned.
3341
3342 Example: >
3343 :echo flatten([1, [2, [3, 4]], 5])
3344< [1, 2, 3, 4, 5] >
3345 :echo flatten([1, [2, [3, 4]], 5], 1)
3346< [1, 2, [3, 4], 5]
3347
3348 Can also be used as a |method|: >
3349 mylist->flatten()
3350<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003351 Return type: list<{type}>
3352
3353
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003354flattennew({list} [, {maxdepth}]) *flattennew()*
3355 Like |flatten()| but first make a copy of {list}.
3356
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003357 Return type: list<{type}>
3358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003359
3360float2nr({expr}) *float2nr()*
3361 Convert {expr} to a Number by omitting the part after the
3362 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003363 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003364 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003365 When the value of {expr} is out of range for a |Number| the
3366 result is truncated to 0x7fffffff or -0x7fffffff (or when
3367 64-bit Number support is enabled, 0x7fffffffffffffff or
3368 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3369 64-bit Number support is enabled, -0x8000000000000000).
3370 Examples: >
3371 echo float2nr(3.95)
3372< 3 >
3373 echo float2nr(-23.45)
3374< -23 >
3375 echo float2nr(1.0e100)
3376< 2147483647 (or 9223372036854775807) >
3377 echo float2nr(-1.0e150)
3378< -2147483647 (or -9223372036854775807) >
3379 echo float2nr(1.0e-100)
3380< 0
3381
3382 Can also be used as a |method|: >
3383 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003384<
3385 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003386
3387
3388floor({expr}) *floor()*
3389 Return the largest integral value less than or equal to
3390 {expr} as a |Float| (round down).
3391 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003392 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003393 Examples: >
3394 echo floor(1.856)
3395< 1.0 >
3396 echo floor(-5.456)
3397< -6.0 >
3398 echo floor(4.0)
3399< 4.0
3400
3401 Can also be used as a |method|: >
3402 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003403<
3404 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003405
3406
3407fmod({expr1}, {expr2}) *fmod()*
3408 Return the remainder of {expr1} / {expr2}, even if the
3409 division is not representable. Returns {expr1} - i * {expr2}
3410 for some integer i such that if {expr2} is non-zero, the
3411 result has the same sign as {expr1} and magnitude less than
3412 the magnitude of {expr2}. If {expr2} is zero, the value
3413 returned is zero. The value returned is a |Float|.
3414 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003415 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3416 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003417 Examples: >
3418 :echo fmod(12.33, 1.22)
3419< 0.13 >
3420 :echo fmod(-12.33, 1.22)
3421< -0.13
3422
3423 Can also be used as a |method|: >
3424 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003425<
3426 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427
3428
3429fnameescape({string}) *fnameescape()*
3430 Escape {string} for use as file name command argument. All
3431 characters that have a special meaning, such as '%' and '|'
3432 are escaped with a backslash.
3433 For most systems the characters escaped are
3434 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3435 appears in a filename, it depends on the value of 'isfname'.
3436 A leading '+' and '>' is also escaped (special after |:edit|
3437 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003438 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003439 Example: >
3440 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003441 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003442< results in executing: >
3443 edit \+some\ str\%nge\|name
3444<
3445 Can also be used as a |method|: >
3446 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003447<
3448 Return type: |String|
3449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003450
3451fnamemodify({fname}, {mods}) *fnamemodify()*
3452 Modify file name {fname} according to {mods}. {mods} is a
3453 string of characters like it is used for file names on the
3454 command line. See |filename-modifiers|.
3455 Example: >
3456 :echo fnamemodify("main.c", ":p:h")
3457< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003458 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003459< If {mods} is empty or an unsupported modifier is used then
3460 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003461 When {fname} is empty then with {mods} ":h" returns ".", so
3462 that `:cd` can be used with it. This is different from
3463 expand('%:h') without a buffer name, which returns an empty
3464 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003465 Note: Environment variables don't work in {fname}, use
3466 |expand()| first then.
3467
3468 Can also be used as a |method|: >
3469 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003470<
3471 Return type: |String|
3472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003473
3474foldclosed({lnum}) *foldclosed()*
3475 The result is a Number. If the line {lnum} is in a closed
3476 fold, the result is the number of the first line in that fold.
3477 If the line {lnum} is not in a closed fold, -1 is returned.
3478 {lnum} is used like with |getline()|. Thus "." is the current
3479 line, "'m" mark m, etc.
3480
3481 Can also be used as a |method|: >
3482 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003483<
3484 Return type: |Number|
3485
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003486
3487foldclosedend({lnum}) *foldclosedend()*
3488 The result is a Number. If the line {lnum} is in a closed
3489 fold, the result is the number of the last line in that fold.
3490 If the line {lnum} is not in a closed fold, -1 is returned.
3491 {lnum} is used like with |getline()|. Thus "." is the current
3492 line, "'m" mark m, etc.
3493
3494 Can also be used as a |method|: >
3495 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003496<
3497 Return type: |Number|
3498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003499
3500foldlevel({lnum}) *foldlevel()*
3501 The result is a Number, which is the foldlevel of line {lnum}
3502 in the current buffer. For nested folds the deepest level is
3503 returned. If there is no fold at line {lnum}, zero is
3504 returned. It doesn't matter if the folds are open or closed.
3505 When used while updating folds (from 'foldexpr') -1 is
3506 returned for lines where folds are still to be updated and the
3507 foldlevel is unknown. As a special case the level of the
3508 previous line is usually available.
3509 {lnum} is used like with |getline()|. Thus "." is the current
3510 line, "'m" mark m, etc.
3511
3512 Can also be used as a |method|: >
3513 GetLnum()->foldlevel()
3514<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003515 Return type: |Number|
3516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003517 *foldtext()*
3518foldtext() Returns a String, to be displayed for a closed fold. This is
3519 the default function used for the 'foldtext' option and should
3520 only be called from evaluating 'foldtext'. It uses the
3521 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3522 The returned string looks like this: >
3523 +-- 45 lines: abcdef
3524< The number of leading dashes depends on the foldlevel. The
3525 "45" is the number of lines in the fold. "abcdef" is the text
3526 in the first non-blank line of the fold. Leading white space,
3527 "//" or "/*" and the text from the 'foldmarker' and
3528 'commentstring' options is removed.
3529 When used to draw the actual foldtext, the rest of the line
3530 will be filled with the fold char from the 'fillchars'
3531 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003532 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003533
3534 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003535 {not available when compiled without the |+folding| feature}
3536
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003538foldtextresult({lnum}) *foldtextresult()*
3539 Returns the text that is displayed for the closed fold at line
3540 {lnum}. Evaluates 'foldtext' in the appropriate context.
3541 When there is no closed fold at {lnum} an empty string is
3542 returned.
3543 {lnum} is used like with |getline()|. Thus "." is the current
3544 line, "'m" mark m, etc.
3545 Useful when exporting folded text, e.g., to HTML.
3546 {not available when compiled without the |+folding| feature}
3547
3548
3549 Can also be used as a |method|: >
3550 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003551<
3552 Return type: |String|
3553
Ernie Raele79e2072024-01-13 11:47:33 +01003554
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003555foreach({expr1}, {expr2}) *foreach()* *E1525*
3556 {expr1} must be a |List|, |Tuple|, |String|, |Blob| or
3557 |Dictionary|.
Ernie Raele79e2072024-01-13 11:47:33 +01003558 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003559 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003560 See |map()| and |filter()| to modify {expr1}.
3561
3562 {expr2} must be a |string| or |Funcref|.
3563
3564 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3565 of the current item. For a |Dictionary| |v:key| has the key
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003566 of the current item and for a |List| or a |Tuple| |v:key| has
3567 the index of the current item. For a |Blob| |v:key| has the
3568 index of the current byte. For a |String| |v:key| has the
3569 index of the current character.
Ernie Raele79e2072024-01-13 11:47:33 +01003570 Examples: >
3571 call foreach(mylist, 'used[v:val] = true')
3572< This records the items that are in the {expr1} list.
3573
3574 Note that {expr2} is the result of expression and is then used
3575 as a command. Often it is good to use a |literal-string| to
3576 avoid having to double backslashes.
3577
3578 If {expr2} is a |Funcref| it must take two arguments:
3579 1. the key or the index of the current item.
3580 2. the value of the current item.
3581 With a legacy script lambda you don't get an error if it only
3582 accepts one argument, but with a Vim9 lambda you get "E1106:
3583 One argument too many", the number of arguments must match.
3584 If the function returns a value, it is ignored.
3585
3586 Returns {expr1} in all cases.
3587 When an error is encountered while executing {expr2} no
3588 further items in {expr1} are processed.
3589 When {expr2} is a Funcref errors inside a function are ignored,
3590 unless it was defined with the "abort" flag.
3591
3592 Can also be used as a |method|: >
3593 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003594<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003595 Return type: |String|, |Blob|, list<{type}>, tuple<{type}> or
3596 dict<{type}> depending on {expr1}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003598 *foreground()*
3599foreground() Move the Vim window to the foreground. Useful when sent from
3600 a client to a Vim server. |remote_send()|
3601 On Win32 systems this might not work, the OS does not always
3602 allow a window to bring itself to the foreground. Use
3603 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003604
3605 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003606 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 Win32 console version}
3608
Bram Moolenaaraa534142022-09-15 21:46:02 +01003609fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003610 Get the full command name from a short abbreviated command
3611 name; see |20.2| for details on command abbreviations.
3612
3613 The string argument {name} may start with a `:` and can
3614 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003615 Returns an empty string if a command doesn't exist, if it's
3616 ambiguous (for user-defined commands) or cannot be shortened
3617 this way. |vim9-no-shorten|
3618
3619 Without the {vim9} argument uses the current script version.
3620 If {vim9} is present and FALSE then legacy script rules are
3621 used. When {vim9} is present and TRUE then Vim9 rules are
3622 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003623
3624 For example `fullcommand('s')`, `fullcommand('sub')`,
3625 `fullcommand(':%substitute')` all return "substitute".
3626
3627 Can also be used as a |method|: >
3628 GetName()->fullcommand()
3629<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003630 Return type: |String|
3631
3632
3633funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003634 Just like |function()|, but the returned Funcref will lookup
3635 the function by reference, not by name. This matters when the
3636 function {name} is redefined later.
3637
3638 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003639 It only works for an autoloaded function if it has already
3640 been loaded (to avoid mistakenly loading the autoload script
3641 when only intending to use the function name, use |function()|
3642 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003643 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003644
3645 Can also be used as a |method|: >
3646 GetFuncname()->funcref([arg])
3647<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003648 Return type: func(...): any or |Number| on error
3649
Dominique Pellee764d1b2023-03-12 21:20:59 +00003650 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003651function({name} [, {arglist}] [, {dict}])
3652 Return a |Funcref| variable that refers to function {name}.
3653 {name} can be the name of a user defined function or an
3654 internal function.
3655
3656 {name} can also be a Funcref or a partial. When it is a
3657 partial the dict stored in it will be used and the {dict}
3658 argument is not allowed. E.g.: >
3659 let FuncWithArg = function(dict.Func, [arg])
3660 let Broken = function(dict.Func, [arg], dict)
3661<
3662 When using the Funcref the function will be found by {name},
3663 also when it was redefined later. Use |funcref()| to keep the
3664 same function.
3665
3666 When {arglist} or {dict} is present this creates a partial.
3667 That means the argument list and/or the dictionary is stored in
3668 the Funcref and will be used when the Funcref is called.
3669
3670 The arguments are passed to the function in front of other
3671 arguments, but after any argument from |method|. Example: >
3672 func Callback(arg1, arg2, name)
3673 ...
3674 let Partial = function('Callback', ['one', 'two'])
3675 ...
3676 call Partial('name')
3677< Invokes the function as with: >
3678 call Callback('one', 'two', 'name')
3679
3680< With a |method|: >
3681 func Callback(one, two, three)
3682 ...
3683 let Partial = function('Callback', ['two'])
3684 ...
3685 eval 'one'->Partial('three')
3686< Invokes the function as with: >
3687 call Callback('one', 'two', 'three')
3688
3689< The function() call can be nested to add more arguments to the
3690 Funcref. The extra arguments are appended to the list of
3691 arguments. Example: >
3692 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003693 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003694 let Func = function('Callback', ['one'])
3695 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003696 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003697 call Func2('name')
3698< Invokes the function as with: >
3699 call Callback('one', 'two', 'name')
3700
3701< The Dictionary is only useful when calling a "dict" function.
3702 In that case the {dict} is passed in as "self". Example: >
3703 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003704 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003705 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003706 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003707 let context = {"name": "example"}
3708 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003709 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003710 call Func() " will echo: called for example
3711< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003712 arguments, these two are equivalent, if Callback() is defined
3713 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003714 let Func = function('Callback', context)
3715 let Func = context.Callback
3716
3717< The argument list and the Dictionary can be combined: >
3718 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003719 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003720 let context = {"name": "example"}
3721 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003722 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003723 call Func(500)
3724< Invokes the function as with: >
3725 call context.Callback('one', 500)
3726<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003727 Returns 0 on error.
3728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003729 Can also be used as a |method|: >
3730 GetFuncname()->function([arg])
3731
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003732<
3733 Return type: func(...): any or |Number| on error
3734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003735
3736garbagecollect([{atexit}]) *garbagecollect()*
3737 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3738 that have circular references.
3739
3740 There is hardly ever a need to invoke this function, as it is
3741 automatically done when Vim runs out of memory or is waiting
3742 for the user to press a key after 'updatetime'. Items without
3743 circular references are always freed when they become unused.
3744 This is useful if you have deleted a very big |List| and/or
3745 |Dictionary| with circular references in a script that runs
3746 for a long time.
3747
3748 When the optional {atexit} argument is one, garbage
3749 collection will also be done when exiting Vim, if it wasn't
3750 done before. This is useful when checking for memory leaks.
3751
3752 The garbage collection is not done immediately but only when
3753 it's safe to perform. This is when waiting for the user to
3754 type a character. To force garbage collection immediately use
3755 |test_garbagecollect_now()|.
3756
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003757 Return type: |String|
3758
3759
LemonBoy48b7d052024-07-09 18:24:59 +02003760get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003761 Get item {idx} from |List| {list}. When this item is not
3762 available return {default}. Return zero when {default} is
3763 omitted.
3764 Preferably used as a |method|: >
3765 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003766<
3767 Return type: any, depending on {list}
3768
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003769get({tuple}, {idx} [, {default}]) *get()-tuple*
3770 Get item {idx} from |Tuple| {tuple}. When this item is not
3771 available return {default}. Return zero when {default} is
3772 omitted.
3773 Preferably used as a |method|: >
3774 mytuple->get(idx)
3775<
3776 Return type: any, depending on {tuple}
3777
LemonBoy48b7d052024-07-09 18:24:59 +02003778get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003779 Get byte {idx} from |Blob| {blob}. When this byte is not
3780 available return {default}. Return -1 when {default} is
3781 omitted.
3782 Preferably used as a |method|: >
3783 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003784<
3785 Return type: |Number|
3786
LemonBoy48b7d052024-07-09 18:24:59 +02003787get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003788 Get item with key {key} from |Dictionary| {dict}. When this
3789 item is not available return {default}. Return zero when
3790 {default} is omitted. Useful example: >
3791 let val = get(g:, 'var_name', 'default')
3792< This gets the value of g:var_name if it exists, and uses
3793 'default' when it does not exist.
3794 Preferably used as a |method|: >
3795 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003796<
h-east84ac2122024-06-17 18:12:30 +02003797 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003798
LemonBoy48b7d052024-07-09 18:24:59 +02003799get({func}, {what}) *get()-func*
3800 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003801 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003802 "name" The function name
3803 "func" The function
3804 "dict" The dictionary
3805 "args" The list with arguments
3806 "arity" A dictionary with information about the number of
3807 arguments accepted by the function (minus the
3808 {arglist}) with the following fields:
3809 required the number of positional arguments
3810 optional the number of optional arguments,
3811 in addition to the required ones
3812 varargs |TRUE| if the function accepts a
3813 variable number of arguments |...|
3814
3815 Note: There is no error, if the {arglist} of
3816 the Funcref contains more arguments than the
3817 Funcref expects, it's not validated.
3818
Bram Moolenaar016188f2022-06-06 20:52:59 +01003819 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003821 Preferably used as a |method|: >
3822 myfunc->get(what)
3823<
LemonBoy48b7d052024-07-09 18:24:59 +02003824 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003826 *getbufinfo()*
3827getbufinfo([{buf}])
3828getbufinfo([{dict}])
3829 Get information about buffers as a List of Dictionaries.
3830
3831 Without an argument information about all the buffers is
3832 returned.
3833
3834 When the argument is a |Dictionary| only the buffers matching
3835 the specified criteria are returned. The following keys can
3836 be specified in {dict}:
3837 buflisted include only listed buffers.
3838 bufloaded include only loaded buffers.
3839 bufmodified include only modified buffers.
3840
3841 Otherwise, {buf} specifies a particular buffer to return
3842 information for. For the use of {buf}, see |bufname()|
3843 above. If the buffer is found the returned List has one item.
3844 Otherwise the result is an empty list.
3845
3846 Each returned List item is a dictionary with the following
3847 entries:
3848 bufnr Buffer number.
3849 changed TRUE if the buffer is modified.
3850 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003851 command TRUE if the buffer belongs to the
3852 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003853 hidden TRUE if the buffer is hidden.
3854 lastused Timestamp in seconds, like
3855 |localtime()|, when the buffer was
3856 last used.
3857 {only with the |+viminfo| feature}
3858 listed TRUE if the buffer is listed.
3859 lnum Line number used for the buffer when
3860 opened in the current window.
3861 Only valid if the buffer has been
3862 displayed in the window in the past.
3863 If you want the line number of the
3864 last known cursor position in a given
3865 window, use |line()|: >
3866 :echo line('.', {winid})
3867<
3868 linecount Number of lines in the buffer (only
3869 valid when loaded)
3870 loaded TRUE if the buffer is loaded.
3871 name Full path to the file in the buffer.
3872 signs List of signs placed in the buffer.
3873 Each list item is a dictionary with
3874 the following fields:
3875 id sign identifier
3876 lnum line number
3877 name sign name
3878 variables A reference to the dictionary with
3879 buffer-local variables.
3880 windows List of |window-ID|s that display this
3881 buffer
3882 popups List of popup |window-ID|s that
3883 display this buffer
3884
3885 Examples: >
3886 for buf in getbufinfo()
3887 echo buf.name
3888 endfor
3889 for buf in getbufinfo({'buflisted':1})
3890 if buf.changed
3891 ....
3892 endif
3893 endfor
3894<
3895 To get buffer-local options use: >
3896 getbufvar({bufnr}, '&option_name')
3897<
3898 Can also be used as a |method|: >
3899 GetBufnr()->getbufinfo()
3900<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003901 Return type: list<dict<any>>
3902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003903
3904 *getbufline()*
3905getbufline({buf}, {lnum} [, {end}])
3906 Return a |List| with the lines starting from {lnum} to {end}
3907 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003908 |List| with only the line {lnum} is returned. See
3909 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003910
3911 For the use of {buf}, see |bufname()| above.
3912
3913 For {lnum} and {end} "$" can be used for the last line of the
3914 buffer. Otherwise a number must be used.
3915
3916 When {lnum} is smaller than 1 or bigger than the number of
3917 lines in the buffer, an empty |List| is returned.
3918
3919 When {end} is greater than the number of lines in the buffer,
3920 it is treated as {end} is set to the number of lines in the
3921 buffer. When {end} is before {lnum} an empty |List| is
3922 returned.
3923
3924 This function works only for loaded buffers. For unloaded and
3925 non-existing buffers, an empty |List| is returned.
3926
3927 Example: >
3928 :let lines = getbufline(bufnr("myfile"), 1, "$")
3929
3930< Can also be used as a |method|: >
3931 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003932<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003933 Return type: list<string>
3934
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003935 *getbufoneline()*
3936getbufoneline({buf}, {lnum})
3937 Just like `getbufline()` but only get one line and return it
3938 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003939
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003940 Return type: |String|
3941
3942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003943getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3944 The result is the value of option or local buffer variable
3945 {varname} in buffer {buf}. Note that the name without "b:"
3946 must be used.
3947 The {varname} argument is a string.
3948 When {varname} is empty returns a |Dictionary| with all the
3949 buffer-local variables.
3950 When {varname} is equal to "&" returns a |Dictionary| with all
3951 the buffer-local options.
3952 Otherwise, when {varname} starts with "&" returns the value of
3953 a buffer-local option.
3954 This also works for a global or buffer-local option, but it
3955 doesn't work for a global variable, window-local variable or
3956 window-local option.
3957 For the use of {buf}, see |bufname()| above.
3958 When the buffer or variable doesn't exist {def} or an empty
3959 string is returned, there is no error message.
3960 Examples: >
3961 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003962 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003963
3964< Can also be used as a |method|: >
3965 GetBufnr()->getbufvar(varname)
3966<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003967 Return type: any, depending on {varname}
3968
3969
mikoto20001083cae2024-11-11 21:24:14 +01003970getcellpixels() *getcellpixels()*
3971 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003972 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003973
3974 Only works on Unix (terminal and gVim) and Windows (gVim only).
3975 Returns [] on other systems or on failure.
3976 Note that there could be variations across different terminals.
3977 On macOS, system Terminal.app returns sizes in points (before
3978 Retina scaling), whereas third-party terminals return raw pixel
3979 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003980
mikoto2000de094dc2024-11-14 22:13:48 +01003981 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003982
3983
Kota Kato66bb9ae2023-01-17 18:31:56 +00003984getcellwidths() *getcellwidths()*
3985 Returns a |List| of cell widths of character ranges overridden
3986 by |setcellwidths()|. The format is equal to the argument of
3987 |setcellwidths()|. If no character ranges have their cell
3988 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003989
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003990 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003991
3992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003993getchangelist([{buf}]) *getchangelist()*
3994 Returns the |changelist| for the buffer {buf}. For the use
3995 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3996 exist, an empty list is returned.
3997
3998 The returned list contains two entries: a list with the change
3999 locations and the current position in the list. Each
4000 entry in the change list is a dictionary with the following
4001 entries:
4002 col column number
4003 coladd column offset for 'virtualedit'
4004 lnum line number
4005 If buffer {buf} is the current buffer, then the current
4006 position refers to the position in the list. For other
4007 buffers, it is set to the length of the list.
4008
4009 Can also be used as a |method|: >
4010 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004011<
4012 Return type: list<any>
4013
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004014
zeertzjqe0a2ab32025-02-02 09:14:35 +01004015getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004016 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01004017 If {expr} is omitted or is -1, wait until a character is
4018 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004019 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004020 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004021 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004022 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01004023 If you prefer always getting a string use |getcharstr()|, or
4024 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004025
Doug Kearns9cd9e752024-04-07 17:42:17 +02004026 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004027 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01004028 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004029 Otherwise a String is returned with the encoded character.
4030 For a special key it's a String with a sequence of bytes
4031 starting with 0x80 (decimal: 128). This is the same value as
4032 the String "\<Key>", e.g., "\<Left>". The returned value is
4033 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01004034 that is not included in the character. |keytrans()| can also
4035 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004036
Doug Kearns9cd9e752024-04-07 17:42:17 +02004037 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038 while Vim waits to see if this is the start of an escape
4039 sequence.
4040
Doug Kearns9cd9e752024-04-07 17:42:17 +02004041 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004042 one-byte character it is the character itself as a number.
4043 Use nr2char() to convert it to a String.
4044
4045 Use getcharmod() to obtain any additional modifiers.
4046
zeertzjqe0a2ab32025-02-02 09:14:35 +01004047 The optional argument {opts} is a Dict and supports the
4048 following items:
4049
zeertzjqedf0f7d2025-02-02 19:01:01 +01004050 cursor A String specifying cursor behavior
4051 when waiting for a character.
4052 "hide": hide the cursor.
4053 "keep": keep current cursor unchanged.
4054 "msg": move cursor to message area.
4055 (default: "msg")
4056
zeertzjqe0a2ab32025-02-02 09:14:35 +01004057 number If |TRUE|, return a Number when getting
4058 a single character.
4059 If |FALSE|, the return value is always
4060 converted to a String, and an empty
4061 String (instead of 0) is returned when
4062 no character is available.
4063 (default: |TRUE|)
4064
4065 simplify If |TRUE|, include modifiers in the
4066 character if possible. E.g., return
4067 the same value for CTRL-I and <Tab>.
4068 If |FALSE|, don't include modifiers in
4069 the character.
4070 (default: |TRUE|)
4071
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004072 When the user clicks a mouse button, the mouse event will be
4073 returned. The position can then be found in |v:mouse_col|,
4074 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
4075 |getmousepos()| can also be used. Mouse move events will be
4076 ignored.
4077 This example positions the mouse as it would normally happen: >
4078 let c = getchar()
4079 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004080 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004081 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004082 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004083 endif
4084<
4085 When using bracketed paste only the first character is
4086 returned, the rest of the pasted text is dropped.
4087 |xterm-bracketed-paste|.
4088
4089 There is no prompt, you will somehow have to make clear to the
4090 user that a character has to be typed. The screen is not
4091 redrawn, e.g. when resizing the window. When using a popup
4092 window it should work better with a |popup-filter|.
4093
4094 There is no mapping for the character.
4095 Key codes are replaced, thus when the user presses the <Del>
4096 key you get the code for the <Del> key, not the raw character
4097 sequence. Examples: >
4098 getchar() == "\<Del>"
4099 getchar() == "\<S-Left>"
4100< This example redefines "f" to ignore case: >
4101 :nmap f :call FindChar()<CR>
4102 :function FindChar()
4103 : let c = nr2char(getchar())
4104 : while col('.') < col('$') - 1
4105 : normal l
4106 : if getline('.')[col('.') - 1] ==? c
4107 : break
4108 : endif
4109 : endwhile
4110 :endfunction
4111<
4112 You may also receive synthetic characters, such as
4113 |<CursorHold>|. Often you will want to ignore this and get
4114 another character: >
4115 :function GetKey()
4116 : let c = getchar()
4117 : while c == "\<CursorHold>"
4118 : let c = getchar()
4119 : endwhile
4120 : return c
4121 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004122<
4123 Return type: |Number| or |String|
4124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004125
4126getcharmod() *getcharmod()*
4127 The result is a Number which is the state of the modifiers for
4128 the last obtained character with getchar() or in another way.
4129 These values are added together:
4130 2 shift
4131 4 control
4132 8 alt (meta)
4133 16 meta (when it's different from ALT)
4134 32 mouse double click
4135 64 mouse triple click
4136 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004137 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004138 Only the modifiers that have not been included in the
4139 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004140 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004141
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004142 Return type: |Number|
4143
4144
4145getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004146 Get the position for String {expr}. Same as |getpos()| but the
4147 column number in the returned List is a character index
4148 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004149 If |getpos()| returns a very large column number, equal to
4150 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004151 of the last character.
4152
4153 Example:
4154 With the cursor on '세' in line 5 with text "여보세요": >
4155 getcharpos('.') returns [0, 5, 3, 0]
4156 getpos('.') returns [0, 5, 7, 0]
4157<
4158 Can also be used as a |method|: >
4159 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004160<
4161 Return type: list<number>
4162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004163
4164getcharsearch() *getcharsearch()*
4165 Return the current character search information as a {dict}
4166 with the following entries:
4167
4168 char character previously used for a character
4169 search (|t|, |f|, |T|, or |F|); empty string
4170 if no character search has been performed
4171 forward direction of character search; 1 for forward,
4172 0 for backward
4173 until type of character search; 1 for a |t| or |T|
4174 character search, 0 for an |f| or |F|
4175 character search
4176
4177 This can be useful to always have |;| and |,| search
4178 forward/backward regardless of the direction of the previous
4179 character search: >
4180 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4181 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4182< Also see |setcharsearch()|.
4183
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004184 Return type: dict<any>
4185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004186
zeertzjqe0a2ab32025-02-02 09:14:35 +01004187getcharstr([{expr} [, {opts}]]) *getcharstr()*
4188 The same as |getchar()|, except that this always returns a
4189 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004190
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004191 Return type: |String|
4192
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004193getcmdcomplpat() *getcmdcomplpat()*
4194 Return completion pattern of the current command-line.
4195 Only works when the command line is being edited, thus
4196 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4197 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4198 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4199 Returns an empty string when completion is not defined.
4200
4201 Return type: |String|
4202
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004203
Shougo Matsushita5d2354f2025-07-03 19:57:00 +02004204getcmdcompltype([{pat}]) *getcmdcompltype()*
4205 Return the type of command-line completion using {pat}.
4206 If {pat} is omited, only works when the command line is being
4207 edited, thus requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4208
Bram Moolenaar921bde82022-05-09 19:50:35 +01004209 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004210 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004211 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004212 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004213
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004214 Return type: |String|
4215
4216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004217getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004218 Return the current command-line input. Only works when the
4219 command line is being edited, thus requires use of
4220 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004221 Example: >
4222 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004223< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4224 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004225 Returns an empty string when entering a password or using
4226 |inputsecret()|.
4227
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004228 Return type: |String|
4229
4230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004231getcmdpos() *getcmdpos()*
4232 Return the position of the cursor in the command line as a
4233 byte count. The first column is 1.
4234 Only works when editing the command line, thus requires use of
4235 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4236 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004237 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4238 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004239
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004240 Return type: |Number|
4241
4242
Shougo Matsushita69084282024-09-23 20:34:47 +02004243getcmdprompt() *getcmdprompt()*
4244 Return the current command-line prompt when using functions
4245 like |input()| or |confirm()|.
4246 Only works when the command line is being edited, thus
4247 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4248 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4249 |setcmdpos()| and |setcmdline()|.
4250
4251 Return type: |String|
4252
4253
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004254getcmdscreenpos() *getcmdscreenpos()*
4255 Return the screen position of the cursor in the command line
4256 as a byte count. The first column is 1.
4257 Instead of |getcmdpos()|, it adds the prompt position.
4258 Only works when editing the command line, thus requires use of
4259 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4260 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004261 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4262 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004263
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004264 Return type: |Number|
4265
4266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004267getcmdtype() *getcmdtype()*
4268 Return the current command-line type. Possible return values
4269 are:
4270 : normal Ex command
4271 > debug mode command |debug-mode|
4272 / forward search command
4273 ? backward search command
4274 @ |input()| command
4275 - |:insert| or |:append| command
4276 = |i_CTRL-R_=|
4277 Only works when editing the command line, thus requires use of
4278 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4279 Returns an empty string otherwise.
4280 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4281
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004282 Return type: |String|
4283
4284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004285getcmdwintype() *getcmdwintype()*
4286 Return the current |command-line-window| type. Possible return
4287 values are the same as |getcmdtype()|. Returns an empty string
4288 when not in the command-line window.
4289
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004290 Return type: |String|
4291
4292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004293getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4294 Return a list of command-line completion matches. The String
4295 {type} argument specifies what for. The following completion
4296 types are supported:
4297
4298 arglist file names in argument list
4299 augroup autocmd groups
4300 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004301 behave |:behave| suboptions
4302 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004303 color color schemes
4304 command Ex command
4305 cmdline |cmdline-completion| result
4306 compiler compilers
4307 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004308 custom,{func} custom completion, defined via {func}
4309 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004310 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004311 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004312 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004313 environment environment variable names
4314 event autocommand events
4315 expression Vim expression
4316 file file and directory names
4317 file_in_path file and directory names in |'path'|
4318 filetype filetype names |'filetype'|
Christian Brabandta3422aa2025-04-23 21:04:24 +02004319 filetypecmd |:filetype| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004320 function function name
4321 help help subjects
4322 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004323 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004324 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004325 locale locale names (as output of locale -a)
4326 mapclear buffer argument
4327 mapping mapping name
4328 menu menus
4329 messages |:messages| suboptions
4330 option options
4331 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004332 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004333 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004334 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004335 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004336 sign |:sign| suboptions
4337 syntax syntax file names |'syntax'|
4338 syntime |:syntime| suboptions
4339 tag tags
4340 tag_listfiles tags, file names
4341 user user names
4342 var user variables
4343
4344 If {pat} is an empty string, then all the matches are
4345 returned. Otherwise only items matching {pat} are returned.
4346 See |wildcards| for the use of special characters in {pat}.
4347
4348 If the optional {filtered} flag is set to 1, then 'wildignore'
4349 is applied to filter the results. Otherwise all the matches
4350 are returned. The 'wildignorecase' option always applies.
4351
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004352 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4353 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004354 regular expression matching is used. Thus this function
4355 follows the user preference, what happens on the command line.
4356 If you do not want this you can make 'wildoptions' empty
4357 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004359 If {type} is "cmdline", then the |cmdline-completion| result is
4360 returned. For example, to complete the possible values after
4361 a ":call" command: >
4362 echo getcompletion('call ', 'cmdline')
4363<
4364 If there are no matches, an empty list is returned. An
4365 invalid value for {type} produces an error.
4366
4367 Can also be used as a |method|: >
4368 GetPattern()->getcompletion('color')
4369<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004370 Return type: list<string>
4371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004372 *getcurpos()*
4373getcurpos([{winid}])
4374 Get the position of the cursor. This is like getpos('.'), but
4375 includes an extra "curswant" item in the list:
4376 [0, lnum, col, off, curswant] ~
4377 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004378 cursor vertically. After |$| command it will be a very large
4379 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004380 |getpos()|.
4381 The first "bufnum" item is always zero. The byte position of
4382 the cursor is returned in 'col'. To get the character
4383 position, use |getcursorcharpos()|.
4384
4385 The optional {winid} argument can specify the window. It can
4386 be the window number or the |window-ID|. The last known
4387 cursor position is returned, this may be invalid for the
4388 current value of the buffer if it is not the current window.
4389 If {winid} is invalid a list with zeroes is returned.
4390
4391 This can be used to save and restore the cursor position: >
4392 let save_cursor = getcurpos()
4393 MoveTheCursorAround
4394 call setpos('.', save_cursor)
4395< Note that this only works within the window. See
4396 |winrestview()| for restoring more state.
4397
4398 Can also be used as a |method|: >
4399 GetWinid()->getcurpos()
4400<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004401 Return type: list<number>
4402
4403
4404getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004405 Same as |getcurpos()| but the column number in the returned
4406 List is a character index instead of a byte index.
4407
4408 Example:
4409 With the cursor on '보' in line 3 with text "여보세요": >
4410 getcursorcharpos() returns [0, 3, 2, 0, 3]
4411 getcurpos() returns [0, 3, 4, 0, 3]
4412<
4413 Can also be used as a |method|: >
4414 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004415<
4416 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004417
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004418
4419getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004420 The result is a String, which is the name of the current
4421 working directory. 'autochdir' is ignored.
4422
4423 With {winnr} return the local current directory of this window
4424 in the current tab page. {winnr} can be the window number or
4425 the |window-ID|.
4426 If {winnr} is -1 return the name of the global working
4427 directory. See also |haslocaldir()|.
4428
4429 With {winnr} and {tabnr} return the local current directory of
4430 the window in the specified tab page. If {winnr} is -1 return
4431 the working directory of the tabpage.
4432 If {winnr} is zero use the current window, if {tabnr} is zero
4433 use the current tabpage.
4434 Without any arguments, return the actual working directory of
4435 the current window.
4436 Return an empty string if the arguments are invalid.
4437
4438 Examples: >
4439 " Get the working directory of the current window
4440 :echo getcwd()
4441 :echo getcwd(0)
4442 :echo getcwd(0, 0)
4443 " Get the working directory of window 3 in tabpage 2
4444 :echo getcwd(3, 2)
4445 " Get the global working directory
4446 :echo getcwd(-1)
4447 " Get the working directory of tabpage 3
4448 :echo getcwd(-1, 3)
4449 " Get the working directory of current tabpage
4450 :echo getcwd(-1, 0)
4451
4452< Can also be used as a |method|: >
4453 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004454<
4455 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004456
4457getenv({name}) *getenv()*
4458 Return the value of environment variable {name}. The {name}
4459 argument is a string, without a leading '$'. Example: >
4460 myHome = getenv('HOME')
4461
4462< When the variable does not exist |v:null| is returned. That
4463 is different from a variable set to an empty string, although
4464 some systems interpret the empty value as the variable being
4465 deleted. See also |expr-env|.
4466
4467 Can also be used as a |method|: >
4468 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004469<
4470 Return type: |String| or |Number|
4471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004472
4473getfontname([{name}]) *getfontname()*
4474 Without an argument returns the name of the normal font being
4475 used. Like what is used for the Normal highlight group
4476 |hl-Normal|.
4477 With an argument a check is done whether String {name} is a
4478 valid font name. If not then an empty string is returned.
4479 Otherwise the actual font name is returned, or {name} if the
4480 GUI does not support obtaining the real name.
4481 Only works when the GUI is running, thus not in your vimrc or
4482 gvimrc file. Use the |GUIEnter| autocommand to use this
4483 function just after the GUI has started.
4484 Note that the GTK GUI accepts any font name, thus checking for
4485 a valid name does not work.
4486
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004487 Return type: |String|
4488
4489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004490getfperm({fname}) *getfperm()*
4491 The result is a String, which is the read, write, and execute
4492 permissions of the given file {fname}.
4493 If {fname} does not exist or its directory cannot be read, an
4494 empty string is returned.
4495 The result is of the form "rwxrwxrwx", where each group of
4496 "rwx" flags represent, in turn, the permissions of the owner
4497 of the file, the group the file belongs to, and other users.
4498 If a user does not have a given permission the flag for this
4499 is replaced with the string "-". Examples: >
4500 :echo getfperm("/etc/passwd")
4501 :echo getfperm(expand("~/.vimrc"))
4502< This will hopefully (from a security point of view) display
4503 the string "rw-r--r--" or even "rw-------".
4504
4505 Can also be used as a |method|: >
4506 GetFilename()->getfperm()
4507<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004508 Return type: |String|
4509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004510 For setting permissions use |setfperm()|.
4511
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004513getfsize({fname}) *getfsize()*
4514 The result is a Number, which is the size in bytes of the
4515 given file {fname}.
4516 If {fname} is a directory, 0 is returned.
4517 If the file {fname} can't be found, -1 is returned.
4518 If the size of {fname} is too big to fit in a Number then -2
4519 is returned.
4520
4521 Can also be used as a |method|: >
4522 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004523<
4524 Return type: |Number|
4525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004526
4527getftime({fname}) *getftime()*
4528 The result is a Number, which is the last modification time of
4529 the given file {fname}. The value is measured as seconds
4530 since 1st Jan 1970, and may be passed to strftime(). See also
4531 |localtime()| and |strftime()|.
4532 If the file {fname} can't be found -1 is returned.
4533
4534 Can also be used as a |method|: >
4535 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004536<
4537 Return type: |Number|
4538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004539
4540getftype({fname}) *getftype()*
4541 The result is a String, which is a description of the kind of
4542 file of the given file {fname}.
4543 If {fname} does not exist an empty string is returned.
4544 Here is a table over different kinds of files and their
4545 results:
4546 Normal file "file"
4547 Directory "dir"
4548 Symbolic link "link"
4549 Block device "bdev"
4550 Character device "cdev"
4551 Socket "socket"
4552 FIFO "fifo"
4553 All other "other"
4554 Example: >
4555 getftype("/home")
4556< Note that a type such as "link" will only be returned on
4557 systems that support it. On some systems only "dir" and
4558 "file" are returned. On MS-Windows a symbolic link to a
4559 directory returns "dir" instead of "link".
4560
4561 Can also be used as a |method|: >
4562 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004563<
4564 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004565
4566getimstatus() *getimstatus()*
4567 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004568 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004569 See 'imstatusfunc'.
4570
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004571 Return type: |Number|
4572
4573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004574getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4575 Returns the |jumplist| for the specified window.
4576
4577 Without arguments use the current window.
4578 With {winnr} only use this window in the current tab page.
4579 {winnr} can also be a |window-ID|.
4580 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004581 page. If {winnr} or {tabnr} is invalid, an empty list is
4582 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004583
4584 The returned list contains two entries: a list with the jump
4585 locations and the last used jump position number in the list.
4586 Each entry in the jump location list is a dictionary with
4587 the following entries:
4588 bufnr buffer number
4589 col column number
4590 coladd column offset for 'virtualedit'
4591 filename filename if available
4592 lnum line number
4593
4594 Can also be used as a |method|: >
4595 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004596<
4597 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004598
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004599 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004600getline({lnum} [, {end}])
4601 Without {end} the result is a String, which is line {lnum}
4602 from the current buffer. Example: >
4603 getline(1)
4604< When {lnum} is a String that doesn't start with a
4605 digit, |line()| is called to translate the String into a Number.
4606 To get the line under the cursor: >
4607 getline(".")
4608< When {lnum} is a number smaller than 1 or bigger than the
4609 number of lines in the buffer, an empty string is returned.
4610
4611 When {end} is given the result is a |List| where each item is
4612 a line from the current buffer in the range {lnum} to {end},
4613 including line {end}.
4614 {end} is used in the same way as {lnum}.
4615 Non-existing lines are silently omitted.
4616 When {end} is before {lnum} an empty |List| is returned.
4617 Example: >
4618 :let start = line('.')
4619 :let end = search("^$") - 1
4620 :let lines = getline(start, end)
4621
4622< Can also be used as a |method|: >
4623 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004624<
4625 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004626
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004627 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004628 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004629
4630getloclist({nr} [, {what}]) *getloclist()*
4631 Returns a |List| with all the entries in the location list for
4632 window {nr}. {nr} can be the window number or the |window-ID|.
4633 When {nr} is zero the current window is used.
4634
4635 For a location list window, the displayed location list is
4636 returned. For an invalid window number {nr}, an empty list is
4637 returned. Otherwise, same as |getqflist()|.
4638
4639 If the optional {what} dictionary argument is supplied, then
4640 returns the items listed in {what} as a dictionary. Refer to
4641 |getqflist()| for the supported items in {what}.
4642
4643 In addition to the items supported by |getqflist()| in {what},
4644 the following item is supported by |getloclist()|:
4645
4646 filewinid id of the window used to display files
4647 from the location list. This field is
4648 applicable only when called from a
4649 location list window. See
4650 |location-list-file-window| for more
4651 details.
4652
4653 Returns a |Dictionary| with default values if there is no
4654 location list for the window {nr}.
4655 Returns an empty Dictionary if window {nr} does not exist.
4656
4657 Examples (See also |getqflist-examples|): >
4658 :echo getloclist(3, {'all': 0})
4659 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004660<
4661 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004662
4663
4664getmarklist([{buf}]) *getmarklist()*
4665 Without the {buf} argument returns a |List| with information
4666 about all the global marks. |mark|
4667
4668 If the optional {buf} argument is specified, returns the
4669 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004670 see |bufname()|. If {buf} is invalid, an empty list is
4671 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004672
4673 Each item in the returned List is a |Dict| with the following:
4674 mark name of the mark prefixed by "'"
4675 pos a |List| with the position of the mark:
4676 [bufnum, lnum, col, off]
4677 Refer to |getpos()| for more information.
4678 file file name
4679
4680 Refer to |getpos()| for getting information about a specific
4681 mark.
4682
4683 Can also be used as a |method|: >
4684 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004685<
4686 Return type: list<dict<any>> or list<any>
4687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004688
4689getmatches([{win}]) *getmatches()*
4690 Returns a |List| with all matches previously defined for the
4691 current window by |matchadd()| and the |:match| commands.
4692 |getmatches()| is useful in combination with |setmatches()|,
4693 as |setmatches()| can restore a list of matches saved by
4694 |getmatches()|.
4695 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004696 window ID instead of the current window. If {win} is invalid,
4697 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004698 Example: >
4699 :echo getmatches()
4700< [{'group': 'MyGroup1', 'pattern': 'TODO',
4701 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4702 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4703 :let m = getmatches()
4704 :call clearmatches()
4705 :echo getmatches()
4706< [] >
4707 :call setmatches(m)
4708 :echo getmatches()
4709< [{'group': 'MyGroup1', 'pattern': 'TODO',
4710 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4711 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4712 :unlet m
4713<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004714 Return type: list<dict<any>> or list<any>
4715
4716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004717getmousepos() *getmousepos()*
4718 Returns a |Dictionary| with the last known position of the
4719 mouse. This can be used in a mapping for a mouse click or in
4720 a filter of a popup window. The items are:
4721 screenrow screen row
4722 screencol screen column
4723 winid Window ID of the click
4724 winrow row inside "winid"
4725 wincol column inside "winid"
4726 line text line inside "winid"
4727 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004728 coladd offset (in screen columns) from the
4729 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004730 All numbers are 1-based.
4731
Hirohito Higashi3b9b95d2025-06-01 20:22:55 +02004732 If not over a window, e.g. when in the command line or within
4733 |tabpanel|, then only "screenrow" and "screencol" are valid,
4734 the others are zero.
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02004735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004736 When on the status line below a window or the vertical
4737 separator right of a window, the "line" and "column" values
4738 are zero.
4739
4740 When the position is after the text then "column" is the
4741 length of the text in bytes plus one.
4742
4743 If the mouse is over a popup window then that window is used.
4744
4745 When using |getchar()| the Vim variables |v:mouse_lnum|,
4746 |v:mouse_col| and |v:mouse_winid| also provide these values.
4747
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004748 Return type: dict<number>
4749
4750
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004751getmouseshape() *getmouseshape()*
4752 Returns the name of the currently showing mouse pointer.
4753 When the |+mouseshape| feature is not supported or the shape
4754 is unknown an empty string is returned.
4755 This function is mainly intended for testing.
4756
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004757 Return type: |String|
4758
4759
4760getpid() *getpid()*
4761 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004762 On Unix and MS-Windows this is a unique number, until Vim
4763 exits.
4764
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004765 Return type: |Number|
4766
4767
4768getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004769 Get the position for String {expr}.
4770 The accepted values for {expr} are: *E1209*
4771 . The cursor position.
4772 $ The last line in the current buffer.
4773 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004774 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004775 w0 First line visible in current window (one if the
4776 display isn't updated, e.g. in silent Ex mode).
4777 w$ Last line visible in current window (this is one
4778 less than "w0" if no lines are visible).
4779 v When not in Visual mode, returns the cursor
4780 position. In Visual mode, returns the other end
4781 of the Visual area. A good way to think about
4782 this is that in Visual mode "v" and "." complement
4783 each other. While "." refers to the cursor
4784 position, "v" refers to where |v_o| would move the
4785 cursor. As a result, you can use "v" and "."
4786 together to work on all of a selection in
4787 characterwise Visual mode. If the cursor is at
4788 the end of a characterwise Visual area, "v" refers
4789 to the start of the same Visual area. And if the
4790 cursor is at the start of a characterwise Visual
4791 area, "v" refers to the end of the same Visual
4792 area. "v" differs from |'<| and |'>| in that it's
4793 updated right away.
4794 Note that a mark in another file can be used. The line number
4795 then applies to another buffer.
4796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004797 The result is a |List| with four numbers:
4798 [bufnum, lnum, col, off]
4799 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4800 is the buffer number of the mark.
4801 "lnum" and "col" are the position in the buffer. The first
4802 column is 1.
4803 The "off" number is zero, unless 'virtualedit' is used. Then
4804 it is the offset in screen columns from the start of the
4805 character. E.g., a position within a <Tab> or after the last
4806 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004807
4808 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004809 The column number in the returned List is the byte position
4810 within the line. To get the character position in the line,
4811 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004812
4813 Note that for '< and '> Visual mode matters: when it is "V"
4814 (visual line mode) the column of '< is zero and the column of
4815 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004816 A very large column number equal to |v:maxcol| can be returned,
4817 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004818 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004820 This can be used to save and restore the position of a mark: >
4821 let save_a_mark = getpos("'a")
4822 ...
4823 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004824<
4825 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004826
4827 Can also be used as a |method|: >
4828 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004829<
4830 Return type: list<number>
4831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004832
4833getqflist([{what}]) *getqflist()*
4834 Returns a |List| with all the current quickfix errors. Each
4835 list item is a dictionary with these entries:
4836 bufnr number of buffer that has the file name, use
4837 bufname() to get the name
4838 module module name
4839 lnum line number in the buffer (first line is 1)
4840 end_lnum
4841 end of line number if the item is multiline
4842 col column number (first column is 1)
4843 end_col end of column number if the item has range
4844 vcol |TRUE|: "col" is visual column
4845 |FALSE|: "col" is byte index
4846 nr error number
h-east84ac2122024-06-17 18:12:30 +02004847 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004848 text description of the error
4849 type type of the error, 'E', '1', etc.
4850 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004851 user_data
4852 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004853 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004854
4855 When there is no error list or it's empty, an empty list is
4856 returned. Quickfix list entries with a non-existing buffer
4857 number are returned with "bufnr" set to zero (Note: some
4858 functions accept buffer number zero for the alternate buffer,
4859 you may need to explicitly check for zero).
4860
4861 Useful application: Find pattern matches in multiple files and
4862 do something with them: >
4863 :vimgrep /theword/jg *.c
4864 :for d in getqflist()
4865 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4866 :endfor
4867<
4868 If the optional {what} dictionary argument is supplied, then
4869 returns only the items listed in {what} as a dictionary. The
4870 following string items are supported in {what}:
4871 changedtick get the total number of changes made
4872 to the list |quickfix-changedtick|
4873 context get the |quickfix-context|
4874 efm errorformat to use when parsing "lines". If
4875 not present, then the 'errorformat' option
4876 value is used.
4877 id get information for the quickfix list with
4878 |quickfix-ID|; zero means the id for the
4879 current list or the list specified by "nr"
4880 idx get information for the quickfix entry at this
4881 index in the list specified by 'id' or 'nr'.
4882 If set to zero, then uses the current entry.
4883 See |quickfix-index|
4884 items quickfix list entries
4885 lines parse a list of lines using 'efm' and return
4886 the resulting entries. Only a |List| type is
4887 accepted. The current quickfix list is not
4888 modified. See |quickfix-parse|.
4889 nr get information for this quickfix list; zero
4890 means the current quickfix list and "$" means
4891 the last quickfix list
4892 qfbufnr number of the buffer displayed in the quickfix
4893 window. Returns 0 if the quickfix buffer is
4894 not present. See |quickfix-buffer|.
4895 size number of entries in the quickfix list
4896 title get the list title |quickfix-title|
4897 winid get the quickfix |window-ID|
4898 all all of the above quickfix properties
4899 Non-string items in {what} are ignored. To get the value of a
4900 particular item, set it to zero.
4901 If "nr" is not present then the current quickfix list is used.
4902 If both "nr" and a non-zero "id" are specified, then the list
4903 specified by "id" is used.
4904 To get the number of lists in the quickfix stack, set "nr" to
4905 "$" in {what}. The "nr" value in the returned dictionary
4906 contains the quickfix stack size.
4907 When "lines" is specified, all the other items except "efm"
4908 are ignored. The returned dictionary contains the entry
4909 "items" with the list of entries.
4910
4911 The returned dictionary contains the following entries:
4912 changedtick total number of changes made to the
4913 list |quickfix-changedtick|
4914 context quickfix list context. See |quickfix-context|
4915 If not present, set to "".
4916 id quickfix list ID |quickfix-ID|. If not
4917 present, set to 0.
4918 idx index of the quickfix entry in the list. If not
4919 present, set to 0.
4920 items quickfix list entries. If not present, set to
4921 an empty list.
4922 nr quickfix list number. If not present, set to 0
4923 qfbufnr number of the buffer displayed in the quickfix
4924 window. If not present, set to 0.
4925 size number of entries in the quickfix list. If not
4926 present, set to 0.
4927 title quickfix list title text. If not present, set
4928 to "".
4929 winid quickfix |window-ID|. If not present, set to 0
4930
4931 Examples (See also |getqflist-examples|): >
4932 :echo getqflist({'all': 1})
4933 :echo getqflist({'nr': 2, 'title': 1})
4934 :echo getqflist({'lines' : ["F1:10:L10"]})
4935<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004936 Return type: list<dict<any>> or list<any>
4937
4938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004939getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4940 The result is a String, which is the contents of register
4941 {regname}. Example: >
4942 :let cliptext = getreg('*')
4943< When register {regname} was not set the result is an empty
4944 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004945 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004946
4947 getreg('=') returns the last evaluated value of the expression
4948 register. (For use in maps.)
4949 getreg('=', 1) returns the expression itself, so that it can
4950 be restored with |setreg()|. For other registers the extra
4951 argument is ignored, thus you can always give it.
4952
4953 If {list} is present and |TRUE|, the result type is changed
4954 to |List|. Each list item is one text line. Use it if you care
4955 about zero bytes possibly present inside register: without
4956 third argument both NLs and zero bytes are represented as NLs
4957 (see |NL-used-for-Nul|).
4958 When the register was not set an empty list is returned.
4959
4960 If {regname} is "", the unnamed register '"' is used.
4961 If {regname} is not specified, |v:register| is used.
4962 In |Vim9-script| {regname} must be one character.
4963
4964 Can also be used as a |method|: >
4965 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004966<
Christian Brabandt17ad8522025-05-09 00:03:20 +02004967 Return type: |String| or list<string> depending on {list}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004969
4970getreginfo([{regname}]) *getreginfo()*
4971 Returns detailed information about register {regname} as a
4972 Dictionary with the following entries:
4973 regcontents List of lines contained in register
4974 {regname}, like
4975 |getreg|({regname}, 1, 1).
4976 regtype the type of register {regname}, as in
4977 |getregtype()|.
4978 isunnamed Boolean flag, v:true if this register
4979 is currently pointed to by the unnamed
4980 register.
4981 points_to for the unnamed register, gives the
4982 single letter name of the register
4983 currently pointed to (see |quotequote|).
4984 For example, after deleting a line
4985 with `dd`, this field will be "1",
4986 which is the register that got the
4987 deleted text.
4988
4989 The {regname} argument is a string. If {regname} is invalid
4990 or not set, an empty Dictionary will be returned.
4991 If {regname} is "" or "@", the unnamed register '"' is used.
4992 If {regname} is not specified, |v:register| is used.
4993 The returned Dictionary can be passed to |setreg()|.
4994 In |Vim9-script| {regname} must be one character.
4995
4996 Can also be used as a |method|: >
4997 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004998<
4999 Return type: dict<any>
5000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005001
Shougo Matsushita19b71882024-02-28 22:48:12 +01005002getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005003 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01005004 buffer.
5005
5006 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005007 See |getpos()| for the format of the list. It's possible
5008 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01005009 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01005010
5011 The optional argument {opts} is a Dict and supports the
5012 following items:
5013
zeertzjqafc22952024-05-24 19:07:12 +02005014 type Specify the region's selection type.
5015 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02005016 except that the width can be omitted
5017 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02005018 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01005019
zeertzjq87410ab2024-03-02 06:00:23 +08005020 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02005021 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08005022 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01005023
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005024 You can get the last selection type by |visualmode()|.
5025 If Visual mode is active, use |mode()| to get the Visual mode
5026 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08005027 This function is useful to get text starting and ending in
5028 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005029
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005030 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005031 Note that:
5032 - Order of {pos1} and {pos2} doesn't matter, it will always
5033 return content from the upper left position to the lower
5034 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08005035 - If 'virtualedit' is enabled and the region is past the end
5036 of the lines, resulting lines are padded with spaces.
5037 - If the region is blockwise and it starts or ends in the
5038 middle of a multi-cell character, it is not included but
5039 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005040 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01005041 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005042 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01005043 - It is evaluated in current window context, which makes a
5044 difference if the buffer is displayed in a window with
5045 different 'virtualedit' or 'list' values.
Christian Brabandtbfeefc42025-06-02 19:56:57 +02005046 - When specifying an exclusive selection and {pos1} and {pos2}
5047 are equal, the returned list contains a single character as
5048 if selection is inclusive, to match the behavior of an empty
5049 exclusive selection in Visual mode.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005050
5051 Examples: >
5052 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01005053 \ <Cmd>echow getregion(
5054 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005055<
5056 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01005057 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02005058<
5059 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005060
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005061
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005062getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
5063 Same as |getregion()|, but returns a list of positions
5064 describing the buffer text segments bound by {pos1} and
5065 {pos2}.
5066 The segments are a pair of positions for every line: >
5067 [[{start_pos}, {end_pos}], ...]
5068<
5069 The position is a |List| with four numbers:
5070 [bufnum, lnum, col, off]
5071 "bufnum" is the buffer number.
5072 "lnum" and "col" are the position in the buffer. The first
5073 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02005074 If the "off" number of a starting position is non-zero, it is
5075 the offset in screen columns from the start of the character.
5076 E.g., a position within a <Tab> or after the last character.
5077 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02005078 the offset of the character's first cell not included in the
5079 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005080
zeertzjq2b09de92024-05-24 07:48:51 +02005081 Apart from the options supported by |getregion()|, {opts} also
5082 supports the following:
5083
5084 eol If |TRUE|, indicate positions beyond
5085 the end of a line with "col" values
5086 one more than the length of the line.
5087 If |FALSE|, positions are limited
5088 within their lines, and if a line is
5089 empty or the selection is entirely
5090 beyond the end of a line, a "col"
5091 value of 0 is used for both positions.
5092 (default: |FALSE|)
5093
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005094 Can also be used as a |method|: >
5095 getpos('.')->getregionpos(getpos("'a"))
5096<
Christian Brabandt83d74402025-03-19 21:55:59 +01005097 For an example, see the highlight-yank plugin |52.6|
5098
zeertzjqd4d12072024-07-16 20:34:16 +02005099 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005100
5101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005102getregtype([{regname}]) *getregtype()*
5103 The result is a String, which is type of register {regname}.
5104 The value will be one of:
5105 "v" for |characterwise| text
5106 "V" for |linewise| text
5107 "<CTRL-V>{width}" for |blockwise-visual| text
5108 "" for an empty or unknown register
5109 <CTRL-V> is one character with value 0x16.
5110 The {regname} argument is a string. If {regname} is "", the
5111 unnamed register '"' is used. If {regname} is not specified,
5112 |v:register| is used.
5113 In |Vim9-script| {regname} must be one character.
5114
5115 Can also be used as a |method|: >
5116 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005117<
5118 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005119
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005120
Bram Moolenaar71badf92023-04-22 22:40:14 +01005121getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005122 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005123 scripts in the order they were sourced, like what
5124 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005125
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005126 The optional Dict argument {opts} supports the following
5127 optional items:
5128 name Script name match pattern. If specified,
5129 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005130 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005131 "name" are returned.
5132 sid Script ID |<SID>|. If specified, only
5133 information about the script with ID "sid" is
5134 returned and "name" is ignored.
5135
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005136 Each item in the returned List is a |Dict| with the following
5137 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005138 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005139 `import autoload` but was not actually sourced
5140 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005141 functions List of script-local function names defined in
5142 the script. Present only when a particular
5143 script is specified using the "sid" item in
5144 {opts}.
5145 name Vim script file name.
5146 sid Script ID |<SID>|.
5147 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005148 this script name links to, if any, otherwise
5149 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005150 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005151 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005152 specified using the "sid" item in {opts}.
5153 Note that this is a copy, the value of
5154 script-local variables cannot be changed using
5155 this dictionary.
h_east59858792023-10-25 22:47:05 +09005156 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005157
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005158 Examples: >
5159 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005160 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005161<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005162 Return type: list<dict<any>>
5163
5164
ichizok663d18d2025-01-02 18:06:00 +01005165getstacktrace() *getstacktrace()*
5166 Returns the current stack trace of Vim scripts.
5167 Stack trace is a |List|, of which each item is a |Dictionary|
5168 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005169 funcref The funcref if the stack is at a function,
5170 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005171 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005172 stack is at an autocmd event, otherwise this
5173 item is omitted.
5174 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005175 filepath The file path of the script on the stack.
5176
5177 Return type: list<dict<any>>
5178
5179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005180gettabinfo([{tabnr}]) *gettabinfo()*
5181 If {tabnr} is not specified, then information about all the
5182 tab pages is returned as a |List|. Each List item is a
5183 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5184 number and information about that one is returned. If the tab
5185 page does not exist an empty List is returned.
5186
5187 Each List item is a |Dictionary| with the following entries:
5188 tabnr tab page number.
5189 variables a reference to the dictionary with
5190 tabpage-local variables
5191 windows List of |window-ID|s in the tab page.
5192
5193 Can also be used as a |method|: >
5194 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005195<
5196 Return type: list<dict<any>>
5197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005198
5199gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5200 Get the value of a tab-local variable {varname} in tab page
5201 {tabnr}. |t:var|
5202 Tabs are numbered starting with one.
5203 The {varname} argument is a string. When {varname} is empty a
5204 dictionary with all tab-local variables is returned.
5205 Note that the name without "t:" must be used.
5206 When the tab or variable doesn't exist {def} or an empty
5207 string is returned, there is no error message.
5208
5209 Can also be used as a |method|: >
5210 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005211<
5212 Return type: any, depending on {varname}
5213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005214
5215gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5216 Get the value of window-local variable {varname} in window
5217 {winnr} in tab page {tabnr}.
5218 The {varname} argument is a string. When {varname} is empty a
5219 dictionary with all window-local variables is returned.
5220 When {varname} is equal to "&" get the values of all
5221 window-local options in a |Dictionary|.
5222 Otherwise, when {varname} starts with "&" get the value of a
5223 window-local option.
5224 Note that {varname} must be the name without "w:".
5225 Tabs are numbered starting with one. For the current tabpage
5226 use |getwinvar()|.
5227 {winnr} can be the window number or the |window-ID|.
5228 When {winnr} is zero the current window is used.
5229 This also works for a global option, buffer-local option and
5230 window-local option, but it doesn't work for a global variable
5231 or buffer-local variable.
5232 When the tab, window or variable doesn't exist {def} or an
5233 empty string is returned, there is no error message.
5234 Examples: >
5235 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005236 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005237<
5238 To obtain all window-local variables use: >
5239 gettabwinvar({tabnr}, {winnr}, '&')
5240
5241< Can also be used as a |method|: >
5242 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005243<
5244 Return type: any, depending on {varname}
5245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005246
5247gettagstack([{winnr}]) *gettagstack()*
5248 The result is a Dict, which is the tag stack of window {winnr}.
5249 {winnr} can be the window number or the |window-ID|.
5250 When {winnr} is not specified, the current window is used.
5251 When window {winnr} doesn't exist, an empty Dict is returned.
5252
5253 The returned dictionary contains the following entries:
5254 curidx Current index in the stack. When at
5255 top of the stack, set to (length + 1).
5256 Index of bottom of the stack is 1.
5257 items List of items in the stack. Each item
5258 is a dictionary containing the
5259 entries described below.
5260 length Number of entries in the stack.
5261
5262 Each item in the stack is a dictionary with the following
5263 entries:
5264 bufnr buffer number of the current jump
5265 from cursor position before the tag jump.
5266 See |getpos()| for the format of the
5267 returned list.
5268 matchnr current matching tag number. Used when
5269 multiple matching tags are found for a
5270 name.
5271 tagname name of the tag
5272
5273 See |tagstack| for more information about the tag stack.
5274
5275 Can also be used as a |method|: >
5276 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005277<
5278 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005279
5280
Christ van Willegence0ef912024-06-20 23:41:59 +02005281gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005282 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005283 This is intended for use in Vim scripts. When generating
5284 message translations the {text} is extracted by `xgettext`,
5285 the translator can add translated messages into the .po file
5286 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005287 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005288 `xgettext` does not support single quoted escaped text.
5289
Christ van Willegence0ef912024-06-20 23:41:59 +02005290 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005291 for that specific package. This is mainly required for
5292 third-party Vim scripts. You need to specify a path to the
5293 translations with the |bindtextdomain()| function before
5294 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005295
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005296 Return type: |String|
5297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005298
5299getwininfo([{winid}]) *getwininfo()*
5300 Returns information about windows as a |List| with Dictionaries.
5301
5302 If {winid} is given Information about the window with that ID
5303 is returned, as a |List| with one item. If the window does not
5304 exist the result is an empty list.
5305
5306 Without {winid} information about all the windows in all the
5307 tab pages is returned.
5308
5309 Each List item is a |Dictionary| with the following entries:
5310 botline last complete displayed buffer line
5311 bufnr number of buffer in the window
5312 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005313 leftcol first column displayed; only used when
5314 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005315 loclist 1 if showing a location list
5316 {only with the +quickfix feature}
5317 quickfix 1 if quickfix or location list window
5318 {only with the +quickfix feature}
5319 terminal 1 if a terminal window
5320 {only with the +terminal feature}
5321 tabnr tab page number
5322 topline first displayed buffer line
5323 variables a reference to the dictionary with
5324 window-local variables
5325 width window width
5326 winbar 1 if the window has a toolbar, 0
5327 otherwise
5328 wincol leftmost screen column of the window;
5329 "col" from |win_screenpos()|
5330 textoff number of columns occupied by any
5331 'foldcolumn', 'signcolumn' and line
5332 number in front of the text
5333 winid |window-ID|
5334 winnr window number
5335 winrow topmost screen line of the window;
5336 "row" from |win_screenpos()|
5337
5338 Can also be used as a |method|: >
5339 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005340<
5341 Return type: list<dict<any>>
5342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005343
5344getwinpos([{timeout}]) *getwinpos()*
5345 The result is a |List| with two numbers, the result of
5346 |getwinposx()| and |getwinposy()| combined:
5347 [x-pos, y-pos]
5348 {timeout} can be used to specify how long to wait in msec for
5349 a response from the terminal. When omitted 100 msec is used.
5350 Use a longer time for a remote terminal.
5351 When using a value less than 10 and no response is received
5352 within that time, a previously reported position is returned,
5353 if available. This can be used to poll for the position and
5354 do some work in the meantime: >
5355 while 1
5356 let res = getwinpos(1)
5357 if res[0] >= 0
5358 break
5359 endif
5360 " Do some work here
5361 endwhile
5362<
5363
5364 Can also be used as a |method|: >
5365 GetTimeout()->getwinpos()
5366<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005367 Return type: list<number>
5368
5369
5370getwinposx() *getwinposx()*
5371 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005372 the left hand side of the GUI Vim window. Also works for an
5373 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005374 The result will be -1 if the information is not available
5375 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005376 The value can be used with `:winpos`.
5377
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005378 Return type: |Number|
5379
5380
5381getwinposy() *getwinposy()*
5382 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005383 the top of the GUI Vim window. Also works for an xterm (uses
5384 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005385 The result will be -1 if the information is not available
5386 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005387 The value can be used with `:winpos`.
5388
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005389 Return type: |Number|
5390
5391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005392getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5393 Like |gettabwinvar()| for the current tabpage.
5394 Examples: >
5395 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005396 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005397
5398< Can also be used as a |method|: >
5399 GetWinnr()->getwinvar(varname)
5400<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005401 Return type: any, depending on {varname}
5402
5403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005404glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5405 Expand the file wildcards in {expr}. See |wildcards| for the
5406 use of special characters.
5407
5408 Unless the optional {nosuf} argument is given and is |TRUE|,
5409 the 'suffixes' and 'wildignore' options apply: Names matching
5410 one of the patterns in 'wildignore' will be skipped and
5411 'suffixes' affect the ordering of matches.
5412 'wildignorecase' always applies.
5413
5414 When {list} is present and it is |TRUE| the result is a |List|
5415 with all matching files. The advantage of using a List is,
5416 you also get filenames containing newlines correctly.
5417 Otherwise the result is a String and when there are several
5418 matches, they are separated by <NL> characters.
5419
5420 If the expansion fails, the result is an empty String or List.
5421
5422 You can also use |readdir()| if you need to do complicated
5423 things, such as limiting the number of matches.
5424
5425 A name for a non-existing file is not included. A symbolic
5426 link is only included if it points to an existing file.
5427 However, when the {alllinks} argument is present and it is
5428 |TRUE| then all symbolic links are included.
5429
5430 For most systems backticks can be used to get files names from
5431 any external command. Example: >
5432 :let tagfiles = glob("`find . -name tags -print`")
5433 :let &tags = substitute(tagfiles, "\n", ",", "g")
5434< The result of the program inside the backticks should be one
5435 item per line. Spaces inside an item are allowed.
5436
5437 See |expand()| for expanding special Vim variables. See
5438 |system()| for getting the raw output of an external command.
5439
5440 Can also be used as a |method|: >
5441 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005442<
5443 Return type: |String| or list<string> or list<any> depending
5444 on {list}
5445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005446
h-east624bb832024-11-09 18:37:32 +01005447glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005448 Convert a file pattern, as used by glob(), into a search
5449 pattern. The result can be used to match with a string that
5450 is a file name. E.g. >
5451 if filename =~ glob2regpat('Make*.mak')
5452< This is equivalent to: >
5453 if filename =~ '^Make.*\.mak$'
5454< When {string} is an empty string the result is "^$", match an
5455 empty string.
5456 Note that the result depends on the system. On MS-Windows
5457 a backslash usually means a path separator.
5458
5459 Can also be used as a |method|: >
5460 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005461<
5462 Return type: |String|
5463
5464 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005465globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5466 Perform glob() for String {expr} on all directories in {path}
5467 and concatenate the results. Example: >
5468 :echo globpath(&rtp, "syntax/c.vim")
5469<
5470 {path} is a comma-separated list of directory names. Each
5471 directory name is prepended to {expr} and expanded like with
5472 |glob()|. A path separator is inserted when needed.
5473 To add a comma inside a directory name escape it with a
5474 backslash. Note that on MS-Windows a directory may have a
5475 trailing backslash, remove it if you put a comma after it.
5476 If the expansion fails for one of the directories, there is no
5477 error message.
5478
5479 Unless the optional {nosuf} argument is given and is |TRUE|,
5480 the 'suffixes' and 'wildignore' options apply: Names matching
5481 one of the patterns in 'wildignore' will be skipped and
5482 'suffixes' affect the ordering of matches.
5483
5484 When {list} is present and it is |TRUE| the result is a |List|
5485 with all matching files. The advantage of using a List is, you
5486 also get filenames containing newlines correctly. Otherwise
5487 the result is a String and when there are several matches,
5488 they are separated by <NL> characters. Example: >
5489 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5490<
5491 {alllinks} is used as with |glob()|.
5492
5493 The "**" item can be used to search in a directory tree.
5494 For example, to find all "README.txt" files in the directories
5495 in 'runtimepath' and below: >
5496 :echo globpath(&rtp, "**/README.txt")
5497< Upwards search and limiting the depth of "**" is not
5498 supported, thus using 'path' will not always work properly.
5499
5500 Can also be used as a |method|, the base is passed as the
5501 second argument: >
5502 GetExpr()->globpath(&rtp)
5503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005504 Return type: |String| or list<string> or list<any> depending
5505 on {list}
5506
5507
5508has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005509 When {check} is omitted or is zero: The result is a Number,
5510 which is 1 if the feature {feature} is supported, zero
5511 otherwise. The {feature} argument is a string, case is
5512 ignored. See |feature-list| below.
5513
5514 When {check} is present and not zero: The result is a Number,
5515 which is 1 if the feature {feature} could ever be supported,
5516 zero otherwise. This is useful to check for a typo in
5517 {feature} and to detect dead code. Keep in mind that an older
5518 Vim version will not know about a feature added later and
5519 features that have been abandoned will not be known by the
5520 current Vim version.
5521
5522 Also see |exists()| and |exists_compiled()|.
5523
5524 Note that to skip code that has a syntax error when the
5525 feature is not available, Vim may skip the rest of the line
5526 and miss a following `endif`. Therefore put the `endif` on a
5527 separate line: >
5528 if has('feature')
5529 let x = this->breaks->without->the->feature
5530 endif
5531< If the `endif` would be moved to the second line as "| endif" it
5532 would not be found.
5533
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005534 Return type: |Number|
5535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005536
5537has_key({dict}, {key}) *has_key()*
5538 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005539 has an entry with key {key}. FALSE otherwise.
5540 The {key} argument is a string. In |Vim9| script a number is
5541 also accepted (and converted to a string) but no other types.
5542 In legacy script the usual automatic conversion to string is
5543 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005544
5545 Can also be used as a |method|: >
5546 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005547<
5548 Return type: |Number|
5549
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005550
5551haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5552 The result is a Number:
5553 1 when the window has set a local directory via |:lcd|
5554 2 when the tab-page has set a local directory via |:tcd|
5555 0 otherwise.
5556
5557 Without arguments use the current window.
5558 With {winnr} use this window in the current tab page.
5559 With {winnr} and {tabnr} use the window in the specified tab
5560 page.
5561 {winnr} can be the window number or the |window-ID|.
5562 If {winnr} is -1 it is ignored and only the tabpage is used.
5563 Return 0 if the arguments are invalid.
5564 Examples: >
5565 if haslocaldir() == 1
5566 " window local directory case
5567 elseif haslocaldir() == 2
5568 " tab-local directory case
5569 else
5570 " global directory case
5571 endif
5572
5573 " current window
5574 :echo haslocaldir()
5575 :echo haslocaldir(0)
5576 :echo haslocaldir(0, 0)
5577 " window n in current tab page
5578 :echo haslocaldir(n)
5579 :echo haslocaldir(n, 0)
5580 " window n in tab page m
5581 :echo haslocaldir(n, m)
5582 " tab page m
5583 :echo haslocaldir(-1, m)
5584<
5585 Can also be used as a |method|: >
5586 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005587<
5588 Return type: |Number|
5589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005590
5591hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5592 The result is a Number, which is TRUE if there is a mapping
5593 that contains {what} in somewhere in the rhs (what it is
5594 mapped to) and this mapping exists in one of the modes
5595 indicated by {mode}.
5596 The arguments {what} and {mode} are strings.
5597 When {abbr} is there and it is |TRUE| use abbreviations
5598 instead of mappings. Don't forget to specify Insert and/or
5599 Command-line mode.
5600 Both the global mappings and the mappings local to the current
5601 buffer are checked for a match.
5602 If no matching mapping is found FALSE is returned.
5603 The following characters are recognized in {mode}:
5604 n Normal mode
5605 v Visual and Select mode
5606 x Visual mode
5607 s Select mode
5608 o Operator-pending mode
5609 i Insert mode
5610 l Language-Argument ("r", "f", "t", etc.)
5611 c Command-line mode
5612 When {mode} is omitted, "nvo" is used.
5613
5614 This function is useful to check if a mapping already exists
5615 to a function in a Vim script. Example: >
5616 :if !hasmapto('\ABCdoit')
5617 : map <Leader>d \ABCdoit
5618 :endif
5619< This installs the mapping to "\ABCdoit" only if there isn't
5620 already a mapping to "\ABCdoit".
5621
5622 Can also be used as a |method|: >
5623 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005624<
5625 Return type: |Number|
5626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005627
5628histadd({history}, {item}) *histadd()*
5629 Add the String {item} to the history {history} which can be
5630 one of: *hist-names*
5631 "cmd" or ":" command line history
5632 "search" or "/" search pattern history
5633 "expr" or "=" typed expression history
5634 "input" or "@" input line history
5635 "debug" or ">" debug command history
5636 empty the current or last used history
5637 The {history} string does not need to be the whole name, one
5638 character is sufficient.
5639 If {item} does already exist in the history, it will be
5640 shifted to become the newest entry.
5641 The result is a Number: TRUE if the operation was successful,
5642 otherwise FALSE is returned.
5643
5644 Example: >
5645 :call histadd("input", strftime("%Y %b %d"))
5646 :let date=input("Enter date: ")
5647< This function is not available in the |sandbox|.
5648
5649 Can also be used as a |method|, the base is passed as the
5650 second argument: >
5651 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005652<
5653 Return type: |Number|
5654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005655
5656histdel({history} [, {item}]) *histdel()*
5657 Clear {history}, i.e. delete all its entries. See |hist-names|
5658 for the possible values of {history}.
5659
5660 If the parameter {item} evaluates to a String, it is used as a
5661 regular expression. All entries matching that expression will
5662 be removed from the history (if there are any).
5663 Upper/lowercase must match, unless "\c" is used |/\c|.
5664 If {item} evaluates to a Number, it will be interpreted as
5665 an index, see |:history-indexing|. The respective entry will
5666 be removed if it exists.
5667
5668 The result is TRUE for a successful operation, otherwise FALSE
5669 is returned.
5670
5671 Examples:
5672 Clear expression register history: >
5673 :call histdel("expr")
5674<
5675 Remove all entries starting with "*" from the search history: >
5676 :call histdel("/", '^\*')
5677<
5678 The following three are equivalent: >
5679 :call histdel("search", histnr("search"))
5680 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005681 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005682<
5683 To delete the last search pattern and use the last-but-one for
5684 the "n" command and 'hlsearch': >
5685 :call histdel("search", -1)
5686 :let @/ = histget("search", -1)
5687<
5688 Can also be used as a |method|: >
5689 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005690<
5691 Return type: |Number|
5692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005693
5694histget({history} [, {index}]) *histget()*
5695 The result is a String, the entry with Number {index} from
5696 {history}. See |hist-names| for the possible values of
5697 {history}, and |:history-indexing| for {index}. If there is
5698 no such entry, an empty String is returned. When {index} is
5699 omitted, the most recent item from the history is used.
5700
5701 Examples:
5702 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005703 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005704
5705< Define an Ex command ":H {num}" that supports re-execution of
5706 the {num}th entry from the output of |:history|. >
5707 :command -nargs=1 H execute histget("cmd", 0+<args>)
5708<
5709 Can also be used as a |method|: >
5710 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005711<
5712 Return type: |String|
5713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005714
5715histnr({history}) *histnr()*
5716 The result is the Number of the current entry in {history}.
5717 See |hist-names| for the possible values of {history}.
5718 If an error occurred, -1 is returned.
5719
5720 Example: >
5721 :let inp_index = histnr("expr")
5722
5723< Can also be used as a |method|: >
5724 GetHistory()->histnr()
5725<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005726 Return type: |Number|
5727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005728hlexists({name}) *hlexists()*
5729 The result is a Number, which is TRUE if a highlight group
5730 called {name} exists. This is when the group has been
5731 defined in some way. Not necessarily when highlighting has
5732 been defined for it, it may also have been used for a syntax
5733 item.
5734 *highlight_exists()*
5735 Obsolete name: highlight_exists().
5736
5737 Can also be used as a |method|: >
5738 GetName()->hlexists()
5739<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005740 Return type: |Number|
5741
5742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005743hlget([{name} [, {resolve}]]) *hlget()*
5744 Returns a List of all the highlight group attributes. If the
5745 optional {name} is specified, then returns a List with only
5746 the attributes of the specified highlight group. Returns an
5747 empty List if the highlight group {name} is not present.
5748
5749 If the optional {resolve} argument is set to v:true and the
5750 highlight group {name} is linked to another group, then the
5751 link is resolved recursively and the attributes of the
5752 resolved highlight group are returned.
5753
5754 Each entry in the returned List is a Dictionary with the
5755 following items:
5756 cleared boolean flag, set to v:true if the highlight
5757 group attributes are cleared or not yet
5758 specified. See |highlight-clear|.
5759 cterm cterm attributes. See |highlight-cterm|.
5760 ctermbg cterm background color.
5761 See |highlight-ctermbg|.
5762 ctermfg cterm foreground color.
5763 See |highlight-ctermfg|.
5764 ctermul cterm underline color. See |highlight-ctermul|.
5765 default boolean flag, set to v:true if the highlight
5766 group link is a default link. See
5767 |highlight-default|.
5768 font highlight group font. See |highlight-font|.
5769 gui gui attributes. See |highlight-gui|.
5770 guibg gui background color. See |highlight-guibg|.
5771 guifg gui foreground color. See |highlight-guifg|.
5772 guisp gui special color. See |highlight-guisp|.
5773 id highlight group ID.
5774 linksto linked highlight group name.
5775 See |:highlight-link|.
5776 name highlight group name. See |group-name|.
5777 start start terminal keycode. See |highlight-start|.
5778 stop stop terminal keycode. See |highlight-stop|.
5779 term term attributes. See |highlight-term|.
5780
5781 The 'term', 'cterm' and 'gui' items in the above Dictionary
5782 have a dictionary value with the following optional boolean
5783 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5784 'reverse', 'inverse' and 'strikethrough'.
5785
5786 Example(s): >
5787 :echo hlget()
5788 :echo hlget('ModeMsg')
5789 :echo hlget('Number', v:true)
5790<
5791 Can also be used as a |method|: >
5792 GetName()->hlget()
5793<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005794 Return type: list<dict<any>>
5795
5796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005797hlset({list}) *hlset()*
5798 Creates or modifies the attributes of a List of highlight
5799 groups. Each item in {list} is a dictionary containing the
5800 attributes of a highlight group. See |hlget()| for the list of
5801 supported items in this dictionary.
5802
5803 In addition to the items described in |hlget()|, the following
5804 additional items are supported in the dictionary:
5805
5806 force boolean flag to force the creation of
5807 a link for an existing highlight group
5808 with attributes.
5809
5810 The highlight group is identified using the 'name' item and
5811 the 'id' item (if supplied) is ignored. If a highlight group
5812 with a specified name doesn't exist, then it is created.
5813 Otherwise the attributes of an existing highlight group are
5814 modified.
5815
5816 If an empty dictionary value is used for the 'term' or 'cterm'
5817 or 'gui' entries, then the corresponding attributes are
5818 cleared. If the 'cleared' item is set to v:true, then all the
5819 attributes of the highlight group are cleared.
5820
5821 The 'linksto' item can be used to link a highlight group to
5822 another highlight group. See |:highlight-link|.
5823
5824 Returns zero for success, -1 for failure.
5825
5826 Example(s): >
5827 " add bold attribute to the Visual highlight group
5828 :call hlset([#{name: 'Visual',
5829 \ term: #{reverse: 1 , bold: 1}}])
5830 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5831 :let l = hlget()
5832 :call hlset(l)
5833 " clear the Search highlight group
5834 :call hlset([#{name: 'Search', cleared: v:true}])
5835 " clear the 'term' attributes for a highlight group
5836 :call hlset([#{name: 'Title', term: {}}])
5837 " create the MyHlg group linking it to DiffAdd
5838 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5839 " remove the MyHlg group link
5840 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5841 " clear the attributes and a link
5842 :call hlset([#{name: 'MyHlg', cleared: v:true,
5843 \ linksto: 'NONE'}])
5844<
5845 Can also be used as a |method|: >
5846 GetAttrList()->hlset()
5847<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005848 Return type: |Number|
5849
5850hlID({name}) *hlID()*
5851 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005852 with name {name}. When the highlight group doesn't exist,
5853 zero is returned.
5854 This can be used to retrieve information about the highlight
5855 group. For example, to get the background color of the
5856 "Comment" group: >
5857 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5858< *highlightID()*
5859 Obsolete name: highlightID().
5860
5861 Can also be used as a |method|: >
5862 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005863<
5864 Return type: |Number|
5865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005866
5867hostname() *hostname()*
5868 The result is a String, which is the name of the machine on
5869 which Vim is currently running. Machine names greater than
5870 256 characters long are truncated.
5871
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005872 Return type: |String|
5873
5874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005875iconv({string}, {from}, {to}) *iconv()*
5876 The result is a String, which is the text {string} converted
5877 from encoding {from} to encoding {to}.
5878 When the conversion completely fails an empty string is
5879 returned. When some characters could not be converted they
5880 are replaced with "?".
5881 The encoding names are whatever the iconv() library function
5882 can accept, see ":!man 3 iconv".
5883 Most conversions require Vim to be compiled with the |+iconv|
5884 feature. Otherwise only UTF-8 to latin1 conversion and back
5885 can be done.
5886 This can be used to display messages with special characters,
5887 no matter what 'encoding' is set to. Write the message in
5888 UTF-8 and use: >
5889 echo iconv(utf8_str, "utf-8", &enc)
5890< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5891 from/to UCS-2 is automatically changed to use UTF-8. You
5892 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5893
5894 Can also be used as a |method|: >
5895 GetText()->iconv('latin1', 'utf-8')
5896<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005897 Return type: |String|
5898
5899
h-east624bb832024-11-09 18:37:32 +01005900id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005901 The result is a unique String associated with the {item} and
5902 not with the {item}'s contents. It is only valid while the
5903 {item} exists and is referenced. It is valid only in the
5904 instance of vim that produces the result. The whole idea is
5905 that `id({item})` does not change if the contents of {item}
5906 changes. This is useful as a `key` for creating an identity
5907 dictionary, rather than one based on equals.
5908
5909 This operation does not reference {item} and there is no
5910 function to convert the `id` to the {item}. It may be useful to
5911 have a map of `id` to {item}. The following >
5912 var referenceMap: dict<any>
5913 var id = item->id()
5914 referenceMap[id] = item
5915< prevents {item} from being garbage collected and provides a
5916 way to get the {item} from the `id`.
5917
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005918 {item} may be a List, Tuple, Dictionary, Object, Job, Channel
5919 or Blob. If the item is not a permitted type, or it is a null
Ernie Raelc8e158b2024-07-09 18:39:52 +02005920 value, then an empty String is returned.
5921
5922 Can also be used as a |method|: >
5923 GetItem()->id()
5924<
5925 Return type: |String|
5926
5927
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005928indent({lnum}) *indent()*
5929 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005930 current buffer. The indent is counted in spaces, the value
5931 of 'tabstop' is relevant. {lnum} is used just like in
5932 |getline()|.
5933 When {lnum} is invalid -1 is returned. In |Vim9| script an
5934 error is given.
5935
5936 Can also be used as a |method|: >
5937 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005938<
5939 Return type: |Number|
5940
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005941
5942index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005943 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005944 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005945
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005946 If {object} is a |List| or a |Tuple| return the lowest index
5947 where the item has a value equal to {expr}. There is no
5948 automatic conversion, so the String "4" is different from the
5949 Number 4. And the number 4 is different from the Float 4.0.
5950 The value of 'ignorecase' is not used here, case matters as
5951 indicated by the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005952
5953 If {object} is |Blob| return the lowest index where the byte
5954 value is equal to {expr}.
5955
5956 If {start} is given then start looking at the item with index
5957 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005959 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5960 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005962 -1 is returned when {expr} is not found in {object}.
5963 Example: >
5964 :let idx = index(words, "the")
5965 :if index(numbers, 123) >= 0
5966
5967< Can also be used as a |method|: >
5968 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005969<
5970 Return type: |Number|
5971
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005972
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005973indexof({object}, {expr} [, {opts}]) *indexof()*
5974 Returns the index of an item in {object} where {expr} is
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005975 v:true. {object} must be a |List|, a |Tuple| or a |Blob|.
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005976
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005977 If {object} is a |List| or a |Tuple|, evaluate {expr} for each
Christ van Willegen92e109f2025-03-24 20:12:37 +01005978 item in the List or Tuple until the expression is v:true
5979 and return the index of this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005980
5981 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005982 Blob until the expression is v:true and return the index of
5983 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005984
5985 {expr} must be a |string| or |Funcref|.
5986
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005987 If {expr} is a |string|: If {object} is a |List| or a |Tuple|,
5988 inside {expr} |v:key| has the index of the current List or
5989 Tuple item and |v:val| has the value of the item. If {object}
5990 is a |Blob|, inside {expr} |v:key| has the index of the
5991 current byte and |v:val| has the byte value.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005992
5993 If {expr} is a |Funcref| it must take two arguments:
5994 1. the key or the index of the current item.
5995 2. the value of the current item.
5996 The function must return |TRUE| if the item is found and the
5997 search should stop.
5998
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005999 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01006000 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01006001 startidx start evaluating {expr} at the item with this
6002 index; may be negative for an item relative to
6003 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01006004 Returns -1 when {expr} evaluates to v:false for all the items.
6005 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01006006 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
6007 :echo indexof(l, "v:val.n == 20")
6008 :echo indexof(l, {i, v -> v.n == 30})
6009 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01006010
6011< Can also be used as a |method|: >
6012 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006013<
6014 Return type: |Number|
6015
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01006016
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006017input({prompt} [, {text} [, {completion}]]) *input()*
6018 The result is a String, which is whatever the user typed on
6019 the command-line. The {prompt} argument is either a prompt
6020 string, or a blank string (for no prompt). A '\n' can be used
6021 in the prompt to start a new line.
6022 The highlighting set with |:echohl| is used for the prompt.
6023 The input is entered just like a command-line, with the same
6024 editing commands and mappings. There is a separate history
6025 for lines typed for input().
6026 Example: >
6027 :if input("Coffee or beer? ") == "beer"
6028 : echo "Cheers!"
6029 :endif
6030<
6031 If the optional {text} argument is present and not empty, this
6032 is used for the default reply, as if the user typed this.
6033 Example: >
6034 :let color = input("Color? ", "white")
6035
6036< The optional {completion} argument specifies the type of
6037 completion supported for the input. Without it completion is
6038 not performed. The supported completion types are the same as
6039 that can be supplied to a user-defined command using the
6040 "-complete=" argument. Refer to |:command-completion| for
6041 more information. Example: >
6042 let fname = input("File: ", "", "file")
6043<
6044 NOTE: This function must not be used in a startup file, for
6045 the versions that only run in GUI mode (e.g., the Win32 GUI).
6046 Note: When input() is called from within a mapping it will
6047 consume remaining characters from that mapping, because a
6048 mapping is handled like the characters were typed.
6049 Use |inputsave()| before input() and |inputrestore()|
6050 after input() to avoid that. Another solution is to avoid
6051 that further characters follow in the mapping, e.g., by using
6052 |:execute| or |:normal|.
6053
6054 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006055 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006056 :function GetFoo()
6057 : call inputsave()
6058 : let g:Foo = input("enter search pattern: ")
6059 : call inputrestore()
6060 :endfunction
6061
6062< Can also be used as a |method|: >
6063 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006064<
6065 Return type: |String|
6066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006067
6068inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
6069 Like |input()|, but when the GUI is running and text dialogs
6070 are supported, a dialog window pops up to input the text.
6071 Example: >
6072 :let n = inputdialog("value for shiftwidth", shiftwidth())
6073 :if n != ""
6074 : let &sw = n
6075 :endif
6076< When the dialog is cancelled {cancelreturn} is returned. When
6077 omitted an empty string is returned.
6078 Hitting <Enter> works like pressing the OK button. Hitting
6079 <Esc> works like pressing the Cancel button.
6080 NOTE: Command-line completion is not supported.
6081
6082 Can also be used as a |method|: >
6083 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006084<
6085 Return type: |String|
6086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006087
6088inputlist({textlist}) *inputlist()*
6089 {textlist} must be a |List| of strings. This |List| is
6090 displayed, one string per line. The user will be prompted to
6091 enter a number, which is returned.
6092 The user can also select an item by clicking on it with the
6093 mouse, if the mouse is enabled in the command line ('mouse' is
6094 "a" or includes "c"). For the first string 0 is returned.
6095 When clicking above the first item a negative number is
6096 returned. When clicking on the prompt one more than the
6097 length of {textlist} is returned.
6098 Make sure {textlist} has less than 'lines' entries, otherwise
6099 it won't work. It's a good idea to put the entry number at
6100 the start of the string. And put a prompt in the first item.
6101 Example: >
6102 let color = inputlist(['Select color:', '1. red',
6103 \ '2. green', '3. blue'])
6104
6105< Can also be used as a |method|: >
6106 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006107<
6108 Return type: |Number|
6109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006110
6111inputrestore() *inputrestore()*
6112 Restore typeahead that was saved with a previous |inputsave()|.
6113 Should be called the same number of times inputsave() is
6114 called. Calling it more often is harmless though.
6115 Returns TRUE when there is nothing to restore, FALSE otherwise.
6116
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006117 Return type: |Number|
6118
6119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006120inputsave() *inputsave()*
6121 Preserve typeahead (also from mappings) and clear it, so that
6122 a following prompt gets input from the user. Should be
6123 followed by a matching inputrestore() after the prompt. Can
6124 be used several times, in which case there must be just as
6125 many inputrestore() calls.
6126 Returns TRUE when out of memory, FALSE otherwise.
6127
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006128 Return type: |Number|
6129
6130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006131inputsecret({prompt} [, {text}]) *inputsecret()*
6132 This function acts much like the |input()| function with but
6133 two exceptions:
6134 a) the user's response will be displayed as a sequence of
6135 asterisks ("*") thereby keeping the entry secret, and
6136 b) the user's response will not be recorded on the input
6137 |history| stack.
6138 The result is a String, which is whatever the user actually
6139 typed on the command-line in response to the issued prompt.
6140 NOTE: Command-line completion is not supported.
6141
6142 Can also be used as a |method|: >
6143 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006144<
6145 Return type: |String|
6146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006147
6148insert({object}, {item} [, {idx}]) *insert()*
6149 When {object} is a |List| or a |Blob| insert {item} at the start
6150 of it.
6151
6152 If {idx} is specified insert {item} before the item with index
6153 {idx}. If {idx} is zero it goes before the first item, just
6154 like omitting {idx}. A negative {idx} is also possible, see
6155 |list-index|. -1 inserts just before the last item.
6156
6157 Returns the resulting |List| or |Blob|. Examples: >
6158 :let mylist = insert([2, 3, 5], 1)
6159 :call insert(mylist, 4, -1)
6160 :call insert(mylist, 6, len(mylist))
6161< The last example can be done simpler with |add()|.
6162 Note that when {item} is a |List| it is inserted as a single
6163 item. Use |extend()| to concatenate |Lists|.
6164
6165 Can also be used as a |method|: >
6166 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006168 Return type: |Number|
6169
6170
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006171 *instanceof()* *E614* *E616* *E693*
6172instanceof({object}, {class})
6173 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006174 argument is a direct or indirect instance of a |Class|,
6175 |Interface|, or class |:type| alias specified by {class}.
6176 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006177 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006178 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006179 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006180
6181< Can also be used as a |method|: >
6182 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006183<
6184 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006186interrupt() *interrupt()*
6187 Interrupt script execution. It works more or less like the
6188 user typing CTRL-C, most commands won't execute and control
6189 returns to the user. This is useful to abort execution
6190 from lower down, e.g. in an autocommand. Example: >
6191 :function s:check_typoname(file)
6192 : if fnamemodify(a:file, ':t') == '['
6193 : echomsg 'Maybe typo'
6194 : call interrupt()
6195 : endif
6196 :endfunction
6197 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006198<
6199 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006200
6201invert({expr}) *invert()*
6202 Bitwise invert. The argument is converted to a number. A
6203 List, Dict or Float argument causes an error. Example: >
6204 :let bits = invert(bits)
6205< Can also be used as a |method|: >
6206 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006207<
6208 Return type: |Number|
6209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006210
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006211isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006212 The result is a Number, which is |TRUE| when {path} is an
6213 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006214 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006215 On MS-Windows, it is considered absolute when it starts with an
6216 optional drive prefix and is followed by a '\' or '/'. UNC paths
6217 are always absolute.
6218 Example: >
6219 echo isabsolutepath('/usr/share/') " 1
6220 echo isabsolutepath('./foobar') " 0
6221 echo isabsolutepath('C:\Windows') " 1
6222 echo isabsolutepath('foobar') " 0
6223 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006224<
LemonBoydca1d402022-04-28 15:26:33 +01006225 Can also be used as a |method|: >
6226 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006227<
6228 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006229
6230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006231isdirectory({directory}) *isdirectory()*
6232 The result is a Number, which is |TRUE| when a directory
6233 with the name {directory} exists. If {directory} doesn't
6234 exist, or isn't a directory, the result is |FALSE|. {directory}
6235 is any expression, which is used as a String.
6236
6237 Can also be used as a |method|: >
6238 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006239<
6240 Return type: |Number|
6241
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006242
6243isinf({expr}) *isinf()*
6244 Return 1 if {expr} is a positive infinity, or -1 a negative
6245 infinity, otherwise 0. >
6246 :echo isinf(1.0 / 0.0)
6247< 1 >
6248 :echo isinf(-1.0 / 0.0)
6249< -1
6250
6251 Can also be used as a |method|: >
6252 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006253<
6254 Return type: |Number|
6255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006256
6257islocked({expr}) *islocked()* *E786*
6258 The result is a Number, which is |TRUE| when {expr} is the
6259 name of a locked variable.
6260 The string argument {expr} must be the name of a variable,
6261 |List| item or |Dictionary| entry, not the variable itself!
6262 Example: >
6263 :let alist = [0, ['a', 'b'], 2, 3]
6264 :lockvar 1 alist
6265 :echo islocked('alist') " 1
6266 :echo islocked('alist[1]') " 0
6267
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006268< When {expr} is a variable that does not exist -1 is returned.
6269 If {expr} uses a range, list or dict index that is out of
6270 range or does not exist you get an error message. Use
6271 |exists()| to check for existence.
6272 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006273
6274 Can also be used as a |method|: >
6275 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006276<
6277 Return type: |Number|
6278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006279
6280isnan({expr}) *isnan()*
6281 Return |TRUE| if {expr} is a float with value NaN. >
6282 echo isnan(0.0 / 0.0)
6283< 1
6284
6285 Can also be used as a |method|: >
6286 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006287<
6288 Return type: |Number|
6289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006290
6291items({dict}) *items()*
6292 Return a |List| with all the key-value pairs of {dict}. Each
6293 |List| item is a list with two items: the key of a {dict}
6294 entry and the value of this entry. The |List| is in arbitrary
6295 order. Also see |keys()| and |values()|.
6296 Example: >
6297 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006298 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006299 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006300<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006301 A |List|, a |Tuple| or a |String| argument is also supported.
6302 In these cases, items() returns a List with the index and the
6303 value at the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006304
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006305 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006306 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006307<
6308 Return type: list<list<any>> or list<any>
6309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006310
6311job_ functions are documented here: |job-functions-details|
6312
6313
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006314join({expr} [, {sep}]) *join()*
6315 Join the items in {expr} together into one String. {expr} can
6316 be a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006317 When {sep} is specified it is put in between the items. If
6318 {sep} is omitted a single space is used.
6319 Note that {sep} is not added at the end. You might want to
6320 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006321 let lines = join(mylist, "\n") .. "\n"
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006322< String items are used as-is. |Lists|, |Tuples| and
6323 |Dictionaries| are converted into a string like with
6324 |string()|. The opposite function is |split()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006325
6326 Can also be used as a |method|: >
6327 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006328<
6329 Return type: |String|
6330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006331
6332js_decode({string}) *js_decode()*
6333 This is similar to |json_decode()| with these differences:
6334 - Object key names do not have to be in quotes.
6335 - Strings can be in single quotes.
6336 - Empty items in an array (between two commas) are allowed and
6337 result in v:none items.
6338
6339 Can also be used as a |method|: >
6340 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006341<
6342 Return type: any, depending on {varname}
6343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006344
6345js_encode({expr}) *js_encode()*
6346 This is similar to |json_encode()| with these differences:
6347 - Object key names are not in quotes.
6348 - v:none items in an array result in an empty item between
6349 commas.
6350 For example, the Vim object:
6351 [1,v:none,{"one":1},v:none] ~
6352 Will be encoded as:
6353 [1,,{one:1},,] ~
6354 While json_encode() would produce:
6355 [1,null,{"one":1},null] ~
6356 This encoding is valid for JavaScript. It is more efficient
6357 than JSON, especially when using an array with optional items.
6358
6359 Can also be used as a |method|: >
6360 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006361<
6362 Return type: |String|
6363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006364
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006365json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006366 This parses a JSON formatted string and returns the equivalent
6367 in Vim values. See |json_encode()| for the relation between
6368 JSON and Vim values.
6369 The decoding is permissive:
6370 - A trailing comma in an array and object is ignored, e.g.
6371 "[1, 2, ]" is the same as "[1, 2]".
6372 - Integer keys are accepted in objects, e.g. {1:2} is the
6373 same as {"1":2}.
6374 - More floating point numbers are recognized, e.g. "1." for
6375 "1.0", or "001.2" for "1.2". Special floating point values
6376 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6377 are accepted.
6378 - Leading zeroes in integer numbers are ignored, e.g. "012"
6379 for "12" or "-012" for "-12".
6380 - Capitalization is ignored in literal names null, true or
6381 false, e.g. "NULL" for "null", "True" for "true".
6382 - Control characters U+0000 through U+001F which are not
6383 escaped in strings are accepted, e.g. " " (tab
6384 character in string) for "\t".
6385 - An empty JSON expression or made of only spaces is accepted
6386 and results in v:none.
6387 - Backslash in an invalid 2-character sequence escape is
6388 ignored, e.g. "\a" is decoded as "a".
6389 - A correct surrogate pair in JSON strings should normally be
6390 a 12 character sequence such as "\uD834\uDD1E", but
6391 json_decode() silently accepts truncated surrogate pairs
6392 such as "\uD834" or "\uD834\u"
6393 *E938*
6394 A duplicate key in an object, valid in rfc7159, is not
6395 accepted by json_decode() as the result must be a valid Vim
6396 type, e.g. this fails: {"a":"b", "a":"c"}
6397
6398 Can also be used as a |method|: >
6399 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006400<
6401 Return type: any, depending on {varname}
6402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006403
6404json_encode({expr}) *json_encode()*
6405 Encode {expr} as JSON and return this as a string.
6406 The encoding is specified in:
6407 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006408 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006409 |Number| decimal number
6410 |Float| floating point number
6411 Float nan "NaN"
6412 Float inf "Infinity"
6413 Float -inf "-Infinity"
6414 |String| in double quotes (possibly null)
6415 |Funcref| not possible, error
6416 |List| as an array (possibly null); when
6417 used recursively: []
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006418 |Tuple| as an array (possibly null); when
6419 used recursively: []
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006420 |Dict| as an object (possibly null); when
6421 used recursively: {}
6422 |Blob| as an array of the individual bytes
6423 v:false "false"
6424 v:true "true"
6425 v:none "null"
6426 v:null "null"
6427 Note that NaN and Infinity are passed on as values. This is
6428 missing in the JSON standard, but several implementations do
6429 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006430 If a string contains an illegal character then the replacement
6431 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006432
6433 Can also be used as a |method|: >
6434 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006435<
6436 Return type: |String|
6437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006438
6439keys({dict}) *keys()*
6440 Return a |List| with all the keys of {dict}. The |List| is in
6441 arbitrary order. Also see |items()| and |values()|.
6442
6443 Can also be used as a |method|: >
6444 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006445<
6446 Return type: list<string>
6447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006448
zeertzjqcdc83932022-09-12 13:38:41 +01006449keytrans({string}) *keytrans()*
6450 Turn the internal byte representation of keys into a form that
6451 can be used for |:map|. E.g. >
6452 :let xx = "\<C-Home>"
6453 :echo keytrans(xx)
6454< <C-Home>
6455
6456 Can also be used as a |method|: >
6457 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006458<
6459 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006460
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006461
6462len({expr}) *len()* *E701*
6463 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006464 When {expr} is a String or a Number the length in bytes is
6465 used, as with |strlen()|.
6466 When {expr} is a |List| the number of items in the |List| is
6467 returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006468 When {expr} is a |Tuple| the number of items in the |Tuple| is
6469 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006470 When {expr} is a |Blob| the number of bytes is returned.
6471 When {expr} is a |Dictionary| the number of entries in the
6472 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006473 When {expr} is an |Object|, invokes the len() method in the
6474 object (if present) to get the length (|object-len()|).
6475 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476
6477 Can also be used as a |method|: >
6478 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006479<
6480 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006482
6483 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006484libcall({libname}, {funcname}, {argument})
6485 Call function {funcname} in the run-time library {libname}
6486 with single argument {argument}.
6487 This is useful to call functions in a library that you
6488 especially made to be used with Vim. Since only one argument
6489 is possible, calling standard library functions is rather
6490 limited.
6491 The result is the String returned by the function. If the
6492 function returns NULL, this will appear as an empty string ""
6493 to Vim.
6494 If the function returns a number, use libcallnr()!
6495 If {argument} is a number, it is passed to the function as an
6496 int; if {argument} is a string, it is passed as a
6497 null-terminated string.
6498 This function will fail in |restricted-mode|.
6499
6500 libcall() allows you to write your own 'plug-in' extensions to
6501 Vim without having to recompile the program. It is NOT a
6502 means to call system functions! If you try to do so Vim will
6503 very probably crash.
6504
6505 For Win32, the functions you write must be placed in a DLL
6506 and use the normal C calling convention (NOT Pascal which is
6507 used in Windows System DLLs). The function must take exactly
6508 one parameter, either a character pointer or a long integer,
6509 and must return a character pointer or NULL. The character
6510 pointer returned must point to memory that will remain valid
6511 after the function has returned (e.g. in static data in the
6512 DLL). If it points to allocated memory, that memory will
6513 leak away. Using a static buffer in the function should work,
6514 it's then freed when the DLL is unloaded.
6515
6516 WARNING: If the function returns a non-valid pointer, Vim may
6517 crash! This also happens if the function returns a number,
6518 because Vim thinks it's a pointer.
6519 For Win32 systems, {libname} should be the filename of the DLL
6520 without the ".DLL" suffix. A full path is only required if
6521 the DLL is not in the usual places.
6522 For Unix: When compiling your own plugins, remember that the
6523 object code must be compiled as position-independent ('PIC').
6524 {only in Win32 and some Unix versions, when the |+libcall|
6525 feature is present}
6526 Examples: >
6527 :echo libcall("libc.so", "getenv", "HOME")
6528
6529< Can also be used as a |method|, the base is passed as the
6530 third argument: >
6531 GetValue()->libcall("libc.so", "getenv")
6532<
6533 *libcallnr()*
6534libcallnr({libname}, {funcname}, {argument})
6535 Just like |libcall()|, but used for a function that returns an
6536 int instead of a string.
6537 {only in Win32 on some Unix versions, when the |+libcall|
6538 feature is present}
6539 Examples: >
6540 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6541 :call libcallnr("libc.so", "printf", "Hello World!\n")
6542 :call libcallnr("libc.so", "sleep", 10)
6543<
6544 Can also be used as a |method|, the base is passed as the
6545 third argument: >
6546 GetValue()->libcallnr("libc.so", "printf")
6547<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006548 Return type: |String|
6549
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006550
6551line({expr} [, {winid}]) *line()*
6552 The result is a Number, which is the line number of the file
6553 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006554 See |getpos()| for accepted positions.
6555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006556 To get the column number use |col()|. To get both use
6557 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006559 With the optional {winid} argument the values are obtained for
6560 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006561
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006562 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006564 Examples: >
6565 line(".") line number of the cursor
6566 line(".", winid) idem, in window "winid"
6567 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006568 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006569<
6570 To jump to the last known position when opening a file see
6571 |last-position-jump|.
6572
6573 Can also be used as a |method|: >
6574 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006575<
6576 Return type: |Number|
6577
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006578
6579line2byte({lnum}) *line2byte()*
6580 Return the byte count from the start of the buffer for line
6581 {lnum}. This includes the end-of-line character, depending on
6582 the 'fileformat' option for the current buffer. The first
6583 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6584 This can also be used to get the byte count for the line just
6585 below the last line: >
6586 line2byte(line("$") + 1)
6587< This is the buffer size plus one. If 'fileencoding' is empty
6588 it is the file size plus one. {lnum} is used like with
6589 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6590 feature has been disabled at compile time, -1 is returned.
6591 Also see |byte2line()|, |go| and |:goto|.
6592
6593 Can also be used as a |method|: >
6594 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006595<
6596 Return type: |Number|
6597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006598
6599lispindent({lnum}) *lispindent()*
6600 Get the amount of indent for line {lnum} according the lisp
6601 indenting rules, as with 'lisp'.
6602 The indent is counted in spaces, the value of 'tabstop' is
6603 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006604 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006605 error is given.
6606
6607 Can also be used as a |method|: >
6608 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006609<
6610 Return type: |Number|
6611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006612
6613list2blob({list}) *list2blob()*
6614 Return a Blob concatenating all the number values in {list}.
6615 Examples: >
6616 list2blob([1, 2, 3, 4]) returns 0z01020304
6617 list2blob([]) returns 0z
6618< Returns an empty Blob on error. If one of the numbers is
6619 negative or more than 255 error *E1239* is given.
6620
6621 |blob2list()| does the opposite.
6622
6623 Can also be used as a |method|: >
6624 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006625<
6626 Return type: |Blob|
6627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006628
6629list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006630 Convert each number in {list} to a character string and
6631 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006632 list2str([32]) returns " "
6633 list2str([65, 66, 67]) returns "ABC"
6634< The same can be done (slowly) with: >
6635 join(map(list, {nr, val -> nr2char(val)}), '')
6636< |str2list()| does the opposite.
6637
6638 When {utf8} is omitted or zero, the current 'encoding' is used.
6639 When {utf8} is TRUE, always return UTF-8 characters.
6640 With UTF-8 composing characters work as expected: >
6641 list2str([97, 769]) returns "á"
6642<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006643 Returns an empty string on error.
6644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006645 Can also be used as a |method|: >
6646 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006647<
6648 Return type: |String|
6649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006650
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006651list2tuple({list}) *list2tuple()*
6652 Create a Tuple from a shallow copy of the list items.
6653 Examples: >
6654 list2tuple([1, 2, 3]) returns (1, 2, 3)
6655< |tuple2list()| does the opposite.
6656
6657 This function doesn't recursively convert all the List items
6658 in {list} to a Tuple. Note that the items are identical
6659 between the list and the tuple, changing an item changes the
6660 contents of both the tuple and the list.
6661
6662 Returns an empty tuple on error.
6663
6664 Can also be used as a |method|: >
6665 GetList()->list2tuple()
6666<
6667 Return type: tuple<{type}> (depending on the given |List|)
6668
6669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006670listener_add({callback} [, {buf}]) *listener_add()*
6671 Add a callback function that will be invoked when changes have
6672 been made to buffer {buf}.
6673 {buf} refers to a buffer name or number. For the accepted
6674 values, see |bufname()|. When {buf} is omitted the current
6675 buffer is used.
6676 Returns a unique ID that can be passed to |listener_remove()|.
6677
6678 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006679 bufnr the buffer that was changed
6680 start first changed line number
6681 end first line number below the change
6682 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006684 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006685
6686 Example: >
6687 func Listener(bufnr, start, end, added, changes)
6688 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6689 endfunc
6690 call listener_add('Listener', bufnr)
6691
Bram Moolenaar944697a2022-02-20 19:48:20 +00006692< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006693 dictionary with these entries:
6694 lnum the first line number of the change
6695 end the first line below the change
6696 added number of lines added; negative if lines were
6697 deleted
6698 col first column in "lnum" that was affected by
6699 the change; one if unknown or the whole line
6700 was affected; this is a byte index, first
6701 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006702 When lines are inserted (not when a line is split, e.g. by
6703 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006704 lnum line above which the new line is added
6705 end equal to "lnum"
6706 added number of lines inserted
6707 col 1
6708 When lines are deleted the values are:
6709 lnum the first deleted line
6710 end the line below the first deleted line, before
6711 the deletion was done
6712 added negative, number of lines deleted
6713 col 1
6714 When lines are changed:
6715 lnum the first changed line
6716 end the line below the last changed line
6717 added 0
6718 col first column with a change or 1
6719
6720 The entries are in the order the changes were made, thus the
6721 most recent change is at the end. The line numbers are valid
6722 when the callback is invoked, but later changes may make them
6723 invalid, thus keeping a copy for later might not work.
6724
6725 The {callback} is invoked just before the screen is updated,
6726 when |listener_flush()| is called or when a change is being
6727 made that changes the line count in a way it causes a line
6728 number in the list of changes to become invalid.
6729
6730 The {callback} is invoked with the text locked, see
6731 |textlock|. If you do need to make changes to the buffer, use
6732 a timer to do this later |timer_start()|.
6733
6734 The {callback} is not invoked when the buffer is first loaded.
6735 Use the |BufReadPost| autocmd event to handle the initial text
6736 of a buffer.
6737 The {callback} is also not invoked when the buffer is
6738 unloaded, use the |BufUnload| autocmd event for that.
6739
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006740 Returns zero if {callback} or {buf} is invalid.
6741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006742 Can also be used as a |method|, the base is passed as the
6743 second argument: >
6744 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006745<
6746 Return type: |Number|
6747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006748
6749listener_flush([{buf}]) *listener_flush()*
6750 Invoke listener callbacks for buffer {buf}. If there are no
6751 pending changes then no callbacks are invoked.
6752
6753 {buf} refers to a buffer name or number. For the accepted
6754 values, see |bufname()|. When {buf} is omitted the current
6755 buffer is used.
6756
6757 Can also be used as a |method|: >
6758 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006759<
6760 Return type: |Number|
6761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006762
6763listener_remove({id}) *listener_remove()*
6764 Remove a listener previously added with listener_add().
6765 Returns FALSE when {id} could not be found, TRUE when {id} was
6766 removed.
6767
6768 Can also be used as a |method|: >
6769 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006770<
6771 Return type: |Number|
6772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006773
6774localtime() *localtime()*
6775 Return the current time, measured as seconds since 1st Jan
6776 1970. See also |strftime()|, |strptime()| and |getftime()|.
6777
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006778 Return type: |Number|
6779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006780
6781log({expr}) *log()*
6782 Return the natural logarithm (base e) of {expr} as a |Float|.
6783 {expr} must evaluate to a |Float| or a |Number| in the range
6784 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006785 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006786 Examples: >
6787 :echo log(10)
6788< 2.302585 >
6789 :echo log(exp(5))
6790< 5.0
6791
6792 Can also be used as a |method|: >
6793 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006794<
6795 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006796
6797
6798log10({expr}) *log10()*
6799 Return the logarithm of Float {expr} to base 10 as a |Float|.
6800 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006801 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006802 Examples: >
6803 :echo log10(1000)
6804< 3.0 >
6805 :echo log10(0.01)
6806< -2.0
6807
6808 Can also be used as a |method|: >
6809 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006810<
6811 Return type: |Float|
6812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006813
6814luaeval({expr} [, {expr}]) *luaeval()*
6815 Evaluate Lua expression {expr} and return its result converted
6816 to Vim data structures. Second {expr} may hold additional
6817 argument accessible as _A inside first {expr}.
6818 Strings are returned as they are.
6819 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006820 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006821 Dictionaries and lists obtained by vim.eval() are returned
6822 as-is.
6823 Other objects are returned as zero without any errors.
6824 See |lua-luaeval| for more details.
6825 Note that in a `:def` function local variables are not visible
6826 to {expr}.
6827
6828 Can also be used as a |method|: >
6829 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006830<
6831 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006832
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006833 {only available when compiled with the |+lua| feature}
6834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006835
6836map({expr1}, {expr2}) *map()*
6837 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006838 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006839 item in {expr1} with the result of evaluating {expr2}.
6840 For a |Blob| each byte is replaced.
6841 For a |String|, each character, including composing
6842 characters, is replaced.
6843 If the item type changes you may want to use |mapnew()| to
6844 create a new List or Dictionary. This is required when using
6845 Vim9 script.
6846
6847 {expr2} must be a |String| or |Funcref|.
6848
6849 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6850 of the current item. For a |Dictionary| |v:key| has the key
6851 of the current item and for a |List| |v:key| has the index of
6852 the current item. For a |Blob| |v:key| has the index of the
6853 current byte. For a |String| |v:key| has the index of the
6854 current character.
6855 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006856 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006857< This puts "> " before and " <" after each item in "mylist".
6858
6859 Note that {expr2} is the result of an expression and is then
6860 used as an expression again. Often it is good to use a
6861 |literal-string| to avoid having to double backslashes. You
6862 still have to double ' quotes
6863
6864 If {expr2} is a |Funcref| it is called with two arguments:
6865 1. The key or the index of the current item.
6866 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006867 With a legacy script lambda you don't get an error if it only
6868 accepts one argument, but with a Vim9 lambda you get "E1106:
6869 One argument too many", the number of arguments must match.
6870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006871 The function must return the new value of the item. Example
6872 that changes each value by "key-value": >
6873 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006874 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006875 endfunc
6876 call map(myDict, function('KeyValue'))
6877< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006878 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006879< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006880 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006881< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006882 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006883<
6884 The operation is done in-place for a |List| and |Dictionary|.
6885 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006886 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006887
6888< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6889 or a new |Blob| or |String|.
6890 When an error is encountered while evaluating {expr2} no
6891 further items in {expr1} are processed.
6892 When {expr2} is a Funcref errors inside a function are ignored,
6893 unless it was defined with the "abort" flag.
6894
6895 Can also be used as a |method|: >
6896 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006897<
6898 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6899 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006900
6901
6902maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6903 When {dict} is omitted or zero: Return the rhs of mapping
6904 {name} in mode {mode}. The returned String has special
6905 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006906 listing. When {dict} is TRUE a dictionary is returned, see
6907 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006908
6909 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006910 returned if {dict} is FALSE, otherwise returns an empty Dict.
6911 When the mapping for {name} is empty, then "<Nop>" is
6912 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006913
6914 The {name} can have special key names, like in the ":map"
6915 command.
6916
6917 {mode} can be one of these strings:
6918 "n" Normal
6919 "v" Visual (including Select)
6920 "o" Operator-pending
6921 "i" Insert
6922 "c" Cmd-line
6923 "s" Select
6924 "x" Visual
6925 "l" langmap |language-mapping|
6926 "t" Terminal-Job
6927 "" Normal, Visual and Operator-pending
6928 When {mode} is omitted, the modes for "" are used.
6929
6930 When {abbr} is there and it is |TRUE| use abbreviations
6931 instead of mappings.
6932
6933 When {dict} is there and it is |TRUE| return a dictionary
6934 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006935 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006936 "lhs" The {lhs} of the mapping as it would be typed
6937 "lhsraw" The {lhs} of the mapping as raw bytes
6938 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6939 form, only present when it differs from "lhsraw"
6940 "rhs" The {rhs} of the mapping as typed.
6941 "silent" 1 for a |:map-silent| mapping, else 0.
6942 "noremap" 1 if the {rhs} of the mapping is not remappable.
6943 "script" 1 if mapping was defined with <script>.
6944 "expr" 1 for an expression mapping (|:map-<expr>|).
6945 "buffer" 1 for a buffer local mapping (|:map-local|).
6946 "mode" Modes for which the mapping is defined. In
6947 addition to the modes mentioned above, these
6948 characters will be used:
6949 " " Normal, Visual and Operator-pending
6950 "!" Insert and Commandline mode
6951 (|mapmode-ic|)
6952 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006953 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006954 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006955 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006956 "lnum" The line number in "sid", zero if unknown.
6957 "nowait" Do not wait for other, longer mappings.
6958 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006959 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006960 "mode_bits" Vim's internal binary representation of "mode".
6961 |mapset()| ignores this; only "mode" is used.
6962 See |maplist()| for usage examples. The values
6963 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006964
6965 The dictionary can be used to restore a mapping with
6966 |mapset()|.
6967
6968 The mappings local to the current buffer are checked first,
6969 then the global mappings.
6970 This function can be used to map a key even when it's already
6971 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006972 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006973
6974< Can also be used as a |method|: >
6975 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006976<
6977 Return type: |String| or dict<any> depending on {dict}
6978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006979
6980mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6981 Check if there is a mapping that matches with {name} in mode
6982 {mode}. See |maparg()| for {mode} and special names in
6983 {name}.
6984 When {abbr} is there and it is |TRUE| use abbreviations
6985 instead of mappings.
6986 A match happens with a mapping that starts with {name} and
6987 with a mapping which is equal to the start of {name}.
6988
6989 matches mapping "a" "ab" "abc" ~
6990 mapcheck("a") yes yes yes
6991 mapcheck("abc") yes yes yes
6992 mapcheck("ax") yes no no
6993 mapcheck("b") no no no
6994
6995 The difference with maparg() is that mapcheck() finds a
6996 mapping that matches with {name}, while maparg() only finds a
6997 mapping for {name} exactly.
6998 When there is no mapping that starts with {name}, an empty
6999 String is returned. If there is one, the RHS of that mapping
7000 is returned. If there are several mappings that start with
7001 {name}, the RHS of one of them is returned. This will be
7002 "<Nop>" if the RHS is empty.
7003 The mappings local to the current buffer are checked first,
7004 then the global mappings.
7005 This function can be used to check if a mapping can be added
7006 without being ambiguous. Example: >
7007 :if mapcheck("_vv") == ""
7008 : map _vv :set guifont=7x13<CR>
7009 :endif
7010< This avoids adding the "_vv" mapping when there already is a
7011 mapping for "_v" or for "_vvv".
7012
7013 Can also be used as a |method|: >
7014 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007015<
7016 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007017
7018
Ernie Rael09661202022-04-25 14:40:44 +01007019maplist([{abbr}]) *maplist()*
7020 Returns a |List| of all mappings. Each List item is a |Dict|,
7021 the same as what is returned by |maparg()|, see
7022 |mapping-dict|. When {abbr} is there and it is |TRUE| use
7023 abbreviations instead of mappings.
7024
7025 Example to show all mappings with 'MultiMatch' in rhs: >
7026 vim9script
7027 echo maplist()->filter(
7028 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01007029< It can be tricky to find mappings for particular |:map-modes|.
7030 |mapping-dict|'s "mode_bits" can simplify this. For example,
7031 the mode_bits for Normal, Insert or Command-line modes are
7032 0x19. To find all the mappings available in those modes you
7033 can do: >
7034 vim9script
7035 var saved_maps = []
7036 for m in maplist()
7037 if and(m.mode_bits, 0x19) != 0
7038 saved_maps->add(m)
7039 endif
7040 endfor
7041 echo saved_maps->mapnew((_, m) => m.lhs)
7042< The values of the mode_bits are defined in Vim's src/vim.h
7043 file and they can be discovered at runtime using
7044 |:map-commands| and "maplist()". Example: >
7045 vim9script
7046 omap xyzzy <Nop>
7047 var op_bit = maplist()->filter(
7048 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
7049 ounmap xyzzy
7050 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007051<
7052 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01007053
7054
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007055mapnew({expr1}, {expr2}) *mapnew()*
7056 Like |map()| but instead of replacing items in {expr1} a new
7057 List or Dictionary is created and returned. {expr1} remains
7058 unchanged. Items can still be changed by {expr2}, if you
7059 don't want that use |deepcopy()| first.
7060
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007061 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
7062 depending on {expr1}
7063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007064
7065mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01007066mapset({dict})
7067 Restore a mapping from a dictionary, possibly returned by
7068 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
7069 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01007070 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01007071 feature allows copying mappings from one buffer to another.
7072 The dict.mode value may restore a single mapping that covers
7073 more than one mode, like with mode values of '!', ' ', 'nox',
7074 or 'v'. *E1276*
7075
7076 In the first form, {mode} and {abbr} should be the same as
7077 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007078 {mode} is used to define the mode in which the mapping is set,
7079 not the "mode" entry in {dict}.
7080 Example for saving and restoring a mapping: >
7081 let save_map = maparg('K', 'n', 0, 1)
7082 nnoremap K somethingelse
7083 ...
7084 call mapset('n', 0, save_map)
7085< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01007086 e.g. with `:map!`, you need to save/restore the mapping for
7087 all of them, when they might differ.
7088
7089 In the second form, with {dict} as the only argument, mode
7090 and abbr are taken from the dict.
7091 Example: >
7092 vim9script
7093 var save_maps = maplist()->filter(
7094 (_, m) => m.lhs == 'K')
7095 nnoremap K somethingelse
7096 cnoremap K somethingelse2
7097 # ...
7098 unmap K
7099 for d in save_maps
7100 mapset(d)
7101 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007102<
7103 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007104
7105
7106match({expr}, {pat} [, {start} [, {count}]]) *match()*
7107 When {expr} is a |List| then this returns the index of the
7108 first item where {pat} matches. Each item is used as a
7109 String, |Lists| and |Dictionaries| are used as echoed.
7110
7111 Otherwise, {expr} is used as a String. The result is a
7112 Number, which gives the index (byte offset) in {expr} where
7113 {pat} matches.
7114
7115 A match at the first character or |List| item returns zero.
7116 If there is no match -1 is returned.
7117
7118 For getting submatches see |matchlist()|.
7119 Example: >
7120 :echo match("testing", "ing") " results in 4
7121 :echo match([1, 'x'], '\a') " results in 1
7122< See |string-match| for how {pat} is used.
7123 *strpbrk()*
7124 Vim doesn't have a strpbrk() function. But you can do: >
7125 :let sepidx = match(line, '[.,;: \t]')
7126< *strcasestr()*
7127 Vim doesn't have a strcasestr() function. But you can add
7128 "\c" to the pattern to ignore case: >
7129 :let idx = match(haystack, '\cneedle')
7130<
7131 If {start} is given, the search starts from byte index
7132 {start} in a String or item {start} in a |List|.
7133 The result, however, is still the index counted from the
7134 first character/item. Example: >
7135 :echo match("testing", "ing", 2)
7136< result is again "4". >
7137 :echo match("testing", "ing", 4)
7138< result is again "4". >
7139 :echo match("testing", "t", 2)
7140< result is "3".
7141 For a String, if {start} > 0 then it is like the string starts
7142 {start} bytes later, thus "^" will match at {start}. Except
7143 when {count} is given, then it's like matches before the
7144 {start} byte are ignored (this is a bit complicated to keep it
7145 backwards compatible).
7146 For a String, if {start} < 0, it will be set to 0. For a list
7147 the index is counted from the end.
7148 If {start} is out of range ({start} > strlen({expr}) for a
7149 String or {start} > len({expr}) for a |List|) -1 is returned.
7150
7151 When {count} is given use the {count}'th match. When a match
7152 is found in a String the search for the next one starts one
7153 character further. Thus this example results in 1: >
7154 echo match("testing", "..", 0, 2)
7155< In a |List| the search continues in the next item.
7156 Note that when {count} is added the way {start} works changes,
7157 see above.
7158
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007159 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007160 See |pattern| for the patterns that are accepted.
7161 The 'ignorecase' option is used to set the ignore-caseness of
7162 the pattern. 'smartcase' is NOT used. The matching is always
7163 done like 'magic' is set and 'cpoptions' is empty.
7164 Note that a match at the start is preferred, thus when the
7165 pattern is using "*" (any number of matches) it tends to find
7166 zero matches at the start instead of a number of matches
7167 further down in the text.
7168
7169 Can also be used as a |method|: >
7170 GetText()->match('word')
7171 GetList()->match('word')
7172<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007173 Return type: |Number|
7174
7175
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007176 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007177matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7178 Defines a pattern to be highlighted in the current window (a
7179 "match"). It will be highlighted with {group}. Returns an
7180 identification number (ID), which can be used to delete the
7181 match using |matchdelete()|. The ID is bound to the window.
7182 Matching is case sensitive and magic, unless case sensitivity
7183 or magicness are explicitly overridden in {pattern}. The
7184 'magic', 'smartcase' and 'ignorecase' options are not used.
7185 The "Conceal" value is special, it causes the match to be
7186 concealed.
7187
7188 The optional {priority} argument assigns a priority to the
7189 match. A match with a high priority will have its
7190 highlighting overrule that of a match with a lower priority.
7191 A priority is specified as an integer (negative numbers are no
7192 exception). If the {priority} argument is not specified, the
7193 default priority is 10. The priority of 'hlsearch' is zero,
7194 hence all matches with a priority greater than zero will
7195 overrule it. Syntax highlighting (see 'syntax') is a separate
7196 mechanism, and regardless of the chosen priority a match will
7197 always overrule syntax highlighting.
7198
7199 The optional {id} argument allows the request for a specific
7200 match ID. If a specified ID is already taken, an error
7201 message will appear and the match will not be added. An ID
7202 is specified as a positive integer (zero excluded). IDs 1, 2
7203 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007204 respectively. 3 is reserved for use by the |matchparen|
7205 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007206 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007207 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007208
7209 The optional {dict} argument allows for further custom
7210 values. Currently this is used to specify a match specific
7211 conceal character that will be shown for |hl-Conceal|
7212 highlighted matches. The dict can have the following members:
7213
7214 conceal Special character to show instead of the
7215 match (only for |hl-Conceal| highlighted
7216 matches, see |:syn-cchar|)
7217 window Instead of the current window use the
7218 window with this number or window ID.
7219
7220 The number of matches is not limited, as it is the case with
7221 the |:match| commands.
7222
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007223 Returns -1 on error.
7224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007225 Example: >
7226 :highlight MyGroup ctermbg=green guibg=green
7227 :let m = matchadd("MyGroup", "TODO")
7228< Deletion of the pattern: >
7229 :call matchdelete(m)
7230
7231< A list of matches defined by |matchadd()| and |:match| are
7232 available from |getmatches()|. All matches can be deleted in
7233 one operation by |clearmatches()|.
7234
7235 Can also be used as a |method|: >
7236 GetGroup()->matchadd('TODO')
7237<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007238 Return type: |Number|
7239
7240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007241 *matchaddpos()*
7242matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7243 Same as |matchadd()|, but requires a list of positions {pos}
7244 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007245 because it does not handle regular expressions and it sets
7246 buffer line boundaries to redraw screen. It is supposed to be
7247 used when fast match additions and deletions are required, for
7248 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007249
7250 {pos} is a list of positions. Each position can be one of
7251 these:
7252 - A number. This whole line will be highlighted. The first
7253 line has number 1.
7254 - A list with one number, e.g., [23]. The whole line with this
7255 number will be highlighted.
7256 - A list with two numbers, e.g., [23, 11]. The first number is
7257 the line number, the second one is the column number (first
7258 column is 1, the value must correspond to the byte index as
7259 |col()| would return). The character at this position will
7260 be highlighted.
7261 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7262 the third number gives the length of the highlight in bytes.
7263
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007264 Returns -1 on error.
7265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007266 Example: >
7267 :highlight MyGroup ctermbg=green guibg=green
7268 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7269< Deletion of the pattern: >
7270 :call matchdelete(m)
7271
7272< Matches added by |matchaddpos()| are returned by
7273 |getmatches()|.
7274
7275 Can also be used as a |method|: >
7276 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007277<
7278 Return type: |Number|
7279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007280
7281matcharg({nr}) *matcharg()*
7282 Selects the {nr} match item, as set with a |:match|,
7283 |:2match| or |:3match| command.
7284 Return a |List| with two elements:
7285 The name of the highlight group used
7286 The pattern used.
7287 When {nr} is not 1, 2 or 3 returns an empty |List|.
7288 When there is no match item set returns ['', ''].
7289 This is useful to save and restore a |:match|.
7290 Highlighting matches using the |:match| commands are limited
7291 to three matches. |matchadd()| does not have this limitation.
7292
7293 Can also be used as a |method|: >
7294 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007295<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007296 Return type: list<string>
7297
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007298 *matchbufline()*
7299matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7300 Returns the |List| of matches in lines from {lnum} to {end} in
7301 buffer {buf} where {pat} matches.
7302
7303 {lnum} and {end} can either be a line number or the string "$"
7304 to refer to the last line in {buf}.
7305
7306 The {dict} argument supports following items:
7307 submatches include submatch information (|/\(|)
7308
7309 For each match, a |Dict| with the following items is returned:
7310 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007311 lnum line number where there is a match
7312 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007313 Note that there can be multiple matches in a single line.
7314
7315 This function works only for loaded buffers. First call
7316 |bufload()| if needed.
7317
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007318 See |match-pattern| for information about the effect of some
7319 option settings on the pattern.
7320
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007321 When {buf} is not a valid buffer, the buffer is not loaded or
7322 {lnum} or {end} is not valid then an error is given and an
7323 empty |List| is returned.
7324
7325 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007326 " Assuming line 3 in buffer 5 contains "a"
7327 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7328 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7329 " Assuming line 4 in buffer 10 contains "tik tok"
7330 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7331 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007332<
7333 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007334 "\1", "\2", etc. are also returned. Example: >
7335 " Assuming line 2 in buffer 2 contains "acd"
7336 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007337 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007338 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007339< The "submatches" List always contains 9 items. If a submatch
7340 is not found, then an empty string is returned for that
7341 submatch.
7342
7343 Can also be used as a |method|: >
7344 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007345<
7346 Return type: list<dict<any>> or list<any>
7347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007348
h-east624bb832024-11-09 18:37:32 +01007349matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007350 Deletes a match with ID {id} previously defined by |matchadd()|
7351 or one of the |:match| commands. Returns 0 if successful,
7352 otherwise -1. See example for |matchadd()|. All matches can
7353 be deleted in one operation by |clearmatches()|.
7354 If {win} is specified, use the window with this number or
7355 window ID instead of the current window.
7356
7357 Can also be used as a |method|: >
7358 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007359<
7360 Return type: |Number|
7361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007362
7363matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7364 Same as |match()|, but return the index of first character
7365 after the match. Example: >
7366 :echo matchend("testing", "ing")
7367< results in "7".
7368 *strspn()* *strcspn()*
7369 Vim doesn't have a strspn() or strcspn() function, but you can
7370 do it with matchend(): >
7371 :let span = matchend(line, '[a-zA-Z]')
7372 :let span = matchend(line, '[^a-zA-Z]')
7373< Except that -1 is returned when there are no matches.
7374
7375 The {start}, if given, has the same meaning as for |match()|. >
7376 :echo matchend("testing", "ing", 2)
7377< results in "7". >
7378 :echo matchend("testing", "ing", 5)
7379< result is "-1".
7380 When {expr} is a |List| the result is equal to |match()|.
7381
7382 Can also be used as a |method|: >
7383 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007384<
7385 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007386
7387
7388matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7389 If {list} is a list of strings, then returns a |List| with all
7390 the strings in {list} that fuzzy match {str}. The strings in
7391 the returned list are sorted based on the matching score.
7392
7393 The optional {dict} argument always supports the following
7394 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007395 matchseq When this item is present return only matches
7396 that contain the characters in {str} in the
7397 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007398 limit Maximum number of matches in {list} to be
7399 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007400 camelcase Use enhanced camel case scoring making results
7401 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007402 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007403
7404 If {list} is a list of dictionaries, then the optional {dict}
7405 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007406 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007407 {str}. The value of this item should be a
7408 string.
7409 text_cb |Funcref| that will be called for every item
7410 in {list} to get the text for fuzzy matching.
7411 This should accept a dictionary item as the
7412 argument and return the text for that item to
7413 use for fuzzy matching.
7414
7415 {str} is treated as a literal string and regular expression
7416 matching is NOT supported. The maximum supported {str} length
7417 is 256.
7418
7419 When {str} has multiple words each separated by white space,
7420 then the list of strings that have all the words is returned.
7421
7422 If there are no matching strings or there is an error, then an
7423 empty list is returned. If length of {str} is greater than
7424 256, then returns an empty list.
7425
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007426 When {limit} is given, matchfuzzy() will find up to this
7427 number of matches in {list} and return them in sorted order.
7428
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007429 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007430 matching strings.
7431
7432 Example: >
7433 :echo matchfuzzy(["clay", "crow"], "cay")
7434< results in ["clay"]. >
7435 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7436< results in a list of buffer names fuzzy matching "ndl". >
7437 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7438< results in a list of buffer information dicts with buffer
7439 names fuzzy matching "ndl". >
7440 :echo getbufinfo()->matchfuzzy("spl",
7441 \ {'text_cb' : {v -> v.name}})
7442< results in a list of buffer information dicts with buffer
7443 names fuzzy matching "spl". >
7444 :echo v:oldfiles->matchfuzzy("test")
7445< results in a list of file names fuzzy matching "test". >
7446 :let l = readfile("buffer.c")->matchfuzzy("str")
7447< results in a list of lines in "buffer.c" fuzzy matching "str". >
7448 :echo ['one two', 'two one']->matchfuzzy('two one')
7449< results in ['two one', 'one two']. >
7450 :echo ['one two', 'two one']->matchfuzzy('two one',
7451 \ {'matchseq': 1})
7452< results in ['two one'].
7453
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007454 Return type: list<string> or list<any>
7455
7456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007457matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7458 Same as |matchfuzzy()|, but returns the list of matched
7459 strings, the list of character positions where characters
7460 in {str} matches and a list of matching scores. You can
7461 use |byteidx()| to convert a character position to a byte
7462 position.
7463
7464 If {str} matches multiple times in a string, then only the
7465 positions for the best match is returned.
7466
7467 If there are no matching strings or there is an error, then a
7468 list with three empty list items is returned.
7469
7470 Example: >
7471 :echo matchfuzzypos(['testing'], 'tsg')
7472< results in [['testing'], [[0, 2, 6]], [99]] >
7473 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7474< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7475 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7476< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007478 Return type: list<list<any>>
7479
7480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007481matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7482 Same as |match()|, but return a |List|. The first item in the
7483 list is the matched string, same as what matchstr() would
7484 return. Following items are submatches, like "\1", "\2", etc.
7485 in |:substitute|. When an optional submatch didn't match an
7486 empty string is used. Example: >
7487 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7488< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7489 When there is no match an empty list is returned.
7490
7491 You can pass in a List, but that is not very useful.
7492
7493 Can also be used as a |method|: >
7494 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007495<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007496 Return type: list<string> or list<any>
7497
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007498 *matchstrlist()*
7499matchstrlist({list}, {pat} [, {dict}])
7500 Returns the |List| of matches in {list} where {pat} matches.
7501 {list} is a |List| of strings. {pat} is matched against each
7502 string in {list}.
7503
7504 The {dict} argument supports following items:
7505 submatches include submatch information (|/\(|)
7506
7507 For each match, a |Dict| with the following items is returned:
7508 byteidx starting byte index of the match.
7509 idx index in {list} of the match.
7510 text matched string
7511 submatches a List of submatches. Present only if
7512 "submatches" is set to v:true in {dict}.
7513
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007514 See |match-pattern| for information about the effect of some
7515 option settings on the pattern.
7516
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007517 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007518 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7519 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7520 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7521 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007522<
7523 If "submatches" is present and is v:true, then submatches like
7524 "\1", "\2", etc. are also returned. Example: >
7525 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7526 \ #{submatches: v:true})
7527 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7528< The "submatches" List always contains 9 items. If a submatch
7529 is not found, then an empty string is returned for that
7530 submatch.
7531
7532 Can also be used as a |method|: >
7533 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007534<
7535 Return type: list<dict<any>> or list<any>
7536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007537
7538matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7539 Same as |match()|, but return the matched string. Example: >
7540 :echo matchstr("testing", "ing")
7541< results in "ing".
7542 When there is no match "" is returned.
7543 The {start}, if given, has the same meaning as for |match()|. >
7544 :echo matchstr("testing", "ing", 2)
7545< results in "ing". >
7546 :echo matchstr("testing", "ing", 5)
7547< result is "".
7548 When {expr} is a |List| then the matching item is returned.
7549 The type isn't changed, it's not necessarily a String.
7550
7551 Can also be used as a |method|: >
7552 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007553<
7554 Return type: |String|
7555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007556
7557matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7558 Same as |matchstr()|, but return the matched string, the start
7559 position and the end position of the match. Example: >
7560 :echo matchstrpos("testing", "ing")
7561< results in ["ing", 4, 7].
7562 When there is no match ["", -1, -1] is returned.
7563 The {start}, if given, has the same meaning as for |match()|. >
7564 :echo matchstrpos("testing", "ing", 2)
7565< results in ["ing", 4, 7]. >
7566 :echo matchstrpos("testing", "ing", 5)
7567< result is ["", -1, -1].
7568 When {expr} is a |List| then the matching item, the index
7569 of first item where {pat} matches, the start position and the
7570 end position of the match are returned. >
7571 :echo matchstrpos([1, '__x'], '\a')
7572< result is ["x", 1, 2, 3].
7573 The type isn't changed, it's not necessarily a String.
7574
7575 Can also be used as a |method|: >
7576 GetText()->matchstrpos('word')
7577<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007578 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007579
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007580
7581max({expr}) *max()*
7582 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007583 echo max([apples, pears, oranges])
7584
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007585< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7586 Dictionary, it returns the maximum of all values in the
7587 Dictionary. If {expr} is neither a List nor a Tuple nor a
7588 Dictionary, or one of the items in {expr} cannot be used as a
7589 Number this results in an error. An empty |List|, |Tuple|
7590 or |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007591
7592 Can also be used as a |method|: >
7593 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007594<
7595 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007596
7597
7598menu_info({name} [, {mode}]) *menu_info()*
7599 Return information about the specified menu {name} in
7600 mode {mode}. The menu name should be specified without the
7601 shortcut character ('&'). If {name} is "", then the top-level
7602 menu names are returned.
7603
7604 {mode} can be one of these strings:
7605 "n" Normal
7606 "v" Visual (including Select)
7607 "o" Operator-pending
7608 "i" Insert
7609 "c" Cmd-line
7610 "s" Select
7611 "x" Visual
7612 "t" Terminal-Job
7613 "" Normal, Visual and Operator-pending
7614 "!" Insert and Cmd-line
7615 When {mode} is omitted, the modes for "" are used.
7616
7617 Returns a |Dictionary| containing the following items:
7618 accel menu item accelerator text |menu-text|
7619 display display name (name without '&')
7620 enabled v:true if this menu item is enabled
7621 Refer to |:menu-enable|
7622 icon name of the icon file (for toolbar)
7623 |toolbar-icon|
7624 iconidx index of a built-in icon
7625 modes modes for which the menu is defined. In
7626 addition to the modes mentioned above, these
7627 characters will be used:
7628 " " Normal, Visual and Operator-pending
7629 name menu item name.
7630 noremenu v:true if the {rhs} of the menu item is not
7631 remappable else v:false.
7632 priority menu order priority |menu-priority|
7633 rhs right-hand-side of the menu item. The returned
7634 string has special characters translated like
7635 in the output of the ":menu" command listing.
7636 When the {rhs} of a menu item is empty, then
7637 "<Nop>" is returned.
7638 script v:true if script-local remapping of {rhs} is
7639 allowed else v:false. See |:menu-script|.
7640 shortcut shortcut key (character after '&' in
7641 the menu name) |menu-shortcut|
7642 silent v:true if the menu item is created
7643 with <silent> argument |:menu-silent|
7644 submenus |List| containing the names of
7645 all the submenus. Present only if the menu
7646 item has submenus.
7647
7648 Returns an empty dictionary if the menu item is not found.
7649
7650 Examples: >
7651 :echo menu_info('Edit.Cut')
7652 :echo menu_info('File.Save', 'n')
7653
7654 " Display the entire menu hierarchy in a buffer
7655 func ShowMenu(name, pfx)
7656 let m = menu_info(a:name)
7657 call append(line('$'), a:pfx .. m.display)
7658 for child in m->get('submenus', [])
7659 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7660 \ a:pfx .. ' ')
7661 endfor
7662 endfunc
7663 new
7664 for topmenu in menu_info('').submenus
7665 call ShowMenu(topmenu, '')
7666 endfor
7667<
7668 Can also be used as a |method|: >
7669 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007670<
7671 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007672
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007673min({expr}) *min()*
7674 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007675 echo min([apples, pears, oranges])
7676
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007677< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7678 Dictionary, it returns the minimum of all values in the
7679 Dictionary. If {expr} is neither a List nor a Tuple nor a
7680 Dictionary, or one of the items in {expr} cannot be used as a
7681 Number this results in an error. An empty |List|, |Tuple| or
7682 |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007683
7684 Can also be used as a |method|: >
7685 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007686<
7687 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007688
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007689
7690mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007691 Create directory {name}.
7692
Bram Moolenaar938ae282023-02-20 20:44:55 +00007693 When {flags} is present it must be a string. An empty string
7694 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007695
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007696 {flags} can contain these character flags:
7697 "p" intermediate directories will be created as necessary
7698 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007699 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007700 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007701 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007702
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007703 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007704 some directories may already exist. Only the first one that
7705 is created and what it contains is scheduled to be deleted.
7706 E.g. when using: >
7707 call mkdir('subdir/tmp/autoload', 'pR')
7708< and "subdir" already exists then "subdir/tmp" will be
7709 scheduled for deletion, like with: >
7710 defer delete('subdir/tmp', 'rf')
7711< Note that if scheduling the defer fails the directory is not
7712 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007713
7714 If {prot} is given it is used to set the protection bits of
7715 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7716 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007717 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007718 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007719 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007720 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007721
7722< This function is not available in the |sandbox|.
7723
7724 There is no error if the directory already exists and the "p"
7725 flag is passed (since patch 8.0.1708). However, without the
7726 "p" option the call will fail.
7727
7728 The function result is a Number, which is TRUE if the call was
7729 successful or FALSE if the directory creation failed or partly
7730 failed.
7731
7732 Not available on all systems. To check use: >
7733 :if exists("*mkdir")
7734
7735< Can also be used as a |method|: >
7736 GetName()->mkdir()
7737<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007738 Return type: |Number|
7739
7740
7741mode([{expr}]) *mode()*
7742 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007743 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007744 a non-empty String (|non-zero-arg|), then the full mode is
7745 returned, otherwise only the first letter is returned.
7746 Also see |state()|.
7747
7748 n Normal
7749 no Operator-pending
7750 nov Operator-pending (forced characterwise |o_v|)
7751 noV Operator-pending (forced linewise |o_V|)
7752 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7753 CTRL-V is one character
7754 niI Normal using |i_CTRL-O| in |Insert-mode|
7755 niR Normal using |i_CTRL-O| in |Replace-mode|
7756 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7757 nt Terminal-Normal (insert goes to Terminal-Job mode)
7758 v Visual by character
7759 vs Visual by character using |v_CTRL-O| in Select mode
7760 V Visual by line
7761 Vs Visual by line using |v_CTRL-O| in Select mode
7762 CTRL-V Visual blockwise
7763 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7764 s Select by character
7765 S Select by line
7766 CTRL-S Select blockwise
7767 i Insert
7768 ic Insert mode completion |compl-generic|
7769 ix Insert mode |i_CTRL-X| completion
7770 R Replace |R|
7771 Rc Replace mode completion |compl-generic|
7772 Rx Replace mode |i_CTRL-X| completion
7773 Rv Virtual Replace |gR|
7774 Rvc Virtual Replace mode completion |compl-generic|
7775 Rvx Virtual Replace mode |i_CTRL-X| completion
7776 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007777 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007778 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007779 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007780 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007781 ce Normal Ex mode |Q|
7782 r Hit-enter prompt
7783 rm The -- more -- prompt
7784 r? A |:confirm| query of some sort
7785 ! Shell or external command is executing
7786 t Terminal-Job mode: keys go to the job
7787
7788 This is useful in the 'statusline' option or when used
7789 with |remote_expr()| In most other places it always returns
7790 "c" or "n".
7791 Note that in the future more modes and more specific modes may
7792 be added. It's better not to compare the whole string but only
7793 the leading character(s).
7794 Also see |visualmode()|.
7795
7796 Can also be used as a |method|: >
7797 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007798<
7799 Return type: |String|
7800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007801
7802mzeval({expr}) *mzeval()*
7803 Evaluate MzScheme expression {expr} and return its result
7804 converted to Vim data structures.
7805 Numbers and strings are returned as they are.
7806 Pairs (including lists and improper lists) and vectors are
7807 returned as Vim |Lists|.
7808 Hash tables are represented as Vim |Dictionary| type with keys
7809 converted to strings.
7810 All other types are converted to string with display function.
7811 Examples: >
7812 :mz (define l (list 1 2 3))
7813 :mz (define h (make-hash)) (hash-set! h "list" l)
7814 :echo mzeval("l")
7815 :echo mzeval("h")
7816<
7817 Note that in a `:def` function local variables are not visible
7818 to {expr}.
7819
7820 Can also be used as a |method|: >
7821 GetExpr()->mzeval()
7822<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007823 Return type: any, depending on {expr}
7824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007825 {only available when compiled with the |+mzscheme| feature}
7826
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007828nextnonblank({lnum}) *nextnonblank()*
7829 Return the line number of the first line at or below {lnum}
7830 that is not blank. Example: >
7831 if getline(nextnonblank(1)) =~ "Java"
7832< When {lnum} is invalid or there is no non-blank line at or
7833 below it, zero is returned.
7834 {lnum} is used like with |getline()|.
7835 See also |prevnonblank()|.
7836
7837 Can also be used as a |method|: >
7838 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007839<
7840 Return type: |Number|
7841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007842
Christ van Willegenc0786752025-02-01 15:42:16 +01007843ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7844 Return a string that contains the correct value for a
7845 message based on the rules for plural form(s) in
7846 a language. Examples: >
7847 ngettext("File", "Files", 2) # returns "Files"
7848<
7849 Can be used as a |method|: >
7850 1->ngettext("File", "Files") # returns "File"
7851<
7852 See |gettext()| for information on the domain parameter.
7853
7854 Return type: |String|
7855
7856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007857nr2char({expr} [, {utf8}]) *nr2char()*
7858 Return a string with a single character, which has the number
7859 value {expr}. Examples: >
7860 nr2char(64) returns "@"
7861 nr2char(32) returns " "
7862< When {utf8} is omitted or zero, the current 'encoding' is used.
7863 Example for "utf-8": >
7864 nr2char(300) returns I with bow character
7865< When {utf8} is TRUE, always return UTF-8 characters.
7866 Note that a NUL character in the file is specified with
7867 nr2char(10), because NULs are represented with newline
7868 characters. nr2char(0) is a real NUL and terminates the
7869 string, thus results in an empty string.
7870 To turn a list of character numbers into a string: >
7871 let list = [65, 66, 67]
7872 let str = join(map(list, {_, val -> nr2char(val)}), '')
7873< Result: "ABC"
7874
7875 Can also be used as a |method|: >
7876 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007877<
7878 Return type: |String|
7879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007880
7881or({expr}, {expr}) *or()*
7882 Bitwise OR on the two arguments. The arguments are converted
7883 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007884 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007885 Example: >
7886 :let bits = or(bits, 0x80)
7887< Can also be used as a |method|: >
7888 :let bits = bits->or(0x80)
7889
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007890< Rationale: The reason this is a function and not using the "|"
7891 character like many languages, is that Vi has always used "|"
7892 to separate commands. In many places it would not be clear if
7893 "|" is an operator or a command separator.
7894
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007895 Return type: |Number|
7896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007897
7898pathshorten({path} [, {len}]) *pathshorten()*
7899 Shorten directory names in the path {path} and return the
7900 result. The tail, the file name, is kept as-is. The other
7901 components in the path are reduced to {len} letters in length.
7902 If {len} is omitted or smaller than 1 then 1 is used (single
7903 letters). Leading '~' and '.' characters are kept. Examples: >
7904 :echo pathshorten('~/.vim/autoload/myfile.vim')
7905< ~/.v/a/myfile.vim ~
7906>
7907 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7908< ~/.vi/au/myfile.vim ~
7909 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007910 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007911
7912 Can also be used as a |method|: >
7913 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007914<
7915 Return type: |String|
7916
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007917
7918perleval({expr}) *perleval()*
7919 Evaluate Perl expression {expr} in scalar context and return
7920 its result converted to Vim data structures. If value can't be
7921 converted, it is returned as a string Perl representation.
7922 Note: If you want an array or hash, {expr} must return a
7923 reference to it.
7924 Example: >
7925 :echo perleval('[1 .. 4]')
7926< [1, 2, 3, 4]
7927
7928 Note that in a `:def` function local variables are not visible
7929 to {expr}.
7930
7931 Can also be used as a |method|: >
7932 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007933<
7934 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007935
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007936 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007937
7938
7939popup_ functions are documented here: |popup-functions|
7940
7941
7942pow({x}, {y}) *pow()*
7943 Return the power of {x} to the exponent {y} as a |Float|.
7944 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007945 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007946 Examples: >
7947 :echo pow(3, 3)
7948< 27.0 >
7949 :echo pow(2, 16)
7950< 65536.0 >
7951 :echo pow(32, 0.20)
7952< 2.0
7953
7954 Can also be used as a |method|: >
7955 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007956<
7957 Return type: |Number|
7958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007959
7960prevnonblank({lnum}) *prevnonblank()*
7961 Return the line number of the first line at or above {lnum}
7962 that is not blank. Example: >
7963 let ind = indent(prevnonblank(v:lnum - 1))
7964< When {lnum} is invalid or there is no non-blank line at or
7965 above it, zero is returned.
7966 {lnum} is used like with |getline()|.
7967 Also see |nextnonblank()|.
7968
7969 Can also be used as a |method|: >
7970 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007971<
7972 Return type: |Number|
7973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007974
7975printf({fmt}, {expr1} ...) *printf()*
7976 Return a String with {fmt}, where "%" items are replaced by
7977 the formatted form of their respective arguments. Example: >
7978 printf("%4d: E%d %.30s", lnum, errno, msg)
7979< May result in:
7980 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7981
7982 When used as a |method| the base is passed as the second
7983 argument: >
7984 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007985<
7986 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007987
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007988 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007989 %s string
7990 %6S string right-aligned in 6 display cells
7991 %6s string right-aligned in 6 bytes
7992 %.9s string truncated to 9 bytes
7993 %c single byte
7994 %d decimal number
7995 %5d decimal number padded with spaces to 5 characters
7996 %x hex number
7997 %04x hex number padded with zeros to at least 4 characters
7998 %X hex number using upper case letters
7999 %o octal number
8000 %08b binary number padded with zeros to at least 8 chars
8001 %f floating point number as 12.23, inf, -inf or nan
8002 %F floating point number as 12.23, INF, -INF or NAN
8003 %e floating point number as 1.23e3, inf, -inf or nan
8004 %E floating point number as 1.23E3, INF, -INF or NAN
8005 %g floating point number, as %f or %e depending on value
8006 %G floating point number, as %F or %E depending on value
8007 %% the % character itself
8008
8009 Conversion specifications start with '%' and end with the
8010 conversion type. All other characters are copied unchanged to
8011 the result.
8012
8013 The "%" starts a conversion specification. The following
8014 arguments appear in sequence:
8015
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008016 % [pos-argument] [flags] [field-width] [.precision] type
8017
8018 pos-argument
8019 At most one positional argument specifier. These
8020 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008021
8022 flags
8023 Zero or more of the following flags:
8024
8025 # The value should be converted to an "alternate
8026 form". For c, d, and s conversions, this option
8027 has no effect. For o conversions, the precision
8028 of the number is increased to force the first
8029 character of the output string to a zero (except
8030 if a zero value is printed with an explicit
8031 precision of zero).
8032 For b and B conversions, a non-zero result has
8033 the string "0b" (or "0B" for B conversions)
8034 prepended to it.
8035 For x and X conversions, a non-zero result has
8036 the string "0x" (or "0X" for X conversions)
8037 prepended to it.
8038
8039 0 (zero) Zero padding. For all conversions the converted
8040 value is padded on the left with zeros rather
8041 than blanks. If a precision is given with a
8042 numeric conversion (d, b, B, o, x, and X), the 0
8043 flag is ignored.
8044
8045 - A negative field width flag; the converted value
8046 is to be left adjusted on the field boundary.
8047 The converted value is padded on the right with
8048 blanks, rather than on the left with blanks or
8049 zeros. A - overrides a 0 if both are given.
8050
8051 ' ' (space) A blank should be left before a positive
8052 number produced by a signed conversion (d).
8053
8054 + A sign must always be placed before a number
8055 produced by a signed conversion. A + overrides
8056 a space if both are used.
8057
8058 field-width
8059 An optional decimal digit string specifying a minimum
8060 field width. If the converted value has fewer bytes
8061 than the field width, it will be padded with spaces on
8062 the left (or right, if the left-adjustment flag has
8063 been given) to fill out the field width. For the S
8064 conversion the count is in cells.
8065
8066 .precision
8067 An optional precision, in the form of a period '.'
8068 followed by an optional digit string. If the digit
8069 string is omitted, the precision is taken as zero.
8070 This gives the minimum number of digits to appear for
8071 d, o, x, and X conversions, the maximum number of
8072 bytes to be printed from a string for s conversions,
8073 or the maximum number of cells to be printed from a
8074 string for S conversions.
8075 For floating point it is the number of digits after
8076 the decimal point.
8077
8078 type
8079 A character that specifies the type of conversion to
8080 be applied, see below.
8081
8082 A field width or precision, or both, may be indicated by an
8083 asterisk '*' instead of a digit string. In this case, a
8084 Number argument supplies the field width or precision. A
8085 negative field width is treated as a left adjustment flag
8086 followed by a positive field width; a negative precision is
8087 treated as though it were missing. Example: >
8088 :echo printf("%d: %.*s", nr, width, line)
8089< This limits the length of the text used from "line" to
8090 "width" bytes.
8091
Dominique Pellé17dca3c2023-12-14 20:36:32 +01008092 If the argument to be formatted is specified using a
8093 positional argument specifier, and a '*' is used to indicate
8094 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008095 precision, the argument(s) to be used must also be specified
8096 using a {n$} positional argument specifier. See |printf-$|.
8097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008098 The conversion specifiers and their meanings are:
8099
8100 *printf-d* *printf-b* *printf-B* *printf-o*
8101 *printf-x* *printf-X*
8102 dbBoxX The Number argument is converted to signed decimal
8103 (d), unsigned binary (b and B), unsigned octal (o), or
8104 unsigned hexadecimal (x and X) notation. The letters
8105 "abcdef" are used for x conversions; the letters
8106 "ABCDEF" are used for X conversions.
8107 The precision, if any, gives the minimum number of
8108 digits that must appear; if the converted value
8109 requires fewer digits, it is padded on the left with
8110 zeros.
8111 In no case does a non-existent or small field width
8112 cause truncation of a numeric field; if the result of
8113 a conversion is wider than the field width, the field
8114 is expanded to contain the conversion result.
8115 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02008116 The 'l' modifier indicates the argument is a long
8117 integer. The size will be 32 bits or 64 bits
8118 depending on your platform.
8119 The "ll" modifier indicates the argument is 64 bits.
8120 The b and B conversion specifiers never take a width
8121 modifier and always assume their argument is a 64 bit
8122 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008123 Generally, these modifiers are not useful. They are
8124 ignored when type is known from the argument.
8125
8126 i alias for d
8127 D alias for ld
8128 U alias for lu
8129 O alias for lo
8130
8131 *printf-c*
8132 c The Number argument is converted to a byte, and the
8133 resulting character is written.
8134
8135 *printf-s*
8136 s The text of the String argument is used. If a
8137 precision is specified, no more bytes than the number
8138 specified are used.
8139 If the argument is not a String type, it is
8140 automatically converted to text with the same format
8141 as ":echo".
8142 *printf-S*
8143 S The text of the String argument is used. If a
8144 precision is specified, no more display cells than the
8145 number specified are used.
8146
8147 *printf-f* *E807*
8148 f F The Float argument is converted into a string of the
8149 form 123.456. The precision specifies the number of
8150 digits after the decimal point. When the precision is
8151 zero the decimal point is omitted. When the precision
8152 is not specified 6 is used. A really big number
8153 (out of range or dividing by zero) results in "inf"
8154 or "-inf" with %f (INF or -INF with %F).
8155 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8156 Example: >
8157 echo printf("%.2f", 12.115)
8158< 12.12
8159 Note that roundoff depends on the system libraries.
8160 Use |round()| when in doubt.
8161
8162 *printf-e* *printf-E*
8163 e E The Float argument is converted into a string of the
8164 form 1.234e+03 or 1.234E+03 when using 'E'. The
8165 precision specifies the number of digits after the
8166 decimal point, like with 'f'.
8167
8168 *printf-g* *printf-G*
8169 g G The Float argument is converted like with 'f' if the
8170 value is between 0.001 (inclusive) and 10000000.0
8171 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8172 for 'G'. When no precision is specified superfluous
8173 zeroes and '+' signs are removed, except for the zero
8174 immediately after the decimal point. Thus 10000000.0
8175 results in 1.0e7.
8176
8177 *printf-%*
8178 % A '%' is written. No argument is converted. The
8179 complete conversion specification is "%%".
8180
8181 When a Number argument is expected a String argument is also
8182 accepted and automatically converted.
8183 When a Float or String argument is expected a Number argument
8184 is also accepted and automatically converted.
8185 Any other argument type results in an error message.
8186
8187 *E766* *E767*
8188 The number of {exprN} arguments must exactly match the number
8189 of "%" items. If there are not sufficient or too many
8190 arguments an error is given. Up to 18 arguments can be used.
8191
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008192 *printf-$*
8193 In certain languages, error and informative messages are
8194 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008195 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008196 having a different word order, positional arguments may be
8197 used to indicate this. For instance: >
8198
h_east596a9f22023-11-21 21:24:23 +09008199 #, c-format
8200 msgid "%s returning %s"
8201 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008202<
h_east596a9f22023-11-21 21:24:23 +09008203 In this example, the sentence has its 2 string arguments
8204 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008205
h_east596a9f22023-11-21 21:24:23 +09008206 echo printf(
8207 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8208 "Bram", "Moolenaar")
8209< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008210
h_east596a9f22023-11-21 21:24:23 +09008211 echo printf(
8212 "In Belgium, vim's creator's name is: %2$s %1$s",
8213 "Bram", "Moolenaar")
8214< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008215
8216 Width (and precision) can be specified using the '*' specifier.
8217 In this case, you must specify the field width position in the
8218 argument list. >
8219
h_east596a9f22023-11-21 21:24:23 +09008220 echo printf("%1$*2$.*3$d", 1, 2, 3)
8221< 001 >
8222 echo printf("%2$*3$.*1$d", 1, 2, 3)
8223< 2 >
8224 echo printf("%3$*1$.*2$d", 1, 2, 3)
8225< 03 >
8226 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8227< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008228
8229 You can mix specifying the width and/or precision directly
8230 and via positional arguments: >
8231
h_east596a9f22023-11-21 21:24:23 +09008232 echo printf("%1$4.*2$f", 1.4142135, 6)
8233< 1.414214 >
8234 echo printf("%1$*2$.4f", 1.4142135, 6)
8235< 1.4142 >
8236 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8237< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008238
Christ van Willegenc35fc032024-03-14 18:30:41 +01008239 You will get an overflow error |E1510|, when the field-width
Hirohito Higashi0ed11ba2025-04-18 18:45:31 +02008240 or precision will result in a string longer than 1 MiB
zeertzjqe9a27ef2025-04-18 10:45:45 +02008241 (1024*1024 = 1048576) chars.
Christ van Willegenc35fc032024-03-14 18:30:41 +01008242
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008243 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008244 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008245 echo printf("%s%1$s", "One", "Two")
8246< E1500: Cannot mix positional and non-positional arguments:
8247 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008248
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008249 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008250 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008251 echo printf("%3$s%1$s", "One", "Two", "Three")
8252< E1501: format argument 2 unused in $-style format:
8253 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008254
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008255 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008256 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008257 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8258< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008259
8260 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008261 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8262< E1502: Positional argument 2 used as field width reused as
8263 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008264
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008265 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008266 When a positional argument is used, but not the correct number
8267 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008268 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8269< E1503: Positional argument 3 out of bounds: %1$d at width
8270 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008271
8272 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008273 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8274< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8275 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008276
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008277 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008278 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008279 echo printf("%1$s %2$s %1$s", "One", "Two")
8280< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008281
8282 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008283 echo printf("%1$s %2$s %1$d", "One", "Two")
8284< E1504: Positional argument 1 type used inconsistently:
8285 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008286
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008287 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008288 Various other errors that lead to a format string being
8289 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008290 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8291< E1505: Invalid format specifier: %1$d at width %2$d is:
8292 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008293
Christ van Willegenea746f92023-10-05 20:48:36 +02008294 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008295 This internal error indicates that the logic to parse a
8296 positional format argument ran into a problem that couldn't be
8297 otherwise reported. Please file a bug against Vim if you run
8298 into this, copying the exact format string and parameters that
8299 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008300
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008301 Return type: |String|
8302
Christ van Willegenea746f92023-10-05 20:48:36 +02008303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008304prompt_getprompt({buf}) *prompt_getprompt()*
8305 Returns the effective prompt text for buffer {buf}. {buf} can
8306 be a buffer name or number. See |prompt-buffer|.
8307
8308 If the buffer doesn't exist or isn't a prompt buffer, an empty
8309 string is returned.
8310
8311 Can also be used as a |method|: >
8312 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008313<
8314 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008315
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008316 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008317
8318
8319prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8320 Set prompt callback for buffer {buf} to {expr}. When {expr}
8321 is an empty string the callback is removed. This has only
8322 effect if {buf} has 'buftype' set to "prompt".
8323
8324 The callback is invoked when pressing Enter. The current
8325 buffer will always be the prompt buffer. A new line for a
8326 prompt is added before invoking the callback, thus the prompt
8327 for which the callback was invoked will be in the last but one
8328 line.
8329 If the callback wants to add text to the buffer, it must
8330 insert it above the last line, since that is where the current
8331 prompt is. This can also be done asynchronously.
8332 The callback is invoked with one argument, which is the text
8333 that was entered at the prompt. This can be an empty string
8334 if the user only typed Enter.
8335 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008336 func s:TextEntered(text)
8337 if a:text == 'exit' || a:text == 'quit'
8338 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008339 " Reset 'modified' to allow the buffer to be closed.
8340 " We assume there is nothing useful to be saved.
8341 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008342 close
8343 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008344 " Do something useful with "a:text". In this example
8345 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008346 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008347 endif
8348 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008349 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008350
8351< Can also be used as a |method|: >
8352 GetBuffer()->prompt_setcallback(callback)
8353
8354< {only available when compiled with the |+channel| feature}
8355
8356prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8357 Set a callback for buffer {buf} to {expr}. When {expr} is an
8358 empty string the callback is removed. This has only effect if
8359 {buf} has 'buftype' set to "prompt".
8360
8361 This callback will be invoked when pressing CTRL-C in Insert
8362 mode. Without setting a callback Vim will exit Insert mode,
8363 as in any buffer.
8364
8365 Can also be used as a |method|: >
8366 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008367<
8368 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008370 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008371
8372prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8373 Set prompt for buffer {buf} to {text}. You most likely want
8374 {text} to end in a space.
8375 The result is only visible if {buf} has 'buftype' set to
8376 "prompt". Example: >
8377 call prompt_setprompt(bufnr(), 'command: ')
8378<
8379 Can also be used as a |method|: >
8380 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008381<
8382 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008383
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008384 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008385
8386prop_ functions are documented here: |text-prop-functions|
8387
8388pum_getpos() *pum_getpos()*
8389 If the popup menu (see |ins-completion-menu|) is not visible,
8390 returns an empty |Dictionary|, otherwise, returns a
8391 |Dictionary| with the following keys:
8392 height nr of items visible
8393 width screen cells
8394 row top screen row (0 first row)
8395 col leftmost screen column (0 first col)
8396 size total nr of items
8397 scrollbar |TRUE| if scrollbar is visible
8398
8399 The values are the same as in |v:event| during
8400 |CompleteChanged|.
8401
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008402 Return type: dict<any>
8403
8404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008405pumvisible() *pumvisible()*
8406 Returns non-zero when the popup menu is visible, zero
8407 otherwise. See |ins-completion-menu|.
8408 This can be used to avoid some things that would remove the
8409 popup menu.
8410
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008411 Return type: |Number|
8412
8413
zeertzjq7c515282024-11-10 20:26:12 +01008414py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008415 Evaluate Python expression {expr} and return its result
8416 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008417 If a {locals} |Dictionary| is given, it defines set of local
8418 variables available in the expression. The keys are variable
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008419 names and the values are the variable values. |Dictionary|,
8420 |List| and |Tuple| values are referenced, and may be updated
8421 by the expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008422 Numbers and strings are returned as they are (strings are
8423 copied though, Unicode strings are additionally converted to
8424 'encoding').
8425 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008426 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008427 Dictionaries are represented as Vim |Dictionary| type with
8428 keys converted to strings.
8429 Note that in a `:def` function local variables are not visible
8430 to {expr}.
8431
8432 Can also be used as a |method|: >
8433 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008434 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008435<
8436 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008437
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008438 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008439
8440 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008441pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008442 Evaluate Python expression {expr} and return its result
8443 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008444 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008445 Numbers and strings are returned as they are (strings are
8446 copied though).
8447 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008448 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008449 Dictionaries are represented as Vim |Dictionary| type,
8450 non-string keys result in error.
8451 Note that in a `:def` function local variables are not visible
8452 to {expr}.
8453
8454 Can also be used as a |method|: >
8455 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008456<
8457 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008458
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008459 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008460
zeertzjq7c515282024-11-10 20:26:12 +01008461pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008462 Evaluate Python expression {expr} and return its result
8463 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008464 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008465 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8466 See also: |pyeval()|, |py3eval()|
8467
8468 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008469 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008470<
8471 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008472
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008473 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008474 |+python3| feature}
8475
8476rand([{expr}]) *rand()* *random*
8477 Return a pseudo-random Number generated with an xoshiro128**
8478 algorithm using seed {expr}. The returned number is 32 bits,
8479 also on 64 bits systems, for consistency.
8480 {expr} can be initialized by |srand()| and will be updated by
8481 rand(). If {expr} is omitted, an internal seed value is used
8482 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008483 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008484
8485 Examples: >
8486 :echo rand()
8487 :let seed = srand()
8488 :echo rand(seed)
8489 :echo rand(seed) % 16 " random number 0 - 15
8490<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008491 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008492
8493 *E726* *E727*
8494range({expr} [, {max} [, {stride}]]) *range()*
8495 Returns a |List| with Numbers:
8496 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8497 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8498 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8499 {max}] (increasing {expr} with {stride} each time, not
8500 producing a value past {max}).
8501 When the maximum is one before the start the result is an
8502 empty list. When the maximum is more than one before the
8503 start this is an error.
8504 Examples: >
8505 range(4) " [0, 1, 2, 3]
8506 range(2, 4) " [2, 3, 4]
8507 range(2, 9, 3) " [2, 5, 8]
8508 range(2, -2, -1) " [2, 1, 0, -1, -2]
8509 range(0) " []
8510 range(2, 0) " error!
8511<
8512 Can also be used as a |method|: >
8513 GetExpr()->range()
8514<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008515 Return type: list<number>
8516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008517
K.Takata11df3ae2022-10-19 14:02:40 +01008518readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008519 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008520 If {offset} is specified, read the file from the specified
8521 offset. If it is a negative value, it is used as an offset
8522 from the end of the file. E.g., to read the last 12 bytes: >
8523 readblob('file.bin', -12)
8524< If {size} is specified, only the specified size will be read.
8525 E.g. to read the first 100 bytes of a file: >
8526 readblob('file.bin', 0, 100)
8527< If {size} is -1 or omitted, the whole data starting from
8528 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008529 This can be also used to read the data from a character device
8530 on Unix when {size} is explicitly set. Only if the device
8531 supports seeking {offset} can be used. Otherwise it should be
8532 zero. E.g. to read 10 bytes from a serial console: >
8533 readblob('/dev/ttyS0', 0, 10)
8534< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008535 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008536 When the offset is beyond the end of the file the result is an
8537 empty blob.
8538 When trying to read more bytes than are available the result
8539 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008540 Also see |readfile()| and |writefile()|.
8541
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008542 Return type: |Blob|
8543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008544
8545readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8546 Return a list with file and directory names in {directory}.
8547 You can also use |glob()| if you don't need to do complicated
8548 things, such as limiting the number of matches.
8549 The list will be sorted (case sensitive), see the {dict}
8550 argument below for changing the sort order.
8551
8552 When {expr} is omitted all entries are included.
8553 When {expr} is given, it is evaluated to check what to do:
8554 If {expr} results in -1 then no further entries will
8555 be handled.
8556 If {expr} results in 0 then this entry will not be
8557 added to the list.
8558 If {expr} results in 1 then this entry will be added
8559 to the list.
8560 The entries "." and ".." are always excluded.
8561 Each time {expr} is evaluated |v:val| is set to the entry name.
8562 When {expr} is a function the name is passed as the argument.
8563 For example, to get a list of files ending in ".txt": >
8564 readdir(dirname, {n -> n =~ '.txt$'})
8565< To skip hidden and backup files: >
8566 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008567< *E857*
8568 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569 values. Currently this is used to specify if and how sorting
8570 should be performed. The dict can have the following members:
8571
8572 sort How to sort the result returned from the system.
8573 Valid values are:
8574 "none" do not sort (fastest method)
8575 "case" sort case sensitive (byte value of
8576 each character, technically, using
8577 strcmp()) (default)
8578 "icase" sort case insensitive (technically
8579 using strcasecmp())
8580 "collate" sort using the collation order
8581 of the "POSIX" or "C" |locale|
8582 (technically using strcoll())
8583 Other values are silently ignored.
8584
8585 For example, to get a list of all files in the current
8586 directory without sorting the individual entries: >
8587 readdir('.', '1', #{sort: 'none'})
8588< If you want to get a directory tree: >
8589 function! s:tree(dir)
8590 return {a:dir : map(readdir(a:dir),
8591 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008592 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008593 endfunction
8594 echo s:tree(".")
8595<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008596 Returns an empty List on error.
8597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008598 Can also be used as a |method|: >
8599 GetDirName()->readdir()
8600<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008601 Return type: list<string> or list<any>
8602
8603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008604readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8605 Extended version of |readdir()|.
8606 Return a list of Dictionaries with file and directory
8607 information in {directory}.
8608 This is useful if you want to get the attributes of file and
8609 directory at the same time as getting a list of a directory.
8610 This is much faster than calling |readdir()| then calling
8611 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8612 each file and directory especially on MS-Windows.
8613 The list will by default be sorted by name (case sensitive),
8614 the sorting can be changed by using the optional {dict}
8615 argument, see |readdir()|.
8616
8617 The Dictionary for file and directory information has the
8618 following items:
8619 group Group name of the entry. (Only on Unix)
8620 name Name of the entry.
8621 perm Permissions of the entry. See |getfperm()|.
8622 size Size of the entry. See |getfsize()|.
8623 time Timestamp of the entry. See |getftime()|.
8624 type Type of the entry.
8625 On Unix, almost same as |getftype()| except:
8626 Symlink to a dir "linkd"
8627 Other symlink "link"
8628 On MS-Windows:
8629 Normal file "file"
8630 Directory "dir"
8631 Junction "junction"
8632 Symlink to a dir "linkd"
8633 Other symlink "link"
8634 Other reparse point "reparse"
8635 user User name of the entry's owner. (Only on Unix)
8636 On Unix, if the entry is a symlink, the Dictionary includes
8637 the information of the target (except the "type" item).
8638 On MS-Windows, it includes the information of the symlink
8639 itself because of performance reasons.
8640
8641 When {expr} is omitted all entries are included.
8642 When {expr} is given, it is evaluated to check what to do:
8643 If {expr} results in -1 then no further entries will
8644 be handled.
8645 If {expr} results in 0 then this entry will not be
8646 added to the list.
8647 If {expr} results in 1 then this entry will be added
8648 to the list.
8649 The entries "." and ".." are always excluded.
8650 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8651 of the entry.
8652 When {expr} is a function the entry is passed as the argument.
8653 For example, to get a list of files ending in ".txt": >
8654 readdirex(dirname, {e -> e.name =~ '.txt$'})
8655<
8656 For example, to get a list of all files in the current
8657 directory without sorting the individual entries: >
8658 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008659<
8660 Can also be used as a |method|: >
8661 GetDirName()->readdirex()
8662<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008663 Return type: list<dict<any>> or list<any>
8664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665
8666 *readfile()*
8667readfile({fname} [, {type} [, {max}]])
8668 Read file {fname} and return a |List|, each line of the file
8669 as an item. Lines are broken at NL characters. Macintosh
8670 files separated with CR will result in a single long line
8671 (unless a NL appears somewhere).
8672 All NUL characters are replaced with a NL character.
8673 When {type} contains "b" binary mode is used:
8674 - When the last line ends in a NL an extra empty list item is
8675 added.
8676 - No CR characters are removed.
8677 Otherwise:
8678 - CR characters that appear before a NL are removed.
8679 - Whether the last line ends in a NL or not does not matter.
8680 - When 'encoding' is Unicode any UTF-8 byte order mark is
8681 removed from the text.
8682 When {max} is given this specifies the maximum number of lines
8683 to be read. Useful if you only want to check the first ten
8684 lines of a file: >
8685 :for line in readfile(fname, '', 10)
8686 : if line =~ 'Date' | echo line | endif
8687 :endfor
8688< When {max} is negative -{max} lines from the end of the file
8689 are returned, or as many as there are.
8690 When {max} is zero the result is an empty list.
8691 Note that without {max} the whole file is read into memory.
8692 Also note that there is no recognition of encoding. Read a
8693 file into a buffer if you need to.
8694 Deprecated (use |readblob()| instead): When {type} contains
8695 "B" a |Blob| is returned with the binary data of the file
8696 unmodified.
8697 When the file can't be opened an error message is given and
8698 the result is an empty list.
8699 Also see |writefile()|.
8700
8701 Can also be used as a |method|: >
8702 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008703<
8704 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008705
8706reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8707 {func} is called for every item in {object}, which can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008708 |String|, |List|, |Tuple| or a |Blob|. {func} is called with
8709 two arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008710 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008711
8712 {initial} is the initial result. When omitted, the first item
8713 in {object} is used and {func} is first called for the second
8714 item. If {initial} is not given and {object} is empty no
8715 result can be computed, an E998 error is given.
8716
8717 Examples: >
8718 echo reduce([1, 3, 5], { acc, val -> acc + val })
8719 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8720 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8721 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8722<
8723 Can also be used as a |method|: >
8724 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008725<
8726 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8727 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008728
8729
8730reg_executing() *reg_executing()*
8731 Returns the single letter name of the register being executed.
8732 Returns an empty string when no register is being executed.
8733 See |@|.
8734
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008735 Return type: |String|
8736
8737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008738reg_recording() *reg_recording()*
8739 Returns the single letter name of the register being recorded.
8740 Returns an empty string when not recording. See |q|.
8741
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008742 Return type: |String|
8743
8744
8745reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008746reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008747reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008748 Return an item that represents a time value. The item is a
8749 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008750 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008751 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008752 string or |reltimefloat()| to convert to a Float. For
8753 example, to see the time spent in function Work(): >
8754 var startTime = reltime()
8755 Work()
8756 echo startTime->reltime()->reltimestr()
8757<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008758 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008759 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008760 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008761 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008762 specified in the argument.
8763 With two arguments it returns the time passed between {start}
8764 and {end}.
8765
8766 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008767 reltime(). If there is an error an empty List is returned in
8768 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008769
8770 Can also be used as a |method|: >
8771 GetStart()->reltime()
8772<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008773 Return type: list<number>
8774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008775 {only available when compiled with the |+reltime| feature}
8776
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008778reltimefloat({time}) *reltimefloat()*
8779 Return a Float that represents the time value of {time}.
8780 Example: >
8781 let start = reltime()
8782 call MyFunction()
8783 let seconds = reltimefloat(reltime(start))
8784< See the note of reltimestr() about overhead.
8785 Also see |profiling|.
8786 If there is an error 0.0 is returned in legacy script, in Vim9
8787 script an error is given.
8788
8789 Can also be used as a |method|: >
8790 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008791<
8792 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008793
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008794 {only available when compiled with the |+reltime| feature}
8795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008796
8797reltimestr({time}) *reltimestr()*
8798 Return a String that represents the time value of {time}.
8799 This is the number of seconds, a dot and the number of
8800 microseconds. Example: >
8801 let start = reltime()
8802 call MyFunction()
8803 echo reltimestr(reltime(start))
8804< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008805 The accuracy depends on the system. Use reltimefloat() for the
8806 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008807 Leading spaces are used to make the string align nicely. You
8808 can use split() to remove it. >
8809 echo split(reltimestr(reltime(start)))[0]
8810< Also see |profiling|.
8811 If there is an error an empty string is returned in legacy
8812 script, in Vim9 script an error is given.
8813
8814 Can also be used as a |method|: >
8815 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008816<
8817 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008818
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008819 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008820
8821 *remote_expr()* *E449*
8822remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008823 Send the {string} to {server}. The {server} argument is a
8824 string, also see |{server}|.
8825
8826 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008827 after evaluation. The result must be a String or a |List|
8828 other types will be converted to String. A |List| is turned
8829 into a String by joining the items with a line break in
8830 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008832 If {idvar} is present and not empty, it is taken as the name
8833 of a variable and a {serverid} for later use with
8834 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008835
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008836 If {timeout} is given the read times out after this many
8837 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008839 See also |clientserver| |RemoteReply|.
8840 This function is not available in the |sandbox|.
8841 {only available when compiled with the |+clientserver| feature}
8842 Note: Any errors will cause a local error message to be issued
8843 and the result will be the empty string.
8844
8845 Variables will be evaluated in the global namespace,
8846 independent of a function currently being active. Except
8847 when in debug mode, then local function variables and
8848 arguments can be evaluated.
8849
8850 Examples: >
8851 :echo remote_expr("gvim", "2+2")
8852 :echo remote_expr("gvim1", "b:current_syntax")
8853<
8854 Can also be used as a |method|: >
8855 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008856<
8857 Return type: |String| or list<{type}>
8858
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008859
8860remote_foreground({server}) *remote_foreground()*
8861 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008862 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008863 This works like: >
8864 remote_expr({server}, "foreground()")
8865< Except that on Win32 systems the client does the work, to work
8866 around the problem that the OS doesn't always allow the server
8867 to bring itself to the foreground.
8868 Note: This does not restore the window if it was minimized,
8869 like foreground() does.
8870 This function is not available in the |sandbox|.
8871
8872 Can also be used as a |method|: >
8873 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008874<
8875 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008876
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008877 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008878 Win32 console version}
8879
8880
8881remote_peek({serverid} [, {retvar}]) *remote_peek()*
8882 Returns a positive number if there are available strings
8883 from {serverid}. Copies any reply string into the variable
8884 {retvar} if specified. {retvar} must be a string with the
8885 name of a variable.
8886 Returns zero if none are available.
8887 Returns -1 if something is wrong.
8888 See also |clientserver|.
8889 This function is not available in the |sandbox|.
8890 {only available when compiled with the |+clientserver| feature}
8891 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008892 :let repl = ""
8893 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008894
8895< Can also be used as a |method|: >
8896 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008897<
8898 Return type: |Number|
8899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008900
8901remote_read({serverid}, [{timeout}]) *remote_read()*
8902 Return the oldest available reply from {serverid} and consume
8903 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008904 reply is available. Returns an empty string, if a reply is
8905 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008906 See also |clientserver|.
8907 This function is not available in the |sandbox|.
8908 {only available when compiled with the |+clientserver| feature}
8909 Example: >
8910 :echo remote_read(id)
8911
8912< Can also be used as a |method|: >
8913 ServerId()->remote_read()
8914<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008915 Return type: |String|
8916
8917
8918remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008919 Send the {string} to {server}. The {server} argument is a
8920 string, also see |{server}|.
8921
8922 The string is sent as input keys and the function returns
8923 immediately. At the Vim server the keys are not mapped
8924 |:map|.
8925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008926 If {idvar} is present, it is taken as the name of a variable
8927 and a {serverid} for later use with remote_read() is stored
8928 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008930 See also |clientserver| |RemoteReply|.
8931 This function is not available in the |sandbox|.
8932 {only available when compiled with the |+clientserver| feature}
8933
8934 Note: Any errors will be reported in the server and may mess
8935 up the display.
8936 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008937 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008938 \ remote_read(serverid)
8939
8940 :autocmd NONE RemoteReply *
8941 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008942 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008943 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8944<
8945 Can also be used as a |method|: >
8946 ServerName()->remote_send(keys)
8947<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008948 Return type: |String|
8949
8950
8951remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008952 Become the server {name}. {name} must be a non-empty string.
8953 This fails if already running as a server, when |v:servername|
8954 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008955
8956 Can also be used as a |method|: >
8957 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008958<
8959 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008960
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008961 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008962
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008963
8964remove({list}, {idx}) *remove()*
8965remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008966 Without {end}: Remove the item at {idx} from |List| {list} and
8967 return the item.
8968 With {end}: Remove items from {idx} to {end} (inclusive) and
8969 return a |List| with these items. When {idx} points to the same
8970 item as {end} a list with one item is returned. When {end}
8971 points to an item before {idx} this is an error.
8972 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008973 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008974 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008975 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008976 :call remove(mylist, 0, 9)
8977<
8978 Use |delete()| to remove a file.
8979
8980 Can also be used as a |method|: >
8981 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008982<
8983 Return type: any, depending on {list}
8984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008985
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008986remove({blob}, {idx})
8987remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008988 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8989 return the byte.
8990 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8991 return a |Blob| with these bytes. When {idx} points to the same
8992 byte as {end} a |Blob| with one byte is returned. When {end}
8993 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008994 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008995 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008996 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008997 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008998<
8999 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009000
9001remove({dict}, {key})
9002 Remove the entry from {dict} with key {key} and return it.
9003 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009004 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009005< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009006 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009007
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009008 Return type: any, depending on {dict}
9009
9010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009011rename({from}, {to}) *rename()*
9012 Rename the file by the name {from} to the name {to}. This
9013 should also work to move files across file systems. The
9014 result is a Number, which is 0 if the file was renamed
9015 successfully, and non-zero when the renaming failed.
9016 NOTE: If {to} exists it is overwritten without warning.
9017 This function is not available in the |sandbox|.
9018
9019 Can also be used as a |method|: >
9020 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009021<
9022 Return type: |Number|
9023
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009024
9025repeat({expr}, {count}) *repeat()*
9026 Repeat {expr} {count} times and return the concatenated
9027 result. Example: >
9028 :let separator = repeat('-', 80)
9029< When {count} is zero or negative the result is empty.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009030 When {expr} is a |List|, a |Tuple| or a |Blob| the result is
9031 {expr} concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009032 :let longlist = repeat(['a', 'b'], 3)
9033< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
9034
9035 Can also be used as a |method|: >
9036 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009037<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009038 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
9039 depending on {expr}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009041
9042resolve({filename}) *resolve()* *E655*
9043 On MS-Windows, when {filename} is a shortcut (a .lnk file),
9044 returns the path the shortcut points to in a simplified form.
9045 When {filename} is a symbolic link or junction point, return
9046 the full path to the target. If the target of junction is
9047 removed, return {filename}.
9048 On Unix, repeat resolving symbolic links in all path
9049 components of {filename} and return the simplified result.
9050 To cope with link cycles, resolving of symbolic links is
9051 stopped after 100 iterations.
9052 On other systems, return the simplified {filename}.
9053 The simplification step is done as by |simplify()|.
9054 resolve() keeps a leading path component specifying the
9055 current directory (provided the result is still a relative
9056 path name) and also keeps a trailing path separator.
9057
9058 Can also be used as a |method|: >
9059 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009060<
9061 Return type: |String|
9062
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009063
9064reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009065 Reverse the order of items in {object}. {object} can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009066 |List|, a |Tuple|, a |Blob| or a |String|. For a List and a
9067 Blob the items are reversed in-place and {object} is returned.
9068 For a Tuple, a new Tuple is returned.
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009069 For a String a new String is returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009070 Returns zero if {object} is not a List, Tuple, Blob or a
9071 String. If you want a List or Blob to remain unmodified make
9072 a copy first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009073 :let revlist = reverse(copy(mylist))
9074< Can also be used as a |method|: >
9075 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009076<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009077 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
9078 depending on {object}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009079
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009080
9081round({expr}) *round()*
9082 Round off {expr} to the nearest integral value and return it
9083 as a |Float|. If {expr} lies halfway between two integral
9084 values, then use the larger one (away from zero).
9085 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009086 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009087 Examples: >
9088 echo round(0.456)
9089< 0.0 >
9090 echo round(4.5)
9091< 5.0 >
9092 echo round(-4.5)
9093< -5.0
9094
9095 Can also be used as a |method|: >
9096 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009097<
9098 Return type: |Float|
9099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009100
9101rubyeval({expr}) *rubyeval()*
9102 Evaluate Ruby expression {expr} and return its result
9103 converted to Vim data structures.
9104 Numbers, floats and strings are returned as they are (strings
9105 are copied though).
9106 Arrays are represented as Vim |List| type.
9107 Hashes are represented as Vim |Dictionary| type.
9108 Other objects are represented as strings resulted from their
9109 "Object#to_s" method.
9110 Note that in a `:def` function local variables are not visible
9111 to {expr}.
9112
9113 Can also be used as a |method|: >
9114 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009115<
9116 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009117
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009118 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009119
9120screenattr({row}, {col}) *screenattr()*
9121 Like |screenchar()|, but return the attribute. This is a rather
9122 arbitrary number that can only be used to compare to the
9123 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009124 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009125
9126 Can also be used as a |method|: >
9127 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009128<
9129 Return type: |Number|
9130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009131
9132screenchar({row}, {col}) *screenchar()*
9133 The result is a Number, which is the character at position
9134 [row, col] on the screen. This works for every possible
9135 screen position, also status lines, window separators and the
9136 command line. The top left position is row one, column one
9137 The character excludes composing characters. For double-byte
9138 encodings it may only be the first byte.
9139 This is mainly to be used for testing.
9140 Returns -1 when row or col is out of range.
9141
9142 Can also be used as a |method|: >
9143 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009144<
9145 Return type: |Number|
9146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009147
9148screenchars({row}, {col}) *screenchars()*
9149 The result is a |List| of Numbers. The first number is the same
9150 as what |screenchar()| returns. Further numbers are
9151 composing characters on top of the base character.
9152 This is mainly to be used for testing.
9153 Returns an empty List when row or col is out of range.
9154
9155 Can also be used as a |method|: >
9156 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009157<
9158 Return type: list<number> or list<any>
9159
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009160
9161screencol() *screencol()*
9162 The result is a Number, which is the current screen column of
9163 the cursor. The leftmost column has number 1.
9164 This function is mainly used for testing.
9165
9166 Note: Always returns the current screen column, thus if used
9167 in a command (e.g. ":echo screencol()") it will return the
9168 column inside the command line, which is 1 when the command is
9169 executed. To get the cursor position in the file use one of
9170 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009171 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009172 nnoremap <silent> GG :echom screencol()<CR>
9173 nnoremap GG <Cmd>echom screencol()<CR>
9174<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009175 Return type: |Number|
9176
9177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009178screenpos({winid}, {lnum}, {col}) *screenpos()*
9179 The result is a Dict with the screen position of the text
9180 character in window {winid} at buffer line {lnum} and column
9181 {col}. {col} is a one-based byte index.
9182 The Dict has these members:
9183 row screen row
9184 col first screen column
9185 endcol last screen column
9186 curscol cursor screen column
9187 If the specified position is not visible, all values are zero.
9188 The "endcol" value differs from "col" when the character
9189 occupies more than one screen cell. E.g. for a Tab "col" can
9190 be 1 and "endcol" can be 8.
9191 The "curscol" value is where the cursor would be placed. For
9192 a Tab it would be the same as "endcol", while for a double
9193 width character it would be the same as "col".
9194 The |conceal| feature is ignored here, the column numbers are
9195 as if 'conceallevel' is zero. You can set the cursor to the
9196 right position and use |screencol()| to get the value with
9197 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009198 If the position is in a closed fold the screen position of the
9199 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009200 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009201
9202 Can also be used as a |method|: >
9203 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009204<
9205 Return type: dict<number> or dict<any>
9206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009207
9208screenrow() *screenrow()*
9209 The result is a Number, which is the current screen row of the
9210 cursor. The top line has number one.
9211 This function is mainly used for testing.
9212 Alternatively you can use |winline()|.
9213
9214 Note: Same restrictions as with |screencol()|.
9215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009216 Return type: |Number|
9217
9218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009219screenstring({row}, {col}) *screenstring()*
9220 The result is a String that contains the base character and
9221 any composing characters at position [row, col] on the screen.
9222 This is like |screenchars()| but returning a String with the
9223 characters.
9224 This is mainly to be used for testing.
9225 Returns an empty String when row or col is out of range.
9226
9227 Can also be used as a |method|: >
9228 GetRow()->screenstring(col)
9229<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009230 Return type: |String|
9231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009232 *search()*
9233search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9234 Search for regexp pattern {pattern}. The search starts at the
9235 cursor position (you can use |cursor()| to set it).
9236
9237 When a match has been found its line number is returned.
9238 If there is no match a 0 is returned and the cursor doesn't
9239 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009240 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009241
9242 {flags} is a String, which can contain these character flags:
9243 'b' search Backward instead of forward
9244 'c' accept a match at the Cursor position
9245 'e' move to the End of the match
9246 'n' do Not move the cursor
9247 'p' return number of matching sub-Pattern (see below)
9248 's' Set the ' mark at the previous location of the cursor
9249 'w' Wrap around the end of the file
9250 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009251 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009252 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9253
9254 If the 's' flag is supplied, the ' mark is set, only if the
9255 cursor is moved. The 's' flag cannot be combined with the 'n'
9256 flag.
9257
9258 'ignorecase', 'smartcase' and 'magic' are used.
9259
9260 When the 'z' flag is not given, forward searching always
9261 starts in column zero and then matches before the cursor are
9262 skipped. When the 'c' flag is present in 'cpo' the next
9263 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009264 search starts one column after the start of the match. This
9265 matters for overlapping matches. See |cpo-c|. You can also
9266 insert "\ze" to change where the match ends, see |/\ze|.
9267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009268 When searching backwards and the 'z' flag is given then the
9269 search starts in column zero, thus no match in the current
9270 line will be found (unless wrapping around the end of the
9271 file).
9272
9273 When the {stopline} argument is given then the search stops
9274 after searching this line. This is useful to restrict the
9275 search to a range of lines. Examples: >
9276 let match = search('(', 'b', line("w0"))
9277 let end = search('END', '', line("w$"))
9278< When {stopline} is used and it is not zero this also implies
9279 that the search does not wrap around the end of the file.
9280 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009281 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009282 When the {timeout} argument is given the search stops when
9283 more than this many milliseconds have passed. Thus when
9284 {timeout} is 500 the search stops after half a second.
9285 The value must not be negative. A zero value is like not
9286 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009287
9288 Note: the timeout is only considered when searching, not
9289 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009290 {only available when compiled with the |+reltime| feature}
9291
9292 If the {skip} expression is given it is evaluated with the
9293 cursor positioned on the start of a match. If it evaluates to
9294 non-zero this match is skipped. This can be used, for
9295 example, to skip a match in a comment or a string.
9296 {skip} can be a string, which is evaluated as an expression, a
9297 function reference or a lambda.
9298 When {skip} is omitted or empty, every match is accepted.
9299 When evaluating {skip} causes an error the search is aborted
9300 and -1 returned.
9301 *search()-sub-match*
9302 With the 'p' flag the returned value is one more than the
9303 first sub-match in \(\). One if none of them matched but the
9304 whole pattern did match.
9305 To get the column number too use |searchpos()|.
9306
9307 The cursor will be positioned at the match, unless the 'n'
9308 flag is used.
9309
9310 Example (goes over all files in the argument list): >
9311 :let n = 1
9312 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009313 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009314 : " start at the last char in the file and wrap for the
9315 : " first search to find match at start of file
9316 : normal G$
9317 : let flags = "w"
9318 : while search("foo", flags) > 0
9319 : s/foo/bar/g
9320 : let flags = "W"
9321 : endwhile
9322 : update " write the file if modified
9323 : let n = n + 1
9324 :endwhile
9325<
9326 Example for using some flags: >
9327 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9328< This will search for the keywords "if", "else", and "endif"
9329 under or after the cursor. Because of the 'p' flag, it
9330 returns 1, 2, or 3 depending on which keyword is found, or 0
9331 if the search fails. With the cursor on the first word of the
9332 line:
9333 if (foo == 0) | let foo = foo + 1 | endif ~
9334 the function returns 1. Without the 'c' flag, the function
9335 finds the "endif" and returns 3. The same thing happens
9336 without the 'e' flag if the cursor is on the "f" of "if".
9337 The 'n' flag tells the function not to move the cursor.
9338
9339 Can also be used as a |method|: >
9340 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009341<
9342 Return type: |Number|
9343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009344
9345searchcount([{options}]) *searchcount()*
9346 Get or update the last search count, like what is displayed
9347 without the "S" flag in 'shortmess'. This works even if
9348 'shortmess' does contain the "S" flag.
9349
9350 This returns a |Dictionary|. The dictionary is empty if the
9351 previous pattern was not set and "pattern" was not specified.
9352
9353 key type meaning ~
9354 current |Number| current position of match;
9355 0 if the cursor position is
9356 before the first match
9357 exact_match |Boolean| 1 if "current" is matched on
9358 "pos", otherwise 0
9359 total |Number| total count of matches found
9360 incomplete |Number| 0: search was fully completed
9361 1: recomputing was timed out
9362 2: max count exceeded
9363
9364 For {options} see further down.
9365
9366 To get the last search count when |n| or |N| was pressed, call
9367 this function with `recompute: 0` . This sometimes returns
9368 wrong information because |n| and |N|'s maximum count is 99.
9369 If it exceeded 99 the result must be max count + 1 (100). If
9370 you want to get correct information, specify `recompute: 1`: >
9371
9372 " result == maxcount + 1 (100) when many matches
9373 let result = searchcount(#{recompute: 0})
9374
9375 " Below returns correct result (recompute defaults
9376 " to 1)
9377 let result = searchcount()
9378<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009379 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009380 function! LastSearchCount() abort
9381 let result = searchcount(#{recompute: 0})
9382 if empty(result)
9383 return ''
9384 endif
9385 if result.incomplete ==# 1 " timed out
9386 return printf(' /%s [?/??]', @/)
9387 elseif result.incomplete ==# 2 " max count exceeded
9388 if result.total > result.maxcount &&
9389 \ result.current > result.maxcount
9390 return printf(' /%s [>%d/>%d]', @/,
9391 \ result.current, result.total)
9392 elseif result.total > result.maxcount
9393 return printf(' /%s [%d/>%d]', @/,
9394 \ result.current, result.total)
9395 endif
9396 endif
9397 return printf(' /%s [%d/%d]', @/,
9398 \ result.current, result.total)
9399 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009400 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009401
9402 " Or if you want to show the count only when
9403 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009404 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009405 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9406<
9407 You can also update the search count, which can be useful in a
9408 |CursorMoved| or |CursorMovedI| autocommand: >
9409
9410 autocmd CursorMoved,CursorMovedI *
9411 \ let s:searchcount_timer = timer_start(
9412 \ 200, function('s:update_searchcount'))
9413 function! s:update_searchcount(timer) abort
9414 if a:timer ==# s:searchcount_timer
9415 call searchcount(#{
9416 \ recompute: 1, maxcount: 0, timeout: 100})
9417 redrawstatus
9418 endif
9419 endfunction
9420<
9421 This can also be used to count matched texts with specified
9422 pattern in the current buffer using "pattern": >
9423
9424 " Count '\<foo\>' in this buffer
9425 " (Note that it also updates search count)
9426 let result = searchcount(#{pattern: '\<foo\>'})
9427
9428 " To restore old search count by old pattern,
9429 " search again
9430 call searchcount()
9431<
9432 {options} must be a |Dictionary|. It can contain:
9433 key type meaning ~
9434 recompute |Boolean| if |TRUE|, recompute the count
9435 like |n| or |N| was executed.
9436 otherwise returns the last
9437 computed result (when |n| or
9438 |N| was used when "S" is not
9439 in 'shortmess', or this
9440 function was called).
9441 (default: |TRUE|)
9442 pattern |String| recompute if this was given
9443 and different with |@/|.
9444 this works as same as the
9445 below command is executed
9446 before calling this function >
9447 let @/ = pattern
9448< (default: |@/|)
9449 timeout |Number| 0 or negative number is no
9450 timeout. timeout milliseconds
9451 for recomputing the result
9452 (default: 0)
9453 maxcount |Number| 0 or negative number is no
9454 limit. max count of matched
9455 text while recomputing the
9456 result. if search exceeded
9457 total count, "total" value
9458 becomes `maxcount + 1`
9459 (default: 99)
9460 pos |List| `[lnum, col, off]` value
9461 when recomputing the result.
9462 this changes "current" result
9463 value. see |cursor()|,
9464 |getpos()|
9465 (default: cursor's position)
9466
9467 Can also be used as a |method|: >
9468 GetSearchOpts()->searchcount()
9469<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009470 Return type: dict<number>
9471
9472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009473searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9474 Search for the declaration of {name}.
9475
9476 With a non-zero {global} argument it works like |gD|, find
9477 first match in the file. Otherwise it works like |gd|, find
9478 first match in the function.
9479
9480 With a non-zero {thisblock} argument matches in a {} block
9481 that ends before the cursor position are ignored. Avoids
9482 finding variable declarations only valid in another scope.
9483
9484 Moves the cursor to the found match.
9485 Returns zero for success, non-zero for failure.
9486 Example: >
9487 if searchdecl('myvar') == 0
9488 echo getline('.')
9489 endif
9490<
9491 Can also be used as a |method|: >
9492 GetName()->searchdecl()
9493<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009494 Return type: |Number|
9495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009496 *searchpair()*
9497searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9498 [, {stopline} [, {timeout}]]]])
9499 Search for the match of a nested start-end pair. This can be
9500 used to find the "endif" that matches an "if", while other
9501 if/endif pairs in between are ignored.
9502 The search starts at the cursor. The default is to search
9503 forward, include 'b' in {flags} to search backward.
9504 If a match is found, the cursor is positioned at it and the
9505 line number is returned. If no match is found 0 or -1 is
9506 returned and the cursor doesn't move. No error message is
9507 given.
9508
9509 {start}, {middle} and {end} are patterns, see |pattern|. They
9510 must not contain \( \) pairs. Use of \%( \) is allowed. When
9511 {middle} is not empty, it is found when searching from either
9512 direction, but only when not in a nested start-end pair. A
9513 typical use is: >
9514 searchpair('\<if\>', '\<else\>', '\<endif\>')
9515< By leaving {middle} empty the "else" is skipped.
9516
9517 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9518 |search()|. Additionally:
9519 'r' Repeat until no more matches found; will find the
9520 outer pair. Implies the 'W' flag.
9521 'm' Return number of matches instead of line number with
9522 the match; will be > 1 when 'r' is used.
9523 Note: it's nearly always a good idea to use the 'W' flag, to
9524 avoid wrapping around the end of the file.
9525
9526 When a match for {start}, {middle} or {end} is found, the
9527 {skip} expression is evaluated with the cursor positioned on
9528 the start of the match. It should return non-zero if this
9529 match is to be skipped. E.g., because it is inside a comment
9530 or a string.
9531 When {skip} is omitted or empty, every match is accepted.
9532 When evaluating {skip} causes an error the search is aborted
9533 and -1 returned.
9534 {skip} can be a string, a lambda, a funcref or a partial.
9535 Anything else makes the function fail.
9536 In a `:def` function when the {skip} argument is a string
9537 constant it is compiled into instructions.
9538
9539 For {stopline} and {timeout} see |search()|.
9540
9541 The value of 'ignorecase' is used. 'magic' is ignored, the
9542 patterns are used like it's on.
9543
9544 The search starts exactly at the cursor. A match with
9545 {start}, {middle} or {end} at the next character, in the
9546 direction of searching, is the first one found. Example: >
9547 if 1
9548 if 2
9549 endif 2
9550 endif 1
9551< When starting at the "if 2", with the cursor on the "i", and
9552 searching forwards, the "endif 2" is found. When starting on
9553 the character just before the "if 2", the "endif 1" will be
9554 found. That's because the "if 2" will be found first, and
9555 then this is considered to be a nested if/endif from "if 2" to
9556 "endif 2".
9557 When searching backwards and {end} is more than one character,
9558 it may be useful to put "\zs" at the end of the pattern, so
9559 that when the cursor is inside a match with the end it finds
9560 the matching start.
9561
9562 Example, to find the "endif" command in a Vim script: >
9563
9564 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9565 \ 'getline(".") =~ "^\\s*\""')
9566
9567< The cursor must be at or after the "if" for which a match is
9568 to be found. Note that single-quote strings are used to avoid
9569 having to double the backslashes. The skip expression only
9570 catches comments at the start of a line, not after a command.
9571 Also, a word "en" or "if" halfway a line is considered a
9572 match.
9573 Another example, to search for the matching "{" of a "}": >
9574
9575 :echo searchpair('{', '', '}', 'bW')
9576
9577< This works when the cursor is at or before the "}" for which a
9578 match is to be found. To reject matches that syntax
9579 highlighting recognized as strings: >
9580
9581 :echo searchpair('{', '', '}', 'bW',
9582 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9583<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009584 Return type: |Number|
9585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009586 *searchpairpos()*
9587searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9588 [, {stopline} [, {timeout}]]]])
9589 Same as |searchpair()|, but returns a |List| with the line and
9590 column position of the match. The first element of the |List|
9591 is the line number and the second element is the byte index of
9592 the column position of the match. If no match is found,
9593 returns [0, 0]. >
9594
9595 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9596<
9597 See |match-parens| for a bigger and more useful example.
9598
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009599 Return type: list<number>
9600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009601 *searchpos()*
9602searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9603 Same as |search()|, but returns a |List| with the line and
9604 column position of the match. The first element of the |List|
9605 is the line number and the second element is the byte index of
9606 the column position of the match. If no match is found,
9607 returns [0, 0].
9608 Example: >
9609 :let [lnum, col] = searchpos('mypattern', 'n')
9610
9611< When the 'p' flag is given then there is an extra item with
9612 the sub-pattern match number |search()-sub-match|. Example: >
9613 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9614< In this example "submatch" is 2 when a lowercase letter is
9615 found |/\l|, 3 when an uppercase letter is found |/\u|.
9616
9617 Can also be used as a |method|: >
9618 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009619<
9620 Return type: list<number>
9621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009622
9623server2client({clientid}, {string}) *server2client()*
9624 Send a reply string to {clientid}. The most recent {clientid}
9625 that sent a string can be retrieved with expand("<client>").
9626 {only available when compiled with the |+clientserver| feature}
9627 Returns zero for success, -1 for failure.
9628 Note:
9629 This id has to be stored before the next command can be
9630 received. I.e. before returning from the received command and
9631 before calling any commands that waits for input.
9632 See also |clientserver|.
9633 Example: >
9634 :echo server2client(expand("<client>"), "HELLO")
9635
9636< Can also be used as a |method|: >
9637 GetClientId()->server2client(string)
9638<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009639 Return type: |Number|
9640
9641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009642serverlist() *serverlist()*
9643 Return a list of available server names, one per line.
9644 When there are no servers or the information is not available
9645 an empty string is returned. See also |clientserver|.
9646 {only available when compiled with the |+clientserver| feature}
9647 Example: >
9648 :echo serverlist()
9649<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009650 Return type: |String|
9651
9652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009653setbufline({buf}, {lnum}, {text}) *setbufline()*
9654 Set line {lnum} to {text} in buffer {buf}. This works like
9655 |setline()| for the specified buffer.
9656
9657 This function works only for loaded buffers. First call
9658 |bufload()| if needed.
9659
9660 To insert lines use |appendbufline()|.
9661 Any text properties in {lnum} are cleared.
9662
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009663 {text} can be a string to set one line, or a List of strings
9664 to set multiple lines. If the List extends below the last
9665 line then those lines are added. If the List is empty then
9666 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009667
9668 For the use of {buf}, see |bufname()| above.
9669
9670 {lnum} is used like with |setline()|.
9671 Use "$" to refer to the last line in buffer {buf}.
9672 When {lnum} is just below the last line the {text} will be
9673 added below the last line.
9674
9675 When {buf} is not a valid buffer, the buffer is not loaded or
9676 {lnum} is not valid then 1 is returned. In |Vim9| script an
9677 error is given.
9678 On success 0 is returned.
9679
9680 Can also be used as a |method|, the base is passed as the
9681 third argument: >
9682 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009683<
9684 Return type: |Number|
9685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009686
9687setbufvar({buf}, {varname}, {val}) *setbufvar()*
9688 Set option or local variable {varname} in buffer {buf} to
9689 {val}.
9690 This also works for a global or local window option, but it
9691 doesn't work for a global or local window variable.
9692 For a local window option the global value is unchanged.
9693 For the use of {buf}, see |bufname()| above.
9694 The {varname} argument is a string.
9695 Note that the variable name without "b:" must be used.
9696 Examples: >
9697 :call setbufvar(1, "&mod", 1)
9698 :call setbufvar("todo", "myvar", "foobar")
9699< This function is not available in the |sandbox|.
9700
9701 Can also be used as a |method|, the base is passed as the
9702 third argument: >
9703 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009704<
9705 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009706
9707
9708setcellwidths({list}) *setcellwidths()*
9709 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009710 tells Vim how wide characters are when displayed in the
9711 terminal, counted in screen cells. The values override
9712 'ambiwidth'. Example: >
9713 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009714 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009715 \ [0x2194, 0x2199, 2],
9716 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009717
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009718< The {list} argument is a List of Lists with each three
9719 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9720 {low} and {high} can be the same, in which case this refers to
9721 one character. Otherwise it is the range of characters from
9722 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009723 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009724
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009725 {width} must be either 1 or 2, indicating the character width
9726 in screen cells. *E1112*
9727 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009728 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009730 If the new value causes 'fillchars' or 'listchars' to become
9731 invalid it is rejected and an error is given.
9732
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009733 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009734 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009736< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009737 the effect for known emoji characters. Move the cursor
9738 through the text to check if the cell widths of your terminal
9739 match with what Vim knows about each emoji. If it doesn't
9740 look right you need to adjust the {list} argument.
9741
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009742 Return type: |Number|
9743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009744
9745setcharpos({expr}, {list}) *setcharpos()*
9746 Same as |setpos()| but uses the specified column number as the
9747 character index instead of the byte index in the line.
9748
9749 Example:
9750 With the text "여보세요" in line 8: >
9751 call setcharpos('.', [0, 8, 4, 0])
9752< positions the cursor on the fourth character '요'. >
9753 call setpos('.', [0, 8, 4, 0])
9754< positions the cursor on the second character '보'.
9755
9756 Can also be used as a |method|: >
9757 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009758<
9759 Return type: |Number|
9760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009761
9762setcharsearch({dict}) *setcharsearch()*
9763 Set the current character search information to {dict},
9764 which contains one or more of the following entries:
9765
9766 char character which will be used for a subsequent
9767 |,| or |;| command; an empty string clears the
9768 character search
9769 forward direction of character search; 1 for forward,
9770 0 for backward
9771 until type of character search; 1 for a |t| or |T|
9772 character search, 0 for an |f| or |F|
9773 character search
9774
9775 This can be useful to save/restore a user's character search
9776 from a script: >
9777 :let prevsearch = getcharsearch()
9778 :" Perform a command which clobbers user's search
9779 :call setcharsearch(prevsearch)
9780< Also see |getcharsearch()|.
9781
9782 Can also be used as a |method|: >
9783 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009784<
9785 Return type: dict<any>
9786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009787
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009788setcmdline({str} [, {pos}]) *setcmdline()*
9789 Set the command line to {str} and set the cursor position to
9790 {pos}.
9791 If {pos} is omitted, the cursor is positioned after the text.
9792 Returns 0 when successful, 1 when not editing the command
9793 line.
9794
9795 Can also be used as a |method|: >
9796 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009797<
9798 Return type: |Number|
9799
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009800
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009801setcmdpos({pos}) *setcmdpos()*
9802 Set the cursor position in the command line to byte position
9803 {pos}. The first position is 1.
9804 Use |getcmdpos()| to obtain the current position.
9805 Only works while editing the command line, thus you must use
9806 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9807 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9808 set after the command line is set to the expression. For
9809 |c_CTRL-R_=| it is set after evaluating the expression but
9810 before inserting the resulting text.
9811 When the number is too big the cursor is put at the end of the
9812 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009813 Returns 0 when successful, 1 when not editing the command
9814 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009815
9816 Can also be used as a |method|: >
9817 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009818<
9819 Return type: |Number|
9820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009821
9822setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9823setcursorcharpos({list})
9824 Same as |cursor()| but uses the specified column number as the
9825 character index instead of the byte index in the line.
9826
9827 Example:
9828 With the text "여보세요" in line 4: >
9829 call setcursorcharpos(4, 3)
9830< positions the cursor on the third character '세'. >
9831 call cursor(4, 3)
9832< positions the cursor on the first character '여'.
9833
9834 Can also be used as a |method|: >
9835 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009836<
Christian Brabandt17ad8522025-05-09 00:03:20 +02009837 Returns 0 when the position could be set, -1 otherwise.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009838 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009839
9840
9841setenv({name}, {val}) *setenv()*
9842 Set environment variable {name} to {val}. Example: >
9843 call setenv('HOME', '/home/myhome')
9844
9845< When {val} is |v:null| the environment variable is deleted.
9846 See also |expr-env|.
9847
9848 Can also be used as a |method|, the base is passed as the
9849 second argument: >
9850 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009851<
9852 Return type: |Number|
9853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009854
9855setfperm({fname}, {mode}) *setfperm()* *chmod*
9856 Set the file permissions for {fname} to {mode}.
9857 {mode} must be a string with 9 characters. It is of the form
9858 "rwxrwxrwx", where each group of "rwx" flags represent, in
9859 turn, the permissions of the owner of the file, the group the
9860 file belongs to, and other users. A '-' character means the
9861 permission is off, any other character means on. Multi-byte
9862 characters are not supported.
9863
9864 For example "rw-r-----" means read-write for the user,
9865 readable by the group, not accessible by others. "xx-x-----"
9866 would do the same thing.
9867
9868 Returns non-zero for success, zero for failure.
9869
9870 Can also be used as a |method|: >
9871 GetFilename()->setfperm(mode)
9872<
9873 To read permissions see |getfperm()|.
9874
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009875 Return type: |Number|
9876
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009877
9878setline({lnum}, {text}) *setline()*
9879 Set line {lnum} of the current buffer to {text}. To insert
9880 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009881 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009882 Any text properties in {lnum} are cleared. See
9883 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009884
9885 {lnum} is used like with |getline()|.
9886 When {lnum} is just below the last line the {text} will be
9887 added below the last line.
9888 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009889 converted to a String. When {text} is an empty List then
9890 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009891
9892 If this succeeds, FALSE is returned. If this fails (most likely
9893 because {lnum} is invalid) TRUE is returned.
9894 In |Vim9| script an error is given if {lnum} is invalid.
9895
9896 Example: >
9897 :call setline(5, strftime("%c"))
9898
9899< When {text} is a |List| then line {lnum} and following lines
9900 will be set to the items in the list. Example: >
9901 :call setline(5, ['aaa', 'bbb', 'ccc'])
9902< This is equivalent to: >
9903 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9904 : call setline(n, l)
9905 :endfor
9906
9907< Note: The '[ and '] marks are not set.
9908
9909 Can also be used as a |method|, the base is passed as the
9910 second argument: >
9911 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009912<
9913 Return type: |Number|
9914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009915
9916setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9917 Create or replace or add to the location list for window {nr}.
9918 {nr} can be the window number or the |window-ID|.
9919 When {nr} is zero the current window is used.
9920
9921 For a location list window, the displayed location list is
9922 modified. For an invalid window number {nr}, -1 is returned.
9923 Otherwise, same as |setqflist()|.
9924 Also see |location-list|.
9925
9926 For {action} see |setqflist-action|.
9927
9928 If the optional {what} dictionary argument is supplied, then
9929 only the items listed in {what} are set. Refer to |setqflist()|
9930 for the list of supported keys in {what}.
9931
9932 Can also be used as a |method|, the base is passed as the
9933 second argument: >
9934 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009935<
9936 Return type: |Number|
9937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009938
9939setmatches({list} [, {win}]) *setmatches()*
9940 Restores a list of matches saved by |getmatches()| for the
9941 current window. Returns 0 if successful, otherwise -1. All
9942 current matches are cleared before the list is restored. See
9943 example for |getmatches()|.
9944 If {win} is specified, use the window with this number or
9945 window ID instead of the current window.
9946
9947 Can also be used as a |method|: >
9948 GetMatches()->setmatches()
9949<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009950 Return type: |Number|
9951
9952
9953setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009954 Set the position for String {expr}. Possible values:
9955 . the cursor
9956 'x mark x
9957
9958 {list} must be a |List| with four or five numbers:
9959 [bufnum, lnum, col, off]
9960 [bufnum, lnum, col, off, curswant]
9961
9962 "bufnum" is the buffer number. Zero can be used for the
9963 current buffer. When setting an uppercase mark "bufnum" is
9964 used for the mark position. For other marks it specifies the
9965 buffer to set the mark in. You can use the |bufnr()| function
9966 to turn a file name into a buffer number.
9967 For setting the cursor and the ' mark "bufnum" is ignored,
9968 since these are associated with a window, not a buffer.
9969 Does not change the jumplist.
9970
9971 "lnum" and "col" are the position in the buffer. The first
9972 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9973 smaller than 1 then 1 is used. To use the character count
9974 instead of the byte count, use |setcharpos()|.
9975
9976 The "off" number is only used when 'virtualedit' is set. Then
9977 it is the offset in screen columns from the start of the
9978 character. E.g., a position within a <Tab> or after the last
9979 character.
9980
9981 The "curswant" number is only used when setting the cursor
9982 position. It sets the preferred column for when moving the
9983 cursor vertically. When the "curswant" number is missing the
9984 preferred column is not set. When it is present and setting a
9985 mark position it is not used.
9986
9987 Note that for '< and '> changing the line number may result in
9988 the marks to be effectively be swapped, so that '< is always
9989 before '>.
9990
9991 Returns 0 when the position could be set, -1 otherwise.
9992 An error message is given if {expr} is invalid.
9993
9994 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9995
9996 This does not restore the preferred column for moving
9997 vertically; if you set the cursor position with this, |j| and
9998 |k| motions will jump to previous columns! Use |cursor()| to
9999 also set the preferred column. Also see the "curswant" key in
10000 |winrestview()|.
10001
10002 Can also be used as a |method|: >
10003 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010004<
10005 Return type: |Number|
10006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010007
10008setqflist({list} [, {action} [, {what}]]) *setqflist()*
10009 Create or replace or add to the quickfix list.
10010
10011 If the optional {what} dictionary argument is supplied, then
10012 only the items listed in {what} are set. The first {list}
10013 argument is ignored. See below for the supported items in
10014 {what}.
10015 *setqflist-what*
10016 When {what} is not present, the items in {list} are used. Each
10017 item must be a dictionary. Non-dictionary items in {list} are
10018 ignored. Each dictionary item can contain the following
10019 entries:
10020
10021 bufnr buffer number; must be the number of a valid
10022 buffer
10023 filename name of a file; only used when "bufnr" is not
10024 present or it is invalid.
10025 module name of a module; if given it will be used in
10026 quickfix error window instead of the filename.
10027 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +000010028 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010029 pattern search pattern used to locate the error
10030 col column number
10031 vcol when non-zero: "col" is visual column
10032 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +000010033 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010034 nr error number
10035 text description of the error
10036 type single-character error type, 'E', 'W', etc.
10037 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +020010038 user_data custom data associated with the item, can be
10039 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010040
10041 The "col", "vcol", "nr", "type" and "text" entries are
10042 optional. Either "lnum" or "pattern" entry can be used to
10043 locate a matching error line.
10044 If the "filename" and "bufnr" entries are not present or
10045 neither the "lnum" or "pattern" entries are present, then the
10046 item will not be handled as an error line.
10047 If both "pattern" and "lnum" are present then "pattern" will
10048 be used.
10049 If the "valid" entry is not supplied, then the valid flag is
10050 set when "bufnr" is a valid buffer or "filename" exists.
10051 If you supply an empty {list}, the quickfix list will be
10052 cleared.
10053 Note that the list is not exactly the same as what
10054 |getqflist()| returns.
10055
10056 {action} values: *setqflist-action* *E927*
10057 'a' The items from {list} are added to the existing
10058 quickfix list. If there is no existing list, then a
10059 new list is created.
10060
10061 'r' The items from the current quickfix list are replaced
10062 with the items from {list}. This can also be used to
10063 clear the list: >
10064 :call setqflist([], 'r')
10065<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +020010066 'u' Like 'r', but tries to preserve the current selection
10067 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010068 'f' All the quickfix lists in the quickfix stack are
10069 freed.
10070
10071 If {action} is not present or is set to ' ', then a new list
10072 is created. The new quickfix list is added after the current
10073 quickfix list in the stack and all the following lists are
10074 freed. To add a new quickfix list at the end of the stack,
10075 set "nr" in {what} to "$".
10076
10077 The following items can be specified in dictionary {what}:
10078 context quickfix list context. See |quickfix-context|
10079 efm errorformat to use when parsing text from
10080 "lines". If this is not present, then the
10081 'errorformat' option value is used.
10082 See |quickfix-parse|
10083 id quickfix list identifier |quickfix-ID|
10084 idx index of the current entry in the quickfix
10085 list specified by 'id' or 'nr'. If set to '$',
10086 then the last entry in the list is set as the
10087 current entry. See |quickfix-index|
10088 items list of quickfix entries. Same as the {list}
10089 argument.
10090 lines use 'errorformat' to parse a list of lines and
10091 add the resulting entries to the quickfix list
10092 {nr} or {id}. Only a |List| value is supported.
10093 See |quickfix-parse|
10094 nr list number in the quickfix stack; zero
10095 means the current quickfix list and "$" means
10096 the last quickfix list.
10097 quickfixtextfunc
10098 function to get the text to display in the
10099 quickfix window. The value can be the name of
10100 a function or a funcref or a lambda. Refer to
10101 |quickfix-window-function| for an explanation
10102 of how to write the function and an example.
10103 title quickfix list title text. See |quickfix-title|
10104 Unsupported keys in {what} are ignored.
10105 If the "nr" item is not present, then the current quickfix list
10106 is modified. When creating a new quickfix list, "nr" can be
10107 set to a value one greater than the quickfix stack size.
10108 When modifying a quickfix list, to guarantee that the correct
10109 list is modified, "id" should be used instead of "nr" to
10110 specify the list.
10111
10112 Examples (See also |setqflist-examples|): >
10113 :call setqflist([], 'r', {'title': 'My search'})
10114 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
10115 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
10116<
10117 Returns zero for success, -1 for failure.
10118
10119 This function can be used to create a quickfix list
10120 independent of the 'errorformat' setting. Use a command like
10121 `:cc 1` to jump to the first position.
10122
10123 Can also be used as a |method|, the base is passed as the
10124 second argument: >
10125 GetErrorlist()->setqflist()
10126<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010127 Return type: |Number|
10128
10129
10130setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010131 Set the register {regname} to {value}.
10132 If {regname} is "" or "@", the unnamed register '"' is used.
10133 The {regname} argument is a string. In |Vim9-script|
10134 {regname} must be one character.
10135
10136 {value} may be any value returned by |getreg()| or
10137 |getreginfo()|, including a |List| or |Dict|.
10138 If {options} contains "a" or {regname} is upper case,
10139 then the value is appended.
10140
10141 {options} can also contain a register type specification:
10142 "c" or "v" |characterwise| mode
10143 "l" or "V" |linewise| mode
10144 "b" or "<CTRL-V>" |blockwise-visual| mode
10145 If a number immediately follows "b" or "<CTRL-V>" then this is
10146 used as the width of the selection - if it is not specified
10147 then the width of the block is set to the number of characters
10148 in the longest line (counting a <Tab> as 1 character).
10149
10150 If {options} contains no register settings, then the default
10151 is to use character mode unless {value} ends in a <NL> for
10152 string {value} and linewise mode for list {value}. Blockwise
10153 mode is never selected automatically.
10154 Returns zero for success, non-zero for failure.
10155
10156 *E883*
10157 Note: you may not use |List| containing more than one item to
10158 set search and expression registers. Lists containing no
10159 items act like empty strings.
10160
10161 Examples: >
10162 :call setreg(v:register, @*)
10163 :call setreg('*', @%, 'ac')
10164 :call setreg('a', "1\n2\n3", 'b5')
10165 :call setreg('"', { 'points_to': 'a'})
10166
10167< This example shows using the functions to save and restore a
10168 register: >
10169 :let var_a = getreginfo()
10170 :call setreg('a', var_a)
10171< or: >
10172 :let var_a = getreg('a', 1, 1)
10173 :let var_amode = getregtype('a')
10174 ....
10175 :call setreg('a', var_a, var_amode)
10176< Note: you may not reliably restore register value
10177 without using the third argument to |getreg()| as without it
10178 newlines are represented as newlines AND Nul bytes are
10179 represented as newlines as well, see |NL-used-for-Nul|.
10180
10181 You can also change the type of a register by appending
10182 nothing: >
10183 :call setreg('a', '', 'al')
10184
10185< Can also be used as a |method|, the base is passed as the
10186 second argument: >
10187 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010188<
10189 Return type: |Number|
10190
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010191
10192settabvar({tabnr}, {varname}, {val}) *settabvar()*
10193 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10194 |t:var|
10195 The {varname} argument is a string.
10196 Note that autocommands are blocked, side effects may not be
10197 triggered, e.g. when setting 'filetype'.
10198 Note that the variable name without "t:" must be used.
10199 Tabs are numbered starting with one.
10200 This function is not available in the |sandbox|.
10201
10202 Can also be used as a |method|, the base is passed as the
10203 third argument: >
10204 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010205<
10206 Return type: |Number|
10207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010208
10209settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10210 Set option or local variable {varname} in window {winnr} to
10211 {val}.
10212 Tabs are numbered starting with one. For the current tabpage
10213 use |setwinvar()|.
10214 {winnr} can be the window number or the |window-ID|.
10215 When {winnr} is zero the current window is used.
10216 Note that autocommands are blocked, side effects may not be
10217 triggered, e.g. when setting 'filetype' or 'syntax'.
10218 This also works for a global or local buffer option, but it
10219 doesn't work for a global or local buffer variable.
10220 For a local buffer option the global value is unchanged.
10221 Note that the variable name without "w:" must be used.
10222 Examples: >
10223 :call settabwinvar(1, 1, "&list", 0)
10224 :call settabwinvar(3, 2, "myvar", "foobar")
10225< This function is not available in the |sandbox|.
10226
10227 Can also be used as a |method|, the base is passed as the
10228 fourth argument: >
10229 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010230<
10231 Return type: |Number|
10232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010233
10234settagstack({nr}, {dict} [, {action}]) *settagstack()*
10235 Modify the tag stack of the window {nr} using {dict}.
10236 {nr} can be the window number or the |window-ID|.
10237
10238 For a list of supported items in {dict}, refer to
10239 |gettagstack()|. "curidx" takes effect before changing the tag
10240 stack.
10241 *E962*
10242 How the tag stack is modified depends on the {action}
10243 argument:
10244 - If {action} is not present or is set to 'r', then the tag
10245 stack is replaced.
10246 - If {action} is set to 'a', then new entries from {dict} are
10247 pushed (added) onto the tag stack.
10248 - If {action} is set to 't', then all the entries from the
10249 current entry in the tag stack or "curidx" in {dict} are
10250 removed and then new entries are pushed to the stack.
10251
10252 The current index is set to one after the length of the tag
10253 stack after the modification.
10254
10255 Returns zero for success, -1 for failure.
10256
10257 Examples (for more examples see |tagstack-examples|):
10258 Empty the tag stack of window 3: >
10259 call settagstack(3, {'items' : []})
10260
10261< Save and restore the tag stack: >
10262 let stack = gettagstack(1003)
10263 " do something else
10264 call settagstack(1003, stack)
10265 unlet stack
10266<
10267 Can also be used as a |method|, the base is passed as the
10268 second argument: >
10269 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010270<
10271 Return type: |Number|
10272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010273
10274setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10275 Like |settabwinvar()| for the current tab page.
10276 Examples: >
10277 :call setwinvar(1, "&list", 0)
10278 :call setwinvar(2, "myvar", "foobar")
10279
10280< Can also be used as a |method|, the base is passed as the
10281 third argument: >
10282 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010283<
10284 Return type: |Number|
10285
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010286
10287sha256({string}) *sha256()*
10288 Returns a String with 64 hex characters, which is the SHA256
10289 checksum of {string}.
10290
10291 Can also be used as a |method|: >
10292 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010293<
10294 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010295
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010296 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010297
10298shellescape({string} [, {special}]) *shellescape()*
10299 Escape {string} for use as a shell command argument.
10300 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010301 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010302 in single quotes and will double up all internal single
10303 quotes.
10304 On MS-Windows, when 'shellslash' is not set, it will enclose
10305 {string} in double quotes and double all double quotes within
10306 {string}.
10307 Otherwise it will enclose {string} in single quotes and
10308 replace all "'" with "'\''".
10309
Enno5faeb602024-05-15 21:54:19 +020010310 The {special} argument adds additional escaping of keywords
10311 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010312 number or a non-empty String (|non-zero-arg|), then special
10313 items such as "!", "%", "#" and "<cword>" (as listed in
10314 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010315 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010316
10317 The "!" character will be escaped (again with a |non-zero-arg|
10318 {special}) when 'shell' contains "csh" in the tail. That is
10319 because for csh and tcsh "!" is used for history replacement
10320 even when inside single quotes.
10321
10322 With a |non-zero-arg| {special} the <NL> character is also
10323 escaped. When 'shell' containing "csh" in the tail it's
10324 escaped a second time.
10325
10326 The "\" character will be escaped when 'shell' contains "fish"
10327 in the tail. That is because for fish "\" is used as an escape
10328 character inside single quotes.
10329
10330 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010331 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010332< This results in a directory listing for the file under the
10333 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010334 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010335< See also |::S|.
10336
10337 Can also be used as a |method|: >
10338 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010339<
10340 Return type: |String|
10341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010342
10343shiftwidth([{col}]) *shiftwidth()*
10344 Returns the effective value of 'shiftwidth'. This is the
10345 'shiftwidth' value unless it is zero, in which case it is the
10346 'tabstop' value. This function was introduced with patch
10347 7.3.694 in 2012, everybody should have it by now (however it
10348 did not allow for the optional {col} argument until 8.1.542).
10349
10350 When there is one argument {col} this is used as column number
10351 for which to return the 'shiftwidth' value. This matters for the
10352 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10353 no {col} argument is given, column 1 will be assumed.
10354
10355 Can also be used as a |method|: >
10356 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010357<
10358 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010359
10360sign_ functions are documented here: |sign-functions-details|
10361
10362
10363simplify({filename}) *simplify()*
10364 Simplify the file name as much as possible without changing
10365 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10366 Unix) are not resolved. If the first path component in
10367 {filename} designates the current directory, this will be
10368 valid for the result as well. A trailing path separator is
10369 not removed either. On Unix "//path" is unchanged, but
10370 "///path" is simplified to "/path" (this follows the Posix
10371 standard).
10372 Example: >
10373 simplify("./dir/.././/file/") == "./file/"
10374< Note: The combination "dir/.." is only removed if "dir" is
10375 a searchable directory or does not exist. On Unix, it is also
10376 removed when "dir" is a symbolic link within the same
10377 directory. In order to resolve all the involved symbolic
10378 links before simplifying the path name, use |resolve()|.
10379
10380 Can also be used as a |method|: >
10381 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010382<
10383 Return type: |String|
10384
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010385
10386sin({expr}) *sin()*
10387 Return the sine of {expr}, measured in radians, as a |Float|.
10388 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010389 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010390 Examples: >
10391 :echo sin(100)
10392< -0.506366 >
10393 :echo sin(-4.01)
10394< 0.763301
10395
10396 Can also be used as a |method|: >
10397 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010398<
10399 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010400
10401
10402sinh({expr}) *sinh()*
10403 Return the hyperbolic sine of {expr} as a |Float| in the range
10404 [-inf, inf].
10405 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010406 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010407 Examples: >
10408 :echo sinh(0.5)
10409< 0.521095 >
10410 :echo sinh(-0.9)
10411< -1.026517
10412
10413 Can also be used as a |method|: >
10414 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010415<
10416 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010417
10418
10419slice({expr}, {start} [, {end}]) *slice()*
10420 Similar to using a |slice| "expr[start : end]", but "end" is
10421 used exclusive. And for a string the indexes are used as
10422 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010423 |vim9script|. Also, composing characters are treated as a
10424 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010425 When {end} is omitted the slice continues to the last item.
10426 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010427 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010428
10429 Can also be used as a |method|: >
10430 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010431<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010432 Return type: list<{type}> or tuple<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010433
10434
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010435sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010436 Sort the items in {list} in-place. Returns {list}.
10437
10438 If you want a list to remain unmodified make a copy first: >
10439 :let sortedlist = sort(copy(mylist))
10440
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010441< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010442 string representation of each item to sort on. Numbers sort
10443 after Strings, |Lists| after Numbers. For sorting text in the
10444 current buffer use |:sort|.
10445
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010446 When {how} is given and it is 'i' then case is ignored.
10447 In legacy script, for backwards compatibility, the value one
10448 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010449
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010450 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010451 locale is used for ordering. Implementation details: strcoll()
10452 is used to compare strings. See |:language| check or set the
10453 collation locale. |v:collate| can also be used to check the
10454 current locale. Sorting using the locale typically ignores
10455 case. Example: >
10456 " ö is sorted similarly to o with English locale.
10457 :language collate en_US.UTF8
10458 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10459< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10460>
10461 " ö is sorted after z with Swedish locale.
10462 :language collate sv_SE.UTF8
10463 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10464< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10465 This does not work properly on Mac.
10466
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010467 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010468 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010469 strtod() function to parse numbers. Strings, Lists, Dicts and
10470 Funcrefs will be considered as being 0). Note that this won't
10471 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010472
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010473 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010474 sorted numerical. This is like 'n' but a string containing
10475 digits will be used as the number they represent.
10476
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010477 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010478 sorted numerical. All values must be a Number or a Float.
10479
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010480 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010481 is called to compare items. The function is invoked with two
10482 items as argument and must return zero if they are equal, 1 or
10483 bigger if the first one sorts after the second one, -1 or
10484 smaller if the first one sorts before the second one.
10485
10486 {dict} is for functions with the "dict" attribute. It will be
10487 used to set the local variable "self". |Dictionary-function|
10488
10489 The sort is stable, items which compare equal (as number or as
10490 string) will keep their relative position. E.g., when sorting
10491 on numbers, text strings will sort next to each other, in the
10492 same order as they were originally.
10493
10494 Can also be used as a |method|: >
10495 mylist->sort()
10496
10497< Also see |uniq()|.
10498
10499 Example: >
10500 func MyCompare(i1, i2)
10501 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10502 endfunc
10503 eval mylist->sort("MyCompare")
10504< A shorter compare version for this specific simple case, which
10505 ignores overflow: >
10506 func MyCompare(i1, i2)
10507 return a:i1 - a:i2
10508 endfunc
10509< For a simple expression you can use a lambda: >
10510 eval mylist->sort({i1, i2 -> i1 - i2})
10511<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010512 Return type: list<{type}>
10513
10514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010515sound_clear() *sound_clear()*
10516 Stop playing all sounds.
10517
10518 On some Linux systems you may need the libcanberra-pulse
10519 package, otherwise sound may not stop.
10520
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010521 Return type: |Number|
10522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010523 {only available when compiled with the |+sound| feature}
10524
10525 *sound_playevent()*
10526sound_playevent({name} [, {callback}])
10527 Play a sound identified by {name}. Which event names are
10528 supported depends on the system. Often the XDG sound names
10529 are used. On Ubuntu they may be found in
10530 /usr/share/sounds/freedesktop/stereo. Example: >
10531 call sound_playevent('bell')
10532< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10533 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10534 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010535 On macOS, {name} refers to files located in
10536 /System/Library/Sounds (e.g. "Tink"). It will also work for
10537 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010538
10539 When {callback} is specified it is invoked when the sound is
10540 finished. The first argument is the sound ID, the second
10541 argument is the status:
10542 0 sound was played to the end
10543 1 sound was interrupted
10544 2 error occurred after sound started
10545 Example: >
10546 func Callback(id, status)
10547 echomsg "sound " .. a:id .. " finished with " .. a:status
10548 endfunc
10549 call sound_playevent('bell', 'Callback')
10550
10551< MS-Windows: {callback} doesn't work for this function.
10552
10553 Returns the sound ID, which can be passed to `sound_stop()`.
10554 Returns zero if the sound could not be played.
10555
10556 Can also be used as a |method|: >
10557 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010558<
10559 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010560
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010561 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010562
10563 *sound_playfile()*
10564sound_playfile({path} [, {callback}])
10565 Like `sound_playevent()` but play sound file {path}. {path}
10566 must be a full path. On Ubuntu you may find files to play
10567 with this command: >
10568 :!find /usr/share/sounds -type f | grep -v index.theme
10569
10570< Can also be used as a |method|: >
10571 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010572<
10573 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010574
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010575 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010576
10577
10578sound_stop({id}) *sound_stop()*
10579 Stop playing sound {id}. {id} must be previously returned by
10580 `sound_playevent()` or `sound_playfile()`.
10581
10582 On some Linux systems you may need the libcanberra-pulse
10583 package, otherwise sound may not stop.
10584
10585 On MS-Windows, this does not work for event sound started by
10586 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10587
10588 Can also be used as a |method|: >
10589 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010590<
10591 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010592
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010593 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010594
10595 *soundfold()*
10596soundfold({word})
10597 Return the sound-folded equivalent of {word}. Uses the first
10598 language in 'spelllang' for the current window that supports
10599 soundfolding. 'spell' must be set. When no sound folding is
10600 possible the {word} is returned unmodified.
10601 This can be used for making spelling suggestions. Note that
10602 the method can be quite slow.
10603
10604 Can also be used as a |method|: >
10605 GetWord()->soundfold()
10606<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010607 Return type: |String|
10608
10609
10610spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010611 Without argument: The result is the badly spelled word under
10612 or after the cursor. The cursor is moved to the start of the
10613 bad word. When no bad word is found in the cursor line the
10614 result is an empty string and the cursor doesn't move.
10615
10616 With argument: The result is the first word in {sentence} that
10617 is badly spelled. If there are no spelling mistakes the
10618 result is an empty string.
10619
10620 The return value is a list with two items:
10621 - The badly spelled word or an empty string.
10622 - The type of the spelling error:
10623 "bad" spelling mistake
10624 "rare" rare word
10625 "local" word only valid in another region
10626 "caps" word should start with Capital
10627 Example: >
10628 echo spellbadword("the quik brown fox")
10629< ['quik', 'bad'] ~
10630
10631 The spelling information for the current window and the value
10632 of 'spelllang' are used.
10633
10634 Can also be used as a |method|: >
10635 GetText()->spellbadword()
10636<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010637 Return type: list<string>
10638
10639
10640spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010641 Return a |List| with spelling suggestions to replace {word}.
10642 When {max} is given up to this number of suggestions are
10643 returned. Otherwise up to 25 suggestions are returned.
10644
10645 When the {capital} argument is given and it's non-zero only
10646 suggestions with a leading capital will be given. Use this
10647 after a match with 'spellcapcheck'.
10648
10649 {word} can be a badly spelled word followed by other text.
10650 This allows for joining two words that were split. The
10651 suggestions also include the following text, thus you can
10652 replace a line.
10653
10654 {word} may also be a good word. Similar words will then be
10655 returned. {word} itself is not included in the suggestions,
10656 although it may appear capitalized.
10657
10658 The spelling information for the current window is used. The
10659 values of 'spelllang' and 'spellsuggest' are used.
10660
10661 Can also be used as a |method|: >
10662 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010663<
10664 Return type: list<string> or list<any>
10665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010666
10667split({string} [, {pattern} [, {keepempty}]]) *split()*
10668 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010669 empty each white space separated sequence of characters
10670 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010671 Otherwise the string is split where {pattern} matches,
10672 removing the matched characters. 'ignorecase' is not used
10673 here, add \c to ignore case. |/\c|
10674 When the first or last item is empty it is omitted, unless the
10675 {keepempty} argument is given and it's non-zero.
10676 Other empty items are kept when {pattern} matches at least one
10677 character or when {keepempty} is non-zero.
10678 Example: >
10679 :let words = split(getline('.'), '\W\+')
10680< To split a string in individual characters: >
10681 :for c in split(mystring, '\zs')
10682< If you want to keep the separator you can also use '\zs' at
10683 the end of the pattern: >
10684 :echo split('abc:def:ghi', ':\zs')
10685< ['abc:', 'def:', 'ghi'] ~
10686 Splitting a table where the first element can be empty: >
10687 :let items = split(line, ':', 1)
10688< The opposite function is |join()|.
10689
10690 Can also be used as a |method|: >
10691 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010692<
10693 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010694
10695sqrt({expr}) *sqrt()*
10696 Return the non-negative square root of Float {expr} as a
10697 |Float|.
10698 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010699 is negative the result is NaN (Not a Number). Returns 0.0 if
10700 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010701 Examples: >
10702 :echo sqrt(100)
10703< 10.0 >
10704 :echo sqrt(-4.01)
10705< nan
10706 "nan" may be different, it depends on system libraries.
10707
10708 Can also be used as a |method|: >
10709 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010710<
10711 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010712
10713
10714srand([{expr}]) *srand()*
10715 Initialize seed used by |rand()|:
10716 - If {expr} is not given, seed values are initialized by
10717 reading from /dev/urandom, if possible, or using time(NULL)
10718 a.k.a. epoch time otherwise; this only has second accuracy.
10719 - If {expr} is given it must be a Number. It is used to
10720 initialize the seed values. This is useful for testing or
10721 when a predictable sequence is intended.
10722
10723 Examples: >
10724 :let seed = srand()
10725 :let seed = srand(userinput)
10726 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010727<
10728 Return type: list<number>
10729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010730
10731state([{what}]) *state()*
10732 Return a string which contains characters indicating the
10733 current state. Mostly useful in callbacks that want to do
10734 work that may not always be safe. Roughly this works like:
10735 - callback uses state() to check if work is safe to do.
10736 Yes: then do it right away.
10737 No: add to work queue and add a |SafeState| and/or
10738 |SafeStateAgain| autocommand (|SafeState| triggers at
10739 toplevel, |SafeStateAgain| triggers after handling
10740 messages and callbacks).
10741 - When SafeState or SafeStateAgain is triggered and executes
10742 your autocommand, check with `state()` if the work can be
10743 done now, and if yes remove it from the queue and execute.
10744 Remove the autocommand if the queue is now empty.
10745 Also see |mode()|.
10746
10747 When {what} is given only characters in this string will be
10748 added. E.g, this checks if the screen has scrolled: >
10749 if state('s') == ''
10750 " screen has not scrolled
10751<
10752 These characters indicate the state, generally indicating that
10753 something is busy:
10754 m halfway a mapping, :normal command, feedkeys() or
10755 stuffed command
10756 o operator pending, e.g. after |d|
10757 a Insert mode autocomplete active
10758 x executing an autocommand
10759 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10760 ch_readraw() when reading json
10761 S not triggering SafeState or SafeStateAgain, e.g. after
10762 |f| or a count
10763 c callback invoked, including timer (repeats for
10764 recursiveness up to "ccc")
10765 s screen has scrolled for messages
10766
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010767 Return type: |String|
10768
10769
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010770str2blob({list} [, {options}]) *str2blob()*
10771 Return a Blob by converting the characters in the List of
10772 strings in {list} into bytes.
10773
10774 A <NL> byte is added to the blob after each list item. A
10775 newline character in the string is translated into a <NUL>
10776 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010777
10778 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010779 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010780
10781 The argument {options} is a |Dict| and supports the following
10782 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010783 encoding Convert the characters using this encoding
10784 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010785 The value is a |String|. See |encoding-names|
10786 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010787
10788 An error is given and an empty blob is returned if the
10789 character encoding fails.
10790
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010791 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010792
10793 See also |blob2str()|
10794
10795 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010796 str2blob(["ab"]) returns 0z6162
10797 str2blob(["«»"]) returns 0zC2ABC2BB
10798 str2blob(["a\nb"]) returns 0z610062
10799 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010800 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010801 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010802<
10803 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010804 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010805<
10806 Return type: |Blob|
10807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010808str2float({string} [, {quoted}]) *str2float()*
10809 Convert String {string} to a Float. This mostly works the
10810 same as when using a floating point number in an expression,
10811 see |floating-point-format|. But it's a bit more permissive.
10812 E.g., "1e40" is accepted, while in an expression you need to
10813 write "1.0e40". The hexadecimal form "0x123" is also
10814 accepted, but not others, like binary or octal.
10815 When {quoted} is present and non-zero then embedded single
10816 quotes before the dot are ignored, thus "1'000.0" is a
10817 thousand.
10818 Text after the number is silently ignored.
10819 The decimal point is always '.', no matter what the locale is
10820 set to. A comma ends the number: "12,345.67" is converted to
10821 12.0. You can strip out thousands separators with
10822 |substitute()|: >
10823 let f = str2float(substitute(text, ',', '', 'g'))
10824<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010825 Returns 0.0 if the conversion fails.
10826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010827 Can also be used as a |method|: >
10828 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010829<
10830 Return type: |Float|
10831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010832
10833str2list({string} [, {utf8}]) *str2list()*
10834 Return a list containing the number values which represent
10835 each character in String {string}. Examples: >
10836 str2list(" ") returns [32]
10837 str2list("ABC") returns [65, 66, 67]
10838< |list2str()| does the opposite.
10839
10840 When {utf8} is omitted or zero, the current 'encoding' is used.
10841 When {utf8} is TRUE, always treat the String as UTF-8
10842 characters. With UTF-8 composing characters are handled
10843 properly: >
10844 str2list("á") returns [97, 769]
10845
10846< Can also be used as a |method|: >
10847 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010848<
10849 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010850
10851
10852str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10853 Convert string {string} to a number.
10854 {base} is the conversion base, it can be 2, 8, 10 or 16.
10855 When {quoted} is present and non-zero then embedded single
10856 quotes are ignored, thus "1'000'000" is a million.
10857
10858 When {base} is omitted base 10 is used. This also means that
10859 a leading zero doesn't cause octal conversion to be used, as
10860 with the default String to Number conversion. Example: >
10861 let nr = str2nr('0123')
10862<
10863 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10864 different base the result will be zero. Similarly, when
10865 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10866 {base} is 2 a leading "0b" or "0B" is ignored.
10867 Text after the number is silently ignored.
10868
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010869 Returns 0 if {string} is empty or on error.
10870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010871 Can also be used as a |method|: >
10872 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010873<
10874 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010875
10876
10877strcharlen({string}) *strcharlen()*
10878 The result is a Number, which is the number of characters
10879 in String {string}. Composing characters are ignored.
10880 |strchars()| can count the number of characters, counting
10881 composing characters separately.
10882
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010883 Returns 0 if {string} is empty or on error.
10884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010885 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10886
10887 Can also be used as a |method|: >
10888 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010889<
10890 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010891
10892
10893strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10894 Like |strpart()| but using character index and length instead
10895 of byte index and length.
10896 When {skipcc} is omitted or zero, composing characters are
10897 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010898 When {skipcc} set to 1, composing characters are treated as a
10899 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010900 When a character index is used where a character does not
10901 exist it is omitted and counted as one character. For
10902 example: >
10903 strcharpart('abc', -1, 2)
10904< results in 'a'.
10905
Bram Moolenaard592deb2022-06-17 15:42:40 +010010906 Returns an empty string on error.
10907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010908 Can also be used as a |method|: >
10909 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010910<
10911 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010912
10913
10914strchars({string} [, {skipcc}]) *strchars()*
10915 The result is a Number, which is the number of characters
10916 in String {string}.
10917 When {skipcc} is omitted or zero, composing characters are
10918 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010919 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010920 |strcharlen()| always does this.
10921
Bram Moolenaard592deb2022-06-17 15:42:40 +010010922 Returns zero on error.
10923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010924 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10925
10926 {skipcc} is only available after 7.4.755. For backward
10927 compatibility, you can define a wrapper function: >
10928 if has("patch-7.4.755")
10929 function s:strchars(str, skipcc)
10930 return strchars(a:str, a:skipcc)
10931 endfunction
10932 else
10933 function s:strchars(str, skipcc)
10934 if a:skipcc
10935 return strlen(substitute(a:str, ".", "x", "g"))
10936 else
10937 return strchars(a:str)
10938 endif
10939 endfunction
10940 endif
10941<
10942 Can also be used as a |method|: >
10943 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010944<
10945 Return type: |Number|
10946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010947
10948strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10949 The result is a Number, which is the number of display cells
10950 String {string} occupies on the screen when it starts at {col}
10951 (first column is zero). When {col} is omitted zero is used.
10952 Otherwise it is the screen column where to start. This
10953 matters for Tab characters.
10954 The option settings of the current window are used. This
10955 matters for anything that's displayed differently, such as
10956 'tabstop' and 'display'.
10957 When {string} contains characters with East Asian Width Class
10958 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010959 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010960 Also see |strlen()|, |strwidth()| and |strchars()|.
10961
10962 Can also be used as a |method|: >
10963 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010964<
10965 Return type: |Number|
10966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010967
10968strftime({format} [, {time}]) *strftime()*
10969 The result is a String, which is a formatted date and time, as
10970 specified by the {format} string. The given {time} is used,
10971 or the current time if no time is given. The accepted
10972 {format} depends on your system, thus this is not portable!
10973 See the manual page of the C function strftime() for the
10974 format. The maximum length of the result is 80 characters.
10975 See also |localtime()|, |getftime()| and |strptime()|.
10976 The language can be changed with the |:language| command.
10977 Examples: >
10978 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10979 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10980 :echo strftime("%y%m%d %T") 970427 11:53:55
10981 :echo strftime("%H:%M") 11:55
10982 :echo strftime("%c", getftime("file.c"))
10983 Show mod time of file.c.
10984< Not available on all systems. To check use: >
10985 :if exists("*strftime")
10986
10987< Can also be used as a |method|: >
10988 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010989<
10990 Return type: |String|
10991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010992
10993strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010994 Get a Number corresponding to the character at {index} in
10995 {str}. This uses a zero-based character index, not a byte
10996 index. Composing characters are considered separate
10997 characters here. Use |nr2char()| to convert the Number to a
10998 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010999 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011000 Also see |strcharpart()| and |strchars()|.
11001
11002 Can also be used as a |method|: >
11003 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011004<
11005 Return type: |Number|
11006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011007
11008stridx({haystack}, {needle} [, {start}]) *stridx()*
11009 The result is a Number, which gives the byte index in
11010 {haystack} of the first occurrence of the String {needle}.
11011 If {start} is specified, the search starts at index {start}.
11012 This can be used to find a second match: >
11013 :let colon1 = stridx(line, ":")
11014 :let colon2 = stridx(line, ":", colon1 + 1)
11015< The search is done case-sensitive.
11016 For pattern searches use |match()|.
11017 -1 is returned if the {needle} does not occur in {haystack}.
11018 See also |strridx()|.
11019 Examples: >
11020 :echo stridx("An Example", "Example") 3
11021 :echo stridx("Starting point", "Start") 0
11022 :echo stridx("Starting point", "start") -1
11023< *strstr()* *strchr()*
11024 stridx() works similar to the C function strstr(). When used
11025 with a single character it works similar to strchr().
11026
11027 Can also be used as a |method|: >
11028 GetHaystack()->stridx(needle)
11029<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011030 Return type: |Number|
11031
11032
11033string({expr}) *string()*
11034 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011035 Float, String, Blob or a composition of them, then the result
11036 can be parsed back with |eval()|.
11037 {expr} type result ~
11038 String 'string' (single quotes are doubled)
11039 Number 123
11040 Float 123.123456 or 1.123456e8
11041 Funcref function('name')
11042 Blob 0z00112233.44556677.8899
11043 List [item, item]
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011044 Tuple (item, item)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011045 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000011046 Class class SomeName
11047 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011048 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020011049 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011050
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011051 When a |List|, |Tuple| or |Dictionary| has a recursive
11052 reference it is replaced by "[...]" or "(...)" or "{...}".
11053 Using eval() on the result will then fail.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011054
mityu7f0bba22024-03-29 10:14:41 +010011055 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011056 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010011057 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011059 Can also be used as a |method|: >
11060 mylist->string()
11061
11062< Also see |strtrans()|.
11063
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011064 Return type: |String|
11065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011066
11067strlen({string}) *strlen()*
11068 The result is a Number, which is the length of the String
11069 {string} in bytes.
11070 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011071 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011072 If you want to count the number of multibyte characters use
11073 |strchars()|.
11074 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
11075
11076 Can also be used as a |method|: >
11077 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011078<
11079 Return type: |Number|
11080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011081
11082strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
11083 The result is a String, which is part of {src}, starting from
11084 byte {start}, with the byte length {len}.
11085 When {chars} is present and TRUE then {len} is the number of
11086 characters positions (composing characters are not counted
11087 separately, thus "1" means one base character and any
11088 following composing characters).
11089 To count {start} as characters instead of bytes use
11090 |strcharpart()|.
11091
11092 When bytes are selected which do not exist, this doesn't
11093 result in an error, the bytes are simply omitted.
11094 If {len} is missing, the copy continues from {start} till the
11095 end of the {src}. >
11096 strpart("abcdefg", 3, 2) == "de"
11097 strpart("abcdefg", -2, 4) == "ab"
11098 strpart("abcdefg", 5, 4) == "fg"
11099 strpart("abcdefg", 3) == "defg"
11100
11101< Note: To get the first character, {start} must be 0. For
11102 example, to get the character under the cursor: >
11103 strpart(getline("."), col(".") - 1, 1, v:true)
11104<
Bram Moolenaard592deb2022-06-17 15:42:40 +010011105 Returns an empty string on error.
11106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011107 Can also be used as a |method|: >
11108 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011109<
11110 Return type: |String|
11111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011112
11113strptime({format}, {timestring}) *strptime()*
11114 The result is a Number, which is a unix timestamp representing
11115 the date and time in {timestring}, which is expected to match
11116 the format specified in {format}.
11117
11118 The accepted {format} depends on your system, thus this is not
11119 portable! See the manual page of the C function strptime()
11120 for the format. Especially avoid "%c". The value of $TZ also
11121 matters.
11122
11123 If the {timestring} cannot be parsed with {format} zero is
11124 returned. If you do not know the format of {timestring} you
11125 can try different {format} values until you get a non-zero
11126 result.
11127
11128 See also |strftime()|.
11129 Examples: >
11130 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11131< 862156163 >
11132 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11133< Sun Apr 27 11:53:55 1997 >
11134 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11135< Sun Apr 27 12:53:55 1997
11136
11137 Can also be used as a |method|: >
11138 GetFormat()->strptime(timestring)
11139<
11140 Not available on all systems. To check use: >
11141 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011142<
11143 Return type: |Number|
11144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011145
11146strridx({haystack}, {needle} [, {start}]) *strridx()*
11147 The result is a Number, which gives the byte index in
11148 {haystack} of the last occurrence of the String {needle}.
11149 When {start} is specified, matches beyond this index are
11150 ignored. This can be used to find a match before a previous
11151 match: >
11152 :let lastcomma = strridx(line, ",")
11153 :let comma2 = strridx(line, ",", lastcomma - 1)
11154< The search is done case-sensitive.
11155 For pattern searches use |match()|.
11156 -1 is returned if the {needle} does not occur in {haystack}.
11157 If the {needle} is empty the length of {haystack} is returned.
11158 See also |stridx()|. Examples: >
11159 :echo strridx("an angry armadillo", "an") 3
11160< *strrchr()*
11161 When used with a single character it works similar to the C
11162 function strrchr().
11163
11164 Can also be used as a |method|: >
11165 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011166<
11167 Return type: |Number|
11168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011169
11170strtrans({string}) *strtrans()*
11171 The result is a String, which is {string} with all unprintable
11172 characters translated into printable characters |'isprint'|.
11173 Like they are shown in a window. Example: >
11174 echo strtrans(@a)
11175< This displays a newline in register a as "^@" instead of
11176 starting a new line.
11177
Bram Moolenaard592deb2022-06-17 15:42:40 +010011178 Returns an empty string on error.
11179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011180 Can also be used as a |method|: >
11181 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011182<
11183 Return type: |String|
11184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011185
Christian Brabandt67672ef2023-04-24 21:09:54 +010011186strutf16len({string} [, {countcc}]) *strutf16len()*
11187 The result is a Number, which is the number of UTF-16 code
11188 units in String {string} (after converting it to UTF-16).
11189
11190 When {countcc} is TRUE, composing characters are counted
11191 separately.
11192 When {countcc} is omitted or FALSE, composing characters are
11193 ignored.
11194
11195 Returns zero on error.
11196
11197 Also see |strlen()| and |strcharlen()|.
11198 Examples: >
11199 echo strutf16len('a') returns 1
11200 echo strutf16len('©') returns 1
11201 echo strutf16len('😊') returns 2
11202 echo strutf16len('ą́') returns 1
11203 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011204<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011205 Can also be used as a |method|: >
11206 GetText()->strutf16len()
11207<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011208 Return type: |Number|
11209
11210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011211strwidth({string}) *strwidth()*
11212 The result is a Number, which is the number of display cells
11213 String {string} occupies. A Tab character is counted as one
11214 cell, alternatively use |strdisplaywidth()|.
11215 When {string} contains characters with East Asian Width Class
11216 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011217 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011218 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11219
11220 Can also be used as a |method|: >
11221 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011222<
11223 Return type: |Number|
11224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011225
11226submatch({nr} [, {list}]) *submatch()* *E935*
11227 Only for an expression in a |:substitute| command or
11228 substitute() function.
11229 Returns the {nr}'th submatch of the matched text. When {nr}
11230 is 0 the whole matched text is returned.
11231 Note that a NL in the string can stand for a line break of a
11232 multi-line match or a NUL character in the text.
11233 Also see |sub-replace-expression|.
11234
11235 If {list} is present and non-zero then submatch() returns
11236 a list of strings, similar to |getline()| with two arguments.
11237 NL characters in the text represent NUL characters in the
11238 text.
11239 Only returns more than one item for |:substitute|, inside
11240 |substitute()| this list will always contain one or zero
11241 items, since there are no real line breaks.
11242
11243 When substitute() is used recursively only the submatches in
11244 the current (deepest) call can be obtained.
11245
Bram Moolenaard592deb2022-06-17 15:42:40 +010011246 Returns an empty string or list on error.
11247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011248 Examples: >
11249 :s/\d\+/\=submatch(0) + 1/
11250 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11251< This finds the first number in the line and adds one to it.
11252 A line break is included as a newline character.
11253
11254 Can also be used as a |method|: >
11255 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011256<
11257 Return type: |String| or list<string> depending on {list}
11258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011259
11260substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11261 The result is a String, which is a copy of {string}, in which
11262 the first match of {pat} is replaced with {sub}.
11263 When {flags} is "g", all matches of {pat} in {string} are
11264 replaced. Otherwise {flags} should be "".
11265
11266 This works like the ":substitute" command (without any flags).
11267 But the matching with {pat} is always done like the 'magic'
11268 option is set and 'cpoptions' is empty (to make scripts
11269 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11270 if you want to ignore or match case and ignore 'ignorecase'.
11271 'smartcase' is not used. See |string-match| for how {pat} is
11272 used.
11273
11274 A "~" in {sub} is not replaced with the previous {sub}.
11275 Note that some codes in {sub} have a special meaning
11276 |sub-replace-special|. For example, to replace something with
11277 "\n" (two characters), use "\\\\n" or '\\n'.
11278
11279 When {pat} does not match in {string}, {string} is returned
11280 unmodified.
11281
11282 Example: >
11283 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11284< This removes the last component of the 'path' option. >
11285 :echo substitute("testing", ".*", "\\U\\0", "")
11286< results in "TESTING".
11287
11288 When {sub} starts with "\=", the remainder is interpreted as
11289 an expression. See |sub-replace-expression|. Example: >
11290 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011291 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011292
11293< When {sub} is a Funcref that function is called, with one
11294 optional argument. Example: >
11295 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11296< The optional argument is a list which contains the whole
11297 matched string and up to nine submatches, like what
11298 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011299 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011300
Bram Moolenaard592deb2022-06-17 15:42:40 +010011301< Returns an empty string on error.
11302
11303 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011304 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011305<
11306 Return type: |String|
11307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011308
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011309swapfilelist() *swapfilelist()*
11310 Returns a list of swap file names, like what "vim -r" shows.
11311 See the |-r| command argument. The 'directory' option is used
11312 for the directories to inspect. If you only want to get a
11313 list of swap files in the current directory then temporarily
11314 set 'directory' to a dot: >
11315 let save_dir = &directory
11316 let &directory = '.'
11317 let swapfiles = swapfilelist()
11318 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011319<
11320 Return type: list<string>
11321
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011323swapinfo({fname}) *swapinfo()*
11324 The result is a dictionary, which holds information about the
11325 swapfile {fname}. The available fields are:
11326 version Vim version
11327 user user name
11328 host host name
11329 fname original file name
11330 pid PID of the Vim process that created the swap
11331 file
11332 mtime last modification time in seconds
11333 inode Optional: INODE number of the file
11334 dirty 1 if file was modified, 0 if not
11335 Note that "user" and "host" are truncated to at most 39 bytes.
11336 In case of failure an "error" item is added with the reason:
11337 Cannot open file: file not found or in accessible
11338 Cannot read file: cannot read first block
11339 Not a swap file: does not contain correct block ID
11340 Magic number mismatch: Info in first block is invalid
11341
11342 Can also be used as a |method|: >
11343 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011344<
11345 Return type: dict<any> or dict<string>
11346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011347
11348swapname({buf}) *swapname()*
11349 The result is the swap file path of the buffer {expr}.
11350 For the use of {buf}, see |bufname()| above.
11351 If buffer {buf} is the current buffer, the result is equal to
11352 |:swapname| (unless there is no swap file).
11353 If buffer {buf} has no swap file, returns an empty string.
11354
11355 Can also be used as a |method|: >
11356 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011357<
11358 Return type: |String|
11359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011360
11361synID({lnum}, {col}, {trans}) *synID()*
11362 The result is a Number, which is the syntax ID at the position
11363 {lnum} and {col} in the current window.
11364 The syntax ID can be used with |synIDattr()| and
11365 |synIDtrans()| to obtain syntax information about text.
11366
11367 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11368 line. 'synmaxcol' applies, in a longer line zero is returned.
11369 Note that when the position is after the last character,
11370 that's where the cursor can be in Insert mode, synID() returns
11371 zero. {lnum} is used like with |getline()|.
11372
11373 When {trans} is |TRUE|, transparent items are reduced to the
11374 item that they reveal. This is useful when wanting to know
11375 the effective color. When {trans} is |FALSE|, the transparent
11376 item is returned. This is useful when wanting to know which
11377 syntax item is effective (e.g. inside parens).
11378 Warning: This function can be very slow. Best speed is
11379 obtained by going through the file in forward direction.
11380
Bram Moolenaard592deb2022-06-17 15:42:40 +010011381 Returns zero on error.
11382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011383 Example (echoes the name of the syntax item under the cursor): >
11384 :echo synIDattr(synID(line("."), col("."), 1), "name")
11385<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011386 Return type: |Number|
11387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011388
11389synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11390 The result is a String, which is the {what} attribute of
11391 syntax ID {synID}. This can be used to obtain information
11392 about a syntax item.
11393 {mode} can be "gui", "cterm" or "term", to get the attributes
11394 for that mode. When {mode} is omitted, or an invalid value is
11395 used, the attributes for the currently active highlighting are
11396 used (GUI, cterm or term).
11397 Use synIDtrans() to follow linked highlight groups.
11398 {what} result
11399 "name" the name of the syntax item
11400 "fg" foreground color (GUI: color name used to set
11401 the color, cterm: color number as a string,
11402 term: empty string)
11403 "bg" background color (as with "fg")
11404 "font" font name (only available in the GUI)
11405 |highlight-font|
11406 "sp" special color for the GUI (as with "fg")
11407 |highlight-guisp|
11408 "ul" underline color for cterm: number as a string
11409 "fg#" like "fg", but for the GUI and the GUI is
11410 running the name in "#RRGGBB" form
11411 "bg#" like "fg#" for "bg"
11412 "sp#" like "fg#" for "sp"
11413 "bold" "1" if bold
11414 "italic" "1" if italic
11415 "reverse" "1" if reverse
11416 "inverse" "1" if inverse (= reverse)
11417 "standout" "1" if standout
11418 "underline" "1" if underlined
11419 "undercurl" "1" if undercurled
11420 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011421 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011422
Bram Moolenaard592deb2022-06-17 15:42:40 +010011423 Returns an empty string on error.
11424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011425 Example (echoes the color of the syntax item under the
11426 cursor): >
11427 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11428<
11429 Can also be used as a |method|: >
11430 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011431<
11432 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011433
11434
11435synIDtrans({synID}) *synIDtrans()*
11436 The result is a Number, which is the translated syntax ID of
11437 {synID}. This is the syntax group ID of what is being used to
11438 highlight the character. Highlight links given with
11439 ":highlight link" are followed.
11440
Bram Moolenaard592deb2022-06-17 15:42:40 +010011441 Returns zero on error.
11442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011443 Can also be used as a |method|: >
11444 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011445<
11446 Return type: |Number|
11447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011448
11449synconcealed({lnum}, {col}) *synconcealed()*
11450 The result is a |List| with currently three items:
11451 1. The first item in the list is 0 if the character at the
11452 position {lnum} and {col} is not part of a concealable
11453 region, 1 if it is. {lnum} is used like with |getline()|.
11454 2. The second item in the list is a string. If the first item
11455 is 1, the second item contains the text which will be
11456 displayed in place of the concealed text, depending on the
11457 current setting of 'conceallevel' and 'listchars'.
11458 3. The third and final item in the list is a number
11459 representing the specific syntax region matched in the
11460 line. When the character is not concealed the value is
11461 zero. This allows detection of the beginning of a new
11462 concealable region if there are two consecutive regions
11463 with the same replacement character. For an example, if
11464 the text is "123456" and both "23" and "45" are concealed
11465 and replaced by the character "X", then:
11466 call returns ~
11467 synconcealed(lnum, 1) [0, '', 0]
11468 synconcealed(lnum, 2) [1, 'X', 1]
11469 synconcealed(lnum, 3) [1, 'X', 1]
11470 synconcealed(lnum, 4) [1, 'X', 2]
11471 synconcealed(lnum, 5) [1, 'X', 2]
11472 synconcealed(lnum, 6) [0, '', 0]
11473
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011474 Note: Doesn't consider |matchadd()| highlighting items,
11475 since syntax and matching highlighting are two different
11476 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011477
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011478 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011480
11481synstack({lnum}, {col}) *synstack()*
11482 Return a |List|, which is the stack of syntax items at the
11483 position {lnum} and {col} in the current window. {lnum} is
11484 used like with |getline()|. Each item in the List is an ID
11485 like what |synID()| returns.
11486 The first item in the List is the outer region, following are
11487 items contained in that one. The last one is what |synID()|
11488 returns, unless not the whole item is highlighted or it is a
11489 transparent item.
11490 This function is useful for debugging a syntax file.
11491 Example that shows the syntax stack under the cursor: >
11492 for id in synstack(line("."), col("."))
11493 echo synIDattr(id, "name")
11494 endfor
11495< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011496 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011497 character in a line and the first column in an empty line are
11498 valid positions.
11499
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011500 Return type: list<number> or list<any>
11501
11502
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011503system({expr} [, {input}]) *system()* *E677*
11504 Get the output of the shell command {expr} as a |String|. See
11505 |systemlist()| to get the output as a |List|.
11506
11507 When {input} is given and is a |String| this string is written
11508 to a file and passed as stdin to the command. The string is
11509 written as-is, you need to take care of using the correct line
11510 separators yourself.
11511 If {input} is given and is a |List| it is written to the file
11512 in a way |writefile()| does with {binary} set to "b" (i.e.
11513 with a newline between each list item with newlines inside
11514 list items converted to NULs).
11515 When {input} is given and is a number that is a valid id for
11516 an existing buffer then the content of the buffer is written
11517 to the file line by line, each line terminated by a NL and
11518 NULs characters where the text has a NL.
11519
11520 Pipes are not used, the 'shelltemp' option is not used.
11521
11522 When prepended by |:silent| the terminal will not be set to
11523 cooked mode. This is meant to be used for commands that do
11524 not need the user to type. It avoids stray characters showing
11525 up on the screen which require |CTRL-L| to remove. >
11526 :silent let f = system('ls *.vim')
11527<
11528 Note: Use |shellescape()| or |::S| with |expand()| or
11529 |fnamemodify()| to escape special characters in a command
11530 argument. Newlines in {expr} may cause the command to fail.
11531 The characters in 'shellquote' and 'shellxquote' may also
11532 cause trouble.
11533 This is not to be used for interactive commands.
11534
11535 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011536 :let files = system('ls ' .. shellescape(expand('%:h')))
11537 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011538
11539< To make the result more system-independent, the shell output
11540 is filtered to replace <CR> with <NL> for Macintosh, and
11541 <CR><NL> with <NL> for DOS-like systems.
11542 To avoid the string being truncated at a NUL, all NUL
11543 characters are replaced with SOH (0x01).
11544
11545 The command executed is constructed using several options:
11546 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11547 ({tmp} is an automatically generated file name).
11548 For Unix, braces are put around {expr} to allow for
11549 concatenated commands.
11550
11551 The command will be executed in "cooked" mode, so that a
11552 CTRL-C will interrupt the command (on Unix at least).
11553
11554 The resulting error code can be found in |v:shell_error|.
11555 This function will fail in |restricted-mode|.
11556
11557 Note that any wrong value in the options mentioned above may
11558 make the function fail. It has also been reported to fail
11559 when using a security agent application.
11560 Unlike ":!cmd" there is no automatic check for changed files.
11561 Use |:checktime| to force a check.
11562
11563 Can also be used as a |method|: >
11564 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011565<
11566 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011567
11568
11569systemlist({expr} [, {input}]) *systemlist()*
11570 Same as |system()|, but returns a |List| with lines (parts of
11571 output separated by NL) with NULs transformed into NLs. Output
11572 is the same as |readfile()| will output with {binary} argument
11573 set to "b", except that there is no extra empty item when the
11574 result ends in a NL.
11575 Note that on MS-Windows you may get trailing CR characters.
11576
11577 To see the difference between "echo hello" and "echo -n hello"
11578 use |system()| and |split()|: >
11579 echo system('echo hello')->split('\n', 1)
11580<
11581 Returns an empty string on error.
11582
11583 Can also be used as a |method|: >
11584 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011585<
11586 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011587
11588
11589tabpagebuflist([{arg}]) *tabpagebuflist()*
11590 The result is a |List|, where each item is the number of the
11591 buffer associated with each window in the current tab page.
11592 {arg} specifies the number of the tab page to be used. When
11593 omitted the current tab page is used.
11594 When {arg} is invalid the number zero is returned.
11595 To get a list of all buffers in all tabs use this: >
11596 let buflist = []
11597 for i in range(tabpagenr('$'))
11598 call extend(buflist, tabpagebuflist(i + 1))
11599 endfor
11600< Note that a buffer may appear in more than one window.
11601
11602 Can also be used as a |method|: >
11603 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011604<
11605 Return type: list<number>
11606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011607
11608tabpagenr([{arg}]) *tabpagenr()*
11609 The result is a Number, which is the number of the current
11610 tab page. The first tab page has number 1.
11611
11612 The optional argument {arg} supports the following values:
11613 $ the number of the last tab page (the tab page
11614 count).
11615 # the number of the last accessed tab page
11616 (where |g<Tab>| goes to). if there is no
11617 previous tab page 0 is returned.
11618 The number can be used with the |:tab| command.
11619
Bram Moolenaard592deb2022-06-17 15:42:40 +010011620 Returns zero on error.
11621
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011622 Return type: |Number|
11623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011624
11625tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11626 Like |winnr()| but for tab page {tabarg}.
11627 {tabarg} specifies the number of tab page to be used.
11628 {arg} is used like with |winnr()|:
11629 - When omitted the current window number is returned. This is
11630 the window which will be used when going to this tab page.
11631 - When "$" the number of windows is returned.
11632 - When "#" the previous window nr is returned.
11633 Useful examples: >
11634 tabpagewinnr(1) " current window of tab page 1
11635 tabpagewinnr(4, '$') " number of windows in tab page 4
11636< When {tabarg} is invalid zero is returned.
11637
11638 Can also be used as a |method|: >
11639 GetTabpage()->tabpagewinnr()
11640<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011641 Return type: |Number|
11642
11643
11644tagfiles() *tagfiles()*
11645 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011646 for the current buffer. This is the 'tags' option expanded.
11647
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011648 Return type: list<string> or list<any>
11649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011650
11651taglist({expr} [, {filename}]) *taglist()*
11652 Returns a |List| of tags matching the regular expression {expr}.
11653
11654 If {filename} is passed it is used to prioritize the results
11655 in the same way that |:tselect| does. See |tag-priority|.
11656 {filename} should be the full path of the file.
11657
11658 Each list item is a dictionary with at least the following
11659 entries:
11660 name Name of the tag.
11661 filename Name of the file where the tag is
11662 defined. It is either relative to the
11663 current directory or a full path.
11664 cmd Ex command used to locate the tag in
11665 the file.
11666 kind Type of the tag. The value for this
11667 entry depends on the language specific
11668 kind values. Only available when
11669 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011670 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011671 static A file specific tag. Refer to
11672 |static-tag| for more information.
11673 More entries may be present, depending on the content of the
11674 tags file: access, implementation, inherits and signature.
11675 Refer to the ctags documentation for information about these
11676 fields. For C code the fields "struct", "class" and "enum"
11677 may appear, they give the name of the entity the tag is
11678 contained in.
11679
11680 The ex-command "cmd" can be either an ex search pattern, a
11681 line number or a line number followed by a byte number.
11682
11683 If there are no matching tags, then an empty list is returned.
11684
11685 To get an exact tag match, the anchors '^' and '$' should be
11686 used in {expr}. This also make the function work faster.
11687 Refer to |tag-regexp| for more information about the tag
11688 search regular expression pattern.
11689
11690 Refer to |'tags'| for information about how the tags file is
11691 located by Vim. Refer to |tags-file-format| for the format of
11692 the tags file generated by the different ctags tools.
11693
11694 Can also be used as a |method|: >
11695 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011696<
11697 Return type: list<dict<any>> or list<any>
11698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011699
11700tan({expr}) *tan()*
11701 Return the tangent of {expr}, measured in radians, as a |Float|
11702 in the range [-inf, inf].
11703 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011704 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011705 Examples: >
11706 :echo tan(10)
11707< 0.648361 >
11708 :echo tan(-4.01)
11709< -1.181502
11710
11711 Can also be used as a |method|: >
11712 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011713<
11714 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011715
11716
11717tanh({expr}) *tanh()*
11718 Return the hyperbolic tangent of {expr} as a |Float| in the
11719 range [-1, 1].
11720 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011721 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011722 Examples: >
11723 :echo tanh(0.5)
11724< 0.462117 >
11725 :echo tanh(-1)
11726< -0.761594
11727
11728 Can also be used as a |method|: >
11729 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011730<
11731 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011732
11733
11734tempname() *tempname()* *temp-file-name*
11735 The result is a String, which is the name of a file that
11736 doesn't exist. It can be used for a temporary file. The name
11737 is different for at least 26 consecutive calls. Example: >
11738 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011739 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011740< For Unix, the file will be in a private directory |tempfile|
11741 that is recursively deleted when Vim exits, on other systems
11742 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011743 For MS-Windows forward slashes are used when the 'shellslash'
11744 option is set, or when 'shellcmdflag' starts with '-' and
11745 'shell' does not contain powershell or pwsh.
11746
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011747 Return type: |String|
11748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011749
11750term_ functions are documented here: |terminal-function-details|
11751
11752
11753terminalprops() *terminalprops()*
11754 Returns a |Dictionary| with properties of the terminal that Vim
11755 detected from the response to |t_RV| request. See
11756 |v:termresponse| for the response itself. If |v:termresponse|
11757 is empty most values here will be 'u' for unknown.
11758 cursor_style whether sending |t_RS| works **
11759 cursor_blink_mode whether sending |t_RC| works **
11760 underline_rgb whether |t_8u| works **
11761 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011762 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011763
11764 ** value 'u' for unknown, 'y' for yes, 'n' for no
11765
11766 If the |+termresponse| feature is missing then the result is
11767 an empty dictionary.
11768
11769 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11770 current cursor style.
11771 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11772 request the cursor blink status.
11773 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11774 is not empty, Vim will detect the working of sending |t_RS|
11775 and |t_RC| on startup.
11776
11777 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11778 This avoids sending it to xterm, which would clear the colors.
11779
11780 For "mouse" the value 'u' is unknown
11781
11782 Also see:
11783 - 'ambiwidth' - detected by using |t_u7|.
11784 - |v:termstyleresp| and |v:termblinkresp| for the response to
11785 |t_RS| and |t_RC|.
11786
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011787 Return type: dict<string>
11788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011789
11790test_ functions are documented here: |test-functions-details|
11791
11792
11793 *timer_info()*
11794timer_info([{id}])
11795 Return a list with information about timers.
11796 When {id} is given only information about this timer is
11797 returned. When timer {id} does not exist an empty list is
11798 returned.
11799 When {id} is omitted information about all timers is returned.
11800
11801 For each timer the information is stored in a |Dictionary| with
11802 these items:
11803 "id" the timer ID
11804 "time" time the timer was started with
11805 "remaining" time until the timer fires
11806 "repeat" number of times the timer will still fire;
11807 -1 means forever
11808 "callback" the callback
11809 "paused" 1 if the timer is paused, 0 otherwise
11810
11811 Can also be used as a |method|: >
11812 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011813<
11814 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011815
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011816 {only available when compiled with the |+timers| feature}
11817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011818
11819timer_pause({timer}, {paused}) *timer_pause()*
11820 Pause or unpause a timer. A paused timer does not invoke its
11821 callback when its time expires. Unpausing a timer may cause
11822 the callback to be invoked almost immediately if enough time
11823 has passed.
11824
11825 Pausing a timer is useful to avoid the callback to be called
11826 for a short time.
11827
11828 If {paused} evaluates to a non-zero Number or a non-empty
11829 String, then the timer is paused, otherwise it is unpaused.
11830 See |non-zero-arg|.
11831
11832 Can also be used as a |method|: >
11833 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011834<
11835 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011836
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011837 {only available when compiled with the |+timers| feature}
11838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011839
11840 *timer_start()* *timer* *timers*
11841timer_start({time}, {callback} [, {options}])
11842 Create a timer and return the timer ID.
11843
11844 {time} is the waiting time in milliseconds. This is the
11845 minimum time before invoking the callback. When the system is
11846 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011847 Zero can be used to execute the callback when Vim is back in
11848 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011849
11850 {callback} is the function to call. It can be the name of a
11851 function or a |Funcref|. It is called with one argument, which
11852 is the timer ID. The callback is only invoked when Vim is
11853 waiting for input.
11854 If you want to show a message look at |popup_notification()|
11855 to avoid interfering with what the user is doing.
11856
11857 {options} is a dictionary. Supported entries:
11858 "repeat" Number of times to repeat calling the
11859 callback. -1 means forever. When not present
11860 the callback will be called once.
11861 If the timer causes an error three times in a
11862 row the repeat is cancelled. This avoids that
11863 Vim becomes unusable because of all the error
11864 messages.
11865
Bram Moolenaard592deb2022-06-17 15:42:40 +010011866 Returns -1 on error.
11867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011868 Example: >
11869 func MyHandler(timer)
11870 echo 'Handler called'
11871 endfunc
11872 let timer = timer_start(500, 'MyHandler',
11873 \ {'repeat': 3})
11874< This will invoke MyHandler() three times at 500 msec
11875 intervals.
11876
11877 Can also be used as a |method|: >
11878 GetMsec()->timer_start(callback)
11879
11880< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011881
11882 Return type: |Number|
11883
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011884 {only available when compiled with the |+timers| feature}
11885
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011887timer_stop({timer}) *timer_stop()*
11888 Stop a timer. The timer callback will no longer be invoked.
11889 {timer} is an ID returned by timer_start(), thus it must be a
11890 Number. If {timer} does not exist there is no error.
11891
11892 Can also be used as a |method|: >
11893 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011894<
11895 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011896
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011897 {only available when compiled with the |+timers| feature}
11898
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011899
11900timer_stopall() *timer_stopall()*
11901 Stop all timers. The timer callbacks will no longer be
11902 invoked. Useful if a timer is misbehaving. If there are no
11903 timers there is no error.
11904
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011905 Return type: |Number|
11906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011907 {only available when compiled with the |+timers| feature}
11908
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011910tolower({expr}) *tolower()*
11911 The result is a copy of the String given, with all uppercase
11912 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011913 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011914
11915 Can also be used as a |method|: >
11916 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011917<
11918 Return type: |String|
11919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011920
11921toupper({expr}) *toupper()*
11922 The result is a copy of the String given, with all lowercase
11923 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011924 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011925
11926 Can also be used as a |method|: >
11927 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011928<
11929 Return type: |String|
11930
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011931
11932tr({src}, {fromstr}, {tostr}) *tr()*
11933 The result is a copy of the {src} string with all characters
11934 which appear in {fromstr} replaced by the character in that
11935 position in the {tostr} string. Thus the first character in
11936 {fromstr} is translated into the first character in {tostr}
11937 and so on. Exactly like the unix "tr" command.
11938 This code also deals with multibyte characters properly.
11939
Bram Moolenaard592deb2022-06-17 15:42:40 +010011940 Returns an empty string on error.
11941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011942 Examples: >
11943 echo tr("hello there", "ht", "HT")
11944< returns "Hello THere" >
11945 echo tr("<blob>", "<>", "{}")
11946< returns "{blob}"
11947
11948 Can also be used as a |method|: >
11949 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011950<
11951 Return type: |String|
11952
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011953
11954trim({text} [, {mask} [, {dir}]]) *trim()*
11955 Return {text} as a String where any character in {mask} is
11956 removed from the beginning and/or end of {text}.
11957
Illia Bobyr80799172023-10-17 18:00:50 +020011958 If {mask} is not given, or is an empty string, {mask} is all
11959 characters up to 0x20, which includes Tab, space, NL and CR,
11960 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011961
11962 The optional {dir} argument specifies where to remove the
11963 characters:
11964 0 remove from the beginning and end of {text}
11965 1 remove only at the beginning of {text}
11966 2 remove only at the end of {text}
11967 When omitted both ends are trimmed.
11968
11969 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011970 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011971
11972 Examples: >
11973 echo trim(" some text ")
11974< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011975 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011976< returns "RESERVE_TAIL" >
11977 echo trim("rm<Xrm<>X>rrm", "rm<>")
11978< returns "Xrm<>X" (characters in the middle are not removed) >
11979 echo trim(" vim ", " ", 2)
11980< returns " vim"
11981
11982 Can also be used as a |method|: >
11983 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011984<
11985 Return type: |String|
11986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011987
11988trunc({expr}) *trunc()*
11989 Return the largest integral value with magnitude less than or
11990 equal to {expr} as a |Float| (truncate towards zero).
11991 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011992 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011993 Examples: >
11994 echo trunc(1.456)
11995< 1.0 >
11996 echo trunc(-5.456)
11997< -5.0 >
11998 echo trunc(4.0)
11999< 4.0
12000
12001 Can also be used as a |method|: >
12002 Compute()->trunc()
12003<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012004 Return type: |Float|
12005
12006
Yegappan Lakshmanan1c2f4752025-03-30 15:37:24 +020012007tuple2list({tuple}) *tuple2list()*
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010012008 Create a List from a shallow copy of the tuple items.
12009 Examples: >
12010 tuple2list((1, 2, 3)) returns [1, 2, 3]
12011< |list2tuple()| does the opposite.
12012
12013 This function doesn't recursively convert all the Tuple items
12014 in {tuple} to a List. Note that the items are identical
12015 between the list and the tuple, changing an item changes the
12016 contents of both the tuple and the list.
12017
12018 Returns an empty list on error.
12019
12020 Can also be used as a |method|: >
12021 GetTuple()->tuple2list()
12022<
12023 Return type: list<{type}> (depending on the given |Tuple|)
12024
12025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012026 *type()*
12027type({expr}) The result is a Number representing the type of {expr}.
12028 Instead of using the number directly, it is better to use the
12029 v:t_ variable that has the value:
12030 Number: 0 |v:t_number|
12031 String: 1 |v:t_string|
12032 Funcref: 2 |v:t_func|
12033 List: 3 |v:t_list|
12034 Dictionary: 4 |v:t_dict|
12035 Float: 5 |v:t_float|
12036 Boolean: 6 |v:t_bool| (v:false and v:true)
12037 None: 7 |v:t_none| (v:null and v:none)
12038 Job: 8 |v:t_job|
12039 Channel: 9 |v:t_channel|
12040 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090012041 Class: 12 |v:t_class|
12042 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010012043 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010012044 Enum: 15 |v:t_enum|
12045 EnumValue: 16 |v:t_enumvalue|
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010012046 Tuple: 17 |v:t_tuple|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012047 For backward compatibility, this method can be used: >
12048 :if type(myvar) == type(0)
12049 :if type(myvar) == type("")
12050 :if type(myvar) == type(function("tr"))
12051 :if type(myvar) == type([])
12052 :if type(myvar) == type({})
12053 :if type(myvar) == type(0.0)
12054 :if type(myvar) == type(v:false)
12055 :if type(myvar) == type(v:none)
12056< To check if the v:t_ variables exist use this: >
12057 :if exists('v:t_number')
12058
12059< Can also be used as a |method|: >
12060 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012061<
12062 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012063
12064
12065typename({expr}) *typename()*
12066 Return a string representation of the type of {expr}.
12067 Example: >
12068 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000012069< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012070
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012071 Return type: |String|
12072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012073
12074undofile({name}) *undofile()*
12075 Return the name of the undo file that would be used for a file
12076 with name {name} when writing. This uses the 'undodir'
12077 option, finding directories that exist. It does not check if
12078 the undo file exists.
12079 {name} is always expanded to the full path, since that is what
12080 is used internally.
12081 If {name} is empty undofile() returns an empty string, since a
12082 buffer without a file name will not write an undo file.
12083 Useful in combination with |:wundo| and |:rundo|.
12084 When compiled without the |+persistent_undo| option this always
12085 returns an empty string.
12086
12087 Can also be used as a |method|: >
12088 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012089<
12090 Return type: |String|
12091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012092
Devin J. Pohly5fee1112023-04-23 20:26:59 -050012093undotree([{buf}]) *undotree()*
12094 Return the current state of the undo tree for the current
12095 buffer, or for a specific buffer if {buf} is given. The
12096 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012097 "seq_last" The highest undo sequence number used.
12098 "seq_cur" The sequence number of the current position in
12099 the undo tree. This differs from "seq_last"
12100 when some changes were undone.
12101 "time_cur" Time last used for |:earlier| and related
12102 commands. Use |strftime()| to convert to
12103 something readable.
12104 "save_last" Number of the last file write. Zero when no
12105 write yet.
12106 "save_cur" Number of the current position in the undo
12107 tree.
12108 "synced" Non-zero when the last undo block was synced.
12109 This happens when waiting from input from the
12110 user. See |undo-blocks|.
12111 "entries" A list of dictionaries with information about
12112 undo blocks.
12113
12114 The first item in the "entries" list is the oldest undo item.
12115 Each List item is a |Dictionary| with these items:
12116 "seq" Undo sequence number. Same as what appears in
12117 |:undolist|.
12118 "time" Timestamp when the change happened. Use
12119 |strftime()| to convert to something readable.
12120 "newhead" Only appears in the item that is the last one
12121 that was added. This marks the last change
12122 and where further changes will be added.
12123 "curhead" Only appears in the item that is the last one
12124 that was undone. This marks the current
12125 position in the undo tree, the block that will
12126 be used by a redo command. When nothing was
12127 undone after the last change this item will
12128 not appear anywhere.
12129 "save" Only appears on the last block before a file
12130 write. The number is the write count. The
12131 first write has number 1, the last one the
12132 "save_last" mentioned above.
12133 "alt" Alternate entry. This is again a List of undo
12134 blocks. Each item may again have an "alt"
12135 item.
12136
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012137 Return type: dict<any>
12138
12139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012140uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
12141 Remove second and succeeding copies of repeated adjacent
12142 {list} items in-place. Returns {list}. If you want a list
12143 to remain unmodified make a copy first: >
12144 :let newlist = uniq(copy(mylist))
12145< The default compare function uses the string representation of
12146 each item. For the use of {func} and {dict} see |sort()|.
Hirohito Higashi74f0a772025-06-23 21:42:36 +020012147 For deduplicating text in the current buffer see |:uniq|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012148
Bram Moolenaard592deb2022-06-17 15:42:40 +010012149 Returns zero if {list} is not a |List|.
12150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012151 Can also be used as a |method|: >
12152 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012153<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012154 Return type: list<{type}>
12155
12156
Christian Brabandt67672ef2023-04-24 21:09:54 +010012157 *utf16idx()*
12158utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012159 Same as |charidx()| but returns the UTF-16 code unit index of
12160 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012161
12162 When {charidx} is present and TRUE, {idx} is used as the
12163 character index in the String {string} instead of as the byte
12164 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012165 An {idx} in the middle of a UTF-8 sequence is rounded
12166 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012167
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012168 Returns -1 if the arguments are invalid or if there are less
12169 than {idx} bytes in {string}. If there are exactly {idx} bytes
12170 the length of the string in UTF-16 code units is returned.
12171
Christian Brabandt67672ef2023-04-24 21:09:54 +010012172 See |byteidx()| and |byteidxcomp()| for getting the byte index
12173 from the UTF-16 index and |charidx()| for getting the
12174 character index from the UTF-16 index.
12175 Refer to |string-offset-encoding| for more information.
12176 Examples: >
12177 echo utf16idx('a😊😊', 3) returns 2
12178 echo utf16idx('a😊😊', 7) returns 4
12179 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12180 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12181 echo utf16idx('aą́c', 6) returns 2
12182 echo utf16idx('aą́c', 6, 1) returns 4
12183 echo utf16idx('a😊😊', 9) returns -1
12184<
12185 Can also be used as a |method|: >
12186 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012187<
12188 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012190
12191values({dict}) *values()*
12192 Return a |List| with all the values of {dict}. The |List| is
12193 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012194 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012195
12196 Can also be used as a |method|: >
12197 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012198<
12199 Return type: list<any>
12200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012201
zeertzjq825cf812023-08-17 22:55:25 +020012202virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012203 The result is a Number, which is the screen column of the file
12204 position given with {expr}. That is, the last screen position
12205 occupied by the character at that position, when the screen
12206 would be of unlimited width. When there is a <Tab> at the
12207 position, the returned Number will be the column at the end of
12208 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12209 set to 8, it returns 8. |conceal| is ignored.
12210 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012211
zeertzjq02f3eba2024-06-12 20:45:24 +020012212 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012213 When {expr} is "$", it means the end of the cursor line, so
12214 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012215
12216 When 'virtualedit' is used {expr} can be [lnum, col, off],
12217 where "off" is the offset in screen columns from the start of
12218 the character. E.g., a position within a <Tab> or after the
12219 last character. When "off" is omitted zero is used. When
12220 Virtual editing is active in the current mode, a position
12221 beyond the end of the line can be returned. Also see
12222 |'virtualedit'|
12223
zeertzjq825cf812023-08-17 22:55:25 +020012224 If {list} is present and non-zero then virtcol() returns a
12225 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012226 character.
12227
zeertzjq825cf812023-08-17 22:55:25 +020012228 With the optional {winid} argument the values are obtained for
12229 that window instead of the current window.
12230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012231 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012233 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012234 " With text "foo^Lbar" and cursor on the "^L":
12235
12236 virtcol(".") " returns 5
12237 virtcol(".", 1) " returns [4, 5]
12238 virtcol("$") " returns 9
12239
12240 " With text " there", with 't at 'h':
12241
12242 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012243<
12244 The first column is 1. 0 or [0, 0] is returned for an error.
12245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012246 A more advanced example that echoes the maximum length of
12247 all lines: >
12248 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12249
12250< Can also be used as a |method|: >
12251 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012252<
12253 Return type: |Number|
12254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012255
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012256virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12257 The result is a Number, which is the byte index of the
12258 character in window {winid} at buffer line {lnum} and virtual
12259 column {col}.
12260
zeertzjqb583eda2023-10-14 11:32:28 +020012261 If buffer line {lnum} is an empty line, 0 is returned.
12262
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012263 If {col} is greater than the last virtual column in line
12264 {lnum}, then the byte index of the character at the last
12265 virtual column is returned.
12266
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012267 For a multi-byte character, the column number of the first
12268 byte in the character is returned.
12269
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012270 The {winid} argument can be the window number or the
12271 |window-ID|. If this is zero, then the current window is used.
12272
12273 Returns -1 if the window {winid} doesn't exist or the buffer
12274 line {lnum} or virtual column {col} is invalid.
12275
12276 See also |screenpos()|, |virtcol()| and |col()|.
12277
12278 Can also be used as a |method|: >
12279 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012280<
12281 Return type: |Number|
12282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012283
12284visualmode([{expr}]) *visualmode()*
12285 The result is a String, which describes the last Visual mode
12286 used in the current buffer. Initially it returns an empty
12287 string, but once Visual mode has been used, it returns "v",
12288 "V", or "<CTRL-V>" (a single CTRL-V character) for
12289 character-wise, line-wise, or block-wise Visual mode
12290 respectively.
12291 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012292 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012293< This enters the same Visual mode as before. It is also useful
12294 in scripts if you wish to act differently depending on the
12295 Visual mode that was used.
12296 If Visual mode is active, use |mode()| to get the Visual mode
12297 (e.g., in a |:vmap|).
12298 If {expr} is supplied and it evaluates to a non-zero Number or
12299 a non-empty String, then the Visual mode will be cleared and
12300 the old value is returned. See |non-zero-arg|.
12301
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012302 Return type: |String|
12303
12304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012305wildmenumode() *wildmenumode()*
12306 Returns |TRUE| when the wildmenu is active and |FALSE|
12307 otherwise. See 'wildmenu' and 'wildmode'.
12308 This can be used in mappings to handle the 'wildcharm' option
12309 gracefully. (Makes only sense with |mapmode-c| mappings).
12310
12311 For example to make <c-j> work like <down> in wildmode, use: >
12312 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12313<
Milly6c2fc372024-10-16 22:11:17 +020012314 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012315
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012316 Return type: |Number|
12317
12318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012319win_execute({id}, {command} [, {silent}]) *win_execute()*
12320 Like `execute()` but in the context of window {id}.
12321 The window will temporarily be made the current window,
12322 without triggering autocommands or changing directory. When
12323 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012324 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012325 Example: >
12326 call win_execute(winid, 'set syntax=python')
12327< Doing the same with `setwinvar()` would not trigger
12328 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012329 *E994*
12330 Not all commands are allowed in popup windows.
12331 When window {id} does not exist then no error is given and
12332 an empty string is returned.
12333
12334 Can also be used as a |method|, the base is passed as the
12335 second argument: >
12336 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012337<
12338 Return type: |String|
12339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012340
12341win_findbuf({bufnr}) *win_findbuf()*
12342 Returns a |List| with |window-ID|s for windows that contain
12343 buffer {bufnr}. When there is none the list is empty.
12344
12345 Can also be used as a |method|: >
12346 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012347<
12348 Return type: list<number> or list<any>
12349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012350
12351win_getid([{win} [, {tab}]]) *win_getid()*
12352 Get the |window-ID| for the specified window.
12353 When {win} is missing use the current window.
12354 With {win} this is the window number. The top window has
12355 number 1.
12356 Without {tab} use the current tab, otherwise the tab with
12357 number {tab}. The first tab has number one.
12358 Return zero if the window cannot be found.
12359
12360 Can also be used as a |method|: >
12361 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012362<
12363 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012364
12365
12366win_gettype([{nr}]) *win_gettype()*
12367 Return the type of the window:
12368 "autocmd" autocommand window. Temporary window
12369 used to execute autocommands.
12370 "command" command-line window |cmdwin|
12371 (empty) normal window
12372 "loclist" |location-list-window|
12373 "popup" popup window |popup|
12374 "preview" preview window |preview-window|
12375 "quickfix" |quickfix-window|
12376 "unknown" window {nr} not found
12377
12378 When {nr} is omitted return the type of the current window.
12379 When {nr} is given return the type of this window by number or
12380 |window-ID|.
12381
12382 Also see the 'buftype' option. When running a terminal in a
12383 popup window then 'buftype' is "terminal" and win_gettype()
12384 returns "popup".
12385
12386 Can also be used as a |method|: >
12387 GetWinid()->win_gettype()
12388<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012389 Return type: |String|
12390
12391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012392win_gotoid({expr}) *win_gotoid()*
12393 Go to window with ID {expr}. This may also change the current
12394 tabpage.
12395 Return TRUE if successful, FALSE if the window cannot be found.
12396
12397 Can also be used as a |method|: >
12398 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012399<
12400 Return type: |Number|
12401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012402
12403win_id2tabwin({expr}) *win_id2tabwin()*
12404 Return a list with the tab number and window number of window
12405 with ID {expr}: [tabnr, winnr].
12406 Return [0, 0] if the window cannot be found.
12407
12408 Can also be used as a |method|: >
12409 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012410<
12411 Return type: list<number>
12412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012413
12414win_id2win({expr}) *win_id2win()*
12415 Return the window number of window with ID {expr}.
12416 Return 0 if the window cannot be found in the current tabpage.
12417
12418 Can also be used as a |method|: >
12419 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012420<
12421 Return type: |Number|
12422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012423
Daniel Steinbergee630312022-01-10 13:36:34 +000012424win_move_separator({nr}, {offset}) *win_move_separator()*
12425 Move window {nr}'s vertical separator (i.e., the right border)
12426 by {offset} columns, as if being dragged by the mouse. {nr}
12427 can be a window number or |window-ID|. A positive {offset}
12428 moves right and a negative {offset} moves left. Moving a
12429 window's vertical separator will change the width of the
12430 window and the width of other windows adjacent to the vertical
12431 separator. The magnitude of movement may be smaller than
12432 specified (e.g., as a consequence of maintaining
12433 'winminwidth'). Returns TRUE if the window can be found and
12434 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012435 This will fail for the rightmost window and a full-width
12436 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012437 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012438
12439 Can also be used as a |method|: >
12440 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012441<
12442 Return type: |Number|
12443
Daniel Steinbergee630312022-01-10 13:36:34 +000012444
12445win_move_statusline({nr}, {offset}) *win_move_statusline()*
12446 Move window {nr}'s status line (i.e., the bottom border) by
12447 {offset} rows, as if being dragged by the mouse. {nr} can be a
12448 window number or |window-ID|. A positive {offset} moves down
12449 and a negative {offset} moves up. Moving a window's status
12450 line will change the height of the window and the height of
12451 other windows adjacent to the status line. The magnitude of
12452 movement may be smaller than specified (e.g., as a consequence
12453 of maintaining 'winminheight'). Returns TRUE if the window can
12454 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012455 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012456
12457 Can also be used as a |method|: >
12458 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012459<
12460 Return type: |Number|
12461
Daniel Steinbergee630312022-01-10 13:36:34 +000012462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012463win_screenpos({nr}) *win_screenpos()*
12464 Return the screen position of window {nr} as a list with two
12465 numbers: [row, col]. The first window always has position
12466 [1, 1], unless there is a tabline, then it is [2, 1].
12467 {nr} can be the window number or the |window-ID|. Use zero
12468 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012469 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012470
12471 Can also be used as a |method|: >
12472 GetWinid()->win_screenpos()
12473<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012474 Return type: list<number>
12475
12476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012477win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012478 Temporarily switch to window {target}, then move window {nr}
12479 to a new split adjacent to {target}.
12480 Unlike commands such as |:split|, no new windows are created
12481 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012482
12483 Both {nr} and {target} can be window numbers or |window-ID|s.
12484 Both must be in the current tab page.
12485
12486 Returns zero for success, non-zero for failure.
12487
12488 {options} is a |Dictionary| with the following optional entries:
12489 "vertical" When TRUE, the split is created vertically,
12490 like with |:vsplit|.
12491 "rightbelow" When TRUE, the split is made below or to the
12492 right (if vertical). When FALSE, it is done
12493 above or to the left (if vertical). When not
12494 present, the values of 'splitbelow' and
12495 'splitright' are used.
12496
12497 Can also be used as a |method|: >
12498 GetWinid()->win_splitmove(target)
12499<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012500 Return type: |Number|
12501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012502
12503 *winbufnr()*
12504winbufnr({nr}) The result is a Number, which is the number of the buffer
12505 associated with window {nr}. {nr} can be the window number or
12506 the |window-ID|.
12507 When {nr} is zero, the number of the buffer in the current
12508 window is returned.
12509 When window {nr} doesn't exist, -1 is returned.
12510 Example: >
12511 :echo "The file in the current window is " . bufname(winbufnr(0))
12512<
12513 Can also be used as a |method|: >
12514 FindWindow()->winbufnr()->bufname()
12515<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012516 Return type: |Number|
12517
12518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012519 *wincol()*
12520wincol() The result is a Number, which is the virtual column of the
12521 cursor in the window. This is counting screen cells from the
12522 left side of the window. The leftmost column is one.
12523
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012524 Return type: |Number|
12525
12526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012527 *windowsversion()*
12528windowsversion()
12529 The result is a String. For MS-Windows it indicates the OS
12530 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12531 Windows XP is "5.1". For non-MS-Windows systems the result is
12532 an empty string.
12533
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012534 Return type: |String|
12535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012536winheight({nr}) *winheight()*
12537 The result is a Number, which is the height of window {nr}.
12538 {nr} can be the window number or the |window-ID|.
12539 When {nr} is zero, the height of the current window is
12540 returned. When window {nr} doesn't exist, -1 is returned.
12541 An existing window always has a height of zero or more.
12542 This excludes any window toolbar line.
12543 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012544 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012545
12546< Can also be used as a |method|: >
12547 GetWinid()->winheight()
12548<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012549 Return type: |Number|
12550
12551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012552winlayout([{tabnr}]) *winlayout()*
12553 The result is a nested List containing the layout of windows
12554 in a tabpage.
12555
12556 Without {tabnr} use the current tabpage, otherwise the tabpage
12557 with number {tabnr}. If the tabpage {tabnr} is not found,
12558 returns an empty list.
12559
12560 For a leaf window, it returns:
12561 ['leaf', {winid}]
12562 For horizontally split windows, which form a column, it
12563 returns:
12564 ['col', [{nested list of windows}]]
12565 For vertically split windows, which form a row, it returns:
12566 ['row', [{nested list of windows}]]
12567
12568 Example: >
12569 " Only one window in the tab page
12570 :echo winlayout()
12571 ['leaf', 1000]
12572 " Two horizontally split windows
12573 :echo winlayout()
12574 ['col', [['leaf', 1000], ['leaf', 1001]]]
12575 " The second tab page, with three horizontally split
12576 " windows, with two vertically split windows in the
12577 " middle window
12578 :echo winlayout(2)
12579 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12580 ['leaf', 1001]]], ['leaf', 1000]]]
12581<
12582 Can also be used as a |method|: >
12583 GetTabnr()->winlayout()
12584<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012585 Return type: list<any>
12586
12587
12588winline() *winline()*
12589 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012590 in the window. This is counting screen lines from the top of
12591 the window. The first line is one.
12592 If the cursor was moved the view on the file will be updated
12593 first, this may cause a scroll.
12594
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012595 Return type: |Number|
12596
12597
12598winnr([{arg}]) *winnr()*
12599 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012600 window. The top window has number 1.
12601 Returns zero for a popup window.
12602
12603 The optional argument {arg} supports the following values:
12604 $ the number of the last window (the window
12605 count).
12606 # the number of the last accessed window (where
12607 |CTRL-W_p| goes to). If there is no previous
12608 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012609 returned. May refer to the current window in
12610 some cases (e.g. when evaluating 'statusline'
12611 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012612 {N}j the number of the Nth window below the
12613 current window (where |CTRL-W_j| goes to).
12614 {N}k the number of the Nth window above the current
12615 window (where |CTRL-W_k| goes to).
12616 {N}h the number of the Nth window left of the
12617 current window (where |CTRL-W_h| goes to).
12618 {N}l the number of the Nth window right of the
12619 current window (where |CTRL-W_l| goes to).
12620 The number can be used with |CTRL-W_w| and ":wincmd w"
12621 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012622 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012623 Also see |tabpagewinnr()| and |win_getid()|.
12624 Examples: >
12625 let window_count = winnr('$')
12626 let prev_window = winnr('#')
12627 let wnum = winnr('3k')
12628
12629< Can also be used as a |method|: >
12630 GetWinval()->winnr()
12631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012632 Return type: |Number|
12633
12634
12635winrestcmd() *winrestcmd()*
12636 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012637 the current window sizes. Only works properly when no windows
12638 are opened or closed and the current window and tab page is
12639 unchanged.
12640 Example: >
12641 :let cmd = winrestcmd()
12642 :call MessWithWindowSizes()
12643 :exe cmd
12644<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012645 Return type: |String|
12646
12647
12648winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012649 Uses the |Dictionary| returned by |winsaveview()| to restore
12650 the view of the current window.
12651 Note: The {dict} does not have to contain all values, that are
12652 returned by |winsaveview()|. If values are missing, those
12653 settings won't be restored. So you can use: >
12654 :call winrestview({'curswant': 4})
12655<
12656 This will only set the curswant value (the column the cursor
12657 wants to move on vertical movements) of the cursor to column 5
12658 (yes, that is 5), while all other settings will remain the
12659 same. This is useful, if you set the cursor position manually.
12660
12661 If you have changed the values the result is unpredictable.
12662 If the window size changed the result won't be the same.
12663
12664 Can also be used as a |method|: >
12665 GetView()->winrestview()
12666<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012667 Return type: |Number|
12668
12669
12670winsaveview() *winsaveview()*
12671 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012672 the view of the current window. Use |winrestview()| to
12673 restore the view.
12674 This is useful if you have a mapping that jumps around in the
12675 buffer and you want to go back to the original view.
12676 This does not save fold information. Use the 'foldenable'
12677 option to temporarily switch off folding, so that folds are
12678 not opened when moving around. This may have side effects.
12679 The return value includes:
12680 lnum cursor line number
12681 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012682 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012683 returns)
12684 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012685 curswant column for vertical movement (Note:
12686 the first column is zero, as opposed
12687 to what |getcurpos()| returns). After
12688 |$| command it will be a very large
12689 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012690 topline first line in the window
12691 topfill filler lines, only in diff mode
12692 leftcol first column displayed; only used when
12693 'wrap' is off
12694 skipcol columns skipped
12695 Note that no option values are saved.
12696
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012697 Return type: dict<number>
12698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012699
12700winwidth({nr}) *winwidth()*
12701 The result is a Number, which is the width of window {nr}.
12702 {nr} can be the window number or the |window-ID|.
12703 When {nr} is zero, the width of the current window is
12704 returned. When window {nr} doesn't exist, -1 is returned.
12705 An existing window always has a width of zero or more.
12706 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012707 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012708 :if winwidth(0) <= 50
12709 : 50 wincmd |
12710 :endif
12711< For getting the terminal or screen size, see the 'columns'
12712 option.
12713
12714 Can also be used as a |method|: >
12715 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012716<
12717 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012718
12719
12720wordcount() *wordcount()*
12721 The result is a dictionary of byte/chars/word statistics for
12722 the current buffer. This is the same info as provided by
12723 |g_CTRL-G|
12724 The return value includes:
12725 bytes Number of bytes in the buffer
12726 chars Number of chars in the buffer
12727 words Number of words in the buffer
12728 cursor_bytes Number of bytes before cursor position
12729 (not in Visual mode)
12730 cursor_chars Number of chars before cursor position
12731 (not in Visual mode)
12732 cursor_words Number of words before cursor position
12733 (not in Visual mode)
12734 visual_bytes Number of bytes visually selected
12735 (only in Visual mode)
12736 visual_chars Number of chars visually selected
12737 (only in Visual mode)
12738 visual_words Number of words visually selected
12739 (only in Visual mode)
12740
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012741 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012742
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012743
12744writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012745 When {object} is a |List| write it to file {fname}. Each list
12746 item is separated with a NL. Each list item must be a String
12747 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012748 All NL characters are replaced with a NUL character.
12749 Inserting CR characters needs to be done before passing {list}
12750 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012751
12752 When {object} is a |Blob| write the bytes to file {fname}
12753 unmodified, also when binary mode is not specified.
12754
12755 {flags} must be a String. These characters are recognized:
12756
12757 'b' Binary mode is used: There will not be a NL after the
12758 last list item. An empty item at the end does cause the
12759 last line in the file to end in a NL.
12760
12761 'a' Append mode is used, lines are appended to the file: >
12762 :call writefile(["foo"], "event.log", "a")
12763 :call writefile(["bar"], "event.log", "a")
12764<
12765 'D' Delete the file when the current function ends. This
12766 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012767 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012768< Fails when not in a function. Also see |:defer|.
12769
12770 's' fsync() is called after writing the file. This flushes
12771 the file to disk, if possible. This takes more time but
12772 avoids losing the file if the system crashes.
12773
12774 'S' fsync() is not called, even when 'fsync' is set.
12775
12776 When {flags} does not contain "S" or "s" then fsync() is
12777 called if the 'fsync' option is set.
12778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012779 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012781 When the write fails -1 is returned, otherwise 0. There is an
12782 error message if the file can't be created or when writing
12783 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012785 Also see |readfile()|.
12786 To copy a file byte for byte: >
12787 :let fl = readfile("foo", "b")
12788 :call writefile(fl, "foocopy", "b")
12789
12790< Can also be used as a |method|: >
12791 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012792<
12793 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012794
12795
12796xor({expr}, {expr}) *xor()*
12797 Bitwise XOR on the two arguments. The arguments are converted
12798 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012799 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012800 Example: >
12801 :let bits = xor(bits, 0x80)
12802<
12803 Can also be used as a |method|: >
12804 :let bits = bits->xor(0x80)
12805<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012806 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012807
12808==============================================================================
128093. Feature list *feature-list*
12810
12811There are three types of features:
128121. Features that are only supported when they have been enabled when Vim
12813 was compiled |+feature-list|. Example: >
12814 :if has("cindent")
12815< *gui_running*
128162. Features that are only supported when certain conditions have been met.
12817 Example: >
12818 :if has("gui_running")
12819< *has-patch*
128203. Beyond a certain version or at a certain version and including a specific
12821 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12822 later, or it is version 7.4 and patch 248 was included. Example: >
12823 :if has("patch-7.4.248")
12824< Note that it's possible for patch 248 to be omitted even though 249 is
12825 included. Only happens when cherry-picking patches.
12826 Note that this form only works for patch 7.4.237 and later, before that
12827 you need to check for the patch and the v:version. Example (checking
12828 version 6.2.148 or later): >
12829 :if v:version > 602 || (v:version == 602 && has("patch148"))
12830
12831Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12832use: `if exists('+shellslash')`
12833
12834
12835acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012836all_builtin_terms Compiled with all builtin terminals enabled. (always
12837 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012838amiga Amiga version of Vim.
12839arabic Compiled with Arabic support |Arabic|.
12840arp Compiled with ARP support (Amiga).
12841autocmd Compiled with autocommand support. (always true)
12842autochdir Compiled with support for 'autochdir'
12843autoservername Automatically enable |clientserver|
12844balloon_eval Compiled with |balloon-eval| support.
12845balloon_multiline GUI supports multiline balloons.
12846beos BeOS version of Vim.
12847browse Compiled with |:browse| support, and browse() will
12848 work.
12849browsefilter Compiled with support for |browsefilter|.
12850bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012851builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012852byte_offset Compiled with support for 'o' in 'statusline'
12853channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012854cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012855clientserver Compiled with remote invocation support |clientserver|.
12856clipboard Compiled with 'clipboard' support.
12857clipboard_working Compiled with 'clipboard' support and it can be used.
12858cmdline_compl Compiled with |cmdline-completion| support.
12859cmdline_hist Compiled with |cmdline-history| support.
12860cmdline_info Compiled with 'showcmd' and 'ruler' support.
12861comments Compiled with |'comments'| support.
12862compatible Compiled to be very Vi compatible.
12863conpty Platform where |ConPTY| can be used.
12864cryptv Compiled with encryption support |encryption|.
12865cscope Compiled with |cscope| support.
12866cursorbind Compiled with |'cursorbind'| (always true)
12867debug Compiled with "DEBUG" defined.
12868dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012869dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012870dialog_gui Compiled with GUI dialog support.
12871diff Compiled with |vimdiff| and 'diff' support.
12872digraphs Compiled with support for digraphs.
12873directx Compiled with support for DirectX and 'renderoptions'.
12874dnd Compiled with support for the "~ register |quote_~|.
12875drop_file Compiled with |drop_file| support.
12876ebcdic Compiled on a machine with ebcdic character set.
12877emacs_tags Compiled with support for Emacs tags.
12878eval Compiled with expression evaluation support. Always
12879 true, of course!
12880ex_extra |+ex_extra| (always true)
12881extra_search Compiled with support for |'incsearch'| and
12882 |'hlsearch'|
12883farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012884file_in_path Compiled with support for |gf| and |<cfile>| (always
12885 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012886filterpipe When 'shelltemp' is off pipes are used for shell
12887 read/write/filter commands
12888find_in_path Compiled with support for include file searches
12889 |+find_in_path|.
12890float Compiled with support for |Float|.
12891fname_case Case in file names matters (for Amiga and MS-Windows
12892 this is not present).
12893folding Compiled with |folding| support.
12894footer Compiled with GUI footer support. |gui-footer|
12895fork Compiled to use fork()/exec() instead of system().
12896gettext Compiled with message translation |multi-lang|
12897gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012898gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012899gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12900gui_gtk Compiled with GTK+ GUI (any version).
12901gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12902gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12903gui_haiku Compiled with Haiku GUI.
12904gui_mac Compiled with Macintosh GUI.
12905gui_motif Compiled with Motif GUI.
12906gui_photon Compiled with Photon GUI.
12907gui_running Vim is running in the GUI, or it will start soon.
12908gui_win32 Compiled with MS-Windows Win32 GUI.
12909gui_win32s idem, and Win32s system being used (Windows 3.1)
12910haiku Haiku version of Vim.
12911hangul_input Compiled with Hangul input support. |hangul|
12912hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012913hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012914iconv Can use iconv() for conversion.
12915insert_expand Compiled with support for CTRL-X expansion commands in
12916 Insert mode. (always true)
12917job Compiled with support for |channel| and |job|
12918ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012919jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012920keymap Compiled with 'keymap' support.
12921lambda Compiled with |lambda| support.
12922langmap Compiled with 'langmap' support.
12923libcall Compiled with |libcall()| support.
12924linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12925 'breakindent' support.
12926linux Linux version of Vim.
12927lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012928 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012929listcmds Compiled with commands for the buffer list |:files|
12930 and the argument list |arglist|.
12931localmap Compiled with local mappings and abbr. |:map-local|
12932lua Compiled with Lua interface |Lua|.
12933mac Any Macintosh version of Vim cf. osx
12934macunix Synonym for osxdarwin
12935menu Compiled with support for |:menu|.
12936mksession Compiled with support for |:mksession|.
12937modify_fname Compiled with file name modifiers. |filename-modifiers|
12938 (always true)
12939mouse Compiled with support for mouse.
12940mouse_dec Compiled with support for Dec terminal mouse.
12941mouse_gpm Compiled with support for gpm (Linux console mouse)
12942mouse_gpm_enabled GPM mouse is working
12943mouse_netterm Compiled with support for netterm mouse.
12944mouse_pterm Compiled with support for qnx pterm mouse.
12945mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12946mouse_sgr Compiled with support for sgr mouse.
12947mouse_urxvt Compiled with support for urxvt mouse.
12948mouse_xterm Compiled with support for xterm mouse.
12949mouseshape Compiled with support for 'mouseshape'.
12950multi_byte Compiled with support for 'encoding' (always true)
12951multi_byte_encoding 'encoding' is set to a multibyte encoding.
12952multi_byte_ime Compiled with support for IME input method.
12953multi_lang Compiled with support for multiple languages.
12954mzscheme Compiled with MzScheme interface |mzscheme|.
12955nanotime Compiled with sub-second time stamp checks.
12956netbeans_enabled Compiled with support for |netbeans| and connected.
12957netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012958num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012959ole Compiled with OLE automation support for Win32.
12960osx Compiled for macOS cf. mac
12961osxdarwin Compiled for macOS, with |mac-darwin-feature|
12962packages Compiled with |packages| support.
12963path_extra Compiled with up/downwards search in 'path' and 'tags'
12964perl Compiled with Perl interface.
12965persistent_undo Compiled with support for persistent undo history.
12966postscript Compiled with PostScript file printing.
12967printer Compiled with |:hardcopy| support.
12968profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012969prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012970python Python 2.x interface available. |has-python|
12971python_compiled Compiled with Python 2.x interface. |has-python|
12972python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12973python3 Python 3.x interface available. |has-python|
12974python3_compiled Compiled with Python 3.x interface. |has-python|
12975python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012976python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012977pythonx Python 2.x and/or 3.x interface available. |python_x|
12978qnx QNX version of Vim.
12979quickfix Compiled with |quickfix| support.
12980reltime Compiled with |reltime()| support.
12981rightleft Compiled with 'rightleft' support.
12982ruby Compiled with Ruby interface |ruby|.
12983scrollbind Compiled with 'scrollbind' support. (always true)
12984showcmd Compiled with 'showcmd' support.
12985signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012986smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012987sodium Compiled with libsodium for better crypt support
12988sound Compiled with sound support, e.g. `sound_playevent()`
12989spell Compiled with spell checking support |spell|.
12990startuptime Compiled with |--startuptime| support.
12991statusline Compiled with support for 'statusline', 'rulerformat'
12992 and special formats of 'titlestring' and 'iconstring'.
12993sun SunOS version of Vim.
12994sun_workshop Support for Sun |workshop| has been removed.
12995syntax Compiled with syntax highlighting support |syntax|.
12996syntax_items There are active syntax highlighting items for the
12997 current buffer.
12998system Compiled to use system() instead of fork()/exec().
12999tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010013000 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013001tag_old_static Support for old static tags was removed, see
13002 |tag-old-static|.
13003tcl Compiled with Tcl interface.
13004termguicolors Compiled with true color in terminal support.
13005terminal Compiled with |terminal| support.
13006terminfo Compiled with terminfo instead of termcap.
13007termresponse Compiled with support for |t_RV| and |v:termresponse|.
13008textobjects Compiled with support for |text-objects|.
13009textprop Compiled with support for |text-properties|.
13010tgetent Compiled with tgetent support, able to use a termcap
13011 or terminfo file.
13012timers Compiled with |timer_start()| support.
13013title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010013014 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013015toolbar Compiled with support for |gui-toolbar|.
13016ttyin input is a terminal (tty)
13017ttyout output is a terminal (tty)
13018unix Unix version of Vim. *+unix*
13019unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
13020user_commands User-defined commands. (always true)
13021vartabs Compiled with variable tabstop support |'vartabstop'|.
13022vcon Win32: Virtual console support is working, can use
13023 'termguicolors'. Also see |+vtp|.
13024vertsplit Compiled with vertically split windows |:vsplit|.
13025 (always true)
13026vim_starting True while initial source'ing takes place. |startup|
13027 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000013028vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013029viminfo Compiled with viminfo support.
13030vimscript-1 Compiled Vim script version 1 support
13031vimscript-2 Compiled Vim script version 2 support
13032vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010013033vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013034virtualedit Compiled with 'virtualedit' option. (always true)
13035visual Compiled with Visual mode. (always true)
13036visualextra Compiled with extra Visual mode commands. (always
13037 true) |blockwise-operators|.
13038vms VMS version of Vim.
13039vreplace Compiled with |gR| and |gr| commands. (always true)
13040vtp Compiled for vcon support |+vtp| (check vcon to find
13041 out if it works in the current console).
Foxe Chenb90c2392025-06-27 21:10:35 +020013042wayland Compiled with Wayland protocol support.
Hirohito Higashi73b96502025-06-28 18:18:21 +020013043wayland_clipboard Compiled with support for Wayland selections/clipboard
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013044wildignore Compiled with 'wildignore' option.
13045wildmenu Compiled with 'wildmenu' option.
13046win16 old version for MS-Windows 3.1 (always false)
13047win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
13048 64 bits)
13049win32unix Win32 version of Vim, using Unix files (Cygwin)
13050win64 Win64 version of Vim (MS-Windows 64 bit).
13051win95 Win32 version for MS-Windows 95/98/ME (always false)
13052winaltkeys Compiled with 'winaltkeys' option.
13053windows Compiled with support for more than one window.
13054 (always true)
13055writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020013056xattr Compiled with extended attributes support |xattr|
13057 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013058xfontset Compiled with X fontset support |xfontset|.
13059xim Compiled with X input method support |xim|.
13060xpm Compiled with pixmap support.
13061xpm_w32 Compiled with pixmap support for Win32. (Only for
13062 backward compatibility. Use "xpm" instead.)
13063xsmp Compiled with X session management support.
13064xsmp_interact Compiled with interactive X session management support.
13065xterm_clipboard Compiled with support for xterm clipboard.
13066xterm_save Compiled with support for saving and restoring the
13067 xterm screen.
13068x11 Compiled with X11 support.
13069
13070
13071==============================================================================
130724. Matching a pattern in a String *string-match*
13073
13074This is common between several functions. A regexp pattern as explained at
13075|pattern| is normally used to find a match in the buffer lines. When a
13076pattern is used to find a match in a String, almost everything works in the
13077same way. The difference is that a String is handled like it is one line.
13078When it contains a "\n" character, this is not seen as a line break for the
13079pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
13080>
13081 :let a = "aaaa\nxxxx"
13082 :echo matchstr(a, "..\n..")
13083 aa
13084 xx
13085 :echo matchstr(a, "a.x")
13086 a
13087 x
13088
13089Don't forget that "^" will only match at the first character of the String and
13090"$" at the last character of the string. They don't match after or before a
13091"\n".
13092
13093 vim:tw=78:ts=8:noet:ft=help:norl: