blob: 7353776f5eefa168cc036ccad09308c0905bd920 [file] [log] [blame]
Girish Palya92f68e22025-04-21 11:12:41 +02001*builtin.txt* For Vim version 9.1. Last change: 2025 Apr 21
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Girish Palya92f68e22025-04-21 11:12:41 +0200132cmdcomplete_info() Dict get current cmdline completion
133 information
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000134col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000135complete({startcol}, {matches}) none set Insert mode completion
136complete_add({expr}) Number add completion match
137complete_check() Number check for key typed during completion
138complete_info([{what}]) Dict get current completion information
139confirm({msg} [, {choices} [, {default} [, {type}]]])
140 Number number of choice picked by user
141copy({expr}) any make a shallow copy of {expr}
142cos({expr}) Float cosine of {expr}
143cosh({expr}) Float hyperbolic cosine of {expr}
144count({comp}, {expr} [, {ic} [, {start}]])
145 Number count how many {expr} are in {comp}
146cscope_connection([{num}, {dbpath} [, {prepend}]])
147 Number checks existence of cscope connection
148cursor({lnum}, {col} [, {off}])
149 Number move cursor to {lnum}, {col}, {off}
150cursor({list}) Number move cursor to position in {list}
151debugbreak({pid}) Number interrupt process being debugged
152deepcopy({expr} [, {noref}]) any make a full copy of {expr}
153delete({fname} [, {flags}]) Number delete the file or directory {fname}
154deletebufline({buf}, {first} [, {last}])
155 Number delete lines from buffer {buf}
156did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100157diff({fromlist}, {tolist} [, {options}])
158 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000159diff_filler({lnum}) Number diff filler lines about {lnum}
160diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
161digraph_get({chars}) String get the |digraph| of {chars}
162digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200163digraph_set({chars}, {digraph}) Bool register |digraph|
164digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000165echoraw({expr}) none output {expr} as-is
166empty({expr}) Number |TRUE| if {expr} is empty
167environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100168err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000169escape({string}, {chars}) String escape {chars} in {string} with '\'
170eval({string}) any evaluate {string} into its value
171eventhandler() Number |TRUE| if inside an event handler
172executable({expr}) Number 1 if executable {expr} exists
173execute({command}) String execute {command} and get the output
174exepath({expr}) String full path of the command {expr}
175exists({expr}) Number |TRUE| if {expr} exists
176exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
177exp({expr}) Float exponential of {expr}
178expand({expr} [, {nosuf} [, {list}]])
179 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100180expandcmd({string} [, {options}])
181 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000182extend({expr1}, {expr2} [, {expr3}])
183 List/Dict insert items of {expr2} into {expr1}
184extendnew({expr1}, {expr2} [, {expr3}])
185 List/Dict like |extend()| but creates a new
186 List or Dictionary
187feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200188filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
189 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000190filereadable({file}) Number |TRUE| if {file} is a readable file
191filewritable({file}) Number |TRUE| if {file} is a writable file
192filter({expr1}, {expr2}) List/Dict/Blob/String
193 remove items from {expr1} where
194 {expr2} is 0
195finddir({name} [, {path} [, {count}]])
196 String find directory {name} in {path}
197findfile({name} [, {path} [, {count}]])
198 String find file {name} in {path}
199flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
200flattennew({list} [, {maxdepth}])
201 List flatten a copy of {list}
202float2nr({expr}) Number convert Float {expr} to a Number
203floor({expr}) Float round {expr} down
204fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
205fnameescape({fname}) String escape special characters in {fname}
206fnamemodify({fname}, {mods}) String modify file name
207foldclosed({lnum}) Number first line of fold at {lnum} if closed
208foldclosedend({lnum}) Number last line of fold at {lnum} if closed
209foldlevel({lnum}) Number fold level at {lnum}
210foldtext() String line displayed for closed fold
211foldtextresult({lnum}) String text for closed fold at {lnum}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100212foreach({expr1}, {expr2}) List/Tuple/Dict/Blob/String
Ernie Raele79e2072024-01-13 11:47:33 +0100213 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100215fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000216funcref({name} [, {arglist}] [, {dict}])
217 Funcref reference to function {name}
218function({name} [, {arglist}] [, {dict}])
219 Funcref named reference to function {name}
220garbagecollect([{atexit}]) none free memory, breaking cyclic references
221get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
222get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
223get({func}, {what}) any get property of funcref/partial {func}
224getbufinfo([{buf}]) List information about buffers
225getbufline({buf}, {lnum} [, {end}])
226 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000227getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000228getbufvar({buf}, {varname} [, {def}])
229 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100230getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000231getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100233getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000234 get one character from the user
235getcharmod() Number modifiers for the last typed character
236getcharpos({expr}) List position of cursor, mark, etc.
237getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100238getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200239getcmdcomplpat() String return the completion pattern of the
240 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100241getcmdcompltype() String return the type of the current
242 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000244getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200245getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100246getcmdscreenpos() Number return cursor screen position in
247 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000248getcmdtype() String return current command-line type
249getcmdwintype() String return current command-line window type
250getcompletion({pat}, {type} [, {filtered}])
251 List list of cmdline completion matches
252getcurpos([{winnr}]) List position of the cursor
253getcursorcharpos([{winnr}]) List character position of the cursor
254getcwd([{winnr} [, {tabnr}]]) String get the current working directory
255getenv({name}) String return environment variable
256getfontname([{name}]) String name of font being used
257getfperm({fname}) String file permissions of file {fname}
258getfsize({fname}) Number size in bytes of file {fname}
259getftime({fname}) Number last modification time of file
260getftype({fname}) String description of type of file {fname}
261getimstatus() Number |TRUE| if the IME status is active
262getjumplist([{winnr} [, {tabnr}]])
263 List list of jump list items
264getline({lnum}) String line {lnum} of current buffer
265getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
266getloclist({nr}) List list of location list items
267getloclist({nr}, {what}) Dict get specific location list properties
268getmarklist([{buf}]) List list of global/local marks
269getmatches([{win}]) List list of current matches
270getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000271getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getpid() Number process ID of Vim
273getpos({expr}) List position of cursor, mark, etc.
274getqflist() List list of quickfix items
275getqflist({what}) Dict get specific quickfix list properties
276getreg([{regname} [, 1 [, {list}]]])
277 String or List contents of a register
278getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100279getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100280 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200281getregionpos({pos1}, {pos2} [, {opts}])
282 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100284getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100285getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286gettabinfo([{expr}]) List list of tab pages
287gettabvar({nr}, {varname} [, {def}])
288 any variable {varname} in tab {nr} or {def}
289gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
290 any {name} in {winnr} in tab page {tabnr}
291gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200292gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000294getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000295getwinposx() Number X coord in pixels of the Vim window
296getwinposy() Number Y coord in pixels of the Vim window
297getwinvar({nr}, {varname} [, {def}])
298 any variable {varname} in window {nr}
299glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
300 any expand file wildcards in {expr}
301glob2regpat({expr}) String convert a glob pat into a search pat
302globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
303 String do glob({expr}) for all dirs in {path}
304has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
305has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
306haslocaldir([{winnr} [, {tabnr}]])
307 Number |TRUE| if the window executed |:lcd|
308 or |:tcd|
309hasmapto({what} [, {mode} [, {abbr}]])
310 Number |TRUE| if mapping to {what} exists
311histadd({history}, {item}) Number add an item to a history
312histdel({history} [, {item}]) Number remove an item from a history
313histget({history} [, {index}]) String get the item {index} from a history
314histnr({history}) Number highest index of a history
315hlID({name}) Number syntax ID of highlight group {name}
316hlexists({name}) Number |TRUE| if highlight group {name} exists
317hlget([{name} [, {resolve}]]) List get highlight group attributes
318hlset({list}) Number set highlight group attributes
319hostname() String name of the machine Vim is running on
320iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200321id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000322indent({lnum}) Number indent of line {lnum}
323index({object}, {expr} [, {start} [, {ic}]])
324 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100325indexof({object}, {expr} [, {opts}]])
326 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327input({prompt} [, {text} [, {completion}]])
328 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100329inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330 String like input() but in a GUI dialog
331inputlist({textlist}) Number let the user pick from a choice list
332inputrestore() Number restore typeahead
333inputsave() Number save and clear typeahead
334inputsecret({prompt} [, {text}]) String like input() but hiding the text
335insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200336instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000337interrupt() none interrupt script execution
338invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100339isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000340isdirectory({directory}) Number |TRUE| if {directory} is a directory
341isinf({expr}) Number determine if {expr} is infinity value
342 (positive or negative)
343islocked({expr}) Number |TRUE| if {expr} is locked
344isnan({expr}) Number |TRUE| if {expr} is NaN
345items({dict}) List key-value pairs in {dict}
346job_getchannel({job}) Channel get the channel handle for {job}
347job_info([{job}]) Dict get information about {job}
348job_setoptions({job}, {options}) none set options for {job}
349job_start({command} [, {options}])
350 Job start a job
351job_status({job}) String get the status of {job}
352job_stop({job} [, {how}]) Number stop {job}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100353join({expr} [, {sep}]) String join items in {expr} into one String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000354js_decode({string}) any decode JS style JSON
355js_encode({expr}) String encode JS style JSON
356json_decode({string}) any decode JSON
357json_encode({expr}) String encode JSON
358keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100359keytrans({string}) String translate internal keycodes to a form
360 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000361len({expr}) Number the length of {expr}
362libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
363libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
364line({expr} [, {winid}]) Number line nr of cursor, last line or mark
365line2byte({lnum}) Number byte count of line {lnum}
366lispindent({lnum}) Number Lisp indent for line {lnum}
367list2blob({list}) Blob turn {list} of numbers into a Blob
368list2str({list} [, {utf8}]) String turn {list} of numbers into a String
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100369list2tuple({list}) Tuple turn {list} of items into a tuple
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000370listener_add({callback} [, {buf}])
371 Number add a callback to listen to changes
372listener_flush([{buf}]) none invoke listener callbacks
373listener_remove({id}) none remove a listener callback
374localtime() Number current time
375log({expr}) Float natural logarithm (base e) of {expr}
376log10({expr}) Float logarithm of Float {expr} to base 10
377luaeval({expr} [, {expr}]) any evaluate |Lua| expression
378map({expr1}, {expr2}) List/Dict/Blob/String
379 change each item in {expr1} to {expr2}
380maparg({name} [, {mode} [, {abbr} [, {dict}]]])
381 String or Dict
382 rhs of mapping {name} in mode {mode}
383mapcheck({name} [, {mode} [, {abbr}]])
384 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100385maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000386mapnew({expr1}, {expr2}) List/Dict/Blob/String
387 like |map()| but creates a new List or
388 Dictionary
389mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
390match({expr}, {pat} [, {start} [, {count}]])
391 Number position where {pat} matches in {expr}
392matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
393 Number highlight {pattern} with {group}
394matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
395 Number highlight positions with {group}
396matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100397matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
398 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000399matchdelete({id} [, {win}]) Number delete match identified by {id}
400matchend({expr}, {pat} [, {start} [, {count}]])
401 Number position where {pat} ends in {expr}
402matchfuzzy({list}, {str} [, {dict}])
403 List fuzzy match {str} in {list}
404matchfuzzypos({list}, {str} [, {dict}])
405 List fuzzy match {str} in {list}
406matchlist({expr}, {pat} [, {start} [, {count}]])
407 List match and submatches of {pat} in {expr}
408matchstr({expr}, {pat} [, {start} [, {count}]])
409 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100410matchstrlist({list}, {pat} [, {dict})
411 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000412matchstrpos({expr}, {pat} [, {start} [, {count}]])
413 List {count}'th match of {pat} in {expr}
414max({expr}) Number maximum value of items in {expr}
415menu_info({name} [, {mode}]) Dict get menu item information
416min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000417mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000418 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200419mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000420mzeval({expr}) any evaluate |MzScheme| expression
421nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100422ngettext({single}, {plural}, {number}[, {domain}])
423 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000424nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
425or({expr}, {expr}) Number bitwise OR
426pathshorten({expr} [, {len}]) String shorten directory names in a path
427perleval({expr}) any evaluate |Perl| expression
428popup_atcursor({what}, {options}) Number create popup window near the cursor
429popup_beval({what}, {options}) Number create popup window for 'ballooneval'
430popup_clear() none close all popup windows
431popup_close({id} [, {result}]) none close popup window {id}
432popup_create({what}, {options}) Number create a popup window
433popup_dialog({what}, {options}) Number create a popup window used as a dialog
434popup_filter_menu({id}, {key}) Number filter for a menu popup window
435popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100436popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000437popup_findinfo() Number get window ID of info popup window
438popup_findpreview() Number get window ID of preview popup window
439popup_getoptions({id}) Dict get options of popup window {id}
440popup_getpos({id}) Dict get position of popup window {id}
441popup_hide({id}) none hide popup menu {id}
442popup_list() List get a list of window IDs of all popups
443popup_locate({row}, {col}) Number get window ID of popup at position
444popup_menu({what}, {options}) Number create a popup window used as a menu
445popup_move({id}, {options}) none set position of popup window {id}
446popup_notification({what}, {options})
447 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200448popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000449popup_setoptions({id}, {options})
450 none set options for popup window {id}
451popup_settext({id}, {text}) none set the text of popup window {id}
452popup_show({id}) none unhide popup window {id}
453pow({x}, {y}) Float {x} to the power of {y}
454prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
455printf({fmt}, {expr1}...) String format text
456prompt_getprompt({buf}) String get prompt text
457prompt_setcallback({buf}, {expr}) none set prompt callback function
458prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
459prompt_setprompt({buf}, {text}) none set prompt text
460prop_add({lnum}, {col}, {props}) none add one text property
461prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
462 none add multiple text properties
463prop_clear({lnum} [, {lnum-end} [, {props}]])
464 none remove all text properties
465prop_find({props} [, {direction}])
466 Dict search for a text property
467prop_list({lnum} [, {props}]) List text properties in {lnum}
468prop_remove({props} [, {lnum} [, {lnum-end}]])
469 Number remove a text property
470prop_type_add({name}, {props}) none define a new property type
471prop_type_change({name}, {props})
472 none change an existing property type
473prop_type_delete({name} [, {props}])
474 none delete a property type
475prop_type_get({name} [, {props}])
476 Dict get property type values
477prop_type_list([{props}]) List get list of property types
478pum_getpos() Dict position and size of pum if visible
479pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100480py3eval({expr} [, {locals}]) any evaluate |python3| expression
481pyeval({expr} [, {locals}]) any evaluate |Python| expression
482pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000483rand([{expr}]) Number get pseudo-random number
484range({expr} [, {max} [, {stride}]])
485 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100486readblob({fname} [, {offset} [, {size}]])
487 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000488readdir({dir} [, {expr} [, {dict}]])
489 List file names in {dir} selected by {expr}
490readdirex({dir} [, {expr} [, {dict}]])
491 List file info in {dir} selected by {expr}
492readfile({fname} [, {type} [, {max}]])
493 List get list of lines from file {fname}
494reduce({object}, {func} [, {initial}])
495 any reduce {object} using {func}
496reg_executing() String get the executing register name
497reg_recording() String get the recording register name
498reltime([{start} [, {end}]]) List get time value
499reltimefloat({time}) Float turn the time value into a Float
500reltimestr({time}) String turn time value into a String
501remote_expr({server}, {string} [, {idvar} [, {timeout}]])
502 String send expression
503remote_foreground({server}) Number bring Vim server to the foreground
504remote_peek({serverid} [, {retvar}])
505 Number check for reply string
506remote_read({serverid} [, {timeout}])
507 String read reply string
508remote_send({server}, {string} [, {idvar}])
509 String send key sequence
510remote_startserver({name}) none become server {name}
511remove({list}, {idx} [, {end}]) any/List
512 remove items {idx}-{end} from {list}
513remove({blob}, {idx} [, {end}]) Number/Blob
514 remove bytes {idx}-{end} from {blob}
515remove({dict}, {key}) any remove entry {key} from {dict}
516rename({from}, {to}) Number rename (move) file from {from} to {to}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100517repeat({expr}, {count}) List/Tuple/Blob/String
Bakudankun375141e2022-09-09 18:46:47 +0100518 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000519resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100520reverse({obj}) List/Tuple/Blob/String
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100521 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000522round({expr}) Float round off {expr}
523rubyeval({expr}) any evaluate |Ruby| expression
524screenattr({row}, {col}) Number attribute at screen position
525screenchar({row}, {col}) Number character at screen position
526screenchars({row}, {col}) List List of characters at screen position
527screencol() Number current cursor column
528screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
529screenrow() Number current cursor row
530screenstring({row}, {col}) String characters at screen position
531search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
532 Number search for {pattern}
533searchcount([{options}]) Dict get or update search stats
534searchdecl({name} [, {global} [, {thisblock}]])
535 Number search for variable declaration
536searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
537 Number search for other end of start/end pair
538searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
539 List search for other end of start/end pair
540searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
541 List search for {pattern}
542server2client({clientid}, {string})
543 Number send reply string
544serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700545setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000546 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700547 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000548setbufvar({buf}, {varname}, {val})
549 none set {varname} in buffer {buf} to {val}
550setcellwidths({list}) none set character cell width overrides
551setcharpos({expr}, {list}) Number set the {expr} position to {list}
552setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100553setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000554setcmdpos({pos}) Number set cursor position in command-line
555setcursorcharpos({list}) Number move cursor to position in {list}
556setenv({name}, {val}) none set environment variable
557setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
558setline({lnum}, {line}) Number set line {lnum} to {line}
559setloclist({nr}, {list} [, {action}])
560 Number modify location list using {list}
561setloclist({nr}, {list}, {action}, {what})
562 Number modify specific location list props
563setmatches({list} [, {win}]) Number restore a list of matches
564setpos({expr}, {list}) Number set the {expr} position to {list}
565setqflist({list} [, {action}]) Number modify quickfix list using {list}
566setqflist({list}, {action}, {what})
567 Number modify specific quickfix list props
568setreg({n}, {v} [, {opt}]) Number set register to value and type
569settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
570settabwinvar({tabnr}, {winnr}, {varname}, {val})
571 none set {varname} in window {winnr} in tab
572 page {tabnr} to {val}
573settagstack({nr}, {dict} [, {action}])
574 Number modify tag stack using {dict}
575setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
576sha256({string}) String SHA256 checksum of {string}
577shellescape({string} [, {special}])
578 String escape {string} for use as shell
579 command argument
580shiftwidth([{col}]) Number effective value of 'shiftwidth'
581sign_define({name} [, {dict}]) Number define or update a sign
582sign_define({list}) List define or update a list of signs
583sign_getdefined([{name}]) List get a list of defined signs
584sign_getplaced([{buf} [, {dict}]])
585 List get a list of placed signs
586sign_jump({id}, {group}, {buf})
587 Number jump to a sign
588sign_place({id}, {group}, {name}, {buf} [, {dict}])
589 Number place a sign
590sign_placelist({list}) List place a list of signs
591sign_undefine([{name}]) Number undefine a sign
592sign_undefine({list}) List undefine a list of signs
593sign_unplace({group} [, {dict}])
594 Number unplace a sign
595sign_unplacelist({list}) List unplace a list of signs
596simplify({filename}) String simplify filename as much as possible
597sin({expr}) Float sine of {expr}
598sinh({expr}) Float hyperbolic sine of {expr}
599slice({expr}, {start} [, {end}]) String, List or Blob
600 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000601sort({list} [, {how} [, {dict}]])
602 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000603sound_clear() none stop playing all sounds
604sound_playevent({name} [, {callback}])
605 Number play an event sound
606sound_playfile({path} [, {callback}])
607 Number play sound file {path}
608sound_stop({id}) none stop playing sound {id}
609soundfold({word}) String sound-fold {word}
610spellbadword() String badly spelled word at cursor
611spellsuggest({word} [, {max} [, {capital}]])
612 List spelling suggestions
613split({expr} [, {pat} [, {keepempty}]])
614 List make |List| from {pat} separated {expr}
615sqrt({expr}) Float square root of {expr}
616srand([{expr}]) List get seed for |rand()|
617state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100618str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000619str2float({expr} [, {quoted}]) Float convert String to Float
620str2list({expr} [, {utf8}]) List convert each character of {expr} to
621 ASCII/UTF-8 value
622str2nr({expr} [, {base} [, {quoted}]])
623 Number convert String to Number
624strcharlen({expr}) Number character length of the String {expr}
625strcharpart({str}, {start} [, {len} [, {skipcc}]])
626 String {len} characters of {str} at
627 character {start}
628strchars({expr} [, {skipcc}]) Number character count of the String {expr}
629strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
630strftime({format} [, {time}]) String format time with a specified format
631strgetchar({str}, {index}) Number get char {index} from {str}
632stridx({haystack}, {needle} [, {start}])
633 Number index of {needle} in {haystack}
634string({expr}) String String representation of {expr} value
635strlen({expr}) Number length of the String {expr}
636strpart({str}, {start} [, {len} [, {chars}]])
637 String {len} bytes/chars of {str} at
638 byte {start}
639strptime({format}, {timestring})
640 Number Convert {timestring} to unix timestamp
641strridx({haystack}, {needle} [, {start}])
642 Number last index of {needle} in {haystack}
643strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100644strutf16len({string} [, {countcc}])
645 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000646strwidth({expr}) Number display cell length of the String {expr}
647submatch({nr} [, {list}]) String or List
648 specific match in ":s" or substitute()
649substitute({expr}, {pat}, {sub}, {flags})
650 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000651swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000652swapinfo({fname}) Dict information about swap file {fname}
653swapname({buf}) String swap file of buffer {buf}
654synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
655synIDattr({synID}, {what} [, {mode}])
656 String attribute {what} of syntax ID {synID}
657synIDtrans({synID}) Number translated syntax ID of {synID}
658synconcealed({lnum}, {col}) List info about concealing
659synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
660system({expr} [, {input}]) String output of shell command/filter {expr}
661systemlist({expr} [, {input}]) List output of shell command/filter {expr}
662tabpagebuflist([{arg}]) List list of buffer numbers in tab page
663tabpagenr([{arg}]) Number number of current or last tab page
664tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
665tagfiles() List tags files used
666taglist({expr} [, {filename}]) List list of tags matching {expr}
667tan({expr}) Float tangent of {expr}
668tanh({expr}) Float hyperbolic tangent of {expr}
669tempname() String name for a temporary file
670term_dumpdiff({filename}, {filename} [, {options}])
671 Number display difference between two dumps
672term_dumpload({filename} [, {options}])
673 Number displaying a screen dump
674term_dumpwrite({buf}, {filename} [, {options}])
675 none dump terminal window contents
676term_getaltscreen({buf}) Number get the alternate screen flag
677term_getansicolors({buf}) List get ANSI palette in GUI color mode
678term_getattr({attr}, {what}) Number get the value of attribute {what}
679term_getcursor({buf}) List get the cursor position of a terminal
680term_getjob({buf}) Job get the job associated with a terminal
681term_getline({buf}, {row}) String get a line of text from a terminal
682term_getscrolled({buf}) Number get the scroll count of a terminal
683term_getsize({buf}) List get the size of a terminal
684term_getstatus({buf}) String get the status of a terminal
685term_gettitle({buf}) String get the title of a terminal
686term_gettty({buf}, [{input}]) String get the tty name of a terminal
687term_list() List get the list of terminal buffers
688term_scrape({buf}, {row}) List get row of a terminal screen
689term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
690term_setansicolors({buf}, {colors})
691 none set ANSI palette in GUI color mode
692term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
693term_setkill({buf}, {how}) none set signal to stop job in terminal
694term_setrestore({buf}, {command}) none set command to restore terminal
695term_setsize({buf}, {rows}, {cols})
696 none set the size of a terminal
697term_start({cmd} [, {options}]) Number open a terminal window and run a job
698term_wait({buf} [, {time}]) Number wait for screen to be updated
699terminalprops() Dict properties of the terminal
700test_alloc_fail({id}, {countdown}, {repeat})
701 none make memory allocation fail
702test_autochdir() none enable 'autochdir' during startup
703test_feedinput({string}) none add key sequence to input buffer
704test_garbagecollect_now() none free memory right now for testing
705test_garbagecollect_soon() none free memory soon for testing
706test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000707test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000709test_mswin_event({event}, {args})
710 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_null_blob() Blob null value for testing
712test_null_channel() Channel null value for testing
713test_null_dict() Dict null value for testing
714test_null_function() Funcref null value for testing
715test_null_job() Job null value for testing
716test_null_list() List null value for testing
717test_null_partial() Funcref null value for testing
718test_null_string() String null value for testing
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100719test_null_tuple() Tuple null value for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000720test_option_not_set({name}) none reset flag indicating option was set
721test_override({expr}, {val}) none test with Vim internal overrides
722test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000723test_setmouse({row}, {col}) none set the mouse position for testing
724test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200725test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726test_unknown() any unknown value for testing
727test_void() any void value for testing
728timer_info([{id}]) List information about timers
729timer_pause({id}, {pause}) none pause or unpause a timer
730timer_start({time}, {callback} [, {options}])
731 Number create a timer
732timer_stop({timer}) none stop a timer
733timer_stopall() none stop all timers
734tolower({expr}) String the String {expr} switched to lowercase
735toupper({expr}) String the String {expr} switched to uppercase
736tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
737 to chars in {tostr}
738trim({text} [, {mask} [, {dir}]])
739 String trim characters in {mask} from {text}
740trunc({expr}) Float truncate Float {expr}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100741tuple2list({tuple}) List turn {tuple} of items into a list
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000742type({expr}) Number type of value {expr}
743typename({expr}) String representation of the type of {expr}
744undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500745undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000746uniq({list} [, {func} [, {dict}]])
747 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100748utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
749 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000750values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200751virtcol({expr} [, {list} [, {winid}])
752 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100753 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100754virtcol2col({winid}, {lnum}, {col})
755 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200756visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000757wildmenumode() Number whether 'wildmenu' mode is active
758win_execute({id}, {command} [, {silent}])
759 String execute {command} in window {id}
760win_findbuf({bufnr}) List find windows containing {bufnr}
761win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
762win_gettype([{nr}]) String type of window {nr}
763win_gotoid({expr}) Number go to window with ID {expr}
764win_id2tabwin({expr}) List get tab and window nr from window ID
765win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000766win_move_separator({nr}) Number move window vertical separator
767win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000768win_screenpos({nr}) List get screen position of window {nr}
769win_splitmove({nr}, {target} [, {options}])
770 Number move window {nr} to split of {target}
771winbufnr({nr}) Number buffer number of window {nr}
772wincol() Number window column of the cursor
773windowsversion() String MS-Windows OS version
774winheight({nr}) Number height of window {nr}
775winlayout([{tabnr}]) List layout of windows in tab {tabnr}
776winline() Number window line of the cursor
777winnr([{expr}]) Number number of current window
778winrestcmd() String returns command to restore window sizes
779winrestview({dict}) none restore view of current window
780winsaveview() Dict save view of current window
781winwidth({nr}) Number width of window {nr}
782wordcount() Dict get byte/char/word statistics
783writefile({object}, {fname} [, {flags}])
784 Number write |Blob| or |List| of lines to file
785xor({expr}, {expr}) Number bitwise XOR
786
787==============================================================================
7882. Details *builtin-function-details*
789
790Not all functions are here, some have been moved to a help file covering the
791specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200792Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000793
794abs({expr}) *abs()*
795 Return the absolute value of {expr}. When {expr} evaluates to
796 a |Float| abs() returns a |Float|. When {expr} can be
797 converted to a |Number| abs() returns a |Number|. Otherwise
798 abs() gives an error message and returns -1.
799 Examples: >
800 echo abs(1.456)
801< 1.456 >
802 echo abs(-5.456)
803< 5.456 >
804 echo abs(-4)
805< 4
806
807 Can also be used as a |method|: >
808 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200809<
810 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812
813acos({expr}) *acos()*
814 Return the arc cosine of {expr} measured in radians, as a
815 |Float| in the range of [0, pi].
816 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100817 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000818 Examples: >
819 :echo acos(0)
820< 1.570796 >
821 :echo acos(-0.5)
822< 2.094395
823
824 Can also be used as a |method|: >
825 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200826<
827 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000829
830add({object}, {expr}) *add()*
831 Append the item {expr} to |List| or |Blob| {object}. Returns
832 the resulting |List| or |Blob|. Examples: >
833 :let alist = add([1, 2, 3], item)
834 :call add(mylist, "woodstock")
835< Note that when {expr} is a |List| it is appended as a single
836 item. Use |extend()| to concatenate |Lists|.
837 When {object} is a |Blob| then {expr} must be a number.
838 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100839 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000840
841 Can also be used as a |method|: >
842 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200843<
844 Return type: list<{type}> (depending on the given |List|) or
845 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846
847
848and({expr}, {expr}) *and()*
849 Bitwise AND on the two arguments. The arguments are converted
850 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100851 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000852 Example: >
853 :let flag = and(bits, 0x80)
854< Can also be used as a |method|: >
855 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200856<
857 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000858
859
860append({lnum}, {text}) *append()*
861 When {text} is a |List|: Append each item of the |List| as a
862 text line below line {lnum} in the current buffer.
863 Otherwise append {text} as one text line below line {lnum} in
864 the current buffer.
865 Any type of item is accepted and converted to a String.
866 {lnum} can be zero to insert a line before the first one.
867 {lnum} is used like with |getline()|.
868 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000869 0 for success. When {text} is an empty list zero is returned,
870 no matter the value of {lnum}.
871 In |Vim9| script an invalid argument or negative number
872 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000873 :let failed = append(line('$'), "# THE END")
874 :let failed = append(0, ["Chapter 1", "the beginning"])
875
876< Can also be used as a |method| after a List, the base is
877 passed as the second argument: >
878 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200879<
880 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000881
882
883appendbufline({buf}, {lnum}, {text}) *appendbufline()*
884 Like |append()| but append the text in buffer {buf}.
885
886 This function works only for loaded buffers. First call
887 |bufload()| if needed.
888
889 For the use of {buf}, see |bufname()|.
890
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000891 {lnum} is the line number to append below. Note that using
892 |line()| would use the current buffer, not the one appending
893 to. Use "$" to append at the end of the buffer. Other string
894 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895
896 On success 0 is returned, on failure 1 is returned.
897 In |Vim9| script an error is given for an invalid {lnum}.
898
899 If {buf} is not a valid buffer or {lnum} is not valid, an
900 error message is given. Example: >
901 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000902< However, when {text} is an empty list then no error is given
903 for an invalid {lnum}, since {lnum} isn't actually used.
904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905 Can also be used as a |method| after a List, the base is
906 passed as the second argument: >
907 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200908<
909 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910
911
912argc([{winid}]) *argc()*
913 The result is the number of files in the argument list. See
914 |arglist|.
915 If {winid} is not supplied, the argument list of the current
916 window is used.
917 If {winid} is -1, the global argument list is used.
918 Otherwise {winid} specifies the window of which the argument
919 list is used: either the window number or the window ID.
920 Returns -1 if the {winid} argument is invalid.
921
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200922 Return type: |Number|
923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924 *argidx()*
925argidx() The result is the current index in the argument list. 0 is
926 the first file. argc() - 1 is the last one. See |arglist|.
927
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200928 Return type: |Number|
929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000930 *arglistid()*
931arglistid([{winnr} [, {tabnr}]])
932 Return the argument list ID. This is a number which
933 identifies the argument list being used. Zero is used for the
934 global argument list. See |arglist|.
935 Returns -1 if the arguments are invalid.
936
937 Without arguments use the current window.
938 With {winnr} only use this window in the current tab page.
939 With {winnr} and {tabnr} use the window in the specified tab
940 page.
941 {winnr} can be the window number or the |window-ID|.
942
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200943 Return type: |Number|
944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000945 *argv()*
946argv([{nr} [, {winid}]])
947 The result is the {nr}th file in the argument list. See
948 |arglist|. "argv(0)" is the first one. Example: >
949 :let i = 0
950 :while i < argc()
951 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000952 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000953 : let i = i + 1
954 :endwhile
955< Without the {nr} argument, or when {nr} is -1, a |List| with
956 the whole |arglist| is returned.
957
958 The {winid} argument specifies the window ID, see |argc()|.
959 For the Vim command line arguments see |v:argv|.
960
Bram Moolenaar016188f2022-06-06 20:52:59 +0100961 Returns an empty string if {nr}th argument is not present in
962 the argument list. Returns an empty List if the {winid}
963 argument is invalid.
964
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200965 Return type: |String|
966
967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000968asin({expr}) *asin()*
969 Return the arc sine of {expr} measured in radians, as a |Float|
970 in the range of [-pi/2, pi/2].
971 {expr} must evaluate to a |Float| or a |Number| in the range
972 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100973 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
974 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000975 Examples: >
976 :echo asin(0.8)
977< 0.927295 >
978 :echo asin(-0.5)
979< -0.523599
980
981 Can also be used as a |method|: >
982 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200983<
984 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000985
986assert_ functions are documented here: |assert-functions-details|
987
988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000989atan({expr}) *atan()*
990 Return the principal value of the arc tangent of {expr}, in
991 the range [-pi/2, +pi/2] radians, as a |Float|.
992 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100993 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000994 Examples: >
995 :echo atan(100)
996< 1.560797 >
997 :echo atan(-4.01)
998< -1.326405
999
1000 Can also be used as a |method|: >
1001 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001002<
1003 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001004
1005
1006atan2({expr1}, {expr2}) *atan2()*
1007 Return the arc tangent of {expr1} / {expr2}, measured in
1008 radians, as a |Float| in the range [-pi, pi].
1009 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001010 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1011 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001012 Examples: >
1013 :echo atan2(-1, 1)
1014< -0.785398 >
1015 :echo atan2(1, -1)
1016< 2.356194
1017
1018 Can also be used as a |method|: >
1019 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001020<
1021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001022
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001023
1024autocmd_add({acmds}) *autocmd_add()*
1025 Adds a List of autocmds and autocmd groups.
1026
1027 The {acmds} argument is a List where each item is a Dict with
1028 the following optional items:
1029 bufnr buffer number to add a buffer-local autocmd.
1030 If this item is specified, then the "pattern"
1031 item is ignored.
1032 cmd Ex command to execute for this autocmd event
1033 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001034 This can be either a String with a single
1035 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001036 group autocmd group name. Refer to |autocmd-groups|.
1037 If this group doesn't exist then it is
1038 created. If not specified or empty, then the
1039 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001040 nested boolean flag, set to v:true to add a nested
1041 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001042 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001043 which executes only once. Refer to
1044 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001045 pattern autocmd pattern string. Refer to
1046 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001047 present, then this item is ignored. This can
1048 be a String with a single pattern or a List of
1049 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001050 replace boolean flag, set to v:true to remove all the
1051 commands associated with the specified autocmd
1052 event and group and add the {cmd}. This is
1053 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001054 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001055
1056 Returns v:true on success and v:false on failure.
1057 Examples: >
1058 " Create a buffer-local autocmd for buffer 5
1059 let acmd = {}
1060 let acmd.group = 'MyGroup'
1061 let acmd.event = 'BufEnter'
1062 let acmd.bufnr = 5
1063 let acmd.cmd = 'call BufEnterFunc()'
1064 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001065<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001066 Can also be used as a |method|: >
1067 GetAutocmdList()->autocmd_add()
1068<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001069 Return type: |vim9-boolean|
1070
1071
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001072autocmd_delete({acmds}) *autocmd_delete()*
1073 Deletes a List of autocmds and autocmd groups.
1074
1075 The {acmds} argument is a List where each item is a Dict with
1076 the following optional items:
1077 bufnr buffer number to delete a buffer-local autocmd.
1078 If this item is specified, then the "pattern"
1079 item is ignored.
1080 cmd Ex command for this autocmd event
1081 event autocmd event name. Refer to |autocmd-events|.
1082 If '*' then all the autocmd events in this
1083 group are deleted.
1084 group autocmd group name. Refer to |autocmd-groups|.
1085 If not specified or empty, then the default
1086 group is used.
1087 nested set to v:true for a nested autocmd.
1088 Refer to |autocmd-nested|.
1089 once set to v:true for an autocmd which executes
1090 only once. Refer to |autocmd-once|.
1091 pattern autocmd pattern string. Refer to
1092 |autocmd-patterns|. If "bufnr" item is
1093 present, then this item is ignored.
1094
1095 If only {group} is specified in a {acmds} entry and {event},
1096 {pattern} and {cmd} are not specified, then that autocmd group
1097 is deleted.
1098
Bram Moolenaar016188f2022-06-06 20:52:59 +01001099 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001100 Examples: >
1101 " :autocmd! BufLeave *.vim
1102 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1103 call autocmd_delete([acmd]})
1104 " :autocmd! MyGroup1 BufLeave
1105 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1106 call autocmd_delete([acmd])
1107 " :autocmd! MyGroup2 BufEnter *.c
1108 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1109 \ pattern: '*.c'}
1110 " :autocmd! MyGroup2 * *.c
1111 let acmd = #{group: 'MyGroup2', event: '*',
1112 \ pattern: '*.c'}
1113 call autocmd_delete([acmd])
1114 " :autocmd! MyGroup3
1115 let acmd = #{group: 'MyGroup3'}
1116 call autocmd_delete([acmd])
1117<
1118 Can also be used as a |method|: >
1119 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001120<
1121 Return type: |vim9-boolean|
1122
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001123
1124autocmd_get([{opts}]) *autocmd_get()*
1125 Returns a |List| of autocmds. If {opts} is not supplied, then
1126 returns the autocmds for all the events in all the groups.
1127
1128 The optional {opts} Dict argument supports the following
1129 items:
1130 group Autocmd group name. If specified, returns only
1131 the autocmds defined in this group. If the
1132 specified group doesn't exist, results in an
1133 error message. If set to an empty string,
1134 then the default autocmd group is used.
1135 event Autocmd event name. If specified, returns only
1136 the autocmds defined for this event. If set
1137 to "*", then returns autocmds for all the
1138 events. If the specified event doesn't exist,
1139 results in an error message.
1140 pattern Autocmd pattern. If specified, returns only
1141 the autocmds defined for this pattern.
1142 A combination of the above three times can be supplied in
1143 {opts}.
1144
1145 Each Dict in the returned List contains the following items:
1146 bufnr For buffer-local autocmds, buffer number where
1147 the autocmd is defined.
1148 cmd Command executed for this autocmd.
1149 event Autocmd event name.
1150 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001151 nested Boolean flag, set to v:true for a nested
1152 autocmd. See |autocmd-nested|.
1153 once Boolean flag, set to v:true, if the autocmd
1154 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001155 pattern Autocmd pattern. For a buffer-local
1156 autocmd, this will be of the form "<buffer=n>".
1157 If there are multiple commands for an autocmd event in a
1158 group, then separate items are returned for each command.
1159
Bram Moolenaar016188f2022-06-06 20:52:59 +01001160 Returns an empty List if an autocmd with the specified group
1161 or event or pattern is not found.
1162
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001163 Examples: >
1164 " :autocmd MyGroup
1165 echo autocmd_get(#{group: 'Mygroup'})
1166 " :autocmd G BufUnload
1167 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1168 " :autocmd G * *.ts
1169 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1170 echo autocmd_get(acmd)
1171 " :autocmd Syntax
1172 echo autocmd_get(#{event: 'Syntax'})
1173 " :autocmd G BufEnter *.ts
1174 let acmd = #{group: 'G', event: 'BufEnter',
1175 \ pattern: '*.ts'}
1176 echo autocmd_get(acmd)
1177<
1178 Can also be used as a |method|: >
1179 Getopts()->autocmd_get()
1180<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001181 Return type: list<dict<any>>
1182
1183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001184balloon_gettext() *balloon_gettext()*
1185 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001186 not used for the List. Returns an empty string if balloon
1187 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001188
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001189 Return type: |String|
1190
1191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001192balloon_show({expr}) *balloon_show()*
1193 Show {expr} inside the balloon. For the GUI {expr} is used as
1194 a string. For a terminal {expr} can be a list, which contains
1195 the lines of the balloon. If {expr} is not a list it will be
1196 split with |balloon_split()|.
1197 If {expr} is an empty string any existing balloon is removed.
1198
1199 Example: >
1200 func GetBalloonContent()
1201 " ... initiate getting the content
1202 return ''
1203 endfunc
1204 set balloonexpr=GetBalloonContent()
1205
1206 func BalloonCallback(result)
1207 call balloon_show(a:result)
1208 endfunc
1209< Can also be used as a |method|: >
1210 GetText()->balloon_show()
1211<
1212 The intended use is that fetching the content of the balloon
1213 is initiated from 'balloonexpr'. It will invoke an
1214 asynchronous method, in which a callback invokes
1215 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001216 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001217
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001218 When showing a balloon is not possible then nothing happens,
1219 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001220 {only available when compiled with the |+balloon_eval| or
1221 |+balloon_eval_term| feature}
1222
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001223 Return type: |Number|
1224
1225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001226balloon_split({msg}) *balloon_split()*
1227 Split String {msg} into lines to be displayed in a balloon.
1228 The splits are made for the current window size and optimize
1229 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001230 Returns a |List| with the split lines. Returns an empty List
1231 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001232 Can also be used as a |method|: >
1233 GetText()->balloon_split()->balloon_show()
1234
1235< {only available when compiled with the |+balloon_eval_term|
1236 feature}
1237
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001238 Return type: list<any> or list<string>
1239
h-easte80f3452025-01-02 10:40:29 +01001240base64_decode({string}) *base64_decode()*
1241 Return a Blob containing the bytes decoded from the base64
1242 encoded characters in {string}.
1243
1244 The {string} argument should contain only base64-encoded
1245 characters and should have a length that is a multiple of 4.
1246
1247 Returns an empty blob on error.
1248
1249 Examples: >
1250 " Write the decoded contents to a binary file
1251 call writefile(base64_decode(s), 'tools.bmp')
1252 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001253 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001254<
1255 Can also be used as a |method|: >
1256 GetEncodedString()->base64_decode()
1257<
1258 Return type: |Blob|
1259
1260
1261base64_encode({blob}) *base64_encode()*
1262 Return a base64-encoded String representing the bytes in
1263 {blob}. The base64 alphabet defined in RFC 4648 is used.
1264
1265 Examples: >
1266 " Encode the contents of a binary file
1267 echo base64_encode(readblob('somefile.bin'))
1268 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001269 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001270<
1271 Can also be used as a |method|: >
1272 GetBinaryData()->base64_encode()
1273<
1274 Return type: |String|
1275
1276
Christ van Willegence0ef912024-06-20 23:41:59 +02001277bindtextdomain({package}, {path}) *bindtextdomain()*
1278 Bind a specific {package} to a {path} so that the
1279 |gettext()| function can be used to get language-specific
1280 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001281 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001282
Christ van Willegen8252ef12024-07-11 21:36:21 +02001283 Returns v:true on success and v:false on failure (out of
1284 memory).
1285
1286 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001288blob2list({blob}) *blob2list()*
1289 Return a List containing the number value of each byte in Blob
1290 {blob}. Examples: >
1291 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1292 blob2list(0z) returns []
1293< Returns an empty List on error. |list2blob()| does the
1294 opposite.
1295
1296 Can also be used as a |method|: >
1297 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001299 Return type: list<any> or list<number>
1300
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001301
1302blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001303 Return a List of Strings in the current 'encoding' by
1304 converting the bytes in {blob} into characters.
1305
1306 Each <NL> byte in the blob is interpreted as the end of a
1307 string and a new list item is added. Each <NUL> byte in the
1308 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001309
1310 If {options} is not supplied, the current 'encoding' value is
1311 used to decode the bytes in {blob}.
1312
1313 The argument {options} is a |Dict| and supports the following
1314 items:
1315 encoding Decode the bytes in {blob} using this
1316 encoding. The value is a |String|. See
Bakudankunb3854bf2025-02-23 20:29:21 +01001317 |encoding-names| for the supported values
1318 (plus the special value "none").
Christian Brabandtd5afc742025-03-18 20:55:42 +01001319 *E1515* *E1516*
Bakudankunb3854bf2025-02-23 20:29:21 +01001320 When current 'encoding' is "utf-8", an error is given and an
1321 empty List is returned if an invalid byte sequence is
1322 encountered in {blob}. To suppress this validation and get
1323 potentially invalid string, set "encoding" in {options} to
1324 "none".
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001325
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001326 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001327
1328 See also |str2blob()|
1329
1330 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +01001331 blob2str(0z6162) returns ['ab']
1332 blob2str(0zC2ABC2BB) returns ['«»']
1333 blob2str(0z610A62) returns ['a', 'b']
1334 blob2str(0z610062) returns ['a\nb']
1335 blob2str(0zABBB, {'encoding': 'latin1'}) returns ['«»']
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001336<
1337 Can also be used as a |method|: >
1338 GetBlob()->blob2str()
1339<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001340 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001341
1342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001343 *browse()*
1344browse({save}, {title}, {initdir}, {default})
1345 Put up a file requester. This only works when "has("browse")"
1346 returns |TRUE| (only in some GUI versions).
1347 The input fields are:
1348 {save} when |TRUE|, select file to write
1349 {title} title for the requester
1350 {initdir} directory to start browsing in
1351 {default} default file name
1352 An empty string is returned when the "Cancel" button is hit,
1353 something went wrong, or browsing is not possible.
1354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001355 Return type: |String|
1356
1357
1358browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001359 Put up a directory requester. This only works when
1360 "has("browse")" returns |TRUE| (only in some GUI versions).
1361 On systems where a directory browser is not supported a file
1362 browser is used. In that case: select a file in the directory
1363 to be used.
1364 The input fields are:
1365 {title} title for the requester
1366 {initdir} directory to start browsing in
1367 When the "Cancel" button is hit, something went wrong, or
1368 browsing is not possible, an empty string is returned.
1369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001370 Return type: |String|
1371
1372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001373bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001374 Add a buffer to the buffer list with name {name} (must be a
1375 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001376 If a buffer for file {name} already exists, return that buffer
1377 number. Otherwise return the buffer number of the newly
1378 created buffer. When {name} is an empty string then a new
1379 buffer is always created.
1380 The buffer will not have 'buflisted' set and not be loaded
1381 yet. To add some text to the buffer use this: >
1382 let bufnr = bufadd('someName')
1383 call bufload(bufnr)
1384 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001385< Returns 0 on error.
1386 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001387 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001388<
1389 Return type: |Number|
1390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001391
1392bufexists({buf}) *bufexists()*
1393 The result is a Number, which is |TRUE| if a buffer called
1394 {buf} exists.
1395 If the {buf} argument is a number, buffer numbers are used.
1396 Number zero is the alternate buffer for the current window.
1397
1398 If the {buf} argument is a string it must match a buffer name
1399 exactly. The name can be:
1400 - Relative to the current directory.
1401 - A full path.
1402 - The name of a buffer with 'buftype' set to "nofile".
1403 - A URL name.
1404 Unlisted buffers will be found.
1405 Note that help files are listed by their short name in the
1406 output of |:buffers|, but bufexists() requires using their
1407 long name to be able to find them.
1408 bufexists() may report a buffer exists, but to use the name
1409 with a |:buffer| command you may need to use |expand()|. Esp
1410 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1411 Use "bufexists(0)" to test for the existence of an alternate
1412 file name.
1413
1414 Can also be used as a |method|: >
1415 let exists = 'somename'->bufexists()
1416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417 Return type: |Number|
1418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001419 Obsolete name: buffer_exists(). *buffer_exists()*
1420
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001422buflisted({buf}) *buflisted()*
1423 The result is a Number, which is |TRUE| if a buffer called
1424 {buf} exists and is listed (has the 'buflisted' option set).
1425 The {buf} argument is used like with |bufexists()|.
1426
1427 Can also be used as a |method|: >
1428 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001429<
1430 Return type: |Number|
1431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001432
1433bufload({buf}) *bufload()*
1434 Ensure the buffer {buf} is loaded. When the buffer name
1435 refers to an existing file then the file is read. Otherwise
1436 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001437 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001438 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001439 If there is an existing swap file for the file of the buffer,
1440 there will be no dialog, the buffer will be loaded anyway.
1441 The {buf} argument is used like with |bufexists()|.
1442
1443 Can also be used as a |method|: >
1444 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001445<
1446 Return type: |Number|
1447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001448
1449bufloaded({buf}) *bufloaded()*
1450 The result is a Number, which is |TRUE| if a buffer called
1451 {buf} exists and is loaded (shown in a window or hidden).
1452 The {buf} argument is used like with |bufexists()|.
1453
1454 Can also be used as a |method|: >
1455 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001456<
1457 Return type: |Number|
1458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001459
1460bufname([{buf}]) *bufname()*
1461 The result is the name of a buffer. Mostly as it is displayed
1462 by the `:ls` command, but not using special names such as
1463 "[No Name]".
1464 If {buf} is omitted the current buffer is used.
1465 If {buf} is a Number, that buffer number's name is given.
1466 Number zero is the alternate buffer for the current window.
1467 If {buf} is a String, it is used as a |file-pattern| to match
1468 with the buffer names. This is always done like 'magic' is
1469 set and 'cpoptions' is empty. When there is more than one
1470 match an empty string is returned.
1471 "" or "%" can be used for the current buffer, "#" for the
1472 alternate buffer.
1473 A full match is preferred, otherwise a match at the start, end
1474 or middle of the buffer name is accepted. If you only want a
1475 full match then put "^" at the start and "$" at the end of the
1476 pattern.
1477 Listed buffers are found first. If there is a single match
1478 with a listed buffer, that one is returned. Next unlisted
1479 buffers are searched for.
1480 If the {buf} is a String, but you want to use it as a buffer
1481 number, force it to be a Number by adding zero to it: >
1482 :echo bufname("3" + 0)
1483< Can also be used as a |method|: >
1484 echo bufnr->bufname()
1485
1486< If the buffer doesn't exist, or doesn't have a name, an empty
1487 string is returned. >
1488 bufname("#") alternate buffer name
1489 bufname(3) name of buffer 3
1490 bufname("%") name of current buffer
1491 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001492<
1493 Return type: |String|
1494 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001495 Obsolete name: buffer_name().
1496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001497
1498bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499 The result is the number of a buffer, as it is displayed by
1500 the `:ls` command. For the use of {buf}, see |bufname()|
1501 above.
1502
1503 If the buffer doesn't exist, -1 is returned. Or, if the
1504 {create} argument is present and TRUE, a new, unlisted,
1505 buffer is created and its number is returned. Example: >
1506 let newbuf = bufnr('Scratch001', 1)
1507< Using an empty name uses the current buffer. To create a new
1508 buffer with an empty name use |bufadd()|.
1509
1510 bufnr("$") is the last buffer: >
1511 :let last_buffer = bufnr("$")
1512< The result is a Number, which is the highest buffer number
1513 of existing buffers. Note that not all buffers with a smaller
1514 number necessarily exist, because ":bwipeout" may have removed
1515 them. Use bufexists() to test for the existence of a buffer.
1516
1517 Can also be used as a |method|: >
1518 echo bufref->bufnr()
1519<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001520 Return type: |Number|
1521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522 Obsolete name: buffer_number(). *buffer_number()*
1523 *last_buffer_nr()*
1524 Obsolete name for bufnr("$"): last_buffer_nr().
1525
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001527bufwinid({buf}) *bufwinid()*
1528 The result is a Number, which is the |window-ID| of the first
1529 window associated with buffer {buf}. For the use of {buf},
1530 see |bufname()| above. If buffer {buf} doesn't exist or
1531 there is no such window, -1 is returned. Example: >
1532
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001533 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001534<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001535 Only deals with the current tab page. See |win_findbuf()| for
1536 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001537
1538 Can also be used as a |method|: >
1539 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001540<
1541 Return type: |Number|
1542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001543
1544bufwinnr({buf}) *bufwinnr()*
1545 Like |bufwinid()| but return the window number instead of the
1546 |window-ID|.
1547 If buffer {buf} doesn't exist or there is no such window, -1
1548 is returned. Example: >
1549
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001550 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001551
1552< The number can be used with |CTRL-W_w| and ":wincmd w"
1553 |:wincmd|.
1554
1555 Can also be used as a |method|: >
1556 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001557<
1558 Return type: |Number|
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560
1561byte2line({byte}) *byte2line()*
1562 Return the line number that contains the character at byte
1563 count {byte} in the current buffer. This includes the
1564 end-of-line character, depending on the 'fileformat' option
1565 for the current buffer. The first character has byte count
1566 one.
1567 Also see |line2byte()|, |go| and |:goto|.
1568
Bram Moolenaar016188f2022-06-06 20:52:59 +01001569 Returns -1 if the {byte} value is invalid.
1570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001571 Can also be used as a |method|: >
1572 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001573<
1574 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001576 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577 feature}
1578
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001579
Christian Brabandt67672ef2023-04-24 21:09:54 +01001580byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581 Return byte index of the {nr}'th character in the String
1582 {expr}. Use zero for the first character, it then returns
1583 zero.
1584 If there are no multibyte characters the returned value is
1585 equal to {nr}.
1586 Composing characters are not counted separately, their byte
1587 length is added to the preceding base character. See
1588 |byteidxcomp()| below for counting composing characters
1589 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001590 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1591 index in the String {expr} instead of as the character index.
1592 The UTF-16 index is the index in the string when it is encoded
1593 with 16-bit words. If the specified UTF-16 index is in the
1594 middle of a character (e.g. in a 4-byte character), then the
1595 byte index of the first byte in the character is returned.
1596 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001597 Example : >
1598 echo matchstr(str, ".", byteidx(str, 3))
1599< will display the fourth character. Another way to do the
1600 same: >
1601 let s = strpart(str, byteidx(str, 3))
1602 echo strpart(s, 0, byteidx(s, 1))
1603< Also see |strgetchar()| and |strcharpart()|.
1604
1605 If there are less than {nr} characters -1 is returned.
1606 If there are exactly {nr} characters the length of the string
1607 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001608 See |charidx()| and |utf16idx()| for getting the character and
1609 UTF-16 index respectively from the byte index.
1610 Examples: >
1611 echo byteidx('a😊😊', 2) returns 5
1612 echo byteidx('a😊😊', 2, 1) returns 1
1613 echo byteidx('a😊😊', 3, 1) returns 5
1614<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001615 Can also be used as a |method|: >
1616 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001617<
1618 Return type: |Number|
1619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620
Christian Brabandt67672ef2023-04-24 21:09:54 +01001621byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622 Like byteidx(), except that a composing character is counted
1623 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001624 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001625 echo byteidx(s, 1)
1626 echo byteidxcomp(s, 1)
1627 echo byteidxcomp(s, 2)
1628< The first and third echo result in 3 ('e' plus composing
1629 character is 3 bytes), the second echo results in 1 ('e' is
1630 one byte).
1631 Only works differently from byteidx() when 'encoding' is set
1632 to a Unicode encoding.
1633
1634 Can also be used as a |method|: >
1635 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001636<
1637 Return type: |Number|
1638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001639
1640call({func}, {arglist} [, {dict}]) *call()* *E699*
1641 Call function {func} with the items in |List| {arglist} as
1642 arguments.
1643 {func} can either be a |Funcref| or the name of a function.
1644 a:firstline and a:lastline are set to the cursor line.
1645 Returns the return value of the called function.
1646 {dict} is for functions with the "dict" attribute. It will be
1647 used to set the local variable "self". |Dictionary-function|
1648
1649 Can also be used as a |method|: >
1650 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001651<
1652 Return type: any, depending on {func}
1653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001654
1655ceil({expr}) *ceil()*
1656 Return the smallest integral value greater than or equal to
1657 {expr} as a |Float| (round up).
1658 {expr} must evaluate to a |Float| or a |Number|.
1659 Examples: >
1660 echo ceil(1.456)
1661< 2.0 >
1662 echo ceil(-5.456)
1663< -5.0 >
1664 echo ceil(4.0)
1665< 4.0
1666
Bram Moolenaar016188f2022-06-06 20:52:59 +01001667 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 Can also be used as a |method|: >
1670 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001671<
1672 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
1674
1675ch_ functions are documented here: |channel-functions-details|
1676
1677
1678changenr() *changenr()*
1679 Return the number of the most recent change. This is the same
1680 number as what is displayed with |:undolist| and can be used
1681 with the |:undo| command.
1682 When a change was made it is the number of that change. After
1683 redo it is the number of the redone change. After undo it is
1684 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001685 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001687 Return type: |Number|
1688
1689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001691 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001692 Examples: >
1693 char2nr(" ") returns 32
1694 char2nr("ABC") returns 65
1695< When {utf8} is omitted or zero, the current 'encoding' is used.
1696 Example for "utf-8": >
1697 char2nr("á") returns 225
1698 char2nr("á"[0]) returns 195
1699< When {utf8} is TRUE, always treat as UTF-8 characters.
1700 A combining character is a separate character.
1701 |nr2char()| does the opposite.
1702 To turn a string into a list of character numbers: >
1703 let str = "ABC"
1704 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1705< Result: [65, 66, 67]
1706
Bram Moolenaar016188f2022-06-06 20:52:59 +01001707 Returns 0 if {string} is not a |String|.
1708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709 Can also be used as a |method|: >
1710 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001711<
1712 Return type: |Number|
1713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715charclass({string}) *charclass()*
1716 Return the character class of the first character in {string}.
1717 The character class is one of:
1718 0 blank
1719 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001720 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001721 3 emoji
1722 other specific Unicode class
1723 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001724 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001726 Return type: |Number|
1727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001728
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001729charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730 Same as |col()| but returns the character index of the column
1731 position given with {expr} instead of the byte position.
1732
1733 Example:
1734 With the cursor on '세' in line 5 with text "여보세요": >
1735 charcol('.') returns 3
1736 col('.') returns 7
1737
1738< Can also be used as a |method|: >
1739 GetPos()->col()
1740<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001741 Return type: |Number|
1742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001743 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001744charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Return the character index of the byte at {idx} in {string}.
1746 The index of the first character is zero.
1747 If there are no multibyte characters the returned value is
1748 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001750 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001751 are not counted separately, their byte length is added to the
1752 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001753 When {countcc} is |TRUE|, then composing characters are
1754 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001755
1756 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1757 index in the String {expr} instead of as the byte index.
1758
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001759 Returns -1 if the arguments are invalid or if there are less
1760 than {idx} bytes. If there are exactly {idx} bytes the length
1761 of the string in characters is returned.
1762
1763 An error is given and -1 is returned if the first argument is
1764 not a string, the second argument is not a number or when the
1765 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001767 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001768 from the character index and |utf16idx()| for getting the
1769 UTF-16 index from the character index.
1770 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771 Examples: >
1772 echo charidx('áb́ć', 3) returns 1
1773 echo charidx('áb́ć', 6, 1) returns 4
1774 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001775 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001776<
1777 Can also be used as a |method|: >
1778 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001779<
1780 Return type: |Number|
1781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001782
1783chdir({dir}) *chdir()*
1784 Change the current working directory to {dir}. The scope of
1785 the directory change depends on the directory of the current
1786 window:
1787 - If the current window has a window-local directory
1788 (|:lcd|), then changes the window local directory.
1789 - Otherwise, if the current tabpage has a local
1790 directory (|:tcd|) then changes the tabpage local
1791 directory.
1792 - Otherwise, changes the global directory.
1793 {dir} must be a String.
1794 If successful, returns the previous working directory. Pass
1795 this to another chdir() to restore the directory.
1796 On failure, returns an empty string.
1797
1798 Example: >
1799 let save_dir = chdir(newdir)
1800 if save_dir != ""
1801 " ... do some work
1802 call chdir(save_dir)
1803 endif
1804
1805< Can also be used as a |method|: >
1806 GetDir()->chdir()
1807<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001808 Return type: |String|
1809
1810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811cindent({lnum}) *cindent()*
1812 Get the amount of indent for line {lnum} according the C
1813 indenting rules, as with 'cindent'.
1814 The indent is counted in spaces, the value of 'tabstop' is
1815 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001816 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001817 See |C-indenting|.
1818
1819 Can also be used as a |method|: >
1820 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821<
1822 Return type: |Number|
1823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001824
1825clearmatches([{win}]) *clearmatches()*
1826 Clears all matches previously defined for the current window
1827 by |matchadd()| and the |:match| commands.
1828 If {win} is specified, use the window with this number or
1829 window ID instead of the current window.
1830
1831 Can also be used as a |method|: >
1832 GetWin()->clearmatches()
1833<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001834 Return type: |Number|
1835
1836
Girish Palya92f68e22025-04-21 11:12:41 +02001837cmdcomplete_info([{what}]) *cmdcomplete_info()*
1838 Returns a |Dictionary| with information about cmdline
1839 completion. See |cmdline-completion|.
1840 The items are:
1841 cmdline_orig The original command-line string before
1842 completion began.
1843 pum_visible |TRUE| if popup menu is visible.
1844 See |pumvisible()|.
1845 matches List of all completion candidates. Each item
1846 is a string.
1847 selected Selected item index. First index is zero.
1848 Index is -1 if no item is selected (showing
1849 typed text only, or the last completion after
1850 no item is selected when using the <Up> or
1851 <Down> keys)
1852
1853 Returns an empty |Dictionary| if no completion was attempted,
1854 if there was only one candidate and it was fully completed, or
1855 if an error occurred.
1856
1857 Return type: dict<any>
1858
1859
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001860col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001861 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001862 position given with {expr}.
1863 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001864 When {expr} is "$", it means the end of the cursor line, so
1865 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001866 Additionally {expr} can be [lnum, col]: a |List| with the line
1867 and column number. Most useful when the column is "$", to get
1868 the last column of a specific line. When "lnum" or "col" is
1869 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001870
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001871 With the optional {winid} argument the values are obtained for
1872 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001874 To get the line number use |line()|. To get both use
1875 |getpos()|.
1876 For the screen column position use |virtcol()|. For the
1877 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001879 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001881 Examples: >
1882 col(".") column of cursor
1883 col("$") length of cursor line plus one
1884 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001885 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001886<
1887 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001888 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001889 For an uppercase mark the column may actually be in another
1890 buffer.
1891 For the cursor position, when 'virtualedit' is active, the
1892 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001893 line. Also, when using a <Cmd> mapping the cursor isn't
1894 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001895 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001896
1897< Can also be used as a |method|: >
1898 GetPos()->col()
1899<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001900 Return type: |Number|
1901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001902
1903complete({startcol}, {matches}) *complete()* *E785*
1904 Set the matches for Insert mode completion.
1905 Can only be used in Insert mode. You need to use a mapping
1906 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1907 or with an expression mapping.
1908 {startcol} is the byte offset in the line where the completed
1909 text start. The text up to the cursor is the original text
1910 that will be replaced by the matches. Use col('.') for an
1911 empty string. "col('.') - 1" will replace one character by a
1912 match.
1913 {matches} must be a |List|. Each |List| item is one match.
1914 See |complete-items| for the kind of items that are possible.
1915 "longest" in 'completeopt' is ignored.
1916 Note that the after calling this function you need to avoid
1917 inserting anything that would cause completion to stop.
1918 The match can be selected with CTRL-N and CTRL-P as usual with
1919 Insert mode completion. The popup menu will appear if
1920 specified, see |ins-completion-menu|.
1921 Example: >
1922 inoremap <F5> <C-R>=ListMonths()<CR>
1923
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001924 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001925 call complete(col('.'), ['January', 'February', 'March',
1926 \ 'April', 'May', 'June', 'July', 'August', 'September',
1927 \ 'October', 'November', 'December'])
1928 return ''
1929 endfunc
1930< This isn't very useful, but it shows how it works. Note that
1931 an empty string is returned to avoid a zero being inserted.
1932
1933 Can also be used as a |method|, the base is passed as the
1934 second argument: >
1935 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001936<
1937 Return type: |Number|
1938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001939
1940complete_add({expr}) *complete_add()*
1941 Add {expr} to the list of matches. Only to be used by the
1942 function specified with the 'completefunc' option.
1943 Returns 0 for failure (empty string or out of memory),
1944 1 when the match was added, 2 when the match was already in
1945 the list.
1946 See |complete-functions| for an explanation of {expr}. It is
1947 the same as one item in the list that 'omnifunc' would return.
1948
1949 Can also be used as a |method|: >
1950 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001951<
1952 Return type: |Number|
1953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954
1955complete_check() *complete_check()*
1956 Check for a key typed while looking for completion matches.
1957 This is to be used when looking for matches takes some time.
1958 Returns |TRUE| when searching for matches is to be aborted,
1959 zero otherwise.
1960 Only to be used by the function specified with the
1961 'completefunc' option.
1962
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001963 Return type: |Number|
1964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001965
1966complete_info([{what}]) *complete_info()*
1967 Returns a |Dictionary| with information about Insert mode
1968 completion. See |ins-completion|.
1969 The items are:
1970 mode Current completion mode name string.
1971 See |complete_info_mode| for the values.
1972 pum_visible |TRUE| if popup menu is visible.
1973 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001974 items List of all completion candidates. Each item
1975 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001976 "abbr", "menu", "kind", "info" and "user_data".
1977 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001978 matches Same as "items", but only returns items that
1979 are matching current query. If both "matches"
1980 and "items" are in "what", the returned list
1981 will still be named "items", but each item
1982 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001983 selected Selected item index. First index is zero.
1984 Index is -1 if no item is selected (showing
1985 typed text only, or the last completion after
1986 no item is selected when using the <Up> or
1987 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001988 completed Return a dictionary containing the entries of
1989 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990
1991 *complete_info_mode*
1992 mode values are:
1993 "" Not in completion mode
1994 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1995 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1996 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1997 |i_CTRL-X_CTRL-Y|
1998 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1999 "files" File names |i_CTRL-X_CTRL-F|
2000 "tags" Tags |i_CTRL-X_CTRL-]|
2001 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
2002 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
2003 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
2004 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
2005 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
2006 "function" User defined completion |i_CTRL-X_CTRL-U|
2007 "omni" Omni completion |i_CTRL-X_CTRL-O|
2008 "spell" Spelling suggestions |i_CTRL-X_s|
2009 "eval" |complete()| completion
2010 "unknown" Other internal modes
2011
2012 If the optional {what} list argument is supplied, then only
2013 the items listed in {what} are returned. Unsupported items in
2014 {what} are silently ignored.
2015
2016 To get the position and size of the popup menu, see
2017 |pum_getpos()|. It's also available in |v:event| during the
2018 |CompleteChanged| event.
2019
Bram Moolenaar016188f2022-06-06 20:52:59 +01002020 Returns an empty |Dictionary| on error.
2021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002022 Examples: >
2023 " Get all items
2024 call complete_info()
2025 " Get only 'mode'
2026 call complete_info(['mode'])
2027 " Get only 'mode' and 'pum_visible'
2028 call complete_info(['mode', 'pum_visible'])
2029
2030< Can also be used as a |method|: >
2031 GetItems()->complete_info()
2032<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002033 Return type: dict<any>
2034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002035 *confirm()*
2036confirm({msg} [, {choices} [, {default} [, {type}]]])
2037 confirm() offers the user a dialog, from which a choice can be
2038 made. It returns the number of the choice. For the first
2039 choice this is 1.
2040 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002041 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002042
2043 {msg} is displayed in a |dialog| with {choices} as the
2044 alternatives. When {choices} is missing or empty, "&OK" is
2045 used (and translated).
2046 {msg} is a String, use '\n' to include a newline. Only on
2047 some systems the string is wrapped when it doesn't fit.
2048
2049 {choices} is a String, with the individual choices separated
2050 by '\n', e.g. >
2051 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2052< The letter after the '&' is the shortcut key for that choice.
2053 Thus you can type 'c' to select "Cancel". The shortcut does
2054 not need to be the first letter: >
2055 confirm("file has been modified", "&Save\nSave &All")
2056< For the console, the first letter of each choice is used as
2057 the default shortcut key. Case is ignored.
2058
2059 The optional {default} argument is the number of the choice
2060 that is made if the user hits <CR>. Use 1 to make the first
2061 choice the default one. Use 0 to not set a default. If
2062 {default} is omitted, 1 is used.
2063
2064 The optional {type} String argument gives the type of dialog.
2065 This is only used for the icon of the GTK, Mac, Motif and
2066 Win32 GUI. It can be one of these values: "Error",
2067 "Question", "Info", "Warning" or "Generic". Only the first
2068 character is relevant. When {type} is omitted, "Generic" is
2069 used.
2070
2071 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2072 or another valid interrupt key, confirm() returns 0.
2073
2074 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002075 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002076 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002077 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002078 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002079 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002080 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002081 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002082 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002083 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002084< In a GUI dialog, buttons are used. The layout of the buttons
2085 depends on the 'v' flag in 'guioptions'. If it is included,
2086 the buttons are always put vertically. Otherwise, confirm()
2087 tries to put the buttons in one horizontal line. If they
2088 don't fit, a vertical layout is used anyway. For some systems
2089 the horizontal layout is always used.
2090
2091 Can also be used as a |method|in: >
2092 BuildMessage()->confirm("&Yes\n&No")
2093<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002094 Return type: |Number|
2095
2096
2097copy({expr}) *copy()*
2098 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002099 different from using {expr} directly.
2100 When {expr} is a |List| a shallow copy is created. This means
2101 that the original |List| can be changed without changing the
2102 copy, and vice versa. But the items are identical, thus
2103 changing an item changes the contents of both |Lists|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002104 A |Tuple| or |Dictionary| is copied in a similar way as a
2105 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002106 Also see |deepcopy()|.
2107 Can also be used as a |method|: >
2108 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002109<
2110 Return type: any, depending on {expr}
2111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002112
2113cos({expr}) *cos()*
2114 Return the cosine of {expr}, measured in radians, as a |Float|.
2115 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002116 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002117 Examples: >
2118 :echo cos(100)
2119< 0.862319 >
2120 :echo cos(-4.01)
2121< -0.646043
2122
2123 Can also be used as a |method|: >
2124 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002125<
2126 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002127
2128
2129cosh({expr}) *cosh()*
2130 Return the hyperbolic cosine of {expr} as a |Float| in the range
2131 [1, inf].
2132 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002133 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002134 Examples: >
2135 :echo cosh(0.5)
2136< 1.127626 >
2137 :echo cosh(-0.5)
2138< -1.127626
2139
2140 Can also be used as a |method|: >
2141 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002142<
2143 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002144
2145
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002146count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002147 Return the number of times an item with value {expr} appears
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002148 in |String|, |List|, |Tuple| or |Dictionary| {comp}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002149
2150 If {start} is given then start with the item with this index.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002151 {start} can only be used with a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002152
2153 When {ic} is given and it's |TRUE| then case is ignored.
2154
2155 When {comp} is a string then the number of not overlapping
2156 occurrences of {expr} is returned. Zero is returned when
2157 {expr} is an empty string.
2158
2159 Can also be used as a |method|: >
2160 mylist->count(val)
2161<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002162 Return type: |Number|
2163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002164 *cscope_connection()*
2165cscope_connection([{num} , {dbpath} [, {prepend}]])
2166 Checks for the existence of a |cscope| connection. If no
2167 parameters are specified, then the function returns:
2168 0, if cscope was not available (not compiled in), or
2169 if there are no cscope connections;
2170 1, if there is at least one cscope connection.
2171
2172 If parameters are specified, then the value of {num}
2173 determines how existence of a cscope connection is checked:
2174
2175 {num} Description of existence check
2176 ----- ------------------------------
2177 0 Same as no parameters (e.g., "cscope_connection()").
2178 1 Ignore {prepend}, and use partial string matches for
2179 {dbpath}.
2180 2 Ignore {prepend}, and use exact string matches for
2181 {dbpath}.
2182 3 Use {prepend}, use partial string matches for both
2183 {dbpath} and {prepend}.
2184 4 Use {prepend}, use exact string matches for both
2185 {dbpath} and {prepend}.
2186
2187 Note: All string comparisons are case sensitive!
2188
2189 Examples. Suppose we had the following (from ":cs show"): >
2190
2191 # pid database name prepend path
2192 0 27664 cscope.out /usr/local
2193<
2194 Invocation Return Val ~
2195 ---------- ---------- >
2196 cscope_connection() 1
2197 cscope_connection(1, "out") 1
2198 cscope_connection(2, "out") 0
2199 cscope_connection(3, "out") 0
2200 cscope_connection(3, "out", "local") 1
2201 cscope_connection(4, "out") 0
2202 cscope_connection(4, "out", "local") 0
2203 cscope_connection(4, "cscope.out", "/usr/local") 1
2204<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002205 Return type: |Number|
2206
2207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002208cursor({lnum}, {col} [, {off}]) *cursor()*
2209cursor({list})
2210 Positions the cursor at the column (byte count) {col} in the
2211 line {lnum}. The first column is one.
2212
2213 When there is one argument {list} this is used as a |List|
2214 with two, three or four item:
2215 [{lnum}, {col}]
2216 [{lnum}, {col}, {off}]
2217 [{lnum}, {col}, {off}, {curswant}]
2218 This is like the return value of |getpos()| or |getcurpos()|,
2219 but without the first item.
2220
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002221 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002222 |setcursorcharpos()|.
2223
2224 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002225 {lnum} is used like with |getline()|, except that if {lnum} is
2226 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002227 If {lnum} is greater than the number of lines in the buffer,
2228 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002229 If {col} is greater than the number of bytes in the line,
2230 the cursor will be positioned at the last character in the
2231 line.
2232 If {col} is zero, the cursor will stay in the current column.
2233 If {curswant} is given it is used to set the preferred column
2234 for vertical movement. Otherwise {col} is used.
2235
2236 When 'virtualedit' is used {off} specifies the offset in
2237 screen columns from the start of the character. E.g., a
2238 position within a <Tab> or after the last character.
2239 Returns 0 when the position could be set, -1 otherwise.
2240
2241 Can also be used as a |method|: >
2242 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002243<
2244 Return type: |Number|
2245
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002246
2247debugbreak({pid}) *debugbreak()*
2248 Specifically used to interrupt a program being debugged. It
2249 will cause process {pid} to get a SIGTRAP. Behavior for other
2250 processes is undefined. See |terminal-debugger|.
2251 {only available on MS-Windows}
2252
Bram Moolenaar016188f2022-06-06 20:52:59 +01002253 Returns |TRUE| if successfully interrupted the program.
2254 Otherwise returns |FALSE|.
2255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002256 Can also be used as a |method|: >
2257 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002258<
2259 Return type: |Number|
2260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002261
2262deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2263 Make a copy of {expr}. For Numbers and Strings this isn't
2264 different from using {expr} directly.
2265 When {expr} is a |List| a full copy is created. This means
2266 that the original |List| can be changed without changing the
2267 copy, and vice versa. When an item is a |List| or
2268 |Dictionary|, a copy for it is made, recursively. Thus
2269 changing an item in the copy does not change the contents of
2270 the original |List|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002271 A |Tuple| or |Dictionary| is copied in a similar way as a
2272 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002273
2274 When {noref} is omitted or zero a contained |List| or
2275 |Dictionary| is only copied once. All references point to
2276 this single copy. With {noref} set to 1 every occurrence of a
2277 |List| or |Dictionary| results in a new copy. This also means
2278 that a cyclic reference causes deepcopy() to fail.
2279 *E724*
2280 Nesting is possible up to 100 levels. When there is an item
2281 that refers back to a higher level making a deep copy with
2282 {noref} set to 1 will fail.
2283 Also see |copy()|.
2284
2285 Can also be used as a |method|: >
2286 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002287<
2288 Return type: any, depending on {expr}
2289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002290
2291delete({fname} [, {flags}]) *delete()*
2292 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002293 name {fname}.
2294
2295 This also works when {fname} is a symbolic link. The symbolic
2296 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002297
2298 When {flags} is "d": Deletes the directory by the name
2299 {fname}. This fails when directory {fname} is not empty.
2300
2301 When {flags} is "rf": Deletes the directory by the name
2302 {fname} and everything in it, recursively. BE CAREFUL!
2303 Note: on MS-Windows it is not possible to delete a directory
2304 that is being used.
2305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002306 The result is a Number, which is 0/false if the delete
2307 operation was successful and -1/true when the deletion failed
2308 or partly failed.
2309
2310 Use |remove()| to delete an item from a |List|.
2311 To delete a line from the buffer use |:delete| or
2312 |deletebufline()|.
2313
2314 Can also be used as a |method|: >
2315 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002316<
2317 Return type: |Number|
2318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002319
2320deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2321 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2322 If {last} is omitted then delete line {first} only.
2323 On success 0 is returned, on failure 1 is returned.
2324
2325 This function works only for loaded buffers. First call
2326 |bufload()| if needed.
2327
2328 For the use of {buf}, see |bufname()| above.
2329
2330 {first} and {last} are used like with |getline()|. Note that
2331 when using |line()| this refers to the current buffer. Use "$"
2332 to refer to the last line in buffer {buf}.
2333
2334 Can also be used as a |method|: >
2335 GetBuffer()->deletebufline(1)
2336<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002337 Return type: |Number|
2338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002339 *did_filetype()*
2340did_filetype() Returns |TRUE| when autocommands are being executed and the
2341 FileType event has been triggered at least once. Can be used
2342 to avoid triggering the FileType event again in the scripts
2343 that detect the file type. |FileType|
2344 Returns |FALSE| when `:setf FALLBACK` was used.
2345 When editing another file, the counter is reset, thus this
2346 really checks if the FileType event has been triggered for the
2347 current buffer. This allows an autocommand that starts
2348 editing another buffer to set 'filetype' and load a syntax
2349 file.
2350
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002351 Return type: |Number|
2352
2353
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002354diff({fromlist}, {tolist} [, {options}]) *diff()*
2355 Returns a String or a List containing the diff between the
2356 strings in {fromlist} and {tolist}. Uses the Vim internal
2357 diff library to compute the diff.
2358
2359 *E106*
2360 The optional "output" item in {options} specifies the returned
2361 diff format. The following values are supported:
2362 indices Return a List of the starting and ending
2363 indices and a count of the strings in each
2364 diff hunk.
2365 unified Return the unified diff output as a String.
2366 This is the default.
2367
2368 If the "output" item in {options} is "indices", then a List is
2369 returned. Each List item contains a Dict with the following
2370 items for each diff hunk:
2371 from_idx start index in {fromlist} for this diff hunk.
2372 from_count number of strings in {fromlist} that are
2373 added/removed/modified in this diff hunk.
2374 to_idx start index in {tolist} for this diff hunk.
2375 to_count number of strings in {tolist} that are
2376 added/removed/modified in this diff hunk.
2377
2378 The {options} Dict argument also specifies diff options
2379 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002380 algorithm Dict specifying the diff algorithm to
2381 use. Supported boolean items are
2382 "myers", "minimal", "patience" and
2383 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002384 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002385 iblank ignore changes where lines are all
2386 blank.
2387 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002388 indent-heuristic use the indent heuristic for the
2389 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002390 iwhite ignore changes in amount of white
2391 space.
2392 iwhiteall ignore all white space changes.
2393 iwhiteeol ignore white space changes at end of
2394 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002395 For more information about these options, refer to 'diffopt'.
2396
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002397 To compute the unified diff, all the items in {fromlist} are
2398 concatenated into a string using a newline separator and the
2399 same for {tolist}. The unified diff output uses line numbers.
2400
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002401 Returns an empty List or String if {fromlist} and {tolist} are
2402 identical.
2403
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002404 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002405 :echo diff(['abc'], ['xxx'])
2406 @@ -1 +1 @@
2407 -abc
2408 +xxx
2409
2410 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2411 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2412 :echo diff(readfile('oldfile'), readfile('newfile'))
2413 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002414<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002415 For more examples, refer to |diff-func-examples|
2416
2417 Can also be used as a |method|: >
2418 GetFromList->diff(to_list)
2419<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002420 Return type: |String| or list<dict<number>> or list<any>
2421 depending on {options}
2422
2423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002424diff_filler({lnum}) *diff_filler()*
2425 Returns the number of filler lines above line {lnum}.
2426 These are the lines that were inserted at this point in
2427 another diff'ed window. These filler lines are shown in the
2428 display but don't exist in the buffer.
2429 {lnum} is used like with |getline()|. Thus "." is the current
2430 line, "'m" mark m, etc.
2431 Returns 0 if the current window is not in diff mode.
2432
2433 Can also be used as a |method|: >
2434 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002435<
2436 Return type: |Number|
2437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002438
2439diff_hlID({lnum}, {col}) *diff_hlID()*
2440 Returns the highlight ID for diff mode at line {lnum} column
2441 {col} (byte index). When the current line does not have a
2442 diff change zero is returned.
2443 {lnum} is used like with |getline()|. Thus "." is the current
2444 line, "'m" mark m, etc.
2445 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2446 line.
2447 The highlight ID can be used with |synIDattr()| to obtain
2448 syntax information about the highlighting.
2449
2450 Can also be used as a |method|: >
2451 GetLnum()->diff_hlID(col)
2452<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002453 Return type: |Number|
2454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002455
2456digraph_get({chars}) *digraph_get()* *E1214*
2457 Return the digraph of {chars}. This should be a string with
2458 exactly two characters. If {chars} are not just two
2459 characters, or the digraph of {chars} does not exist, an error
2460 is given and an empty string is returned.
2461
2462 The character will be converted from Unicode to 'encoding'
2463 when needed. This does require the conversion to be
2464 available, it might fail.
2465
2466 Also see |digraph_getlist()|.
2467
2468 Examples: >
2469 " Get a built-in digraph
2470 :echo digraph_get('00') " Returns '∞'
2471
2472 " Get a user-defined digraph
2473 :call digraph_set('aa', 'あ')
2474 :echo digraph_get('aa') " Returns 'あ'
2475<
2476 Can also be used as a |method|: >
2477 GetChars()->digraph_get()
2478<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002479 Return type: |String|
2480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002481 This function works only when compiled with the |+digraphs|
2482 feature. If this feature is disabled, this function will
2483 display an error message.
2484
2485
2486digraph_getlist([{listall}]) *digraph_getlist()*
2487 Return a list of digraphs. If the {listall} argument is given
2488 and it is TRUE, return all digraphs, including the default
2489 digraphs. Otherwise, return only user-defined digraphs.
2490
2491 The characters will be converted from Unicode to 'encoding'
2492 when needed. This does require the conservation to be
2493 available, it might fail.
2494
2495 Also see |digraph_get()|.
2496
2497 Examples: >
2498 " Get user-defined digraphs
2499 :echo digraph_getlist()
2500
2501 " Get all the digraphs, including default digraphs
2502 :echo digraph_getlist(1)
2503<
2504 Can also be used as a |method|: >
2505 GetNumber()->digraph_getlist()
2506<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002507 Return type: list<list<string>>
2508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002509 This function works only when compiled with the |+digraphs|
2510 feature. If this feature is disabled, this function will
2511 display an error message.
2512
2513
Bram Moolenaara2baa732022-02-04 16:09:54 +00002514digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002515 Add digraph {chars} to the list. {chars} must be a string
2516 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002517 encoded character. *E1215*
2518 Be careful, composing characters are NOT ignored. This
2519 function is similar to |:digraphs| command, but useful to add
2520 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002521
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002522 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002523 this fails an error message is given and v:false is returned.
2524
2525 If you want to define multiple digraphs at once, you can use
2526 |digraph_setlist()|.
2527
2528 Example: >
2529 call digraph_set(' ', 'あ')
2530<
2531 Can be used as a |method|: >
2532 GetString()->digraph_set('あ')
2533<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002534 Return type: |vim9-boolean|
2535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002536 This function works only when compiled with the |+digraphs|
2537 feature. If this feature is disabled, this function will
2538 display an error message.
2539
2540
2541digraph_setlist({digraphlist}) *digraph_setlist()*
2542 Similar to |digraph_set()| but this function can add multiple
2543 digraphs at once. {digraphlist} is a list composed of lists,
2544 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002545 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002546 Example: >
2547 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2548<
2549 It is similar to the following: >
2550 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2551 call digraph_set(chars, digraph)
2552 endfor
2553< Except that the function returns after the first error,
2554 following digraphs will not be added.
2555
2556 Can be used as a |method|: >
2557 GetList()->digraph_setlist()
2558<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002559 Return type: |vim9-boolean|
2560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002561 This function works only when compiled with the |+digraphs|
2562 feature. If this feature is disabled, this function will
2563 display an error message.
2564
2565
2566echoraw({string}) *echoraw()*
2567 Output {string} as-is, including unprintable characters.
2568 This can be used to output a terminal code. For example, to
2569 disable modifyOtherKeys: >
2570 call echoraw(&t_TE)
2571< and to enable it again: >
2572 call echoraw(&t_TI)
2573< Use with care, you can mess up the terminal this way.
2574
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002575 Return type: |Number|
2576
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002577
2578empty({expr}) *empty()*
2579 Return the Number 1 if {expr} is empty, zero otherwise.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002580 - A |List|, |Tuple| or |Dictionary| is empty when it does
2581 not have any items.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002582 - A |String| is empty when its length is zero.
2583 - A |Number| and |Float| are empty when their value is zero.
2584 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2585 - A |Job| is empty when it failed to start.
2586 - A |Channel| is empty when it is closed.
2587 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002588 - An |Object| is empty, when the empty() method in the object
2589 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002590
2591 For a long |List| this is much faster than comparing the
2592 length with zero.
2593
2594 Can also be used as a |method|: >
2595 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002596<
2597 Return type: |Number|
2598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002599
2600environ() *environ()*
2601 Return all of environment variables as dictionary. You can
2602 check if an environment variable exists like this: >
2603 :echo has_key(environ(), 'HOME')
2604< Note that the variable name may be CamelCase; to ignore case
2605 use this: >
2606 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002607<
2608 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002609
Bram Moolenaar416bd912023-07-07 23:19:18 +01002610
2611err_teapot([{expr}]) *err_teapot()*
2612 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002613 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002614 If {expr} is present and it is TRUE error 503 is given,
2615 indicating that coffee is temporarily not available.
2616 If {expr} is present it must be a String.
2617
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002618 Return type: |Number|
2619
Bram Moolenaar416bd912023-07-07 23:19:18 +01002620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621escape({string}, {chars}) *escape()*
2622 Escape the characters in {chars} that occur in {string} with a
2623 backslash. Example: >
2624 :echo escape('c:\program files\vim', ' \')
2625< results in: >
2626 c:\\program\ files\\vim
2627< Also see |shellescape()| and |fnameescape()|.
2628
2629 Can also be used as a |method|: >
2630 GetText()->escape(' \')
2631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002632 Return type: |String|
2633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002634 *eval()*
2635eval({string}) Evaluate {string} and return the result. Especially useful to
2636 turn the result of |string()| back into the original value.
2637 This works for Numbers, Floats, Strings, Blobs and composites
2638 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002639 functions. In |Vim9| script, it can be used to obtain |enum|
2640 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002641
2642 Can also be used as a |method|: >
2643 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002644<
2645 Return type: any, depending on {string}
2646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002647
2648eventhandler() *eventhandler()*
2649 Returns 1 when inside an event handler. That is that Vim got
2650 interrupted while waiting for the user to type a character,
2651 e.g., when dropping a file on Vim. This means interactive
2652 commands cannot be used. Otherwise zero is returned.
2653
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002654 Return type: |Number|
2655
2656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657executable({expr}) *executable()*
2658 This function checks if an executable with the name {expr}
2659 exists. {expr} must be the name of the program without any
2660 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002662 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002663 searchpath for programs.
2664 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002665 On MS-Windows the ".exe", ".bat", etc. can optionally be
2666 included. Then the extensions in $PATHEXT are tried. Thus if
2667 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2668 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2669 by itself can be used in $PATHEXT to try using the name
2670 without an extension. When 'shell' looks like a Unix shell,
2671 then the name is also tried without adding an extension.
2672 On MS-Windows it only checks if the file exists and is not a
2673 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002674 On MS-Windows an executable in the same directory as the Vim
2675 executable is always found. Since this directory is added to
2676 $PATH it should also work to execute it |win32-PATH|.
2677 *NoDefaultCurrentDirectoryInExePath*
2678 On MS-Windows an executable in Vim's current working directory
2679 is also normally found, but this can be disabled by setting
2680 the $NoDefaultCurrentDirectoryInExePath environment variable.
2681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002682 The result is a Number:
2683 1 exists
2684 0 does not exist
2685 -1 not implemented on this system
2686 |exepath()| can be used to get the full path of an executable.
2687
2688 Can also be used as a |method|: >
2689 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002690<
2691 Return type: |Number|
2692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002693
2694execute({command} [, {silent}]) *execute()*
2695 Execute an Ex command or commands and return the output as a
2696 string.
2697 {command} can be a string or a List. In case of a List the
2698 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002699 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002700 redir => var
2701 {command}
2702 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002703< Except that line continuation in {command} is not recognized.
2704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002705 The optional {silent} argument can have these values:
2706 "" no `:silent` used
2707 "silent" `:silent` used
2708 "silent!" `:silent!` used
2709 The default is "silent". Note that with "silent!", unlike
2710 `:redir`, error messages are dropped. When using an external
2711 command the screen may be messed up, use `system()` instead.
2712 *E930*
2713 It is not possible to use `:redir` anywhere in {command}.
2714
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002715 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002716 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002717
2718< To execute a command in another window than the current one
2719 use `win_execute()`.
2720
2721 When used recursively the output of the recursive call is not
2722 included in the output of the higher level call.
2723
2724 Can also be used as a |method|: >
2725 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002726<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002727 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002729
2730exepath({expr}) *exepath()*
2731 If {expr} is an executable and is either an absolute path, a
2732 relative path or found in $PATH, return the full path.
2733 Note that the current directory is used when {expr} starts
2734 with "./", which may be a problem for Vim: >
2735 echo exepath(v:progpath)
2736< If {expr} cannot be found in $PATH or is not executable then
2737 an empty string is returned.
2738
2739 Can also be used as a |method|: >
2740 GetCommand()->exepath()
2741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002742 Return type: |String|
2743
2744
2745exists({expr}) *exists()*
2746 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002747 zero otherwise.
2748
2749 Note: In a compiled |:def| function the evaluation is done at
2750 runtime. Use `exists_compiled()` to evaluate the expression
2751 at compile time.
2752
2753 For checking for a supported feature use |has()|.
2754 For checking if a file exists use |filereadable()|.
2755
2756 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002757 varname internal variable (see
2758 dict.key |internal-variables|). Also works
2759 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002760 import.Func entries, |List| items, class and
2761 class.Func object methods, imported items, etc.
2762 object.Func Does not work for local variables in a
2763 class.varname compiled `:def` function.
2764 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002765 script, since it can be used as a
2766 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002767 Beware that evaluating an index may
2768 cause an error message for an invalid
2769 expression. E.g.: >
2770 :let l = [1, 2, 3]
2771 :echo exists("l[5]")
2772< 0 >
2773 :echo exists("l[xx]")
2774< E121: Undefined variable: xx
2775 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002776 &option-name Vim option (only checks if it exists,
2777 not if it really works)
2778 +option-name Vim option that works.
2779 $ENVNAME environment variable (could also be
2780 done by comparing with an empty
2781 string)
2782 *funcname built-in function (see |functions|)
2783 or user defined function (see
2784 |user-functions|) that is implemented.
2785 Also works for a variable that is a
2786 Funcref.
2787 ?funcname built-in function that could be
2788 implemented; to be used to check if
2789 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002790 :cmdname Ex command: built-in command, user
2791 command or command modifier |:command|.
2792 Returns:
2793 1 for match with start of a command
2794 2 full match with a command
2795 3 matches several user commands
2796 To check for a supported command
2797 always check the return value to be 2.
2798 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002799 :3match The |:3match| command (but you
2800 probably should not use it, it is
2801 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002802 #event autocommand defined for this event
2803 #event#pattern autocommand defined for this event and
2804 pattern (the pattern is taken
2805 literally and compared to the
2806 autocommand patterns character by
2807 character)
2808 #group autocommand group exists
2809 #group#event autocommand defined for this group and
2810 event.
2811 #group#event#pattern
2812 autocommand defined for this group,
2813 event and pattern.
2814 ##event autocommand for this event is
2815 supported.
2816
2817 Examples: >
2818 exists("&shortname")
2819 exists("$HOSTNAME")
2820 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002821 exists("*s:MyFunc") " only for legacy script
2822 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002823 exists("bufcount")
2824 exists(":Make")
2825 exists("#CursorHold")
2826 exists("#BufReadPre#*.gz")
2827 exists("#filetypeindent")
2828 exists("#filetypeindent#FileType")
2829 exists("#filetypeindent#FileType#*")
2830 exists("##ColorScheme")
2831< There must be no space between the symbol (&/$/*/#) and the
2832 name.
2833 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002834 a few cases this is ignored. That may become stricter in the
2835 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002836 Working example: >
2837 exists(":make")
2838< NOT working example: >
2839 exists(":make install")
2840
2841< Note that the argument must be a string, not the name of the
2842 variable itself. For example: >
2843 exists(bufcount)
2844< This doesn't check for existence of the "bufcount" variable,
2845 but gets the value of "bufcount", and checks if that exists.
2846
2847 Can also be used as a |method|: >
2848 Varname()->exists()
2849<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002850 Return type: |String|
2851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002852
2853exists_compiled({expr}) *exists_compiled()*
2854 Like `exists()` but evaluated at compile time. This is useful
2855 to skip a block where a function is used that would otherwise
2856 give an error: >
2857 if exists_compiled('*ThatFunction')
2858 ThatFunction('works')
2859 endif
2860< If `exists()` were used then a compilation error would be
2861 given if ThatFunction() is not defined.
2862
2863 {expr} must be a literal string. *E1232*
2864 Can only be used in a |:def| function. *E1233*
2865 This does not work to check for arguments or local variables.
2866
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002867 Return type: |String|
2868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002869
2870exp({expr}) *exp()*
2871 Return the exponential of {expr} as a |Float| in the range
2872 [0, inf].
2873 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002874 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002875 Examples: >
2876 :echo exp(2)
2877< 7.389056 >
2878 :echo exp(-1)
2879< 0.367879
2880
2881 Can also be used as a |method|: >
2882 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002883<
2884 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002885
2886
2887expand({string} [, {nosuf} [, {list}]]) *expand()*
2888 Expand wildcards and the following special keywords in
2889 {string}. 'wildignorecase' applies.
2890
2891 If {list} is given and it is |TRUE|, a List will be returned.
2892 Otherwise the result is a String and when there are several
2893 matches, they are separated by <NL> characters. [Note: in
2894 version 5.0 a space was used, which caused problems when a
2895 file name contains a space]
2896
2897 If the expansion fails, the result is an empty string. A name
2898 for a non-existing file is not included, unless {string} does
2899 not start with '%', '#' or '<', see below.
2900
Christian Brabandtec9c3262024-02-21 20:40:05 +01002901 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002902 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002904 When {string} starts with '%', '#' or '<', the expansion is
2905 done like for the |cmdline-special| variables with their
2906 associated modifiers. Here is a short overview:
2907
2908 % current file name
2909 # alternate file name
2910 #n alternate file name n
2911 <cfile> file name under the cursor
2912 <afile> autocmd file name
2913 <abuf> autocmd buffer number (as a String!)
2914 <amatch> autocmd matched name
2915 <cexpr> C expression under the cursor
2916 <sfile> sourced script file or function name
2917 <slnum> sourced script line number or function
2918 line number
2919 <sflnum> script file line number, also when in
2920 a function
2921 <SID> "<SNR>123_" where "123" is the
2922 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002923 <script> sourced script file, or script file
2924 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002925 <stack> call stack
2926 <cword> word under the cursor
2927 <cWORD> WORD under the cursor
2928 <client> the {clientid} of the last received
2929 message |server2client()|
2930 Modifiers:
2931 :p expand to full path
2932 :h head (last path component removed)
2933 :t tail (last path component only)
2934 :r root (one extension removed)
2935 :e extension only
2936
2937 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002938 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002939< Note that when expanding a string that starts with '%', '#' or
2940 '<', any following text is ignored. This does NOT work: >
2941 :let doesntwork = expand("%:h.bak")
2942< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002943 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002944< Also note that expanding "<cfile>" and others only returns the
2945 referenced file name without further expansion. If "<cfile>"
2946 is "~/.cshrc", you need to do another expand() to have the
2947 "~/" expanded into the path of the home directory: >
2948 :echo expand(expand("<cfile>"))
2949<
2950 There cannot be white space between the variables and the
2951 following modifier. The |fnamemodify()| function can be used
2952 to modify normal file names.
2953
2954 When using '%' or '#', and the current or alternate file name
2955 is not defined, an empty string is used. Using "%:p" in a
2956 buffer with no name, results in the current directory, with a
2957 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002958 When 'verbose' is set then expanding '%', '#' and <> items
2959 will result in an error message if the argument cannot be
2960 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002961
2962 When {string} does not start with '%', '#' or '<', it is
2963 expanded like a file name is expanded on the command line.
2964 'suffixes' and 'wildignore' are used, unless the optional
2965 {nosuf} argument is given and it is |TRUE|.
2966 Names for non-existing files are included. The "**" item can
2967 be used to search in a directory tree. For example, to find
2968 all "README" files in the current directory and below: >
2969 :echo expand("**/README")
2970<
2971 expand() can also be used to expand variables and environment
2972 variables that are only known in a shell. But this can be
2973 slow, because a shell may be used to do the expansion. See
2974 |expr-env-expand|.
2975 The expanded variable is still handled like a list of file
2976 names. When an environment variable cannot be expanded, it is
2977 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2978 "$FOOBAR".
2979
2980 See |glob()| for finding existing files. See |system()| for
2981 getting the raw output of an external command.
2982
2983 Can also be used as a |method|: >
2984 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002985<
2986 Return type: |String| or list<string> depending on {list}
2987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002988
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002989expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002990 Expand special items in String {string} like what is done for
2991 an Ex command such as `:edit`. This expands special keywords,
2992 like with |expand()|, and environment variables, anywhere in
2993 {string}. "~user" and "~/path" are only expanded at the
2994 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002995
2996 The following items are supported in the {options} Dict
2997 argument:
2998 errmsg If set to TRUE, error messages are displayed
2999 if an error is encountered during expansion.
3000 By default, error messages are not displayed.
3001
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003002 Returns the expanded string. If an error is encountered
3003 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003004
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003005 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003006 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003007 make /path/runtime/doc/builtin.o
3008 :echo expandcmd('make %<.o', {'errmsg': v:true})
3009<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003010 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003011 GetCommand()->expandcmd()
3012<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003013 Return type: |String| or list<string> depending on {list}
3014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003015extend({expr1}, {expr2} [, {expr3}]) *extend()*
3016 {expr1} and {expr2} must be both |Lists| or both
3017 |Dictionaries|.
3018
3019 If they are |Lists|: Append {expr2} to {expr1}.
3020 If {expr3} is given insert the items of {expr2} before the
3021 item with index {expr3} in {expr1}. When {expr3} is zero
3022 insert before the first item. When {expr3} is equal to
3023 len({expr1}) then {expr2} is appended.
3024 Examples: >
3025 :echo sort(extend(mylist, [7, 5]))
3026 :call extend(mylist, [2, 3], 1)
3027< When {expr1} is the same List as {expr2} then the number of
3028 items copied is equal to the original length of the List.
3029 E.g., when {expr3} is 1 you get N new copies of the first item
3030 (where N is the original length of the List).
3031 Use |add()| to concatenate one item to a list. To concatenate
3032 two lists into a new list use the + operator: >
3033 :let newlist = [1, 2, 3] + [4, 5]
3034<
3035 If they are |Dictionaries|:
3036 Add all entries from {expr2} to {expr1}.
3037 If a key exists in both {expr1} and {expr2} then {expr3} is
3038 used to decide what to do:
3039 {expr3} = "keep": keep the value of {expr1}
3040 {expr3} = "force": use the value of {expr2}
3041 {expr3} = "error": give an error message *E737*
3042 When {expr3} is omitted then "force" is assumed.
3043
3044 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003045 make a copy of {expr1} first or use |extendnew()| to return a
3046 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003047 {expr2} remains unchanged.
3048 When {expr1} is locked and {expr2} is not empty the operation
3049 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003050 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003051
3052 Can also be used as a |method|: >
3053 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003054<
3055 Return type: list<{type}> or dict<{type}> depending on {expr1}
3056 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003057
3058
3059extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3060 Like |extend()| but instead of adding items to {expr1} a new
3061 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003062 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003063
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003064 Return type: list<{type}> or dict<{type}> depending on {expr1}
3065 and {expr2}, in case of error: |Number|
3066
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003067
3068feedkeys({string} [, {mode}]) *feedkeys()*
3069 Characters in {string} are queued for processing as if they
3070 come from a mapping or were typed by the user.
3071
3072 By default the string is added to the end of the typeahead
3073 buffer, thus if a mapping is still being executed the
3074 characters come after them. Use the 'i' flag to insert before
3075 other characters, they will be executed next, before any
3076 characters from a mapping.
3077
3078 The function does not wait for processing of keys contained in
3079 {string}.
3080
3081 To include special keys into {string}, use double-quotes
3082 and "\..." notation |expr-quote|. For example,
3083 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3084 feedkeys('\<CR>') pushes 5 characters.
3085 A special code that might be useful is <Ignore>, it exits the
3086 wait for a character without doing anything. *<Ignore>*
3087
3088 {mode} is a String, which can contain these character flags:
3089 'm' Remap keys. This is default. If {mode} is absent,
3090 keys are remapped.
3091 'n' Do not remap keys.
3092 't' Handle keys as if typed; otherwise they are handled as
3093 if coming from a mapping. This matters for undo,
3094 opening folds, etc.
3095 'L' Lowlevel input. Only works for Unix or when using the
3096 GUI. Keys are used as if they were coming from the
3097 terminal. Other flags are not used. *E980*
3098 When a CTRL-C interrupts and 't' is included it sets
3099 the internal "got_int" flag.
3100 'i' Insert the string instead of appending (see above).
3101 'x' Execute commands until typeahead is empty. This is
3102 similar to using ":normal!". You can call feedkeys()
3103 several times without 'x' and then one time with 'x'
3104 (possibly with an empty {string}) to execute all the
3105 typeahead. Note that when Vim ends in Insert mode it
3106 will behave as if <Esc> is typed, to avoid getting
3107 stuck, waiting for a character to be typed before the
3108 script continues.
3109 Note that if you manage to call feedkeys() while
3110 executing commands, thus calling it recursively, then
3111 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003112 'c' Remove any script context when executing, so that
3113 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003114 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003115 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003116 '!' When used with 'x' will not end Insert mode. Can be
3117 used in a test when a timer is set to exit Insert mode
3118 a little later. Useful for testing CursorHoldI.
3119
3120 Return value is always 0.
3121
3122 Can also be used as a |method|: >
3123 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003124<
3125 Return type: |String| or list<string> depending on {list}
3126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003127
Shougo Matsushita60c87432024-06-03 22:59:27 +02003128filecopy({from}, {to}) *filecopy()*
3129 Copy the file pointed to by the name {from} to {to}. The
3130 result is a Number, which is |TRUE| if the file was copied
3131 successfully, and |FALSE| when it failed.
3132 If a file with name {to} already exists, it will fail.
3133 Note that it does not handle directories (yet).
3134
3135 This function is not available in the |sandbox|.
3136
3137 Can also be used as a |method|: >
3138 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003139<
3140 Return type: |Number|
3141
Shougo Matsushita60c87432024-06-03 22:59:27 +02003142
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003143filereadable({file}) *filereadable()*
3144 The result is a Number, which is |TRUE| when a file with the
3145 name {file} exists, and can be read. If {file} doesn't exist,
3146 or is a directory, the result is |FALSE|. {file} is any
3147 expression, which is used as a String.
3148 If you don't care about the file being readable you can use
3149 |glob()|.
3150 {file} is used as-is, you may want to expand wildcards first: >
3151 echo filereadable('~/.vimrc')
3152 0
3153 echo filereadable(expand('~/.vimrc'))
3154 1
3155
3156< Can also be used as a |method|: >
3157 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003158<
3159 Return type: |Number|
3160
3161 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003162 Obsolete name: file_readable().
3163
3164
3165filewritable({file}) *filewritable()*
3166 The result is a Number, which is 1 when a file with the
3167 name {file} exists, and can be written. If {file} doesn't
3168 exist, or is not writable, the result is 0. If {file} is a
3169 directory, and we can write to it, the result is 2.
3170
3171 Can also be used as a |method|: >
3172 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003173<
3174 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003175
3176
3177filter({expr1}, {expr2}) *filter()*
3178 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3179 For each item in {expr1} evaluate {expr2} and when the result
3180 is zero or false remove the item from the |List| or
3181 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003182 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003183
3184 {expr2} must be a |string| or |Funcref|.
3185
3186 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3187 of the current item. For a |Dictionary| |v:key| has the key
3188 of the current item and for a |List| |v:key| has the index of
3189 the current item. For a |Blob| |v:key| has the index of the
3190 current byte. For a |String| |v:key| has the index of the
3191 current character.
3192 Examples: >
3193 call filter(mylist, 'v:val !~ "OLD"')
3194< Removes the items where "OLD" appears. >
3195 call filter(mydict, 'v:key >= 8')
3196< Removes the items with a key below 8. >
3197 call filter(var, 0)
3198< Removes all the items, thus clears the |List| or |Dictionary|.
3199
3200 Note that {expr2} is the result of expression and is then
3201 used as an expression again. Often it is good to use a
3202 |literal-string| to avoid having to double backslashes.
3203
3204 If {expr2} is a |Funcref| it must take two arguments:
3205 1. the key or the index of the current item.
3206 2. the value of the current item.
3207 The function must return |TRUE| if the item should be kept.
3208 Example that keeps the odd items of a list: >
3209 func Odd(idx, val)
3210 return a:idx % 2 == 1
3211 endfunc
3212 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003213< It is shorter when using a |lambda|. In |Vim9| syntax: >
3214 call filter(myList, (idx, val) => idx * val <= 42)
3215< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216 call filter(myList, {idx, val -> idx * val <= 42})
3217< If you do not use "val" you can leave it out: >
3218 call filter(myList, {idx -> idx % 2 == 1})
3219<
3220 In |Vim9| script the result must be true, false, zero or one.
3221 Other values will result in a type error.
3222
3223 For a |List| and a |Dictionary| the operation is done
3224 in-place. If you want it to remain unmodified make a copy
3225 first: >
3226 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3227
3228< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003229 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003230 When an error is encountered while evaluating {expr2} no
3231 further items in {expr1} are processed.
3232 When {expr2} is a Funcref errors inside a function are ignored,
3233 unless it was defined with the "abort" flag.
3234
3235 Can also be used as a |method|: >
3236 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003237<
3238 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3239 depending on {expr1}
3240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003241
3242finddir({name} [, {path} [, {count}]]) *finddir()*
3243 Find directory {name} in {path}. Supports both downwards and
3244 upwards recursive directory searches. See |file-searching|
3245 for the syntax of {path}.
3246
3247 Returns the path of the first found match. When the found
3248 directory is below the current directory a relative path is
3249 returned. Otherwise a full path is returned.
3250 If {path} is omitted or empty then 'path' is used.
3251
3252 If the optional {count} is given, find {count}'s occurrence of
3253 {name} in {path} instead of the first one.
3254 When {count} is negative return all the matches in a |List|.
3255
Bram Moolenaar016188f2022-06-06 20:52:59 +01003256 Returns an empty string if the directory is not found.
3257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003258 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003259
3260 Can also be used as a |method|: >
3261 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003262<
3263 Return type: |String|
3264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003265
3266findfile({name} [, {path} [, {count}]]) *findfile()*
3267 Just like |finddir()|, but find a file instead of a directory.
3268 Uses 'suffixesadd'.
3269 Example: >
3270 :echo findfile("tags.vim", ".;")
3271< Searches from the directory of the current file upwards until
3272 it finds the file "tags.vim".
3273
3274 Can also be used as a |method|: >
3275 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003276<
3277 Return type: |String|
3278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003279
3280flatten({list} [, {maxdepth}]) *flatten()*
3281 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3282 the result is a |List| without nesting, as if {maxdepth} is
3283 a very large number.
3284 The {list} is changed in place, use |flattennew()| if you do
3285 not want that.
3286 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003287 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003288 *E900*
3289 {maxdepth} means how deep in nested lists changes are made.
3290 {list} is not modified when {maxdepth} is 0.
3291 {maxdepth} must be positive number.
3292
3293 If there is an error the number zero is returned.
3294
3295 Example: >
3296 :echo flatten([1, [2, [3, 4]], 5])
3297< [1, 2, 3, 4, 5] >
3298 :echo flatten([1, [2, [3, 4]], 5], 1)
3299< [1, 2, [3, 4], 5]
3300
3301 Can also be used as a |method|: >
3302 mylist->flatten()
3303<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003304 Return type: list<{type}>
3305
3306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003307flattennew({list} [, {maxdepth}]) *flattennew()*
3308 Like |flatten()| but first make a copy of {list}.
3309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003310 Return type: list<{type}>
3311
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003312
3313float2nr({expr}) *float2nr()*
3314 Convert {expr} to a Number by omitting the part after the
3315 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003316 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003317 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003318 When the value of {expr} is out of range for a |Number| the
3319 result is truncated to 0x7fffffff or -0x7fffffff (or when
3320 64-bit Number support is enabled, 0x7fffffffffffffff or
3321 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3322 64-bit Number support is enabled, -0x8000000000000000).
3323 Examples: >
3324 echo float2nr(3.95)
3325< 3 >
3326 echo float2nr(-23.45)
3327< -23 >
3328 echo float2nr(1.0e100)
3329< 2147483647 (or 9223372036854775807) >
3330 echo float2nr(-1.0e150)
3331< -2147483647 (or -9223372036854775807) >
3332 echo float2nr(1.0e-100)
3333< 0
3334
3335 Can also be used as a |method|: >
3336 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003337<
3338 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003339
3340
3341floor({expr}) *floor()*
3342 Return the largest integral value less than or equal to
3343 {expr} as a |Float| (round down).
3344 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003345 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003346 Examples: >
3347 echo floor(1.856)
3348< 1.0 >
3349 echo floor(-5.456)
3350< -6.0 >
3351 echo floor(4.0)
3352< 4.0
3353
3354 Can also be used as a |method|: >
3355 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003356<
3357 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003358
3359
3360fmod({expr1}, {expr2}) *fmod()*
3361 Return the remainder of {expr1} / {expr2}, even if the
3362 division is not representable. Returns {expr1} - i * {expr2}
3363 for some integer i such that if {expr2} is non-zero, the
3364 result has the same sign as {expr1} and magnitude less than
3365 the magnitude of {expr2}. If {expr2} is zero, the value
3366 returned is zero. The value returned is a |Float|.
3367 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003368 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3369 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003370 Examples: >
3371 :echo fmod(12.33, 1.22)
3372< 0.13 >
3373 :echo fmod(-12.33, 1.22)
3374< -0.13
3375
3376 Can also be used as a |method|: >
3377 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003378<
3379 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003380
3381
3382fnameescape({string}) *fnameescape()*
3383 Escape {string} for use as file name command argument. All
3384 characters that have a special meaning, such as '%' and '|'
3385 are escaped with a backslash.
3386 For most systems the characters escaped are
3387 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3388 appears in a filename, it depends on the value of 'isfname'.
3389 A leading '+' and '>' is also escaped (special after |:edit|
3390 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003391 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003392 Example: >
3393 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003394 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003395< results in executing: >
3396 edit \+some\ str\%nge\|name
3397<
3398 Can also be used as a |method|: >
3399 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003400<
3401 Return type: |String|
3402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003403
3404fnamemodify({fname}, {mods}) *fnamemodify()*
3405 Modify file name {fname} according to {mods}. {mods} is a
3406 string of characters like it is used for file names on the
3407 command line. See |filename-modifiers|.
3408 Example: >
3409 :echo fnamemodify("main.c", ":p:h")
3410< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003411 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003412< If {mods} is empty or an unsupported modifier is used then
3413 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003414 When {fname} is empty then with {mods} ":h" returns ".", so
3415 that `:cd` can be used with it. This is different from
3416 expand('%:h') without a buffer name, which returns an empty
3417 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003418 Note: Environment variables don't work in {fname}, use
3419 |expand()| first then.
3420
3421 Can also be used as a |method|: >
3422 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003423<
3424 Return type: |String|
3425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003426
3427foldclosed({lnum}) *foldclosed()*
3428 The result is a Number. If the line {lnum} is in a closed
3429 fold, the result is the number of the first line in that fold.
3430 If the line {lnum} is not in a closed fold, -1 is returned.
3431 {lnum} is used like with |getline()|. Thus "." is the current
3432 line, "'m" mark m, etc.
3433
3434 Can also be used as a |method|: >
3435 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003436<
3437 Return type: |Number|
3438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003439
3440foldclosedend({lnum}) *foldclosedend()*
3441 The result is a Number. If the line {lnum} is in a closed
3442 fold, the result is the number of the last line in that fold.
3443 If the line {lnum} is not in a closed fold, -1 is returned.
3444 {lnum} is used like with |getline()|. Thus "." is the current
3445 line, "'m" mark m, etc.
3446
3447 Can also be used as a |method|: >
3448 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003449<
3450 Return type: |Number|
3451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003452
3453foldlevel({lnum}) *foldlevel()*
3454 The result is a Number, which is the foldlevel of line {lnum}
3455 in the current buffer. For nested folds the deepest level is
3456 returned. If there is no fold at line {lnum}, zero is
3457 returned. It doesn't matter if the folds are open or closed.
3458 When used while updating folds (from 'foldexpr') -1 is
3459 returned for lines where folds are still to be updated and the
3460 foldlevel is unknown. As a special case the level of the
3461 previous line is usually available.
3462 {lnum} is used like with |getline()|. Thus "." is the current
3463 line, "'m" mark m, etc.
3464
3465 Can also be used as a |method|: >
3466 GetLnum()->foldlevel()
3467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003468 Return type: |Number|
3469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003470 *foldtext()*
3471foldtext() Returns a String, to be displayed for a closed fold. This is
3472 the default function used for the 'foldtext' option and should
3473 only be called from evaluating 'foldtext'. It uses the
3474 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3475 The returned string looks like this: >
3476 +-- 45 lines: abcdef
3477< The number of leading dashes depends on the foldlevel. The
3478 "45" is the number of lines in the fold. "abcdef" is the text
3479 in the first non-blank line of the fold. Leading white space,
3480 "//" or "/*" and the text from the 'foldmarker' and
3481 'commentstring' options is removed.
3482 When used to draw the actual foldtext, the rest of the line
3483 will be filled with the fold char from the 'fillchars'
3484 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003485 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003486
3487 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003488 {not available when compiled without the |+folding| feature}
3489
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003491foldtextresult({lnum}) *foldtextresult()*
3492 Returns the text that is displayed for the closed fold at line
3493 {lnum}. Evaluates 'foldtext' in the appropriate context.
3494 When there is no closed fold at {lnum} an empty string is
3495 returned.
3496 {lnum} is used like with |getline()|. Thus "." is the current
3497 line, "'m" mark m, etc.
3498 Useful when exporting folded text, e.g., to HTML.
3499 {not available when compiled without the |+folding| feature}
3500
3501
3502 Can also be used as a |method|: >
3503 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003504<
3505 Return type: |String|
3506
Ernie Raele79e2072024-01-13 11:47:33 +01003507
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003508foreach({expr1}, {expr2}) *foreach()* *E1525*
3509 {expr1} must be a |List|, |Tuple|, |String|, |Blob| or
3510 |Dictionary|.
Ernie Raele79e2072024-01-13 11:47:33 +01003511 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003512 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003513 See |map()| and |filter()| to modify {expr1}.
3514
3515 {expr2} must be a |string| or |Funcref|.
3516
3517 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3518 of the current item. For a |Dictionary| |v:key| has the key
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003519 of the current item and for a |List| or a |Tuple| |v:key| has
3520 the index of the current item. For a |Blob| |v:key| has the
3521 index of the current byte. For a |String| |v:key| has the
3522 index of the current character.
Ernie Raele79e2072024-01-13 11:47:33 +01003523 Examples: >
3524 call foreach(mylist, 'used[v:val] = true')
3525< This records the items that are in the {expr1} list.
3526
3527 Note that {expr2} is the result of expression and is then used
3528 as a command. Often it is good to use a |literal-string| to
3529 avoid having to double backslashes.
3530
3531 If {expr2} is a |Funcref| it must take two arguments:
3532 1. the key or the index of the current item.
3533 2. the value of the current item.
3534 With a legacy script lambda you don't get an error if it only
3535 accepts one argument, but with a Vim9 lambda you get "E1106:
3536 One argument too many", the number of arguments must match.
3537 If the function returns a value, it is ignored.
3538
3539 Returns {expr1} in all cases.
3540 When an error is encountered while executing {expr2} no
3541 further items in {expr1} are processed.
3542 When {expr2} is a Funcref errors inside a function are ignored,
3543 unless it was defined with the "abort" flag.
3544
3545 Can also be used as a |method|: >
3546 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003547<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003548 Return type: |String|, |Blob|, list<{type}>, tuple<{type}> or
3549 dict<{type}> depending on {expr1}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003551 *foreground()*
3552foreground() Move the Vim window to the foreground. Useful when sent from
3553 a client to a Vim server. |remote_send()|
3554 On Win32 systems this might not work, the OS does not always
3555 allow a window to bring itself to the foreground. Use
3556 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003557
3558 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003559 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003560 Win32 console version}
3561
Bram Moolenaaraa534142022-09-15 21:46:02 +01003562fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003563 Get the full command name from a short abbreviated command
3564 name; see |20.2| for details on command abbreviations.
3565
3566 The string argument {name} may start with a `:` and can
3567 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003568 Returns an empty string if a command doesn't exist, if it's
3569 ambiguous (for user-defined commands) or cannot be shortened
3570 this way. |vim9-no-shorten|
3571
3572 Without the {vim9} argument uses the current script version.
3573 If {vim9} is present and FALSE then legacy script rules are
3574 used. When {vim9} is present and TRUE then Vim9 rules are
3575 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003576
3577 For example `fullcommand('s')`, `fullcommand('sub')`,
3578 `fullcommand(':%substitute')` all return "substitute".
3579
3580 Can also be used as a |method|: >
3581 GetName()->fullcommand()
3582<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003583 Return type: |String|
3584
3585
3586funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003587 Just like |function()|, but the returned Funcref will lookup
3588 the function by reference, not by name. This matters when the
3589 function {name} is redefined later.
3590
3591 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003592 It only works for an autoloaded function if it has already
3593 been loaded (to avoid mistakenly loading the autoload script
3594 when only intending to use the function name, use |function()|
3595 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003596 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597
3598 Can also be used as a |method|: >
3599 GetFuncname()->funcref([arg])
3600<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003601 Return type: func(...): any or |Number| on error
3602
Dominique Pellee764d1b2023-03-12 21:20:59 +00003603 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003604function({name} [, {arglist}] [, {dict}])
3605 Return a |Funcref| variable that refers to function {name}.
3606 {name} can be the name of a user defined function or an
3607 internal function.
3608
3609 {name} can also be a Funcref or a partial. When it is a
3610 partial the dict stored in it will be used and the {dict}
3611 argument is not allowed. E.g.: >
3612 let FuncWithArg = function(dict.Func, [arg])
3613 let Broken = function(dict.Func, [arg], dict)
3614<
3615 When using the Funcref the function will be found by {name},
3616 also when it was redefined later. Use |funcref()| to keep the
3617 same function.
3618
3619 When {arglist} or {dict} is present this creates a partial.
3620 That means the argument list and/or the dictionary is stored in
3621 the Funcref and will be used when the Funcref is called.
3622
3623 The arguments are passed to the function in front of other
3624 arguments, but after any argument from |method|. Example: >
3625 func Callback(arg1, arg2, name)
3626 ...
3627 let Partial = function('Callback', ['one', 'two'])
3628 ...
3629 call Partial('name')
3630< Invokes the function as with: >
3631 call Callback('one', 'two', 'name')
3632
3633< With a |method|: >
3634 func Callback(one, two, three)
3635 ...
3636 let Partial = function('Callback', ['two'])
3637 ...
3638 eval 'one'->Partial('three')
3639< Invokes the function as with: >
3640 call Callback('one', 'two', 'three')
3641
3642< The function() call can be nested to add more arguments to the
3643 Funcref. The extra arguments are appended to the list of
3644 arguments. Example: >
3645 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003646 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003647 let Func = function('Callback', ['one'])
3648 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003649 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003650 call Func2('name')
3651< Invokes the function as with: >
3652 call Callback('one', 'two', 'name')
3653
3654< The Dictionary is only useful when calling a "dict" function.
3655 In that case the {dict} is passed in as "self". Example: >
3656 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003657 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003658 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003659 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003660 let context = {"name": "example"}
3661 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003662 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003663 call Func() " will echo: called for example
3664< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003665 arguments, these two are equivalent, if Callback() is defined
3666 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003667 let Func = function('Callback', context)
3668 let Func = context.Callback
3669
3670< The argument list and the Dictionary can be combined: >
3671 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003672 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003673 let context = {"name": "example"}
3674 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003675 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003676 call Func(500)
3677< Invokes the function as with: >
3678 call context.Callback('one', 500)
3679<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003680 Returns 0 on error.
3681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003682 Can also be used as a |method|: >
3683 GetFuncname()->function([arg])
3684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003685<
3686 Return type: func(...): any or |Number| on error
3687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003688
3689garbagecollect([{atexit}]) *garbagecollect()*
3690 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3691 that have circular references.
3692
3693 There is hardly ever a need to invoke this function, as it is
3694 automatically done when Vim runs out of memory or is waiting
3695 for the user to press a key after 'updatetime'. Items without
3696 circular references are always freed when they become unused.
3697 This is useful if you have deleted a very big |List| and/or
3698 |Dictionary| with circular references in a script that runs
3699 for a long time.
3700
3701 When the optional {atexit} argument is one, garbage
3702 collection will also be done when exiting Vim, if it wasn't
3703 done before. This is useful when checking for memory leaks.
3704
3705 The garbage collection is not done immediately but only when
3706 it's safe to perform. This is when waiting for the user to
3707 type a character. To force garbage collection immediately use
3708 |test_garbagecollect_now()|.
3709
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003710 Return type: |String|
3711
3712
LemonBoy48b7d052024-07-09 18:24:59 +02003713get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003714 Get item {idx} from |List| {list}. When this item is not
3715 available return {default}. Return zero when {default} is
3716 omitted.
3717 Preferably used as a |method|: >
3718 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003719<
3720 Return type: any, depending on {list}
3721
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003722get({tuple}, {idx} [, {default}]) *get()-tuple*
3723 Get item {idx} from |Tuple| {tuple}. When this item is not
3724 available return {default}. Return zero when {default} is
3725 omitted.
3726 Preferably used as a |method|: >
3727 mytuple->get(idx)
3728<
3729 Return type: any, depending on {tuple}
3730
LemonBoy48b7d052024-07-09 18:24:59 +02003731get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003732 Get byte {idx} from |Blob| {blob}. When this byte is not
3733 available return {default}. Return -1 when {default} is
3734 omitted.
3735 Preferably used as a |method|: >
3736 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003737<
3738 Return type: |Number|
3739
LemonBoy48b7d052024-07-09 18:24:59 +02003740get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003741 Get item with key {key} from |Dictionary| {dict}. When this
3742 item is not available return {default}. Return zero when
3743 {default} is omitted. Useful example: >
3744 let val = get(g:, 'var_name', 'default')
3745< This gets the value of g:var_name if it exists, and uses
3746 'default' when it does not exist.
3747 Preferably used as a |method|: >
3748 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003749<
h-east84ac2122024-06-17 18:12:30 +02003750 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003751
LemonBoy48b7d052024-07-09 18:24:59 +02003752get({func}, {what}) *get()-func*
3753 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003754 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003755 "name" The function name
3756 "func" The function
3757 "dict" The dictionary
3758 "args" The list with arguments
3759 "arity" A dictionary with information about the number of
3760 arguments accepted by the function (minus the
3761 {arglist}) with the following fields:
3762 required the number of positional arguments
3763 optional the number of optional arguments,
3764 in addition to the required ones
3765 varargs |TRUE| if the function accepts a
3766 variable number of arguments |...|
3767
3768 Note: There is no error, if the {arglist} of
3769 the Funcref contains more arguments than the
3770 Funcref expects, it's not validated.
3771
Bram Moolenaar016188f2022-06-06 20:52:59 +01003772 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003774 Preferably used as a |method|: >
3775 myfunc->get(what)
3776<
LemonBoy48b7d052024-07-09 18:24:59 +02003777 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003779 *getbufinfo()*
3780getbufinfo([{buf}])
3781getbufinfo([{dict}])
3782 Get information about buffers as a List of Dictionaries.
3783
3784 Without an argument information about all the buffers is
3785 returned.
3786
3787 When the argument is a |Dictionary| only the buffers matching
3788 the specified criteria are returned. The following keys can
3789 be specified in {dict}:
3790 buflisted include only listed buffers.
3791 bufloaded include only loaded buffers.
3792 bufmodified include only modified buffers.
3793
3794 Otherwise, {buf} specifies a particular buffer to return
3795 information for. For the use of {buf}, see |bufname()|
3796 above. If the buffer is found the returned List has one item.
3797 Otherwise the result is an empty list.
3798
3799 Each returned List item is a dictionary with the following
3800 entries:
3801 bufnr Buffer number.
3802 changed TRUE if the buffer is modified.
3803 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003804 command TRUE if the buffer belongs to the
3805 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003806 hidden TRUE if the buffer is hidden.
3807 lastused Timestamp in seconds, like
3808 |localtime()|, when the buffer was
3809 last used.
3810 {only with the |+viminfo| feature}
3811 listed TRUE if the buffer is listed.
3812 lnum Line number used for the buffer when
3813 opened in the current window.
3814 Only valid if the buffer has been
3815 displayed in the window in the past.
3816 If you want the line number of the
3817 last known cursor position in a given
3818 window, use |line()|: >
3819 :echo line('.', {winid})
3820<
3821 linecount Number of lines in the buffer (only
3822 valid when loaded)
3823 loaded TRUE if the buffer is loaded.
3824 name Full path to the file in the buffer.
3825 signs List of signs placed in the buffer.
3826 Each list item is a dictionary with
3827 the following fields:
3828 id sign identifier
3829 lnum line number
3830 name sign name
3831 variables A reference to the dictionary with
3832 buffer-local variables.
3833 windows List of |window-ID|s that display this
3834 buffer
3835 popups List of popup |window-ID|s that
3836 display this buffer
3837
3838 Examples: >
3839 for buf in getbufinfo()
3840 echo buf.name
3841 endfor
3842 for buf in getbufinfo({'buflisted':1})
3843 if buf.changed
3844 ....
3845 endif
3846 endfor
3847<
3848 To get buffer-local options use: >
3849 getbufvar({bufnr}, '&option_name')
3850<
3851 Can also be used as a |method|: >
3852 GetBufnr()->getbufinfo()
3853<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003854 Return type: list<dict<any>>
3855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003856
3857 *getbufline()*
3858getbufline({buf}, {lnum} [, {end}])
3859 Return a |List| with the lines starting from {lnum} to {end}
3860 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003861 |List| with only the line {lnum} is returned. See
3862 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003863
3864 For the use of {buf}, see |bufname()| above.
3865
3866 For {lnum} and {end} "$" can be used for the last line of the
3867 buffer. Otherwise a number must be used.
3868
3869 When {lnum} is smaller than 1 or bigger than the number of
3870 lines in the buffer, an empty |List| is returned.
3871
3872 When {end} is greater than the number of lines in the buffer,
3873 it is treated as {end} is set to the number of lines in the
3874 buffer. When {end} is before {lnum} an empty |List| is
3875 returned.
3876
3877 This function works only for loaded buffers. For unloaded and
3878 non-existing buffers, an empty |List| is returned.
3879
3880 Example: >
3881 :let lines = getbufline(bufnr("myfile"), 1, "$")
3882
3883< Can also be used as a |method|: >
3884 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003885<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003886 Return type: list<string>
3887
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003888 *getbufoneline()*
3889getbufoneline({buf}, {lnum})
3890 Just like `getbufline()` but only get one line and return it
3891 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003892
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003893 Return type: |String|
3894
3895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003896getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3897 The result is the value of option or local buffer variable
3898 {varname} in buffer {buf}. Note that the name without "b:"
3899 must be used.
3900 The {varname} argument is a string.
3901 When {varname} is empty returns a |Dictionary| with all the
3902 buffer-local variables.
3903 When {varname} is equal to "&" returns a |Dictionary| with all
3904 the buffer-local options.
3905 Otherwise, when {varname} starts with "&" returns the value of
3906 a buffer-local option.
3907 This also works for a global or buffer-local option, but it
3908 doesn't work for a global variable, window-local variable or
3909 window-local option.
3910 For the use of {buf}, see |bufname()| above.
3911 When the buffer or variable doesn't exist {def} or an empty
3912 string is returned, there is no error message.
3913 Examples: >
3914 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003915 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003916
3917< Can also be used as a |method|: >
3918 GetBufnr()->getbufvar(varname)
3919<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003920 Return type: any, depending on {varname}
3921
3922
mikoto20001083cae2024-11-11 21:24:14 +01003923getcellpixels() *getcellpixels()*
3924 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003925 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003926
3927 Only works on Unix (terminal and gVim) and Windows (gVim only).
3928 Returns [] on other systems or on failure.
3929 Note that there could be variations across different terminals.
3930 On macOS, system Terminal.app returns sizes in points (before
3931 Retina scaling), whereas third-party terminals return raw pixel
3932 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003933
mikoto2000de094dc2024-11-14 22:13:48 +01003934 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003935
3936
Kota Kato66bb9ae2023-01-17 18:31:56 +00003937getcellwidths() *getcellwidths()*
3938 Returns a |List| of cell widths of character ranges overridden
3939 by |setcellwidths()|. The format is equal to the argument of
3940 |setcellwidths()|. If no character ranges have their cell
3941 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003942
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003943 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003944
3945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003946getchangelist([{buf}]) *getchangelist()*
3947 Returns the |changelist| for the buffer {buf}. For the use
3948 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3949 exist, an empty list is returned.
3950
3951 The returned list contains two entries: a list with the change
3952 locations and the current position in the list. Each
3953 entry in the change list is a dictionary with the following
3954 entries:
3955 col column number
3956 coladd column offset for 'virtualedit'
3957 lnum line number
3958 If buffer {buf} is the current buffer, then the current
3959 position refers to the position in the list. For other
3960 buffers, it is set to the length of the list.
3961
3962 Can also be used as a |method|: >
3963 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003964<
3965 Return type: list<any>
3966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003967
zeertzjqe0a2ab32025-02-02 09:14:35 +01003968getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003969 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003970 If {expr} is omitted or is -1, wait until a character is
3971 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003972 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003973 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003974 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003975 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003976 If you prefer always getting a string use |getcharstr()|, or
3977 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003978
Doug Kearns9cd9e752024-04-07 17:42:17 +02003979 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003980 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003981 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003982 Otherwise a String is returned with the encoded character.
3983 For a special key it's a String with a sequence of bytes
3984 starting with 0x80 (decimal: 128). This is the same value as
3985 the String "\<Key>", e.g., "\<Left>". The returned value is
3986 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01003987 that is not included in the character. |keytrans()| can also
3988 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003989
Doug Kearns9cd9e752024-04-07 17:42:17 +02003990 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003991 while Vim waits to see if this is the start of an escape
3992 sequence.
3993
Doug Kearns9cd9e752024-04-07 17:42:17 +02003994 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003995 one-byte character it is the character itself as a number.
3996 Use nr2char() to convert it to a String.
3997
3998 Use getcharmod() to obtain any additional modifiers.
3999
zeertzjqe0a2ab32025-02-02 09:14:35 +01004000 The optional argument {opts} is a Dict and supports the
4001 following items:
4002
zeertzjqedf0f7d2025-02-02 19:01:01 +01004003 cursor A String specifying cursor behavior
4004 when waiting for a character.
4005 "hide": hide the cursor.
4006 "keep": keep current cursor unchanged.
4007 "msg": move cursor to message area.
4008 (default: "msg")
4009
zeertzjqe0a2ab32025-02-02 09:14:35 +01004010 number If |TRUE|, return a Number when getting
4011 a single character.
4012 If |FALSE|, the return value is always
4013 converted to a String, and an empty
4014 String (instead of 0) is returned when
4015 no character is available.
4016 (default: |TRUE|)
4017
4018 simplify If |TRUE|, include modifiers in the
4019 character if possible. E.g., return
4020 the same value for CTRL-I and <Tab>.
4021 If |FALSE|, don't include modifiers in
4022 the character.
4023 (default: |TRUE|)
4024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004025 When the user clicks a mouse button, the mouse event will be
4026 returned. The position can then be found in |v:mouse_col|,
4027 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
4028 |getmousepos()| can also be used. Mouse move events will be
4029 ignored.
4030 This example positions the mouse as it would normally happen: >
4031 let c = getchar()
4032 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004033 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004034 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004035 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004036 endif
4037<
4038 When using bracketed paste only the first character is
4039 returned, the rest of the pasted text is dropped.
4040 |xterm-bracketed-paste|.
4041
4042 There is no prompt, you will somehow have to make clear to the
4043 user that a character has to be typed. The screen is not
4044 redrawn, e.g. when resizing the window. When using a popup
4045 window it should work better with a |popup-filter|.
4046
4047 There is no mapping for the character.
4048 Key codes are replaced, thus when the user presses the <Del>
4049 key you get the code for the <Del> key, not the raw character
4050 sequence. Examples: >
4051 getchar() == "\<Del>"
4052 getchar() == "\<S-Left>"
4053< This example redefines "f" to ignore case: >
4054 :nmap f :call FindChar()<CR>
4055 :function FindChar()
4056 : let c = nr2char(getchar())
4057 : while col('.') < col('$') - 1
4058 : normal l
4059 : if getline('.')[col('.') - 1] ==? c
4060 : break
4061 : endif
4062 : endwhile
4063 :endfunction
4064<
4065 You may also receive synthetic characters, such as
4066 |<CursorHold>|. Often you will want to ignore this and get
4067 another character: >
4068 :function GetKey()
4069 : let c = getchar()
4070 : while c == "\<CursorHold>"
4071 : let c = getchar()
4072 : endwhile
4073 : return c
4074 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004075<
4076 Return type: |Number| or |String|
4077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004078
4079getcharmod() *getcharmod()*
4080 The result is a Number which is the state of the modifiers for
4081 the last obtained character with getchar() or in another way.
4082 These values are added together:
4083 2 shift
4084 4 control
4085 8 alt (meta)
4086 16 meta (when it's different from ALT)
4087 32 mouse double click
4088 64 mouse triple click
4089 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004090 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004091 Only the modifiers that have not been included in the
4092 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004093 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004094
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004095 Return type: |Number|
4096
4097
4098getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004099 Get the position for String {expr}. Same as |getpos()| but the
4100 column number in the returned List is a character index
4101 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004102 If |getpos()| returns a very large column number, equal to
4103 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004104 of the last character.
4105
4106 Example:
4107 With the cursor on '세' in line 5 with text "여보세요": >
4108 getcharpos('.') returns [0, 5, 3, 0]
4109 getpos('.') returns [0, 5, 7, 0]
4110<
4111 Can also be used as a |method|: >
4112 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004113<
4114 Return type: list<number>
4115
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004116
4117getcharsearch() *getcharsearch()*
4118 Return the current character search information as a {dict}
4119 with the following entries:
4120
4121 char character previously used for a character
4122 search (|t|, |f|, |T|, or |F|); empty string
4123 if no character search has been performed
4124 forward direction of character search; 1 for forward,
4125 0 for backward
4126 until type of character search; 1 for a |t| or |T|
4127 character search, 0 for an |f| or |F|
4128 character search
4129
4130 This can be useful to always have |;| and |,| search
4131 forward/backward regardless of the direction of the previous
4132 character search: >
4133 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4134 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4135< Also see |setcharsearch()|.
4136
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004137 Return type: dict<any>
4138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004139
zeertzjqe0a2ab32025-02-02 09:14:35 +01004140getcharstr([{expr} [, {opts}]]) *getcharstr()*
4141 The same as |getchar()|, except that this always returns a
4142 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004143
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004144 Return type: |String|
4145
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004146getcmdcomplpat() *getcmdcomplpat()*
4147 Return completion pattern of the current command-line.
4148 Only works when the command line is being edited, thus
4149 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4150 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4151 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4152 Returns an empty string when completion is not defined.
4153
4154 Return type: |String|
4155
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004156
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004157getcmdcompltype() *getcmdcompltype()*
4158 Return the type of the current command-line completion.
4159 Only works when the command line is being edited, thus
4160 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004161 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004162 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004163 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004164 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004165
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004166 Return type: |String|
4167
4168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004169getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004170 Return the current command-line input. Only works when the
4171 command line is being edited, thus requires use of
4172 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004173 Example: >
4174 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004175< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4176 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004177 Returns an empty string when entering a password or using
4178 |inputsecret()|.
4179
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004180 Return type: |String|
4181
4182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004183getcmdpos() *getcmdpos()*
4184 Return the position of the cursor in the command line as a
4185 byte count. The first column is 1.
4186 Only works when editing the command line, thus requires use of
4187 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4188 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004189 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4190 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004191
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004192 Return type: |Number|
4193
4194
Shougo Matsushita69084282024-09-23 20:34:47 +02004195getcmdprompt() *getcmdprompt()*
4196 Return the current command-line prompt when using functions
4197 like |input()| or |confirm()|.
4198 Only works when the command line is being edited, thus
4199 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4200 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4201 |setcmdpos()| and |setcmdline()|.
4202
4203 Return type: |String|
4204
4205
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004206getcmdscreenpos() *getcmdscreenpos()*
4207 Return the screen position of the cursor in the command line
4208 as a byte count. The first column is 1.
4209 Instead of |getcmdpos()|, it adds the prompt position.
4210 Only works when editing the command line, thus requires use of
4211 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4212 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004213 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4214 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004216 Return type: |Number|
4217
4218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004219getcmdtype() *getcmdtype()*
4220 Return the current command-line type. Possible return values
4221 are:
4222 : normal Ex command
4223 > debug mode command |debug-mode|
4224 / forward search command
4225 ? backward search command
4226 @ |input()| command
4227 - |:insert| or |:append| command
4228 = |i_CTRL-R_=|
4229 Only works when editing the command line, thus requires use of
4230 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4231 Returns an empty string otherwise.
4232 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4233
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004234 Return type: |String|
4235
4236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004237getcmdwintype() *getcmdwintype()*
4238 Return the current |command-line-window| type. Possible return
4239 values are the same as |getcmdtype()|. Returns an empty string
4240 when not in the command-line window.
4241
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004242 Return type: |String|
4243
4244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004245getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4246 Return a list of command-line completion matches. The String
4247 {type} argument specifies what for. The following completion
4248 types are supported:
4249
4250 arglist file names in argument list
4251 augroup autocmd groups
4252 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004253 behave |:behave| suboptions
4254 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004255 color color schemes
4256 command Ex command
4257 cmdline |cmdline-completion| result
4258 compiler compilers
4259 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004260 custom,{func} custom completion, defined via {func}
4261 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004262 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004263 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004264 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004265 environment environment variable names
4266 event autocommand events
4267 expression Vim expression
4268 file file and directory names
4269 file_in_path file and directory names in |'path'|
4270 filetype filetype names |'filetype'|
4271 function function name
4272 help help subjects
4273 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004274 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004275 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004276 locale locale names (as output of locale -a)
4277 mapclear buffer argument
4278 mapping mapping name
4279 menu menus
4280 messages |:messages| suboptions
4281 option options
4282 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004283 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004284 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004285 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004286 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004287 sign |:sign| suboptions
4288 syntax syntax file names |'syntax'|
4289 syntime |:syntime| suboptions
4290 tag tags
4291 tag_listfiles tags, file names
4292 user user names
4293 var user variables
4294
4295 If {pat} is an empty string, then all the matches are
4296 returned. Otherwise only items matching {pat} are returned.
4297 See |wildcards| for the use of special characters in {pat}.
4298
4299 If the optional {filtered} flag is set to 1, then 'wildignore'
4300 is applied to filter the results. Otherwise all the matches
4301 are returned. The 'wildignorecase' option always applies.
4302
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004303 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4304 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004305 regular expression matching is used. Thus this function
4306 follows the user preference, what happens on the command line.
4307 If you do not want this you can make 'wildoptions' empty
4308 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004310 If {type} is "cmdline", then the |cmdline-completion| result is
4311 returned. For example, to complete the possible values after
4312 a ":call" command: >
4313 echo getcompletion('call ', 'cmdline')
4314<
4315 If there are no matches, an empty list is returned. An
4316 invalid value for {type} produces an error.
4317
4318 Can also be used as a |method|: >
4319 GetPattern()->getcompletion('color')
4320<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004321 Return type: list<string>
4322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004323 *getcurpos()*
4324getcurpos([{winid}])
4325 Get the position of the cursor. This is like getpos('.'), but
4326 includes an extra "curswant" item in the list:
4327 [0, lnum, col, off, curswant] ~
4328 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004329 cursor vertically. After |$| command it will be a very large
4330 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004331 |getpos()|.
4332 The first "bufnum" item is always zero. The byte position of
4333 the cursor is returned in 'col'. To get the character
4334 position, use |getcursorcharpos()|.
4335
4336 The optional {winid} argument can specify the window. It can
4337 be the window number or the |window-ID|. The last known
4338 cursor position is returned, this may be invalid for the
4339 current value of the buffer if it is not the current window.
4340 If {winid} is invalid a list with zeroes is returned.
4341
4342 This can be used to save and restore the cursor position: >
4343 let save_cursor = getcurpos()
4344 MoveTheCursorAround
4345 call setpos('.', save_cursor)
4346< Note that this only works within the window. See
4347 |winrestview()| for restoring more state.
4348
4349 Can also be used as a |method|: >
4350 GetWinid()->getcurpos()
4351<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004352 Return type: list<number>
4353
4354
4355getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004356 Same as |getcurpos()| but the column number in the returned
4357 List is a character index instead of a byte index.
4358
4359 Example:
4360 With the cursor on '보' in line 3 with text "여보세요": >
4361 getcursorcharpos() returns [0, 3, 2, 0, 3]
4362 getcurpos() returns [0, 3, 4, 0, 3]
4363<
4364 Can also be used as a |method|: >
4365 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004366<
4367 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004368
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004369
4370getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004371 The result is a String, which is the name of the current
4372 working directory. 'autochdir' is ignored.
4373
4374 With {winnr} return the local current directory of this window
4375 in the current tab page. {winnr} can be the window number or
4376 the |window-ID|.
4377 If {winnr} is -1 return the name of the global working
4378 directory. See also |haslocaldir()|.
4379
4380 With {winnr} and {tabnr} return the local current directory of
4381 the window in the specified tab page. If {winnr} is -1 return
4382 the working directory of the tabpage.
4383 If {winnr} is zero use the current window, if {tabnr} is zero
4384 use the current tabpage.
4385 Without any arguments, return the actual working directory of
4386 the current window.
4387 Return an empty string if the arguments are invalid.
4388
4389 Examples: >
4390 " Get the working directory of the current window
4391 :echo getcwd()
4392 :echo getcwd(0)
4393 :echo getcwd(0, 0)
4394 " Get the working directory of window 3 in tabpage 2
4395 :echo getcwd(3, 2)
4396 " Get the global working directory
4397 :echo getcwd(-1)
4398 " Get the working directory of tabpage 3
4399 :echo getcwd(-1, 3)
4400 " Get the working directory of current tabpage
4401 :echo getcwd(-1, 0)
4402
4403< Can also be used as a |method|: >
4404 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004405<
4406 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004407
4408getenv({name}) *getenv()*
4409 Return the value of environment variable {name}. The {name}
4410 argument is a string, without a leading '$'. Example: >
4411 myHome = getenv('HOME')
4412
4413< When the variable does not exist |v:null| is returned. That
4414 is different from a variable set to an empty string, although
4415 some systems interpret the empty value as the variable being
4416 deleted. See also |expr-env|.
4417
4418 Can also be used as a |method|: >
4419 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004420<
4421 Return type: |String| or |Number|
4422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004423
4424getfontname([{name}]) *getfontname()*
4425 Without an argument returns the name of the normal font being
4426 used. Like what is used for the Normal highlight group
4427 |hl-Normal|.
4428 With an argument a check is done whether String {name} is a
4429 valid font name. If not then an empty string is returned.
4430 Otherwise the actual font name is returned, or {name} if the
4431 GUI does not support obtaining the real name.
4432 Only works when the GUI is running, thus not in your vimrc or
4433 gvimrc file. Use the |GUIEnter| autocommand to use this
4434 function just after the GUI has started.
4435 Note that the GTK GUI accepts any font name, thus checking for
4436 a valid name does not work.
4437
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004438 Return type: |String|
4439
4440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004441getfperm({fname}) *getfperm()*
4442 The result is a String, which is the read, write, and execute
4443 permissions of the given file {fname}.
4444 If {fname} does not exist or its directory cannot be read, an
4445 empty string is returned.
4446 The result is of the form "rwxrwxrwx", where each group of
4447 "rwx" flags represent, in turn, the permissions of the owner
4448 of the file, the group the file belongs to, and other users.
4449 If a user does not have a given permission the flag for this
4450 is replaced with the string "-". Examples: >
4451 :echo getfperm("/etc/passwd")
4452 :echo getfperm(expand("~/.vimrc"))
4453< This will hopefully (from a security point of view) display
4454 the string "rw-r--r--" or even "rw-------".
4455
4456 Can also be used as a |method|: >
4457 GetFilename()->getfperm()
4458<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004459 Return type: |String|
4460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004461 For setting permissions use |setfperm()|.
4462
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004463
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004464getfsize({fname}) *getfsize()*
4465 The result is a Number, which is the size in bytes of the
4466 given file {fname}.
4467 If {fname} is a directory, 0 is returned.
4468 If the file {fname} can't be found, -1 is returned.
4469 If the size of {fname} is too big to fit in a Number then -2
4470 is returned.
4471
4472 Can also be used as a |method|: >
4473 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004474<
4475 Return type: |Number|
4476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004477
4478getftime({fname}) *getftime()*
4479 The result is a Number, which is the last modification time of
4480 the given file {fname}. The value is measured as seconds
4481 since 1st Jan 1970, and may be passed to strftime(). See also
4482 |localtime()| and |strftime()|.
4483 If the file {fname} can't be found -1 is returned.
4484
4485 Can also be used as a |method|: >
4486 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004487<
4488 Return type: |Number|
4489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004490
4491getftype({fname}) *getftype()*
4492 The result is a String, which is a description of the kind of
4493 file of the given file {fname}.
4494 If {fname} does not exist an empty string is returned.
4495 Here is a table over different kinds of files and their
4496 results:
4497 Normal file "file"
4498 Directory "dir"
4499 Symbolic link "link"
4500 Block device "bdev"
4501 Character device "cdev"
4502 Socket "socket"
4503 FIFO "fifo"
4504 All other "other"
4505 Example: >
4506 getftype("/home")
4507< Note that a type such as "link" will only be returned on
4508 systems that support it. On some systems only "dir" and
4509 "file" are returned. On MS-Windows a symbolic link to a
4510 directory returns "dir" instead of "link".
4511
4512 Can also be used as a |method|: >
4513 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004514<
4515 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004516
4517getimstatus() *getimstatus()*
4518 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004519 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004520 See 'imstatusfunc'.
4521
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004522 Return type: |Number|
4523
4524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004525getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4526 Returns the |jumplist| for the specified window.
4527
4528 Without arguments use the current window.
4529 With {winnr} only use this window in the current tab page.
4530 {winnr} can also be a |window-ID|.
4531 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004532 page. If {winnr} or {tabnr} is invalid, an empty list is
4533 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004534
4535 The returned list contains two entries: a list with the jump
4536 locations and the last used jump position number in the list.
4537 Each entry in the jump location list is a dictionary with
4538 the following entries:
4539 bufnr buffer number
4540 col column number
4541 coladd column offset for 'virtualedit'
4542 filename filename if available
4543 lnum line number
4544
4545 Can also be used as a |method|: >
4546 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004547<
4548 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004549
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004550 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004551getline({lnum} [, {end}])
4552 Without {end} the result is a String, which is line {lnum}
4553 from the current buffer. Example: >
4554 getline(1)
4555< When {lnum} is a String that doesn't start with a
4556 digit, |line()| is called to translate the String into a Number.
4557 To get the line under the cursor: >
4558 getline(".")
4559< When {lnum} is a number smaller than 1 or bigger than the
4560 number of lines in the buffer, an empty string is returned.
4561
4562 When {end} is given the result is a |List| where each item is
4563 a line from the current buffer in the range {lnum} to {end},
4564 including line {end}.
4565 {end} is used in the same way as {lnum}.
4566 Non-existing lines are silently omitted.
4567 When {end} is before {lnum} an empty |List| is returned.
4568 Example: >
4569 :let start = line('.')
4570 :let end = search("^$") - 1
4571 :let lines = getline(start, end)
4572
4573< Can also be used as a |method|: >
4574 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004575<
4576 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004577
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004578 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004579 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004580
4581getloclist({nr} [, {what}]) *getloclist()*
4582 Returns a |List| with all the entries in the location list for
4583 window {nr}. {nr} can be the window number or the |window-ID|.
4584 When {nr} is zero the current window is used.
4585
4586 For a location list window, the displayed location list is
4587 returned. For an invalid window number {nr}, an empty list is
4588 returned. Otherwise, same as |getqflist()|.
4589
4590 If the optional {what} dictionary argument is supplied, then
4591 returns the items listed in {what} as a dictionary. Refer to
4592 |getqflist()| for the supported items in {what}.
4593
4594 In addition to the items supported by |getqflist()| in {what},
4595 the following item is supported by |getloclist()|:
4596
4597 filewinid id of the window used to display files
4598 from the location list. This field is
4599 applicable only when called from a
4600 location list window. See
4601 |location-list-file-window| for more
4602 details.
4603
4604 Returns a |Dictionary| with default values if there is no
4605 location list for the window {nr}.
4606 Returns an empty Dictionary if window {nr} does not exist.
4607
4608 Examples (See also |getqflist-examples|): >
4609 :echo getloclist(3, {'all': 0})
4610 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004611<
4612 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004613
4614
4615getmarklist([{buf}]) *getmarklist()*
4616 Without the {buf} argument returns a |List| with information
4617 about all the global marks. |mark|
4618
4619 If the optional {buf} argument is specified, returns the
4620 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004621 see |bufname()|. If {buf} is invalid, an empty list is
4622 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004623
4624 Each item in the returned List is a |Dict| with the following:
4625 mark name of the mark prefixed by "'"
4626 pos a |List| with the position of the mark:
4627 [bufnum, lnum, col, off]
4628 Refer to |getpos()| for more information.
4629 file file name
4630
4631 Refer to |getpos()| for getting information about a specific
4632 mark.
4633
4634 Can also be used as a |method|: >
4635 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004636<
4637 Return type: list<dict<any>> or list<any>
4638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004639
4640getmatches([{win}]) *getmatches()*
4641 Returns a |List| with all matches previously defined for the
4642 current window by |matchadd()| and the |:match| commands.
4643 |getmatches()| is useful in combination with |setmatches()|,
4644 as |setmatches()| can restore a list of matches saved by
4645 |getmatches()|.
4646 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004647 window ID instead of the current window. If {win} is invalid,
4648 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004649 Example: >
4650 :echo getmatches()
4651< [{'group': 'MyGroup1', 'pattern': 'TODO',
4652 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4653 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4654 :let m = getmatches()
4655 :call clearmatches()
4656 :echo getmatches()
4657< [] >
4658 :call setmatches(m)
4659 :echo getmatches()
4660< [{'group': 'MyGroup1', 'pattern': 'TODO',
4661 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4662 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4663 :unlet m
4664<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004665 Return type: list<dict<any>> or list<any>
4666
4667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004668getmousepos() *getmousepos()*
4669 Returns a |Dictionary| with the last known position of the
4670 mouse. This can be used in a mapping for a mouse click or in
4671 a filter of a popup window. The items are:
4672 screenrow screen row
4673 screencol screen column
4674 winid Window ID of the click
4675 winrow row inside "winid"
4676 wincol column inside "winid"
4677 line text line inside "winid"
4678 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004679 coladd offset (in screen columns) from the
4680 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004681 All numbers are 1-based.
4682
4683 If not over a window, e.g. when in the command line, then only
4684 "screenrow" and "screencol" are valid, the others are zero.
4685
4686 When on the status line below a window or the vertical
4687 separator right of a window, the "line" and "column" values
4688 are zero.
4689
4690 When the position is after the text then "column" is the
4691 length of the text in bytes plus one.
4692
4693 If the mouse is over a popup window then that window is used.
4694
4695 When using |getchar()| the Vim variables |v:mouse_lnum|,
4696 |v:mouse_col| and |v:mouse_winid| also provide these values.
4697
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004698 Return type: dict<number>
4699
4700
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004701getmouseshape() *getmouseshape()*
4702 Returns the name of the currently showing mouse pointer.
4703 When the |+mouseshape| feature is not supported or the shape
4704 is unknown an empty string is returned.
4705 This function is mainly intended for testing.
4706
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004707 Return type: |String|
4708
4709
4710getpid() *getpid()*
4711 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004712 On Unix and MS-Windows this is a unique number, until Vim
4713 exits.
4714
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004715 Return type: |Number|
4716
4717
4718getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004719 Get the position for String {expr}.
4720 The accepted values for {expr} are: *E1209*
4721 . The cursor position.
4722 $ The last line in the current buffer.
4723 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004724 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004725 w0 First line visible in current window (one if the
4726 display isn't updated, e.g. in silent Ex mode).
4727 w$ Last line visible in current window (this is one
4728 less than "w0" if no lines are visible).
4729 v When not in Visual mode, returns the cursor
4730 position. In Visual mode, returns the other end
4731 of the Visual area. A good way to think about
4732 this is that in Visual mode "v" and "." complement
4733 each other. While "." refers to the cursor
4734 position, "v" refers to where |v_o| would move the
4735 cursor. As a result, you can use "v" and "."
4736 together to work on all of a selection in
4737 characterwise Visual mode. If the cursor is at
4738 the end of a characterwise Visual area, "v" refers
4739 to the start of the same Visual area. And if the
4740 cursor is at the start of a characterwise Visual
4741 area, "v" refers to the end of the same Visual
4742 area. "v" differs from |'<| and |'>| in that it's
4743 updated right away.
4744 Note that a mark in another file can be used. The line number
4745 then applies to another buffer.
4746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004747 The result is a |List| with four numbers:
4748 [bufnum, lnum, col, off]
4749 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4750 is the buffer number of the mark.
4751 "lnum" and "col" are the position in the buffer. The first
4752 column is 1.
4753 The "off" number is zero, unless 'virtualedit' is used. Then
4754 it is the offset in screen columns from the start of the
4755 character. E.g., a position within a <Tab> or after the last
4756 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004757
4758 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004759 The column number in the returned List is the byte position
4760 within the line. To get the character position in the line,
4761 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004762
4763 Note that for '< and '> Visual mode matters: when it is "V"
4764 (visual line mode) the column of '< is zero and the column of
4765 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004766 A very large column number equal to |v:maxcol| can be returned,
4767 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004768 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004770 This can be used to save and restore the position of a mark: >
4771 let save_a_mark = getpos("'a")
4772 ...
4773 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004774<
4775 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004776
4777 Can also be used as a |method|: >
4778 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004779<
4780 Return type: list<number>
4781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004782
4783getqflist([{what}]) *getqflist()*
4784 Returns a |List| with all the current quickfix errors. Each
4785 list item is a dictionary with these entries:
4786 bufnr number of buffer that has the file name, use
4787 bufname() to get the name
4788 module module name
4789 lnum line number in the buffer (first line is 1)
4790 end_lnum
4791 end of line number if the item is multiline
4792 col column number (first column is 1)
4793 end_col end of column number if the item has range
4794 vcol |TRUE|: "col" is visual column
4795 |FALSE|: "col" is byte index
4796 nr error number
h-east84ac2122024-06-17 18:12:30 +02004797 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004798 text description of the error
4799 type type of the error, 'E', '1', etc.
4800 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004801 user_data
4802 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004803 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004804
4805 When there is no error list or it's empty, an empty list is
4806 returned. Quickfix list entries with a non-existing buffer
4807 number are returned with "bufnr" set to zero (Note: some
4808 functions accept buffer number zero for the alternate buffer,
4809 you may need to explicitly check for zero).
4810
4811 Useful application: Find pattern matches in multiple files and
4812 do something with them: >
4813 :vimgrep /theword/jg *.c
4814 :for d in getqflist()
4815 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4816 :endfor
4817<
4818 If the optional {what} dictionary argument is supplied, then
4819 returns only the items listed in {what} as a dictionary. The
4820 following string items are supported in {what}:
4821 changedtick get the total number of changes made
4822 to the list |quickfix-changedtick|
4823 context get the |quickfix-context|
4824 efm errorformat to use when parsing "lines". If
4825 not present, then the 'errorformat' option
4826 value is used.
4827 id get information for the quickfix list with
4828 |quickfix-ID|; zero means the id for the
4829 current list or the list specified by "nr"
4830 idx get information for the quickfix entry at this
4831 index in the list specified by 'id' or 'nr'.
4832 If set to zero, then uses the current entry.
4833 See |quickfix-index|
4834 items quickfix list entries
4835 lines parse a list of lines using 'efm' and return
4836 the resulting entries. Only a |List| type is
4837 accepted. The current quickfix list is not
4838 modified. See |quickfix-parse|.
4839 nr get information for this quickfix list; zero
4840 means the current quickfix list and "$" means
4841 the last quickfix list
4842 qfbufnr number of the buffer displayed in the quickfix
4843 window. Returns 0 if the quickfix buffer is
4844 not present. See |quickfix-buffer|.
4845 size number of entries in the quickfix list
4846 title get the list title |quickfix-title|
4847 winid get the quickfix |window-ID|
4848 all all of the above quickfix properties
4849 Non-string items in {what} are ignored. To get the value of a
4850 particular item, set it to zero.
4851 If "nr" is not present then the current quickfix list is used.
4852 If both "nr" and a non-zero "id" are specified, then the list
4853 specified by "id" is used.
4854 To get the number of lists in the quickfix stack, set "nr" to
4855 "$" in {what}. The "nr" value in the returned dictionary
4856 contains the quickfix stack size.
4857 When "lines" is specified, all the other items except "efm"
4858 are ignored. The returned dictionary contains the entry
4859 "items" with the list of entries.
4860
4861 The returned dictionary contains the following entries:
4862 changedtick total number of changes made to the
4863 list |quickfix-changedtick|
4864 context quickfix list context. See |quickfix-context|
4865 If not present, set to "".
4866 id quickfix list ID |quickfix-ID|. If not
4867 present, set to 0.
4868 idx index of the quickfix entry in the list. If not
4869 present, set to 0.
4870 items quickfix list entries. If not present, set to
4871 an empty list.
4872 nr quickfix list number. If not present, set to 0
4873 qfbufnr number of the buffer displayed in the quickfix
4874 window. If not present, set to 0.
4875 size number of entries in the quickfix list. If not
4876 present, set to 0.
4877 title quickfix list title text. If not present, set
4878 to "".
4879 winid quickfix |window-ID|. If not present, set to 0
4880
4881 Examples (See also |getqflist-examples|): >
4882 :echo getqflist({'all': 1})
4883 :echo getqflist({'nr': 2, 'title': 1})
4884 :echo getqflist({'lines' : ["F1:10:L10"]})
4885<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004886 Return type: list<dict<any>> or list<any>
4887
4888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004889getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4890 The result is a String, which is the contents of register
4891 {regname}. Example: >
4892 :let cliptext = getreg('*')
4893< When register {regname} was not set the result is an empty
4894 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004895 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004896
4897 getreg('=') returns the last evaluated value of the expression
4898 register. (For use in maps.)
4899 getreg('=', 1) returns the expression itself, so that it can
4900 be restored with |setreg()|. For other registers the extra
4901 argument is ignored, thus you can always give it.
4902
4903 If {list} is present and |TRUE|, the result type is changed
4904 to |List|. Each list item is one text line. Use it if you care
4905 about zero bytes possibly present inside register: without
4906 third argument both NLs and zero bytes are represented as NLs
4907 (see |NL-used-for-Nul|).
4908 When the register was not set an empty list is returned.
4909
4910 If {regname} is "", the unnamed register '"' is used.
4911 If {regname} is not specified, |v:register| is used.
4912 In |Vim9-script| {regname} must be one character.
4913
4914 Can also be used as a |method|: >
4915 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004916<
4917 Return type: |String|
4918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004919
4920getreginfo([{regname}]) *getreginfo()*
4921 Returns detailed information about register {regname} as a
4922 Dictionary with the following entries:
4923 regcontents List of lines contained in register
4924 {regname}, like
4925 |getreg|({regname}, 1, 1).
4926 regtype the type of register {regname}, as in
4927 |getregtype()|.
4928 isunnamed Boolean flag, v:true if this register
4929 is currently pointed to by the unnamed
4930 register.
4931 points_to for the unnamed register, gives the
4932 single letter name of the register
4933 currently pointed to (see |quotequote|).
4934 For example, after deleting a line
4935 with `dd`, this field will be "1",
4936 which is the register that got the
4937 deleted text.
4938
4939 The {regname} argument is a string. If {regname} is invalid
4940 or not set, an empty Dictionary will be returned.
4941 If {regname} is "" or "@", the unnamed register '"' is used.
4942 If {regname} is not specified, |v:register| is used.
4943 The returned Dictionary can be passed to |setreg()|.
4944 In |Vim9-script| {regname} must be one character.
4945
4946 Can also be used as a |method|: >
4947 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004948<
4949 Return type: dict<any>
4950
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004951
Shougo Matsushita19b71882024-02-28 22:48:12 +01004952getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004953 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004954 buffer.
4955
4956 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004957 See |getpos()| for the format of the list. It's possible
4958 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004959 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004960
4961 The optional argument {opts} is a Dict and supports the
4962 following items:
4963
zeertzjqafc22952024-05-24 19:07:12 +02004964 type Specify the region's selection type.
4965 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004966 except that the width can be omitted
4967 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004968 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004969
zeertzjq87410ab2024-03-02 06:00:23 +08004970 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004971 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004972 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004973
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004974 You can get the last selection type by |visualmode()|.
4975 If Visual mode is active, use |mode()| to get the Visual mode
4976 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004977 This function is useful to get text starting and ending in
4978 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004979
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004980 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004981 Note that:
4982 - Order of {pos1} and {pos2} doesn't matter, it will always
4983 return content from the upper left position to the lower
4984 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004985 - If 'virtualedit' is enabled and the region is past the end
4986 of the lines, resulting lines are padded with spaces.
4987 - If the region is blockwise and it starts or ends in the
4988 middle of a multi-cell character, it is not included but
4989 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004990 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004991 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004992 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004993 - It is evaluated in current window context, which makes a
4994 difference if the buffer is displayed in a window with
4995 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004996
4997 Examples: >
4998 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004999 \ <Cmd>echow getregion(
5000 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005001<
5002 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01005003 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02005004<
5005 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005006
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005007
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005008getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
5009 Same as |getregion()|, but returns a list of positions
5010 describing the buffer text segments bound by {pos1} and
5011 {pos2}.
5012 The segments are a pair of positions for every line: >
5013 [[{start_pos}, {end_pos}], ...]
5014<
5015 The position is a |List| with four numbers:
5016 [bufnum, lnum, col, off]
5017 "bufnum" is the buffer number.
5018 "lnum" and "col" are the position in the buffer. The first
5019 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02005020 If the "off" number of a starting position is non-zero, it is
5021 the offset in screen columns from the start of the character.
5022 E.g., a position within a <Tab> or after the last character.
5023 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02005024 the offset of the character's first cell not included in the
5025 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005026
zeertzjq2b09de92024-05-24 07:48:51 +02005027 Apart from the options supported by |getregion()|, {opts} also
5028 supports the following:
5029
5030 eol If |TRUE|, indicate positions beyond
5031 the end of a line with "col" values
5032 one more than the length of the line.
5033 If |FALSE|, positions are limited
5034 within their lines, and if a line is
5035 empty or the selection is entirely
5036 beyond the end of a line, a "col"
5037 value of 0 is used for both positions.
5038 (default: |FALSE|)
5039
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005040 Can also be used as a |method|: >
5041 getpos('.')->getregionpos(getpos("'a"))
5042<
Christian Brabandt83d74402025-03-19 21:55:59 +01005043 For an example, see the highlight-yank plugin |52.6|
5044
zeertzjqd4d12072024-07-16 20:34:16 +02005045 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005046
5047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005048getregtype([{regname}]) *getregtype()*
5049 The result is a String, which is type of register {regname}.
5050 The value will be one of:
5051 "v" for |characterwise| text
5052 "V" for |linewise| text
5053 "<CTRL-V>{width}" for |blockwise-visual| text
5054 "" for an empty or unknown register
5055 <CTRL-V> is one character with value 0x16.
5056 The {regname} argument is a string. If {regname} is "", the
5057 unnamed register '"' is used. If {regname} is not specified,
5058 |v:register| is used.
5059 In |Vim9-script| {regname} must be one character.
5060
5061 Can also be used as a |method|: >
5062 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005063<
5064 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005065
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005066
Bram Moolenaar71badf92023-04-22 22:40:14 +01005067getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005068 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005069 scripts in the order they were sourced, like what
5070 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005071
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005072 The optional Dict argument {opts} supports the following
5073 optional items:
5074 name Script name match pattern. If specified,
5075 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005076 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005077 "name" are returned.
5078 sid Script ID |<SID>|. If specified, only
5079 information about the script with ID "sid" is
5080 returned and "name" is ignored.
5081
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005082 Each item in the returned List is a |Dict| with the following
5083 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005084 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005085 `import autoload` but was not actually sourced
5086 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005087 functions List of script-local function names defined in
5088 the script. Present only when a particular
5089 script is specified using the "sid" item in
5090 {opts}.
5091 name Vim script file name.
5092 sid Script ID |<SID>|.
5093 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005094 this script name links to, if any, otherwise
5095 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005096 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005097 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005098 specified using the "sid" item in {opts}.
5099 Note that this is a copy, the value of
5100 script-local variables cannot be changed using
5101 this dictionary.
h_east59858792023-10-25 22:47:05 +09005102 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005103
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005104 Examples: >
5105 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005106 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005107<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005108 Return type: list<dict<any>>
5109
5110
ichizok663d18d2025-01-02 18:06:00 +01005111getstacktrace() *getstacktrace()*
5112 Returns the current stack trace of Vim scripts.
5113 Stack trace is a |List|, of which each item is a |Dictionary|
5114 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005115 funcref The funcref if the stack is at a function,
5116 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005117 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005118 stack is at an autocmd event, otherwise this
5119 item is omitted.
5120 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005121 filepath The file path of the script on the stack.
5122
5123 Return type: list<dict<any>>
5124
5125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005126gettabinfo([{tabnr}]) *gettabinfo()*
5127 If {tabnr} is not specified, then information about all the
5128 tab pages is returned as a |List|. Each List item is a
5129 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5130 number and information about that one is returned. If the tab
5131 page does not exist an empty List is returned.
5132
5133 Each List item is a |Dictionary| with the following entries:
5134 tabnr tab page number.
5135 variables a reference to the dictionary with
5136 tabpage-local variables
5137 windows List of |window-ID|s in the tab page.
5138
5139 Can also be used as a |method|: >
5140 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005141<
5142 Return type: list<dict<any>>
5143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005144
5145gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5146 Get the value of a tab-local variable {varname} in tab page
5147 {tabnr}. |t:var|
5148 Tabs are numbered starting with one.
5149 The {varname} argument is a string. When {varname} is empty a
5150 dictionary with all tab-local variables is returned.
5151 Note that the name without "t:" must be used.
5152 When the tab or variable doesn't exist {def} or an empty
5153 string is returned, there is no error message.
5154
5155 Can also be used as a |method|: >
5156 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005157<
5158 Return type: any, depending on {varname}
5159
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005160
5161gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5162 Get the value of window-local variable {varname} in window
5163 {winnr} in tab page {tabnr}.
5164 The {varname} argument is a string. When {varname} is empty a
5165 dictionary with all window-local variables is returned.
5166 When {varname} is equal to "&" get the values of all
5167 window-local options in a |Dictionary|.
5168 Otherwise, when {varname} starts with "&" get the value of a
5169 window-local option.
5170 Note that {varname} must be the name without "w:".
5171 Tabs are numbered starting with one. For the current tabpage
5172 use |getwinvar()|.
5173 {winnr} can be the window number or the |window-ID|.
5174 When {winnr} is zero the current window is used.
5175 This also works for a global option, buffer-local option and
5176 window-local option, but it doesn't work for a global variable
5177 or buffer-local variable.
5178 When the tab, window or variable doesn't exist {def} or an
5179 empty string is returned, there is no error message.
5180 Examples: >
5181 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005182 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005183<
5184 To obtain all window-local variables use: >
5185 gettabwinvar({tabnr}, {winnr}, '&')
5186
5187< Can also be used as a |method|: >
5188 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005189<
5190 Return type: any, depending on {varname}
5191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005192
5193gettagstack([{winnr}]) *gettagstack()*
5194 The result is a Dict, which is the tag stack of window {winnr}.
5195 {winnr} can be the window number or the |window-ID|.
5196 When {winnr} is not specified, the current window is used.
5197 When window {winnr} doesn't exist, an empty Dict is returned.
5198
5199 The returned dictionary contains the following entries:
5200 curidx Current index in the stack. When at
5201 top of the stack, set to (length + 1).
5202 Index of bottom of the stack is 1.
5203 items List of items in the stack. Each item
5204 is a dictionary containing the
5205 entries described below.
5206 length Number of entries in the stack.
5207
5208 Each item in the stack is a dictionary with the following
5209 entries:
5210 bufnr buffer number of the current jump
5211 from cursor position before the tag jump.
5212 See |getpos()| for the format of the
5213 returned list.
5214 matchnr current matching tag number. Used when
5215 multiple matching tags are found for a
5216 name.
5217 tagname name of the tag
5218
5219 See |tagstack| for more information about the tag stack.
5220
5221 Can also be used as a |method|: >
5222 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005223<
5224 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005225
5226
Christ van Willegence0ef912024-06-20 23:41:59 +02005227gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005228 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005229 This is intended for use in Vim scripts. When generating
5230 message translations the {text} is extracted by `xgettext`,
5231 the translator can add translated messages into the .po file
5232 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005233 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005234 `xgettext` does not support single quoted escaped text.
5235
Christ van Willegence0ef912024-06-20 23:41:59 +02005236 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005237 for that specific package. This is mainly required for
5238 third-party Vim scripts. You need to specify a path to the
5239 translations with the |bindtextdomain()| function before
5240 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005241
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005242 Return type: |String|
5243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005244
5245getwininfo([{winid}]) *getwininfo()*
5246 Returns information about windows as a |List| with Dictionaries.
5247
5248 If {winid} is given Information about the window with that ID
5249 is returned, as a |List| with one item. If the window does not
5250 exist the result is an empty list.
5251
5252 Without {winid} information about all the windows in all the
5253 tab pages is returned.
5254
5255 Each List item is a |Dictionary| with the following entries:
5256 botline last complete displayed buffer line
5257 bufnr number of buffer in the window
5258 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005259 leftcol first column displayed; only used when
5260 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005261 loclist 1 if showing a location list
5262 {only with the +quickfix feature}
5263 quickfix 1 if quickfix or location list window
5264 {only with the +quickfix feature}
5265 terminal 1 if a terminal window
5266 {only with the +terminal feature}
5267 tabnr tab page number
5268 topline first displayed buffer line
5269 variables a reference to the dictionary with
5270 window-local variables
5271 width window width
5272 winbar 1 if the window has a toolbar, 0
5273 otherwise
5274 wincol leftmost screen column of the window;
5275 "col" from |win_screenpos()|
5276 textoff number of columns occupied by any
5277 'foldcolumn', 'signcolumn' and line
5278 number in front of the text
5279 winid |window-ID|
5280 winnr window number
5281 winrow topmost screen line of the window;
5282 "row" from |win_screenpos()|
5283
5284 Can also be used as a |method|: >
5285 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005286<
5287 Return type: list<dict<any>>
5288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005289
5290getwinpos([{timeout}]) *getwinpos()*
5291 The result is a |List| with two numbers, the result of
5292 |getwinposx()| and |getwinposy()| combined:
5293 [x-pos, y-pos]
5294 {timeout} can be used to specify how long to wait in msec for
5295 a response from the terminal. When omitted 100 msec is used.
5296 Use a longer time for a remote terminal.
5297 When using a value less than 10 and no response is received
5298 within that time, a previously reported position is returned,
5299 if available. This can be used to poll for the position and
5300 do some work in the meantime: >
5301 while 1
5302 let res = getwinpos(1)
5303 if res[0] >= 0
5304 break
5305 endif
5306 " Do some work here
5307 endwhile
5308<
5309
5310 Can also be used as a |method|: >
5311 GetTimeout()->getwinpos()
5312<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005313 Return type: list<number>
5314
5315
5316getwinposx() *getwinposx()*
5317 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005318 the left hand side of the GUI Vim window. Also works for an
5319 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005320 The result will be -1 if the information is not available
5321 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005322 The value can be used with `:winpos`.
5323
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005324 Return type: |Number|
5325
5326
5327getwinposy() *getwinposy()*
5328 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005329 the top of the GUI Vim window. Also works for an xterm (uses
5330 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005331 The result will be -1 if the information is not available
5332 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005333 The value can be used with `:winpos`.
5334
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005335 Return type: |Number|
5336
5337
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005338getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5339 Like |gettabwinvar()| for the current tabpage.
5340 Examples: >
5341 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005342 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005343
5344< Can also be used as a |method|: >
5345 GetWinnr()->getwinvar(varname)
5346<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005347 Return type: any, depending on {varname}
5348
5349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005350glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5351 Expand the file wildcards in {expr}. See |wildcards| for the
5352 use of special characters.
5353
5354 Unless the optional {nosuf} argument is given and is |TRUE|,
5355 the 'suffixes' and 'wildignore' options apply: Names matching
5356 one of the patterns in 'wildignore' will be skipped and
5357 'suffixes' affect the ordering of matches.
5358 'wildignorecase' always applies.
5359
5360 When {list} is present and it is |TRUE| the result is a |List|
5361 with all matching files. The advantage of using a List is,
5362 you also get filenames containing newlines correctly.
5363 Otherwise the result is a String and when there are several
5364 matches, they are separated by <NL> characters.
5365
5366 If the expansion fails, the result is an empty String or List.
5367
5368 You can also use |readdir()| if you need to do complicated
5369 things, such as limiting the number of matches.
5370
5371 A name for a non-existing file is not included. A symbolic
5372 link is only included if it points to an existing file.
5373 However, when the {alllinks} argument is present and it is
5374 |TRUE| then all symbolic links are included.
5375
5376 For most systems backticks can be used to get files names from
5377 any external command. Example: >
5378 :let tagfiles = glob("`find . -name tags -print`")
5379 :let &tags = substitute(tagfiles, "\n", ",", "g")
5380< The result of the program inside the backticks should be one
5381 item per line. Spaces inside an item are allowed.
5382
5383 See |expand()| for expanding special Vim variables. See
5384 |system()| for getting the raw output of an external command.
5385
5386 Can also be used as a |method|: >
5387 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005388<
5389 Return type: |String| or list<string> or list<any> depending
5390 on {list}
5391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005392
h-east624bb832024-11-09 18:37:32 +01005393glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005394 Convert a file pattern, as used by glob(), into a search
5395 pattern. The result can be used to match with a string that
5396 is a file name. E.g. >
5397 if filename =~ glob2regpat('Make*.mak')
5398< This is equivalent to: >
5399 if filename =~ '^Make.*\.mak$'
5400< When {string} is an empty string the result is "^$", match an
5401 empty string.
5402 Note that the result depends on the system. On MS-Windows
5403 a backslash usually means a path separator.
5404
5405 Can also be used as a |method|: >
5406 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005407<
5408 Return type: |String|
5409
5410 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005411globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5412 Perform glob() for String {expr} on all directories in {path}
5413 and concatenate the results. Example: >
5414 :echo globpath(&rtp, "syntax/c.vim")
5415<
5416 {path} is a comma-separated list of directory names. Each
5417 directory name is prepended to {expr} and expanded like with
5418 |glob()|. A path separator is inserted when needed.
5419 To add a comma inside a directory name escape it with a
5420 backslash. Note that on MS-Windows a directory may have a
5421 trailing backslash, remove it if you put a comma after it.
5422 If the expansion fails for one of the directories, there is no
5423 error message.
5424
5425 Unless the optional {nosuf} argument is given and is |TRUE|,
5426 the 'suffixes' and 'wildignore' options apply: Names matching
5427 one of the patterns in 'wildignore' will be skipped and
5428 'suffixes' affect the ordering of matches.
5429
5430 When {list} is present and it is |TRUE| the result is a |List|
5431 with all matching files. The advantage of using a List is, you
5432 also get filenames containing newlines correctly. Otherwise
5433 the result is a String and when there are several matches,
5434 they are separated by <NL> characters. Example: >
5435 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5436<
5437 {alllinks} is used as with |glob()|.
5438
5439 The "**" item can be used to search in a directory tree.
5440 For example, to find all "README.txt" files in the directories
5441 in 'runtimepath' and below: >
5442 :echo globpath(&rtp, "**/README.txt")
5443< Upwards search and limiting the depth of "**" is not
5444 supported, thus using 'path' will not always work properly.
5445
5446 Can also be used as a |method|, the base is passed as the
5447 second argument: >
5448 GetExpr()->globpath(&rtp)
5449<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005450 Return type: |String| or list<string> or list<any> depending
5451 on {list}
5452
5453
5454has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005455 When {check} is omitted or is zero: The result is a Number,
5456 which is 1 if the feature {feature} is supported, zero
5457 otherwise. The {feature} argument is a string, case is
5458 ignored. See |feature-list| below.
5459
5460 When {check} is present and not zero: The result is a Number,
5461 which is 1 if the feature {feature} could ever be supported,
5462 zero otherwise. This is useful to check for a typo in
5463 {feature} and to detect dead code. Keep in mind that an older
5464 Vim version will not know about a feature added later and
5465 features that have been abandoned will not be known by the
5466 current Vim version.
5467
5468 Also see |exists()| and |exists_compiled()|.
5469
5470 Note that to skip code that has a syntax error when the
5471 feature is not available, Vim may skip the rest of the line
5472 and miss a following `endif`. Therefore put the `endif` on a
5473 separate line: >
5474 if has('feature')
5475 let x = this->breaks->without->the->feature
5476 endif
5477< If the `endif` would be moved to the second line as "| endif" it
5478 would not be found.
5479
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005480 Return type: |Number|
5481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005482
5483has_key({dict}, {key}) *has_key()*
5484 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005485 has an entry with key {key}. FALSE otherwise.
5486 The {key} argument is a string. In |Vim9| script a number is
5487 also accepted (and converted to a string) but no other types.
5488 In legacy script the usual automatic conversion to string is
5489 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005490
5491 Can also be used as a |method|: >
5492 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005493<
5494 Return type: |Number|
5495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005496
5497haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5498 The result is a Number:
5499 1 when the window has set a local directory via |:lcd|
5500 2 when the tab-page has set a local directory via |:tcd|
5501 0 otherwise.
5502
5503 Without arguments use the current window.
5504 With {winnr} use this window in the current tab page.
5505 With {winnr} and {tabnr} use the window in the specified tab
5506 page.
5507 {winnr} can be the window number or the |window-ID|.
5508 If {winnr} is -1 it is ignored and only the tabpage is used.
5509 Return 0 if the arguments are invalid.
5510 Examples: >
5511 if haslocaldir() == 1
5512 " window local directory case
5513 elseif haslocaldir() == 2
5514 " tab-local directory case
5515 else
5516 " global directory case
5517 endif
5518
5519 " current window
5520 :echo haslocaldir()
5521 :echo haslocaldir(0)
5522 :echo haslocaldir(0, 0)
5523 " window n in current tab page
5524 :echo haslocaldir(n)
5525 :echo haslocaldir(n, 0)
5526 " window n in tab page m
5527 :echo haslocaldir(n, m)
5528 " tab page m
5529 :echo haslocaldir(-1, m)
5530<
5531 Can also be used as a |method|: >
5532 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005533<
5534 Return type: |Number|
5535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005536
5537hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5538 The result is a Number, which is TRUE if there is a mapping
5539 that contains {what} in somewhere in the rhs (what it is
5540 mapped to) and this mapping exists in one of the modes
5541 indicated by {mode}.
5542 The arguments {what} and {mode} are strings.
5543 When {abbr} is there and it is |TRUE| use abbreviations
5544 instead of mappings. Don't forget to specify Insert and/or
5545 Command-line mode.
5546 Both the global mappings and the mappings local to the current
5547 buffer are checked for a match.
5548 If no matching mapping is found FALSE is returned.
5549 The following characters are recognized in {mode}:
5550 n Normal mode
5551 v Visual and Select mode
5552 x Visual mode
5553 s Select mode
5554 o Operator-pending mode
5555 i Insert mode
5556 l Language-Argument ("r", "f", "t", etc.)
5557 c Command-line mode
5558 When {mode} is omitted, "nvo" is used.
5559
5560 This function is useful to check if a mapping already exists
5561 to a function in a Vim script. Example: >
5562 :if !hasmapto('\ABCdoit')
5563 : map <Leader>d \ABCdoit
5564 :endif
5565< This installs the mapping to "\ABCdoit" only if there isn't
5566 already a mapping to "\ABCdoit".
5567
5568 Can also be used as a |method|: >
5569 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005570<
5571 Return type: |Number|
5572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005573
5574histadd({history}, {item}) *histadd()*
5575 Add the String {item} to the history {history} which can be
5576 one of: *hist-names*
5577 "cmd" or ":" command line history
5578 "search" or "/" search pattern history
5579 "expr" or "=" typed expression history
5580 "input" or "@" input line history
5581 "debug" or ">" debug command history
5582 empty the current or last used history
5583 The {history} string does not need to be the whole name, one
5584 character is sufficient.
5585 If {item} does already exist in the history, it will be
5586 shifted to become the newest entry.
5587 The result is a Number: TRUE if the operation was successful,
5588 otherwise FALSE is returned.
5589
5590 Example: >
5591 :call histadd("input", strftime("%Y %b %d"))
5592 :let date=input("Enter date: ")
5593< This function is not available in the |sandbox|.
5594
5595 Can also be used as a |method|, the base is passed as the
5596 second argument: >
5597 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005598<
5599 Return type: |Number|
5600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005601
5602histdel({history} [, {item}]) *histdel()*
5603 Clear {history}, i.e. delete all its entries. See |hist-names|
5604 for the possible values of {history}.
5605
5606 If the parameter {item} evaluates to a String, it is used as a
5607 regular expression. All entries matching that expression will
5608 be removed from the history (if there are any).
5609 Upper/lowercase must match, unless "\c" is used |/\c|.
5610 If {item} evaluates to a Number, it will be interpreted as
5611 an index, see |:history-indexing|. The respective entry will
5612 be removed if it exists.
5613
5614 The result is TRUE for a successful operation, otherwise FALSE
5615 is returned.
5616
5617 Examples:
5618 Clear expression register history: >
5619 :call histdel("expr")
5620<
5621 Remove all entries starting with "*" from the search history: >
5622 :call histdel("/", '^\*')
5623<
5624 The following three are equivalent: >
5625 :call histdel("search", histnr("search"))
5626 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005627 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005628<
5629 To delete the last search pattern and use the last-but-one for
5630 the "n" command and 'hlsearch': >
5631 :call histdel("search", -1)
5632 :let @/ = histget("search", -1)
5633<
5634 Can also be used as a |method|: >
5635 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005636<
5637 Return type: |Number|
5638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005639
5640histget({history} [, {index}]) *histget()*
5641 The result is a String, the entry with Number {index} from
5642 {history}. See |hist-names| for the possible values of
5643 {history}, and |:history-indexing| for {index}. If there is
5644 no such entry, an empty String is returned. When {index} is
5645 omitted, the most recent item from the history is used.
5646
5647 Examples:
5648 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005649 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005650
5651< Define an Ex command ":H {num}" that supports re-execution of
5652 the {num}th entry from the output of |:history|. >
5653 :command -nargs=1 H execute histget("cmd", 0+<args>)
5654<
5655 Can also be used as a |method|: >
5656 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005657<
5658 Return type: |String|
5659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005660
5661histnr({history}) *histnr()*
5662 The result is the Number of the current entry in {history}.
5663 See |hist-names| for the possible values of {history}.
5664 If an error occurred, -1 is returned.
5665
5666 Example: >
5667 :let inp_index = histnr("expr")
5668
5669< Can also be used as a |method|: >
5670 GetHistory()->histnr()
5671<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005672 Return type: |Number|
5673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005674hlexists({name}) *hlexists()*
5675 The result is a Number, which is TRUE if a highlight group
5676 called {name} exists. This is when the group has been
5677 defined in some way. Not necessarily when highlighting has
5678 been defined for it, it may also have been used for a syntax
5679 item.
5680 *highlight_exists()*
5681 Obsolete name: highlight_exists().
5682
5683 Can also be used as a |method|: >
5684 GetName()->hlexists()
5685<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005686 Return type: |Number|
5687
5688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005689hlget([{name} [, {resolve}]]) *hlget()*
5690 Returns a List of all the highlight group attributes. If the
5691 optional {name} is specified, then returns a List with only
5692 the attributes of the specified highlight group. Returns an
5693 empty List if the highlight group {name} is not present.
5694
5695 If the optional {resolve} argument is set to v:true and the
5696 highlight group {name} is linked to another group, then the
5697 link is resolved recursively and the attributes of the
5698 resolved highlight group are returned.
5699
5700 Each entry in the returned List is a Dictionary with the
5701 following items:
5702 cleared boolean flag, set to v:true if the highlight
5703 group attributes are cleared or not yet
5704 specified. See |highlight-clear|.
5705 cterm cterm attributes. See |highlight-cterm|.
5706 ctermbg cterm background color.
5707 See |highlight-ctermbg|.
5708 ctermfg cterm foreground color.
5709 See |highlight-ctermfg|.
5710 ctermul cterm underline color. See |highlight-ctermul|.
5711 default boolean flag, set to v:true if the highlight
5712 group link is a default link. See
5713 |highlight-default|.
5714 font highlight group font. See |highlight-font|.
5715 gui gui attributes. See |highlight-gui|.
5716 guibg gui background color. See |highlight-guibg|.
5717 guifg gui foreground color. See |highlight-guifg|.
5718 guisp gui special color. See |highlight-guisp|.
5719 id highlight group ID.
5720 linksto linked highlight group name.
5721 See |:highlight-link|.
5722 name highlight group name. See |group-name|.
5723 start start terminal keycode. See |highlight-start|.
5724 stop stop terminal keycode. See |highlight-stop|.
5725 term term attributes. See |highlight-term|.
5726
5727 The 'term', 'cterm' and 'gui' items in the above Dictionary
5728 have a dictionary value with the following optional boolean
5729 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5730 'reverse', 'inverse' and 'strikethrough'.
5731
5732 Example(s): >
5733 :echo hlget()
5734 :echo hlget('ModeMsg')
5735 :echo hlget('Number', v:true)
5736<
5737 Can also be used as a |method|: >
5738 GetName()->hlget()
5739<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005740 Return type: list<dict<any>>
5741
5742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005743hlset({list}) *hlset()*
5744 Creates or modifies the attributes of a List of highlight
5745 groups. Each item in {list} is a dictionary containing the
5746 attributes of a highlight group. See |hlget()| for the list of
5747 supported items in this dictionary.
5748
5749 In addition to the items described in |hlget()|, the following
5750 additional items are supported in the dictionary:
5751
5752 force boolean flag to force the creation of
5753 a link for an existing highlight group
5754 with attributes.
5755
5756 The highlight group is identified using the 'name' item and
5757 the 'id' item (if supplied) is ignored. If a highlight group
5758 with a specified name doesn't exist, then it is created.
5759 Otherwise the attributes of an existing highlight group are
5760 modified.
5761
5762 If an empty dictionary value is used for the 'term' or 'cterm'
5763 or 'gui' entries, then the corresponding attributes are
5764 cleared. If the 'cleared' item is set to v:true, then all the
5765 attributes of the highlight group are cleared.
5766
5767 The 'linksto' item can be used to link a highlight group to
5768 another highlight group. See |:highlight-link|.
5769
5770 Returns zero for success, -1 for failure.
5771
5772 Example(s): >
5773 " add bold attribute to the Visual highlight group
5774 :call hlset([#{name: 'Visual',
5775 \ term: #{reverse: 1 , bold: 1}}])
5776 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5777 :let l = hlget()
5778 :call hlset(l)
5779 " clear the Search highlight group
5780 :call hlset([#{name: 'Search', cleared: v:true}])
5781 " clear the 'term' attributes for a highlight group
5782 :call hlset([#{name: 'Title', term: {}}])
5783 " create the MyHlg group linking it to DiffAdd
5784 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5785 " remove the MyHlg group link
5786 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5787 " clear the attributes and a link
5788 :call hlset([#{name: 'MyHlg', cleared: v:true,
5789 \ linksto: 'NONE'}])
5790<
5791 Can also be used as a |method|: >
5792 GetAttrList()->hlset()
5793<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005794 Return type: |Number|
5795
5796hlID({name}) *hlID()*
5797 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005798 with name {name}. When the highlight group doesn't exist,
5799 zero is returned.
5800 This can be used to retrieve information about the highlight
5801 group. For example, to get the background color of the
5802 "Comment" group: >
5803 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5804< *highlightID()*
5805 Obsolete name: highlightID().
5806
5807 Can also be used as a |method|: >
5808 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005809<
5810 Return type: |Number|
5811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005812
5813hostname() *hostname()*
5814 The result is a String, which is the name of the machine on
5815 which Vim is currently running. Machine names greater than
5816 256 characters long are truncated.
5817
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005818 Return type: |String|
5819
5820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005821iconv({string}, {from}, {to}) *iconv()*
5822 The result is a String, which is the text {string} converted
5823 from encoding {from} to encoding {to}.
5824 When the conversion completely fails an empty string is
5825 returned. When some characters could not be converted they
5826 are replaced with "?".
5827 The encoding names are whatever the iconv() library function
5828 can accept, see ":!man 3 iconv".
5829 Most conversions require Vim to be compiled with the |+iconv|
5830 feature. Otherwise only UTF-8 to latin1 conversion and back
5831 can be done.
5832 This can be used to display messages with special characters,
5833 no matter what 'encoding' is set to. Write the message in
5834 UTF-8 and use: >
5835 echo iconv(utf8_str, "utf-8", &enc)
5836< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5837 from/to UCS-2 is automatically changed to use UTF-8. You
5838 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5839
5840 Can also be used as a |method|: >
5841 GetText()->iconv('latin1', 'utf-8')
5842<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005843 Return type: |String|
5844
5845
h-east624bb832024-11-09 18:37:32 +01005846id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005847 The result is a unique String associated with the {item} and
5848 not with the {item}'s contents. It is only valid while the
5849 {item} exists and is referenced. It is valid only in the
5850 instance of vim that produces the result. The whole idea is
5851 that `id({item})` does not change if the contents of {item}
5852 changes. This is useful as a `key` for creating an identity
5853 dictionary, rather than one based on equals.
5854
5855 This operation does not reference {item} and there is no
5856 function to convert the `id` to the {item}. It may be useful to
5857 have a map of `id` to {item}. The following >
5858 var referenceMap: dict<any>
5859 var id = item->id()
5860 referenceMap[id] = item
5861< prevents {item} from being garbage collected and provides a
5862 way to get the {item} from the `id`.
5863
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005864 {item} may be a List, Tuple, Dictionary, Object, Job, Channel
5865 or Blob. If the item is not a permitted type, or it is a null
Ernie Raelc8e158b2024-07-09 18:39:52 +02005866 value, then an empty String is returned.
5867
5868 Can also be used as a |method|: >
5869 GetItem()->id()
5870<
5871 Return type: |String|
5872
5873
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005874indent({lnum}) *indent()*
5875 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005876 current buffer. The indent is counted in spaces, the value
5877 of 'tabstop' is relevant. {lnum} is used just like in
5878 |getline()|.
5879 When {lnum} is invalid -1 is returned. In |Vim9| script an
5880 error is given.
5881
5882 Can also be used as a |method|: >
5883 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005884<
5885 Return type: |Number|
5886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005887
5888index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005889 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005890 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005891
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005892 If {object} is a |List| or a |Tuple| return the lowest index
5893 where the item has a value equal to {expr}. There is no
5894 automatic conversion, so the String "4" is different from the
5895 Number 4. And the number 4 is different from the Float 4.0.
5896 The value of 'ignorecase' is not used here, case matters as
5897 indicated by the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005898
5899 If {object} is |Blob| return the lowest index where the byte
5900 value is equal to {expr}.
5901
5902 If {start} is given then start looking at the item with index
5903 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005905 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5906 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005908 -1 is returned when {expr} is not found in {object}.
5909 Example: >
5910 :let idx = index(words, "the")
5911 :if index(numbers, 123) >= 0
5912
5913< Can also be used as a |method|: >
5914 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005915<
5916 Return type: |Number|
5917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005918
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005919indexof({object}, {expr} [, {opts}]) *indexof()*
5920 Returns the index of an item in {object} where {expr} is
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005921 v:true. {object} must be a |List|, a |Tuple| or a |Blob|.
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005922
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005923 If {object} is a |List| or a |Tuple|, evaluate {expr} for each
Christ van Willegen92e109f2025-03-24 20:12:37 +01005924 item in the List or Tuple until the expression is v:true
5925 and return the index of this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005926
5927 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005928 Blob until the expression is v:true and return the index of
5929 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005930
5931 {expr} must be a |string| or |Funcref|.
5932
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005933 If {expr} is a |string|: If {object} is a |List| or a |Tuple|,
5934 inside {expr} |v:key| has the index of the current List or
5935 Tuple item and |v:val| has the value of the item. If {object}
5936 is a |Blob|, inside {expr} |v:key| has the index of the
5937 current byte and |v:val| has the byte value.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005938
5939 If {expr} is a |Funcref| it must take two arguments:
5940 1. the key or the index of the current item.
5941 2. the value of the current item.
5942 The function must return |TRUE| if the item is found and the
5943 search should stop.
5944
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005945 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005946 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005947 startidx start evaluating {expr} at the item with this
5948 index; may be negative for an item relative to
5949 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005950 Returns -1 when {expr} evaluates to v:false for all the items.
5951 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005952 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5953 :echo indexof(l, "v:val.n == 20")
5954 :echo indexof(l, {i, v -> v.n == 30})
5955 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005956
5957< Can also be used as a |method|: >
5958 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005959<
5960 Return type: |Number|
5961
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005963input({prompt} [, {text} [, {completion}]]) *input()*
5964 The result is a String, which is whatever the user typed on
5965 the command-line. The {prompt} argument is either a prompt
5966 string, or a blank string (for no prompt). A '\n' can be used
5967 in the prompt to start a new line.
5968 The highlighting set with |:echohl| is used for the prompt.
5969 The input is entered just like a command-line, with the same
5970 editing commands and mappings. There is a separate history
5971 for lines typed for input().
5972 Example: >
5973 :if input("Coffee or beer? ") == "beer"
5974 : echo "Cheers!"
5975 :endif
5976<
5977 If the optional {text} argument is present and not empty, this
5978 is used for the default reply, as if the user typed this.
5979 Example: >
5980 :let color = input("Color? ", "white")
5981
5982< The optional {completion} argument specifies the type of
5983 completion supported for the input. Without it completion is
5984 not performed. The supported completion types are the same as
5985 that can be supplied to a user-defined command using the
5986 "-complete=" argument. Refer to |:command-completion| for
5987 more information. Example: >
5988 let fname = input("File: ", "", "file")
5989<
5990 NOTE: This function must not be used in a startup file, for
5991 the versions that only run in GUI mode (e.g., the Win32 GUI).
5992 Note: When input() is called from within a mapping it will
5993 consume remaining characters from that mapping, because a
5994 mapping is handled like the characters were typed.
5995 Use |inputsave()| before input() and |inputrestore()|
5996 after input() to avoid that. Another solution is to avoid
5997 that further characters follow in the mapping, e.g., by using
5998 |:execute| or |:normal|.
5999
6000 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006001 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006002 :function GetFoo()
6003 : call inputsave()
6004 : let g:Foo = input("enter search pattern: ")
6005 : call inputrestore()
6006 :endfunction
6007
6008< Can also be used as a |method|: >
6009 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006010<
6011 Return type: |String|
6012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006013
6014inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
6015 Like |input()|, but when the GUI is running and text dialogs
6016 are supported, a dialog window pops up to input the text.
6017 Example: >
6018 :let n = inputdialog("value for shiftwidth", shiftwidth())
6019 :if n != ""
6020 : let &sw = n
6021 :endif
6022< When the dialog is cancelled {cancelreturn} is returned. When
6023 omitted an empty string is returned.
6024 Hitting <Enter> works like pressing the OK button. Hitting
6025 <Esc> works like pressing the Cancel button.
6026 NOTE: Command-line completion is not supported.
6027
6028 Can also be used as a |method|: >
6029 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006030<
6031 Return type: |String|
6032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006033
6034inputlist({textlist}) *inputlist()*
6035 {textlist} must be a |List| of strings. This |List| is
6036 displayed, one string per line. The user will be prompted to
6037 enter a number, which is returned.
6038 The user can also select an item by clicking on it with the
6039 mouse, if the mouse is enabled in the command line ('mouse' is
6040 "a" or includes "c"). For the first string 0 is returned.
6041 When clicking above the first item a negative number is
6042 returned. When clicking on the prompt one more than the
6043 length of {textlist} is returned.
6044 Make sure {textlist} has less than 'lines' entries, otherwise
6045 it won't work. It's a good idea to put the entry number at
6046 the start of the string. And put a prompt in the first item.
6047 Example: >
6048 let color = inputlist(['Select color:', '1. red',
6049 \ '2. green', '3. blue'])
6050
6051< Can also be used as a |method|: >
6052 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006053<
6054 Return type: |Number|
6055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006056
6057inputrestore() *inputrestore()*
6058 Restore typeahead that was saved with a previous |inputsave()|.
6059 Should be called the same number of times inputsave() is
6060 called. Calling it more often is harmless though.
6061 Returns TRUE when there is nothing to restore, FALSE otherwise.
6062
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006063 Return type: |Number|
6064
6065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006066inputsave() *inputsave()*
6067 Preserve typeahead (also from mappings) and clear it, so that
6068 a following prompt gets input from the user. Should be
6069 followed by a matching inputrestore() after the prompt. Can
6070 be used several times, in which case there must be just as
6071 many inputrestore() calls.
6072 Returns TRUE when out of memory, FALSE otherwise.
6073
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006074 Return type: |Number|
6075
6076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006077inputsecret({prompt} [, {text}]) *inputsecret()*
6078 This function acts much like the |input()| function with but
6079 two exceptions:
6080 a) the user's response will be displayed as a sequence of
6081 asterisks ("*") thereby keeping the entry secret, and
6082 b) the user's response will not be recorded on the input
6083 |history| stack.
6084 The result is a String, which is whatever the user actually
6085 typed on the command-line in response to the issued prompt.
6086 NOTE: Command-line completion is not supported.
6087
6088 Can also be used as a |method|: >
6089 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006090<
6091 Return type: |String|
6092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006093
6094insert({object}, {item} [, {idx}]) *insert()*
6095 When {object} is a |List| or a |Blob| insert {item} at the start
6096 of it.
6097
6098 If {idx} is specified insert {item} before the item with index
6099 {idx}. If {idx} is zero it goes before the first item, just
6100 like omitting {idx}. A negative {idx} is also possible, see
6101 |list-index|. -1 inserts just before the last item.
6102
6103 Returns the resulting |List| or |Blob|. Examples: >
6104 :let mylist = insert([2, 3, 5], 1)
6105 :call insert(mylist, 4, -1)
6106 :call insert(mylist, 6, len(mylist))
6107< The last example can be done simpler with |add()|.
6108 Note that when {item} is a |List| it is inserted as a single
6109 item. Use |extend()| to concatenate |Lists|.
6110
6111 Can also be used as a |method|: >
6112 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006113<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006114 Return type: |Number|
6115
6116
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006117 *instanceof()* *E614* *E616* *E693*
6118instanceof({object}, {class})
6119 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006120 argument is a direct or indirect instance of a |Class|,
6121 |Interface|, or class |:type| alias specified by {class}.
6122 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006123 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006124 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006125 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006126
6127< Can also be used as a |method|: >
6128 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006129<
6130 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006132interrupt() *interrupt()*
6133 Interrupt script execution. It works more or less like the
6134 user typing CTRL-C, most commands won't execute and control
6135 returns to the user. This is useful to abort execution
6136 from lower down, e.g. in an autocommand. Example: >
6137 :function s:check_typoname(file)
6138 : if fnamemodify(a:file, ':t') == '['
6139 : echomsg 'Maybe typo'
6140 : call interrupt()
6141 : endif
6142 :endfunction
6143 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006144<
6145 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006146
6147invert({expr}) *invert()*
6148 Bitwise invert. The argument is converted to a number. A
6149 List, Dict or Float argument causes an error. Example: >
6150 :let bits = invert(bits)
6151< Can also be used as a |method|: >
6152 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006153<
6154 Return type: |Number|
6155
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006156
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006157isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006158 The result is a Number, which is |TRUE| when {path} is an
6159 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006160 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006161 On MS-Windows, it is considered absolute when it starts with an
6162 optional drive prefix and is followed by a '\' or '/'. UNC paths
6163 are always absolute.
6164 Example: >
6165 echo isabsolutepath('/usr/share/') " 1
6166 echo isabsolutepath('./foobar') " 0
6167 echo isabsolutepath('C:\Windows') " 1
6168 echo isabsolutepath('foobar') " 0
6169 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006170<
LemonBoydca1d402022-04-28 15:26:33 +01006171 Can also be used as a |method|: >
6172 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006173<
6174 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006175
6176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006177isdirectory({directory}) *isdirectory()*
6178 The result is a Number, which is |TRUE| when a directory
6179 with the name {directory} exists. If {directory} doesn't
6180 exist, or isn't a directory, the result is |FALSE|. {directory}
6181 is any expression, which is used as a String.
6182
6183 Can also be used as a |method|: >
6184 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006185<
6186 Return type: |Number|
6187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006188
6189isinf({expr}) *isinf()*
6190 Return 1 if {expr} is a positive infinity, or -1 a negative
6191 infinity, otherwise 0. >
6192 :echo isinf(1.0 / 0.0)
6193< 1 >
6194 :echo isinf(-1.0 / 0.0)
6195< -1
6196
6197 Can also be used as a |method|: >
6198 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006199<
6200 Return type: |Number|
6201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006202
6203islocked({expr}) *islocked()* *E786*
6204 The result is a Number, which is |TRUE| when {expr} is the
6205 name of a locked variable.
6206 The string argument {expr} must be the name of a variable,
6207 |List| item or |Dictionary| entry, not the variable itself!
6208 Example: >
6209 :let alist = [0, ['a', 'b'], 2, 3]
6210 :lockvar 1 alist
6211 :echo islocked('alist') " 1
6212 :echo islocked('alist[1]') " 0
6213
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006214< When {expr} is a variable that does not exist -1 is returned.
6215 If {expr} uses a range, list or dict index that is out of
6216 range or does not exist you get an error message. Use
6217 |exists()| to check for existence.
6218 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006219
6220 Can also be used as a |method|: >
6221 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006222<
6223 Return type: |Number|
6224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006225
6226isnan({expr}) *isnan()*
6227 Return |TRUE| if {expr} is a float with value NaN. >
6228 echo isnan(0.0 / 0.0)
6229< 1
6230
6231 Can also be used as a |method|: >
6232 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006233<
6234 Return type: |Number|
6235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006236
6237items({dict}) *items()*
6238 Return a |List| with all the key-value pairs of {dict}. Each
6239 |List| item is a list with two items: the key of a {dict}
6240 entry and the value of this entry. The |List| is in arbitrary
6241 order. Also see |keys()| and |values()|.
6242 Example: >
6243 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006244 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006245 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006246<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006247 A |List|, a |Tuple| or a |String| argument is also supported.
6248 In these cases, items() returns a List with the index and the
6249 value at the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006250
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006251 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006252 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006253<
6254 Return type: list<list<any>> or list<any>
6255
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006256
6257job_ functions are documented here: |job-functions-details|
6258
6259
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006260join({expr} [, {sep}]) *join()*
6261 Join the items in {expr} together into one String. {expr} can
6262 be a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006263 When {sep} is specified it is put in between the items. If
6264 {sep} is omitted a single space is used.
6265 Note that {sep} is not added at the end. You might want to
6266 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006267 let lines = join(mylist, "\n") .. "\n"
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006268< String items are used as-is. |Lists|, |Tuples| and
6269 |Dictionaries| are converted into a string like with
6270 |string()|. The opposite function is |split()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006271
6272 Can also be used as a |method|: >
6273 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006274<
6275 Return type: |String|
6276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006277
6278js_decode({string}) *js_decode()*
6279 This is similar to |json_decode()| with these differences:
6280 - Object key names do not have to be in quotes.
6281 - Strings can be in single quotes.
6282 - Empty items in an array (between two commas) are allowed and
6283 result in v:none items.
6284
6285 Can also be used as a |method|: >
6286 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006287<
6288 Return type: any, depending on {varname}
6289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006290
6291js_encode({expr}) *js_encode()*
6292 This is similar to |json_encode()| with these differences:
6293 - Object key names are not in quotes.
6294 - v:none items in an array result in an empty item between
6295 commas.
6296 For example, the Vim object:
6297 [1,v:none,{"one":1},v:none] ~
6298 Will be encoded as:
6299 [1,,{one:1},,] ~
6300 While json_encode() would produce:
6301 [1,null,{"one":1},null] ~
6302 This encoding is valid for JavaScript. It is more efficient
6303 than JSON, especially when using an array with optional items.
6304
6305 Can also be used as a |method|: >
6306 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006307<
6308 Return type: |String|
6309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006310
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006311json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006312 This parses a JSON formatted string and returns the equivalent
6313 in Vim values. See |json_encode()| for the relation between
6314 JSON and Vim values.
6315 The decoding is permissive:
6316 - A trailing comma in an array and object is ignored, e.g.
6317 "[1, 2, ]" is the same as "[1, 2]".
6318 - Integer keys are accepted in objects, e.g. {1:2} is the
6319 same as {"1":2}.
6320 - More floating point numbers are recognized, e.g. "1." for
6321 "1.0", or "001.2" for "1.2". Special floating point values
6322 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6323 are accepted.
6324 - Leading zeroes in integer numbers are ignored, e.g. "012"
6325 for "12" or "-012" for "-12".
6326 - Capitalization is ignored in literal names null, true or
6327 false, e.g. "NULL" for "null", "True" for "true".
6328 - Control characters U+0000 through U+001F which are not
6329 escaped in strings are accepted, e.g. " " (tab
6330 character in string) for "\t".
6331 - An empty JSON expression or made of only spaces is accepted
6332 and results in v:none.
6333 - Backslash in an invalid 2-character sequence escape is
6334 ignored, e.g. "\a" is decoded as "a".
6335 - A correct surrogate pair in JSON strings should normally be
6336 a 12 character sequence such as "\uD834\uDD1E", but
6337 json_decode() silently accepts truncated surrogate pairs
6338 such as "\uD834" or "\uD834\u"
6339 *E938*
6340 A duplicate key in an object, valid in rfc7159, is not
6341 accepted by json_decode() as the result must be a valid Vim
6342 type, e.g. this fails: {"a":"b", "a":"c"}
6343
6344 Can also be used as a |method|: >
6345 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006346<
6347 Return type: any, depending on {varname}
6348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006349
6350json_encode({expr}) *json_encode()*
6351 Encode {expr} as JSON and return this as a string.
6352 The encoding is specified in:
6353 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006354 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006355 |Number| decimal number
6356 |Float| floating point number
6357 Float nan "NaN"
6358 Float inf "Infinity"
6359 Float -inf "-Infinity"
6360 |String| in double quotes (possibly null)
6361 |Funcref| not possible, error
6362 |List| as an array (possibly null); when
6363 used recursively: []
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006364 |Tuple| as an array (possibly null); when
6365 used recursively: []
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006366 |Dict| as an object (possibly null); when
6367 used recursively: {}
6368 |Blob| as an array of the individual bytes
6369 v:false "false"
6370 v:true "true"
6371 v:none "null"
6372 v:null "null"
6373 Note that NaN and Infinity are passed on as values. This is
6374 missing in the JSON standard, but several implementations do
6375 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006376 If a string contains an illegal character then the replacement
6377 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006378
6379 Can also be used as a |method|: >
6380 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006381<
6382 Return type: |String|
6383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006384
6385keys({dict}) *keys()*
6386 Return a |List| with all the keys of {dict}. The |List| is in
6387 arbitrary order. Also see |items()| and |values()|.
6388
6389 Can also be used as a |method|: >
6390 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006391<
6392 Return type: list<string>
6393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006394
zeertzjqcdc83932022-09-12 13:38:41 +01006395keytrans({string}) *keytrans()*
6396 Turn the internal byte representation of keys into a form that
6397 can be used for |:map|. E.g. >
6398 :let xx = "\<C-Home>"
6399 :echo keytrans(xx)
6400< <C-Home>
6401
6402 Can also be used as a |method|: >
6403 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006404<
6405 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006406
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006407
6408len({expr}) *len()* *E701*
6409 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006410 When {expr} is a String or a Number the length in bytes is
6411 used, as with |strlen()|.
6412 When {expr} is a |List| the number of items in the |List| is
6413 returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006414 When {expr} is a |Tuple| the number of items in the |Tuple| is
6415 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006416 When {expr} is a |Blob| the number of bytes is returned.
6417 When {expr} is a |Dictionary| the number of entries in the
6418 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006419 When {expr} is an |Object|, invokes the len() method in the
6420 object (if present) to get the length (|object-len()|).
6421 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006422
6423 Can also be used as a |method|: >
6424 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006425<
6426 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006428
6429 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006430libcall({libname}, {funcname}, {argument})
6431 Call function {funcname} in the run-time library {libname}
6432 with single argument {argument}.
6433 This is useful to call functions in a library that you
6434 especially made to be used with Vim. Since only one argument
6435 is possible, calling standard library functions is rather
6436 limited.
6437 The result is the String returned by the function. If the
6438 function returns NULL, this will appear as an empty string ""
6439 to Vim.
6440 If the function returns a number, use libcallnr()!
6441 If {argument} is a number, it is passed to the function as an
6442 int; if {argument} is a string, it is passed as a
6443 null-terminated string.
6444 This function will fail in |restricted-mode|.
6445
6446 libcall() allows you to write your own 'plug-in' extensions to
6447 Vim without having to recompile the program. It is NOT a
6448 means to call system functions! If you try to do so Vim will
6449 very probably crash.
6450
6451 For Win32, the functions you write must be placed in a DLL
6452 and use the normal C calling convention (NOT Pascal which is
6453 used in Windows System DLLs). The function must take exactly
6454 one parameter, either a character pointer or a long integer,
6455 and must return a character pointer or NULL. The character
6456 pointer returned must point to memory that will remain valid
6457 after the function has returned (e.g. in static data in the
6458 DLL). If it points to allocated memory, that memory will
6459 leak away. Using a static buffer in the function should work,
6460 it's then freed when the DLL is unloaded.
6461
6462 WARNING: If the function returns a non-valid pointer, Vim may
6463 crash! This also happens if the function returns a number,
6464 because Vim thinks it's a pointer.
6465 For Win32 systems, {libname} should be the filename of the DLL
6466 without the ".DLL" suffix. A full path is only required if
6467 the DLL is not in the usual places.
6468 For Unix: When compiling your own plugins, remember that the
6469 object code must be compiled as position-independent ('PIC').
6470 {only in Win32 and some Unix versions, when the |+libcall|
6471 feature is present}
6472 Examples: >
6473 :echo libcall("libc.so", "getenv", "HOME")
6474
6475< Can also be used as a |method|, the base is passed as the
6476 third argument: >
6477 GetValue()->libcall("libc.so", "getenv")
6478<
6479 *libcallnr()*
6480libcallnr({libname}, {funcname}, {argument})
6481 Just like |libcall()|, but used for a function that returns an
6482 int instead of a string.
6483 {only in Win32 on some Unix versions, when the |+libcall|
6484 feature is present}
6485 Examples: >
6486 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6487 :call libcallnr("libc.so", "printf", "Hello World!\n")
6488 :call libcallnr("libc.so", "sleep", 10)
6489<
6490 Can also be used as a |method|, the base is passed as the
6491 third argument: >
6492 GetValue()->libcallnr("libc.so", "printf")
6493<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006494 Return type: |String|
6495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006496
6497line({expr} [, {winid}]) *line()*
6498 The result is a Number, which is the line number of the file
6499 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006500 See |getpos()| for accepted positions.
6501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006502 To get the column number use |col()|. To get both use
6503 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006505 With the optional {winid} argument the values are obtained for
6506 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006507
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006508 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006510 Examples: >
6511 line(".") line number of the cursor
6512 line(".", winid) idem, in window "winid"
6513 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006514 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006515<
6516 To jump to the last known position when opening a file see
6517 |last-position-jump|.
6518
6519 Can also be used as a |method|: >
6520 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006521<
6522 Return type: |Number|
6523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006524
6525line2byte({lnum}) *line2byte()*
6526 Return the byte count from the start of the buffer for line
6527 {lnum}. This includes the end-of-line character, depending on
6528 the 'fileformat' option for the current buffer. The first
6529 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6530 This can also be used to get the byte count for the line just
6531 below the last line: >
6532 line2byte(line("$") + 1)
6533< This is the buffer size plus one. If 'fileencoding' is empty
6534 it is the file size plus one. {lnum} is used like with
6535 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6536 feature has been disabled at compile time, -1 is returned.
6537 Also see |byte2line()|, |go| and |:goto|.
6538
6539 Can also be used as a |method|: >
6540 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006541<
6542 Return type: |Number|
6543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006544
6545lispindent({lnum}) *lispindent()*
6546 Get the amount of indent for line {lnum} according the lisp
6547 indenting rules, as with 'lisp'.
6548 The indent is counted in spaces, the value of 'tabstop' is
6549 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006550 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006551 error is given.
6552
6553 Can also be used as a |method|: >
6554 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006555<
6556 Return type: |Number|
6557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006558
6559list2blob({list}) *list2blob()*
6560 Return a Blob concatenating all the number values in {list}.
6561 Examples: >
6562 list2blob([1, 2, 3, 4]) returns 0z01020304
6563 list2blob([]) returns 0z
6564< Returns an empty Blob on error. If one of the numbers is
6565 negative or more than 255 error *E1239* is given.
6566
6567 |blob2list()| does the opposite.
6568
6569 Can also be used as a |method|: >
6570 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006571<
6572 Return type: |Blob|
6573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006574
6575list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006576 Convert each number in {list} to a character string and
6577 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006578 list2str([32]) returns " "
6579 list2str([65, 66, 67]) returns "ABC"
6580< The same can be done (slowly) with: >
6581 join(map(list, {nr, val -> nr2char(val)}), '')
6582< |str2list()| does the opposite.
6583
6584 When {utf8} is omitted or zero, the current 'encoding' is used.
6585 When {utf8} is TRUE, always return UTF-8 characters.
6586 With UTF-8 composing characters work as expected: >
6587 list2str([97, 769]) returns "á"
6588<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006589 Returns an empty string on error.
6590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006591 Can also be used as a |method|: >
6592 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006593<
6594 Return type: |String|
6595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006596
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006597list2tuple({list}) *list2tuple()*
6598 Create a Tuple from a shallow copy of the list items.
6599 Examples: >
6600 list2tuple([1, 2, 3]) returns (1, 2, 3)
6601< |tuple2list()| does the opposite.
6602
6603 This function doesn't recursively convert all the List items
6604 in {list} to a Tuple. Note that the items are identical
6605 between the list and the tuple, changing an item changes the
6606 contents of both the tuple and the list.
6607
6608 Returns an empty tuple on error.
6609
6610 Can also be used as a |method|: >
6611 GetList()->list2tuple()
6612<
6613 Return type: tuple<{type}> (depending on the given |List|)
6614
6615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006616listener_add({callback} [, {buf}]) *listener_add()*
6617 Add a callback function that will be invoked when changes have
6618 been made to buffer {buf}.
6619 {buf} refers to a buffer name or number. For the accepted
6620 values, see |bufname()|. When {buf} is omitted the current
6621 buffer is used.
6622 Returns a unique ID that can be passed to |listener_remove()|.
6623
6624 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006625 bufnr the buffer that was changed
6626 start first changed line number
6627 end first line number below the change
6628 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006629 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006630 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006631
6632 Example: >
6633 func Listener(bufnr, start, end, added, changes)
6634 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6635 endfunc
6636 call listener_add('Listener', bufnr)
6637
Bram Moolenaar944697a2022-02-20 19:48:20 +00006638< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006639 dictionary with these entries:
6640 lnum the first line number of the change
6641 end the first line below the change
6642 added number of lines added; negative if lines were
6643 deleted
6644 col first column in "lnum" that was affected by
6645 the change; one if unknown or the whole line
6646 was affected; this is a byte index, first
6647 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006648 When lines are inserted (not when a line is split, e.g. by
6649 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006650 lnum line above which the new line is added
6651 end equal to "lnum"
6652 added number of lines inserted
6653 col 1
6654 When lines are deleted the values are:
6655 lnum the first deleted line
6656 end the line below the first deleted line, before
6657 the deletion was done
6658 added negative, number of lines deleted
6659 col 1
6660 When lines are changed:
6661 lnum the first changed line
6662 end the line below the last changed line
6663 added 0
6664 col first column with a change or 1
6665
6666 The entries are in the order the changes were made, thus the
6667 most recent change is at the end. The line numbers are valid
6668 when the callback is invoked, but later changes may make them
6669 invalid, thus keeping a copy for later might not work.
6670
6671 The {callback} is invoked just before the screen is updated,
6672 when |listener_flush()| is called or when a change is being
6673 made that changes the line count in a way it causes a line
6674 number in the list of changes to become invalid.
6675
6676 The {callback} is invoked with the text locked, see
6677 |textlock|. If you do need to make changes to the buffer, use
6678 a timer to do this later |timer_start()|.
6679
6680 The {callback} is not invoked when the buffer is first loaded.
6681 Use the |BufReadPost| autocmd event to handle the initial text
6682 of a buffer.
6683 The {callback} is also not invoked when the buffer is
6684 unloaded, use the |BufUnload| autocmd event for that.
6685
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006686 Returns zero if {callback} or {buf} is invalid.
6687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006688 Can also be used as a |method|, the base is passed as the
6689 second argument: >
6690 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006691<
6692 Return type: |Number|
6693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006694
6695listener_flush([{buf}]) *listener_flush()*
6696 Invoke listener callbacks for buffer {buf}. If there are no
6697 pending changes then no callbacks are invoked.
6698
6699 {buf} refers to a buffer name or number. For the accepted
6700 values, see |bufname()|. When {buf} is omitted the current
6701 buffer is used.
6702
6703 Can also be used as a |method|: >
6704 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006705<
6706 Return type: |Number|
6707
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006708
6709listener_remove({id}) *listener_remove()*
6710 Remove a listener previously added with listener_add().
6711 Returns FALSE when {id} could not be found, TRUE when {id} was
6712 removed.
6713
6714 Can also be used as a |method|: >
6715 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006716<
6717 Return type: |Number|
6718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006719
6720localtime() *localtime()*
6721 Return the current time, measured as seconds since 1st Jan
6722 1970. See also |strftime()|, |strptime()| and |getftime()|.
6723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006724 Return type: |Number|
6725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006726
6727log({expr}) *log()*
6728 Return the natural logarithm (base e) of {expr} as a |Float|.
6729 {expr} must evaluate to a |Float| or a |Number| in the range
6730 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006731 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006732 Examples: >
6733 :echo log(10)
6734< 2.302585 >
6735 :echo log(exp(5))
6736< 5.0
6737
6738 Can also be used as a |method|: >
6739 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006740<
6741 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006742
6743
6744log10({expr}) *log10()*
6745 Return the logarithm of Float {expr} to base 10 as a |Float|.
6746 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006747 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006748 Examples: >
6749 :echo log10(1000)
6750< 3.0 >
6751 :echo log10(0.01)
6752< -2.0
6753
6754 Can also be used as a |method|: >
6755 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006756<
6757 Return type: |Float|
6758
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006759
6760luaeval({expr} [, {expr}]) *luaeval()*
6761 Evaluate Lua expression {expr} and return its result converted
6762 to Vim data structures. Second {expr} may hold additional
6763 argument accessible as _A inside first {expr}.
6764 Strings are returned as they are.
6765 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006766 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006767 Dictionaries and lists obtained by vim.eval() are returned
6768 as-is.
6769 Other objects are returned as zero without any errors.
6770 See |lua-luaeval| for more details.
6771 Note that in a `:def` function local variables are not visible
6772 to {expr}.
6773
6774 Can also be used as a |method|: >
6775 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006776<
6777 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006778
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006779 {only available when compiled with the |+lua| feature}
6780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006781
6782map({expr1}, {expr2}) *map()*
6783 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006784 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006785 item in {expr1} with the result of evaluating {expr2}.
6786 For a |Blob| each byte is replaced.
6787 For a |String|, each character, including composing
6788 characters, is replaced.
6789 If the item type changes you may want to use |mapnew()| to
6790 create a new List or Dictionary. This is required when using
6791 Vim9 script.
6792
6793 {expr2} must be a |String| or |Funcref|.
6794
6795 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6796 of the current item. For a |Dictionary| |v:key| has the key
6797 of the current item and for a |List| |v:key| has the index of
6798 the current item. For a |Blob| |v:key| has the index of the
6799 current byte. For a |String| |v:key| has the index of the
6800 current character.
6801 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006802 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006803< This puts "> " before and " <" after each item in "mylist".
6804
6805 Note that {expr2} is the result of an expression and is then
6806 used as an expression again. Often it is good to use a
6807 |literal-string| to avoid having to double backslashes. You
6808 still have to double ' quotes
6809
6810 If {expr2} is a |Funcref| it is called with two arguments:
6811 1. The key or the index of the current item.
6812 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006813 With a legacy script lambda you don't get an error if it only
6814 accepts one argument, but with a Vim9 lambda you get "E1106:
6815 One argument too many", the number of arguments must match.
6816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006817 The function must return the new value of the item. Example
6818 that changes each value by "key-value": >
6819 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006820 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006821 endfunc
6822 call map(myDict, function('KeyValue'))
6823< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006824 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006825< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006826 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006827< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006828 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006829<
6830 The operation is done in-place for a |List| and |Dictionary|.
6831 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006832 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006833
6834< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6835 or a new |Blob| or |String|.
6836 When an error is encountered while evaluating {expr2} no
6837 further items in {expr1} are processed.
6838 When {expr2} is a Funcref errors inside a function are ignored,
6839 unless it was defined with the "abort" flag.
6840
6841 Can also be used as a |method|: >
6842 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006843<
6844 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6845 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006846
6847
6848maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6849 When {dict} is omitted or zero: Return the rhs of mapping
6850 {name} in mode {mode}. The returned String has special
6851 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006852 listing. When {dict} is TRUE a dictionary is returned, see
6853 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006854
6855 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006856 returned if {dict} is FALSE, otherwise returns an empty Dict.
6857 When the mapping for {name} is empty, then "<Nop>" is
6858 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006859
6860 The {name} can have special key names, like in the ":map"
6861 command.
6862
6863 {mode} can be one of these strings:
6864 "n" Normal
6865 "v" Visual (including Select)
6866 "o" Operator-pending
6867 "i" Insert
6868 "c" Cmd-line
6869 "s" Select
6870 "x" Visual
6871 "l" langmap |language-mapping|
6872 "t" Terminal-Job
6873 "" Normal, Visual and Operator-pending
6874 When {mode} is omitted, the modes for "" are used.
6875
6876 When {abbr} is there and it is |TRUE| use abbreviations
6877 instead of mappings.
6878
6879 When {dict} is there and it is |TRUE| return a dictionary
6880 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006881 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006882 "lhs" The {lhs} of the mapping as it would be typed
6883 "lhsraw" The {lhs} of the mapping as raw bytes
6884 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6885 form, only present when it differs from "lhsraw"
6886 "rhs" The {rhs} of the mapping as typed.
6887 "silent" 1 for a |:map-silent| mapping, else 0.
6888 "noremap" 1 if the {rhs} of the mapping is not remappable.
6889 "script" 1 if mapping was defined with <script>.
6890 "expr" 1 for an expression mapping (|:map-<expr>|).
6891 "buffer" 1 for a buffer local mapping (|:map-local|).
6892 "mode" Modes for which the mapping is defined. In
6893 addition to the modes mentioned above, these
6894 characters will be used:
6895 " " Normal, Visual and Operator-pending
6896 "!" Insert and Commandline mode
6897 (|mapmode-ic|)
6898 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006899 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006900 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006901 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006902 "lnum" The line number in "sid", zero if unknown.
6903 "nowait" Do not wait for other, longer mappings.
6904 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006905 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006906 "mode_bits" Vim's internal binary representation of "mode".
6907 |mapset()| ignores this; only "mode" is used.
6908 See |maplist()| for usage examples. The values
6909 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006910
6911 The dictionary can be used to restore a mapping with
6912 |mapset()|.
6913
6914 The mappings local to the current buffer are checked first,
6915 then the global mappings.
6916 This function can be used to map a key even when it's already
6917 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006918 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006919
6920< Can also be used as a |method|: >
6921 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006922<
6923 Return type: |String| or dict<any> depending on {dict}
6924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006925
6926mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6927 Check if there is a mapping that matches with {name} in mode
6928 {mode}. See |maparg()| for {mode} and special names in
6929 {name}.
6930 When {abbr} is there and it is |TRUE| use abbreviations
6931 instead of mappings.
6932 A match happens with a mapping that starts with {name} and
6933 with a mapping which is equal to the start of {name}.
6934
6935 matches mapping "a" "ab" "abc" ~
6936 mapcheck("a") yes yes yes
6937 mapcheck("abc") yes yes yes
6938 mapcheck("ax") yes no no
6939 mapcheck("b") no no no
6940
6941 The difference with maparg() is that mapcheck() finds a
6942 mapping that matches with {name}, while maparg() only finds a
6943 mapping for {name} exactly.
6944 When there is no mapping that starts with {name}, an empty
6945 String is returned. If there is one, the RHS of that mapping
6946 is returned. If there are several mappings that start with
6947 {name}, the RHS of one of them is returned. This will be
6948 "<Nop>" if the RHS is empty.
6949 The mappings local to the current buffer are checked first,
6950 then the global mappings.
6951 This function can be used to check if a mapping can be added
6952 without being ambiguous. Example: >
6953 :if mapcheck("_vv") == ""
6954 : map _vv :set guifont=7x13<CR>
6955 :endif
6956< This avoids adding the "_vv" mapping when there already is a
6957 mapping for "_v" or for "_vvv".
6958
6959 Can also be used as a |method|: >
6960 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006961<
6962 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006963
6964
Ernie Rael09661202022-04-25 14:40:44 +01006965maplist([{abbr}]) *maplist()*
6966 Returns a |List| of all mappings. Each List item is a |Dict|,
6967 the same as what is returned by |maparg()|, see
6968 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6969 abbreviations instead of mappings.
6970
6971 Example to show all mappings with 'MultiMatch' in rhs: >
6972 vim9script
6973 echo maplist()->filter(
6974 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006975< It can be tricky to find mappings for particular |:map-modes|.
6976 |mapping-dict|'s "mode_bits" can simplify this. For example,
6977 the mode_bits for Normal, Insert or Command-line modes are
6978 0x19. To find all the mappings available in those modes you
6979 can do: >
6980 vim9script
6981 var saved_maps = []
6982 for m in maplist()
6983 if and(m.mode_bits, 0x19) != 0
6984 saved_maps->add(m)
6985 endif
6986 endfor
6987 echo saved_maps->mapnew((_, m) => m.lhs)
6988< The values of the mode_bits are defined in Vim's src/vim.h
6989 file and they can be discovered at runtime using
6990 |:map-commands| and "maplist()". Example: >
6991 vim9script
6992 omap xyzzy <Nop>
6993 var op_bit = maplist()->filter(
6994 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6995 ounmap xyzzy
6996 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006997<
6998 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006999
7000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007001mapnew({expr1}, {expr2}) *mapnew()*
7002 Like |map()| but instead of replacing items in {expr1} a new
7003 List or Dictionary is created and returned. {expr1} remains
7004 unchanged. Items can still be changed by {expr2}, if you
7005 don't want that use |deepcopy()| first.
7006
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007007 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
7008 depending on {expr1}
7009
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007010
7011mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01007012mapset({dict})
7013 Restore a mapping from a dictionary, possibly returned by
7014 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
7015 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01007016 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01007017 feature allows copying mappings from one buffer to another.
7018 The dict.mode value may restore a single mapping that covers
7019 more than one mode, like with mode values of '!', ' ', 'nox',
7020 or 'v'. *E1276*
7021
7022 In the first form, {mode} and {abbr} should be the same as
7023 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007024 {mode} is used to define the mode in which the mapping is set,
7025 not the "mode" entry in {dict}.
7026 Example for saving and restoring a mapping: >
7027 let save_map = maparg('K', 'n', 0, 1)
7028 nnoremap K somethingelse
7029 ...
7030 call mapset('n', 0, save_map)
7031< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01007032 e.g. with `:map!`, you need to save/restore the mapping for
7033 all of them, when they might differ.
7034
7035 In the second form, with {dict} as the only argument, mode
7036 and abbr are taken from the dict.
7037 Example: >
7038 vim9script
7039 var save_maps = maplist()->filter(
7040 (_, m) => m.lhs == 'K')
7041 nnoremap K somethingelse
7042 cnoremap K somethingelse2
7043 # ...
7044 unmap K
7045 for d in save_maps
7046 mapset(d)
7047 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007048<
7049 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007050
7051
7052match({expr}, {pat} [, {start} [, {count}]]) *match()*
7053 When {expr} is a |List| then this returns the index of the
7054 first item where {pat} matches. Each item is used as a
7055 String, |Lists| and |Dictionaries| are used as echoed.
7056
7057 Otherwise, {expr} is used as a String. The result is a
7058 Number, which gives the index (byte offset) in {expr} where
7059 {pat} matches.
7060
7061 A match at the first character or |List| item returns zero.
7062 If there is no match -1 is returned.
7063
7064 For getting submatches see |matchlist()|.
7065 Example: >
7066 :echo match("testing", "ing") " results in 4
7067 :echo match([1, 'x'], '\a') " results in 1
7068< See |string-match| for how {pat} is used.
7069 *strpbrk()*
7070 Vim doesn't have a strpbrk() function. But you can do: >
7071 :let sepidx = match(line, '[.,;: \t]')
7072< *strcasestr()*
7073 Vim doesn't have a strcasestr() function. But you can add
7074 "\c" to the pattern to ignore case: >
7075 :let idx = match(haystack, '\cneedle')
7076<
7077 If {start} is given, the search starts from byte index
7078 {start} in a String or item {start} in a |List|.
7079 The result, however, is still the index counted from the
7080 first character/item. Example: >
7081 :echo match("testing", "ing", 2)
7082< result is again "4". >
7083 :echo match("testing", "ing", 4)
7084< result is again "4". >
7085 :echo match("testing", "t", 2)
7086< result is "3".
7087 For a String, if {start} > 0 then it is like the string starts
7088 {start} bytes later, thus "^" will match at {start}. Except
7089 when {count} is given, then it's like matches before the
7090 {start} byte are ignored (this is a bit complicated to keep it
7091 backwards compatible).
7092 For a String, if {start} < 0, it will be set to 0. For a list
7093 the index is counted from the end.
7094 If {start} is out of range ({start} > strlen({expr}) for a
7095 String or {start} > len({expr}) for a |List|) -1 is returned.
7096
7097 When {count} is given use the {count}'th match. When a match
7098 is found in a String the search for the next one starts one
7099 character further. Thus this example results in 1: >
7100 echo match("testing", "..", 0, 2)
7101< In a |List| the search continues in the next item.
7102 Note that when {count} is added the way {start} works changes,
7103 see above.
7104
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007105 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007106 See |pattern| for the patterns that are accepted.
7107 The 'ignorecase' option is used to set the ignore-caseness of
7108 the pattern. 'smartcase' is NOT used. The matching is always
7109 done like 'magic' is set and 'cpoptions' is empty.
7110 Note that a match at the start is preferred, thus when the
7111 pattern is using "*" (any number of matches) it tends to find
7112 zero matches at the start instead of a number of matches
7113 further down in the text.
7114
7115 Can also be used as a |method|: >
7116 GetText()->match('word')
7117 GetList()->match('word')
7118<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007119 Return type: |Number|
7120
7121
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007122 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007123matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7124 Defines a pattern to be highlighted in the current window (a
7125 "match"). It will be highlighted with {group}. Returns an
7126 identification number (ID), which can be used to delete the
7127 match using |matchdelete()|. The ID is bound to the window.
7128 Matching is case sensitive and magic, unless case sensitivity
7129 or magicness are explicitly overridden in {pattern}. The
7130 'magic', 'smartcase' and 'ignorecase' options are not used.
7131 The "Conceal" value is special, it causes the match to be
7132 concealed.
7133
7134 The optional {priority} argument assigns a priority to the
7135 match. A match with a high priority will have its
7136 highlighting overrule that of a match with a lower priority.
7137 A priority is specified as an integer (negative numbers are no
7138 exception). If the {priority} argument is not specified, the
7139 default priority is 10. The priority of 'hlsearch' is zero,
7140 hence all matches with a priority greater than zero will
7141 overrule it. Syntax highlighting (see 'syntax') is a separate
7142 mechanism, and regardless of the chosen priority a match will
7143 always overrule syntax highlighting.
7144
7145 The optional {id} argument allows the request for a specific
7146 match ID. If a specified ID is already taken, an error
7147 message will appear and the match will not be added. An ID
7148 is specified as a positive integer (zero excluded). IDs 1, 2
7149 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007150 respectively. 3 is reserved for use by the |matchparen|
7151 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007152 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007153 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007154
7155 The optional {dict} argument allows for further custom
7156 values. Currently this is used to specify a match specific
7157 conceal character that will be shown for |hl-Conceal|
7158 highlighted matches. The dict can have the following members:
7159
7160 conceal Special character to show instead of the
7161 match (only for |hl-Conceal| highlighted
7162 matches, see |:syn-cchar|)
7163 window Instead of the current window use the
7164 window with this number or window ID.
7165
7166 The number of matches is not limited, as it is the case with
7167 the |:match| commands.
7168
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007169 Returns -1 on error.
7170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007171 Example: >
7172 :highlight MyGroup ctermbg=green guibg=green
7173 :let m = matchadd("MyGroup", "TODO")
7174< Deletion of the pattern: >
7175 :call matchdelete(m)
7176
7177< A list of matches defined by |matchadd()| and |:match| are
7178 available from |getmatches()|. All matches can be deleted in
7179 one operation by |clearmatches()|.
7180
7181 Can also be used as a |method|: >
7182 GetGroup()->matchadd('TODO')
7183<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007184 Return type: |Number|
7185
7186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007187 *matchaddpos()*
7188matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7189 Same as |matchadd()|, but requires a list of positions {pos}
7190 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007191 because it does not handle regular expressions and it sets
7192 buffer line boundaries to redraw screen. It is supposed to be
7193 used when fast match additions and deletions are required, for
7194 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007195
7196 {pos} is a list of positions. Each position can be one of
7197 these:
7198 - A number. This whole line will be highlighted. The first
7199 line has number 1.
7200 - A list with one number, e.g., [23]. The whole line with this
7201 number will be highlighted.
7202 - A list with two numbers, e.g., [23, 11]. The first number is
7203 the line number, the second one is the column number (first
7204 column is 1, the value must correspond to the byte index as
7205 |col()| would return). The character at this position will
7206 be highlighted.
7207 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7208 the third number gives the length of the highlight in bytes.
7209
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007210 Returns -1 on error.
7211
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007212 Example: >
7213 :highlight MyGroup ctermbg=green guibg=green
7214 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7215< Deletion of the pattern: >
7216 :call matchdelete(m)
7217
7218< Matches added by |matchaddpos()| are returned by
7219 |getmatches()|.
7220
7221 Can also be used as a |method|: >
7222 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007223<
7224 Return type: |Number|
7225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007226
7227matcharg({nr}) *matcharg()*
7228 Selects the {nr} match item, as set with a |:match|,
7229 |:2match| or |:3match| command.
7230 Return a |List| with two elements:
7231 The name of the highlight group used
7232 The pattern used.
7233 When {nr} is not 1, 2 or 3 returns an empty |List|.
7234 When there is no match item set returns ['', ''].
7235 This is useful to save and restore a |:match|.
7236 Highlighting matches using the |:match| commands are limited
7237 to three matches. |matchadd()| does not have this limitation.
7238
7239 Can also be used as a |method|: >
7240 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007241<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007242 Return type: list<string>
7243
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007244 *matchbufline()*
7245matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7246 Returns the |List| of matches in lines from {lnum} to {end} in
7247 buffer {buf} where {pat} matches.
7248
7249 {lnum} and {end} can either be a line number or the string "$"
7250 to refer to the last line in {buf}.
7251
7252 The {dict} argument supports following items:
7253 submatches include submatch information (|/\(|)
7254
7255 For each match, a |Dict| with the following items is returned:
7256 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007257 lnum line number where there is a match
7258 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007259 Note that there can be multiple matches in a single line.
7260
7261 This function works only for loaded buffers. First call
7262 |bufload()| if needed.
7263
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007264 See |match-pattern| for information about the effect of some
7265 option settings on the pattern.
7266
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007267 When {buf} is not a valid buffer, the buffer is not loaded or
7268 {lnum} or {end} is not valid then an error is given and an
7269 empty |List| is returned.
7270
7271 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007272 " Assuming line 3 in buffer 5 contains "a"
7273 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7274 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7275 " Assuming line 4 in buffer 10 contains "tik tok"
7276 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7277 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007278<
7279 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007280 "\1", "\2", etc. are also returned. Example: >
7281 " Assuming line 2 in buffer 2 contains "acd"
7282 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007283 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007284 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007285< The "submatches" List always contains 9 items. If a submatch
7286 is not found, then an empty string is returned for that
7287 submatch.
7288
7289 Can also be used as a |method|: >
7290 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007291<
7292 Return type: list<dict<any>> or list<any>
7293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007294
h-east624bb832024-11-09 18:37:32 +01007295matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007296 Deletes a match with ID {id} previously defined by |matchadd()|
7297 or one of the |:match| commands. Returns 0 if successful,
7298 otherwise -1. See example for |matchadd()|. All matches can
7299 be deleted in one operation by |clearmatches()|.
7300 If {win} is specified, use the window with this number or
7301 window ID instead of the current window.
7302
7303 Can also be used as a |method|: >
7304 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007305<
7306 Return type: |Number|
7307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007308
7309matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7310 Same as |match()|, but return the index of first character
7311 after the match. Example: >
7312 :echo matchend("testing", "ing")
7313< results in "7".
7314 *strspn()* *strcspn()*
7315 Vim doesn't have a strspn() or strcspn() function, but you can
7316 do it with matchend(): >
7317 :let span = matchend(line, '[a-zA-Z]')
7318 :let span = matchend(line, '[^a-zA-Z]')
7319< Except that -1 is returned when there are no matches.
7320
7321 The {start}, if given, has the same meaning as for |match()|. >
7322 :echo matchend("testing", "ing", 2)
7323< results in "7". >
7324 :echo matchend("testing", "ing", 5)
7325< result is "-1".
7326 When {expr} is a |List| the result is equal to |match()|.
7327
7328 Can also be used as a |method|: >
7329 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007330<
7331 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007332
7333
7334matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7335 If {list} is a list of strings, then returns a |List| with all
7336 the strings in {list} that fuzzy match {str}. The strings in
7337 the returned list are sorted based on the matching score.
7338
7339 The optional {dict} argument always supports the following
7340 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007341 matchseq When this item is present return only matches
7342 that contain the characters in {str} in the
7343 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007344 limit Maximum number of matches in {list} to be
7345 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007346 camelcase Use enhanced camel case scoring making results
7347 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007348 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007349
7350 If {list} is a list of dictionaries, then the optional {dict}
7351 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007352 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007353 {str}. The value of this item should be a
7354 string.
7355 text_cb |Funcref| that will be called for every item
7356 in {list} to get the text for fuzzy matching.
7357 This should accept a dictionary item as the
7358 argument and return the text for that item to
7359 use for fuzzy matching.
7360
7361 {str} is treated as a literal string and regular expression
7362 matching is NOT supported. The maximum supported {str} length
7363 is 256.
7364
7365 When {str} has multiple words each separated by white space,
7366 then the list of strings that have all the words is returned.
7367
7368 If there are no matching strings or there is an error, then an
7369 empty list is returned. If length of {str} is greater than
7370 256, then returns an empty list.
7371
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007372 When {limit} is given, matchfuzzy() will find up to this
7373 number of matches in {list} and return them in sorted order.
7374
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007375 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007376 matching strings.
7377
7378 Example: >
7379 :echo matchfuzzy(["clay", "crow"], "cay")
7380< results in ["clay"]. >
7381 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7382< results in a list of buffer names fuzzy matching "ndl". >
7383 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7384< results in a list of buffer information dicts with buffer
7385 names fuzzy matching "ndl". >
7386 :echo getbufinfo()->matchfuzzy("spl",
7387 \ {'text_cb' : {v -> v.name}})
7388< results in a list of buffer information dicts with buffer
7389 names fuzzy matching "spl". >
7390 :echo v:oldfiles->matchfuzzy("test")
7391< results in a list of file names fuzzy matching "test". >
7392 :let l = readfile("buffer.c")->matchfuzzy("str")
7393< results in a list of lines in "buffer.c" fuzzy matching "str". >
7394 :echo ['one two', 'two one']->matchfuzzy('two one')
7395< results in ['two one', 'one two']. >
7396 :echo ['one two', 'two one']->matchfuzzy('two one',
7397 \ {'matchseq': 1})
7398< results in ['two one'].
7399
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007400 Return type: list<string> or list<any>
7401
7402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007403matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7404 Same as |matchfuzzy()|, but returns the list of matched
7405 strings, the list of character positions where characters
7406 in {str} matches and a list of matching scores. You can
7407 use |byteidx()| to convert a character position to a byte
7408 position.
7409
7410 If {str} matches multiple times in a string, then only the
7411 positions for the best match is returned.
7412
7413 If there are no matching strings or there is an error, then a
7414 list with three empty list items is returned.
7415
7416 Example: >
7417 :echo matchfuzzypos(['testing'], 'tsg')
7418< results in [['testing'], [[0, 2, 6]], [99]] >
7419 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7420< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7421 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7422< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7423
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007424 Return type: list<list<any>>
7425
7426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007427matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7428 Same as |match()|, but return a |List|. The first item in the
7429 list is the matched string, same as what matchstr() would
7430 return. Following items are submatches, like "\1", "\2", etc.
7431 in |:substitute|. When an optional submatch didn't match an
7432 empty string is used. Example: >
7433 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7434< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7435 When there is no match an empty list is returned.
7436
7437 You can pass in a List, but that is not very useful.
7438
7439 Can also be used as a |method|: >
7440 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007441<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007442 Return type: list<string> or list<any>
7443
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007444 *matchstrlist()*
7445matchstrlist({list}, {pat} [, {dict}])
7446 Returns the |List| of matches in {list} where {pat} matches.
7447 {list} is a |List| of strings. {pat} is matched against each
7448 string in {list}.
7449
7450 The {dict} argument supports following items:
7451 submatches include submatch information (|/\(|)
7452
7453 For each match, a |Dict| with the following items is returned:
7454 byteidx starting byte index of the match.
7455 idx index in {list} of the match.
7456 text matched string
7457 submatches a List of submatches. Present only if
7458 "submatches" is set to v:true in {dict}.
7459
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007460 See |match-pattern| for information about the effect of some
7461 option settings on the pattern.
7462
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007463 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007464 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7465 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7466 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7467 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007468<
7469 If "submatches" is present and is v:true, then submatches like
7470 "\1", "\2", etc. are also returned. Example: >
7471 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7472 \ #{submatches: v:true})
7473 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7474< The "submatches" List always contains 9 items. If a submatch
7475 is not found, then an empty string is returned for that
7476 submatch.
7477
7478 Can also be used as a |method|: >
7479 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007480<
7481 Return type: list<dict<any>> or list<any>
7482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007483
7484matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7485 Same as |match()|, but return the matched string. Example: >
7486 :echo matchstr("testing", "ing")
7487< results in "ing".
7488 When there is no match "" is returned.
7489 The {start}, if given, has the same meaning as for |match()|. >
7490 :echo matchstr("testing", "ing", 2)
7491< results in "ing". >
7492 :echo matchstr("testing", "ing", 5)
7493< result is "".
7494 When {expr} is a |List| then the matching item is returned.
7495 The type isn't changed, it's not necessarily a String.
7496
7497 Can also be used as a |method|: >
7498 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007499<
7500 Return type: |String|
7501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007502
7503matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7504 Same as |matchstr()|, but return the matched string, the start
7505 position and the end position of the match. Example: >
7506 :echo matchstrpos("testing", "ing")
7507< results in ["ing", 4, 7].
7508 When there is no match ["", -1, -1] is returned.
7509 The {start}, if given, has the same meaning as for |match()|. >
7510 :echo matchstrpos("testing", "ing", 2)
7511< results in ["ing", 4, 7]. >
7512 :echo matchstrpos("testing", "ing", 5)
7513< result is ["", -1, -1].
7514 When {expr} is a |List| then the matching item, the index
7515 of first item where {pat} matches, the start position and the
7516 end position of the match are returned. >
7517 :echo matchstrpos([1, '__x'], '\a')
7518< result is ["x", 1, 2, 3].
7519 The type isn't changed, it's not necessarily a String.
7520
7521 Can also be used as a |method|: >
7522 GetText()->matchstrpos('word')
7523<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007524 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007525
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007526
7527max({expr}) *max()*
7528 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007529 echo max([apples, pears, oranges])
7530
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007531< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7532 Dictionary, it returns the maximum of all values in the
7533 Dictionary. If {expr} is neither a List nor a Tuple nor a
7534 Dictionary, or one of the items in {expr} cannot be used as a
7535 Number this results in an error. An empty |List|, |Tuple|
7536 or |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007537
7538 Can also be used as a |method|: >
7539 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007540<
7541 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007542
7543
7544menu_info({name} [, {mode}]) *menu_info()*
7545 Return information about the specified menu {name} in
7546 mode {mode}. The menu name should be specified without the
7547 shortcut character ('&'). If {name} is "", then the top-level
7548 menu names are returned.
7549
7550 {mode} can be one of these strings:
7551 "n" Normal
7552 "v" Visual (including Select)
7553 "o" Operator-pending
7554 "i" Insert
7555 "c" Cmd-line
7556 "s" Select
7557 "x" Visual
7558 "t" Terminal-Job
7559 "" Normal, Visual and Operator-pending
7560 "!" Insert and Cmd-line
7561 When {mode} is omitted, the modes for "" are used.
7562
7563 Returns a |Dictionary| containing the following items:
7564 accel menu item accelerator text |menu-text|
7565 display display name (name without '&')
7566 enabled v:true if this menu item is enabled
7567 Refer to |:menu-enable|
7568 icon name of the icon file (for toolbar)
7569 |toolbar-icon|
7570 iconidx index of a built-in icon
7571 modes modes for which the menu is defined. In
7572 addition to the modes mentioned above, these
7573 characters will be used:
7574 " " Normal, Visual and Operator-pending
7575 name menu item name.
7576 noremenu v:true if the {rhs} of the menu item is not
7577 remappable else v:false.
7578 priority menu order priority |menu-priority|
7579 rhs right-hand-side of the menu item. The returned
7580 string has special characters translated like
7581 in the output of the ":menu" command listing.
7582 When the {rhs} of a menu item is empty, then
7583 "<Nop>" is returned.
7584 script v:true if script-local remapping of {rhs} is
7585 allowed else v:false. See |:menu-script|.
7586 shortcut shortcut key (character after '&' in
7587 the menu name) |menu-shortcut|
7588 silent v:true if the menu item is created
7589 with <silent> argument |:menu-silent|
7590 submenus |List| containing the names of
7591 all the submenus. Present only if the menu
7592 item has submenus.
7593
7594 Returns an empty dictionary if the menu item is not found.
7595
7596 Examples: >
7597 :echo menu_info('Edit.Cut')
7598 :echo menu_info('File.Save', 'n')
7599
7600 " Display the entire menu hierarchy in a buffer
7601 func ShowMenu(name, pfx)
7602 let m = menu_info(a:name)
7603 call append(line('$'), a:pfx .. m.display)
7604 for child in m->get('submenus', [])
7605 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7606 \ a:pfx .. ' ')
7607 endfor
7608 endfunc
7609 new
7610 for topmenu in menu_info('').submenus
7611 call ShowMenu(topmenu, '')
7612 endfor
7613<
7614 Can also be used as a |method|: >
7615 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007616<
7617 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007618
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007619min({expr}) *min()*
7620 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007621 echo min([apples, pears, oranges])
7622
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007623< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7624 Dictionary, it returns the minimum of all values in the
7625 Dictionary. If {expr} is neither a List nor a Tuple nor a
7626 Dictionary, or one of the items in {expr} cannot be used as a
7627 Number this results in an error. An empty |List|, |Tuple| or
7628 |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007629
7630 Can also be used as a |method|: >
7631 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007632<
7633 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007634
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007635
7636mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007637 Create directory {name}.
7638
Bram Moolenaar938ae282023-02-20 20:44:55 +00007639 When {flags} is present it must be a string. An empty string
7640 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007641
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007642 {flags} can contain these character flags:
7643 "p" intermediate directories will be created as necessary
7644 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007645 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007646 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007647 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007648
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007649 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007650 some directories may already exist. Only the first one that
7651 is created and what it contains is scheduled to be deleted.
7652 E.g. when using: >
7653 call mkdir('subdir/tmp/autoload', 'pR')
7654< and "subdir" already exists then "subdir/tmp" will be
7655 scheduled for deletion, like with: >
7656 defer delete('subdir/tmp', 'rf')
7657< Note that if scheduling the defer fails the directory is not
7658 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007659
7660 If {prot} is given it is used to set the protection bits of
7661 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7662 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007663 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007664 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007665 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007666 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007667
7668< This function is not available in the |sandbox|.
7669
7670 There is no error if the directory already exists and the "p"
7671 flag is passed (since patch 8.0.1708). However, without the
7672 "p" option the call will fail.
7673
7674 The function result is a Number, which is TRUE if the call was
7675 successful or FALSE if the directory creation failed or partly
7676 failed.
7677
7678 Not available on all systems. To check use: >
7679 :if exists("*mkdir")
7680
7681< Can also be used as a |method|: >
7682 GetName()->mkdir()
7683<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007684 Return type: |Number|
7685
7686
7687mode([{expr}]) *mode()*
7688 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007689 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007690 a non-empty String (|non-zero-arg|), then the full mode is
7691 returned, otherwise only the first letter is returned.
7692 Also see |state()|.
7693
7694 n Normal
7695 no Operator-pending
7696 nov Operator-pending (forced characterwise |o_v|)
7697 noV Operator-pending (forced linewise |o_V|)
7698 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7699 CTRL-V is one character
7700 niI Normal using |i_CTRL-O| in |Insert-mode|
7701 niR Normal using |i_CTRL-O| in |Replace-mode|
7702 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7703 nt Terminal-Normal (insert goes to Terminal-Job mode)
7704 v Visual by character
7705 vs Visual by character using |v_CTRL-O| in Select mode
7706 V Visual by line
7707 Vs Visual by line using |v_CTRL-O| in Select mode
7708 CTRL-V Visual blockwise
7709 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7710 s Select by character
7711 S Select by line
7712 CTRL-S Select blockwise
7713 i Insert
7714 ic Insert mode completion |compl-generic|
7715 ix Insert mode |i_CTRL-X| completion
7716 R Replace |R|
7717 Rc Replace mode completion |compl-generic|
7718 Rx Replace mode |i_CTRL-X| completion
7719 Rv Virtual Replace |gR|
7720 Rvc Virtual Replace mode completion |compl-generic|
7721 Rvx Virtual Replace mode |i_CTRL-X| completion
7722 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007723 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007724 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007725 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007726 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007727 ce Normal Ex mode |Q|
7728 r Hit-enter prompt
7729 rm The -- more -- prompt
7730 r? A |:confirm| query of some sort
7731 ! Shell or external command is executing
7732 t Terminal-Job mode: keys go to the job
7733
7734 This is useful in the 'statusline' option or when used
7735 with |remote_expr()| In most other places it always returns
7736 "c" or "n".
7737 Note that in the future more modes and more specific modes may
7738 be added. It's better not to compare the whole string but only
7739 the leading character(s).
7740 Also see |visualmode()|.
7741
7742 Can also be used as a |method|: >
7743 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007744<
7745 Return type: |String|
7746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007747
7748mzeval({expr}) *mzeval()*
7749 Evaluate MzScheme expression {expr} and return its result
7750 converted to Vim data structures.
7751 Numbers and strings are returned as they are.
7752 Pairs (including lists and improper lists) and vectors are
7753 returned as Vim |Lists|.
7754 Hash tables are represented as Vim |Dictionary| type with keys
7755 converted to strings.
7756 All other types are converted to string with display function.
7757 Examples: >
7758 :mz (define l (list 1 2 3))
7759 :mz (define h (make-hash)) (hash-set! h "list" l)
7760 :echo mzeval("l")
7761 :echo mzeval("h")
7762<
7763 Note that in a `:def` function local variables are not visible
7764 to {expr}.
7765
7766 Can also be used as a |method|: >
7767 GetExpr()->mzeval()
7768<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007769 Return type: any, depending on {expr}
7770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007771 {only available when compiled with the |+mzscheme| feature}
7772
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007774nextnonblank({lnum}) *nextnonblank()*
7775 Return the line number of the first line at or below {lnum}
7776 that is not blank. Example: >
7777 if getline(nextnonblank(1)) =~ "Java"
7778< When {lnum} is invalid or there is no non-blank line at or
7779 below it, zero is returned.
7780 {lnum} is used like with |getline()|.
7781 See also |prevnonblank()|.
7782
7783 Can also be used as a |method|: >
7784 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007785<
7786 Return type: |Number|
7787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007788
Christ van Willegenc0786752025-02-01 15:42:16 +01007789ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7790 Return a string that contains the correct value for a
7791 message based on the rules for plural form(s) in
7792 a language. Examples: >
7793 ngettext("File", "Files", 2) # returns "Files"
7794<
7795 Can be used as a |method|: >
7796 1->ngettext("File", "Files") # returns "File"
7797<
7798 See |gettext()| for information on the domain parameter.
7799
7800 Return type: |String|
7801
7802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007803nr2char({expr} [, {utf8}]) *nr2char()*
7804 Return a string with a single character, which has the number
7805 value {expr}. Examples: >
7806 nr2char(64) returns "@"
7807 nr2char(32) returns " "
7808< When {utf8} is omitted or zero, the current 'encoding' is used.
7809 Example for "utf-8": >
7810 nr2char(300) returns I with bow character
7811< When {utf8} is TRUE, always return UTF-8 characters.
7812 Note that a NUL character in the file is specified with
7813 nr2char(10), because NULs are represented with newline
7814 characters. nr2char(0) is a real NUL and terminates the
7815 string, thus results in an empty string.
7816 To turn a list of character numbers into a string: >
7817 let list = [65, 66, 67]
7818 let str = join(map(list, {_, val -> nr2char(val)}), '')
7819< Result: "ABC"
7820
7821 Can also be used as a |method|: >
7822 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007823<
7824 Return type: |String|
7825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007826
7827or({expr}, {expr}) *or()*
7828 Bitwise OR on the two arguments. The arguments are converted
7829 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007830 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007831 Example: >
7832 :let bits = or(bits, 0x80)
7833< Can also be used as a |method|: >
7834 :let bits = bits->or(0x80)
7835
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007836< Rationale: The reason this is a function and not using the "|"
7837 character like many languages, is that Vi has always used "|"
7838 to separate commands. In many places it would not be clear if
7839 "|" is an operator or a command separator.
7840
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007841 Return type: |Number|
7842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007843
7844pathshorten({path} [, {len}]) *pathshorten()*
7845 Shorten directory names in the path {path} and return the
7846 result. The tail, the file name, is kept as-is. The other
7847 components in the path are reduced to {len} letters in length.
7848 If {len} is omitted or smaller than 1 then 1 is used (single
7849 letters). Leading '~' and '.' characters are kept. Examples: >
7850 :echo pathshorten('~/.vim/autoload/myfile.vim')
7851< ~/.v/a/myfile.vim ~
7852>
7853 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7854< ~/.vi/au/myfile.vim ~
7855 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007856 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007857
7858 Can also be used as a |method|: >
7859 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007860<
7861 Return type: |String|
7862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007863
7864perleval({expr}) *perleval()*
7865 Evaluate Perl expression {expr} in scalar context and return
7866 its result converted to Vim data structures. If value can't be
7867 converted, it is returned as a string Perl representation.
7868 Note: If you want an array or hash, {expr} must return a
7869 reference to it.
7870 Example: >
7871 :echo perleval('[1 .. 4]')
7872< [1, 2, 3, 4]
7873
7874 Note that in a `:def` function local variables are not visible
7875 to {expr}.
7876
7877 Can also be used as a |method|: >
7878 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007879<
7880 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007881
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007882 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007883
7884
7885popup_ functions are documented here: |popup-functions|
7886
7887
7888pow({x}, {y}) *pow()*
7889 Return the power of {x} to the exponent {y} as a |Float|.
7890 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007891 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007892 Examples: >
7893 :echo pow(3, 3)
7894< 27.0 >
7895 :echo pow(2, 16)
7896< 65536.0 >
7897 :echo pow(32, 0.20)
7898< 2.0
7899
7900 Can also be used as a |method|: >
7901 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007902<
7903 Return type: |Number|
7904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007905
7906prevnonblank({lnum}) *prevnonblank()*
7907 Return the line number of the first line at or above {lnum}
7908 that is not blank. Example: >
7909 let ind = indent(prevnonblank(v:lnum - 1))
7910< When {lnum} is invalid or there is no non-blank line at or
7911 above it, zero is returned.
7912 {lnum} is used like with |getline()|.
7913 Also see |nextnonblank()|.
7914
7915 Can also be used as a |method|: >
7916 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007917<
7918 Return type: |Number|
7919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007920
7921printf({fmt}, {expr1} ...) *printf()*
7922 Return a String with {fmt}, where "%" items are replaced by
7923 the formatted form of their respective arguments. Example: >
7924 printf("%4d: E%d %.30s", lnum, errno, msg)
7925< May result in:
7926 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7927
7928 When used as a |method| the base is passed as the second
7929 argument: >
7930 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007931<
7932 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007933
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007934 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007935 %s string
7936 %6S string right-aligned in 6 display cells
7937 %6s string right-aligned in 6 bytes
7938 %.9s string truncated to 9 bytes
7939 %c single byte
7940 %d decimal number
7941 %5d decimal number padded with spaces to 5 characters
7942 %x hex number
7943 %04x hex number padded with zeros to at least 4 characters
7944 %X hex number using upper case letters
7945 %o octal number
7946 %08b binary number padded with zeros to at least 8 chars
7947 %f floating point number as 12.23, inf, -inf or nan
7948 %F floating point number as 12.23, INF, -INF or NAN
7949 %e floating point number as 1.23e3, inf, -inf or nan
7950 %E floating point number as 1.23E3, INF, -INF or NAN
7951 %g floating point number, as %f or %e depending on value
7952 %G floating point number, as %F or %E depending on value
7953 %% the % character itself
7954
7955 Conversion specifications start with '%' and end with the
7956 conversion type. All other characters are copied unchanged to
7957 the result.
7958
7959 The "%" starts a conversion specification. The following
7960 arguments appear in sequence:
7961
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007962 % [pos-argument] [flags] [field-width] [.precision] type
7963
7964 pos-argument
7965 At most one positional argument specifier. These
7966 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007967
7968 flags
7969 Zero or more of the following flags:
7970
7971 # The value should be converted to an "alternate
7972 form". For c, d, and s conversions, this option
7973 has no effect. For o conversions, the precision
7974 of the number is increased to force the first
7975 character of the output string to a zero (except
7976 if a zero value is printed with an explicit
7977 precision of zero).
7978 For b and B conversions, a non-zero result has
7979 the string "0b" (or "0B" for B conversions)
7980 prepended to it.
7981 For x and X conversions, a non-zero result has
7982 the string "0x" (or "0X" for X conversions)
7983 prepended to it.
7984
7985 0 (zero) Zero padding. For all conversions the converted
7986 value is padded on the left with zeros rather
7987 than blanks. If a precision is given with a
7988 numeric conversion (d, b, B, o, x, and X), the 0
7989 flag is ignored.
7990
7991 - A negative field width flag; the converted value
7992 is to be left adjusted on the field boundary.
7993 The converted value is padded on the right with
7994 blanks, rather than on the left with blanks or
7995 zeros. A - overrides a 0 if both are given.
7996
7997 ' ' (space) A blank should be left before a positive
7998 number produced by a signed conversion (d).
7999
8000 + A sign must always be placed before a number
8001 produced by a signed conversion. A + overrides
8002 a space if both are used.
8003
8004 field-width
8005 An optional decimal digit string specifying a minimum
8006 field width. If the converted value has fewer bytes
8007 than the field width, it will be padded with spaces on
8008 the left (or right, if the left-adjustment flag has
8009 been given) to fill out the field width. For the S
8010 conversion the count is in cells.
8011
8012 .precision
8013 An optional precision, in the form of a period '.'
8014 followed by an optional digit string. If the digit
8015 string is omitted, the precision is taken as zero.
8016 This gives the minimum number of digits to appear for
8017 d, o, x, and X conversions, the maximum number of
8018 bytes to be printed from a string for s conversions,
8019 or the maximum number of cells to be printed from a
8020 string for S conversions.
8021 For floating point it is the number of digits after
8022 the decimal point.
8023
8024 type
8025 A character that specifies the type of conversion to
8026 be applied, see below.
8027
8028 A field width or precision, or both, may be indicated by an
8029 asterisk '*' instead of a digit string. In this case, a
8030 Number argument supplies the field width or precision. A
8031 negative field width is treated as a left adjustment flag
8032 followed by a positive field width; a negative precision is
8033 treated as though it were missing. Example: >
8034 :echo printf("%d: %.*s", nr, width, line)
8035< This limits the length of the text used from "line" to
8036 "width" bytes.
8037
Dominique Pellé17dca3c2023-12-14 20:36:32 +01008038 If the argument to be formatted is specified using a
8039 positional argument specifier, and a '*' is used to indicate
8040 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008041 precision, the argument(s) to be used must also be specified
8042 using a {n$} positional argument specifier. See |printf-$|.
8043
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008044 The conversion specifiers and their meanings are:
8045
8046 *printf-d* *printf-b* *printf-B* *printf-o*
8047 *printf-x* *printf-X*
8048 dbBoxX The Number argument is converted to signed decimal
8049 (d), unsigned binary (b and B), unsigned octal (o), or
8050 unsigned hexadecimal (x and X) notation. The letters
8051 "abcdef" are used for x conversions; the letters
8052 "ABCDEF" are used for X conversions.
8053 The precision, if any, gives the minimum number of
8054 digits that must appear; if the converted value
8055 requires fewer digits, it is padded on the left with
8056 zeros.
8057 In no case does a non-existent or small field width
8058 cause truncation of a numeric field; if the result of
8059 a conversion is wider than the field width, the field
8060 is expanded to contain the conversion result.
8061 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02008062 The 'l' modifier indicates the argument is a long
8063 integer. The size will be 32 bits or 64 bits
8064 depending on your platform.
8065 The "ll" modifier indicates the argument is 64 bits.
8066 The b and B conversion specifiers never take a width
8067 modifier and always assume their argument is a 64 bit
8068 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008069 Generally, these modifiers are not useful. They are
8070 ignored when type is known from the argument.
8071
8072 i alias for d
8073 D alias for ld
8074 U alias for lu
8075 O alias for lo
8076
8077 *printf-c*
8078 c The Number argument is converted to a byte, and the
8079 resulting character is written.
8080
8081 *printf-s*
8082 s The text of the String argument is used. If a
8083 precision is specified, no more bytes than the number
8084 specified are used.
8085 If the argument is not a String type, it is
8086 automatically converted to text with the same format
8087 as ":echo".
8088 *printf-S*
8089 S The text of the String argument is used. If a
8090 precision is specified, no more display cells than the
8091 number specified are used.
8092
8093 *printf-f* *E807*
8094 f F The Float argument is converted into a string of the
8095 form 123.456. The precision specifies the number of
8096 digits after the decimal point. When the precision is
8097 zero the decimal point is omitted. When the precision
8098 is not specified 6 is used. A really big number
8099 (out of range or dividing by zero) results in "inf"
8100 or "-inf" with %f (INF or -INF with %F).
8101 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8102 Example: >
8103 echo printf("%.2f", 12.115)
8104< 12.12
8105 Note that roundoff depends on the system libraries.
8106 Use |round()| when in doubt.
8107
8108 *printf-e* *printf-E*
8109 e E The Float argument is converted into a string of the
8110 form 1.234e+03 or 1.234E+03 when using 'E'. The
8111 precision specifies the number of digits after the
8112 decimal point, like with 'f'.
8113
8114 *printf-g* *printf-G*
8115 g G The Float argument is converted like with 'f' if the
8116 value is between 0.001 (inclusive) and 10000000.0
8117 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8118 for 'G'. When no precision is specified superfluous
8119 zeroes and '+' signs are removed, except for the zero
8120 immediately after the decimal point. Thus 10000000.0
8121 results in 1.0e7.
8122
8123 *printf-%*
8124 % A '%' is written. No argument is converted. The
8125 complete conversion specification is "%%".
8126
8127 When a Number argument is expected a String argument is also
8128 accepted and automatically converted.
8129 When a Float or String argument is expected a Number argument
8130 is also accepted and automatically converted.
8131 Any other argument type results in an error message.
8132
8133 *E766* *E767*
8134 The number of {exprN} arguments must exactly match the number
8135 of "%" items. If there are not sufficient or too many
8136 arguments an error is given. Up to 18 arguments can be used.
8137
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008138 *printf-$*
8139 In certain languages, error and informative messages are
8140 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008141 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008142 having a different word order, positional arguments may be
8143 used to indicate this. For instance: >
8144
h_east596a9f22023-11-21 21:24:23 +09008145 #, c-format
8146 msgid "%s returning %s"
8147 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008148<
h_east596a9f22023-11-21 21:24:23 +09008149 In this example, the sentence has its 2 string arguments
8150 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008151
h_east596a9f22023-11-21 21:24:23 +09008152 echo printf(
8153 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8154 "Bram", "Moolenaar")
8155< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008156
h_east596a9f22023-11-21 21:24:23 +09008157 echo printf(
8158 "In Belgium, vim's creator's name is: %2$s %1$s",
8159 "Bram", "Moolenaar")
8160< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008161
8162 Width (and precision) can be specified using the '*' specifier.
8163 In this case, you must specify the field width position in the
8164 argument list. >
8165
h_east596a9f22023-11-21 21:24:23 +09008166 echo printf("%1$*2$.*3$d", 1, 2, 3)
8167< 001 >
8168 echo printf("%2$*3$.*1$d", 1, 2, 3)
8169< 2 >
8170 echo printf("%3$*1$.*2$d", 1, 2, 3)
8171< 03 >
8172 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8173< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008174
8175 You can mix specifying the width and/or precision directly
8176 and via positional arguments: >
8177
h_east596a9f22023-11-21 21:24:23 +09008178 echo printf("%1$4.*2$f", 1.4142135, 6)
8179< 1.414214 >
8180 echo printf("%1$*2$.4f", 1.4142135, 6)
8181< 1.4142 >
8182 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8183< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008184
Christ van Willegenc35fc032024-03-14 18:30:41 +01008185 You will get an overflow error |E1510|, when the field-width
Hirohito Higashi0ed11ba2025-04-18 18:45:31 +02008186 or precision will result in a string longer than 1 MiB
zeertzjqe9a27ef2025-04-18 10:45:45 +02008187 (1024*1024 = 1048576) chars.
Christ van Willegenc35fc032024-03-14 18:30:41 +01008188
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008189 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008190 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008191 echo printf("%s%1$s", "One", "Two")
8192< E1500: Cannot mix positional and non-positional arguments:
8193 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008194
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008195 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008196 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008197 echo printf("%3$s%1$s", "One", "Two", "Three")
8198< E1501: format argument 2 unused in $-style format:
8199 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008200
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008201 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008202 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008203 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8204< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008205
8206 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008207 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8208< E1502: Positional argument 2 used as field width reused as
8209 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008210
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008211 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008212 When a positional argument is used, but not the correct number
8213 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008214 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8215< E1503: Positional argument 3 out of bounds: %1$d at width
8216 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008217
8218 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008219 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8220< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8221 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008222
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008223 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008224 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008225 echo printf("%1$s %2$s %1$s", "One", "Two")
8226< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008227
8228 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008229 echo printf("%1$s %2$s %1$d", "One", "Two")
8230< E1504: Positional argument 1 type used inconsistently:
8231 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008232
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008233 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008234 Various other errors that lead to a format string being
8235 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008236 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8237< E1505: Invalid format specifier: %1$d at width %2$d is:
8238 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008239
Christ van Willegenea746f92023-10-05 20:48:36 +02008240 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008241 This internal error indicates that the logic to parse a
8242 positional format argument ran into a problem that couldn't be
8243 otherwise reported. Please file a bug against Vim if you run
8244 into this, copying the exact format string and parameters that
8245 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008246
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008247 Return type: |String|
8248
Christ van Willegenea746f92023-10-05 20:48:36 +02008249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008250prompt_getprompt({buf}) *prompt_getprompt()*
8251 Returns the effective prompt text for buffer {buf}. {buf} can
8252 be a buffer name or number. See |prompt-buffer|.
8253
8254 If the buffer doesn't exist or isn't a prompt buffer, an empty
8255 string is returned.
8256
8257 Can also be used as a |method|: >
8258 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008259<
8260 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008261
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008262 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008263
8264
8265prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8266 Set prompt callback for buffer {buf} to {expr}. When {expr}
8267 is an empty string the callback is removed. This has only
8268 effect if {buf} has 'buftype' set to "prompt".
8269
8270 The callback is invoked when pressing Enter. The current
8271 buffer will always be the prompt buffer. A new line for a
8272 prompt is added before invoking the callback, thus the prompt
8273 for which the callback was invoked will be in the last but one
8274 line.
8275 If the callback wants to add text to the buffer, it must
8276 insert it above the last line, since that is where the current
8277 prompt is. This can also be done asynchronously.
8278 The callback is invoked with one argument, which is the text
8279 that was entered at the prompt. This can be an empty string
8280 if the user only typed Enter.
8281 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008282 func s:TextEntered(text)
8283 if a:text == 'exit' || a:text == 'quit'
8284 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008285 " Reset 'modified' to allow the buffer to be closed.
8286 " We assume there is nothing useful to be saved.
8287 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008288 close
8289 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008290 " Do something useful with "a:text". In this example
8291 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008292 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008293 endif
8294 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008295 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008296
8297< Can also be used as a |method|: >
8298 GetBuffer()->prompt_setcallback(callback)
8299
8300< {only available when compiled with the |+channel| feature}
8301
8302prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8303 Set a callback for buffer {buf} to {expr}. When {expr} is an
8304 empty string the callback is removed. This has only effect if
8305 {buf} has 'buftype' set to "prompt".
8306
8307 This callback will be invoked when pressing CTRL-C in Insert
8308 mode. Without setting a callback Vim will exit Insert mode,
8309 as in any buffer.
8310
8311 Can also be used as a |method|: >
8312 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008313<
8314 Return type: |Number|
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
8318prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8319 Set prompt for buffer {buf} to {text}. You most likely want
8320 {text} to end in a space.
8321 The result is only visible if {buf} has 'buftype' set to
8322 "prompt". Example: >
8323 call prompt_setprompt(bufnr(), 'command: ')
8324<
8325 Can also be used as a |method|: >
8326 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008327<
8328 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008329
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008330 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008331
8332prop_ functions are documented here: |text-prop-functions|
8333
8334pum_getpos() *pum_getpos()*
8335 If the popup menu (see |ins-completion-menu|) is not visible,
8336 returns an empty |Dictionary|, otherwise, returns a
8337 |Dictionary| with the following keys:
8338 height nr of items visible
8339 width screen cells
8340 row top screen row (0 first row)
8341 col leftmost screen column (0 first col)
8342 size total nr of items
8343 scrollbar |TRUE| if scrollbar is visible
8344
8345 The values are the same as in |v:event| during
8346 |CompleteChanged|.
8347
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008348 Return type: dict<any>
8349
8350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008351pumvisible() *pumvisible()*
8352 Returns non-zero when the popup menu is visible, zero
8353 otherwise. See |ins-completion-menu|.
8354 This can be used to avoid some things that would remove the
8355 popup menu.
8356
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008357 Return type: |Number|
8358
8359
zeertzjq7c515282024-11-10 20:26:12 +01008360py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008361 Evaluate Python expression {expr} and return its result
8362 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008363 If a {locals} |Dictionary| is given, it defines set of local
8364 variables available in the expression. The keys are variable
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008365 names and the values are the variable values. |Dictionary|,
8366 |List| and |Tuple| values are referenced, and may be updated
8367 by the expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008368 Numbers and strings are returned as they are (strings are
8369 copied though, Unicode strings are additionally converted to
8370 'encoding').
8371 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008372 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008373 Dictionaries are represented as Vim |Dictionary| type with
8374 keys converted to strings.
8375 Note that in a `:def` function local variables are not visible
8376 to {expr}.
8377
8378 Can also be used as a |method|: >
8379 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008380 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008381<
8382 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008383
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008384 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008385
8386 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008387pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008388 Evaluate Python expression {expr} and return its result
8389 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008390 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008391 Numbers and strings are returned as they are (strings are
8392 copied though).
8393 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008394 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008395 Dictionaries are represented as Vim |Dictionary| type,
8396 non-string keys result in error.
8397 Note that in a `:def` function local variables are not visible
8398 to {expr}.
8399
8400 Can also be used as a |method|: >
8401 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008402<
8403 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008404
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008405 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008406
zeertzjq7c515282024-11-10 20:26:12 +01008407pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008408 Evaluate Python expression {expr} and return its result
8409 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008410 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008411 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8412 See also: |pyeval()|, |py3eval()|
8413
8414 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008415 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008416<
8417 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008418
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008419 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008420 |+python3| feature}
8421
8422rand([{expr}]) *rand()* *random*
8423 Return a pseudo-random Number generated with an xoshiro128**
8424 algorithm using seed {expr}. The returned number is 32 bits,
8425 also on 64 bits systems, for consistency.
8426 {expr} can be initialized by |srand()| and will be updated by
8427 rand(). If {expr} is omitted, an internal seed value is used
8428 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008429 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008430
8431 Examples: >
8432 :echo rand()
8433 :let seed = srand()
8434 :echo rand(seed)
8435 :echo rand(seed) % 16 " random number 0 - 15
8436<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008437 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008438
8439 *E726* *E727*
8440range({expr} [, {max} [, {stride}]]) *range()*
8441 Returns a |List| with Numbers:
8442 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8443 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8444 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8445 {max}] (increasing {expr} with {stride} each time, not
8446 producing a value past {max}).
8447 When the maximum is one before the start the result is an
8448 empty list. When the maximum is more than one before the
8449 start this is an error.
8450 Examples: >
8451 range(4) " [0, 1, 2, 3]
8452 range(2, 4) " [2, 3, 4]
8453 range(2, 9, 3) " [2, 5, 8]
8454 range(2, -2, -1) " [2, 1, 0, -1, -2]
8455 range(0) " []
8456 range(2, 0) " error!
8457<
8458 Can also be used as a |method|: >
8459 GetExpr()->range()
8460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008461 Return type: list<number>
8462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008463
K.Takata11df3ae2022-10-19 14:02:40 +01008464readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008465 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008466 If {offset} is specified, read the file from the specified
8467 offset. If it is a negative value, it is used as an offset
8468 from the end of the file. E.g., to read the last 12 bytes: >
8469 readblob('file.bin', -12)
8470< If {size} is specified, only the specified size will be read.
8471 E.g. to read the first 100 bytes of a file: >
8472 readblob('file.bin', 0, 100)
8473< If {size} is -1 or omitted, the whole data starting from
8474 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008475 This can be also used to read the data from a character device
8476 on Unix when {size} is explicitly set. Only if the device
8477 supports seeking {offset} can be used. Otherwise it should be
8478 zero. E.g. to read 10 bytes from a serial console: >
8479 readblob('/dev/ttyS0', 0, 10)
8480< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008481 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008482 When the offset is beyond the end of the file the result is an
8483 empty blob.
8484 When trying to read more bytes than are available the result
8485 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008486 Also see |readfile()| and |writefile()|.
8487
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008488 Return type: |Blob|
8489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008490
8491readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8492 Return a list with file and directory names in {directory}.
8493 You can also use |glob()| if you don't need to do complicated
8494 things, such as limiting the number of matches.
8495 The list will be sorted (case sensitive), see the {dict}
8496 argument below for changing the sort order.
8497
8498 When {expr} is omitted all entries are included.
8499 When {expr} is given, it is evaluated to check what to do:
8500 If {expr} results in -1 then no further entries will
8501 be handled.
8502 If {expr} results in 0 then this entry will not be
8503 added to the list.
8504 If {expr} results in 1 then this entry will be added
8505 to the list.
8506 The entries "." and ".." are always excluded.
8507 Each time {expr} is evaluated |v:val| is set to the entry name.
8508 When {expr} is a function the name is passed as the argument.
8509 For example, to get a list of files ending in ".txt": >
8510 readdir(dirname, {n -> n =~ '.txt$'})
8511< To skip hidden and backup files: >
8512 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008513< *E857*
8514 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008515 values. Currently this is used to specify if and how sorting
8516 should be performed. The dict can have the following members:
8517
8518 sort How to sort the result returned from the system.
8519 Valid values are:
8520 "none" do not sort (fastest method)
8521 "case" sort case sensitive (byte value of
8522 each character, technically, using
8523 strcmp()) (default)
8524 "icase" sort case insensitive (technically
8525 using strcasecmp())
8526 "collate" sort using the collation order
8527 of the "POSIX" or "C" |locale|
8528 (technically using strcoll())
8529 Other values are silently ignored.
8530
8531 For example, to get a list of all files in the current
8532 directory without sorting the individual entries: >
8533 readdir('.', '1', #{sort: 'none'})
8534< If you want to get a directory tree: >
8535 function! s:tree(dir)
8536 return {a:dir : map(readdir(a:dir),
8537 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008538 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008539 endfunction
8540 echo s:tree(".")
8541<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008542 Returns an empty List on error.
8543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008544 Can also be used as a |method|: >
8545 GetDirName()->readdir()
8546<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008547 Return type: list<string> or list<any>
8548
8549
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008550readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8551 Extended version of |readdir()|.
8552 Return a list of Dictionaries with file and directory
8553 information in {directory}.
8554 This is useful if you want to get the attributes of file and
8555 directory at the same time as getting a list of a directory.
8556 This is much faster than calling |readdir()| then calling
8557 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8558 each file and directory especially on MS-Windows.
8559 The list will by default be sorted by name (case sensitive),
8560 the sorting can be changed by using the optional {dict}
8561 argument, see |readdir()|.
8562
8563 The Dictionary for file and directory information has the
8564 following items:
8565 group Group name of the entry. (Only on Unix)
8566 name Name of the entry.
8567 perm Permissions of the entry. See |getfperm()|.
8568 size Size of the entry. See |getfsize()|.
8569 time Timestamp of the entry. See |getftime()|.
8570 type Type of the entry.
8571 On Unix, almost same as |getftype()| except:
8572 Symlink to a dir "linkd"
8573 Other symlink "link"
8574 On MS-Windows:
8575 Normal file "file"
8576 Directory "dir"
8577 Junction "junction"
8578 Symlink to a dir "linkd"
8579 Other symlink "link"
8580 Other reparse point "reparse"
8581 user User name of the entry's owner. (Only on Unix)
8582 On Unix, if the entry is a symlink, the Dictionary includes
8583 the information of the target (except the "type" item).
8584 On MS-Windows, it includes the information of the symlink
8585 itself because of performance reasons.
8586
8587 When {expr} is omitted all entries are included.
8588 When {expr} is given, it is evaluated to check what to do:
8589 If {expr} results in -1 then no further entries will
8590 be handled.
8591 If {expr} results in 0 then this entry will not be
8592 added to the list.
8593 If {expr} results in 1 then this entry will be added
8594 to the list.
8595 The entries "." and ".." are always excluded.
8596 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8597 of the entry.
8598 When {expr} is a function the entry is passed as the argument.
8599 For example, to get a list of files ending in ".txt": >
8600 readdirex(dirname, {e -> e.name =~ '.txt$'})
8601<
8602 For example, to get a list of all files in the current
8603 directory without sorting the individual entries: >
8604 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008605<
8606 Can also be used as a |method|: >
8607 GetDirName()->readdirex()
8608<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008609 Return type: list<dict<any>> or list<any>
8610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008611
8612 *readfile()*
8613readfile({fname} [, {type} [, {max}]])
8614 Read file {fname} and return a |List|, each line of the file
8615 as an item. Lines are broken at NL characters. Macintosh
8616 files separated with CR will result in a single long line
8617 (unless a NL appears somewhere).
8618 All NUL characters are replaced with a NL character.
8619 When {type} contains "b" binary mode is used:
8620 - When the last line ends in a NL an extra empty list item is
8621 added.
8622 - No CR characters are removed.
8623 Otherwise:
8624 - CR characters that appear before a NL are removed.
8625 - Whether the last line ends in a NL or not does not matter.
8626 - When 'encoding' is Unicode any UTF-8 byte order mark is
8627 removed from the text.
8628 When {max} is given this specifies the maximum number of lines
8629 to be read. Useful if you only want to check the first ten
8630 lines of a file: >
8631 :for line in readfile(fname, '', 10)
8632 : if line =~ 'Date' | echo line | endif
8633 :endfor
8634< When {max} is negative -{max} lines from the end of the file
8635 are returned, or as many as there are.
8636 When {max} is zero the result is an empty list.
8637 Note that without {max} the whole file is read into memory.
8638 Also note that there is no recognition of encoding. Read a
8639 file into a buffer if you need to.
8640 Deprecated (use |readblob()| instead): When {type} contains
8641 "B" a |Blob| is returned with the binary data of the file
8642 unmodified.
8643 When the file can't be opened an error message is given and
8644 the result is an empty list.
8645 Also see |writefile()|.
8646
8647 Can also be used as a |method|: >
8648 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008649<
8650 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008651
8652reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8653 {func} is called for every item in {object}, which can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008654 |String|, |List|, |Tuple| or a |Blob|. {func} is called with
8655 two arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008656 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008657
8658 {initial} is the initial result. When omitted, the first item
8659 in {object} is used and {func} is first called for the second
8660 item. If {initial} is not given and {object} is empty no
8661 result can be computed, an E998 error is given.
8662
8663 Examples: >
8664 echo reduce([1, 3, 5], { acc, val -> acc + val })
8665 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8666 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8667 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8668<
8669 Can also be used as a |method|: >
8670 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008671<
8672 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8673 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008674
8675
8676reg_executing() *reg_executing()*
8677 Returns the single letter name of the register being executed.
8678 Returns an empty string when no register is being executed.
8679 See |@|.
8680
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008681 Return type: |String|
8682
8683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008684reg_recording() *reg_recording()*
8685 Returns the single letter name of the register being recorded.
8686 Returns an empty string when not recording. See |q|.
8687
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008688 Return type: |String|
8689
8690
8691reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008692reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008693reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008694 Return an item that represents a time value. The item is a
8695 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008696 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008697 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008698 string or |reltimefloat()| to convert to a Float. For
8699 example, to see the time spent in function Work(): >
8700 var startTime = reltime()
8701 Work()
8702 echo startTime->reltime()->reltimestr()
8703<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008704 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008705 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008706 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008707 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008708 specified in the argument.
8709 With two arguments it returns the time passed between {start}
8710 and {end}.
8711
8712 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008713 reltime(). If there is an error an empty List is returned in
8714 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008715
8716 Can also be used as a |method|: >
8717 GetStart()->reltime()
8718<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008719 Return type: list<number>
8720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008721 {only available when compiled with the |+reltime| feature}
8722
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008724reltimefloat({time}) *reltimefloat()*
8725 Return a Float that represents the time value of {time}.
8726 Example: >
8727 let start = reltime()
8728 call MyFunction()
8729 let seconds = reltimefloat(reltime(start))
8730< See the note of reltimestr() about overhead.
8731 Also see |profiling|.
8732 If there is an error 0.0 is returned in legacy script, in Vim9
8733 script an error is given.
8734
8735 Can also be used as a |method|: >
8736 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008737<
8738 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008739
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008740 {only available when compiled with the |+reltime| feature}
8741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008742
8743reltimestr({time}) *reltimestr()*
8744 Return a String that represents the time value of {time}.
8745 This is the number of seconds, a dot and the number of
8746 microseconds. Example: >
8747 let start = reltime()
8748 call MyFunction()
8749 echo reltimestr(reltime(start))
8750< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008751 The accuracy depends on the system. Use reltimefloat() for the
8752 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008753 Leading spaces are used to make the string align nicely. You
8754 can use split() to remove it. >
8755 echo split(reltimestr(reltime(start)))[0]
8756< Also see |profiling|.
8757 If there is an error an empty string is returned in legacy
8758 script, in Vim9 script an error is given.
8759
8760 Can also be used as a |method|: >
8761 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008762<
8763 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008764
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008765 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008766
8767 *remote_expr()* *E449*
8768remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008769 Send the {string} to {server}. The {server} argument is a
8770 string, also see |{server}|.
8771
8772 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008773 after evaluation. The result must be a String or a |List|
8774 other types will be converted to String. A |List| is turned
8775 into a String by joining the items with a line break in
8776 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008778 If {idvar} is present and not empty, it is taken as the name
8779 of a variable and a {serverid} for later use with
8780 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008782 If {timeout} is given the read times out after this many
8783 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008784
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008785 See also |clientserver| |RemoteReply|.
8786 This function is not available in the |sandbox|.
8787 {only available when compiled with the |+clientserver| feature}
8788 Note: Any errors will cause a local error message to be issued
8789 and the result will be the empty string.
8790
8791 Variables will be evaluated in the global namespace,
8792 independent of a function currently being active. Except
8793 when in debug mode, then local function variables and
8794 arguments can be evaluated.
8795
8796 Examples: >
8797 :echo remote_expr("gvim", "2+2")
8798 :echo remote_expr("gvim1", "b:current_syntax")
8799<
8800 Can also be used as a |method|: >
8801 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008802<
8803 Return type: |String| or list<{type}>
8804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008805
8806remote_foreground({server}) *remote_foreground()*
8807 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008808 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008809 This works like: >
8810 remote_expr({server}, "foreground()")
8811< Except that on Win32 systems the client does the work, to work
8812 around the problem that the OS doesn't always allow the server
8813 to bring itself to the foreground.
8814 Note: This does not restore the window if it was minimized,
8815 like foreground() does.
8816 This function is not available in the |sandbox|.
8817
8818 Can also be used as a |method|: >
8819 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008820<
8821 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008822
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008823 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008824 Win32 console version}
8825
8826
8827remote_peek({serverid} [, {retvar}]) *remote_peek()*
8828 Returns a positive number if there are available strings
8829 from {serverid}. Copies any reply string into the variable
8830 {retvar} if specified. {retvar} must be a string with the
8831 name of a variable.
8832 Returns zero if none are available.
8833 Returns -1 if something is wrong.
8834 See also |clientserver|.
8835 This function is not available in the |sandbox|.
8836 {only available when compiled with the |+clientserver| feature}
8837 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008838 :let repl = ""
8839 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008840
8841< Can also be used as a |method|: >
8842 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008843<
8844 Return type: |Number|
8845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008846
8847remote_read({serverid}, [{timeout}]) *remote_read()*
8848 Return the oldest available reply from {serverid} and consume
8849 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008850 reply is available. Returns an empty string, if a reply is
8851 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008852 See also |clientserver|.
8853 This function is not available in the |sandbox|.
8854 {only available when compiled with the |+clientserver| feature}
8855 Example: >
8856 :echo remote_read(id)
8857
8858< Can also be used as a |method|: >
8859 ServerId()->remote_read()
8860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008861 Return type: |String|
8862
8863
8864remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008865 Send the {string} to {server}. The {server} argument is a
8866 string, also see |{server}|.
8867
8868 The string is sent as input keys and the function returns
8869 immediately. At the Vim server the keys are not mapped
8870 |:map|.
8871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008872 If {idvar} is present, it is taken as the name of a variable
8873 and a {serverid} for later use with remote_read() is stored
8874 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008876 See also |clientserver| |RemoteReply|.
8877 This function is not available in the |sandbox|.
8878 {only available when compiled with the |+clientserver| feature}
8879
8880 Note: Any errors will be reported in the server and may mess
8881 up the display.
8882 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008883 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008884 \ remote_read(serverid)
8885
8886 :autocmd NONE RemoteReply *
8887 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008888 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008889 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8890<
8891 Can also be used as a |method|: >
8892 ServerName()->remote_send(keys)
8893<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008894 Return type: |String|
8895
8896
8897remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008898 Become the server {name}. {name} must be a non-empty string.
8899 This fails if already running as a server, when |v:servername|
8900 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008901
8902 Can also be used as a |method|: >
8903 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008904<
8905 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008906
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008907 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008908
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008909
8910remove({list}, {idx}) *remove()*
8911remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008912 Without {end}: Remove the item at {idx} from |List| {list} and
8913 return the item.
8914 With {end}: Remove items from {idx} to {end} (inclusive) and
8915 return a |List| with these items. When {idx} points to the same
8916 item as {end} a list with one item is returned. When {end}
8917 points to an item before {idx} this is an error.
8918 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008919 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008920 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008921 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008922 :call remove(mylist, 0, 9)
8923<
8924 Use |delete()| to remove a file.
8925
8926 Can also be used as a |method|: >
8927 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008928<
8929 Return type: any, depending on {list}
8930
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008931
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008932remove({blob}, {idx})
8933remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008934 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8935 return the byte.
8936 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8937 return a |Blob| with these bytes. When {idx} points to the same
8938 byte as {end} a |Blob| with one byte is returned. When {end}
8939 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008940 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008941 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008942 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008943 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008944<
8945 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008946
8947remove({dict}, {key})
8948 Remove the entry from {dict} with key {key} and return it.
8949 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008950 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008951< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008952 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008953
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008954 Return type: any, depending on {dict}
8955
8956
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008957rename({from}, {to}) *rename()*
8958 Rename the file by the name {from} to the name {to}. This
8959 should also work to move files across file systems. The
8960 result is a Number, which is 0 if the file was renamed
8961 successfully, and non-zero when the renaming failed.
8962 NOTE: If {to} exists it is overwritten without warning.
8963 This function is not available in the |sandbox|.
8964
8965 Can also be used as a |method|: >
8966 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008967<
8968 Return type: |Number|
8969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008970
8971repeat({expr}, {count}) *repeat()*
8972 Repeat {expr} {count} times and return the concatenated
8973 result. Example: >
8974 :let separator = repeat('-', 80)
8975< When {count} is zero or negative the result is empty.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008976 When {expr} is a |List|, a |Tuple| or a |Blob| the result is
8977 {expr} concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008978 :let longlist = repeat(['a', 'b'], 3)
8979< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8980
8981 Can also be used as a |method|: >
8982 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008983<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008984 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
8985 depending on {expr}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008987
8988resolve({filename}) *resolve()* *E655*
8989 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8990 returns the path the shortcut points to in a simplified form.
8991 When {filename} is a symbolic link or junction point, return
8992 the full path to the target. If the target of junction is
8993 removed, return {filename}.
8994 On Unix, repeat resolving symbolic links in all path
8995 components of {filename} and return the simplified result.
8996 To cope with link cycles, resolving of symbolic links is
8997 stopped after 100 iterations.
8998 On other systems, return the simplified {filename}.
8999 The simplification step is done as by |simplify()|.
9000 resolve() keeps a leading path component specifying the
9001 current directory (provided the result is still a relative
9002 path name) and also keeps a trailing path separator.
9003
9004 Can also be used as a |method|: >
9005 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009006<
9007 Return type: |String|
9008
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009009
9010reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009011 Reverse the order of items in {object}. {object} can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009012 |List|, a |Tuple|, a |Blob| or a |String|. For a List and a
9013 Blob the items are reversed in-place and {object} is returned.
9014 For a Tuple, a new Tuple is returned.
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009015 For a String a new String is returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009016 Returns zero if {object} is not a List, Tuple, Blob or a
9017 String. If you want a List or Blob to remain unmodified make
9018 a copy first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009019 :let revlist = reverse(copy(mylist))
9020< Can also be used as a |method|: >
9021 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009022<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009023 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
9024 depending on {object}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009026
9027round({expr}) *round()*
9028 Round off {expr} to the nearest integral value and return it
9029 as a |Float|. If {expr} lies halfway between two integral
9030 values, then use the larger one (away from zero).
9031 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009032 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009033 Examples: >
9034 echo round(0.456)
9035< 0.0 >
9036 echo round(4.5)
9037< 5.0 >
9038 echo round(-4.5)
9039< -5.0
9040
9041 Can also be used as a |method|: >
9042 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009043<
9044 Return type: |Float|
9045
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009046
9047rubyeval({expr}) *rubyeval()*
9048 Evaluate Ruby expression {expr} and return its result
9049 converted to Vim data structures.
9050 Numbers, floats and strings are returned as they are (strings
9051 are copied though).
9052 Arrays are represented as Vim |List| type.
9053 Hashes are represented as Vim |Dictionary| type.
9054 Other objects are represented as strings resulted from their
9055 "Object#to_s" method.
9056 Note that in a `:def` function local variables are not visible
9057 to {expr}.
9058
9059 Can also be used as a |method|: >
9060 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009061<
9062 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009063
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009064 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009065
9066screenattr({row}, {col}) *screenattr()*
9067 Like |screenchar()|, but return the attribute. This is a rather
9068 arbitrary number that can only be used to compare to the
9069 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009070 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009071
9072 Can also be used as a |method|: >
9073 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009074<
9075 Return type: |Number|
9076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009077
9078screenchar({row}, {col}) *screenchar()*
9079 The result is a Number, which is the character at position
9080 [row, col] on the screen. This works for every possible
9081 screen position, also status lines, window separators and the
9082 command line. The top left position is row one, column one
9083 The character excludes composing characters. For double-byte
9084 encodings it may only be the first byte.
9085 This is mainly to be used for testing.
9086 Returns -1 when row or col is out of range.
9087
9088 Can also be used as a |method|: >
9089 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009090<
9091 Return type: |Number|
9092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009093
9094screenchars({row}, {col}) *screenchars()*
9095 The result is a |List| of Numbers. The first number is the same
9096 as what |screenchar()| returns. Further numbers are
9097 composing characters on top of the base character.
9098 This is mainly to be used for testing.
9099 Returns an empty List when row or col is out of range.
9100
9101 Can also be used as a |method|: >
9102 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009103<
9104 Return type: list<number> or list<any>
9105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009106
9107screencol() *screencol()*
9108 The result is a Number, which is the current screen column of
9109 the cursor. The leftmost column has number 1.
9110 This function is mainly used for testing.
9111
9112 Note: Always returns the current screen column, thus if used
9113 in a command (e.g. ":echo screencol()") it will return the
9114 column inside the command line, which is 1 when the command is
9115 executed. To get the cursor position in the file use one of
9116 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009117 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009118 nnoremap <silent> GG :echom screencol()<CR>
9119 nnoremap GG <Cmd>echom screencol()<CR>
9120<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009121 Return type: |Number|
9122
9123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009124screenpos({winid}, {lnum}, {col}) *screenpos()*
9125 The result is a Dict with the screen position of the text
9126 character in window {winid} at buffer line {lnum} and column
9127 {col}. {col} is a one-based byte index.
9128 The Dict has these members:
9129 row screen row
9130 col first screen column
9131 endcol last screen column
9132 curscol cursor screen column
9133 If the specified position is not visible, all values are zero.
9134 The "endcol" value differs from "col" when the character
9135 occupies more than one screen cell. E.g. for a Tab "col" can
9136 be 1 and "endcol" can be 8.
9137 The "curscol" value is where the cursor would be placed. For
9138 a Tab it would be the same as "endcol", while for a double
9139 width character it would be the same as "col".
9140 The |conceal| feature is ignored here, the column numbers are
9141 as if 'conceallevel' is zero. You can set the cursor to the
9142 right position and use |screencol()| to get the value with
9143 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009144 If the position is in a closed fold the screen position of the
9145 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009146 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009147
9148 Can also be used as a |method|: >
9149 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009150<
9151 Return type: dict<number> or dict<any>
9152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009153
9154screenrow() *screenrow()*
9155 The result is a Number, which is the current screen row of the
9156 cursor. The top line has number one.
9157 This function is mainly used for testing.
9158 Alternatively you can use |winline()|.
9159
9160 Note: Same restrictions as with |screencol()|.
9161
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009162 Return type: |Number|
9163
9164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009165screenstring({row}, {col}) *screenstring()*
9166 The result is a String that contains the base character and
9167 any composing characters at position [row, col] on the screen.
9168 This is like |screenchars()| but returning a String with the
9169 characters.
9170 This is mainly to be used for testing.
9171 Returns an empty String when row or col is out of range.
9172
9173 Can also be used as a |method|: >
9174 GetRow()->screenstring(col)
9175<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009176 Return type: |String|
9177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009178 *search()*
9179search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9180 Search for regexp pattern {pattern}. The search starts at the
9181 cursor position (you can use |cursor()| to set it).
9182
9183 When a match has been found its line number is returned.
9184 If there is no match a 0 is returned and the cursor doesn't
9185 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009186 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009187
9188 {flags} is a String, which can contain these character flags:
9189 'b' search Backward instead of forward
9190 'c' accept a match at the Cursor position
9191 'e' move to the End of the match
9192 'n' do Not move the cursor
9193 'p' return number of matching sub-Pattern (see below)
9194 's' Set the ' mark at the previous location of the cursor
9195 'w' Wrap around the end of the file
9196 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009197 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009198 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9199
9200 If the 's' flag is supplied, the ' mark is set, only if the
9201 cursor is moved. The 's' flag cannot be combined with the 'n'
9202 flag.
9203
9204 'ignorecase', 'smartcase' and 'magic' are used.
9205
9206 When the 'z' flag is not given, forward searching always
9207 starts in column zero and then matches before the cursor are
9208 skipped. When the 'c' flag is present in 'cpo' the next
9209 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009210 search starts one column after the start of the match. This
9211 matters for overlapping matches. See |cpo-c|. You can also
9212 insert "\ze" to change where the match ends, see |/\ze|.
9213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009214 When searching backwards and the 'z' flag is given then the
9215 search starts in column zero, thus no match in the current
9216 line will be found (unless wrapping around the end of the
9217 file).
9218
9219 When the {stopline} argument is given then the search stops
9220 after searching this line. This is useful to restrict the
9221 search to a range of lines. Examples: >
9222 let match = search('(', 'b', line("w0"))
9223 let end = search('END', '', line("w$"))
9224< When {stopline} is used and it is not zero this also implies
9225 that the search does not wrap around the end of the file.
9226 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009227 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009228 When the {timeout} argument is given the search stops when
9229 more than this many milliseconds have passed. Thus when
9230 {timeout} is 500 the search stops after half a second.
9231 The value must not be negative. A zero value is like not
9232 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009233
9234 Note: the timeout is only considered when searching, not
9235 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009236 {only available when compiled with the |+reltime| feature}
9237
9238 If the {skip} expression is given it is evaluated with the
9239 cursor positioned on the start of a match. If it evaluates to
9240 non-zero this match is skipped. This can be used, for
9241 example, to skip a match in a comment or a string.
9242 {skip} can be a string, which is evaluated as an expression, a
9243 function reference or a lambda.
9244 When {skip} is omitted or empty, every match is accepted.
9245 When evaluating {skip} causes an error the search is aborted
9246 and -1 returned.
9247 *search()-sub-match*
9248 With the 'p' flag the returned value is one more than the
9249 first sub-match in \(\). One if none of them matched but the
9250 whole pattern did match.
9251 To get the column number too use |searchpos()|.
9252
9253 The cursor will be positioned at the match, unless the 'n'
9254 flag is used.
9255
9256 Example (goes over all files in the argument list): >
9257 :let n = 1
9258 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009259 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009260 : " start at the last char in the file and wrap for the
9261 : " first search to find match at start of file
9262 : normal G$
9263 : let flags = "w"
9264 : while search("foo", flags) > 0
9265 : s/foo/bar/g
9266 : let flags = "W"
9267 : endwhile
9268 : update " write the file if modified
9269 : let n = n + 1
9270 :endwhile
9271<
9272 Example for using some flags: >
9273 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9274< This will search for the keywords "if", "else", and "endif"
9275 under or after the cursor. Because of the 'p' flag, it
9276 returns 1, 2, or 3 depending on which keyword is found, or 0
9277 if the search fails. With the cursor on the first word of the
9278 line:
9279 if (foo == 0) | let foo = foo + 1 | endif ~
9280 the function returns 1. Without the 'c' flag, the function
9281 finds the "endif" and returns 3. The same thing happens
9282 without the 'e' flag if the cursor is on the "f" of "if".
9283 The 'n' flag tells the function not to move the cursor.
9284
9285 Can also be used as a |method|: >
9286 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009287<
9288 Return type: |Number|
9289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009290
9291searchcount([{options}]) *searchcount()*
9292 Get or update the last search count, like what is displayed
9293 without the "S" flag in 'shortmess'. This works even if
9294 'shortmess' does contain the "S" flag.
9295
9296 This returns a |Dictionary|. The dictionary is empty if the
9297 previous pattern was not set and "pattern" was not specified.
9298
9299 key type meaning ~
9300 current |Number| current position of match;
9301 0 if the cursor position is
9302 before the first match
9303 exact_match |Boolean| 1 if "current" is matched on
9304 "pos", otherwise 0
9305 total |Number| total count of matches found
9306 incomplete |Number| 0: search was fully completed
9307 1: recomputing was timed out
9308 2: max count exceeded
9309
9310 For {options} see further down.
9311
9312 To get the last search count when |n| or |N| was pressed, call
9313 this function with `recompute: 0` . This sometimes returns
9314 wrong information because |n| and |N|'s maximum count is 99.
9315 If it exceeded 99 the result must be max count + 1 (100). If
9316 you want to get correct information, specify `recompute: 1`: >
9317
9318 " result == maxcount + 1 (100) when many matches
9319 let result = searchcount(#{recompute: 0})
9320
9321 " Below returns correct result (recompute defaults
9322 " to 1)
9323 let result = searchcount()
9324<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009325 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009326 function! LastSearchCount() abort
9327 let result = searchcount(#{recompute: 0})
9328 if empty(result)
9329 return ''
9330 endif
9331 if result.incomplete ==# 1 " timed out
9332 return printf(' /%s [?/??]', @/)
9333 elseif result.incomplete ==# 2 " max count exceeded
9334 if result.total > result.maxcount &&
9335 \ result.current > result.maxcount
9336 return printf(' /%s [>%d/>%d]', @/,
9337 \ result.current, result.total)
9338 elseif result.total > result.maxcount
9339 return printf(' /%s [%d/>%d]', @/,
9340 \ result.current, result.total)
9341 endif
9342 endif
9343 return printf(' /%s [%d/%d]', @/,
9344 \ result.current, result.total)
9345 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009346 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009347
9348 " Or if you want to show the count only when
9349 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009350 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009351 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9352<
9353 You can also update the search count, which can be useful in a
9354 |CursorMoved| or |CursorMovedI| autocommand: >
9355
9356 autocmd CursorMoved,CursorMovedI *
9357 \ let s:searchcount_timer = timer_start(
9358 \ 200, function('s:update_searchcount'))
9359 function! s:update_searchcount(timer) abort
9360 if a:timer ==# s:searchcount_timer
9361 call searchcount(#{
9362 \ recompute: 1, maxcount: 0, timeout: 100})
9363 redrawstatus
9364 endif
9365 endfunction
9366<
9367 This can also be used to count matched texts with specified
9368 pattern in the current buffer using "pattern": >
9369
9370 " Count '\<foo\>' in this buffer
9371 " (Note that it also updates search count)
9372 let result = searchcount(#{pattern: '\<foo\>'})
9373
9374 " To restore old search count by old pattern,
9375 " search again
9376 call searchcount()
9377<
9378 {options} must be a |Dictionary|. It can contain:
9379 key type meaning ~
9380 recompute |Boolean| if |TRUE|, recompute the count
9381 like |n| or |N| was executed.
9382 otherwise returns the last
9383 computed result (when |n| or
9384 |N| was used when "S" is not
9385 in 'shortmess', or this
9386 function was called).
9387 (default: |TRUE|)
9388 pattern |String| recompute if this was given
9389 and different with |@/|.
9390 this works as same as the
9391 below command is executed
9392 before calling this function >
9393 let @/ = pattern
9394< (default: |@/|)
9395 timeout |Number| 0 or negative number is no
9396 timeout. timeout milliseconds
9397 for recomputing the result
9398 (default: 0)
9399 maxcount |Number| 0 or negative number is no
9400 limit. max count of matched
9401 text while recomputing the
9402 result. if search exceeded
9403 total count, "total" value
9404 becomes `maxcount + 1`
9405 (default: 99)
9406 pos |List| `[lnum, col, off]` value
9407 when recomputing the result.
9408 this changes "current" result
9409 value. see |cursor()|,
9410 |getpos()|
9411 (default: cursor's position)
9412
9413 Can also be used as a |method|: >
9414 GetSearchOpts()->searchcount()
9415<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009416 Return type: dict<number>
9417
9418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009419searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9420 Search for the declaration of {name}.
9421
9422 With a non-zero {global} argument it works like |gD|, find
9423 first match in the file. Otherwise it works like |gd|, find
9424 first match in the function.
9425
9426 With a non-zero {thisblock} argument matches in a {} block
9427 that ends before the cursor position are ignored. Avoids
9428 finding variable declarations only valid in another scope.
9429
9430 Moves the cursor to the found match.
9431 Returns zero for success, non-zero for failure.
9432 Example: >
9433 if searchdecl('myvar') == 0
9434 echo getline('.')
9435 endif
9436<
9437 Can also be used as a |method|: >
9438 GetName()->searchdecl()
9439<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009440 Return type: |Number|
9441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009442 *searchpair()*
9443searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9444 [, {stopline} [, {timeout}]]]])
9445 Search for the match of a nested start-end pair. This can be
9446 used to find the "endif" that matches an "if", while other
9447 if/endif pairs in between are ignored.
9448 The search starts at the cursor. The default is to search
9449 forward, include 'b' in {flags} to search backward.
9450 If a match is found, the cursor is positioned at it and the
9451 line number is returned. If no match is found 0 or -1 is
9452 returned and the cursor doesn't move. No error message is
9453 given.
9454
9455 {start}, {middle} and {end} are patterns, see |pattern|. They
9456 must not contain \( \) pairs. Use of \%( \) is allowed. When
9457 {middle} is not empty, it is found when searching from either
9458 direction, but only when not in a nested start-end pair. A
9459 typical use is: >
9460 searchpair('\<if\>', '\<else\>', '\<endif\>')
9461< By leaving {middle} empty the "else" is skipped.
9462
9463 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9464 |search()|. Additionally:
9465 'r' Repeat until no more matches found; will find the
9466 outer pair. Implies the 'W' flag.
9467 'm' Return number of matches instead of line number with
9468 the match; will be > 1 when 'r' is used.
9469 Note: it's nearly always a good idea to use the 'W' flag, to
9470 avoid wrapping around the end of the file.
9471
9472 When a match for {start}, {middle} or {end} is found, the
9473 {skip} expression is evaluated with the cursor positioned on
9474 the start of the match. It should return non-zero if this
9475 match is to be skipped. E.g., because it is inside a comment
9476 or a string.
9477 When {skip} is omitted or empty, every match is accepted.
9478 When evaluating {skip} causes an error the search is aborted
9479 and -1 returned.
9480 {skip} can be a string, a lambda, a funcref or a partial.
9481 Anything else makes the function fail.
9482 In a `:def` function when the {skip} argument is a string
9483 constant it is compiled into instructions.
9484
9485 For {stopline} and {timeout} see |search()|.
9486
9487 The value of 'ignorecase' is used. 'magic' is ignored, the
9488 patterns are used like it's on.
9489
9490 The search starts exactly at the cursor. A match with
9491 {start}, {middle} or {end} at the next character, in the
9492 direction of searching, is the first one found. Example: >
9493 if 1
9494 if 2
9495 endif 2
9496 endif 1
9497< When starting at the "if 2", with the cursor on the "i", and
9498 searching forwards, the "endif 2" is found. When starting on
9499 the character just before the "if 2", the "endif 1" will be
9500 found. That's because the "if 2" will be found first, and
9501 then this is considered to be a nested if/endif from "if 2" to
9502 "endif 2".
9503 When searching backwards and {end} is more than one character,
9504 it may be useful to put "\zs" at the end of the pattern, so
9505 that when the cursor is inside a match with the end it finds
9506 the matching start.
9507
9508 Example, to find the "endif" command in a Vim script: >
9509
9510 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9511 \ 'getline(".") =~ "^\\s*\""')
9512
9513< The cursor must be at or after the "if" for which a match is
9514 to be found. Note that single-quote strings are used to avoid
9515 having to double the backslashes. The skip expression only
9516 catches comments at the start of a line, not after a command.
9517 Also, a word "en" or "if" halfway a line is considered a
9518 match.
9519 Another example, to search for the matching "{" of a "}": >
9520
9521 :echo searchpair('{', '', '}', 'bW')
9522
9523< This works when the cursor is at or before the "}" for which a
9524 match is to be found. To reject matches that syntax
9525 highlighting recognized as strings: >
9526
9527 :echo searchpair('{', '', '}', 'bW',
9528 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9529<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009530 Return type: |Number|
9531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009532 *searchpairpos()*
9533searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9534 [, {stopline} [, {timeout}]]]])
9535 Same as |searchpair()|, but returns a |List| with the line and
9536 column position of the match. The first element of the |List|
9537 is the line number and the second element is the byte index of
9538 the column position of the match. If no match is found,
9539 returns [0, 0]. >
9540
9541 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9542<
9543 See |match-parens| for a bigger and more useful example.
9544
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009545 Return type: list<number>
9546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009547 *searchpos()*
9548searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9549 Same as |search()|, but returns a |List| with the line and
9550 column position of the match. The first element of the |List|
9551 is the line number and the second element is the byte index of
9552 the column position of the match. If no match is found,
9553 returns [0, 0].
9554 Example: >
9555 :let [lnum, col] = searchpos('mypattern', 'n')
9556
9557< When the 'p' flag is given then there is an extra item with
9558 the sub-pattern match number |search()-sub-match|. Example: >
9559 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9560< In this example "submatch" is 2 when a lowercase letter is
9561 found |/\l|, 3 when an uppercase letter is found |/\u|.
9562
9563 Can also be used as a |method|: >
9564 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009565<
9566 Return type: list<number>
9567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009568
9569server2client({clientid}, {string}) *server2client()*
9570 Send a reply string to {clientid}. The most recent {clientid}
9571 that sent a string can be retrieved with expand("<client>").
9572 {only available when compiled with the |+clientserver| feature}
9573 Returns zero for success, -1 for failure.
9574 Note:
9575 This id has to be stored before the next command can be
9576 received. I.e. before returning from the received command and
9577 before calling any commands that waits for input.
9578 See also |clientserver|.
9579 Example: >
9580 :echo server2client(expand("<client>"), "HELLO")
9581
9582< Can also be used as a |method|: >
9583 GetClientId()->server2client(string)
9584<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009585 Return type: |Number|
9586
9587
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009588serverlist() *serverlist()*
9589 Return a list of available server names, one per line.
9590 When there are no servers or the information is not available
9591 an empty string is returned. See also |clientserver|.
9592 {only available when compiled with the |+clientserver| feature}
9593 Example: >
9594 :echo serverlist()
9595<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009596 Return type: |String|
9597
9598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009599setbufline({buf}, {lnum}, {text}) *setbufline()*
9600 Set line {lnum} to {text} in buffer {buf}. This works like
9601 |setline()| for the specified buffer.
9602
9603 This function works only for loaded buffers. First call
9604 |bufload()| if needed.
9605
9606 To insert lines use |appendbufline()|.
9607 Any text properties in {lnum} are cleared.
9608
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009609 {text} can be a string to set one line, or a List of strings
9610 to set multiple lines. If the List extends below the last
9611 line then those lines are added. If the List is empty then
9612 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009613
9614 For the use of {buf}, see |bufname()| above.
9615
9616 {lnum} is used like with |setline()|.
9617 Use "$" to refer to the last line in buffer {buf}.
9618 When {lnum} is just below the last line the {text} will be
9619 added below the last line.
9620
9621 When {buf} is not a valid buffer, the buffer is not loaded or
9622 {lnum} is not valid then 1 is returned. In |Vim9| script an
9623 error is given.
9624 On success 0 is returned.
9625
9626 Can also be used as a |method|, the base is passed as the
9627 third argument: >
9628 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009629<
9630 Return type: |Number|
9631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009632
9633setbufvar({buf}, {varname}, {val}) *setbufvar()*
9634 Set option or local variable {varname} in buffer {buf} to
9635 {val}.
9636 This also works for a global or local window option, but it
9637 doesn't work for a global or local window variable.
9638 For a local window option the global value is unchanged.
9639 For the use of {buf}, see |bufname()| above.
9640 The {varname} argument is a string.
9641 Note that the variable name without "b:" must be used.
9642 Examples: >
9643 :call setbufvar(1, "&mod", 1)
9644 :call setbufvar("todo", "myvar", "foobar")
9645< This function is not available in the |sandbox|.
9646
9647 Can also be used as a |method|, the base is passed as the
9648 third argument: >
9649 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009650<
9651 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009652
9653
9654setcellwidths({list}) *setcellwidths()*
9655 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009656 tells Vim how wide characters are when displayed in the
9657 terminal, counted in screen cells. The values override
9658 'ambiwidth'. Example: >
9659 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009660 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009661 \ [0x2194, 0x2199, 2],
9662 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009663
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009664< The {list} argument is a List of Lists with each three
9665 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9666 {low} and {high} can be the same, in which case this refers to
9667 one character. Otherwise it is the range of characters from
9668 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009669 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009670
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009671 {width} must be either 1 or 2, indicating the character width
9672 in screen cells. *E1112*
9673 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009674 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009676 If the new value causes 'fillchars' or 'listchars' to become
9677 invalid it is rejected and an error is given.
9678
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009679 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009680 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009682< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009683 the effect for known emoji characters. Move the cursor
9684 through the text to check if the cell widths of your terminal
9685 match with what Vim knows about each emoji. If it doesn't
9686 look right you need to adjust the {list} argument.
9687
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009688 Return type: |Number|
9689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009690
9691setcharpos({expr}, {list}) *setcharpos()*
9692 Same as |setpos()| but uses the specified column number as the
9693 character index instead of the byte index in the line.
9694
9695 Example:
9696 With the text "여보세요" in line 8: >
9697 call setcharpos('.', [0, 8, 4, 0])
9698< positions the cursor on the fourth character '요'. >
9699 call setpos('.', [0, 8, 4, 0])
9700< positions the cursor on the second character '보'.
9701
9702 Can also be used as a |method|: >
9703 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009704<
9705 Return type: |Number|
9706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009707
9708setcharsearch({dict}) *setcharsearch()*
9709 Set the current character search information to {dict},
9710 which contains one or more of the following entries:
9711
9712 char character which will be used for a subsequent
9713 |,| or |;| command; an empty string clears the
9714 character search
9715 forward direction of character search; 1 for forward,
9716 0 for backward
9717 until type of character search; 1 for a |t| or |T|
9718 character search, 0 for an |f| or |F|
9719 character search
9720
9721 This can be useful to save/restore a user's character search
9722 from a script: >
9723 :let prevsearch = getcharsearch()
9724 :" Perform a command which clobbers user's search
9725 :call setcharsearch(prevsearch)
9726< Also see |getcharsearch()|.
9727
9728 Can also be used as a |method|: >
9729 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009730<
9731 Return type: dict<any>
9732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009733
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009734setcmdline({str} [, {pos}]) *setcmdline()*
9735 Set the command line to {str} and set the cursor position to
9736 {pos}.
9737 If {pos} is omitted, the cursor is positioned after the text.
9738 Returns 0 when successful, 1 when not editing the command
9739 line.
9740
9741 Can also be used as a |method|: >
9742 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009743<
9744 Return type: |Number|
9745
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009747setcmdpos({pos}) *setcmdpos()*
9748 Set the cursor position in the command line to byte position
9749 {pos}. The first position is 1.
9750 Use |getcmdpos()| to obtain the current position.
9751 Only works while editing the command line, thus you must use
9752 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9753 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9754 set after the command line is set to the expression. For
9755 |c_CTRL-R_=| it is set after evaluating the expression but
9756 before inserting the resulting text.
9757 When the number is too big the cursor is put at the end of the
9758 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009759 Returns 0 when successful, 1 when not editing the command
9760 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009761
9762 Can also be used as a |method|: >
9763 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009764<
9765 Return type: |Number|
9766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009767
9768setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9769setcursorcharpos({list})
9770 Same as |cursor()| but uses the specified column number as the
9771 character index instead of the byte index in the line.
9772
9773 Example:
9774 With the text "여보세요" in line 4: >
9775 call setcursorcharpos(4, 3)
9776< positions the cursor on the third character '세'. >
9777 call cursor(4, 3)
9778< positions the cursor on the first character '여'.
9779
9780 Can also be used as a |method|: >
9781 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009782<
9783 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009784
9785
9786setenv({name}, {val}) *setenv()*
9787 Set environment variable {name} to {val}. Example: >
9788 call setenv('HOME', '/home/myhome')
9789
9790< When {val} is |v:null| the environment variable is deleted.
9791 See also |expr-env|.
9792
9793 Can also be used as a |method|, the base is passed as the
9794 second argument: >
9795 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009796<
9797 Return type: |Number|
9798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009799
9800setfperm({fname}, {mode}) *setfperm()* *chmod*
9801 Set the file permissions for {fname} to {mode}.
9802 {mode} must be a string with 9 characters. It is of the form
9803 "rwxrwxrwx", where each group of "rwx" flags represent, in
9804 turn, the permissions of the owner of the file, the group the
9805 file belongs to, and other users. A '-' character means the
9806 permission is off, any other character means on. Multi-byte
9807 characters are not supported.
9808
9809 For example "rw-r-----" means read-write for the user,
9810 readable by the group, not accessible by others. "xx-x-----"
9811 would do the same thing.
9812
9813 Returns non-zero for success, zero for failure.
9814
9815 Can also be used as a |method|: >
9816 GetFilename()->setfperm(mode)
9817<
9818 To read permissions see |getfperm()|.
9819
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009820 Return type: |Number|
9821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009822
9823setline({lnum}, {text}) *setline()*
9824 Set line {lnum} of the current buffer to {text}. To insert
9825 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009826 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009827 Any text properties in {lnum} are cleared. See
9828 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009829
9830 {lnum} is used like with |getline()|.
9831 When {lnum} is just below the last line the {text} will be
9832 added below the last line.
9833 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009834 converted to a String. When {text} is an empty List then
9835 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009836
9837 If this succeeds, FALSE is returned. If this fails (most likely
9838 because {lnum} is invalid) TRUE is returned.
9839 In |Vim9| script an error is given if {lnum} is invalid.
9840
9841 Example: >
9842 :call setline(5, strftime("%c"))
9843
9844< When {text} is a |List| then line {lnum} and following lines
9845 will be set to the items in the list. Example: >
9846 :call setline(5, ['aaa', 'bbb', 'ccc'])
9847< This is equivalent to: >
9848 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9849 : call setline(n, l)
9850 :endfor
9851
9852< Note: The '[ and '] marks are not set.
9853
9854 Can also be used as a |method|, the base is passed as the
9855 second argument: >
9856 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009857<
9858 Return type: |Number|
9859
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009860
9861setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9862 Create or replace or add to the location list for window {nr}.
9863 {nr} can be the window number or the |window-ID|.
9864 When {nr} is zero the current window is used.
9865
9866 For a location list window, the displayed location list is
9867 modified. For an invalid window number {nr}, -1 is returned.
9868 Otherwise, same as |setqflist()|.
9869 Also see |location-list|.
9870
9871 For {action} see |setqflist-action|.
9872
9873 If the optional {what} dictionary argument is supplied, then
9874 only the items listed in {what} are set. Refer to |setqflist()|
9875 for the list of supported keys in {what}.
9876
9877 Can also be used as a |method|, the base is passed as the
9878 second argument: >
9879 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009880<
9881 Return type: |Number|
9882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009883
9884setmatches({list} [, {win}]) *setmatches()*
9885 Restores a list of matches saved by |getmatches()| for the
9886 current window. Returns 0 if successful, otherwise -1. All
9887 current matches are cleared before the list is restored. See
9888 example for |getmatches()|.
9889 If {win} is specified, use the window with this number or
9890 window ID instead of the current window.
9891
9892 Can also be used as a |method|: >
9893 GetMatches()->setmatches()
9894<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009895 Return type: |Number|
9896
9897
9898setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009899 Set the position for String {expr}. Possible values:
9900 . the cursor
9901 'x mark x
9902
9903 {list} must be a |List| with four or five numbers:
9904 [bufnum, lnum, col, off]
9905 [bufnum, lnum, col, off, curswant]
9906
9907 "bufnum" is the buffer number. Zero can be used for the
9908 current buffer. When setting an uppercase mark "bufnum" is
9909 used for the mark position. For other marks it specifies the
9910 buffer to set the mark in. You can use the |bufnr()| function
9911 to turn a file name into a buffer number.
9912 For setting the cursor and the ' mark "bufnum" is ignored,
9913 since these are associated with a window, not a buffer.
9914 Does not change the jumplist.
9915
9916 "lnum" and "col" are the position in the buffer. The first
9917 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9918 smaller than 1 then 1 is used. To use the character count
9919 instead of the byte count, use |setcharpos()|.
9920
9921 The "off" number is only used when 'virtualedit' is set. Then
9922 it is the offset in screen columns from the start of the
9923 character. E.g., a position within a <Tab> or after the last
9924 character.
9925
9926 The "curswant" number is only used when setting the cursor
9927 position. It sets the preferred column for when moving the
9928 cursor vertically. When the "curswant" number is missing the
9929 preferred column is not set. When it is present and setting a
9930 mark position it is not used.
9931
9932 Note that for '< and '> changing the line number may result in
9933 the marks to be effectively be swapped, so that '< is always
9934 before '>.
9935
9936 Returns 0 when the position could be set, -1 otherwise.
9937 An error message is given if {expr} is invalid.
9938
9939 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9940
9941 This does not restore the preferred column for moving
9942 vertically; if you set the cursor position with this, |j| and
9943 |k| motions will jump to previous columns! Use |cursor()| to
9944 also set the preferred column. Also see the "curswant" key in
9945 |winrestview()|.
9946
9947 Can also be used as a |method|: >
9948 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009949<
9950 Return type: |Number|
9951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009952
9953setqflist({list} [, {action} [, {what}]]) *setqflist()*
9954 Create or replace or add to the quickfix list.
9955
9956 If the optional {what} dictionary argument is supplied, then
9957 only the items listed in {what} are set. The first {list}
9958 argument is ignored. See below for the supported items in
9959 {what}.
9960 *setqflist-what*
9961 When {what} is not present, the items in {list} are used. Each
9962 item must be a dictionary. Non-dictionary items in {list} are
9963 ignored. Each dictionary item can contain the following
9964 entries:
9965
9966 bufnr buffer number; must be the number of a valid
9967 buffer
9968 filename name of a file; only used when "bufnr" is not
9969 present or it is invalid.
9970 module name of a module; if given it will be used in
9971 quickfix error window instead of the filename.
9972 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009973 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009974 pattern search pattern used to locate the error
9975 col column number
9976 vcol when non-zero: "col" is visual column
9977 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009978 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009979 nr error number
9980 text description of the error
9981 type single-character error type, 'E', 'W', etc.
9982 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009983 user_data custom data associated with the item, can be
9984 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009985
9986 The "col", "vcol", "nr", "type" and "text" entries are
9987 optional. Either "lnum" or "pattern" entry can be used to
9988 locate a matching error line.
9989 If the "filename" and "bufnr" entries are not present or
9990 neither the "lnum" or "pattern" entries are present, then the
9991 item will not be handled as an error line.
9992 If both "pattern" and "lnum" are present then "pattern" will
9993 be used.
9994 If the "valid" entry is not supplied, then the valid flag is
9995 set when "bufnr" is a valid buffer or "filename" exists.
9996 If you supply an empty {list}, the quickfix list will be
9997 cleared.
9998 Note that the list is not exactly the same as what
9999 |getqflist()| returns.
10000
10001 {action} values: *setqflist-action* *E927*
10002 'a' The items from {list} are added to the existing
10003 quickfix list. If there is no existing list, then a
10004 new list is created.
10005
10006 'r' The items from the current quickfix list are replaced
10007 with the items from {list}. This can also be used to
10008 clear the list: >
10009 :call setqflist([], 'r')
10010<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +020010011 'u' Like 'r', but tries to preserve the current selection
10012 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010013 'f' All the quickfix lists in the quickfix stack are
10014 freed.
10015
10016 If {action} is not present or is set to ' ', then a new list
10017 is created. The new quickfix list is added after the current
10018 quickfix list in the stack and all the following lists are
10019 freed. To add a new quickfix list at the end of the stack,
10020 set "nr" in {what} to "$".
10021
10022 The following items can be specified in dictionary {what}:
10023 context quickfix list context. See |quickfix-context|
10024 efm errorformat to use when parsing text from
10025 "lines". If this is not present, then the
10026 'errorformat' option value is used.
10027 See |quickfix-parse|
10028 id quickfix list identifier |quickfix-ID|
10029 idx index of the current entry in the quickfix
10030 list specified by 'id' or 'nr'. If set to '$',
10031 then the last entry in the list is set as the
10032 current entry. See |quickfix-index|
10033 items list of quickfix entries. Same as the {list}
10034 argument.
10035 lines use 'errorformat' to parse a list of lines and
10036 add the resulting entries to the quickfix list
10037 {nr} or {id}. Only a |List| value is supported.
10038 See |quickfix-parse|
10039 nr list number in the quickfix stack; zero
10040 means the current quickfix list and "$" means
10041 the last quickfix list.
10042 quickfixtextfunc
10043 function to get the text to display in the
10044 quickfix window. The value can be the name of
10045 a function or a funcref or a lambda. Refer to
10046 |quickfix-window-function| for an explanation
10047 of how to write the function and an example.
10048 title quickfix list title text. See |quickfix-title|
10049 Unsupported keys in {what} are ignored.
10050 If the "nr" item is not present, then the current quickfix list
10051 is modified. When creating a new quickfix list, "nr" can be
10052 set to a value one greater than the quickfix stack size.
10053 When modifying a quickfix list, to guarantee that the correct
10054 list is modified, "id" should be used instead of "nr" to
10055 specify the list.
10056
10057 Examples (See also |setqflist-examples|): >
10058 :call setqflist([], 'r', {'title': 'My search'})
10059 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
10060 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
10061<
10062 Returns zero for success, -1 for failure.
10063
10064 This function can be used to create a quickfix list
10065 independent of the 'errorformat' setting. Use a command like
10066 `:cc 1` to jump to the first position.
10067
10068 Can also be used as a |method|, the base is passed as the
10069 second argument: >
10070 GetErrorlist()->setqflist()
10071<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010072 Return type: |Number|
10073
10074
10075setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010076 Set the register {regname} to {value}.
10077 If {regname} is "" or "@", the unnamed register '"' is used.
10078 The {regname} argument is a string. In |Vim9-script|
10079 {regname} must be one character.
10080
10081 {value} may be any value returned by |getreg()| or
10082 |getreginfo()|, including a |List| or |Dict|.
10083 If {options} contains "a" or {regname} is upper case,
10084 then the value is appended.
10085
10086 {options} can also contain a register type specification:
10087 "c" or "v" |characterwise| mode
10088 "l" or "V" |linewise| mode
10089 "b" or "<CTRL-V>" |blockwise-visual| mode
10090 If a number immediately follows "b" or "<CTRL-V>" then this is
10091 used as the width of the selection - if it is not specified
10092 then the width of the block is set to the number of characters
10093 in the longest line (counting a <Tab> as 1 character).
10094
10095 If {options} contains no register settings, then the default
10096 is to use character mode unless {value} ends in a <NL> for
10097 string {value} and linewise mode for list {value}. Blockwise
10098 mode is never selected automatically.
10099 Returns zero for success, non-zero for failure.
10100
10101 *E883*
10102 Note: you may not use |List| containing more than one item to
10103 set search and expression registers. Lists containing no
10104 items act like empty strings.
10105
10106 Examples: >
10107 :call setreg(v:register, @*)
10108 :call setreg('*', @%, 'ac')
10109 :call setreg('a', "1\n2\n3", 'b5')
10110 :call setreg('"', { 'points_to': 'a'})
10111
10112< This example shows using the functions to save and restore a
10113 register: >
10114 :let var_a = getreginfo()
10115 :call setreg('a', var_a)
10116< or: >
10117 :let var_a = getreg('a', 1, 1)
10118 :let var_amode = getregtype('a')
10119 ....
10120 :call setreg('a', var_a, var_amode)
10121< Note: you may not reliably restore register value
10122 without using the third argument to |getreg()| as without it
10123 newlines are represented as newlines AND Nul bytes are
10124 represented as newlines as well, see |NL-used-for-Nul|.
10125
10126 You can also change the type of a register by appending
10127 nothing: >
10128 :call setreg('a', '', 'al')
10129
10130< Can also be used as a |method|, the base is passed as the
10131 second argument: >
10132 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010133<
10134 Return type: |Number|
10135
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010136
10137settabvar({tabnr}, {varname}, {val}) *settabvar()*
10138 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10139 |t:var|
10140 The {varname} argument is a string.
10141 Note that autocommands are blocked, side effects may not be
10142 triggered, e.g. when setting 'filetype'.
10143 Note that the variable name without "t:" must be used.
10144 Tabs are numbered starting with one.
10145 This function is not available in the |sandbox|.
10146
10147 Can also be used as a |method|, the base is passed as the
10148 third argument: >
10149 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010150<
10151 Return type: |Number|
10152
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010153
10154settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10155 Set option or local variable {varname} in window {winnr} to
10156 {val}.
10157 Tabs are numbered starting with one. For the current tabpage
10158 use |setwinvar()|.
10159 {winnr} can be the window number or the |window-ID|.
10160 When {winnr} is zero the current window is used.
10161 Note that autocommands are blocked, side effects may not be
10162 triggered, e.g. when setting 'filetype' or 'syntax'.
10163 This also works for a global or local buffer option, but it
10164 doesn't work for a global or local buffer variable.
10165 For a local buffer option the global value is unchanged.
10166 Note that the variable name without "w:" must be used.
10167 Examples: >
10168 :call settabwinvar(1, 1, "&list", 0)
10169 :call settabwinvar(3, 2, "myvar", "foobar")
10170< This function is not available in the |sandbox|.
10171
10172 Can also be used as a |method|, the base is passed as the
10173 fourth argument: >
10174 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010175<
10176 Return type: |Number|
10177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010178
10179settagstack({nr}, {dict} [, {action}]) *settagstack()*
10180 Modify the tag stack of the window {nr} using {dict}.
10181 {nr} can be the window number or the |window-ID|.
10182
10183 For a list of supported items in {dict}, refer to
10184 |gettagstack()|. "curidx" takes effect before changing the tag
10185 stack.
10186 *E962*
10187 How the tag stack is modified depends on the {action}
10188 argument:
10189 - If {action} is not present or is set to 'r', then the tag
10190 stack is replaced.
10191 - If {action} is set to 'a', then new entries from {dict} are
10192 pushed (added) onto the tag stack.
10193 - If {action} is set to 't', then all the entries from the
10194 current entry in the tag stack or "curidx" in {dict} are
10195 removed and then new entries are pushed to the stack.
10196
10197 The current index is set to one after the length of the tag
10198 stack after the modification.
10199
10200 Returns zero for success, -1 for failure.
10201
10202 Examples (for more examples see |tagstack-examples|):
10203 Empty the tag stack of window 3: >
10204 call settagstack(3, {'items' : []})
10205
10206< Save and restore the tag stack: >
10207 let stack = gettagstack(1003)
10208 " do something else
10209 call settagstack(1003, stack)
10210 unlet stack
10211<
10212 Can also be used as a |method|, the base is passed as the
10213 second argument: >
10214 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010215<
10216 Return type: |Number|
10217
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010218
10219setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10220 Like |settabwinvar()| for the current tab page.
10221 Examples: >
10222 :call setwinvar(1, "&list", 0)
10223 :call setwinvar(2, "myvar", "foobar")
10224
10225< Can also be used as a |method|, the base is passed as the
10226 third argument: >
10227 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010228<
10229 Return type: |Number|
10230
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010231
10232sha256({string}) *sha256()*
10233 Returns a String with 64 hex characters, which is the SHA256
10234 checksum of {string}.
10235
10236 Can also be used as a |method|: >
10237 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010238<
10239 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010240
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010241 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010242
10243shellescape({string} [, {special}]) *shellescape()*
10244 Escape {string} for use as a shell command argument.
10245 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010246 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010247 in single quotes and will double up all internal single
10248 quotes.
10249 On MS-Windows, when 'shellslash' is not set, it will enclose
10250 {string} in double quotes and double all double quotes within
10251 {string}.
10252 Otherwise it will enclose {string} in single quotes and
10253 replace all "'" with "'\''".
10254
Enno5faeb602024-05-15 21:54:19 +020010255 The {special} argument adds additional escaping of keywords
10256 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010257 number or a non-empty String (|non-zero-arg|), then special
10258 items such as "!", "%", "#" and "<cword>" (as listed in
10259 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010260 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010261
10262 The "!" character will be escaped (again with a |non-zero-arg|
10263 {special}) when 'shell' contains "csh" in the tail. That is
10264 because for csh and tcsh "!" is used for history replacement
10265 even when inside single quotes.
10266
10267 With a |non-zero-arg| {special} the <NL> character is also
10268 escaped. When 'shell' containing "csh" in the tail it's
10269 escaped a second time.
10270
10271 The "\" character will be escaped when 'shell' contains "fish"
10272 in the tail. That is because for fish "\" is used as an escape
10273 character inside single quotes.
10274
10275 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010276 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010277< This results in a directory listing for the file under the
10278 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010279 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010280< See also |::S|.
10281
10282 Can also be used as a |method|: >
10283 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010284<
10285 Return type: |String|
10286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010287
10288shiftwidth([{col}]) *shiftwidth()*
10289 Returns the effective value of 'shiftwidth'. This is the
10290 'shiftwidth' value unless it is zero, in which case it is the
10291 'tabstop' value. This function was introduced with patch
10292 7.3.694 in 2012, everybody should have it by now (however it
10293 did not allow for the optional {col} argument until 8.1.542).
10294
10295 When there is one argument {col} this is used as column number
10296 for which to return the 'shiftwidth' value. This matters for the
10297 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10298 no {col} argument is given, column 1 will be assumed.
10299
10300 Can also be used as a |method|: >
10301 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010302<
10303 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010304
10305sign_ functions are documented here: |sign-functions-details|
10306
10307
10308simplify({filename}) *simplify()*
10309 Simplify the file name as much as possible without changing
10310 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10311 Unix) are not resolved. If the first path component in
10312 {filename} designates the current directory, this will be
10313 valid for the result as well. A trailing path separator is
10314 not removed either. On Unix "//path" is unchanged, but
10315 "///path" is simplified to "/path" (this follows the Posix
10316 standard).
10317 Example: >
10318 simplify("./dir/.././/file/") == "./file/"
10319< Note: The combination "dir/.." is only removed if "dir" is
10320 a searchable directory or does not exist. On Unix, it is also
10321 removed when "dir" is a symbolic link within the same
10322 directory. In order to resolve all the involved symbolic
10323 links before simplifying the path name, use |resolve()|.
10324
10325 Can also be used as a |method|: >
10326 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010327<
10328 Return type: |String|
10329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010330
10331sin({expr}) *sin()*
10332 Return the sine of {expr}, measured in radians, as a |Float|.
10333 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010334 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010335 Examples: >
10336 :echo sin(100)
10337< -0.506366 >
10338 :echo sin(-4.01)
10339< 0.763301
10340
10341 Can also be used as a |method|: >
10342 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010343<
10344 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010345
10346
10347sinh({expr}) *sinh()*
10348 Return the hyperbolic sine of {expr} as a |Float| in the range
10349 [-inf, inf].
10350 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010351 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010352 Examples: >
10353 :echo sinh(0.5)
10354< 0.521095 >
10355 :echo sinh(-0.9)
10356< -1.026517
10357
10358 Can also be used as a |method|: >
10359 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010360<
10361 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010362
10363
10364slice({expr}, {start} [, {end}]) *slice()*
10365 Similar to using a |slice| "expr[start : end]", but "end" is
10366 used exclusive. And for a string the indexes are used as
10367 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010368 |vim9script|. Also, composing characters are treated as a
10369 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010370 When {end} is omitted the slice continues to the last item.
10371 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010372 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010373
10374 Can also be used as a |method|: >
10375 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010376<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010377 Return type: list<{type}> or tuple<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010378
10379
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010380sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010381 Sort the items in {list} in-place. Returns {list}.
10382
10383 If you want a list to remain unmodified make a copy first: >
10384 :let sortedlist = sort(copy(mylist))
10385
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010386< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010387 string representation of each item to sort on. Numbers sort
10388 after Strings, |Lists| after Numbers. For sorting text in the
10389 current buffer use |:sort|.
10390
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010391 When {how} is given and it is 'i' then case is ignored.
10392 In legacy script, for backwards compatibility, the value one
10393 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010394
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010395 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010396 locale is used for ordering. Implementation details: strcoll()
10397 is used to compare strings. See |:language| check or set the
10398 collation locale. |v:collate| can also be used to check the
10399 current locale. Sorting using the locale typically ignores
10400 case. Example: >
10401 " ö is sorted similarly to o with English locale.
10402 :language collate en_US.UTF8
10403 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10404< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10405>
10406 " ö is sorted after z with Swedish locale.
10407 :language collate sv_SE.UTF8
10408 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10409< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10410 This does not work properly on Mac.
10411
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010412 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010413 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010414 strtod() function to parse numbers. Strings, Lists, Dicts and
10415 Funcrefs will be considered as being 0). Note that this won't
10416 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010417
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010418 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010419 sorted numerical. This is like 'n' but a string containing
10420 digits will be used as the number they represent.
10421
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010422 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010423 sorted numerical. All values must be a Number or a Float.
10424
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010425 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010426 is called to compare items. The function is invoked with two
10427 items as argument and must return zero if they are equal, 1 or
10428 bigger if the first one sorts after the second one, -1 or
10429 smaller if the first one sorts before the second one.
10430
10431 {dict} is for functions with the "dict" attribute. It will be
10432 used to set the local variable "self". |Dictionary-function|
10433
10434 The sort is stable, items which compare equal (as number or as
10435 string) will keep their relative position. E.g., when sorting
10436 on numbers, text strings will sort next to each other, in the
10437 same order as they were originally.
10438
10439 Can also be used as a |method|: >
10440 mylist->sort()
10441
10442< Also see |uniq()|.
10443
10444 Example: >
10445 func MyCompare(i1, i2)
10446 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10447 endfunc
10448 eval mylist->sort("MyCompare")
10449< A shorter compare version for this specific simple case, which
10450 ignores overflow: >
10451 func MyCompare(i1, i2)
10452 return a:i1 - a:i2
10453 endfunc
10454< For a simple expression you can use a lambda: >
10455 eval mylist->sort({i1, i2 -> i1 - i2})
10456<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010457 Return type: list<{type}>
10458
10459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010460sound_clear() *sound_clear()*
10461 Stop playing all sounds.
10462
10463 On some Linux systems you may need the libcanberra-pulse
10464 package, otherwise sound may not stop.
10465
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010466 Return type: |Number|
10467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010468 {only available when compiled with the |+sound| feature}
10469
10470 *sound_playevent()*
10471sound_playevent({name} [, {callback}])
10472 Play a sound identified by {name}. Which event names are
10473 supported depends on the system. Often the XDG sound names
10474 are used. On Ubuntu they may be found in
10475 /usr/share/sounds/freedesktop/stereo. Example: >
10476 call sound_playevent('bell')
10477< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10478 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10479 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010480 On macOS, {name} refers to files located in
10481 /System/Library/Sounds (e.g. "Tink"). It will also work for
10482 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010483
10484 When {callback} is specified it is invoked when the sound is
10485 finished. The first argument is the sound ID, the second
10486 argument is the status:
10487 0 sound was played to the end
10488 1 sound was interrupted
10489 2 error occurred after sound started
10490 Example: >
10491 func Callback(id, status)
10492 echomsg "sound " .. a:id .. " finished with " .. a:status
10493 endfunc
10494 call sound_playevent('bell', 'Callback')
10495
10496< MS-Windows: {callback} doesn't work for this function.
10497
10498 Returns the sound ID, which can be passed to `sound_stop()`.
10499 Returns zero if the sound could not be played.
10500
10501 Can also be used as a |method|: >
10502 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010503<
10504 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010505
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010506 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010507
10508 *sound_playfile()*
10509sound_playfile({path} [, {callback}])
10510 Like `sound_playevent()` but play sound file {path}. {path}
10511 must be a full path. On Ubuntu you may find files to play
10512 with this command: >
10513 :!find /usr/share/sounds -type f | grep -v index.theme
10514
10515< Can also be used as a |method|: >
10516 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010517<
10518 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010519
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010520 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010521
10522
10523sound_stop({id}) *sound_stop()*
10524 Stop playing sound {id}. {id} must be previously returned by
10525 `sound_playevent()` or `sound_playfile()`.
10526
10527 On some Linux systems you may need the libcanberra-pulse
10528 package, otherwise sound may not stop.
10529
10530 On MS-Windows, this does not work for event sound started by
10531 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10532
10533 Can also be used as a |method|: >
10534 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010535<
10536 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010537
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010538 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010539
10540 *soundfold()*
10541soundfold({word})
10542 Return the sound-folded equivalent of {word}. Uses the first
10543 language in 'spelllang' for the current window that supports
10544 soundfolding. 'spell' must be set. When no sound folding is
10545 possible the {word} is returned unmodified.
10546 This can be used for making spelling suggestions. Note that
10547 the method can be quite slow.
10548
10549 Can also be used as a |method|: >
10550 GetWord()->soundfold()
10551<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010552 Return type: |String|
10553
10554
10555spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010556 Without argument: The result is the badly spelled word under
10557 or after the cursor. The cursor is moved to the start of the
10558 bad word. When no bad word is found in the cursor line the
10559 result is an empty string and the cursor doesn't move.
10560
10561 With argument: The result is the first word in {sentence} that
10562 is badly spelled. If there are no spelling mistakes the
10563 result is an empty string.
10564
10565 The return value is a list with two items:
10566 - The badly spelled word or an empty string.
10567 - The type of the spelling error:
10568 "bad" spelling mistake
10569 "rare" rare word
10570 "local" word only valid in another region
10571 "caps" word should start with Capital
10572 Example: >
10573 echo spellbadword("the quik brown fox")
10574< ['quik', 'bad'] ~
10575
10576 The spelling information for the current window and the value
10577 of 'spelllang' are used.
10578
10579 Can also be used as a |method|: >
10580 GetText()->spellbadword()
10581<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010582 Return type: list<string>
10583
10584
10585spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010586 Return a |List| with spelling suggestions to replace {word}.
10587 When {max} is given up to this number of suggestions are
10588 returned. Otherwise up to 25 suggestions are returned.
10589
10590 When the {capital} argument is given and it's non-zero only
10591 suggestions with a leading capital will be given. Use this
10592 after a match with 'spellcapcheck'.
10593
10594 {word} can be a badly spelled word followed by other text.
10595 This allows for joining two words that were split. The
10596 suggestions also include the following text, thus you can
10597 replace a line.
10598
10599 {word} may also be a good word. Similar words will then be
10600 returned. {word} itself is not included in the suggestions,
10601 although it may appear capitalized.
10602
10603 The spelling information for the current window is used. The
10604 values of 'spelllang' and 'spellsuggest' are used.
10605
10606 Can also be used as a |method|: >
10607 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010608<
10609 Return type: list<string> or list<any>
10610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010611
10612split({string} [, {pattern} [, {keepempty}]]) *split()*
10613 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010614 empty each white space separated sequence of characters
10615 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010616 Otherwise the string is split where {pattern} matches,
10617 removing the matched characters. 'ignorecase' is not used
10618 here, add \c to ignore case. |/\c|
10619 When the first or last item is empty it is omitted, unless the
10620 {keepempty} argument is given and it's non-zero.
10621 Other empty items are kept when {pattern} matches at least one
10622 character or when {keepempty} is non-zero.
10623 Example: >
10624 :let words = split(getline('.'), '\W\+')
10625< To split a string in individual characters: >
10626 :for c in split(mystring, '\zs')
10627< If you want to keep the separator you can also use '\zs' at
10628 the end of the pattern: >
10629 :echo split('abc:def:ghi', ':\zs')
10630< ['abc:', 'def:', 'ghi'] ~
10631 Splitting a table where the first element can be empty: >
10632 :let items = split(line, ':', 1)
10633< The opposite function is |join()|.
10634
10635 Can also be used as a |method|: >
10636 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010637<
10638 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010639
10640sqrt({expr}) *sqrt()*
10641 Return the non-negative square root of Float {expr} as a
10642 |Float|.
10643 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010644 is negative the result is NaN (Not a Number). Returns 0.0 if
10645 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010646 Examples: >
10647 :echo sqrt(100)
10648< 10.0 >
10649 :echo sqrt(-4.01)
10650< nan
10651 "nan" may be different, it depends on system libraries.
10652
10653 Can also be used as a |method|: >
10654 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010655<
10656 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010657
10658
10659srand([{expr}]) *srand()*
10660 Initialize seed used by |rand()|:
10661 - If {expr} is not given, seed values are initialized by
10662 reading from /dev/urandom, if possible, or using time(NULL)
10663 a.k.a. epoch time otherwise; this only has second accuracy.
10664 - If {expr} is given it must be a Number. It is used to
10665 initialize the seed values. This is useful for testing or
10666 when a predictable sequence is intended.
10667
10668 Examples: >
10669 :let seed = srand()
10670 :let seed = srand(userinput)
10671 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010672<
10673 Return type: list<number>
10674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010675
10676state([{what}]) *state()*
10677 Return a string which contains characters indicating the
10678 current state. Mostly useful in callbacks that want to do
10679 work that may not always be safe. Roughly this works like:
10680 - callback uses state() to check if work is safe to do.
10681 Yes: then do it right away.
10682 No: add to work queue and add a |SafeState| and/or
10683 |SafeStateAgain| autocommand (|SafeState| triggers at
10684 toplevel, |SafeStateAgain| triggers after handling
10685 messages and callbacks).
10686 - When SafeState or SafeStateAgain is triggered and executes
10687 your autocommand, check with `state()` if the work can be
10688 done now, and if yes remove it from the queue and execute.
10689 Remove the autocommand if the queue is now empty.
10690 Also see |mode()|.
10691
10692 When {what} is given only characters in this string will be
10693 added. E.g, this checks if the screen has scrolled: >
10694 if state('s') == ''
10695 " screen has not scrolled
10696<
10697 These characters indicate the state, generally indicating that
10698 something is busy:
10699 m halfway a mapping, :normal command, feedkeys() or
10700 stuffed command
10701 o operator pending, e.g. after |d|
10702 a Insert mode autocomplete active
10703 x executing an autocommand
10704 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10705 ch_readraw() when reading json
10706 S not triggering SafeState or SafeStateAgain, e.g. after
10707 |f| or a count
10708 c callback invoked, including timer (repeats for
10709 recursiveness up to "ccc")
10710 s screen has scrolled for messages
10711
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010712 Return type: |String|
10713
10714
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010715str2blob({list} [, {options}]) *str2blob()*
10716 Return a Blob by converting the characters in the List of
10717 strings in {list} into bytes.
10718
10719 A <NL> byte is added to the blob after each list item. A
10720 newline character in the string is translated into a <NUL>
10721 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010722
10723 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010724 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010725
10726 The argument {options} is a |Dict| and supports the following
10727 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010728 encoding Convert the characters using this encoding
10729 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010730 The value is a |String|. See |encoding-names|
10731 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010732
10733 An error is given and an empty blob is returned if the
10734 character encoding fails.
10735
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010736 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010737
10738 See also |blob2str()|
10739
10740 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010741 str2blob(["ab"]) returns 0z6162
10742 str2blob(["«»"]) returns 0zC2ABC2BB
10743 str2blob(["a\nb"]) returns 0z610062
10744 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010745 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010746 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010747<
10748 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010749 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010750<
10751 Return type: |Blob|
10752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010753str2float({string} [, {quoted}]) *str2float()*
10754 Convert String {string} to a Float. This mostly works the
10755 same as when using a floating point number in an expression,
10756 see |floating-point-format|. But it's a bit more permissive.
10757 E.g., "1e40" is accepted, while in an expression you need to
10758 write "1.0e40". The hexadecimal form "0x123" is also
10759 accepted, but not others, like binary or octal.
10760 When {quoted} is present and non-zero then embedded single
10761 quotes before the dot are ignored, thus "1'000.0" is a
10762 thousand.
10763 Text after the number is silently ignored.
10764 The decimal point is always '.', no matter what the locale is
10765 set to. A comma ends the number: "12,345.67" is converted to
10766 12.0. You can strip out thousands separators with
10767 |substitute()|: >
10768 let f = str2float(substitute(text, ',', '', 'g'))
10769<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010770 Returns 0.0 if the conversion fails.
10771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010772 Can also be used as a |method|: >
10773 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010774<
10775 Return type: |Float|
10776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010777
10778str2list({string} [, {utf8}]) *str2list()*
10779 Return a list containing the number values which represent
10780 each character in String {string}. Examples: >
10781 str2list(" ") returns [32]
10782 str2list("ABC") returns [65, 66, 67]
10783< |list2str()| does the opposite.
10784
10785 When {utf8} is omitted or zero, the current 'encoding' is used.
10786 When {utf8} is TRUE, always treat the String as UTF-8
10787 characters. With UTF-8 composing characters are handled
10788 properly: >
10789 str2list("á") returns [97, 769]
10790
10791< Can also be used as a |method|: >
10792 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010793<
10794 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010795
10796
10797str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10798 Convert string {string} to a number.
10799 {base} is the conversion base, it can be 2, 8, 10 or 16.
10800 When {quoted} is present and non-zero then embedded single
10801 quotes are ignored, thus "1'000'000" is a million.
10802
10803 When {base} is omitted base 10 is used. This also means that
10804 a leading zero doesn't cause octal conversion to be used, as
10805 with the default String to Number conversion. Example: >
10806 let nr = str2nr('0123')
10807<
10808 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10809 different base the result will be zero. Similarly, when
10810 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10811 {base} is 2 a leading "0b" or "0B" is ignored.
10812 Text after the number is silently ignored.
10813
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010814 Returns 0 if {string} is empty or on error.
10815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010816 Can also be used as a |method|: >
10817 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010818<
10819 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010820
10821
10822strcharlen({string}) *strcharlen()*
10823 The result is a Number, which is the number of characters
10824 in String {string}. Composing characters are ignored.
10825 |strchars()| can count the number of characters, counting
10826 composing characters separately.
10827
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010828 Returns 0 if {string} is empty or on error.
10829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010830 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10831
10832 Can also be used as a |method|: >
10833 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010834<
10835 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010836
10837
10838strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10839 Like |strpart()| but using character index and length instead
10840 of byte index and length.
10841 When {skipcc} is omitted or zero, composing characters are
10842 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010843 When {skipcc} set to 1, composing characters are treated as a
10844 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010845 When a character index is used where a character does not
10846 exist it is omitted and counted as one character. For
10847 example: >
10848 strcharpart('abc', -1, 2)
10849< results in 'a'.
10850
Bram Moolenaard592deb2022-06-17 15:42:40 +010010851 Returns an empty string on error.
10852
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010853 Can also be used as a |method|: >
10854 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010855<
10856 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010857
10858
10859strchars({string} [, {skipcc}]) *strchars()*
10860 The result is a Number, which is the number of characters
10861 in String {string}.
10862 When {skipcc} is omitted or zero, composing characters are
10863 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010864 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010865 |strcharlen()| always does this.
10866
Bram Moolenaard592deb2022-06-17 15:42:40 +010010867 Returns zero on error.
10868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010869 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10870
10871 {skipcc} is only available after 7.4.755. For backward
10872 compatibility, you can define a wrapper function: >
10873 if has("patch-7.4.755")
10874 function s:strchars(str, skipcc)
10875 return strchars(a:str, a:skipcc)
10876 endfunction
10877 else
10878 function s:strchars(str, skipcc)
10879 if a:skipcc
10880 return strlen(substitute(a:str, ".", "x", "g"))
10881 else
10882 return strchars(a:str)
10883 endif
10884 endfunction
10885 endif
10886<
10887 Can also be used as a |method|: >
10888 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010889<
10890 Return type: |Number|
10891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010892
10893strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10894 The result is a Number, which is the number of display cells
10895 String {string} occupies on the screen when it starts at {col}
10896 (first column is zero). When {col} is omitted zero is used.
10897 Otherwise it is the screen column where to start. This
10898 matters for Tab characters.
10899 The option settings of the current window are used. This
10900 matters for anything that's displayed differently, such as
10901 'tabstop' and 'display'.
10902 When {string} contains characters with East Asian Width Class
10903 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010904 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010905 Also see |strlen()|, |strwidth()| and |strchars()|.
10906
10907 Can also be used as a |method|: >
10908 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010909<
10910 Return type: |Number|
10911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010912
10913strftime({format} [, {time}]) *strftime()*
10914 The result is a String, which is a formatted date and time, as
10915 specified by the {format} string. The given {time} is used,
10916 or the current time if no time is given. The accepted
10917 {format} depends on your system, thus this is not portable!
10918 See the manual page of the C function strftime() for the
10919 format. The maximum length of the result is 80 characters.
10920 See also |localtime()|, |getftime()| and |strptime()|.
10921 The language can be changed with the |:language| command.
10922 Examples: >
10923 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10924 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10925 :echo strftime("%y%m%d %T") 970427 11:53:55
10926 :echo strftime("%H:%M") 11:55
10927 :echo strftime("%c", getftime("file.c"))
10928 Show mod time of file.c.
10929< Not available on all systems. To check use: >
10930 :if exists("*strftime")
10931
10932< Can also be used as a |method|: >
10933 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010934<
10935 Return type: |String|
10936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010937
10938strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010939 Get a Number corresponding to the character at {index} in
10940 {str}. This uses a zero-based character index, not a byte
10941 index. Composing characters are considered separate
10942 characters here. Use |nr2char()| to convert the Number to a
10943 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010944 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010945 Also see |strcharpart()| and |strchars()|.
10946
10947 Can also be used as a |method|: >
10948 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010949<
10950 Return type: |Number|
10951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010952
10953stridx({haystack}, {needle} [, {start}]) *stridx()*
10954 The result is a Number, which gives the byte index in
10955 {haystack} of the first occurrence of the String {needle}.
10956 If {start} is specified, the search starts at index {start}.
10957 This can be used to find a second match: >
10958 :let colon1 = stridx(line, ":")
10959 :let colon2 = stridx(line, ":", colon1 + 1)
10960< The search is done case-sensitive.
10961 For pattern searches use |match()|.
10962 -1 is returned if the {needle} does not occur in {haystack}.
10963 See also |strridx()|.
10964 Examples: >
10965 :echo stridx("An Example", "Example") 3
10966 :echo stridx("Starting point", "Start") 0
10967 :echo stridx("Starting point", "start") -1
10968< *strstr()* *strchr()*
10969 stridx() works similar to the C function strstr(). When used
10970 with a single character it works similar to strchr().
10971
10972 Can also be used as a |method|: >
10973 GetHaystack()->stridx(needle)
10974<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010975 Return type: |Number|
10976
10977
10978string({expr}) *string()*
10979 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010980 Float, String, Blob or a composition of them, then the result
10981 can be parsed back with |eval()|.
10982 {expr} type result ~
10983 String 'string' (single quotes are doubled)
10984 Number 123
10985 Float 123.123456 or 1.123456e8
10986 Funcref function('name')
10987 Blob 0z00112233.44556677.8899
10988 List [item, item]
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010989 Tuple (item, item)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010990 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010991 Class class SomeName
10992 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010993 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010994 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010995
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010996 When a |List|, |Tuple| or |Dictionary| has a recursive
10997 reference it is replaced by "[...]" or "(...)" or "{...}".
10998 Using eval() on the result will then fail.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010999
mityu7f0bba22024-03-29 10:14:41 +010011000 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011001 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010011002 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011004 Can also be used as a |method|: >
11005 mylist->string()
11006
11007< Also see |strtrans()|.
11008
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011009 Return type: |String|
11010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011011
11012strlen({string}) *strlen()*
11013 The result is a Number, which is the length of the String
11014 {string} in bytes.
11015 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011016 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011017 If you want to count the number of multibyte characters use
11018 |strchars()|.
11019 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
11020
11021 Can also be used as a |method|: >
11022 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011023<
11024 Return type: |Number|
11025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011026
11027strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
11028 The result is a String, which is part of {src}, starting from
11029 byte {start}, with the byte length {len}.
11030 When {chars} is present and TRUE then {len} is the number of
11031 characters positions (composing characters are not counted
11032 separately, thus "1" means one base character and any
11033 following composing characters).
11034 To count {start} as characters instead of bytes use
11035 |strcharpart()|.
11036
11037 When bytes are selected which do not exist, this doesn't
11038 result in an error, the bytes are simply omitted.
11039 If {len} is missing, the copy continues from {start} till the
11040 end of the {src}. >
11041 strpart("abcdefg", 3, 2) == "de"
11042 strpart("abcdefg", -2, 4) == "ab"
11043 strpart("abcdefg", 5, 4) == "fg"
11044 strpart("abcdefg", 3) == "defg"
11045
11046< Note: To get the first character, {start} must be 0. For
11047 example, to get the character under the cursor: >
11048 strpart(getline("."), col(".") - 1, 1, v:true)
11049<
Bram Moolenaard592deb2022-06-17 15:42:40 +010011050 Returns an empty string on error.
11051
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011052 Can also be used as a |method|: >
11053 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011054<
11055 Return type: |String|
11056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011057
11058strptime({format}, {timestring}) *strptime()*
11059 The result is a Number, which is a unix timestamp representing
11060 the date and time in {timestring}, which is expected to match
11061 the format specified in {format}.
11062
11063 The accepted {format} depends on your system, thus this is not
11064 portable! See the manual page of the C function strptime()
11065 for the format. Especially avoid "%c". The value of $TZ also
11066 matters.
11067
11068 If the {timestring} cannot be parsed with {format} zero is
11069 returned. If you do not know the format of {timestring} you
11070 can try different {format} values until you get a non-zero
11071 result.
11072
11073 See also |strftime()|.
11074 Examples: >
11075 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11076< 862156163 >
11077 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11078< Sun Apr 27 11:53:55 1997 >
11079 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11080< Sun Apr 27 12:53:55 1997
11081
11082 Can also be used as a |method|: >
11083 GetFormat()->strptime(timestring)
11084<
11085 Not available on all systems. To check use: >
11086 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011087<
11088 Return type: |Number|
11089
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011090
11091strridx({haystack}, {needle} [, {start}]) *strridx()*
11092 The result is a Number, which gives the byte index in
11093 {haystack} of the last occurrence of the String {needle}.
11094 When {start} is specified, matches beyond this index are
11095 ignored. This can be used to find a match before a previous
11096 match: >
11097 :let lastcomma = strridx(line, ",")
11098 :let comma2 = strridx(line, ",", lastcomma - 1)
11099< The search is done case-sensitive.
11100 For pattern searches use |match()|.
11101 -1 is returned if the {needle} does not occur in {haystack}.
11102 If the {needle} is empty the length of {haystack} is returned.
11103 See also |stridx()|. Examples: >
11104 :echo strridx("an angry armadillo", "an") 3
11105< *strrchr()*
11106 When used with a single character it works similar to the C
11107 function strrchr().
11108
11109 Can also be used as a |method|: >
11110 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011111<
11112 Return type: |Number|
11113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011114
11115strtrans({string}) *strtrans()*
11116 The result is a String, which is {string} with all unprintable
11117 characters translated into printable characters |'isprint'|.
11118 Like they are shown in a window. Example: >
11119 echo strtrans(@a)
11120< This displays a newline in register a as "^@" instead of
11121 starting a new line.
11122
Bram Moolenaard592deb2022-06-17 15:42:40 +010011123 Returns an empty string on error.
11124
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011125 Can also be used as a |method|: >
11126 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011127<
11128 Return type: |String|
11129
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011130
Christian Brabandt67672ef2023-04-24 21:09:54 +010011131strutf16len({string} [, {countcc}]) *strutf16len()*
11132 The result is a Number, which is the number of UTF-16 code
11133 units in String {string} (after converting it to UTF-16).
11134
11135 When {countcc} is TRUE, composing characters are counted
11136 separately.
11137 When {countcc} is omitted or FALSE, composing characters are
11138 ignored.
11139
11140 Returns zero on error.
11141
11142 Also see |strlen()| and |strcharlen()|.
11143 Examples: >
11144 echo strutf16len('a') returns 1
11145 echo strutf16len('©') returns 1
11146 echo strutf16len('😊') returns 2
11147 echo strutf16len('ą́') returns 1
11148 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011149<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011150 Can also be used as a |method|: >
11151 GetText()->strutf16len()
11152<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011153 Return type: |Number|
11154
11155
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011156strwidth({string}) *strwidth()*
11157 The result is a Number, which is the number of display cells
11158 String {string} occupies. A Tab character is counted as one
11159 cell, alternatively use |strdisplaywidth()|.
11160 When {string} contains characters with East Asian Width Class
11161 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011162 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011163 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11164
11165 Can also be used as a |method|: >
11166 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011167<
11168 Return type: |Number|
11169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011170
11171submatch({nr} [, {list}]) *submatch()* *E935*
11172 Only for an expression in a |:substitute| command or
11173 substitute() function.
11174 Returns the {nr}'th submatch of the matched text. When {nr}
11175 is 0 the whole matched text is returned.
11176 Note that a NL in the string can stand for a line break of a
11177 multi-line match or a NUL character in the text.
11178 Also see |sub-replace-expression|.
11179
11180 If {list} is present and non-zero then submatch() returns
11181 a list of strings, similar to |getline()| with two arguments.
11182 NL characters in the text represent NUL characters in the
11183 text.
11184 Only returns more than one item for |:substitute|, inside
11185 |substitute()| this list will always contain one or zero
11186 items, since there are no real line breaks.
11187
11188 When substitute() is used recursively only the submatches in
11189 the current (deepest) call can be obtained.
11190
Bram Moolenaard592deb2022-06-17 15:42:40 +010011191 Returns an empty string or list on error.
11192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011193 Examples: >
11194 :s/\d\+/\=submatch(0) + 1/
11195 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11196< This finds the first number in the line and adds one to it.
11197 A line break is included as a newline character.
11198
11199 Can also be used as a |method|: >
11200 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011201<
11202 Return type: |String| or list<string> depending on {list}
11203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011204
11205substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11206 The result is a String, which is a copy of {string}, in which
11207 the first match of {pat} is replaced with {sub}.
11208 When {flags} is "g", all matches of {pat} in {string} are
11209 replaced. Otherwise {flags} should be "".
11210
11211 This works like the ":substitute" command (without any flags).
11212 But the matching with {pat} is always done like the 'magic'
11213 option is set and 'cpoptions' is empty (to make scripts
11214 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11215 if you want to ignore or match case and ignore 'ignorecase'.
11216 'smartcase' is not used. See |string-match| for how {pat} is
11217 used.
11218
11219 A "~" in {sub} is not replaced with the previous {sub}.
11220 Note that some codes in {sub} have a special meaning
11221 |sub-replace-special|. For example, to replace something with
11222 "\n" (two characters), use "\\\\n" or '\\n'.
11223
11224 When {pat} does not match in {string}, {string} is returned
11225 unmodified.
11226
11227 Example: >
11228 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11229< This removes the last component of the 'path' option. >
11230 :echo substitute("testing", ".*", "\\U\\0", "")
11231< results in "TESTING".
11232
11233 When {sub} starts with "\=", the remainder is interpreted as
11234 an expression. See |sub-replace-expression|. Example: >
11235 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011236 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011237
11238< When {sub} is a Funcref that function is called, with one
11239 optional argument. Example: >
11240 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11241< The optional argument is a list which contains the whole
11242 matched string and up to nine submatches, like what
11243 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011244 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011245
Bram Moolenaard592deb2022-06-17 15:42:40 +010011246< Returns an empty string on error.
11247
11248 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011249 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011250<
11251 Return type: |String|
11252
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011253
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011254swapfilelist() *swapfilelist()*
11255 Returns a list of swap file names, like what "vim -r" shows.
11256 See the |-r| command argument. The 'directory' option is used
11257 for the directories to inspect. If you only want to get a
11258 list of swap files in the current directory then temporarily
11259 set 'directory' to a dot: >
11260 let save_dir = &directory
11261 let &directory = '.'
11262 let swapfiles = swapfilelist()
11263 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011264<
11265 Return type: list<string>
11266
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011268swapinfo({fname}) *swapinfo()*
11269 The result is a dictionary, which holds information about the
11270 swapfile {fname}. The available fields are:
11271 version Vim version
11272 user user name
11273 host host name
11274 fname original file name
11275 pid PID of the Vim process that created the swap
11276 file
11277 mtime last modification time in seconds
11278 inode Optional: INODE number of the file
11279 dirty 1 if file was modified, 0 if not
11280 Note that "user" and "host" are truncated to at most 39 bytes.
11281 In case of failure an "error" item is added with the reason:
11282 Cannot open file: file not found or in accessible
11283 Cannot read file: cannot read first block
11284 Not a swap file: does not contain correct block ID
11285 Magic number mismatch: Info in first block is invalid
11286
11287 Can also be used as a |method|: >
11288 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011289<
11290 Return type: dict<any> or dict<string>
11291
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011292
11293swapname({buf}) *swapname()*
11294 The result is the swap file path of the buffer {expr}.
11295 For the use of {buf}, see |bufname()| above.
11296 If buffer {buf} is the current buffer, the result is equal to
11297 |:swapname| (unless there is no swap file).
11298 If buffer {buf} has no swap file, returns an empty string.
11299
11300 Can also be used as a |method|: >
11301 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011302<
11303 Return type: |String|
11304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011305
11306synID({lnum}, {col}, {trans}) *synID()*
11307 The result is a Number, which is the syntax ID at the position
11308 {lnum} and {col} in the current window.
11309 The syntax ID can be used with |synIDattr()| and
11310 |synIDtrans()| to obtain syntax information about text.
11311
11312 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11313 line. 'synmaxcol' applies, in a longer line zero is returned.
11314 Note that when the position is after the last character,
11315 that's where the cursor can be in Insert mode, synID() returns
11316 zero. {lnum} is used like with |getline()|.
11317
11318 When {trans} is |TRUE|, transparent items are reduced to the
11319 item that they reveal. This is useful when wanting to know
11320 the effective color. When {trans} is |FALSE|, the transparent
11321 item is returned. This is useful when wanting to know which
11322 syntax item is effective (e.g. inside parens).
11323 Warning: This function can be very slow. Best speed is
11324 obtained by going through the file in forward direction.
11325
Bram Moolenaard592deb2022-06-17 15:42:40 +010011326 Returns zero on error.
11327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011328 Example (echoes the name of the syntax item under the cursor): >
11329 :echo synIDattr(synID(line("."), col("."), 1), "name")
11330<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011331 Return type: |Number|
11332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011333
11334synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11335 The result is a String, which is the {what} attribute of
11336 syntax ID {synID}. This can be used to obtain information
11337 about a syntax item.
11338 {mode} can be "gui", "cterm" or "term", to get the attributes
11339 for that mode. When {mode} is omitted, or an invalid value is
11340 used, the attributes for the currently active highlighting are
11341 used (GUI, cterm or term).
11342 Use synIDtrans() to follow linked highlight groups.
11343 {what} result
11344 "name" the name of the syntax item
11345 "fg" foreground color (GUI: color name used to set
11346 the color, cterm: color number as a string,
11347 term: empty string)
11348 "bg" background color (as with "fg")
11349 "font" font name (only available in the GUI)
11350 |highlight-font|
11351 "sp" special color for the GUI (as with "fg")
11352 |highlight-guisp|
11353 "ul" underline color for cterm: number as a string
11354 "fg#" like "fg", but for the GUI and the GUI is
11355 running the name in "#RRGGBB" form
11356 "bg#" like "fg#" for "bg"
11357 "sp#" like "fg#" for "sp"
11358 "bold" "1" if bold
11359 "italic" "1" if italic
11360 "reverse" "1" if reverse
11361 "inverse" "1" if inverse (= reverse)
11362 "standout" "1" if standout
11363 "underline" "1" if underlined
11364 "undercurl" "1" if undercurled
11365 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011366 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011367
Bram Moolenaard592deb2022-06-17 15:42:40 +010011368 Returns an empty string on error.
11369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011370 Example (echoes the color of the syntax item under the
11371 cursor): >
11372 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11373<
11374 Can also be used as a |method|: >
11375 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011376<
11377 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011378
11379
11380synIDtrans({synID}) *synIDtrans()*
11381 The result is a Number, which is the translated syntax ID of
11382 {synID}. This is the syntax group ID of what is being used to
11383 highlight the character. Highlight links given with
11384 ":highlight link" are followed.
11385
Bram Moolenaard592deb2022-06-17 15:42:40 +010011386 Returns zero on error.
11387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011388 Can also be used as a |method|: >
11389 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011390<
11391 Return type: |Number|
11392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011393
11394synconcealed({lnum}, {col}) *synconcealed()*
11395 The result is a |List| with currently three items:
11396 1. The first item in the list is 0 if the character at the
11397 position {lnum} and {col} is not part of a concealable
11398 region, 1 if it is. {lnum} is used like with |getline()|.
11399 2. The second item in the list is a string. If the first item
11400 is 1, the second item contains the text which will be
11401 displayed in place of the concealed text, depending on the
11402 current setting of 'conceallevel' and 'listchars'.
11403 3. The third and final item in the list is a number
11404 representing the specific syntax region matched in the
11405 line. When the character is not concealed the value is
11406 zero. This allows detection of the beginning of a new
11407 concealable region if there are two consecutive regions
11408 with the same replacement character. For an example, if
11409 the text is "123456" and both "23" and "45" are concealed
11410 and replaced by the character "X", then:
11411 call returns ~
11412 synconcealed(lnum, 1) [0, '', 0]
11413 synconcealed(lnum, 2) [1, 'X', 1]
11414 synconcealed(lnum, 3) [1, 'X', 1]
11415 synconcealed(lnum, 4) [1, 'X', 2]
11416 synconcealed(lnum, 5) [1, 'X', 2]
11417 synconcealed(lnum, 6) [0, '', 0]
11418
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011419 Note: Doesn't consider |matchadd()| highlighting items,
11420 since syntax and matching highlighting are two different
11421 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011422
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011423 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011425
11426synstack({lnum}, {col}) *synstack()*
11427 Return a |List|, which is the stack of syntax items at the
11428 position {lnum} and {col} in the current window. {lnum} is
11429 used like with |getline()|. Each item in the List is an ID
11430 like what |synID()| returns.
11431 The first item in the List is the outer region, following are
11432 items contained in that one. The last one is what |synID()|
11433 returns, unless not the whole item is highlighted or it is a
11434 transparent item.
11435 This function is useful for debugging a syntax file.
11436 Example that shows the syntax stack under the cursor: >
11437 for id in synstack(line("."), col("."))
11438 echo synIDattr(id, "name")
11439 endfor
11440< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011441 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011442 character in a line and the first column in an empty line are
11443 valid positions.
11444
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011445 Return type: list<number> or list<any>
11446
11447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011448system({expr} [, {input}]) *system()* *E677*
11449 Get the output of the shell command {expr} as a |String|. See
11450 |systemlist()| to get the output as a |List|.
11451
11452 When {input} is given and is a |String| this string is written
11453 to a file and passed as stdin to the command. The string is
11454 written as-is, you need to take care of using the correct line
11455 separators yourself.
11456 If {input} is given and is a |List| it is written to the file
11457 in a way |writefile()| does with {binary} set to "b" (i.e.
11458 with a newline between each list item with newlines inside
11459 list items converted to NULs).
11460 When {input} is given and is a number that is a valid id for
11461 an existing buffer then the content of the buffer is written
11462 to the file line by line, each line terminated by a NL and
11463 NULs characters where the text has a NL.
11464
11465 Pipes are not used, the 'shelltemp' option is not used.
11466
11467 When prepended by |:silent| the terminal will not be set to
11468 cooked mode. This is meant to be used for commands that do
11469 not need the user to type. It avoids stray characters showing
11470 up on the screen which require |CTRL-L| to remove. >
11471 :silent let f = system('ls *.vim')
11472<
11473 Note: Use |shellescape()| or |::S| with |expand()| or
11474 |fnamemodify()| to escape special characters in a command
11475 argument. Newlines in {expr} may cause the command to fail.
11476 The characters in 'shellquote' and 'shellxquote' may also
11477 cause trouble.
11478 This is not to be used for interactive commands.
11479
11480 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011481 :let files = system('ls ' .. shellescape(expand('%:h')))
11482 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011483
11484< To make the result more system-independent, the shell output
11485 is filtered to replace <CR> with <NL> for Macintosh, and
11486 <CR><NL> with <NL> for DOS-like systems.
11487 To avoid the string being truncated at a NUL, all NUL
11488 characters are replaced with SOH (0x01).
11489
11490 The command executed is constructed using several options:
11491 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11492 ({tmp} is an automatically generated file name).
11493 For Unix, braces are put around {expr} to allow for
11494 concatenated commands.
11495
11496 The command will be executed in "cooked" mode, so that a
11497 CTRL-C will interrupt the command (on Unix at least).
11498
11499 The resulting error code can be found in |v:shell_error|.
11500 This function will fail in |restricted-mode|.
11501
11502 Note that any wrong value in the options mentioned above may
11503 make the function fail. It has also been reported to fail
11504 when using a security agent application.
11505 Unlike ":!cmd" there is no automatic check for changed files.
11506 Use |:checktime| to force a check.
11507
11508 Can also be used as a |method|: >
11509 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011510<
11511 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011512
11513
11514systemlist({expr} [, {input}]) *systemlist()*
11515 Same as |system()|, but returns a |List| with lines (parts of
11516 output separated by NL) with NULs transformed into NLs. Output
11517 is the same as |readfile()| will output with {binary} argument
11518 set to "b", except that there is no extra empty item when the
11519 result ends in a NL.
11520 Note that on MS-Windows you may get trailing CR characters.
11521
11522 To see the difference between "echo hello" and "echo -n hello"
11523 use |system()| and |split()|: >
11524 echo system('echo hello')->split('\n', 1)
11525<
11526 Returns an empty string on error.
11527
11528 Can also be used as a |method|: >
11529 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011530<
11531 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011532
11533
11534tabpagebuflist([{arg}]) *tabpagebuflist()*
11535 The result is a |List|, where each item is the number of the
11536 buffer associated with each window in the current tab page.
11537 {arg} specifies the number of the tab page to be used. When
11538 omitted the current tab page is used.
11539 When {arg} is invalid the number zero is returned.
11540 To get a list of all buffers in all tabs use this: >
11541 let buflist = []
11542 for i in range(tabpagenr('$'))
11543 call extend(buflist, tabpagebuflist(i + 1))
11544 endfor
11545< Note that a buffer may appear in more than one window.
11546
11547 Can also be used as a |method|: >
11548 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011549<
11550 Return type: list<number>
11551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011552
11553tabpagenr([{arg}]) *tabpagenr()*
11554 The result is a Number, which is the number of the current
11555 tab page. The first tab page has number 1.
11556
11557 The optional argument {arg} supports the following values:
11558 $ the number of the last tab page (the tab page
11559 count).
11560 # the number of the last accessed tab page
11561 (where |g<Tab>| goes to). if there is no
11562 previous tab page 0 is returned.
11563 The number can be used with the |:tab| command.
11564
Bram Moolenaard592deb2022-06-17 15:42:40 +010011565 Returns zero on error.
11566
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011567 Return type: |Number|
11568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011569
11570tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11571 Like |winnr()| but for tab page {tabarg}.
11572 {tabarg} specifies the number of tab page to be used.
11573 {arg} is used like with |winnr()|:
11574 - When omitted the current window number is returned. This is
11575 the window which will be used when going to this tab page.
11576 - When "$" the number of windows is returned.
11577 - When "#" the previous window nr is returned.
11578 Useful examples: >
11579 tabpagewinnr(1) " current window of tab page 1
11580 tabpagewinnr(4, '$') " number of windows in tab page 4
11581< When {tabarg} is invalid zero is returned.
11582
11583 Can also be used as a |method|: >
11584 GetTabpage()->tabpagewinnr()
11585<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011586 Return type: |Number|
11587
11588
11589tagfiles() *tagfiles()*
11590 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011591 for the current buffer. This is the 'tags' option expanded.
11592
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011593 Return type: list<string> or list<any>
11594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011595
11596taglist({expr} [, {filename}]) *taglist()*
11597 Returns a |List| of tags matching the regular expression {expr}.
11598
11599 If {filename} is passed it is used to prioritize the results
11600 in the same way that |:tselect| does. See |tag-priority|.
11601 {filename} should be the full path of the file.
11602
11603 Each list item is a dictionary with at least the following
11604 entries:
11605 name Name of the tag.
11606 filename Name of the file where the tag is
11607 defined. It is either relative to the
11608 current directory or a full path.
11609 cmd Ex command used to locate the tag in
11610 the file.
11611 kind Type of the tag. The value for this
11612 entry depends on the language specific
11613 kind values. Only available when
11614 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011615 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011616 static A file specific tag. Refer to
11617 |static-tag| for more information.
11618 More entries may be present, depending on the content of the
11619 tags file: access, implementation, inherits and signature.
11620 Refer to the ctags documentation for information about these
11621 fields. For C code the fields "struct", "class" and "enum"
11622 may appear, they give the name of the entity the tag is
11623 contained in.
11624
11625 The ex-command "cmd" can be either an ex search pattern, a
11626 line number or a line number followed by a byte number.
11627
11628 If there are no matching tags, then an empty list is returned.
11629
11630 To get an exact tag match, the anchors '^' and '$' should be
11631 used in {expr}. This also make the function work faster.
11632 Refer to |tag-regexp| for more information about the tag
11633 search regular expression pattern.
11634
11635 Refer to |'tags'| for information about how the tags file is
11636 located by Vim. Refer to |tags-file-format| for the format of
11637 the tags file generated by the different ctags tools.
11638
11639 Can also be used as a |method|: >
11640 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011641<
11642 Return type: list<dict<any>> or list<any>
11643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011644
11645tan({expr}) *tan()*
11646 Return the tangent of {expr}, measured in radians, as a |Float|
11647 in the range [-inf, inf].
11648 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011649 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011650 Examples: >
11651 :echo tan(10)
11652< 0.648361 >
11653 :echo tan(-4.01)
11654< -1.181502
11655
11656 Can also be used as a |method|: >
11657 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011658<
11659 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011660
11661
11662tanh({expr}) *tanh()*
11663 Return the hyperbolic tangent of {expr} as a |Float| in the
11664 range [-1, 1].
11665 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011666 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011667 Examples: >
11668 :echo tanh(0.5)
11669< 0.462117 >
11670 :echo tanh(-1)
11671< -0.761594
11672
11673 Can also be used as a |method|: >
11674 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011675<
11676 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011677
11678
11679tempname() *tempname()* *temp-file-name*
11680 The result is a String, which is the name of a file that
11681 doesn't exist. It can be used for a temporary file. The name
11682 is different for at least 26 consecutive calls. Example: >
11683 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011684 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011685< For Unix, the file will be in a private directory |tempfile|
11686 that is recursively deleted when Vim exits, on other systems
11687 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011688 For MS-Windows forward slashes are used when the 'shellslash'
11689 option is set, or when 'shellcmdflag' starts with '-' and
11690 'shell' does not contain powershell or pwsh.
11691
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011692 Return type: |String|
11693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011694
11695term_ functions are documented here: |terminal-function-details|
11696
11697
11698terminalprops() *terminalprops()*
11699 Returns a |Dictionary| with properties of the terminal that Vim
11700 detected from the response to |t_RV| request. See
11701 |v:termresponse| for the response itself. If |v:termresponse|
11702 is empty most values here will be 'u' for unknown.
11703 cursor_style whether sending |t_RS| works **
11704 cursor_blink_mode whether sending |t_RC| works **
11705 underline_rgb whether |t_8u| works **
11706 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011707 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011708
11709 ** value 'u' for unknown, 'y' for yes, 'n' for no
11710
11711 If the |+termresponse| feature is missing then the result is
11712 an empty dictionary.
11713
11714 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11715 current cursor style.
11716 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11717 request the cursor blink status.
11718 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11719 is not empty, Vim will detect the working of sending |t_RS|
11720 and |t_RC| on startup.
11721
11722 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11723 This avoids sending it to xterm, which would clear the colors.
11724
11725 For "mouse" the value 'u' is unknown
11726
11727 Also see:
11728 - 'ambiwidth' - detected by using |t_u7|.
11729 - |v:termstyleresp| and |v:termblinkresp| for the response to
11730 |t_RS| and |t_RC|.
11731
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011732 Return type: dict<string>
11733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011734
11735test_ functions are documented here: |test-functions-details|
11736
11737
11738 *timer_info()*
11739timer_info([{id}])
11740 Return a list with information about timers.
11741 When {id} is given only information about this timer is
11742 returned. When timer {id} does not exist an empty list is
11743 returned.
11744 When {id} is omitted information about all timers is returned.
11745
11746 For each timer the information is stored in a |Dictionary| with
11747 these items:
11748 "id" the timer ID
11749 "time" time the timer was started with
11750 "remaining" time until the timer fires
11751 "repeat" number of times the timer will still fire;
11752 -1 means forever
11753 "callback" the callback
11754 "paused" 1 if the timer is paused, 0 otherwise
11755
11756 Can also be used as a |method|: >
11757 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011758<
11759 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011760
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011761 {only available when compiled with the |+timers| feature}
11762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011763
11764timer_pause({timer}, {paused}) *timer_pause()*
11765 Pause or unpause a timer. A paused timer does not invoke its
11766 callback when its time expires. Unpausing a timer may cause
11767 the callback to be invoked almost immediately if enough time
11768 has passed.
11769
11770 Pausing a timer is useful to avoid the callback to be called
11771 for a short time.
11772
11773 If {paused} evaluates to a non-zero Number or a non-empty
11774 String, then the timer is paused, otherwise it is unpaused.
11775 See |non-zero-arg|.
11776
11777 Can also be used as a |method|: >
11778 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011779<
11780 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011781
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011782 {only available when compiled with the |+timers| feature}
11783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011784
11785 *timer_start()* *timer* *timers*
11786timer_start({time}, {callback} [, {options}])
11787 Create a timer and return the timer ID.
11788
11789 {time} is the waiting time in milliseconds. This is the
11790 minimum time before invoking the callback. When the system is
11791 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011792 Zero can be used to execute the callback when Vim is back in
11793 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011794
11795 {callback} is the function to call. It can be the name of a
11796 function or a |Funcref|. It is called with one argument, which
11797 is the timer ID. The callback is only invoked when Vim is
11798 waiting for input.
11799 If you want to show a message look at |popup_notification()|
11800 to avoid interfering with what the user is doing.
11801
11802 {options} is a dictionary. Supported entries:
11803 "repeat" Number of times to repeat calling the
11804 callback. -1 means forever. When not present
11805 the callback will be called once.
11806 If the timer causes an error three times in a
11807 row the repeat is cancelled. This avoids that
11808 Vim becomes unusable because of all the error
11809 messages.
11810
Bram Moolenaard592deb2022-06-17 15:42:40 +010011811 Returns -1 on error.
11812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011813 Example: >
11814 func MyHandler(timer)
11815 echo 'Handler called'
11816 endfunc
11817 let timer = timer_start(500, 'MyHandler',
11818 \ {'repeat': 3})
11819< This will invoke MyHandler() three times at 500 msec
11820 intervals.
11821
11822 Can also be used as a |method|: >
11823 GetMsec()->timer_start(callback)
11824
11825< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011826
11827 Return type: |Number|
11828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011829 {only available when compiled with the |+timers| feature}
11830
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011832timer_stop({timer}) *timer_stop()*
11833 Stop a timer. The timer callback will no longer be invoked.
11834 {timer} is an ID returned by timer_start(), thus it must be a
11835 Number. If {timer} does not exist there is no error.
11836
11837 Can also be used as a |method|: >
11838 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011839<
11840 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011841
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011842 {only available when compiled with the |+timers| feature}
11843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011844
11845timer_stopall() *timer_stopall()*
11846 Stop all timers. The timer callbacks will no longer be
11847 invoked. Useful if a timer is misbehaving. If there are no
11848 timers there is no error.
11849
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011850 Return type: |Number|
11851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011852 {only available when compiled with the |+timers| feature}
11853
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011855tolower({expr}) *tolower()*
11856 The result is a copy of the String given, with all uppercase
11857 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011858 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011859
11860 Can also be used as a |method|: >
11861 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011862<
11863 Return type: |String|
11864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011865
11866toupper({expr}) *toupper()*
11867 The result is a copy of the String given, with all lowercase
11868 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011869 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011870
11871 Can also be used as a |method|: >
11872 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011873<
11874 Return type: |String|
11875
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011876
11877tr({src}, {fromstr}, {tostr}) *tr()*
11878 The result is a copy of the {src} string with all characters
11879 which appear in {fromstr} replaced by the character in that
11880 position in the {tostr} string. Thus the first character in
11881 {fromstr} is translated into the first character in {tostr}
11882 and so on. Exactly like the unix "tr" command.
11883 This code also deals with multibyte characters properly.
11884
Bram Moolenaard592deb2022-06-17 15:42:40 +010011885 Returns an empty string on error.
11886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011887 Examples: >
11888 echo tr("hello there", "ht", "HT")
11889< returns "Hello THere" >
11890 echo tr("<blob>", "<>", "{}")
11891< returns "{blob}"
11892
11893 Can also be used as a |method|: >
11894 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011895<
11896 Return type: |String|
11897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011898
11899trim({text} [, {mask} [, {dir}]]) *trim()*
11900 Return {text} as a String where any character in {mask} is
11901 removed from the beginning and/or end of {text}.
11902
Illia Bobyr80799172023-10-17 18:00:50 +020011903 If {mask} is not given, or is an empty string, {mask} is all
11904 characters up to 0x20, which includes Tab, space, NL and CR,
11905 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011906
11907 The optional {dir} argument specifies where to remove the
11908 characters:
11909 0 remove from the beginning and end of {text}
11910 1 remove only at the beginning of {text}
11911 2 remove only at the end of {text}
11912 When omitted both ends are trimmed.
11913
11914 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011915 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011916
11917 Examples: >
11918 echo trim(" some text ")
11919< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011920 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011921< returns "RESERVE_TAIL" >
11922 echo trim("rm<Xrm<>X>rrm", "rm<>")
11923< returns "Xrm<>X" (characters in the middle are not removed) >
11924 echo trim(" vim ", " ", 2)
11925< returns " vim"
11926
11927 Can also be used as a |method|: >
11928 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011929<
11930 Return type: |String|
11931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011932
11933trunc({expr}) *trunc()*
11934 Return the largest integral value with magnitude less than or
11935 equal to {expr} as a |Float| (truncate towards zero).
11936 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011937 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011938 Examples: >
11939 echo trunc(1.456)
11940< 1.0 >
11941 echo trunc(-5.456)
11942< -5.0 >
11943 echo trunc(4.0)
11944< 4.0
11945
11946 Can also be used as a |method|: >
11947 Compute()->trunc()
11948<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011949 Return type: |Float|
11950
11951
Yegappan Lakshmanan1c2f4752025-03-30 15:37:24 +020011952tuple2list({tuple}) *tuple2list()*
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011953 Create a List from a shallow copy of the tuple items.
11954 Examples: >
11955 tuple2list((1, 2, 3)) returns [1, 2, 3]
11956< |list2tuple()| does the opposite.
11957
11958 This function doesn't recursively convert all the Tuple items
11959 in {tuple} to a List. Note that the items are identical
11960 between the list and the tuple, changing an item changes the
11961 contents of both the tuple and the list.
11962
11963 Returns an empty list on error.
11964
11965 Can also be used as a |method|: >
11966 GetTuple()->tuple2list()
11967<
11968 Return type: list<{type}> (depending on the given |Tuple|)
11969
11970
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011971 *type()*
11972type({expr}) The result is a Number representing the type of {expr}.
11973 Instead of using the number directly, it is better to use the
11974 v:t_ variable that has the value:
11975 Number: 0 |v:t_number|
11976 String: 1 |v:t_string|
11977 Funcref: 2 |v:t_func|
11978 List: 3 |v:t_list|
11979 Dictionary: 4 |v:t_dict|
11980 Float: 5 |v:t_float|
11981 Boolean: 6 |v:t_bool| (v:false and v:true)
11982 None: 7 |v:t_none| (v:null and v:none)
11983 Job: 8 |v:t_job|
11984 Channel: 9 |v:t_channel|
11985 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011986 Class: 12 |v:t_class|
11987 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011988 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011989 Enum: 15 |v:t_enum|
11990 EnumValue: 16 |v:t_enumvalue|
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011991 Tuple: 17 |v:t_tuple|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011992 For backward compatibility, this method can be used: >
11993 :if type(myvar) == type(0)
11994 :if type(myvar) == type("")
11995 :if type(myvar) == type(function("tr"))
11996 :if type(myvar) == type([])
11997 :if type(myvar) == type({})
11998 :if type(myvar) == type(0.0)
11999 :if type(myvar) == type(v:false)
12000 :if type(myvar) == type(v:none)
12001< To check if the v:t_ variables exist use this: >
12002 :if exists('v:t_number')
12003
12004< Can also be used as a |method|: >
12005 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012006<
12007 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012008
12009
12010typename({expr}) *typename()*
12011 Return a string representation of the type of {expr}.
12012 Example: >
12013 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000012014< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012015
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012016 Return type: |String|
12017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012018
12019undofile({name}) *undofile()*
12020 Return the name of the undo file that would be used for a file
12021 with name {name} when writing. This uses the 'undodir'
12022 option, finding directories that exist. It does not check if
12023 the undo file exists.
12024 {name} is always expanded to the full path, since that is what
12025 is used internally.
12026 If {name} is empty undofile() returns an empty string, since a
12027 buffer without a file name will not write an undo file.
12028 Useful in combination with |:wundo| and |:rundo|.
12029 When compiled without the |+persistent_undo| option this always
12030 returns an empty string.
12031
12032 Can also be used as a |method|: >
12033 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012034<
12035 Return type: |String|
12036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012037
Devin J. Pohly5fee1112023-04-23 20:26:59 -050012038undotree([{buf}]) *undotree()*
12039 Return the current state of the undo tree for the current
12040 buffer, or for a specific buffer if {buf} is given. The
12041 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012042 "seq_last" The highest undo sequence number used.
12043 "seq_cur" The sequence number of the current position in
12044 the undo tree. This differs from "seq_last"
12045 when some changes were undone.
12046 "time_cur" Time last used for |:earlier| and related
12047 commands. Use |strftime()| to convert to
12048 something readable.
12049 "save_last" Number of the last file write. Zero when no
12050 write yet.
12051 "save_cur" Number of the current position in the undo
12052 tree.
12053 "synced" Non-zero when the last undo block was synced.
12054 This happens when waiting from input from the
12055 user. See |undo-blocks|.
12056 "entries" A list of dictionaries with information about
12057 undo blocks.
12058
12059 The first item in the "entries" list is the oldest undo item.
12060 Each List item is a |Dictionary| with these items:
12061 "seq" Undo sequence number. Same as what appears in
12062 |:undolist|.
12063 "time" Timestamp when the change happened. Use
12064 |strftime()| to convert to something readable.
12065 "newhead" Only appears in the item that is the last one
12066 that was added. This marks the last change
12067 and where further changes will be added.
12068 "curhead" Only appears in the item that is the last one
12069 that was undone. This marks the current
12070 position in the undo tree, the block that will
12071 be used by a redo command. When nothing was
12072 undone after the last change this item will
12073 not appear anywhere.
12074 "save" Only appears on the last block before a file
12075 write. The number is the write count. The
12076 first write has number 1, the last one the
12077 "save_last" mentioned above.
12078 "alt" Alternate entry. This is again a List of undo
12079 blocks. Each item may again have an "alt"
12080 item.
12081
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012082 Return type: dict<any>
12083
12084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012085uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
12086 Remove second and succeeding copies of repeated adjacent
12087 {list} items in-place. Returns {list}. If you want a list
12088 to remain unmodified make a copy first: >
12089 :let newlist = uniq(copy(mylist))
12090< The default compare function uses the string representation of
12091 each item. For the use of {func} and {dict} see |sort()|.
12092
Bram Moolenaard592deb2022-06-17 15:42:40 +010012093 Returns zero if {list} is not a |List|.
12094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012095 Can also be used as a |method|: >
12096 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012097<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012098 Return type: list<{type}>
12099
12100
Christian Brabandt67672ef2023-04-24 21:09:54 +010012101 *utf16idx()*
12102utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012103 Same as |charidx()| but returns the UTF-16 code unit index of
12104 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012105
12106 When {charidx} is present and TRUE, {idx} is used as the
12107 character index in the String {string} instead of as the byte
12108 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012109 An {idx} in the middle of a UTF-8 sequence is rounded
12110 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012111
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012112 Returns -1 if the arguments are invalid or if there are less
12113 than {idx} bytes in {string}. If there are exactly {idx} bytes
12114 the length of the string in UTF-16 code units is returned.
12115
Christian Brabandt67672ef2023-04-24 21:09:54 +010012116 See |byteidx()| and |byteidxcomp()| for getting the byte index
12117 from the UTF-16 index and |charidx()| for getting the
12118 character index from the UTF-16 index.
12119 Refer to |string-offset-encoding| for more information.
12120 Examples: >
12121 echo utf16idx('a😊😊', 3) returns 2
12122 echo utf16idx('a😊😊', 7) returns 4
12123 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12124 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12125 echo utf16idx('aą́c', 6) returns 2
12126 echo utf16idx('aą́c', 6, 1) returns 4
12127 echo utf16idx('a😊😊', 9) returns -1
12128<
12129 Can also be used as a |method|: >
12130 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012131<
12132 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012134
12135values({dict}) *values()*
12136 Return a |List| with all the values of {dict}. The |List| is
12137 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012138 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012139
12140 Can also be used as a |method|: >
12141 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012142<
12143 Return type: list<any>
12144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012145
zeertzjq825cf812023-08-17 22:55:25 +020012146virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012147 The result is a Number, which is the screen column of the file
12148 position given with {expr}. That is, the last screen position
12149 occupied by the character at that position, when the screen
12150 would be of unlimited width. When there is a <Tab> at the
12151 position, the returned Number will be the column at the end of
12152 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12153 set to 8, it returns 8. |conceal| is ignored.
12154 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012155
zeertzjq02f3eba2024-06-12 20:45:24 +020012156 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012157 When {expr} is "$", it means the end of the cursor line, so
12158 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012159
12160 When 'virtualedit' is used {expr} can be [lnum, col, off],
12161 where "off" is the offset in screen columns from the start of
12162 the character. E.g., a position within a <Tab> or after the
12163 last character. When "off" is omitted zero is used. When
12164 Virtual editing is active in the current mode, a position
12165 beyond the end of the line can be returned. Also see
12166 |'virtualedit'|
12167
zeertzjq825cf812023-08-17 22:55:25 +020012168 If {list} is present and non-zero then virtcol() returns a
12169 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012170 character.
12171
zeertzjq825cf812023-08-17 22:55:25 +020012172 With the optional {winid} argument the values are obtained for
12173 that window instead of the current window.
12174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012175 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012177 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012178 " With text "foo^Lbar" and cursor on the "^L":
12179
12180 virtcol(".") " returns 5
12181 virtcol(".", 1) " returns [4, 5]
12182 virtcol("$") " returns 9
12183
12184 " With text " there", with 't at 'h':
12185
12186 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012187<
12188 The first column is 1. 0 or [0, 0] is returned for an error.
12189
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012190 A more advanced example that echoes the maximum length of
12191 all lines: >
12192 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12193
12194< Can also be used as a |method|: >
12195 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012196<
12197 Return type: |Number|
12198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012199
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012200virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12201 The result is a Number, which is the byte index of the
12202 character in window {winid} at buffer line {lnum} and virtual
12203 column {col}.
12204
zeertzjqb583eda2023-10-14 11:32:28 +020012205 If buffer line {lnum} is an empty line, 0 is returned.
12206
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012207 If {col} is greater than the last virtual column in line
12208 {lnum}, then the byte index of the character at the last
12209 virtual column is returned.
12210
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012211 For a multi-byte character, the column number of the first
12212 byte in the character is returned.
12213
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012214 The {winid} argument can be the window number or the
12215 |window-ID|. If this is zero, then the current window is used.
12216
12217 Returns -1 if the window {winid} doesn't exist or the buffer
12218 line {lnum} or virtual column {col} is invalid.
12219
12220 See also |screenpos()|, |virtcol()| and |col()|.
12221
12222 Can also be used as a |method|: >
12223 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012224<
12225 Return type: |Number|
12226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012227
12228visualmode([{expr}]) *visualmode()*
12229 The result is a String, which describes the last Visual mode
12230 used in the current buffer. Initially it returns an empty
12231 string, but once Visual mode has been used, it returns "v",
12232 "V", or "<CTRL-V>" (a single CTRL-V character) for
12233 character-wise, line-wise, or block-wise Visual mode
12234 respectively.
12235 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012236 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012237< This enters the same Visual mode as before. It is also useful
12238 in scripts if you wish to act differently depending on the
12239 Visual mode that was used.
12240 If Visual mode is active, use |mode()| to get the Visual mode
12241 (e.g., in a |:vmap|).
12242 If {expr} is supplied and it evaluates to a non-zero Number or
12243 a non-empty String, then the Visual mode will be cleared and
12244 the old value is returned. See |non-zero-arg|.
12245
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012246 Return type: |String|
12247
12248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012249wildmenumode() *wildmenumode()*
12250 Returns |TRUE| when the wildmenu is active and |FALSE|
12251 otherwise. See 'wildmenu' and 'wildmode'.
12252 This can be used in mappings to handle the 'wildcharm' option
12253 gracefully. (Makes only sense with |mapmode-c| mappings).
12254
12255 For example to make <c-j> work like <down> in wildmode, use: >
12256 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12257<
Milly6c2fc372024-10-16 22:11:17 +020012258 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012259
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012260 Return type: |Number|
12261
12262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012263win_execute({id}, {command} [, {silent}]) *win_execute()*
12264 Like `execute()` but in the context of window {id}.
12265 The window will temporarily be made the current window,
12266 without triggering autocommands or changing directory. When
12267 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012268 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012269 Example: >
12270 call win_execute(winid, 'set syntax=python')
12271< Doing the same with `setwinvar()` would not trigger
12272 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012273 *E994*
12274 Not all commands are allowed in popup windows.
12275 When window {id} does not exist then no error is given and
12276 an empty string is returned.
12277
12278 Can also be used as a |method|, the base is passed as the
12279 second argument: >
12280 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012281<
12282 Return type: |String|
12283
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012284
12285win_findbuf({bufnr}) *win_findbuf()*
12286 Returns a |List| with |window-ID|s for windows that contain
12287 buffer {bufnr}. When there is none the list is empty.
12288
12289 Can also be used as a |method|: >
12290 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012291<
12292 Return type: list<number> or list<any>
12293
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012294
12295win_getid([{win} [, {tab}]]) *win_getid()*
12296 Get the |window-ID| for the specified window.
12297 When {win} is missing use the current window.
12298 With {win} this is the window number. The top window has
12299 number 1.
12300 Without {tab} use the current tab, otherwise the tab with
12301 number {tab}. The first tab has number one.
12302 Return zero if the window cannot be found.
12303
12304 Can also be used as a |method|: >
12305 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012306<
12307 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012308
12309
12310win_gettype([{nr}]) *win_gettype()*
12311 Return the type of the window:
12312 "autocmd" autocommand window. Temporary window
12313 used to execute autocommands.
12314 "command" command-line window |cmdwin|
12315 (empty) normal window
12316 "loclist" |location-list-window|
12317 "popup" popup window |popup|
12318 "preview" preview window |preview-window|
12319 "quickfix" |quickfix-window|
12320 "unknown" window {nr} not found
12321
12322 When {nr} is omitted return the type of the current window.
12323 When {nr} is given return the type of this window by number or
12324 |window-ID|.
12325
12326 Also see the 'buftype' option. When running a terminal in a
12327 popup window then 'buftype' is "terminal" and win_gettype()
12328 returns "popup".
12329
12330 Can also be used as a |method|: >
12331 GetWinid()->win_gettype()
12332<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012333 Return type: |String|
12334
12335
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012336win_gotoid({expr}) *win_gotoid()*
12337 Go to window with ID {expr}. This may also change the current
12338 tabpage.
12339 Return TRUE if successful, FALSE if the window cannot be found.
12340
12341 Can also be used as a |method|: >
12342 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012343<
12344 Return type: |Number|
12345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012346
12347win_id2tabwin({expr}) *win_id2tabwin()*
12348 Return a list with the tab number and window number of window
12349 with ID {expr}: [tabnr, winnr].
12350 Return [0, 0] if the window cannot be found.
12351
12352 Can also be used as a |method|: >
12353 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012354<
12355 Return type: list<number>
12356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012357
12358win_id2win({expr}) *win_id2win()*
12359 Return the window number of window with ID {expr}.
12360 Return 0 if the window cannot be found in the current tabpage.
12361
12362 Can also be used as a |method|: >
12363 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012364<
12365 Return type: |Number|
12366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012367
Daniel Steinbergee630312022-01-10 13:36:34 +000012368win_move_separator({nr}, {offset}) *win_move_separator()*
12369 Move window {nr}'s vertical separator (i.e., the right border)
12370 by {offset} columns, as if being dragged by the mouse. {nr}
12371 can be a window number or |window-ID|. A positive {offset}
12372 moves right and a negative {offset} moves left. Moving a
12373 window's vertical separator will change the width of the
12374 window and the width of other windows adjacent to the vertical
12375 separator. The magnitude of movement may be smaller than
12376 specified (e.g., as a consequence of maintaining
12377 'winminwidth'). Returns TRUE if the window can be found and
12378 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012379 This will fail for the rightmost window and a full-width
12380 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012381 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012382
12383 Can also be used as a |method|: >
12384 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012385<
12386 Return type: |Number|
12387
Daniel Steinbergee630312022-01-10 13:36:34 +000012388
12389win_move_statusline({nr}, {offset}) *win_move_statusline()*
12390 Move window {nr}'s status line (i.e., the bottom border) by
12391 {offset} rows, as if being dragged by the mouse. {nr} can be a
12392 window number or |window-ID|. A positive {offset} moves down
12393 and a negative {offset} moves up. Moving a window's status
12394 line will change the height of the window and the height of
12395 other windows adjacent to the status line. The magnitude of
12396 movement may be smaller than specified (e.g., as a consequence
12397 of maintaining 'winminheight'). Returns TRUE if the window can
12398 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012399 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012400
12401 Can also be used as a |method|: >
12402 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012403<
12404 Return type: |Number|
12405
Daniel Steinbergee630312022-01-10 13:36:34 +000012406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012407win_screenpos({nr}) *win_screenpos()*
12408 Return the screen position of window {nr} as a list with two
12409 numbers: [row, col]. The first window always has position
12410 [1, 1], unless there is a tabline, then it is [2, 1].
12411 {nr} can be the window number or the |window-ID|. Use zero
12412 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012413 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012414
12415 Can also be used as a |method|: >
12416 GetWinid()->win_screenpos()
12417<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012418 Return type: list<number>
12419
12420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012421win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012422 Temporarily switch to window {target}, then move window {nr}
12423 to a new split adjacent to {target}.
12424 Unlike commands such as |:split|, no new windows are created
12425 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012426
12427 Both {nr} and {target} can be window numbers or |window-ID|s.
12428 Both must be in the current tab page.
12429
12430 Returns zero for success, non-zero for failure.
12431
12432 {options} is a |Dictionary| with the following optional entries:
12433 "vertical" When TRUE, the split is created vertically,
12434 like with |:vsplit|.
12435 "rightbelow" When TRUE, the split is made below or to the
12436 right (if vertical). When FALSE, it is done
12437 above or to the left (if vertical). When not
12438 present, the values of 'splitbelow' and
12439 'splitright' are used.
12440
12441 Can also be used as a |method|: >
12442 GetWinid()->win_splitmove(target)
12443<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012444 Return type: |Number|
12445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012446
12447 *winbufnr()*
12448winbufnr({nr}) The result is a Number, which is the number of the buffer
12449 associated with window {nr}. {nr} can be the window number or
12450 the |window-ID|.
12451 When {nr} is zero, the number of the buffer in the current
12452 window is returned.
12453 When window {nr} doesn't exist, -1 is returned.
12454 Example: >
12455 :echo "The file in the current window is " . bufname(winbufnr(0))
12456<
12457 Can also be used as a |method|: >
12458 FindWindow()->winbufnr()->bufname()
12459<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012460 Return type: |Number|
12461
12462
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012463 *wincol()*
12464wincol() The result is a Number, which is the virtual column of the
12465 cursor in the window. This is counting screen cells from the
12466 left side of the window. The leftmost column is one.
12467
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012468 Return type: |Number|
12469
12470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012471 *windowsversion()*
12472windowsversion()
12473 The result is a String. For MS-Windows it indicates the OS
12474 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12475 Windows XP is "5.1". For non-MS-Windows systems the result is
12476 an empty string.
12477
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012478 Return type: |String|
12479
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012480winheight({nr}) *winheight()*
12481 The result is a Number, which is the height of window {nr}.
12482 {nr} can be the window number or the |window-ID|.
12483 When {nr} is zero, the height of the current window is
12484 returned. When window {nr} doesn't exist, -1 is returned.
12485 An existing window always has a height of zero or more.
12486 This excludes any window toolbar line.
12487 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012488 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012489
12490< Can also be used as a |method|: >
12491 GetWinid()->winheight()
12492<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012493 Return type: |Number|
12494
12495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012496winlayout([{tabnr}]) *winlayout()*
12497 The result is a nested List containing the layout of windows
12498 in a tabpage.
12499
12500 Without {tabnr} use the current tabpage, otherwise the tabpage
12501 with number {tabnr}. If the tabpage {tabnr} is not found,
12502 returns an empty list.
12503
12504 For a leaf window, it returns:
12505 ['leaf', {winid}]
12506 For horizontally split windows, which form a column, it
12507 returns:
12508 ['col', [{nested list of windows}]]
12509 For vertically split windows, which form a row, it returns:
12510 ['row', [{nested list of windows}]]
12511
12512 Example: >
12513 " Only one window in the tab page
12514 :echo winlayout()
12515 ['leaf', 1000]
12516 " Two horizontally split windows
12517 :echo winlayout()
12518 ['col', [['leaf', 1000], ['leaf', 1001]]]
12519 " The second tab page, with three horizontally split
12520 " windows, with two vertically split windows in the
12521 " middle window
12522 :echo winlayout(2)
12523 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12524 ['leaf', 1001]]], ['leaf', 1000]]]
12525<
12526 Can also be used as a |method|: >
12527 GetTabnr()->winlayout()
12528<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012529 Return type: list<any>
12530
12531
12532winline() *winline()*
12533 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012534 in the window. This is counting screen lines from the top of
12535 the window. The first line is one.
12536 If the cursor was moved the view on the file will be updated
12537 first, this may cause a scroll.
12538
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012539 Return type: |Number|
12540
12541
12542winnr([{arg}]) *winnr()*
12543 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012544 window. The top window has number 1.
12545 Returns zero for a popup window.
12546
12547 The optional argument {arg} supports the following values:
12548 $ the number of the last window (the window
12549 count).
12550 # the number of the last accessed window (where
12551 |CTRL-W_p| goes to). If there is no previous
12552 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012553 returned. May refer to the current window in
12554 some cases (e.g. when evaluating 'statusline'
12555 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012556 {N}j the number of the Nth window below the
12557 current window (where |CTRL-W_j| goes to).
12558 {N}k the number of the Nth window above the current
12559 window (where |CTRL-W_k| goes to).
12560 {N}h the number of the Nth window left of the
12561 current window (where |CTRL-W_h| goes to).
12562 {N}l the number of the Nth window right of the
12563 current window (where |CTRL-W_l| goes to).
12564 The number can be used with |CTRL-W_w| and ":wincmd w"
12565 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012566 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012567 Also see |tabpagewinnr()| and |win_getid()|.
12568 Examples: >
12569 let window_count = winnr('$')
12570 let prev_window = winnr('#')
12571 let wnum = winnr('3k')
12572
12573< Can also be used as a |method|: >
12574 GetWinval()->winnr()
12575<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012576 Return type: |Number|
12577
12578
12579winrestcmd() *winrestcmd()*
12580 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012581 the current window sizes. Only works properly when no windows
12582 are opened or closed and the current window and tab page is
12583 unchanged.
12584 Example: >
12585 :let cmd = winrestcmd()
12586 :call MessWithWindowSizes()
12587 :exe cmd
12588<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012589 Return type: |String|
12590
12591
12592winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012593 Uses the |Dictionary| returned by |winsaveview()| to restore
12594 the view of the current window.
12595 Note: The {dict} does not have to contain all values, that are
12596 returned by |winsaveview()|. If values are missing, those
12597 settings won't be restored. So you can use: >
12598 :call winrestview({'curswant': 4})
12599<
12600 This will only set the curswant value (the column the cursor
12601 wants to move on vertical movements) of the cursor to column 5
12602 (yes, that is 5), while all other settings will remain the
12603 same. This is useful, if you set the cursor position manually.
12604
12605 If you have changed the values the result is unpredictable.
12606 If the window size changed the result won't be the same.
12607
12608 Can also be used as a |method|: >
12609 GetView()->winrestview()
12610<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012611 Return type: |Number|
12612
12613
12614winsaveview() *winsaveview()*
12615 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012616 the view of the current window. Use |winrestview()| to
12617 restore the view.
12618 This is useful if you have a mapping that jumps around in the
12619 buffer and you want to go back to the original view.
12620 This does not save fold information. Use the 'foldenable'
12621 option to temporarily switch off folding, so that folds are
12622 not opened when moving around. This may have side effects.
12623 The return value includes:
12624 lnum cursor line number
12625 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012626 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012627 returns)
12628 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012629 curswant column for vertical movement (Note:
12630 the first column is zero, as opposed
12631 to what |getcurpos()| returns). After
12632 |$| command it will be a very large
12633 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012634 topline first line in the window
12635 topfill filler lines, only in diff mode
12636 leftcol first column displayed; only used when
12637 'wrap' is off
12638 skipcol columns skipped
12639 Note that no option values are saved.
12640
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012641 Return type: dict<number>
12642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012643
12644winwidth({nr}) *winwidth()*
12645 The result is a Number, which is the width of window {nr}.
12646 {nr} can be the window number or the |window-ID|.
12647 When {nr} is zero, the width of the current window is
12648 returned. When window {nr} doesn't exist, -1 is returned.
12649 An existing window always has a width of zero or more.
12650 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012651 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012652 :if winwidth(0) <= 50
12653 : 50 wincmd |
12654 :endif
12655< For getting the terminal or screen size, see the 'columns'
12656 option.
12657
12658 Can also be used as a |method|: >
12659 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012660<
12661 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012662
12663
12664wordcount() *wordcount()*
12665 The result is a dictionary of byte/chars/word statistics for
12666 the current buffer. This is the same info as provided by
12667 |g_CTRL-G|
12668 The return value includes:
12669 bytes Number of bytes in the buffer
12670 chars Number of chars in the buffer
12671 words Number of words in the buffer
12672 cursor_bytes Number of bytes before cursor position
12673 (not in Visual mode)
12674 cursor_chars Number of chars before cursor position
12675 (not in Visual mode)
12676 cursor_words Number of words before cursor position
12677 (not in Visual mode)
12678 visual_bytes Number of bytes visually selected
12679 (only in Visual mode)
12680 visual_chars Number of chars visually selected
12681 (only in Visual mode)
12682 visual_words Number of words visually selected
12683 (only in Visual mode)
12684
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012685 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012686
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012687
12688writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012689 When {object} is a |List| write it to file {fname}. Each list
12690 item is separated with a NL. Each list item must be a String
12691 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012692 All NL characters are replaced with a NUL character.
12693 Inserting CR characters needs to be done before passing {list}
12694 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012695
12696 When {object} is a |Blob| write the bytes to file {fname}
12697 unmodified, also when binary mode is not specified.
12698
12699 {flags} must be a String. These characters are recognized:
12700
12701 'b' Binary mode is used: There will not be a NL after the
12702 last list item. An empty item at the end does cause the
12703 last line in the file to end in a NL.
12704
12705 'a' Append mode is used, lines are appended to the file: >
12706 :call writefile(["foo"], "event.log", "a")
12707 :call writefile(["bar"], "event.log", "a")
12708<
12709 'D' Delete the file when the current function ends. This
12710 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012711 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012712< Fails when not in a function. Also see |:defer|.
12713
12714 's' fsync() is called after writing the file. This flushes
12715 the file to disk, if possible. This takes more time but
12716 avoids losing the file if the system crashes.
12717
12718 'S' fsync() is not called, even when 'fsync' is set.
12719
12720 When {flags} does not contain "S" or "s" then fsync() is
12721 called if the 'fsync' option is set.
12722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012723 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012725 When the write fails -1 is returned, otherwise 0. There is an
12726 error message if the file can't be created or when writing
12727 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012729 Also see |readfile()|.
12730 To copy a file byte for byte: >
12731 :let fl = readfile("foo", "b")
12732 :call writefile(fl, "foocopy", "b")
12733
12734< Can also be used as a |method|: >
12735 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012736<
12737 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012738
12739
12740xor({expr}, {expr}) *xor()*
12741 Bitwise XOR on the two arguments. The arguments are converted
12742 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012743 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012744 Example: >
12745 :let bits = xor(bits, 0x80)
12746<
12747 Can also be used as a |method|: >
12748 :let bits = bits->xor(0x80)
12749<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012750 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012751
12752==============================================================================
127533. Feature list *feature-list*
12754
12755There are three types of features:
127561. Features that are only supported when they have been enabled when Vim
12757 was compiled |+feature-list|. Example: >
12758 :if has("cindent")
12759< *gui_running*
127602. Features that are only supported when certain conditions have been met.
12761 Example: >
12762 :if has("gui_running")
12763< *has-patch*
127643. Beyond a certain version or at a certain version and including a specific
12765 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12766 later, or it is version 7.4 and patch 248 was included. Example: >
12767 :if has("patch-7.4.248")
12768< Note that it's possible for patch 248 to be omitted even though 249 is
12769 included. Only happens when cherry-picking patches.
12770 Note that this form only works for patch 7.4.237 and later, before that
12771 you need to check for the patch and the v:version. Example (checking
12772 version 6.2.148 or later): >
12773 :if v:version > 602 || (v:version == 602 && has("patch148"))
12774
12775Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12776use: `if exists('+shellslash')`
12777
12778
12779acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012780all_builtin_terms Compiled with all builtin terminals enabled. (always
12781 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012782amiga Amiga version of Vim.
12783arabic Compiled with Arabic support |Arabic|.
12784arp Compiled with ARP support (Amiga).
12785autocmd Compiled with autocommand support. (always true)
12786autochdir Compiled with support for 'autochdir'
12787autoservername Automatically enable |clientserver|
12788balloon_eval Compiled with |balloon-eval| support.
12789balloon_multiline GUI supports multiline balloons.
12790beos BeOS version of Vim.
12791browse Compiled with |:browse| support, and browse() will
12792 work.
12793browsefilter Compiled with support for |browsefilter|.
12794bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012795builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012796byte_offset Compiled with support for 'o' in 'statusline'
12797channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012798cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012799clientserver Compiled with remote invocation support |clientserver|.
12800clipboard Compiled with 'clipboard' support.
12801clipboard_working Compiled with 'clipboard' support and it can be used.
12802cmdline_compl Compiled with |cmdline-completion| support.
12803cmdline_hist Compiled with |cmdline-history| support.
12804cmdline_info Compiled with 'showcmd' and 'ruler' support.
12805comments Compiled with |'comments'| support.
12806compatible Compiled to be very Vi compatible.
12807conpty Platform where |ConPTY| can be used.
12808cryptv Compiled with encryption support |encryption|.
12809cscope Compiled with |cscope| support.
12810cursorbind Compiled with |'cursorbind'| (always true)
12811debug Compiled with "DEBUG" defined.
12812dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012813dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012814dialog_gui Compiled with GUI dialog support.
12815diff Compiled with |vimdiff| and 'diff' support.
12816digraphs Compiled with support for digraphs.
12817directx Compiled with support for DirectX and 'renderoptions'.
12818dnd Compiled with support for the "~ register |quote_~|.
12819drop_file Compiled with |drop_file| support.
12820ebcdic Compiled on a machine with ebcdic character set.
12821emacs_tags Compiled with support for Emacs tags.
12822eval Compiled with expression evaluation support. Always
12823 true, of course!
12824ex_extra |+ex_extra| (always true)
12825extra_search Compiled with support for |'incsearch'| and
12826 |'hlsearch'|
12827farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012828file_in_path Compiled with support for |gf| and |<cfile>| (always
12829 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012830filterpipe When 'shelltemp' is off pipes are used for shell
12831 read/write/filter commands
12832find_in_path Compiled with support for include file searches
12833 |+find_in_path|.
12834float Compiled with support for |Float|.
12835fname_case Case in file names matters (for Amiga and MS-Windows
12836 this is not present).
12837folding Compiled with |folding| support.
12838footer Compiled with GUI footer support. |gui-footer|
12839fork Compiled to use fork()/exec() instead of system().
12840gettext Compiled with message translation |multi-lang|
12841gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012842gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012843gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12844gui_gtk Compiled with GTK+ GUI (any version).
12845gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12846gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12847gui_haiku Compiled with Haiku GUI.
12848gui_mac Compiled with Macintosh GUI.
12849gui_motif Compiled with Motif GUI.
12850gui_photon Compiled with Photon GUI.
12851gui_running Vim is running in the GUI, or it will start soon.
12852gui_win32 Compiled with MS-Windows Win32 GUI.
12853gui_win32s idem, and Win32s system being used (Windows 3.1)
12854haiku Haiku version of Vim.
12855hangul_input Compiled with Hangul input support. |hangul|
12856hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012857hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012858iconv Can use iconv() for conversion.
12859insert_expand Compiled with support for CTRL-X expansion commands in
12860 Insert mode. (always true)
12861job Compiled with support for |channel| and |job|
12862ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012863jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012864keymap Compiled with 'keymap' support.
12865lambda Compiled with |lambda| support.
12866langmap Compiled with 'langmap' support.
12867libcall Compiled with |libcall()| support.
12868linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12869 'breakindent' support.
12870linux Linux version of Vim.
12871lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012872 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012873listcmds Compiled with commands for the buffer list |:files|
12874 and the argument list |arglist|.
12875localmap Compiled with local mappings and abbr. |:map-local|
12876lua Compiled with Lua interface |Lua|.
12877mac Any Macintosh version of Vim cf. osx
12878macunix Synonym for osxdarwin
12879menu Compiled with support for |:menu|.
12880mksession Compiled with support for |:mksession|.
12881modify_fname Compiled with file name modifiers. |filename-modifiers|
12882 (always true)
12883mouse Compiled with support for mouse.
12884mouse_dec Compiled with support for Dec terminal mouse.
12885mouse_gpm Compiled with support for gpm (Linux console mouse)
12886mouse_gpm_enabled GPM mouse is working
12887mouse_netterm Compiled with support for netterm mouse.
12888mouse_pterm Compiled with support for qnx pterm mouse.
12889mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12890mouse_sgr Compiled with support for sgr mouse.
12891mouse_urxvt Compiled with support for urxvt mouse.
12892mouse_xterm Compiled with support for xterm mouse.
12893mouseshape Compiled with support for 'mouseshape'.
12894multi_byte Compiled with support for 'encoding' (always true)
12895multi_byte_encoding 'encoding' is set to a multibyte encoding.
12896multi_byte_ime Compiled with support for IME input method.
12897multi_lang Compiled with support for multiple languages.
12898mzscheme Compiled with MzScheme interface |mzscheme|.
12899nanotime Compiled with sub-second time stamp checks.
12900netbeans_enabled Compiled with support for |netbeans| and connected.
12901netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012902num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012903ole Compiled with OLE automation support for Win32.
12904osx Compiled for macOS cf. mac
12905osxdarwin Compiled for macOS, with |mac-darwin-feature|
12906packages Compiled with |packages| support.
12907path_extra Compiled with up/downwards search in 'path' and 'tags'
12908perl Compiled with Perl interface.
12909persistent_undo Compiled with support for persistent undo history.
12910postscript Compiled with PostScript file printing.
12911printer Compiled with |:hardcopy| support.
12912profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012913prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012914python Python 2.x interface available. |has-python|
12915python_compiled Compiled with Python 2.x interface. |has-python|
12916python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12917python3 Python 3.x interface available. |has-python|
12918python3_compiled Compiled with Python 3.x interface. |has-python|
12919python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012920python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012921pythonx Python 2.x and/or 3.x interface available. |python_x|
12922qnx QNX version of Vim.
12923quickfix Compiled with |quickfix| support.
12924reltime Compiled with |reltime()| support.
12925rightleft Compiled with 'rightleft' support.
12926ruby Compiled with Ruby interface |ruby|.
12927scrollbind Compiled with 'scrollbind' support. (always true)
12928showcmd Compiled with 'showcmd' support.
12929signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012930smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012931sodium Compiled with libsodium for better crypt support
12932sound Compiled with sound support, e.g. `sound_playevent()`
12933spell Compiled with spell checking support |spell|.
12934startuptime Compiled with |--startuptime| support.
12935statusline Compiled with support for 'statusline', 'rulerformat'
12936 and special formats of 'titlestring' and 'iconstring'.
12937sun SunOS version of Vim.
12938sun_workshop Support for Sun |workshop| has been removed.
12939syntax Compiled with syntax highlighting support |syntax|.
12940syntax_items There are active syntax highlighting items for the
12941 current buffer.
12942system Compiled to use system() instead of fork()/exec().
12943tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012944 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012945tag_old_static Support for old static tags was removed, see
12946 |tag-old-static|.
12947tcl Compiled with Tcl interface.
12948termguicolors Compiled with true color in terminal support.
12949terminal Compiled with |terminal| support.
12950terminfo Compiled with terminfo instead of termcap.
12951termresponse Compiled with support for |t_RV| and |v:termresponse|.
12952textobjects Compiled with support for |text-objects|.
12953textprop Compiled with support for |text-properties|.
12954tgetent Compiled with tgetent support, able to use a termcap
12955 or terminfo file.
12956timers Compiled with |timer_start()| support.
12957title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012958 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012959toolbar Compiled with support for |gui-toolbar|.
12960ttyin input is a terminal (tty)
12961ttyout output is a terminal (tty)
12962unix Unix version of Vim. *+unix*
12963unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12964user_commands User-defined commands. (always true)
12965vartabs Compiled with variable tabstop support |'vartabstop'|.
12966vcon Win32: Virtual console support is working, can use
12967 'termguicolors'. Also see |+vtp|.
12968vertsplit Compiled with vertically split windows |:vsplit|.
12969 (always true)
12970vim_starting True while initial source'ing takes place. |startup|
12971 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012972vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012973viminfo Compiled with viminfo support.
12974vimscript-1 Compiled Vim script version 1 support
12975vimscript-2 Compiled Vim script version 2 support
12976vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012977vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012978virtualedit Compiled with 'virtualedit' option. (always true)
12979visual Compiled with Visual mode. (always true)
12980visualextra Compiled with extra Visual mode commands. (always
12981 true) |blockwise-operators|.
12982vms VMS version of Vim.
12983vreplace Compiled with |gR| and |gr| commands. (always true)
12984vtp Compiled for vcon support |+vtp| (check vcon to find
12985 out if it works in the current console).
12986wildignore Compiled with 'wildignore' option.
12987wildmenu Compiled with 'wildmenu' option.
12988win16 old version for MS-Windows 3.1 (always false)
12989win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12990 64 bits)
12991win32unix Win32 version of Vim, using Unix files (Cygwin)
12992win64 Win64 version of Vim (MS-Windows 64 bit).
12993win95 Win32 version for MS-Windows 95/98/ME (always false)
12994winaltkeys Compiled with 'winaltkeys' option.
12995windows Compiled with support for more than one window.
12996 (always true)
12997writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012998xattr Compiled with extended attributes support |xattr|
12999 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013000xfontset Compiled with X fontset support |xfontset|.
13001xim Compiled with X input method support |xim|.
13002xpm Compiled with pixmap support.
13003xpm_w32 Compiled with pixmap support for Win32. (Only for
13004 backward compatibility. Use "xpm" instead.)
13005xsmp Compiled with X session management support.
13006xsmp_interact Compiled with interactive X session management support.
13007xterm_clipboard Compiled with support for xterm clipboard.
13008xterm_save Compiled with support for saving and restoring the
13009 xterm screen.
13010x11 Compiled with X11 support.
13011
13012
13013==============================================================================
130144. Matching a pattern in a String *string-match*
13015
13016This is common between several functions. A regexp pattern as explained at
13017|pattern| is normally used to find a match in the buffer lines. When a
13018pattern is used to find a match in a String, almost everything works in the
13019same way. The difference is that a String is handled like it is one line.
13020When it contains a "\n" character, this is not seen as a line break for the
13021pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
13022>
13023 :let a = "aaaa\nxxxx"
13024 :echo matchstr(a, "..\n..")
13025 aa
13026 xx
13027 :echo matchstr(a, "a.x")
13028 a
13029 x
13030
13031Don't forget that "^" will only match at the first character of the String and
13032"$" at the last character of the string. They don't match after or before a
13033"\n".
13034
13035 vim:tw=78:ts=8:noet:ft=help:norl: