blob: 48bdc43a398673b1595a8725cfd193d30d573066 [file] [log] [blame]
Hirohito Higashi932a5352025-03-23 10:20:20 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Mar 22
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
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000132col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000133complete({startcol}, {matches}) none set Insert mode completion
134complete_add({expr}) Number add completion match
135complete_check() Number check for key typed during completion
136complete_info([{what}]) Dict get current completion information
137confirm({msg} [, {choices} [, {default} [, {type}]]])
138 Number number of choice picked by user
139copy({expr}) any make a shallow copy of {expr}
140cos({expr}) Float cosine of {expr}
141cosh({expr}) Float hyperbolic cosine of {expr}
142count({comp}, {expr} [, {ic} [, {start}]])
143 Number count how many {expr} are in {comp}
144cscope_connection([{num}, {dbpath} [, {prepend}]])
145 Number checks existence of cscope connection
146cursor({lnum}, {col} [, {off}])
147 Number move cursor to {lnum}, {col}, {off}
148cursor({list}) Number move cursor to position in {list}
149debugbreak({pid}) Number interrupt process being debugged
150deepcopy({expr} [, {noref}]) any make a full copy of {expr}
151delete({fname} [, {flags}]) Number delete the file or directory {fname}
152deletebufline({buf}, {first} [, {last}])
153 Number delete lines from buffer {buf}
154did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100155diff({fromlist}, {tolist} [, {options}])
156 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000157diff_filler({lnum}) Number diff filler lines about {lnum}
158diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
159digraph_get({chars}) String get the |digraph| of {chars}
160digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200161digraph_set({chars}, {digraph}) Bool register |digraph|
162digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000163echoraw({expr}) none output {expr} as-is
164empty({expr}) Number |TRUE| if {expr} is empty
165environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100166err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000167escape({string}, {chars}) String escape {chars} in {string} with '\'
168eval({string}) any evaluate {string} into its value
169eventhandler() Number |TRUE| if inside an event handler
170executable({expr}) Number 1 if executable {expr} exists
171execute({command}) String execute {command} and get the output
172exepath({expr}) String full path of the command {expr}
173exists({expr}) Number |TRUE| if {expr} exists
174exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
175exp({expr}) Float exponential of {expr}
176expand({expr} [, {nosuf} [, {list}]])
177 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100178expandcmd({string} [, {options}])
179 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000180extend({expr1}, {expr2} [, {expr3}])
181 List/Dict insert items of {expr2} into {expr1}
182extendnew({expr1}, {expr2} [, {expr3}])
183 List/Dict like |extend()| but creates a new
184 List or Dictionary
185feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200186filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
187 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000188filereadable({file}) Number |TRUE| if {file} is a readable file
189filewritable({file}) Number |TRUE| if {file} is a writable file
190filter({expr1}, {expr2}) List/Dict/Blob/String
191 remove items from {expr1} where
192 {expr2} is 0
193finddir({name} [, {path} [, {count}]])
194 String find directory {name} in {path}
195findfile({name} [, {path} [, {count}]])
196 String find file {name} in {path}
197flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
198flattennew({list} [, {maxdepth}])
199 List flatten a copy of {list}
200float2nr({expr}) Number convert Float {expr} to a Number
201floor({expr}) Float round {expr} down
202fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
203fnameescape({fname}) String escape special characters in {fname}
204fnamemodify({fname}, {mods}) String modify file name
205foldclosed({lnum}) Number first line of fold at {lnum} if closed
206foldclosedend({lnum}) Number last line of fold at {lnum} if closed
207foldlevel({lnum}) Number fold level at {lnum}
208foldtext() String line displayed for closed fold
209foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100210foreach({expr1}, {expr2}) List/Dict/Blob/String
211 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100213fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214funcref({name} [, {arglist}] [, {dict}])
215 Funcref reference to function {name}
216function({name} [, {arglist}] [, {dict}])
217 Funcref named reference to function {name}
218garbagecollect([{atexit}]) none free memory, breaking cyclic references
219get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
220get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
221get({func}, {what}) any get property of funcref/partial {func}
222getbufinfo([{buf}]) List information about buffers
223getbufline({buf}, {lnum} [, {end}])
224 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000225getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getbufvar({buf}, {varname} [, {def}])
227 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100228getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000229getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100231getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232 get one character from the user
233getcharmod() Number modifiers for the last typed character
234getcharpos({expr}) List position of cursor, mark, etc.
235getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100236getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200237getcmdcomplpat() String return the completion pattern of the
238 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100239getcmdcompltype() String return the type of the current
240 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200241getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100244getcmdscreenpos() Number return cursor screen position in
245 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000246getcmdtype() String return current command-line type
247getcmdwintype() String return current command-line window type
248getcompletion({pat}, {type} [, {filtered}])
249 List list of cmdline completion matches
250getcurpos([{winnr}]) List position of the cursor
251getcursorcharpos([{winnr}]) List character position of the cursor
252getcwd([{winnr} [, {tabnr}]]) String get the current working directory
253getenv({name}) String return environment variable
254getfontname([{name}]) String name of font being used
255getfperm({fname}) String file permissions of file {fname}
256getfsize({fname}) Number size in bytes of file {fname}
257getftime({fname}) Number last modification time of file
258getftype({fname}) String description of type of file {fname}
259getimstatus() Number |TRUE| if the IME status is active
260getjumplist([{winnr} [, {tabnr}]])
261 List list of jump list items
262getline({lnum}) String line {lnum} of current buffer
263getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
264getloclist({nr}) List list of location list items
265getloclist({nr}, {what}) Dict get specific location list properties
266getmarklist([{buf}]) List list of global/local marks
267getmatches([{win}]) List list of current matches
268getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000269getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000270getpid() Number process ID of Vim
271getpos({expr}) List position of cursor, mark, etc.
272getqflist() List list of quickfix items
273getqflist({what}) Dict get specific quickfix list properties
274getreg([{regname} [, 1 [, {list}]]])
275 String or List contents of a register
276getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100277getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100278 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200279getregionpos({pos1}, {pos2} [, {opts}])
280 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000281getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100282getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100283getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284gettabinfo([{expr}]) List list of tab pages
285gettabvar({nr}, {varname} [, {def}])
286 any variable {varname} in tab {nr} or {def}
287gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
288 any {name} in {winnr} in tab page {tabnr}
289gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200290gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000292getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwinposx() Number X coord in pixels of the Vim window
294getwinposy() Number Y coord in pixels of the Vim window
295getwinvar({nr}, {varname} [, {def}])
296 any variable {varname} in window {nr}
297glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
298 any expand file wildcards in {expr}
299glob2regpat({expr}) String convert a glob pat into a search pat
300globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
301 String do glob({expr}) for all dirs in {path}
302has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
303has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
304haslocaldir([{winnr} [, {tabnr}]])
305 Number |TRUE| if the window executed |:lcd|
306 or |:tcd|
307hasmapto({what} [, {mode} [, {abbr}]])
308 Number |TRUE| if mapping to {what} exists
309histadd({history}, {item}) Number add an item to a history
310histdel({history} [, {item}]) Number remove an item from a history
311histget({history} [, {index}]) String get the item {index} from a history
312histnr({history}) Number highest index of a history
313hlID({name}) Number syntax ID of highlight group {name}
314hlexists({name}) Number |TRUE| if highlight group {name} exists
315hlget([{name} [, {resolve}]]) List get highlight group attributes
316hlset({list}) Number set highlight group attributes
317hostname() String name of the machine Vim is running on
318iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200319id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320indent({lnum}) Number indent of line {lnum}
321index({object}, {expr} [, {start} [, {ic}]])
322 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100323indexof({object}, {expr} [, {opts}]])
324 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000325input({prompt} [, {text} [, {completion}]])
326 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100327inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000328 String like input() but in a GUI dialog
329inputlist({textlist}) Number let the user pick from a choice list
330inputrestore() Number restore typeahead
331inputsave() Number save and clear typeahead
332inputsecret({prompt} [, {text}]) String like input() but hiding the text
333insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200334instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000335interrupt() none interrupt script execution
336invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100337isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000338isdirectory({directory}) Number |TRUE| if {directory} is a directory
339isinf({expr}) Number determine if {expr} is infinity value
340 (positive or negative)
341islocked({expr}) Number |TRUE| if {expr} is locked
342isnan({expr}) Number |TRUE| if {expr} is NaN
343items({dict}) List key-value pairs in {dict}
344job_getchannel({job}) Channel get the channel handle for {job}
345job_info([{job}]) Dict get information about {job}
346job_setoptions({job}, {options}) none set options for {job}
347job_start({command} [, {options}])
348 Job start a job
349job_status({job}) String get the status of {job}
350job_stop({job} [, {how}]) Number stop {job}
351join({list} [, {sep}]) String join {list} items into one String
352js_decode({string}) any decode JS style JSON
353js_encode({expr}) String encode JS style JSON
354json_decode({string}) any decode JSON
355json_encode({expr}) String encode JSON
356keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100357keytrans({string}) String translate internal keycodes to a form
358 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000359len({expr}) Number the length of {expr}
360libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
361libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
362line({expr} [, {winid}]) Number line nr of cursor, last line or mark
363line2byte({lnum}) Number byte count of line {lnum}
364lispindent({lnum}) Number Lisp indent for line {lnum}
365list2blob({list}) Blob turn {list} of numbers into a Blob
366list2str({list} [, {utf8}]) String turn {list} of numbers into a String
367listener_add({callback} [, {buf}])
368 Number add a callback to listen to changes
369listener_flush([{buf}]) none invoke listener callbacks
370listener_remove({id}) none remove a listener callback
371localtime() Number current time
372log({expr}) Float natural logarithm (base e) of {expr}
373log10({expr}) Float logarithm of Float {expr} to base 10
374luaeval({expr} [, {expr}]) any evaluate |Lua| expression
375map({expr1}, {expr2}) List/Dict/Blob/String
376 change each item in {expr1} to {expr2}
377maparg({name} [, {mode} [, {abbr} [, {dict}]]])
378 String or Dict
379 rhs of mapping {name} in mode {mode}
380mapcheck({name} [, {mode} [, {abbr}]])
381 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100382maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000383mapnew({expr1}, {expr2}) List/Dict/Blob/String
384 like |map()| but creates a new List or
385 Dictionary
386mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
387match({expr}, {pat} [, {start} [, {count}]])
388 Number position where {pat} matches in {expr}
389matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
390 Number highlight {pattern} with {group}
391matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
392 Number highlight positions with {group}
393matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100394matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
395 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000396matchdelete({id} [, {win}]) Number delete match identified by {id}
397matchend({expr}, {pat} [, {start} [, {count}]])
398 Number position where {pat} ends in {expr}
399matchfuzzy({list}, {str} [, {dict}])
400 List fuzzy match {str} in {list}
401matchfuzzypos({list}, {str} [, {dict}])
402 List fuzzy match {str} in {list}
403matchlist({expr}, {pat} [, {start} [, {count}]])
404 List match and submatches of {pat} in {expr}
405matchstr({expr}, {pat} [, {start} [, {count}]])
406 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100407matchstrlist({list}, {pat} [, {dict})
408 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000409matchstrpos({expr}, {pat} [, {start} [, {count}]])
410 List {count}'th match of {pat} in {expr}
411max({expr}) Number maximum value of items in {expr}
412menu_info({name} [, {mode}]) Dict get menu item information
413min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000414mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000415 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200416mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000417mzeval({expr}) any evaluate |MzScheme| expression
418nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100419ngettext({single}, {plural}, {number}[, {domain}])
420 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000421nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
422or({expr}, {expr}) Number bitwise OR
423pathshorten({expr} [, {len}]) String shorten directory names in a path
424perleval({expr}) any evaluate |Perl| expression
425popup_atcursor({what}, {options}) Number create popup window near the cursor
426popup_beval({what}, {options}) Number create popup window for 'ballooneval'
427popup_clear() none close all popup windows
428popup_close({id} [, {result}]) none close popup window {id}
429popup_create({what}, {options}) Number create a popup window
430popup_dialog({what}, {options}) Number create a popup window used as a dialog
431popup_filter_menu({id}, {key}) Number filter for a menu popup window
432popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100433popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000434popup_findinfo() Number get window ID of info popup window
435popup_findpreview() Number get window ID of preview popup window
436popup_getoptions({id}) Dict get options of popup window {id}
437popup_getpos({id}) Dict get position of popup window {id}
438popup_hide({id}) none hide popup menu {id}
439popup_list() List get a list of window IDs of all popups
440popup_locate({row}, {col}) Number get window ID of popup at position
441popup_menu({what}, {options}) Number create a popup window used as a menu
442popup_move({id}, {options}) none set position of popup window {id}
443popup_notification({what}, {options})
444 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200445popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000446popup_setoptions({id}, {options})
447 none set options for popup window {id}
448popup_settext({id}, {text}) none set the text of popup window {id}
449popup_show({id}) none unhide popup window {id}
450pow({x}, {y}) Float {x} to the power of {y}
451prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
452printf({fmt}, {expr1}...) String format text
453prompt_getprompt({buf}) String get prompt text
454prompt_setcallback({buf}, {expr}) none set prompt callback function
455prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
456prompt_setprompt({buf}, {text}) none set prompt text
457prop_add({lnum}, {col}, {props}) none add one text property
458prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
459 none add multiple text properties
460prop_clear({lnum} [, {lnum-end} [, {props}]])
461 none remove all text properties
462prop_find({props} [, {direction}])
463 Dict search for a text property
464prop_list({lnum} [, {props}]) List text properties in {lnum}
465prop_remove({props} [, {lnum} [, {lnum-end}]])
466 Number remove a text property
467prop_type_add({name}, {props}) none define a new property type
468prop_type_change({name}, {props})
469 none change an existing property type
470prop_type_delete({name} [, {props}])
471 none delete a property type
472prop_type_get({name} [, {props}])
473 Dict get property type values
474prop_type_list([{props}]) List get list of property types
475pum_getpos() Dict position and size of pum if visible
476pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100477py3eval({expr} [, {locals}]) any evaluate |python3| expression
478pyeval({expr} [, {locals}]) any evaluate |Python| expression
479pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000480rand([{expr}]) Number get pseudo-random number
481range({expr} [, {max} [, {stride}]])
482 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100483readblob({fname} [, {offset} [, {size}]])
484 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000485readdir({dir} [, {expr} [, {dict}]])
486 List file names in {dir} selected by {expr}
487readdirex({dir} [, {expr} [, {dict}]])
488 List file info in {dir} selected by {expr}
489readfile({fname} [, {type} [, {max}]])
490 List get list of lines from file {fname}
491reduce({object}, {func} [, {initial}])
492 any reduce {object} using {func}
493reg_executing() String get the executing register name
494reg_recording() String get the recording register name
495reltime([{start} [, {end}]]) List get time value
496reltimefloat({time}) Float turn the time value into a Float
497reltimestr({time}) String turn time value into a String
498remote_expr({server}, {string} [, {idvar} [, {timeout}]])
499 String send expression
500remote_foreground({server}) Number bring Vim server to the foreground
501remote_peek({serverid} [, {retvar}])
502 Number check for reply string
503remote_read({serverid} [, {timeout}])
504 String read reply string
505remote_send({server}, {string} [, {idvar}])
506 String send key sequence
507remote_startserver({name}) none become server {name}
508remove({list}, {idx} [, {end}]) any/List
509 remove items {idx}-{end} from {list}
510remove({blob}, {idx} [, {end}]) Number/Blob
511 remove bytes {idx}-{end} from {blob}
512remove({dict}, {key}) any remove entry {key} from {dict}
513rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100514repeat({expr}, {count}) List/Blob/String
515 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000516resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100517reverse({obj}) List/Blob/String
518 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000519round({expr}) Float round off {expr}
520rubyeval({expr}) any evaluate |Ruby| expression
521screenattr({row}, {col}) Number attribute at screen position
522screenchar({row}, {col}) Number character at screen position
523screenchars({row}, {col}) List List of characters at screen position
524screencol() Number current cursor column
525screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
526screenrow() Number current cursor row
527screenstring({row}, {col}) String characters at screen position
528search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
529 Number search for {pattern}
530searchcount([{options}]) Dict get or update search stats
531searchdecl({name} [, {global} [, {thisblock}]])
532 Number search for variable declaration
533searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
534 Number search for other end of start/end pair
535searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
536 List search for other end of start/end pair
537searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
538 List search for {pattern}
539server2client({clientid}, {string})
540 Number send reply string
541serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700542setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000543 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700544 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000545setbufvar({buf}, {varname}, {val})
546 none set {varname} in buffer {buf} to {val}
547setcellwidths({list}) none set character cell width overrides
548setcharpos({expr}, {list}) Number set the {expr} position to {list}
549setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100550setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000551setcmdpos({pos}) Number set cursor position in command-line
552setcursorcharpos({list}) Number move cursor to position in {list}
553setenv({name}, {val}) none set environment variable
554setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
555setline({lnum}, {line}) Number set line {lnum} to {line}
556setloclist({nr}, {list} [, {action}])
557 Number modify location list using {list}
558setloclist({nr}, {list}, {action}, {what})
559 Number modify specific location list props
560setmatches({list} [, {win}]) Number restore a list of matches
561setpos({expr}, {list}) Number set the {expr} position to {list}
562setqflist({list} [, {action}]) Number modify quickfix list using {list}
563setqflist({list}, {action}, {what})
564 Number modify specific quickfix list props
565setreg({n}, {v} [, {opt}]) Number set register to value and type
566settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
567settabwinvar({tabnr}, {winnr}, {varname}, {val})
568 none set {varname} in window {winnr} in tab
569 page {tabnr} to {val}
570settagstack({nr}, {dict} [, {action}])
571 Number modify tag stack using {dict}
572setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
573sha256({string}) String SHA256 checksum of {string}
574shellescape({string} [, {special}])
575 String escape {string} for use as shell
576 command argument
577shiftwidth([{col}]) Number effective value of 'shiftwidth'
578sign_define({name} [, {dict}]) Number define or update a sign
579sign_define({list}) List define or update a list of signs
580sign_getdefined([{name}]) List get a list of defined signs
581sign_getplaced([{buf} [, {dict}]])
582 List get a list of placed signs
583sign_jump({id}, {group}, {buf})
584 Number jump to a sign
585sign_place({id}, {group}, {name}, {buf} [, {dict}])
586 Number place a sign
587sign_placelist({list}) List place a list of signs
588sign_undefine([{name}]) Number undefine a sign
589sign_undefine({list}) List undefine a list of signs
590sign_unplace({group} [, {dict}])
591 Number unplace a sign
592sign_unplacelist({list}) List unplace a list of signs
593simplify({filename}) String simplify filename as much as possible
594sin({expr}) Float sine of {expr}
595sinh({expr}) Float hyperbolic sine of {expr}
596slice({expr}, {start} [, {end}]) String, List or Blob
597 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000598sort({list} [, {how} [, {dict}]])
599 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000600sound_clear() none stop playing all sounds
601sound_playevent({name} [, {callback}])
602 Number play an event sound
603sound_playfile({path} [, {callback}])
604 Number play sound file {path}
605sound_stop({id}) none stop playing sound {id}
606soundfold({word}) String sound-fold {word}
607spellbadword() String badly spelled word at cursor
608spellsuggest({word} [, {max} [, {capital}]])
609 List spelling suggestions
610split({expr} [, {pat} [, {keepempty}]])
611 List make |List| from {pat} separated {expr}
612sqrt({expr}) Float square root of {expr}
613srand([{expr}]) List get seed for |rand()|
614state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100615str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000616str2float({expr} [, {quoted}]) Float convert String to Float
617str2list({expr} [, {utf8}]) List convert each character of {expr} to
618 ASCII/UTF-8 value
619str2nr({expr} [, {base} [, {quoted}]])
620 Number convert String to Number
621strcharlen({expr}) Number character length of the String {expr}
622strcharpart({str}, {start} [, {len} [, {skipcc}]])
623 String {len} characters of {str} at
624 character {start}
625strchars({expr} [, {skipcc}]) Number character count of the String {expr}
626strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
627strftime({format} [, {time}]) String format time with a specified format
628strgetchar({str}, {index}) Number get char {index} from {str}
629stridx({haystack}, {needle} [, {start}])
630 Number index of {needle} in {haystack}
631string({expr}) String String representation of {expr} value
632strlen({expr}) Number length of the String {expr}
633strpart({str}, {start} [, {len} [, {chars}]])
634 String {len} bytes/chars of {str} at
635 byte {start}
636strptime({format}, {timestring})
637 Number Convert {timestring} to unix timestamp
638strridx({haystack}, {needle} [, {start}])
639 Number last index of {needle} in {haystack}
640strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100641strutf16len({string} [, {countcc}])
642 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000643strwidth({expr}) Number display cell length of the String {expr}
644submatch({nr} [, {list}]) String or List
645 specific match in ":s" or substitute()
646substitute({expr}, {pat}, {sub}, {flags})
647 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000648swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000649swapinfo({fname}) Dict information about swap file {fname}
650swapname({buf}) String swap file of buffer {buf}
651synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
652synIDattr({synID}, {what} [, {mode}])
653 String attribute {what} of syntax ID {synID}
654synIDtrans({synID}) Number translated syntax ID of {synID}
655synconcealed({lnum}, {col}) List info about concealing
656synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
657system({expr} [, {input}]) String output of shell command/filter {expr}
658systemlist({expr} [, {input}]) List output of shell command/filter {expr}
659tabpagebuflist([{arg}]) List list of buffer numbers in tab page
660tabpagenr([{arg}]) Number number of current or last tab page
661tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
662tagfiles() List tags files used
663taglist({expr} [, {filename}]) List list of tags matching {expr}
664tan({expr}) Float tangent of {expr}
665tanh({expr}) Float hyperbolic tangent of {expr}
666tempname() String name for a temporary file
667term_dumpdiff({filename}, {filename} [, {options}])
668 Number display difference between two dumps
669term_dumpload({filename} [, {options}])
670 Number displaying a screen dump
671term_dumpwrite({buf}, {filename} [, {options}])
672 none dump terminal window contents
673term_getaltscreen({buf}) Number get the alternate screen flag
674term_getansicolors({buf}) List get ANSI palette in GUI color mode
675term_getattr({attr}, {what}) Number get the value of attribute {what}
676term_getcursor({buf}) List get the cursor position of a terminal
677term_getjob({buf}) Job get the job associated with a terminal
678term_getline({buf}, {row}) String get a line of text from a terminal
679term_getscrolled({buf}) Number get the scroll count of a terminal
680term_getsize({buf}) List get the size of a terminal
681term_getstatus({buf}) String get the status of a terminal
682term_gettitle({buf}) String get the title of a terminal
683term_gettty({buf}, [{input}]) String get the tty name of a terminal
684term_list() List get the list of terminal buffers
685term_scrape({buf}, {row}) List get row of a terminal screen
686term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
687term_setansicolors({buf}, {colors})
688 none set ANSI palette in GUI color mode
689term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
690term_setkill({buf}, {how}) none set signal to stop job in terminal
691term_setrestore({buf}, {command}) none set command to restore terminal
692term_setsize({buf}, {rows}, {cols})
693 none set the size of a terminal
694term_start({cmd} [, {options}]) Number open a terminal window and run a job
695term_wait({buf} [, {time}]) Number wait for screen to be updated
696terminalprops() Dict properties of the terminal
697test_alloc_fail({id}, {countdown}, {repeat})
698 none make memory allocation fail
699test_autochdir() none enable 'autochdir' during startup
700test_feedinput({string}) none add key sequence to input buffer
701test_garbagecollect_now() none free memory right now for testing
702test_garbagecollect_soon() none free memory soon for testing
703test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000704test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000705test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000706test_mswin_event({event}, {args})
707 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_null_blob() Blob null value for testing
709test_null_channel() Channel null value for testing
710test_null_dict() Dict null value for testing
711test_null_function() Funcref null value for testing
712test_null_job() Job null value for testing
713test_null_list() List null value for testing
714test_null_partial() Funcref null value for testing
715test_null_string() String null value for testing
716test_option_not_set({name}) none reset flag indicating option was set
717test_override({expr}, {val}) none test with Vim internal overrides
718test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000719test_setmouse({row}, {col}) none set the mouse position for testing
720test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200721test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000722test_unknown() any unknown value for testing
723test_void() any void value for testing
724timer_info([{id}]) List information about timers
725timer_pause({id}, {pause}) none pause or unpause a timer
726timer_start({time}, {callback} [, {options}])
727 Number create a timer
728timer_stop({timer}) none stop a timer
729timer_stopall() none stop all timers
730tolower({expr}) String the String {expr} switched to lowercase
731toupper({expr}) String the String {expr} switched to uppercase
732tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
733 to chars in {tostr}
734trim({text} [, {mask} [, {dir}]])
735 String trim characters in {mask} from {text}
736trunc({expr}) Float truncate Float {expr}
737type({expr}) Number type of value {expr}
738typename({expr}) String representation of the type of {expr}
739undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500740undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000741uniq({list} [, {func} [, {dict}]])
742 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100743utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
744 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000745values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200746virtcol({expr} [, {list} [, {winid}])
747 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100748 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100749virtcol2col({winid}, {lnum}, {col})
750 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200751visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000752wildmenumode() Number whether 'wildmenu' mode is active
753win_execute({id}, {command} [, {silent}])
754 String execute {command} in window {id}
755win_findbuf({bufnr}) List find windows containing {bufnr}
756win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
757win_gettype([{nr}]) String type of window {nr}
758win_gotoid({expr}) Number go to window with ID {expr}
759win_id2tabwin({expr}) List get tab and window nr from window ID
760win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000761win_move_separator({nr}) Number move window vertical separator
762win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000763win_screenpos({nr}) List get screen position of window {nr}
764win_splitmove({nr}, {target} [, {options}])
765 Number move window {nr} to split of {target}
766winbufnr({nr}) Number buffer number of window {nr}
767wincol() Number window column of the cursor
768windowsversion() String MS-Windows OS version
769winheight({nr}) Number height of window {nr}
770winlayout([{tabnr}]) List layout of windows in tab {tabnr}
771winline() Number window line of the cursor
772winnr([{expr}]) Number number of current window
773winrestcmd() String returns command to restore window sizes
774winrestview({dict}) none restore view of current window
775winsaveview() Dict save view of current window
776winwidth({nr}) Number width of window {nr}
777wordcount() Dict get byte/char/word statistics
778writefile({object}, {fname} [, {flags}])
779 Number write |Blob| or |List| of lines to file
780xor({expr}, {expr}) Number bitwise XOR
781
782==============================================================================
7832. Details *builtin-function-details*
784
785Not all functions are here, some have been moved to a help file covering the
786specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200787Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000788
789abs({expr}) *abs()*
790 Return the absolute value of {expr}. When {expr} evaluates to
791 a |Float| abs() returns a |Float|. When {expr} can be
792 converted to a |Number| abs() returns a |Number|. Otherwise
793 abs() gives an error message and returns -1.
794 Examples: >
795 echo abs(1.456)
796< 1.456 >
797 echo abs(-5.456)
798< 5.456 >
799 echo abs(-4)
800< 4
801
802 Can also be used as a |method|: >
803 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200804<
805 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000807
808acos({expr}) *acos()*
809 Return the arc cosine of {expr} measured in radians, as a
810 |Float| in the range of [0, pi].
811 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100812 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000813 Examples: >
814 :echo acos(0)
815< 1.570796 >
816 :echo acos(-0.5)
817< 2.094395
818
819 Can also be used as a |method|: >
820 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200821<
822 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000824
825add({object}, {expr}) *add()*
826 Append the item {expr} to |List| or |Blob| {object}. Returns
827 the resulting |List| or |Blob|. Examples: >
828 :let alist = add([1, 2, 3], item)
829 :call add(mylist, "woodstock")
830< Note that when {expr} is a |List| it is appended as a single
831 item. Use |extend()| to concatenate |Lists|.
832 When {object} is a |Blob| then {expr} must be a number.
833 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100834 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000835
836 Can also be used as a |method|: >
837 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200838<
839 Return type: list<{type}> (depending on the given |List|) or
840 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000841
842
843and({expr}, {expr}) *and()*
844 Bitwise AND on the two arguments. The arguments are converted
845 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100846 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000847 Example: >
848 :let flag = and(bits, 0x80)
849< Can also be used as a |method|: >
850 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200851<
852 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000853
854
855append({lnum}, {text}) *append()*
856 When {text} is a |List|: Append each item of the |List| as a
857 text line below line {lnum} in the current buffer.
858 Otherwise append {text} as one text line below line {lnum} in
859 the current buffer.
860 Any type of item is accepted and converted to a String.
861 {lnum} can be zero to insert a line before the first one.
862 {lnum} is used like with |getline()|.
863 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000864 0 for success. When {text} is an empty list zero is returned,
865 no matter the value of {lnum}.
866 In |Vim9| script an invalid argument or negative number
867 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000868 :let failed = append(line('$'), "# THE END")
869 :let failed = append(0, ["Chapter 1", "the beginning"])
870
871< Can also be used as a |method| after a List, the base is
872 passed as the second argument: >
873 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200874<
875 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000876
877
878appendbufline({buf}, {lnum}, {text}) *appendbufline()*
879 Like |append()| but append the text in buffer {buf}.
880
881 This function works only for loaded buffers. First call
882 |bufload()| if needed.
883
884 For the use of {buf}, see |bufname()|.
885
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000886 {lnum} is the line number to append below. Note that using
887 |line()| would use the current buffer, not the one appending
888 to. Use "$" to append at the end of the buffer. Other string
889 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000890
891 On success 0 is returned, on failure 1 is returned.
892 In |Vim9| script an error is given for an invalid {lnum}.
893
894 If {buf} is not a valid buffer or {lnum} is not valid, an
895 error message is given. Example: >
896 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000897< However, when {text} is an empty list then no error is given
898 for an invalid {lnum}, since {lnum} isn't actually used.
899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000900 Can also be used as a |method| after a List, the base is
901 passed as the second argument: >
902 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200903<
904 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905
906
907argc([{winid}]) *argc()*
908 The result is the number of files in the argument list. See
909 |arglist|.
910 If {winid} is not supplied, the argument list of the current
911 window is used.
912 If {winid} is -1, the global argument list is used.
913 Otherwise {winid} specifies the window of which the argument
914 list is used: either the window number or the window ID.
915 Returns -1 if the {winid} argument is invalid.
916
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200917 Return type: |Number|
918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000919 *argidx()*
920argidx() The result is the current index in the argument list. 0 is
921 the first file. argc() - 1 is the last one. See |arglist|.
922
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200923 Return type: |Number|
924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000925 *arglistid()*
926arglistid([{winnr} [, {tabnr}]])
927 Return the argument list ID. This is a number which
928 identifies the argument list being used. Zero is used for the
929 global argument list. See |arglist|.
930 Returns -1 if the arguments are invalid.
931
932 Without arguments use the current window.
933 With {winnr} only use this window in the current tab page.
934 With {winnr} and {tabnr} use the window in the specified tab
935 page.
936 {winnr} can be the window number or the |window-ID|.
937
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200938 Return type: |Number|
939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000940 *argv()*
941argv([{nr} [, {winid}]])
942 The result is the {nr}th file in the argument list. See
943 |arglist|. "argv(0)" is the first one. Example: >
944 :let i = 0
945 :while i < argc()
946 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000947 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000948 : let i = i + 1
949 :endwhile
950< Without the {nr} argument, or when {nr} is -1, a |List| with
951 the whole |arglist| is returned.
952
953 The {winid} argument specifies the window ID, see |argc()|.
954 For the Vim command line arguments see |v:argv|.
955
Bram Moolenaar016188f2022-06-06 20:52:59 +0100956 Returns an empty string if {nr}th argument is not present in
957 the argument list. Returns an empty List if the {winid}
958 argument is invalid.
959
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200960 Return type: |String|
961
962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000963asin({expr}) *asin()*
964 Return the arc sine of {expr} measured in radians, as a |Float|
965 in the range of [-pi/2, pi/2].
966 {expr} must evaluate to a |Float| or a |Number| in the range
967 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100968 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
969 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000970 Examples: >
971 :echo asin(0.8)
972< 0.927295 >
973 :echo asin(-0.5)
974< -0.523599
975
976 Can also be used as a |method|: >
977 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200978<
979 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000980
981assert_ functions are documented here: |assert-functions-details|
982
983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984atan({expr}) *atan()*
985 Return the principal value of the arc tangent of {expr}, in
986 the range [-pi/2, +pi/2] radians, as a |Float|.
987 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100988 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000989 Examples: >
990 :echo atan(100)
991< 1.560797 >
992 :echo atan(-4.01)
993< -1.326405
994
995 Can also be used as a |method|: >
996 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200997<
998 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000999
1000
1001atan2({expr1}, {expr2}) *atan2()*
1002 Return the arc tangent of {expr1} / {expr2}, measured in
1003 radians, as a |Float| in the range [-pi, pi].
1004 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001005 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1006 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001007 Examples: >
1008 :echo atan2(-1, 1)
1009< -0.785398 >
1010 :echo atan2(1, -1)
1011< 2.356194
1012
1013 Can also be used as a |method|: >
1014 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001015<
1016 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001017
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001018
1019autocmd_add({acmds}) *autocmd_add()*
1020 Adds a List of autocmds and autocmd groups.
1021
1022 The {acmds} argument is a List where each item is a Dict with
1023 the following optional items:
1024 bufnr buffer number to add a buffer-local autocmd.
1025 If this item is specified, then the "pattern"
1026 item is ignored.
1027 cmd Ex command to execute for this autocmd event
1028 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001029 This can be either a String with a single
1030 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001031 group autocmd group name. Refer to |autocmd-groups|.
1032 If this group doesn't exist then it is
1033 created. If not specified or empty, then the
1034 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001035 nested boolean flag, set to v:true to add a nested
1036 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001037 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001038 which executes only once. Refer to
1039 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001040 pattern autocmd pattern string. Refer to
1041 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001042 present, then this item is ignored. This can
1043 be a String with a single pattern or a List of
1044 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001045 replace boolean flag, set to v:true to remove all the
1046 commands associated with the specified autocmd
1047 event and group and add the {cmd}. This is
1048 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001049 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001050
1051 Returns v:true on success and v:false on failure.
1052 Examples: >
1053 " Create a buffer-local autocmd for buffer 5
1054 let acmd = {}
1055 let acmd.group = 'MyGroup'
1056 let acmd.event = 'BufEnter'
1057 let acmd.bufnr = 5
1058 let acmd.cmd = 'call BufEnterFunc()'
1059 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001060<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001061 Can also be used as a |method|: >
1062 GetAutocmdList()->autocmd_add()
1063<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001064 Return type: |vim9-boolean|
1065
1066
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001067autocmd_delete({acmds}) *autocmd_delete()*
1068 Deletes a List of autocmds and autocmd groups.
1069
1070 The {acmds} argument is a List where each item is a Dict with
1071 the following optional items:
1072 bufnr buffer number to delete a buffer-local autocmd.
1073 If this item is specified, then the "pattern"
1074 item is ignored.
1075 cmd Ex command for this autocmd event
1076 event autocmd event name. Refer to |autocmd-events|.
1077 If '*' then all the autocmd events in this
1078 group are deleted.
1079 group autocmd group name. Refer to |autocmd-groups|.
1080 If not specified or empty, then the default
1081 group is used.
1082 nested set to v:true for a nested autocmd.
1083 Refer to |autocmd-nested|.
1084 once set to v:true for an autocmd which executes
1085 only once. Refer to |autocmd-once|.
1086 pattern autocmd pattern string. Refer to
1087 |autocmd-patterns|. If "bufnr" item is
1088 present, then this item is ignored.
1089
1090 If only {group} is specified in a {acmds} entry and {event},
1091 {pattern} and {cmd} are not specified, then that autocmd group
1092 is deleted.
1093
Bram Moolenaar016188f2022-06-06 20:52:59 +01001094 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001095 Examples: >
1096 " :autocmd! BufLeave *.vim
1097 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1098 call autocmd_delete([acmd]})
1099 " :autocmd! MyGroup1 BufLeave
1100 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1101 call autocmd_delete([acmd])
1102 " :autocmd! MyGroup2 BufEnter *.c
1103 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1104 \ pattern: '*.c'}
1105 " :autocmd! MyGroup2 * *.c
1106 let acmd = #{group: 'MyGroup2', event: '*',
1107 \ pattern: '*.c'}
1108 call autocmd_delete([acmd])
1109 " :autocmd! MyGroup3
1110 let acmd = #{group: 'MyGroup3'}
1111 call autocmd_delete([acmd])
1112<
1113 Can also be used as a |method|: >
1114 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001115<
1116 Return type: |vim9-boolean|
1117
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001118
1119autocmd_get([{opts}]) *autocmd_get()*
1120 Returns a |List| of autocmds. If {opts} is not supplied, then
1121 returns the autocmds for all the events in all the groups.
1122
1123 The optional {opts} Dict argument supports the following
1124 items:
1125 group Autocmd group name. If specified, returns only
1126 the autocmds defined in this group. If the
1127 specified group doesn't exist, results in an
1128 error message. If set to an empty string,
1129 then the default autocmd group is used.
1130 event Autocmd event name. If specified, returns only
1131 the autocmds defined for this event. If set
1132 to "*", then returns autocmds for all the
1133 events. If the specified event doesn't exist,
1134 results in an error message.
1135 pattern Autocmd pattern. If specified, returns only
1136 the autocmds defined for this pattern.
1137 A combination of the above three times can be supplied in
1138 {opts}.
1139
1140 Each Dict in the returned List contains the following items:
1141 bufnr For buffer-local autocmds, buffer number where
1142 the autocmd is defined.
1143 cmd Command executed for this autocmd.
1144 event Autocmd event name.
1145 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001146 nested Boolean flag, set to v:true for a nested
1147 autocmd. See |autocmd-nested|.
1148 once Boolean flag, set to v:true, if the autocmd
1149 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001150 pattern Autocmd pattern. For a buffer-local
1151 autocmd, this will be of the form "<buffer=n>".
1152 If there are multiple commands for an autocmd event in a
1153 group, then separate items are returned for each command.
1154
Bram Moolenaar016188f2022-06-06 20:52:59 +01001155 Returns an empty List if an autocmd with the specified group
1156 or event or pattern is not found.
1157
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001158 Examples: >
1159 " :autocmd MyGroup
1160 echo autocmd_get(#{group: 'Mygroup'})
1161 " :autocmd G BufUnload
1162 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1163 " :autocmd G * *.ts
1164 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1165 echo autocmd_get(acmd)
1166 " :autocmd Syntax
1167 echo autocmd_get(#{event: 'Syntax'})
1168 " :autocmd G BufEnter *.ts
1169 let acmd = #{group: 'G', event: 'BufEnter',
1170 \ pattern: '*.ts'}
1171 echo autocmd_get(acmd)
1172<
1173 Can also be used as a |method|: >
1174 Getopts()->autocmd_get()
1175<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001176 Return type: list<dict<any>>
1177
1178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001179balloon_gettext() *balloon_gettext()*
1180 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001181 not used for the List. Returns an empty string if balloon
1182 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001183
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001184 Return type: |String|
1185
1186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001187balloon_show({expr}) *balloon_show()*
1188 Show {expr} inside the balloon. For the GUI {expr} is used as
1189 a string. For a terminal {expr} can be a list, which contains
1190 the lines of the balloon. If {expr} is not a list it will be
1191 split with |balloon_split()|.
1192 If {expr} is an empty string any existing balloon is removed.
1193
1194 Example: >
1195 func GetBalloonContent()
1196 " ... initiate getting the content
1197 return ''
1198 endfunc
1199 set balloonexpr=GetBalloonContent()
1200
1201 func BalloonCallback(result)
1202 call balloon_show(a:result)
1203 endfunc
1204< Can also be used as a |method|: >
1205 GetText()->balloon_show()
1206<
1207 The intended use is that fetching the content of the balloon
1208 is initiated from 'balloonexpr'. It will invoke an
1209 asynchronous method, in which a callback invokes
1210 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001211 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001212
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001213 When showing a balloon is not possible then nothing happens,
1214 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001215 {only available when compiled with the |+balloon_eval| or
1216 |+balloon_eval_term| feature}
1217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001218 Return type: |Number|
1219
1220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001221balloon_split({msg}) *balloon_split()*
1222 Split String {msg} into lines to be displayed in a balloon.
1223 The splits are made for the current window size and optimize
1224 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001225 Returns a |List| with the split lines. Returns an empty List
1226 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001227 Can also be used as a |method|: >
1228 GetText()->balloon_split()->balloon_show()
1229
1230< {only available when compiled with the |+balloon_eval_term|
1231 feature}
1232
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001233 Return type: list<any> or list<string>
1234
h-easte80f3452025-01-02 10:40:29 +01001235base64_decode({string}) *base64_decode()*
1236 Return a Blob containing the bytes decoded from the base64
1237 encoded characters in {string}.
1238
1239 The {string} argument should contain only base64-encoded
1240 characters and should have a length that is a multiple of 4.
1241
1242 Returns an empty blob on error.
1243
1244 Examples: >
1245 " Write the decoded contents to a binary file
1246 call writefile(base64_decode(s), 'tools.bmp')
1247 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001248 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001249<
1250 Can also be used as a |method|: >
1251 GetEncodedString()->base64_decode()
1252<
1253 Return type: |Blob|
1254
1255
1256base64_encode({blob}) *base64_encode()*
1257 Return a base64-encoded String representing the bytes in
1258 {blob}. The base64 alphabet defined in RFC 4648 is used.
1259
1260 Examples: >
1261 " Encode the contents of a binary file
1262 echo base64_encode(readblob('somefile.bin'))
1263 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001264 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001265<
1266 Can also be used as a |method|: >
1267 GetBinaryData()->base64_encode()
1268<
1269 Return type: |String|
1270
1271
Christ van Willegence0ef912024-06-20 23:41:59 +02001272bindtextdomain({package}, {path}) *bindtextdomain()*
1273 Bind a specific {package} to a {path} so that the
1274 |gettext()| function can be used to get language-specific
1275 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001276 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001277
Christ van Willegen8252ef12024-07-11 21:36:21 +02001278 Returns v:true on success and v:false on failure (out of
1279 memory).
1280
1281 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001283blob2list({blob}) *blob2list()*
1284 Return a List containing the number value of each byte in Blob
1285 {blob}. Examples: >
1286 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1287 blob2list(0z) returns []
1288< Returns an empty List on error. |list2blob()| does the
1289 opposite.
1290
1291 Can also be used as a |method|: >
1292 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001293<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001294 Return type: list<any> or list<number>
1295
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001296
1297blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001298 Return a List of Strings in the current 'encoding' by
1299 converting the bytes in {blob} into characters.
1300
1301 Each <NL> byte in the blob is interpreted as the end of a
1302 string and a new list item is added. Each <NUL> byte in the
1303 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001304
1305 If {options} is not supplied, the current 'encoding' value is
1306 used to decode the bytes in {blob}.
1307
1308 The argument {options} is a |Dict| and supports the following
1309 items:
1310 encoding Decode the bytes in {blob} using this
1311 encoding. The value is a |String|. See
Bakudankunb3854bf2025-02-23 20:29:21 +01001312 |encoding-names| for the supported values
1313 (plus the special value "none").
Christian Brabandtd5afc742025-03-18 20:55:42 +01001314 *E1515* *E1516*
Bakudankunb3854bf2025-02-23 20:29:21 +01001315 When current 'encoding' is "utf-8", an error is given and an
1316 empty List is returned if an invalid byte sequence is
1317 encountered in {blob}. To suppress this validation and get
1318 potentially invalid string, set "encoding" in {options} to
1319 "none".
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001320
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001321 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001322
1323 See also |str2blob()|
1324
1325 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +01001326 blob2str(0z6162) returns ['ab']
1327 blob2str(0zC2ABC2BB) returns ['«»']
1328 blob2str(0z610A62) returns ['a', 'b']
1329 blob2str(0z610062) returns ['a\nb']
1330 blob2str(0zABBB, {'encoding': 'latin1'}) returns ['«»']
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001331<
1332 Can also be used as a |method|: >
1333 GetBlob()->blob2str()
1334<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001335 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001336
1337
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001338 *browse()*
1339browse({save}, {title}, {initdir}, {default})
1340 Put up a file requester. This only works when "has("browse")"
1341 returns |TRUE| (only in some GUI versions).
1342 The input fields are:
1343 {save} when |TRUE|, select file to write
1344 {title} title for the requester
1345 {initdir} directory to start browsing in
1346 {default} default file name
1347 An empty string is returned when the "Cancel" button is hit,
1348 something went wrong, or browsing is not possible.
1349
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001350 Return type: |String|
1351
1352
1353browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001354 Put up a directory requester. This only works when
1355 "has("browse")" returns |TRUE| (only in some GUI versions).
1356 On systems where a directory browser is not supported a file
1357 browser is used. In that case: select a file in the directory
1358 to be used.
1359 The input fields are:
1360 {title} title for the requester
1361 {initdir} directory to start browsing in
1362 When the "Cancel" button is hit, something went wrong, or
1363 browsing is not possible, an empty string is returned.
1364
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001365 Return type: |String|
1366
1367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001368bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001369 Add a buffer to the buffer list with name {name} (must be a
1370 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001371 If a buffer for file {name} already exists, return that buffer
1372 number. Otherwise return the buffer number of the newly
1373 created buffer. When {name} is an empty string then a new
1374 buffer is always created.
1375 The buffer will not have 'buflisted' set and not be loaded
1376 yet. To add some text to the buffer use this: >
1377 let bufnr = bufadd('someName')
1378 call bufload(bufnr)
1379 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001380< Returns 0 on error.
1381 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001382 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001383<
1384 Return type: |Number|
1385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001386
1387bufexists({buf}) *bufexists()*
1388 The result is a Number, which is |TRUE| if a buffer called
1389 {buf} exists.
1390 If the {buf} argument is a number, buffer numbers are used.
1391 Number zero is the alternate buffer for the current window.
1392
1393 If the {buf} argument is a string it must match a buffer name
1394 exactly. The name can be:
1395 - Relative to the current directory.
1396 - A full path.
1397 - The name of a buffer with 'buftype' set to "nofile".
1398 - A URL name.
1399 Unlisted buffers will be found.
1400 Note that help files are listed by their short name in the
1401 output of |:buffers|, but bufexists() requires using their
1402 long name to be able to find them.
1403 bufexists() may report a buffer exists, but to use the name
1404 with a |:buffer| command you may need to use |expand()|. Esp
1405 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1406 Use "bufexists(0)" to test for the existence of an alternate
1407 file name.
1408
1409 Can also be used as a |method|: >
1410 let exists = 'somename'->bufexists()
1411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001412 Return type: |Number|
1413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001414 Obsolete name: buffer_exists(). *buffer_exists()*
1415
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001417buflisted({buf}) *buflisted()*
1418 The result is a Number, which is |TRUE| if a buffer called
1419 {buf} exists and is listed (has the 'buflisted' option set).
1420 The {buf} argument is used like with |bufexists()|.
1421
1422 Can also be used as a |method|: >
1423 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001424<
1425 Return type: |Number|
1426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001427
1428bufload({buf}) *bufload()*
1429 Ensure the buffer {buf} is loaded. When the buffer name
1430 refers to an existing file then the file is read. Otherwise
1431 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001432 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001433 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001434 If there is an existing swap file for the file of the buffer,
1435 there will be no dialog, the buffer will be loaded anyway.
1436 The {buf} argument is used like with |bufexists()|.
1437
1438 Can also be used as a |method|: >
1439 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001440<
1441 Return type: |Number|
1442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001443
1444bufloaded({buf}) *bufloaded()*
1445 The result is a Number, which is |TRUE| if a buffer called
1446 {buf} exists and is loaded (shown in a window or hidden).
1447 The {buf} argument is used like with |bufexists()|.
1448
1449 Can also be used as a |method|: >
1450 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001451<
1452 Return type: |Number|
1453
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001454
1455bufname([{buf}]) *bufname()*
1456 The result is the name of a buffer. Mostly as it is displayed
1457 by the `:ls` command, but not using special names such as
1458 "[No Name]".
1459 If {buf} is omitted the current buffer is used.
1460 If {buf} is a Number, that buffer number's name is given.
1461 Number zero is the alternate buffer for the current window.
1462 If {buf} is a String, it is used as a |file-pattern| to match
1463 with the buffer names. This is always done like 'magic' is
1464 set and 'cpoptions' is empty. When there is more than one
1465 match an empty string is returned.
1466 "" or "%" can be used for the current buffer, "#" for the
1467 alternate buffer.
1468 A full match is preferred, otherwise a match at the start, end
1469 or middle of the buffer name is accepted. If you only want a
1470 full match then put "^" at the start and "$" at the end of the
1471 pattern.
1472 Listed buffers are found first. If there is a single match
1473 with a listed buffer, that one is returned. Next unlisted
1474 buffers are searched for.
1475 If the {buf} is a String, but you want to use it as a buffer
1476 number, force it to be a Number by adding zero to it: >
1477 :echo bufname("3" + 0)
1478< Can also be used as a |method|: >
1479 echo bufnr->bufname()
1480
1481< If the buffer doesn't exist, or doesn't have a name, an empty
1482 string is returned. >
1483 bufname("#") alternate buffer name
1484 bufname(3) name of buffer 3
1485 bufname("%") name of current buffer
1486 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001487<
1488 Return type: |String|
1489 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001490 Obsolete name: buffer_name().
1491
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001492
1493bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001494 The result is the number of a buffer, as it is displayed by
1495 the `:ls` command. For the use of {buf}, see |bufname()|
1496 above.
1497
1498 If the buffer doesn't exist, -1 is returned. Or, if the
1499 {create} argument is present and TRUE, a new, unlisted,
1500 buffer is created and its number is returned. Example: >
1501 let newbuf = bufnr('Scratch001', 1)
1502< Using an empty name uses the current buffer. To create a new
1503 buffer with an empty name use |bufadd()|.
1504
1505 bufnr("$") is the last buffer: >
1506 :let last_buffer = bufnr("$")
1507< The result is a Number, which is the highest buffer number
1508 of existing buffers. Note that not all buffers with a smaller
1509 number necessarily exist, because ":bwipeout" may have removed
1510 them. Use bufexists() to test for the existence of a buffer.
1511
1512 Can also be used as a |method|: >
1513 echo bufref->bufnr()
1514<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001515 Return type: |Number|
1516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001517 Obsolete name: buffer_number(). *buffer_number()*
1518 *last_buffer_nr()*
1519 Obsolete name for bufnr("$"): last_buffer_nr().
1520
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522bufwinid({buf}) *bufwinid()*
1523 The result is a Number, which is the |window-ID| of the first
1524 window associated with buffer {buf}. For the use of {buf},
1525 see |bufname()| above. If buffer {buf} doesn't exist or
1526 there is no such window, -1 is returned. Example: >
1527
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001528 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001529<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001530 Only deals with the current tab page. See |win_findbuf()| for
1531 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001532
1533 Can also be used as a |method|: >
1534 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001535<
1536 Return type: |Number|
1537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001538
1539bufwinnr({buf}) *bufwinnr()*
1540 Like |bufwinid()| but return the window number instead of the
1541 |window-ID|.
1542 If buffer {buf} doesn't exist or there is no such window, -1
1543 is returned. Example: >
1544
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001545 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001546
1547< The number can be used with |CTRL-W_w| and ":wincmd w"
1548 |:wincmd|.
1549
1550 Can also be used as a |method|: >
1551 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001552<
1553 Return type: |Number|
1554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001555
1556byte2line({byte}) *byte2line()*
1557 Return the line number that contains the character at byte
1558 count {byte} in the current buffer. This includes the
1559 end-of-line character, depending on the 'fileformat' option
1560 for the current buffer. The first character has byte count
1561 one.
1562 Also see |line2byte()|, |go| and |:goto|.
1563
Bram Moolenaar016188f2022-06-06 20:52:59 +01001564 Returns -1 if the {byte} value is invalid.
1565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001566 Can also be used as a |method|: >
1567 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001568<
1569 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001570
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001571 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001572 feature}
1573
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001574
Christian Brabandt67672ef2023-04-24 21:09:54 +01001575byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001576 Return byte index of the {nr}'th character in the String
1577 {expr}. Use zero for the first character, it then returns
1578 zero.
1579 If there are no multibyte characters the returned value is
1580 equal to {nr}.
1581 Composing characters are not counted separately, their byte
1582 length is added to the preceding base character. See
1583 |byteidxcomp()| below for counting composing characters
1584 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001585 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1586 index in the String {expr} instead of as the character index.
1587 The UTF-16 index is the index in the string when it is encoded
1588 with 16-bit words. If the specified UTF-16 index is in the
1589 middle of a character (e.g. in a 4-byte character), then the
1590 byte index of the first byte in the character is returned.
1591 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001592 Example : >
1593 echo matchstr(str, ".", byteidx(str, 3))
1594< will display the fourth character. Another way to do the
1595 same: >
1596 let s = strpart(str, byteidx(str, 3))
1597 echo strpart(s, 0, byteidx(s, 1))
1598< Also see |strgetchar()| and |strcharpart()|.
1599
1600 If there are less than {nr} characters -1 is returned.
1601 If there are exactly {nr} characters the length of the string
1602 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001603 See |charidx()| and |utf16idx()| for getting the character and
1604 UTF-16 index respectively from the byte index.
1605 Examples: >
1606 echo byteidx('a😊😊', 2) returns 5
1607 echo byteidx('a😊😊', 2, 1) returns 1
1608 echo byteidx('a😊😊', 3, 1) returns 5
1609<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001610 Can also be used as a |method|: >
1611 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001612<
1613 Return type: |Number|
1614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001615
Christian Brabandt67672ef2023-04-24 21:09:54 +01001616byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001617 Like byteidx(), except that a composing character is counted
1618 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001619 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620 echo byteidx(s, 1)
1621 echo byteidxcomp(s, 1)
1622 echo byteidxcomp(s, 2)
1623< The first and third echo result in 3 ('e' plus composing
1624 character is 3 bytes), the second echo results in 1 ('e' is
1625 one byte).
1626 Only works differently from byteidx() when 'encoding' is set
1627 to a Unicode encoding.
1628
1629 Can also be used as a |method|: >
1630 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001631<
1632 Return type: |Number|
1633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001634
1635call({func}, {arglist} [, {dict}]) *call()* *E699*
1636 Call function {func} with the items in |List| {arglist} as
1637 arguments.
1638 {func} can either be a |Funcref| or the name of a function.
1639 a:firstline and a:lastline are set to the cursor line.
1640 Returns the return value of the called function.
1641 {dict} is for functions with the "dict" attribute. It will be
1642 used to set the local variable "self". |Dictionary-function|
1643
1644 Can also be used as a |method|: >
1645 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001646<
1647 Return type: any, depending on {func}
1648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001649
1650ceil({expr}) *ceil()*
1651 Return the smallest integral value greater than or equal to
1652 {expr} as a |Float| (round up).
1653 {expr} must evaluate to a |Float| or a |Number|.
1654 Examples: >
1655 echo ceil(1.456)
1656< 2.0 >
1657 echo ceil(-5.456)
1658< -5.0 >
1659 echo ceil(4.0)
1660< 4.0
1661
Bram Moolenaar016188f2022-06-06 20:52:59 +01001662 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001664 Can also be used as a |method|: >
1665 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001666<
1667 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001668
1669
1670ch_ functions are documented here: |channel-functions-details|
1671
1672
1673changenr() *changenr()*
1674 Return the number of the most recent change. This is the same
1675 number as what is displayed with |:undolist| and can be used
1676 with the |:undo| command.
1677 When a change was made it is the number of that change. After
1678 redo it is the number of the redone change. After undo it is
1679 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001680 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001681
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001682 Return type: |Number|
1683
1684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001685char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001686 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001687 Examples: >
1688 char2nr(" ") returns 32
1689 char2nr("ABC") returns 65
1690< When {utf8} is omitted or zero, the current 'encoding' is used.
1691 Example for "utf-8": >
1692 char2nr("á") returns 225
1693 char2nr("á"[0]) returns 195
1694< When {utf8} is TRUE, always treat as UTF-8 characters.
1695 A combining character is a separate character.
1696 |nr2char()| does the opposite.
1697 To turn a string into a list of character numbers: >
1698 let str = "ABC"
1699 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1700< Result: [65, 66, 67]
1701
Bram Moolenaar016188f2022-06-06 20:52:59 +01001702 Returns 0 if {string} is not a |String|.
1703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001704 Can also be used as a |method|: >
1705 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001706<
1707 Return type: |Number|
1708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001710charclass({string}) *charclass()*
1711 Return the character class of the first character in {string}.
1712 The character class is one of:
1713 0 blank
1714 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001715 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001716 3 emoji
1717 other specific Unicode class
1718 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001719 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001720
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001721 Return type: |Number|
1722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001723
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001724charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725 Same as |col()| but returns the character index of the column
1726 position given with {expr} instead of the byte position.
1727
1728 Example:
1729 With the cursor on '세' in line 5 with text "여보세요": >
1730 charcol('.') returns 3
1731 col('.') returns 7
1732
1733< Can also be used as a |method|: >
1734 GetPos()->col()
1735<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001736 Return type: |Number|
1737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001738 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001739charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001740 Return the character index of the byte at {idx} in {string}.
1741 The index of the first character is zero.
1742 If there are no multibyte characters the returned value is
1743 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001746 are not counted separately, their byte length is added to the
1747 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001748 When {countcc} is |TRUE|, then composing characters are
1749 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001750
1751 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1752 index in the String {expr} instead of as the byte index.
1753
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001754 Returns -1 if the arguments are invalid or if there are less
1755 than {idx} bytes. If there are exactly {idx} bytes the length
1756 of the string in characters is returned.
1757
1758 An error is given and -1 is returned if the first argument is
1759 not a string, the second argument is not a number or when the
1760 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001762 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001763 from the character index and |utf16idx()| for getting the
1764 UTF-16 index from the character index.
1765 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001766 Examples: >
1767 echo charidx('áb́ć', 3) returns 1
1768 echo charidx('áb́ć', 6, 1) returns 4
1769 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001770 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771<
1772 Can also be used as a |method|: >
1773 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001774<
1775 Return type: |Number|
1776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001777
1778chdir({dir}) *chdir()*
1779 Change the current working directory to {dir}. The scope of
1780 the directory change depends on the directory of the current
1781 window:
1782 - If the current window has a window-local directory
1783 (|:lcd|), then changes the window local directory.
1784 - Otherwise, if the current tabpage has a local
1785 directory (|:tcd|) then changes the tabpage local
1786 directory.
1787 - Otherwise, changes the global directory.
1788 {dir} must be a String.
1789 If successful, returns the previous working directory. Pass
1790 this to another chdir() to restore the directory.
1791 On failure, returns an empty string.
1792
1793 Example: >
1794 let save_dir = chdir(newdir)
1795 if save_dir != ""
1796 " ... do some work
1797 call chdir(save_dir)
1798 endif
1799
1800< Can also be used as a |method|: >
1801 GetDir()->chdir()
1802<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001803 Return type: |String|
1804
1805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001806cindent({lnum}) *cindent()*
1807 Get the amount of indent for line {lnum} according the C
1808 indenting rules, as with 'cindent'.
1809 The indent is counted in spaces, the value of 'tabstop' is
1810 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001811 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001812 See |C-indenting|.
1813
1814 Can also be used as a |method|: >
1815 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001816<
1817 Return type: |Number|
1818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001819
1820clearmatches([{win}]) *clearmatches()*
1821 Clears all matches previously defined for the current window
1822 by |matchadd()| and the |:match| commands.
1823 If {win} is specified, use the window with this number or
1824 window ID instead of the current window.
1825
1826 Can also be used as a |method|: >
1827 GetWin()->clearmatches()
1828<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001829 Return type: |Number|
1830
1831
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001832col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001833 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001834 position given with {expr}.
1835 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001836 When {expr} is "$", it means the end of the cursor line, so
1837 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001838 Additionally {expr} can be [lnum, col]: a |List| with the line
1839 and column number. Most useful when the column is "$", to get
1840 the last column of a specific line. When "lnum" or "col" is
1841 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001842
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001843 With the optional {winid} argument the values are obtained for
1844 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001846 To get the line number use |line()|. To get both use
1847 |getpos()|.
1848 For the screen column position use |virtcol()|. For the
1849 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001851 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001852
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001853 Examples: >
1854 col(".") column of cursor
1855 col("$") length of cursor line plus one
1856 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001857 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001858<
1859 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001860 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001861 For an uppercase mark the column may actually be in another
1862 buffer.
1863 For the cursor position, when 'virtualedit' is active, the
1864 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001865 line. Also, when using a <Cmd> mapping the cursor isn't
1866 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001867 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001868
1869< Can also be used as a |method|: >
1870 GetPos()->col()
1871<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001872 Return type: |Number|
1873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001874
1875complete({startcol}, {matches}) *complete()* *E785*
1876 Set the matches for Insert mode completion.
1877 Can only be used in Insert mode. You need to use a mapping
1878 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1879 or with an expression mapping.
1880 {startcol} is the byte offset in the line where the completed
1881 text start. The text up to the cursor is the original text
1882 that will be replaced by the matches. Use col('.') for an
1883 empty string. "col('.') - 1" will replace one character by a
1884 match.
1885 {matches} must be a |List|. Each |List| item is one match.
1886 See |complete-items| for the kind of items that are possible.
1887 "longest" in 'completeopt' is ignored.
1888 Note that the after calling this function you need to avoid
1889 inserting anything that would cause completion to stop.
1890 The match can be selected with CTRL-N and CTRL-P as usual with
1891 Insert mode completion. The popup menu will appear if
1892 specified, see |ins-completion-menu|.
1893 Example: >
1894 inoremap <F5> <C-R>=ListMonths()<CR>
1895
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001896 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001897 call complete(col('.'), ['January', 'February', 'March',
1898 \ 'April', 'May', 'June', 'July', 'August', 'September',
1899 \ 'October', 'November', 'December'])
1900 return ''
1901 endfunc
1902< This isn't very useful, but it shows how it works. Note that
1903 an empty string is returned to avoid a zero being inserted.
1904
1905 Can also be used as a |method|, the base is passed as the
1906 second argument: >
1907 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001908<
1909 Return type: |Number|
1910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001911
1912complete_add({expr}) *complete_add()*
1913 Add {expr} to the list of matches. Only to be used by the
1914 function specified with the 'completefunc' option.
1915 Returns 0 for failure (empty string or out of memory),
1916 1 when the match was added, 2 when the match was already in
1917 the list.
1918 See |complete-functions| for an explanation of {expr}. It is
1919 the same as one item in the list that 'omnifunc' would return.
1920
1921 Can also be used as a |method|: >
1922 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001923<
1924 Return type: |Number|
1925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001926
1927complete_check() *complete_check()*
1928 Check for a key typed while looking for completion matches.
1929 This is to be used when looking for matches takes some time.
1930 Returns |TRUE| when searching for matches is to be aborted,
1931 zero otherwise.
1932 Only to be used by the function specified with the
1933 'completefunc' option.
1934
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001935 Return type: |Number|
1936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001937
1938complete_info([{what}]) *complete_info()*
1939 Returns a |Dictionary| with information about Insert mode
1940 completion. See |ins-completion|.
1941 The items are:
1942 mode Current completion mode name string.
1943 See |complete_info_mode| for the values.
1944 pum_visible |TRUE| if popup menu is visible.
1945 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001946 items List of all completion candidates. Each item
1947 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001948 "abbr", "menu", "kind", "info" and "user_data".
1949 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001950 matches Same as "items", but only returns items that
1951 are matching current query. If both "matches"
1952 and "items" are in "what", the returned list
1953 will still be named "items", but each item
1954 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001955 selected Selected item index. First index is zero.
1956 Index is -1 if no item is selected (showing
1957 typed text only, or the last completion after
1958 no item is selected when using the <Up> or
1959 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001960 completed Return a dictionary containing the entries of
1961 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001962
1963 *complete_info_mode*
1964 mode values are:
1965 "" Not in completion mode
1966 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1967 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1968 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1969 |i_CTRL-X_CTRL-Y|
1970 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1971 "files" File names |i_CTRL-X_CTRL-F|
1972 "tags" Tags |i_CTRL-X_CTRL-]|
1973 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1974 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1975 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1976 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1977 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1978 "function" User defined completion |i_CTRL-X_CTRL-U|
1979 "omni" Omni completion |i_CTRL-X_CTRL-O|
1980 "spell" Spelling suggestions |i_CTRL-X_s|
1981 "eval" |complete()| completion
1982 "unknown" Other internal modes
1983
1984 If the optional {what} list argument is supplied, then only
1985 the items listed in {what} are returned. Unsupported items in
1986 {what} are silently ignored.
1987
1988 To get the position and size of the popup menu, see
1989 |pum_getpos()|. It's also available in |v:event| during the
1990 |CompleteChanged| event.
1991
Bram Moolenaar016188f2022-06-06 20:52:59 +01001992 Returns an empty |Dictionary| on error.
1993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001994 Examples: >
1995 " Get all items
1996 call complete_info()
1997 " Get only 'mode'
1998 call complete_info(['mode'])
1999 " Get only 'mode' and 'pum_visible'
2000 call complete_info(['mode', 'pum_visible'])
2001
2002< Can also be used as a |method|: >
2003 GetItems()->complete_info()
2004<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002005 Return type: dict<any>
2006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002007 *confirm()*
2008confirm({msg} [, {choices} [, {default} [, {type}]]])
2009 confirm() offers the user a dialog, from which a choice can be
2010 made. It returns the number of the choice. For the first
2011 choice this is 1.
2012 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002013 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002014
2015 {msg} is displayed in a |dialog| with {choices} as the
2016 alternatives. When {choices} is missing or empty, "&OK" is
2017 used (and translated).
2018 {msg} is a String, use '\n' to include a newline. Only on
2019 some systems the string is wrapped when it doesn't fit.
2020
2021 {choices} is a String, with the individual choices separated
2022 by '\n', e.g. >
2023 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2024< The letter after the '&' is the shortcut key for that choice.
2025 Thus you can type 'c' to select "Cancel". The shortcut does
2026 not need to be the first letter: >
2027 confirm("file has been modified", "&Save\nSave &All")
2028< For the console, the first letter of each choice is used as
2029 the default shortcut key. Case is ignored.
2030
2031 The optional {default} argument is the number of the choice
2032 that is made if the user hits <CR>. Use 1 to make the first
2033 choice the default one. Use 0 to not set a default. If
2034 {default} is omitted, 1 is used.
2035
2036 The optional {type} String argument gives the type of dialog.
2037 This is only used for the icon of the GTK, Mac, Motif and
2038 Win32 GUI. It can be one of these values: "Error",
2039 "Question", "Info", "Warning" or "Generic". Only the first
2040 character is relevant. When {type} is omitted, "Generic" is
2041 used.
2042
2043 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2044 or another valid interrupt key, confirm() returns 0.
2045
2046 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002047 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002048 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002049 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002050 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002051 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002052 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002053 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002054 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002055 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002056< In a GUI dialog, buttons are used. The layout of the buttons
2057 depends on the 'v' flag in 'guioptions'. If it is included,
2058 the buttons are always put vertically. Otherwise, confirm()
2059 tries to put the buttons in one horizontal line. If they
2060 don't fit, a vertical layout is used anyway. For some systems
2061 the horizontal layout is always used.
2062
2063 Can also be used as a |method|in: >
2064 BuildMessage()->confirm("&Yes\n&No")
2065<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002066 Return type: |Number|
2067
2068
2069copy({expr}) *copy()*
2070 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002071 different from using {expr} directly.
2072 When {expr} is a |List| a shallow copy is created. This means
2073 that the original |List| can be changed without changing the
2074 copy, and vice versa. But the items are identical, thus
2075 changing an item changes the contents of both |Lists|.
2076 A |Dictionary| is copied in a similar way as a |List|.
2077 Also see |deepcopy()|.
2078 Can also be used as a |method|: >
2079 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002080<
2081 Return type: any, depending on {expr}
2082
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002083
2084cos({expr}) *cos()*
2085 Return the cosine of {expr}, measured in radians, as a |Float|.
2086 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002087 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002088 Examples: >
2089 :echo cos(100)
2090< 0.862319 >
2091 :echo cos(-4.01)
2092< -0.646043
2093
2094 Can also be used as a |method|: >
2095 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002096<
2097 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002098
2099
2100cosh({expr}) *cosh()*
2101 Return the hyperbolic cosine of {expr} as a |Float| in the range
2102 [1, inf].
2103 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002104 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002105 Examples: >
2106 :echo cosh(0.5)
2107< 1.127626 >
2108 :echo cosh(-0.5)
2109< -1.127626
2110
2111 Can also be used as a |method|: >
2112 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002113<
2114 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002115
2116
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002117count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002118 Return the number of times an item with value {expr} appears
2119 in |String|, |List| or |Dictionary| {comp}.
2120
2121 If {start} is given then start with the item with this index.
2122 {start} can only be used with a |List|.
2123
2124 When {ic} is given and it's |TRUE| then case is ignored.
2125
2126 When {comp} is a string then the number of not overlapping
2127 occurrences of {expr} is returned. Zero is returned when
2128 {expr} is an empty string.
2129
2130 Can also be used as a |method|: >
2131 mylist->count(val)
2132<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002133 Return type: |Number|
2134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002135 *cscope_connection()*
2136cscope_connection([{num} , {dbpath} [, {prepend}]])
2137 Checks for the existence of a |cscope| connection. If no
2138 parameters are specified, then the function returns:
2139 0, if cscope was not available (not compiled in), or
2140 if there are no cscope connections;
2141 1, if there is at least one cscope connection.
2142
2143 If parameters are specified, then the value of {num}
2144 determines how existence of a cscope connection is checked:
2145
2146 {num} Description of existence check
2147 ----- ------------------------------
2148 0 Same as no parameters (e.g., "cscope_connection()").
2149 1 Ignore {prepend}, and use partial string matches for
2150 {dbpath}.
2151 2 Ignore {prepend}, and use exact string matches for
2152 {dbpath}.
2153 3 Use {prepend}, use partial string matches for both
2154 {dbpath} and {prepend}.
2155 4 Use {prepend}, use exact string matches for both
2156 {dbpath} and {prepend}.
2157
2158 Note: All string comparisons are case sensitive!
2159
2160 Examples. Suppose we had the following (from ":cs show"): >
2161
2162 # pid database name prepend path
2163 0 27664 cscope.out /usr/local
2164<
2165 Invocation Return Val ~
2166 ---------- ---------- >
2167 cscope_connection() 1
2168 cscope_connection(1, "out") 1
2169 cscope_connection(2, "out") 0
2170 cscope_connection(3, "out") 0
2171 cscope_connection(3, "out", "local") 1
2172 cscope_connection(4, "out") 0
2173 cscope_connection(4, "out", "local") 0
2174 cscope_connection(4, "cscope.out", "/usr/local") 1
2175<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002176 Return type: |Number|
2177
2178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002179cursor({lnum}, {col} [, {off}]) *cursor()*
2180cursor({list})
2181 Positions the cursor at the column (byte count) {col} in the
2182 line {lnum}. The first column is one.
2183
2184 When there is one argument {list} this is used as a |List|
2185 with two, three or four item:
2186 [{lnum}, {col}]
2187 [{lnum}, {col}, {off}]
2188 [{lnum}, {col}, {off}, {curswant}]
2189 This is like the return value of |getpos()| or |getcurpos()|,
2190 but without the first item.
2191
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002192 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002193 |setcursorcharpos()|.
2194
2195 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002196 {lnum} is used like with |getline()|, except that if {lnum} is
2197 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002198 If {lnum} is greater than the number of lines in the buffer,
2199 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002200 If {col} is greater than the number of bytes in the line,
2201 the cursor will be positioned at the last character in the
2202 line.
2203 If {col} is zero, the cursor will stay in the current column.
2204 If {curswant} is given it is used to set the preferred column
2205 for vertical movement. Otherwise {col} is used.
2206
2207 When 'virtualedit' is used {off} specifies the offset in
2208 screen columns from the start of the character. E.g., a
2209 position within a <Tab> or after the last character.
2210 Returns 0 when the position could be set, -1 otherwise.
2211
2212 Can also be used as a |method|: >
2213 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002214<
2215 Return type: |Number|
2216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002217
2218debugbreak({pid}) *debugbreak()*
2219 Specifically used to interrupt a program being debugged. It
2220 will cause process {pid} to get a SIGTRAP. Behavior for other
2221 processes is undefined. See |terminal-debugger|.
2222 {only available on MS-Windows}
2223
Bram Moolenaar016188f2022-06-06 20:52:59 +01002224 Returns |TRUE| if successfully interrupted the program.
2225 Otherwise returns |FALSE|.
2226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002227 Can also be used as a |method|: >
2228 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002229<
2230 Return type: |Number|
2231
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002232
2233deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2234 Make a copy of {expr}. For Numbers and Strings this isn't
2235 different from using {expr} directly.
2236 When {expr} is a |List| a full copy is created. This means
2237 that the original |List| can be changed without changing the
2238 copy, and vice versa. When an item is a |List| or
2239 |Dictionary|, a copy for it is made, recursively. Thus
2240 changing an item in the copy does not change the contents of
2241 the original |List|.
2242 A |Dictionary| is copied in a similar way as a |List|.
2243
2244 When {noref} is omitted or zero a contained |List| or
2245 |Dictionary| is only copied once. All references point to
2246 this single copy. With {noref} set to 1 every occurrence of a
2247 |List| or |Dictionary| results in a new copy. This also means
2248 that a cyclic reference causes deepcopy() to fail.
2249 *E724*
2250 Nesting is possible up to 100 levels. When there is an item
2251 that refers back to a higher level making a deep copy with
2252 {noref} set to 1 will fail.
2253 Also see |copy()|.
2254
2255 Can also be used as a |method|: >
2256 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002257<
2258 Return type: any, depending on {expr}
2259
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002260
2261delete({fname} [, {flags}]) *delete()*
2262 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002263 name {fname}.
2264
2265 This also works when {fname} is a symbolic link. The symbolic
2266 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002267
2268 When {flags} is "d": Deletes the directory by the name
2269 {fname}. This fails when directory {fname} is not empty.
2270
2271 When {flags} is "rf": Deletes the directory by the name
2272 {fname} and everything in it, recursively. BE CAREFUL!
2273 Note: on MS-Windows it is not possible to delete a directory
2274 that is being used.
2275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002276 The result is a Number, which is 0/false if the delete
2277 operation was successful and -1/true when the deletion failed
2278 or partly failed.
2279
2280 Use |remove()| to delete an item from a |List|.
2281 To delete a line from the buffer use |:delete| or
2282 |deletebufline()|.
2283
2284 Can also be used as a |method|: >
2285 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002286<
2287 Return type: |Number|
2288
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002289
2290deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2291 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2292 If {last} is omitted then delete line {first} only.
2293 On success 0 is returned, on failure 1 is returned.
2294
2295 This function works only for loaded buffers. First call
2296 |bufload()| if needed.
2297
2298 For the use of {buf}, see |bufname()| above.
2299
2300 {first} and {last} are used like with |getline()|. Note that
2301 when using |line()| this refers to the current buffer. Use "$"
2302 to refer to the last line in buffer {buf}.
2303
2304 Can also be used as a |method|: >
2305 GetBuffer()->deletebufline(1)
2306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002307 Return type: |Number|
2308
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002309 *did_filetype()*
2310did_filetype() Returns |TRUE| when autocommands are being executed and the
2311 FileType event has been triggered at least once. Can be used
2312 to avoid triggering the FileType event again in the scripts
2313 that detect the file type. |FileType|
2314 Returns |FALSE| when `:setf FALLBACK` was used.
2315 When editing another file, the counter is reset, thus this
2316 really checks if the FileType event has been triggered for the
2317 current buffer. This allows an autocommand that starts
2318 editing another buffer to set 'filetype' and load a syntax
2319 file.
2320
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002321 Return type: |Number|
2322
2323
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002324diff({fromlist}, {tolist} [, {options}]) *diff()*
2325 Returns a String or a List containing the diff between the
2326 strings in {fromlist} and {tolist}. Uses the Vim internal
2327 diff library to compute the diff.
2328
2329 *E106*
2330 The optional "output" item in {options} specifies the returned
2331 diff format. The following values are supported:
2332 indices Return a List of the starting and ending
2333 indices and a count of the strings in each
2334 diff hunk.
2335 unified Return the unified diff output as a String.
2336 This is the default.
2337
2338 If the "output" item in {options} is "indices", then a List is
2339 returned. Each List item contains a Dict with the following
2340 items for each diff hunk:
2341 from_idx start index in {fromlist} for this diff hunk.
2342 from_count number of strings in {fromlist} that are
2343 added/removed/modified in this diff hunk.
2344 to_idx start index in {tolist} for this diff hunk.
2345 to_count number of strings in {tolist} that are
2346 added/removed/modified in this diff hunk.
2347
2348 The {options} Dict argument also specifies diff options
2349 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002350 algorithm Dict specifying the diff algorithm to
2351 use. Supported boolean items are
2352 "myers", "minimal", "patience" and
2353 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002354 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002355 iblank ignore changes where lines are all
2356 blank.
2357 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002358 indent-heuristic use the indent heuristic for the
2359 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002360 iwhite ignore changes in amount of white
2361 space.
2362 iwhiteall ignore all white space changes.
2363 iwhiteeol ignore white space changes at end of
2364 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002365 For more information about these options, refer to 'diffopt'.
2366
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002367 To compute the unified diff, all the items in {fromlist} are
2368 concatenated into a string using a newline separator and the
2369 same for {tolist}. The unified diff output uses line numbers.
2370
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002371 Returns an empty List or String if {fromlist} and {tolist} are
2372 identical.
2373
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002374 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002375 :echo diff(['abc'], ['xxx'])
2376 @@ -1 +1 @@
2377 -abc
2378 +xxx
2379
2380 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2381 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2382 :echo diff(readfile('oldfile'), readfile('newfile'))
2383 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002384<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002385 For more examples, refer to |diff-func-examples|
2386
2387 Can also be used as a |method|: >
2388 GetFromList->diff(to_list)
2389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002390 Return type: |String| or list<dict<number>> or list<any>
2391 depending on {options}
2392
2393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002394diff_filler({lnum}) *diff_filler()*
2395 Returns the number of filler lines above line {lnum}.
2396 These are the lines that were inserted at this point in
2397 another diff'ed window. These filler lines are shown in the
2398 display but don't exist in the buffer.
2399 {lnum} is used like with |getline()|. Thus "." is the current
2400 line, "'m" mark m, etc.
2401 Returns 0 if the current window is not in diff mode.
2402
2403 Can also be used as a |method|: >
2404 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002405<
2406 Return type: |Number|
2407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002408
2409diff_hlID({lnum}, {col}) *diff_hlID()*
2410 Returns the highlight ID for diff mode at line {lnum} column
2411 {col} (byte index). When the current line does not have a
2412 diff change zero is returned.
2413 {lnum} is used like with |getline()|. Thus "." is the current
2414 line, "'m" mark m, etc.
2415 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2416 line.
2417 The highlight ID can be used with |synIDattr()| to obtain
2418 syntax information about the highlighting.
2419
2420 Can also be used as a |method|: >
2421 GetLnum()->diff_hlID(col)
2422<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002423 Return type: |Number|
2424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002425
2426digraph_get({chars}) *digraph_get()* *E1214*
2427 Return the digraph of {chars}. This should be a string with
2428 exactly two characters. If {chars} are not just two
2429 characters, or the digraph of {chars} does not exist, an error
2430 is given and an empty string is returned.
2431
2432 The character will be converted from Unicode to 'encoding'
2433 when needed. This does require the conversion to be
2434 available, it might fail.
2435
2436 Also see |digraph_getlist()|.
2437
2438 Examples: >
2439 " Get a built-in digraph
2440 :echo digraph_get('00') " Returns '∞'
2441
2442 " Get a user-defined digraph
2443 :call digraph_set('aa', 'あ')
2444 :echo digraph_get('aa') " Returns 'あ'
2445<
2446 Can also be used as a |method|: >
2447 GetChars()->digraph_get()
2448<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002449 Return type: |String|
2450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002451 This function works only when compiled with the |+digraphs|
2452 feature. If this feature is disabled, this function will
2453 display an error message.
2454
2455
2456digraph_getlist([{listall}]) *digraph_getlist()*
2457 Return a list of digraphs. If the {listall} argument is given
2458 and it is TRUE, return all digraphs, including the default
2459 digraphs. Otherwise, return only user-defined digraphs.
2460
2461 The characters will be converted from Unicode to 'encoding'
2462 when needed. This does require the conservation to be
2463 available, it might fail.
2464
2465 Also see |digraph_get()|.
2466
2467 Examples: >
2468 " Get user-defined digraphs
2469 :echo digraph_getlist()
2470
2471 " Get all the digraphs, including default digraphs
2472 :echo digraph_getlist(1)
2473<
2474 Can also be used as a |method|: >
2475 GetNumber()->digraph_getlist()
2476<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002477 Return type: list<list<string>>
2478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002479 This function works only when compiled with the |+digraphs|
2480 feature. If this feature is disabled, this function will
2481 display an error message.
2482
2483
Bram Moolenaara2baa732022-02-04 16:09:54 +00002484digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002485 Add digraph {chars} to the list. {chars} must be a string
2486 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002487 encoded character. *E1215*
2488 Be careful, composing characters are NOT ignored. This
2489 function is similar to |:digraphs| command, but useful to add
2490 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002491
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002492 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002493 this fails an error message is given and v:false is returned.
2494
2495 If you want to define multiple digraphs at once, you can use
2496 |digraph_setlist()|.
2497
2498 Example: >
2499 call digraph_set(' ', 'あ')
2500<
2501 Can be used as a |method|: >
2502 GetString()->digraph_set('あ')
2503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002504 Return type: |vim9-boolean|
2505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002506 This function works only when compiled with the |+digraphs|
2507 feature. If this feature is disabled, this function will
2508 display an error message.
2509
2510
2511digraph_setlist({digraphlist}) *digraph_setlist()*
2512 Similar to |digraph_set()| but this function can add multiple
2513 digraphs at once. {digraphlist} is a list composed of lists,
2514 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002515 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002516 Example: >
2517 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2518<
2519 It is similar to the following: >
2520 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2521 call digraph_set(chars, digraph)
2522 endfor
2523< Except that the function returns after the first error,
2524 following digraphs will not be added.
2525
2526 Can be used as a |method|: >
2527 GetList()->digraph_setlist()
2528<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002529 Return type: |vim9-boolean|
2530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002531 This function works only when compiled with the |+digraphs|
2532 feature. If this feature is disabled, this function will
2533 display an error message.
2534
2535
2536echoraw({string}) *echoraw()*
2537 Output {string} as-is, including unprintable characters.
2538 This can be used to output a terminal code. For example, to
2539 disable modifyOtherKeys: >
2540 call echoraw(&t_TE)
2541< and to enable it again: >
2542 call echoraw(&t_TI)
2543< Use with care, you can mess up the terminal this way.
2544
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002545 Return type: |Number|
2546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002547
2548empty({expr}) *empty()*
2549 Return the Number 1 if {expr} is empty, zero otherwise.
2550 - A |List| or |Dictionary| is empty when it does not have any
2551 items.
2552 - A |String| is empty when its length is zero.
2553 - A |Number| and |Float| are empty when their value is zero.
2554 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2555 - A |Job| is empty when it failed to start.
2556 - A |Channel| is empty when it is closed.
2557 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002558 - An |Object| is empty, when the empty() method in the object
2559 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002560
2561 For a long |List| this is much faster than comparing the
2562 length with zero.
2563
2564 Can also be used as a |method|: >
2565 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002566<
2567 Return type: |Number|
2568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002569
2570environ() *environ()*
2571 Return all of environment variables as dictionary. You can
2572 check if an environment variable exists like this: >
2573 :echo has_key(environ(), 'HOME')
2574< Note that the variable name may be CamelCase; to ignore case
2575 use this: >
2576 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002577<
2578 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002579
Bram Moolenaar416bd912023-07-07 23:19:18 +01002580
2581err_teapot([{expr}]) *err_teapot()*
2582 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002583 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002584 If {expr} is present and it is TRUE error 503 is given,
2585 indicating that coffee is temporarily not available.
2586 If {expr} is present it must be a String.
2587
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002588 Return type: |Number|
2589
Bram Moolenaar416bd912023-07-07 23:19:18 +01002590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002591escape({string}, {chars}) *escape()*
2592 Escape the characters in {chars} that occur in {string} with a
2593 backslash. Example: >
2594 :echo escape('c:\program files\vim', ' \')
2595< results in: >
2596 c:\\program\ files\\vim
2597< Also see |shellescape()| and |fnameescape()|.
2598
2599 Can also be used as a |method|: >
2600 GetText()->escape(' \')
2601<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002602 Return type: |String|
2603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002604 *eval()*
2605eval({string}) Evaluate {string} and return the result. Especially useful to
2606 turn the result of |string()| back into the original value.
2607 This works for Numbers, Floats, Strings, Blobs and composites
2608 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002609 functions. In |Vim9| script, it can be used to obtain |enum|
2610 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002611
2612 Can also be used as a |method|: >
2613 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002614<
2615 Return type: any, depending on {string}
2616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002617
2618eventhandler() *eventhandler()*
2619 Returns 1 when inside an event handler. That is that Vim got
2620 interrupted while waiting for the user to type a character,
2621 e.g., when dropping a file on Vim. This means interactive
2622 commands cannot be used. Otherwise zero is returned.
2623
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002624 Return type: |Number|
2625
2626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002627executable({expr}) *executable()*
2628 This function checks if an executable with the name {expr}
2629 exists. {expr} must be the name of the program without any
2630 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002632 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002633 searchpath for programs.
2634 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002635 On MS-Windows the ".exe", ".bat", etc. can optionally be
2636 included. Then the extensions in $PATHEXT are tried. Thus if
2637 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2638 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2639 by itself can be used in $PATHEXT to try using the name
2640 without an extension. When 'shell' looks like a Unix shell,
2641 then the name is also tried without adding an extension.
2642 On MS-Windows it only checks if the file exists and is not a
2643 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002644 On MS-Windows an executable in the same directory as the Vim
2645 executable is always found. Since this directory is added to
2646 $PATH it should also work to execute it |win32-PATH|.
2647 *NoDefaultCurrentDirectoryInExePath*
2648 On MS-Windows an executable in Vim's current working directory
2649 is also normally found, but this can be disabled by setting
2650 the $NoDefaultCurrentDirectoryInExePath environment variable.
2651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002652 The result is a Number:
2653 1 exists
2654 0 does not exist
2655 -1 not implemented on this system
2656 |exepath()| can be used to get the full path of an executable.
2657
2658 Can also be used as a |method|: >
2659 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002660<
2661 Return type: |Number|
2662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002663
2664execute({command} [, {silent}]) *execute()*
2665 Execute an Ex command or commands and return the output as a
2666 string.
2667 {command} can be a string or a List. In case of a List the
2668 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002669 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002670 redir => var
2671 {command}
2672 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002673< Except that line continuation in {command} is not recognized.
2674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002675 The optional {silent} argument can have these values:
2676 "" no `:silent` used
2677 "silent" `:silent` used
2678 "silent!" `:silent!` used
2679 The default is "silent". Note that with "silent!", unlike
2680 `:redir`, error messages are dropped. When using an external
2681 command the screen may be messed up, use `system()` instead.
2682 *E930*
2683 It is not possible to use `:redir` anywhere in {command}.
2684
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002685 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002686 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002687
2688< To execute a command in another window than the current one
2689 use `win_execute()`.
2690
2691 When used recursively the output of the recursive call is not
2692 included in the output of the higher level call.
2693
2694 Can also be used as a |method|: >
2695 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002696<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002697 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002699
2700exepath({expr}) *exepath()*
2701 If {expr} is an executable and is either an absolute path, a
2702 relative path or found in $PATH, return the full path.
2703 Note that the current directory is used when {expr} starts
2704 with "./", which may be a problem for Vim: >
2705 echo exepath(v:progpath)
2706< If {expr} cannot be found in $PATH or is not executable then
2707 an empty string is returned.
2708
2709 Can also be used as a |method|: >
2710 GetCommand()->exepath()
2711<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002712 Return type: |String|
2713
2714
2715exists({expr}) *exists()*
2716 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002717 zero otherwise.
2718
2719 Note: In a compiled |:def| function the evaluation is done at
2720 runtime. Use `exists_compiled()` to evaluate the expression
2721 at compile time.
2722
2723 For checking for a supported feature use |has()|.
2724 For checking if a file exists use |filereadable()|.
2725
2726 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002727 varname internal variable (see
2728 dict.key |internal-variables|). Also works
2729 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002730 import.Func entries, |List| items, class and
2731 class.Func object methods, imported items, etc.
2732 object.Func Does not work for local variables in a
2733 class.varname compiled `:def` function.
2734 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002735 script, since it can be used as a
2736 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002737 Beware that evaluating an index may
2738 cause an error message for an invalid
2739 expression. E.g.: >
2740 :let l = [1, 2, 3]
2741 :echo exists("l[5]")
2742< 0 >
2743 :echo exists("l[xx]")
2744< E121: Undefined variable: xx
2745 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002746 &option-name Vim option (only checks if it exists,
2747 not if it really works)
2748 +option-name Vim option that works.
2749 $ENVNAME environment variable (could also be
2750 done by comparing with an empty
2751 string)
2752 *funcname built-in function (see |functions|)
2753 or user defined function (see
2754 |user-functions|) that is implemented.
2755 Also works for a variable that is a
2756 Funcref.
2757 ?funcname built-in function that could be
2758 implemented; to be used to check if
2759 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002760 :cmdname Ex command: built-in command, user
2761 command or command modifier |:command|.
2762 Returns:
2763 1 for match with start of a command
2764 2 full match with a command
2765 3 matches several user commands
2766 To check for a supported command
2767 always check the return value to be 2.
2768 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002769 :3match The |:3match| command (but you
2770 probably should not use it, it is
2771 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002772 #event autocommand defined for this event
2773 #event#pattern autocommand defined for this event and
2774 pattern (the pattern is taken
2775 literally and compared to the
2776 autocommand patterns character by
2777 character)
2778 #group autocommand group exists
2779 #group#event autocommand defined for this group and
2780 event.
2781 #group#event#pattern
2782 autocommand defined for this group,
2783 event and pattern.
2784 ##event autocommand for this event is
2785 supported.
2786
2787 Examples: >
2788 exists("&shortname")
2789 exists("$HOSTNAME")
2790 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002791 exists("*s:MyFunc") " only for legacy script
2792 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002793 exists("bufcount")
2794 exists(":Make")
2795 exists("#CursorHold")
2796 exists("#BufReadPre#*.gz")
2797 exists("#filetypeindent")
2798 exists("#filetypeindent#FileType")
2799 exists("#filetypeindent#FileType#*")
2800 exists("##ColorScheme")
2801< There must be no space between the symbol (&/$/*/#) and the
2802 name.
2803 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002804 a few cases this is ignored. That may become stricter in the
2805 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002806 Working example: >
2807 exists(":make")
2808< NOT working example: >
2809 exists(":make install")
2810
2811< Note that the argument must be a string, not the name of the
2812 variable itself. For example: >
2813 exists(bufcount)
2814< This doesn't check for existence of the "bufcount" variable,
2815 but gets the value of "bufcount", and checks if that exists.
2816
2817 Can also be used as a |method|: >
2818 Varname()->exists()
2819<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002820 Return type: |String|
2821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002822
2823exists_compiled({expr}) *exists_compiled()*
2824 Like `exists()` but evaluated at compile time. This is useful
2825 to skip a block where a function is used that would otherwise
2826 give an error: >
2827 if exists_compiled('*ThatFunction')
2828 ThatFunction('works')
2829 endif
2830< If `exists()` were used then a compilation error would be
2831 given if ThatFunction() is not defined.
2832
2833 {expr} must be a literal string. *E1232*
2834 Can only be used in a |:def| function. *E1233*
2835 This does not work to check for arguments or local variables.
2836
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002837 Return type: |String|
2838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002839
2840exp({expr}) *exp()*
2841 Return the exponential of {expr} as a |Float| in the range
2842 [0, inf].
2843 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002844 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002845 Examples: >
2846 :echo exp(2)
2847< 7.389056 >
2848 :echo exp(-1)
2849< 0.367879
2850
2851 Can also be used as a |method|: >
2852 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002853<
2854 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002855
2856
2857expand({string} [, {nosuf} [, {list}]]) *expand()*
2858 Expand wildcards and the following special keywords in
2859 {string}. 'wildignorecase' applies.
2860
2861 If {list} is given and it is |TRUE|, a List will be returned.
2862 Otherwise the result is a String and when there are several
2863 matches, they are separated by <NL> characters. [Note: in
2864 version 5.0 a space was used, which caused problems when a
2865 file name contains a space]
2866
2867 If the expansion fails, the result is an empty string. A name
2868 for a non-existing file is not included, unless {string} does
2869 not start with '%', '#' or '<', see below.
2870
Christian Brabandtec9c3262024-02-21 20:40:05 +01002871 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002872 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002874 When {string} starts with '%', '#' or '<', the expansion is
2875 done like for the |cmdline-special| variables with their
2876 associated modifiers. Here is a short overview:
2877
2878 % current file name
2879 # alternate file name
2880 #n alternate file name n
2881 <cfile> file name under the cursor
2882 <afile> autocmd file name
2883 <abuf> autocmd buffer number (as a String!)
2884 <amatch> autocmd matched name
2885 <cexpr> C expression under the cursor
2886 <sfile> sourced script file or function name
2887 <slnum> sourced script line number or function
2888 line number
2889 <sflnum> script file line number, also when in
2890 a function
2891 <SID> "<SNR>123_" where "123" is the
2892 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002893 <script> sourced script file, or script file
2894 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002895 <stack> call stack
2896 <cword> word under the cursor
2897 <cWORD> WORD under the cursor
2898 <client> the {clientid} of the last received
2899 message |server2client()|
2900 Modifiers:
2901 :p expand to full path
2902 :h head (last path component removed)
2903 :t tail (last path component only)
2904 :r root (one extension removed)
2905 :e extension only
2906
2907 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002908 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002909< Note that when expanding a string that starts with '%', '#' or
2910 '<', any following text is ignored. This does NOT work: >
2911 :let doesntwork = expand("%:h.bak")
2912< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002913 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002914< Also note that expanding "<cfile>" and others only returns the
2915 referenced file name without further expansion. If "<cfile>"
2916 is "~/.cshrc", you need to do another expand() to have the
2917 "~/" expanded into the path of the home directory: >
2918 :echo expand(expand("<cfile>"))
2919<
2920 There cannot be white space between the variables and the
2921 following modifier. The |fnamemodify()| function can be used
2922 to modify normal file names.
2923
2924 When using '%' or '#', and the current or alternate file name
2925 is not defined, an empty string is used. Using "%:p" in a
2926 buffer with no name, results in the current directory, with a
2927 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002928 When 'verbose' is set then expanding '%', '#' and <> items
2929 will result in an error message if the argument cannot be
2930 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002931
2932 When {string} does not start with '%', '#' or '<', it is
2933 expanded like a file name is expanded on the command line.
2934 'suffixes' and 'wildignore' are used, unless the optional
2935 {nosuf} argument is given and it is |TRUE|.
2936 Names for non-existing files are included. The "**" item can
2937 be used to search in a directory tree. For example, to find
2938 all "README" files in the current directory and below: >
2939 :echo expand("**/README")
2940<
2941 expand() can also be used to expand variables and environment
2942 variables that are only known in a shell. But this can be
2943 slow, because a shell may be used to do the expansion. See
2944 |expr-env-expand|.
2945 The expanded variable is still handled like a list of file
2946 names. When an environment variable cannot be expanded, it is
2947 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2948 "$FOOBAR".
2949
2950 See |glob()| for finding existing files. See |system()| for
2951 getting the raw output of an external command.
2952
2953 Can also be used as a |method|: >
2954 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002955<
2956 Return type: |String| or list<string> depending on {list}
2957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002958
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002959expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002960 Expand special items in String {string} like what is done for
2961 an Ex command such as `:edit`. This expands special keywords,
2962 like with |expand()|, and environment variables, anywhere in
2963 {string}. "~user" and "~/path" are only expanded at the
2964 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002965
2966 The following items are supported in the {options} Dict
2967 argument:
2968 errmsg If set to TRUE, error messages are displayed
2969 if an error is encountered during expansion.
2970 By default, error messages are not displayed.
2971
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002972 Returns the expanded string. If an error is encountered
2973 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002974
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002975 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002976 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002977 make /path/runtime/doc/builtin.o
2978 :echo expandcmd('make %<.o', {'errmsg': v:true})
2979<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002980 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002981 GetCommand()->expandcmd()
2982<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002983 Return type: |String| or list<string> depending on {list}
2984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002985extend({expr1}, {expr2} [, {expr3}]) *extend()*
2986 {expr1} and {expr2} must be both |Lists| or both
2987 |Dictionaries|.
2988
2989 If they are |Lists|: Append {expr2} to {expr1}.
2990 If {expr3} is given insert the items of {expr2} before the
2991 item with index {expr3} in {expr1}. When {expr3} is zero
2992 insert before the first item. When {expr3} is equal to
2993 len({expr1}) then {expr2} is appended.
2994 Examples: >
2995 :echo sort(extend(mylist, [7, 5]))
2996 :call extend(mylist, [2, 3], 1)
2997< When {expr1} is the same List as {expr2} then the number of
2998 items copied is equal to the original length of the List.
2999 E.g., when {expr3} is 1 you get N new copies of the first item
3000 (where N is the original length of the List).
3001 Use |add()| to concatenate one item to a list. To concatenate
3002 two lists into a new list use the + operator: >
3003 :let newlist = [1, 2, 3] + [4, 5]
3004<
3005 If they are |Dictionaries|:
3006 Add all entries from {expr2} to {expr1}.
3007 If a key exists in both {expr1} and {expr2} then {expr3} is
3008 used to decide what to do:
3009 {expr3} = "keep": keep the value of {expr1}
3010 {expr3} = "force": use the value of {expr2}
3011 {expr3} = "error": give an error message *E737*
3012 When {expr3} is omitted then "force" is assumed.
3013
3014 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003015 make a copy of {expr1} first or use |extendnew()| to return a
3016 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003017 {expr2} remains unchanged.
3018 When {expr1} is locked and {expr2} is not empty the operation
3019 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003020 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003021
3022 Can also be used as a |method|: >
3023 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003024<
3025 Return type: list<{type}> or dict<{type}> depending on {expr1}
3026 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003027
3028
3029extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3030 Like |extend()| but instead of adding items to {expr1} a new
3031 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003032 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003034 Return type: list<{type}> or dict<{type}> depending on {expr1}
3035 and {expr2}, in case of error: |Number|
3036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003037
3038feedkeys({string} [, {mode}]) *feedkeys()*
3039 Characters in {string} are queued for processing as if they
3040 come from a mapping or were typed by the user.
3041
3042 By default the string is added to the end of the typeahead
3043 buffer, thus if a mapping is still being executed the
3044 characters come after them. Use the 'i' flag to insert before
3045 other characters, they will be executed next, before any
3046 characters from a mapping.
3047
3048 The function does not wait for processing of keys contained in
3049 {string}.
3050
3051 To include special keys into {string}, use double-quotes
3052 and "\..." notation |expr-quote|. For example,
3053 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3054 feedkeys('\<CR>') pushes 5 characters.
3055 A special code that might be useful is <Ignore>, it exits the
3056 wait for a character without doing anything. *<Ignore>*
3057
3058 {mode} is a String, which can contain these character flags:
3059 'm' Remap keys. This is default. If {mode} is absent,
3060 keys are remapped.
3061 'n' Do not remap keys.
3062 't' Handle keys as if typed; otherwise they are handled as
3063 if coming from a mapping. This matters for undo,
3064 opening folds, etc.
3065 'L' Lowlevel input. Only works for Unix or when using the
3066 GUI. Keys are used as if they were coming from the
3067 terminal. Other flags are not used. *E980*
3068 When a CTRL-C interrupts and 't' is included it sets
3069 the internal "got_int" flag.
3070 'i' Insert the string instead of appending (see above).
3071 'x' Execute commands until typeahead is empty. This is
3072 similar to using ":normal!". You can call feedkeys()
3073 several times without 'x' and then one time with 'x'
3074 (possibly with an empty {string}) to execute all the
3075 typeahead. Note that when Vim ends in Insert mode it
3076 will behave as if <Esc> is typed, to avoid getting
3077 stuck, waiting for a character to be typed before the
3078 script continues.
3079 Note that if you manage to call feedkeys() while
3080 executing commands, thus calling it recursively, then
3081 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003082 'c' Remove any script context when executing, so that
3083 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003084 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003085 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003086 '!' When used with 'x' will not end Insert mode. Can be
3087 used in a test when a timer is set to exit Insert mode
3088 a little later. Useful for testing CursorHoldI.
3089
3090 Return value is always 0.
3091
3092 Can also be used as a |method|: >
3093 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003094<
3095 Return type: |String| or list<string> depending on {list}
3096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003097
Shougo Matsushita60c87432024-06-03 22:59:27 +02003098filecopy({from}, {to}) *filecopy()*
3099 Copy the file pointed to by the name {from} to {to}. The
3100 result is a Number, which is |TRUE| if the file was copied
3101 successfully, and |FALSE| when it failed.
3102 If a file with name {to} already exists, it will fail.
3103 Note that it does not handle directories (yet).
3104
3105 This function is not available in the |sandbox|.
3106
3107 Can also be used as a |method|: >
3108 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003109<
3110 Return type: |Number|
3111
Shougo Matsushita60c87432024-06-03 22:59:27 +02003112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003113filereadable({file}) *filereadable()*
3114 The result is a Number, which is |TRUE| when a file with the
3115 name {file} exists, and can be read. If {file} doesn't exist,
3116 or is a directory, the result is |FALSE|. {file} is any
3117 expression, which is used as a String.
3118 If you don't care about the file being readable you can use
3119 |glob()|.
3120 {file} is used as-is, you may want to expand wildcards first: >
3121 echo filereadable('~/.vimrc')
3122 0
3123 echo filereadable(expand('~/.vimrc'))
3124 1
3125
3126< Can also be used as a |method|: >
3127 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003128<
3129 Return type: |Number|
3130
3131 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003132 Obsolete name: file_readable().
3133
3134
3135filewritable({file}) *filewritable()*
3136 The result is a Number, which is 1 when a file with the
3137 name {file} exists, and can be written. If {file} doesn't
3138 exist, or is not writable, the result is 0. If {file} is a
3139 directory, and we can write to it, the result is 2.
3140
3141 Can also be used as a |method|: >
3142 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003143<
3144 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003145
3146
3147filter({expr1}, {expr2}) *filter()*
3148 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3149 For each item in {expr1} evaluate {expr2} and when the result
3150 is zero or false remove the item from the |List| or
3151 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003152 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003153
3154 {expr2} must be a |string| or |Funcref|.
3155
3156 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3157 of the current item. For a |Dictionary| |v:key| has the key
3158 of the current item and for a |List| |v:key| has the index of
3159 the current item. For a |Blob| |v:key| has the index of the
3160 current byte. For a |String| |v:key| has the index of the
3161 current character.
3162 Examples: >
3163 call filter(mylist, 'v:val !~ "OLD"')
3164< Removes the items where "OLD" appears. >
3165 call filter(mydict, 'v:key >= 8')
3166< Removes the items with a key below 8. >
3167 call filter(var, 0)
3168< Removes all the items, thus clears the |List| or |Dictionary|.
3169
3170 Note that {expr2} is the result of expression and is then
3171 used as an expression again. Often it is good to use a
3172 |literal-string| to avoid having to double backslashes.
3173
3174 If {expr2} is a |Funcref| it must take two arguments:
3175 1. the key or the index of the current item.
3176 2. the value of the current item.
3177 The function must return |TRUE| if the item should be kept.
3178 Example that keeps the odd items of a list: >
3179 func Odd(idx, val)
3180 return a:idx % 2 == 1
3181 endfunc
3182 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003183< It is shorter when using a |lambda|. In |Vim9| syntax: >
3184 call filter(myList, (idx, val) => idx * val <= 42)
3185< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003186 call filter(myList, {idx, val -> idx * val <= 42})
3187< If you do not use "val" you can leave it out: >
3188 call filter(myList, {idx -> idx % 2 == 1})
3189<
3190 In |Vim9| script the result must be true, false, zero or one.
3191 Other values will result in a type error.
3192
3193 For a |List| and a |Dictionary| the operation is done
3194 in-place. If you want it to remain unmodified make a copy
3195 first: >
3196 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3197
3198< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003199 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003200 When an error is encountered while evaluating {expr2} no
3201 further items in {expr1} are processed.
3202 When {expr2} is a Funcref errors inside a function are ignored,
3203 unless it was defined with the "abort" flag.
3204
3205 Can also be used as a |method|: >
3206 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003207<
3208 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3209 depending on {expr1}
3210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003211
3212finddir({name} [, {path} [, {count}]]) *finddir()*
3213 Find directory {name} in {path}. Supports both downwards and
3214 upwards recursive directory searches. See |file-searching|
3215 for the syntax of {path}.
3216
3217 Returns the path of the first found match. When the found
3218 directory is below the current directory a relative path is
3219 returned. Otherwise a full path is returned.
3220 If {path} is omitted or empty then 'path' is used.
3221
3222 If the optional {count} is given, find {count}'s occurrence of
3223 {name} in {path} instead of the first one.
3224 When {count} is negative return all the matches in a |List|.
3225
Bram Moolenaar016188f2022-06-06 20:52:59 +01003226 Returns an empty string if the directory is not found.
3227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003228 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003229
3230 Can also be used as a |method|: >
3231 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003232<
3233 Return type: |String|
3234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003235
3236findfile({name} [, {path} [, {count}]]) *findfile()*
3237 Just like |finddir()|, but find a file instead of a directory.
3238 Uses 'suffixesadd'.
3239 Example: >
3240 :echo findfile("tags.vim", ".;")
3241< Searches from the directory of the current file upwards until
3242 it finds the file "tags.vim".
3243
3244 Can also be used as a |method|: >
3245 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003246<
3247 Return type: |String|
3248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003249
3250flatten({list} [, {maxdepth}]) *flatten()*
3251 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3252 the result is a |List| without nesting, as if {maxdepth} is
3253 a very large number.
3254 The {list} is changed in place, use |flattennew()| if you do
3255 not want that.
3256 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003257 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003258 *E900*
3259 {maxdepth} means how deep in nested lists changes are made.
3260 {list} is not modified when {maxdepth} is 0.
3261 {maxdepth} must be positive number.
3262
3263 If there is an error the number zero is returned.
3264
3265 Example: >
3266 :echo flatten([1, [2, [3, 4]], 5])
3267< [1, 2, 3, 4, 5] >
3268 :echo flatten([1, [2, [3, 4]], 5], 1)
3269< [1, 2, [3, 4], 5]
3270
3271 Can also be used as a |method|: >
3272 mylist->flatten()
3273<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003274 Return type: list<{type}>
3275
3276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003277flattennew({list} [, {maxdepth}]) *flattennew()*
3278 Like |flatten()| but first make a copy of {list}.
3279
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003280 Return type: list<{type}>
3281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003282
3283float2nr({expr}) *float2nr()*
3284 Convert {expr} to a Number by omitting the part after the
3285 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003286 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003287 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003288 When the value of {expr} is out of range for a |Number| the
3289 result is truncated to 0x7fffffff or -0x7fffffff (or when
3290 64-bit Number support is enabled, 0x7fffffffffffffff or
3291 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3292 64-bit Number support is enabled, -0x8000000000000000).
3293 Examples: >
3294 echo float2nr(3.95)
3295< 3 >
3296 echo float2nr(-23.45)
3297< -23 >
3298 echo float2nr(1.0e100)
3299< 2147483647 (or 9223372036854775807) >
3300 echo float2nr(-1.0e150)
3301< -2147483647 (or -9223372036854775807) >
3302 echo float2nr(1.0e-100)
3303< 0
3304
3305 Can also be used as a |method|: >
3306 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003307<
3308 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003309
3310
3311floor({expr}) *floor()*
3312 Return the largest integral value less than or equal to
3313 {expr} as a |Float| (round down).
3314 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003315 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003316 Examples: >
3317 echo floor(1.856)
3318< 1.0 >
3319 echo floor(-5.456)
3320< -6.0 >
3321 echo floor(4.0)
3322< 4.0
3323
3324 Can also be used as a |method|: >
3325 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003326<
3327 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003328
3329
3330fmod({expr1}, {expr2}) *fmod()*
3331 Return the remainder of {expr1} / {expr2}, even if the
3332 division is not representable. Returns {expr1} - i * {expr2}
3333 for some integer i such that if {expr2} is non-zero, the
3334 result has the same sign as {expr1} and magnitude less than
3335 the magnitude of {expr2}. If {expr2} is zero, the value
3336 returned is zero. The value returned is a |Float|.
3337 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003338 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3339 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003340 Examples: >
3341 :echo fmod(12.33, 1.22)
3342< 0.13 >
3343 :echo fmod(-12.33, 1.22)
3344< -0.13
3345
3346 Can also be used as a |method|: >
3347 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003348<
3349 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003350
3351
3352fnameescape({string}) *fnameescape()*
3353 Escape {string} for use as file name command argument. All
3354 characters that have a special meaning, such as '%' and '|'
3355 are escaped with a backslash.
3356 For most systems the characters escaped are
3357 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3358 appears in a filename, it depends on the value of 'isfname'.
3359 A leading '+' and '>' is also escaped (special after |:edit|
3360 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003361 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003362 Example: >
3363 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003364 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003365< results in executing: >
3366 edit \+some\ str\%nge\|name
3367<
3368 Can also be used as a |method|: >
3369 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003370<
3371 Return type: |String|
3372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003373
3374fnamemodify({fname}, {mods}) *fnamemodify()*
3375 Modify file name {fname} according to {mods}. {mods} is a
3376 string of characters like it is used for file names on the
3377 command line. See |filename-modifiers|.
3378 Example: >
3379 :echo fnamemodify("main.c", ":p:h")
3380< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003381 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003382< If {mods} is empty or an unsupported modifier is used then
3383 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003384 When {fname} is empty then with {mods} ":h" returns ".", so
3385 that `:cd` can be used with it. This is different from
3386 expand('%:h') without a buffer name, which returns an empty
3387 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003388 Note: Environment variables don't work in {fname}, use
3389 |expand()| first then.
3390
3391 Can also be used as a |method|: >
3392 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003393<
3394 Return type: |String|
3395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003396
3397foldclosed({lnum}) *foldclosed()*
3398 The result is a Number. If the line {lnum} is in a closed
3399 fold, the result is the number of the first line in that fold.
3400 If the line {lnum} is not in a closed fold, -1 is returned.
3401 {lnum} is used like with |getline()|. Thus "." is the current
3402 line, "'m" mark m, etc.
3403
3404 Can also be used as a |method|: >
3405 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003406<
3407 Return type: |Number|
3408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003409
3410foldclosedend({lnum}) *foldclosedend()*
3411 The result is a Number. If the line {lnum} is in a closed
3412 fold, the result is the number of the last line in that fold.
3413 If the line {lnum} is not in a closed fold, -1 is returned.
3414 {lnum} is used like with |getline()|. Thus "." is the current
3415 line, "'m" mark m, etc.
3416
3417 Can also be used as a |method|: >
3418 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003419<
3420 Return type: |Number|
3421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003422
3423foldlevel({lnum}) *foldlevel()*
3424 The result is a Number, which is the foldlevel of line {lnum}
3425 in the current buffer. For nested folds the deepest level is
3426 returned. If there is no fold at line {lnum}, zero is
3427 returned. It doesn't matter if the folds are open or closed.
3428 When used while updating folds (from 'foldexpr') -1 is
3429 returned for lines where folds are still to be updated and the
3430 foldlevel is unknown. As a special case the level of the
3431 previous line is usually available.
3432 {lnum} is used like with |getline()|. Thus "." is the current
3433 line, "'m" mark m, etc.
3434
3435 Can also be used as a |method|: >
3436 GetLnum()->foldlevel()
3437<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003438 Return type: |Number|
3439
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003440 *foldtext()*
3441foldtext() Returns a String, to be displayed for a closed fold. This is
3442 the default function used for the 'foldtext' option and should
3443 only be called from evaluating 'foldtext'. It uses the
3444 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3445 The returned string looks like this: >
3446 +-- 45 lines: abcdef
3447< The number of leading dashes depends on the foldlevel. The
3448 "45" is the number of lines in the fold. "abcdef" is the text
3449 in the first non-blank line of the fold. Leading white space,
3450 "//" or "/*" and the text from the 'foldmarker' and
3451 'commentstring' options is removed.
3452 When used to draw the actual foldtext, the rest of the line
3453 will be filled with the fold char from the 'fillchars'
3454 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003455 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003456
3457 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003458 {not available when compiled without the |+folding| feature}
3459
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003461foldtextresult({lnum}) *foldtextresult()*
3462 Returns the text that is displayed for the closed fold at line
3463 {lnum}. Evaluates 'foldtext' in the appropriate context.
3464 When there is no closed fold at {lnum} an empty string is
3465 returned.
3466 {lnum} is used like with |getline()|. Thus "." is the current
3467 line, "'m" mark m, etc.
3468 Useful when exporting folded text, e.g., to HTML.
3469 {not available when compiled without the |+folding| feature}
3470
3471
3472 Can also be used as a |method|: >
3473 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003474<
3475 Return type: |String|
3476
Ernie Raele79e2072024-01-13 11:47:33 +01003477
3478foreach({expr1}, {expr2}) *foreach()*
3479 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3480 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003481 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003482 See |map()| and |filter()| to modify {expr1}.
3483
3484 {expr2} must be a |string| or |Funcref|.
3485
3486 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3487 of the current item. For a |Dictionary| |v:key| has the key
3488 of the current item and for a |List| |v:key| has the index of
3489 the current item. For a |Blob| |v:key| has the index of the
3490 current byte. For a |String| |v:key| has the index of the
3491 current character.
3492 Examples: >
3493 call foreach(mylist, 'used[v:val] = true')
3494< This records the items that are in the {expr1} list.
3495
3496 Note that {expr2} is the result of expression and is then used
3497 as a command. Often it is good to use a |literal-string| to
3498 avoid having to double backslashes.
3499
3500 If {expr2} is a |Funcref| it must take two arguments:
3501 1. the key or the index of the current item.
3502 2. the value of the current item.
3503 With a legacy script lambda you don't get an error if it only
3504 accepts one argument, but with a Vim9 lambda you get "E1106:
3505 One argument too many", the number of arguments must match.
3506 If the function returns a value, it is ignored.
3507
3508 Returns {expr1} in all cases.
3509 When an error is encountered while executing {expr2} no
3510 further items in {expr1} are processed.
3511 When {expr2} is a Funcref errors inside a function are ignored,
3512 unless it was defined with the "abort" flag.
3513
3514 Can also be used as a |method|: >
3515 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003516<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003517 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3518 depending on {expr1}
3519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003520 *foreground()*
3521foreground() Move the Vim window to the foreground. Useful when sent from
3522 a client to a Vim server. |remote_send()|
3523 On Win32 systems this might not work, the OS does not always
3524 allow a window to bring itself to the foreground. Use
3525 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003526
3527 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003528 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003529 Win32 console version}
3530
Bram Moolenaaraa534142022-09-15 21:46:02 +01003531fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003532 Get the full command name from a short abbreviated command
3533 name; see |20.2| for details on command abbreviations.
3534
3535 The string argument {name} may start with a `:` and can
3536 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003537 Returns an empty string if a command doesn't exist, if it's
3538 ambiguous (for user-defined commands) or cannot be shortened
3539 this way. |vim9-no-shorten|
3540
3541 Without the {vim9} argument uses the current script version.
3542 If {vim9} is present and FALSE then legacy script rules are
3543 used. When {vim9} is present and TRUE then Vim9 rules are
3544 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003545
3546 For example `fullcommand('s')`, `fullcommand('sub')`,
3547 `fullcommand(':%substitute')` all return "substitute".
3548
3549 Can also be used as a |method|: >
3550 GetName()->fullcommand()
3551<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003552 Return type: |String|
3553
3554
3555funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003556 Just like |function()|, but the returned Funcref will lookup
3557 the function by reference, not by name. This matters when the
3558 function {name} is redefined later.
3559
3560 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003561 It only works for an autoloaded function if it has already
3562 been loaded (to avoid mistakenly loading the autoload script
3563 when only intending to use the function name, use |function()|
3564 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003565 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003566
3567 Can also be used as a |method|: >
3568 GetFuncname()->funcref([arg])
3569<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003570 Return type: func(...): any or |Number| on error
3571
Dominique Pellee764d1b2023-03-12 21:20:59 +00003572 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003573function({name} [, {arglist}] [, {dict}])
3574 Return a |Funcref| variable that refers to function {name}.
3575 {name} can be the name of a user defined function or an
3576 internal function.
3577
3578 {name} can also be a Funcref or a partial. When it is a
3579 partial the dict stored in it will be used and the {dict}
3580 argument is not allowed. E.g.: >
3581 let FuncWithArg = function(dict.Func, [arg])
3582 let Broken = function(dict.Func, [arg], dict)
3583<
3584 When using the Funcref the function will be found by {name},
3585 also when it was redefined later. Use |funcref()| to keep the
3586 same function.
3587
3588 When {arglist} or {dict} is present this creates a partial.
3589 That means the argument list and/or the dictionary is stored in
3590 the Funcref and will be used when the Funcref is called.
3591
3592 The arguments are passed to the function in front of other
3593 arguments, but after any argument from |method|. Example: >
3594 func Callback(arg1, arg2, name)
3595 ...
3596 let Partial = function('Callback', ['one', 'two'])
3597 ...
3598 call Partial('name')
3599< Invokes the function as with: >
3600 call Callback('one', 'two', 'name')
3601
3602< With a |method|: >
3603 func Callback(one, two, three)
3604 ...
3605 let Partial = function('Callback', ['two'])
3606 ...
3607 eval 'one'->Partial('three')
3608< Invokes the function as with: >
3609 call Callback('one', 'two', 'three')
3610
3611< The function() call can be nested to add more arguments to the
3612 Funcref. The extra arguments are appended to the list of
3613 arguments. Example: >
3614 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003615 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003616 let Func = function('Callback', ['one'])
3617 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003618 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003619 call Func2('name')
3620< Invokes the function as with: >
3621 call Callback('one', 'two', 'name')
3622
3623< The Dictionary is only useful when calling a "dict" function.
3624 In that case the {dict} is passed in as "self". Example: >
3625 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003626 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003627 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003628 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003629 let context = {"name": "example"}
3630 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003631 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003632 call Func() " will echo: called for example
3633< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003634 arguments, these two are equivalent, if Callback() is defined
3635 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003636 let Func = function('Callback', context)
3637 let Func = context.Callback
3638
3639< The argument list and the Dictionary can be combined: >
3640 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003641 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003642 let context = {"name": "example"}
3643 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003644 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003645 call Func(500)
3646< Invokes the function as with: >
3647 call context.Callback('one', 500)
3648<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003649 Returns 0 on error.
3650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003651 Can also be used as a |method|: >
3652 GetFuncname()->function([arg])
3653
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003654<
3655 Return type: func(...): any or |Number| on error
3656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003657
3658garbagecollect([{atexit}]) *garbagecollect()*
3659 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3660 that have circular references.
3661
3662 There is hardly ever a need to invoke this function, as it is
3663 automatically done when Vim runs out of memory or is waiting
3664 for the user to press a key after 'updatetime'. Items without
3665 circular references are always freed when they become unused.
3666 This is useful if you have deleted a very big |List| and/or
3667 |Dictionary| with circular references in a script that runs
3668 for a long time.
3669
3670 When the optional {atexit} argument is one, garbage
3671 collection will also be done when exiting Vim, if it wasn't
3672 done before. This is useful when checking for memory leaks.
3673
3674 The garbage collection is not done immediately but only when
3675 it's safe to perform. This is when waiting for the user to
3676 type a character. To force garbage collection immediately use
3677 |test_garbagecollect_now()|.
3678
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003679 Return type: |String|
3680
3681
LemonBoy48b7d052024-07-09 18:24:59 +02003682get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003683 Get item {idx} from |List| {list}. When this item is not
3684 available return {default}. Return zero when {default} is
3685 omitted.
3686 Preferably used as a |method|: >
3687 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003688<
3689 Return type: any, depending on {list}
3690
LemonBoy48b7d052024-07-09 18:24:59 +02003691get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003692 Get byte {idx} from |Blob| {blob}. When this byte is not
3693 available return {default}. Return -1 when {default} is
3694 omitted.
3695 Preferably used as a |method|: >
3696 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003697<
3698 Return type: |Number|
3699
LemonBoy48b7d052024-07-09 18:24:59 +02003700get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003701 Get item with key {key} from |Dictionary| {dict}. When this
3702 item is not available return {default}. Return zero when
3703 {default} is omitted. Useful example: >
3704 let val = get(g:, 'var_name', 'default')
3705< This gets the value of g:var_name if it exists, and uses
3706 'default' when it does not exist.
3707 Preferably used as a |method|: >
3708 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003709<
h-east84ac2122024-06-17 18:12:30 +02003710 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003711
LemonBoy48b7d052024-07-09 18:24:59 +02003712get({func}, {what}) *get()-func*
3713 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003714 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003715 "name" The function name
3716 "func" The function
3717 "dict" The dictionary
3718 "args" The list with arguments
3719 "arity" A dictionary with information about the number of
3720 arguments accepted by the function (minus the
3721 {arglist}) with the following fields:
3722 required the number of positional arguments
3723 optional the number of optional arguments,
3724 in addition to the required ones
3725 varargs |TRUE| if the function accepts a
3726 variable number of arguments |...|
3727
3728 Note: There is no error, if the {arglist} of
3729 the Funcref contains more arguments than the
3730 Funcref expects, it's not validated.
3731
Bram Moolenaar016188f2022-06-06 20:52:59 +01003732 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003734 Preferably used as a |method|: >
3735 myfunc->get(what)
3736<
LemonBoy48b7d052024-07-09 18:24:59 +02003737 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003739 *getbufinfo()*
3740getbufinfo([{buf}])
3741getbufinfo([{dict}])
3742 Get information about buffers as a List of Dictionaries.
3743
3744 Without an argument information about all the buffers is
3745 returned.
3746
3747 When the argument is a |Dictionary| only the buffers matching
3748 the specified criteria are returned. The following keys can
3749 be specified in {dict}:
3750 buflisted include only listed buffers.
3751 bufloaded include only loaded buffers.
3752 bufmodified include only modified buffers.
3753
3754 Otherwise, {buf} specifies a particular buffer to return
3755 information for. For the use of {buf}, see |bufname()|
3756 above. If the buffer is found the returned List has one item.
3757 Otherwise the result is an empty list.
3758
3759 Each returned List item is a dictionary with the following
3760 entries:
3761 bufnr Buffer number.
3762 changed TRUE if the buffer is modified.
3763 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003764 command TRUE if the buffer belongs to the
3765 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003766 hidden TRUE if the buffer is hidden.
3767 lastused Timestamp in seconds, like
3768 |localtime()|, when the buffer was
3769 last used.
3770 {only with the |+viminfo| feature}
3771 listed TRUE if the buffer is listed.
3772 lnum Line number used for the buffer when
3773 opened in the current window.
3774 Only valid if the buffer has been
3775 displayed in the window in the past.
3776 If you want the line number of the
3777 last known cursor position in a given
3778 window, use |line()|: >
3779 :echo line('.', {winid})
3780<
3781 linecount Number of lines in the buffer (only
3782 valid when loaded)
3783 loaded TRUE if the buffer is loaded.
3784 name Full path to the file in the buffer.
3785 signs List of signs placed in the buffer.
3786 Each list item is a dictionary with
3787 the following fields:
3788 id sign identifier
3789 lnum line number
3790 name sign name
3791 variables A reference to the dictionary with
3792 buffer-local variables.
3793 windows List of |window-ID|s that display this
3794 buffer
3795 popups List of popup |window-ID|s that
3796 display this buffer
3797
3798 Examples: >
3799 for buf in getbufinfo()
3800 echo buf.name
3801 endfor
3802 for buf in getbufinfo({'buflisted':1})
3803 if buf.changed
3804 ....
3805 endif
3806 endfor
3807<
3808 To get buffer-local options use: >
3809 getbufvar({bufnr}, '&option_name')
3810<
3811 Can also be used as a |method|: >
3812 GetBufnr()->getbufinfo()
3813<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003814 Return type: list<dict<any>>
3815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003816
3817 *getbufline()*
3818getbufline({buf}, {lnum} [, {end}])
3819 Return a |List| with the lines starting from {lnum} to {end}
3820 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003821 |List| with only the line {lnum} is returned. See
3822 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003823
3824 For the use of {buf}, see |bufname()| above.
3825
3826 For {lnum} and {end} "$" can be used for the last line of the
3827 buffer. Otherwise a number must be used.
3828
3829 When {lnum} is smaller than 1 or bigger than the number of
3830 lines in the buffer, an empty |List| is returned.
3831
3832 When {end} is greater than the number of lines in the buffer,
3833 it is treated as {end} is set to the number of lines in the
3834 buffer. When {end} is before {lnum} an empty |List| is
3835 returned.
3836
3837 This function works only for loaded buffers. For unloaded and
3838 non-existing buffers, an empty |List| is returned.
3839
3840 Example: >
3841 :let lines = getbufline(bufnr("myfile"), 1, "$")
3842
3843< Can also be used as a |method|: >
3844 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003845<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003846 Return type: list<string>
3847
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003848 *getbufoneline()*
3849getbufoneline({buf}, {lnum})
3850 Just like `getbufline()` but only get one line and return it
3851 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003852
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003853 Return type: |String|
3854
3855
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003856getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3857 The result is the value of option or local buffer variable
3858 {varname} in buffer {buf}. Note that the name without "b:"
3859 must be used.
3860 The {varname} argument is a string.
3861 When {varname} is empty returns a |Dictionary| with all the
3862 buffer-local variables.
3863 When {varname} is equal to "&" returns a |Dictionary| with all
3864 the buffer-local options.
3865 Otherwise, when {varname} starts with "&" returns the value of
3866 a buffer-local option.
3867 This also works for a global or buffer-local option, but it
3868 doesn't work for a global variable, window-local variable or
3869 window-local option.
3870 For the use of {buf}, see |bufname()| above.
3871 When the buffer or variable doesn't exist {def} or an empty
3872 string is returned, there is no error message.
3873 Examples: >
3874 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003875 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003876
3877< Can also be used as a |method|: >
3878 GetBufnr()->getbufvar(varname)
3879<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003880 Return type: any, depending on {varname}
3881
3882
mikoto20001083cae2024-11-11 21:24:14 +01003883getcellpixels() *getcellpixels()*
3884 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003885 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003886
3887 Only works on Unix (terminal and gVim) and Windows (gVim only).
3888 Returns [] on other systems or on failure.
3889 Note that there could be variations across different terminals.
3890 On macOS, system Terminal.app returns sizes in points (before
3891 Retina scaling), whereas third-party terminals return raw pixel
3892 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003893
mikoto2000de094dc2024-11-14 22:13:48 +01003894 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003895
3896
Kota Kato66bb9ae2023-01-17 18:31:56 +00003897getcellwidths() *getcellwidths()*
3898 Returns a |List| of cell widths of character ranges overridden
3899 by |setcellwidths()|. The format is equal to the argument of
3900 |setcellwidths()|. If no character ranges have their cell
3901 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003902
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003903 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003904
3905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003906getchangelist([{buf}]) *getchangelist()*
3907 Returns the |changelist| for the buffer {buf}. For the use
3908 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3909 exist, an empty list is returned.
3910
3911 The returned list contains two entries: a list with the change
3912 locations and the current position in the list. Each
3913 entry in the change list is a dictionary with the following
3914 entries:
3915 col column number
3916 coladd column offset for 'virtualedit'
3917 lnum line number
3918 If buffer {buf} is the current buffer, then the current
3919 position refers to the position in the list. For other
3920 buffers, it is set to the length of the list.
3921
3922 Can also be used as a |method|: >
3923 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003924<
3925 Return type: list<any>
3926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003927
zeertzjqe0a2ab32025-02-02 09:14:35 +01003928getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003929 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003930 If {expr} is omitted or is -1, wait until a character is
3931 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003932 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003933 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003934 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003935 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003936 If you prefer always getting a string use |getcharstr()|, or
3937 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938
Doug Kearns9cd9e752024-04-07 17:42:17 +02003939 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003941 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003942 Otherwise a String is returned with the encoded character.
3943 For a special key it's a String with a sequence of bytes
3944 starting with 0x80 (decimal: 128). This is the same value as
3945 the String "\<Key>", e.g., "\<Left>". The returned value is
3946 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01003947 that is not included in the character. |keytrans()| can also
3948 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003949
Doug Kearns9cd9e752024-04-07 17:42:17 +02003950 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003951 while Vim waits to see if this is the start of an escape
3952 sequence.
3953
Doug Kearns9cd9e752024-04-07 17:42:17 +02003954 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955 one-byte character it is the character itself as a number.
3956 Use nr2char() to convert it to a String.
3957
3958 Use getcharmod() to obtain any additional modifiers.
3959
zeertzjqe0a2ab32025-02-02 09:14:35 +01003960 The optional argument {opts} is a Dict and supports the
3961 following items:
3962
zeertzjqedf0f7d2025-02-02 19:01:01 +01003963 cursor A String specifying cursor behavior
3964 when waiting for a character.
3965 "hide": hide the cursor.
3966 "keep": keep current cursor unchanged.
3967 "msg": move cursor to message area.
3968 (default: "msg")
3969
zeertzjqe0a2ab32025-02-02 09:14:35 +01003970 number If |TRUE|, return a Number when getting
3971 a single character.
3972 If |FALSE|, the return value is always
3973 converted to a String, and an empty
3974 String (instead of 0) is returned when
3975 no character is available.
3976 (default: |TRUE|)
3977
3978 simplify If |TRUE|, include modifiers in the
3979 character if possible. E.g., return
3980 the same value for CTRL-I and <Tab>.
3981 If |FALSE|, don't include modifiers in
3982 the character.
3983 (default: |TRUE|)
3984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003985 When the user clicks a mouse button, the mouse event will be
3986 returned. The position can then be found in |v:mouse_col|,
3987 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3988 |getmousepos()| can also be used. Mouse move events will be
3989 ignored.
3990 This example positions the mouse as it would normally happen: >
3991 let c = getchar()
3992 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003993 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003994 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003995 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003996 endif
3997<
3998 When using bracketed paste only the first character is
3999 returned, the rest of the pasted text is dropped.
4000 |xterm-bracketed-paste|.
4001
4002 There is no prompt, you will somehow have to make clear to the
4003 user that a character has to be typed. The screen is not
4004 redrawn, e.g. when resizing the window. When using a popup
4005 window it should work better with a |popup-filter|.
4006
4007 There is no mapping for the character.
4008 Key codes are replaced, thus when the user presses the <Del>
4009 key you get the code for the <Del> key, not the raw character
4010 sequence. Examples: >
4011 getchar() == "\<Del>"
4012 getchar() == "\<S-Left>"
4013< This example redefines "f" to ignore case: >
4014 :nmap f :call FindChar()<CR>
4015 :function FindChar()
4016 : let c = nr2char(getchar())
4017 : while col('.') < col('$') - 1
4018 : normal l
4019 : if getline('.')[col('.') - 1] ==? c
4020 : break
4021 : endif
4022 : endwhile
4023 :endfunction
4024<
4025 You may also receive synthetic characters, such as
4026 |<CursorHold>|. Often you will want to ignore this and get
4027 another character: >
4028 :function GetKey()
4029 : let c = getchar()
4030 : while c == "\<CursorHold>"
4031 : let c = getchar()
4032 : endwhile
4033 : return c
4034 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004035<
4036 Return type: |Number| or |String|
4037
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004038
4039getcharmod() *getcharmod()*
4040 The result is a Number which is the state of the modifiers for
4041 the last obtained character with getchar() or in another way.
4042 These values are added together:
4043 2 shift
4044 4 control
4045 8 alt (meta)
4046 16 meta (when it's different from ALT)
4047 32 mouse double click
4048 64 mouse triple click
4049 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004050 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004051 Only the modifiers that have not been included in the
4052 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004053 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004054
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004055 Return type: |Number|
4056
4057
4058getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004059 Get the position for String {expr}. Same as |getpos()| but the
4060 column number in the returned List is a character index
4061 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004062 If |getpos()| returns a very large column number, equal to
4063 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004064 of the last character.
4065
4066 Example:
4067 With the cursor on '세' in line 5 with text "여보세요": >
4068 getcharpos('.') returns [0, 5, 3, 0]
4069 getpos('.') returns [0, 5, 7, 0]
4070<
4071 Can also be used as a |method|: >
4072 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004073<
4074 Return type: list<number>
4075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004076
4077getcharsearch() *getcharsearch()*
4078 Return the current character search information as a {dict}
4079 with the following entries:
4080
4081 char character previously used for a character
4082 search (|t|, |f|, |T|, or |F|); empty string
4083 if no character search has been performed
4084 forward direction of character search; 1 for forward,
4085 0 for backward
4086 until type of character search; 1 for a |t| or |T|
4087 character search, 0 for an |f| or |F|
4088 character search
4089
4090 This can be useful to always have |;| and |,| search
4091 forward/backward regardless of the direction of the previous
4092 character search: >
4093 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4094 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4095< Also see |setcharsearch()|.
4096
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004097 Return type: dict<any>
4098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004099
zeertzjqe0a2ab32025-02-02 09:14:35 +01004100getcharstr([{expr} [, {opts}]]) *getcharstr()*
4101 The same as |getchar()|, except that this always returns a
4102 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004103
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004104 Return type: |String|
4105
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004106getcmdcomplpat() *getcmdcomplpat()*
4107 Return completion pattern of the current command-line.
4108 Only works when the command line is being edited, thus
4109 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4110 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4111 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4112 Returns an empty string when completion is not defined.
4113
4114 Return type: |String|
4115
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004116
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004117getcmdcompltype() *getcmdcompltype()*
4118 Return the type of the current command-line completion.
4119 Only works when the command line is being edited, thus
4120 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004121 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004122 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004123 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004124 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004125
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004126 Return type: |String|
4127
4128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004129getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004130 Return the current command-line input. Only works when the
4131 command line is being edited, thus requires use of
4132 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004133 Example: >
4134 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004135< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4136 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004137 Returns an empty string when entering a password or using
4138 |inputsecret()|.
4139
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004140 Return type: |String|
4141
4142
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004143getcmdpos() *getcmdpos()*
4144 Return the position of the cursor in the command line as a
4145 byte count. The first column is 1.
4146 Only works when editing the command line, thus requires use of
4147 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4148 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004149 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4150 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004151
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004152 Return type: |Number|
4153
4154
Shougo Matsushita69084282024-09-23 20:34:47 +02004155getcmdprompt() *getcmdprompt()*
4156 Return the current command-line prompt when using functions
4157 like |input()| or |confirm()|.
4158 Only works when the command line is being edited, thus
4159 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4160 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4161 |setcmdpos()| and |setcmdline()|.
4162
4163 Return type: |String|
4164
4165
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004166getcmdscreenpos() *getcmdscreenpos()*
4167 Return the screen position of the cursor in the command line
4168 as a byte count. The first column is 1.
4169 Instead of |getcmdpos()|, it adds the prompt position.
4170 Only works when editing the command line, thus requires use of
4171 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4172 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004173 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4174 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004175
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004176 Return type: |Number|
4177
4178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004179getcmdtype() *getcmdtype()*
4180 Return the current command-line type. Possible return values
4181 are:
4182 : normal Ex command
4183 > debug mode command |debug-mode|
4184 / forward search command
4185 ? backward search command
4186 @ |input()| command
4187 - |:insert| or |:append| command
4188 = |i_CTRL-R_=|
4189 Only works when editing the command line, thus requires use of
4190 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4191 Returns an empty string otherwise.
4192 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4193
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004194 Return type: |String|
4195
4196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004197getcmdwintype() *getcmdwintype()*
4198 Return the current |command-line-window| type. Possible return
4199 values are the same as |getcmdtype()|. Returns an empty string
4200 when not in the command-line window.
4201
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004202 Return type: |String|
4203
4204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004205getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4206 Return a list of command-line completion matches. The String
4207 {type} argument specifies what for. The following completion
4208 types are supported:
4209
4210 arglist file names in argument list
4211 augroup autocmd groups
4212 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004213 behave |:behave| suboptions
4214 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215 color color schemes
4216 command Ex command
4217 cmdline |cmdline-completion| result
4218 compiler compilers
4219 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004220 custom,{func} custom completion, defined via {func}
4221 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004222 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004223 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004224 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004225 environment environment variable names
4226 event autocommand events
4227 expression Vim expression
4228 file file and directory names
4229 file_in_path file and directory names in |'path'|
4230 filetype filetype names |'filetype'|
4231 function function name
4232 help help subjects
4233 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004234 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004235 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004236 locale locale names (as output of locale -a)
4237 mapclear buffer argument
4238 mapping mapping name
4239 menu menus
4240 messages |:messages| suboptions
4241 option options
4242 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004243 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004244 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004245 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004246 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004247 sign |:sign| suboptions
4248 syntax syntax file names |'syntax'|
4249 syntime |:syntime| suboptions
4250 tag tags
4251 tag_listfiles tags, file names
4252 user user names
4253 var user variables
4254
4255 If {pat} is an empty string, then all the matches are
4256 returned. Otherwise only items matching {pat} are returned.
4257 See |wildcards| for the use of special characters in {pat}.
4258
4259 If the optional {filtered} flag is set to 1, then 'wildignore'
4260 is applied to filter the results. Otherwise all the matches
4261 are returned. The 'wildignorecase' option always applies.
4262
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004263 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4264 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004265 regular expression matching is used. Thus this function
4266 follows the user preference, what happens on the command line.
4267 If you do not want this you can make 'wildoptions' empty
4268 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004270 If {type} is "cmdline", then the |cmdline-completion| result is
4271 returned. For example, to complete the possible values after
4272 a ":call" command: >
4273 echo getcompletion('call ', 'cmdline')
4274<
4275 If there are no matches, an empty list is returned. An
4276 invalid value for {type} produces an error.
4277
4278 Can also be used as a |method|: >
4279 GetPattern()->getcompletion('color')
4280<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004281 Return type: list<string>
4282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004283 *getcurpos()*
4284getcurpos([{winid}])
4285 Get the position of the cursor. This is like getpos('.'), but
4286 includes an extra "curswant" item in the list:
4287 [0, lnum, col, off, curswant] ~
4288 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004289 cursor vertically. After |$| command it will be a very large
4290 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004291 |getpos()|.
4292 The first "bufnum" item is always zero. The byte position of
4293 the cursor is returned in 'col'. To get the character
4294 position, use |getcursorcharpos()|.
4295
4296 The optional {winid} argument can specify the window. It can
4297 be the window number or the |window-ID|. The last known
4298 cursor position is returned, this may be invalid for the
4299 current value of the buffer if it is not the current window.
4300 If {winid} is invalid a list with zeroes is returned.
4301
4302 This can be used to save and restore the cursor position: >
4303 let save_cursor = getcurpos()
4304 MoveTheCursorAround
4305 call setpos('.', save_cursor)
4306< Note that this only works within the window. See
4307 |winrestview()| for restoring more state.
4308
4309 Can also be used as a |method|: >
4310 GetWinid()->getcurpos()
4311<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004312 Return type: list<number>
4313
4314
4315getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004316 Same as |getcurpos()| but the column number in the returned
4317 List is a character index instead of a byte index.
4318
4319 Example:
4320 With the cursor on '보' in line 3 with text "여보세요": >
4321 getcursorcharpos() returns [0, 3, 2, 0, 3]
4322 getcurpos() returns [0, 3, 4, 0, 3]
4323<
4324 Can also be used as a |method|: >
4325 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004326<
4327 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004329
4330getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004331 The result is a String, which is the name of the current
4332 working directory. 'autochdir' is ignored.
4333
4334 With {winnr} return the local current directory of this window
4335 in the current tab page. {winnr} can be the window number or
4336 the |window-ID|.
4337 If {winnr} is -1 return the name of the global working
4338 directory. See also |haslocaldir()|.
4339
4340 With {winnr} and {tabnr} return the local current directory of
4341 the window in the specified tab page. If {winnr} is -1 return
4342 the working directory of the tabpage.
4343 If {winnr} is zero use the current window, if {tabnr} is zero
4344 use the current tabpage.
4345 Without any arguments, return the actual working directory of
4346 the current window.
4347 Return an empty string if the arguments are invalid.
4348
4349 Examples: >
4350 " Get the working directory of the current window
4351 :echo getcwd()
4352 :echo getcwd(0)
4353 :echo getcwd(0, 0)
4354 " Get the working directory of window 3 in tabpage 2
4355 :echo getcwd(3, 2)
4356 " Get the global working directory
4357 :echo getcwd(-1)
4358 " Get the working directory of tabpage 3
4359 :echo getcwd(-1, 3)
4360 " Get the working directory of current tabpage
4361 :echo getcwd(-1, 0)
4362
4363< Can also be used as a |method|: >
4364 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004365<
4366 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004367
4368getenv({name}) *getenv()*
4369 Return the value of environment variable {name}. The {name}
4370 argument is a string, without a leading '$'. Example: >
4371 myHome = getenv('HOME')
4372
4373< When the variable does not exist |v:null| is returned. That
4374 is different from a variable set to an empty string, although
4375 some systems interpret the empty value as the variable being
4376 deleted. See also |expr-env|.
4377
4378 Can also be used as a |method|: >
4379 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004380<
4381 Return type: |String| or |Number|
4382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004383
4384getfontname([{name}]) *getfontname()*
4385 Without an argument returns the name of the normal font being
4386 used. Like what is used for the Normal highlight group
4387 |hl-Normal|.
4388 With an argument a check is done whether String {name} is a
4389 valid font name. If not then an empty string is returned.
4390 Otherwise the actual font name is returned, or {name} if the
4391 GUI does not support obtaining the real name.
4392 Only works when the GUI is running, thus not in your vimrc or
4393 gvimrc file. Use the |GUIEnter| autocommand to use this
4394 function just after the GUI has started.
4395 Note that the GTK GUI accepts any font name, thus checking for
4396 a valid name does not work.
4397
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004398 Return type: |String|
4399
4400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004401getfperm({fname}) *getfperm()*
4402 The result is a String, which is the read, write, and execute
4403 permissions of the given file {fname}.
4404 If {fname} does not exist or its directory cannot be read, an
4405 empty string is returned.
4406 The result is of the form "rwxrwxrwx", where each group of
4407 "rwx" flags represent, in turn, the permissions of the owner
4408 of the file, the group the file belongs to, and other users.
4409 If a user does not have a given permission the flag for this
4410 is replaced with the string "-". Examples: >
4411 :echo getfperm("/etc/passwd")
4412 :echo getfperm(expand("~/.vimrc"))
4413< This will hopefully (from a security point of view) display
4414 the string "rw-r--r--" or even "rw-------".
4415
4416 Can also be used as a |method|: >
4417 GetFilename()->getfperm()
4418<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004419 Return type: |String|
4420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004421 For setting permissions use |setfperm()|.
4422
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004424getfsize({fname}) *getfsize()*
4425 The result is a Number, which is the size in bytes of the
4426 given file {fname}.
4427 If {fname} is a directory, 0 is returned.
4428 If the file {fname} can't be found, -1 is returned.
4429 If the size of {fname} is too big to fit in a Number then -2
4430 is returned.
4431
4432 Can also be used as a |method|: >
4433 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004434<
4435 Return type: |Number|
4436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004437
4438getftime({fname}) *getftime()*
4439 The result is a Number, which is the last modification time of
4440 the given file {fname}. The value is measured as seconds
4441 since 1st Jan 1970, and may be passed to strftime(). See also
4442 |localtime()| and |strftime()|.
4443 If the file {fname} can't be found -1 is returned.
4444
4445 Can also be used as a |method|: >
4446 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004447<
4448 Return type: |Number|
4449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004450
4451getftype({fname}) *getftype()*
4452 The result is a String, which is a description of the kind of
4453 file of the given file {fname}.
4454 If {fname} does not exist an empty string is returned.
4455 Here is a table over different kinds of files and their
4456 results:
4457 Normal file "file"
4458 Directory "dir"
4459 Symbolic link "link"
4460 Block device "bdev"
4461 Character device "cdev"
4462 Socket "socket"
4463 FIFO "fifo"
4464 All other "other"
4465 Example: >
4466 getftype("/home")
4467< Note that a type such as "link" will only be returned on
4468 systems that support it. On some systems only "dir" and
4469 "file" are returned. On MS-Windows a symbolic link to a
4470 directory returns "dir" instead of "link".
4471
4472 Can also be used as a |method|: >
4473 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004474<
4475 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004476
4477getimstatus() *getimstatus()*
4478 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004479 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004480 See 'imstatusfunc'.
4481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004482 Return type: |Number|
4483
4484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004485getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4486 Returns the |jumplist| for the specified window.
4487
4488 Without arguments use the current window.
4489 With {winnr} only use this window in the current tab page.
4490 {winnr} can also be a |window-ID|.
4491 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004492 page. If {winnr} or {tabnr} is invalid, an empty list is
4493 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004494
4495 The returned list contains two entries: a list with the jump
4496 locations and the last used jump position number in the list.
4497 Each entry in the jump location list is a dictionary with
4498 the following entries:
4499 bufnr buffer number
4500 col column number
4501 coladd column offset for 'virtualedit'
4502 filename filename if available
4503 lnum line number
4504
4505 Can also be used as a |method|: >
4506 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004507<
4508 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004509
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004510 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004511getline({lnum} [, {end}])
4512 Without {end} the result is a String, which is line {lnum}
4513 from the current buffer. Example: >
4514 getline(1)
4515< When {lnum} is a String that doesn't start with a
4516 digit, |line()| is called to translate the String into a Number.
4517 To get the line under the cursor: >
4518 getline(".")
4519< When {lnum} is a number smaller than 1 or bigger than the
4520 number of lines in the buffer, an empty string is returned.
4521
4522 When {end} is given the result is a |List| where each item is
4523 a line from the current buffer in the range {lnum} to {end},
4524 including line {end}.
4525 {end} is used in the same way as {lnum}.
4526 Non-existing lines are silently omitted.
4527 When {end} is before {lnum} an empty |List| is returned.
4528 Example: >
4529 :let start = line('.')
4530 :let end = search("^$") - 1
4531 :let lines = getline(start, end)
4532
4533< Can also be used as a |method|: >
4534 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004535<
4536 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004537
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004538 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004539 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004540
4541getloclist({nr} [, {what}]) *getloclist()*
4542 Returns a |List| with all the entries in the location list for
4543 window {nr}. {nr} can be the window number or the |window-ID|.
4544 When {nr} is zero the current window is used.
4545
4546 For a location list window, the displayed location list is
4547 returned. For an invalid window number {nr}, an empty list is
4548 returned. Otherwise, same as |getqflist()|.
4549
4550 If the optional {what} dictionary argument is supplied, then
4551 returns the items listed in {what} as a dictionary. Refer to
4552 |getqflist()| for the supported items in {what}.
4553
4554 In addition to the items supported by |getqflist()| in {what},
4555 the following item is supported by |getloclist()|:
4556
4557 filewinid id of the window used to display files
4558 from the location list. This field is
4559 applicable only when called from a
4560 location list window. See
4561 |location-list-file-window| for more
4562 details.
4563
4564 Returns a |Dictionary| with default values if there is no
4565 location list for the window {nr}.
4566 Returns an empty Dictionary if window {nr} does not exist.
4567
4568 Examples (See also |getqflist-examples|): >
4569 :echo getloclist(3, {'all': 0})
4570 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004571<
4572 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004573
4574
4575getmarklist([{buf}]) *getmarklist()*
4576 Without the {buf} argument returns a |List| with information
4577 about all the global marks. |mark|
4578
4579 If the optional {buf} argument is specified, returns the
4580 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004581 see |bufname()|. If {buf} is invalid, an empty list is
4582 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004583
4584 Each item in the returned List is a |Dict| with the following:
4585 mark name of the mark prefixed by "'"
4586 pos a |List| with the position of the mark:
4587 [bufnum, lnum, col, off]
4588 Refer to |getpos()| for more information.
4589 file file name
4590
4591 Refer to |getpos()| for getting information about a specific
4592 mark.
4593
4594 Can also be used as a |method|: >
4595 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004596<
4597 Return type: list<dict<any>> or list<any>
4598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004599
4600getmatches([{win}]) *getmatches()*
4601 Returns a |List| with all matches previously defined for the
4602 current window by |matchadd()| and the |:match| commands.
4603 |getmatches()| is useful in combination with |setmatches()|,
4604 as |setmatches()| can restore a list of matches saved by
4605 |getmatches()|.
4606 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004607 window ID instead of the current window. If {win} is invalid,
4608 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004609 Example: >
4610 :echo getmatches()
4611< [{'group': 'MyGroup1', 'pattern': 'TODO',
4612 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4613 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4614 :let m = getmatches()
4615 :call clearmatches()
4616 :echo getmatches()
4617< [] >
4618 :call setmatches(m)
4619 :echo getmatches()
4620< [{'group': 'MyGroup1', 'pattern': 'TODO',
4621 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4622 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4623 :unlet m
4624<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004625 Return type: list<dict<any>> or list<any>
4626
4627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004628getmousepos() *getmousepos()*
4629 Returns a |Dictionary| with the last known position of the
4630 mouse. This can be used in a mapping for a mouse click or in
4631 a filter of a popup window. The items are:
4632 screenrow screen row
4633 screencol screen column
4634 winid Window ID of the click
4635 winrow row inside "winid"
4636 wincol column inside "winid"
4637 line text line inside "winid"
4638 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004639 coladd offset (in screen columns) from the
4640 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004641 All numbers are 1-based.
4642
4643 If not over a window, e.g. when in the command line, then only
4644 "screenrow" and "screencol" are valid, the others are zero.
4645
4646 When on the status line below a window or the vertical
4647 separator right of a window, the "line" and "column" values
4648 are zero.
4649
4650 When the position is after the text then "column" is the
4651 length of the text in bytes plus one.
4652
4653 If the mouse is over a popup window then that window is used.
4654
4655 When using |getchar()| the Vim variables |v:mouse_lnum|,
4656 |v:mouse_col| and |v:mouse_winid| also provide these values.
4657
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004658 Return type: dict<number>
4659
4660
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004661getmouseshape() *getmouseshape()*
4662 Returns the name of the currently showing mouse pointer.
4663 When the |+mouseshape| feature is not supported or the shape
4664 is unknown an empty string is returned.
4665 This function is mainly intended for testing.
4666
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004667 Return type: |String|
4668
4669
4670getpid() *getpid()*
4671 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004672 On Unix and MS-Windows this is a unique number, until Vim
4673 exits.
4674
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004675 Return type: |Number|
4676
4677
4678getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004679 Get the position for String {expr}.
4680 The accepted values for {expr} are: *E1209*
4681 . The cursor position.
4682 $ The last line in the current buffer.
4683 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004684 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004685 w0 First line visible in current window (one if the
4686 display isn't updated, e.g. in silent Ex mode).
4687 w$ Last line visible in current window (this is one
4688 less than "w0" if no lines are visible).
4689 v When not in Visual mode, returns the cursor
4690 position. In Visual mode, returns the other end
4691 of the Visual area. A good way to think about
4692 this is that in Visual mode "v" and "." complement
4693 each other. While "." refers to the cursor
4694 position, "v" refers to where |v_o| would move the
4695 cursor. As a result, you can use "v" and "."
4696 together to work on all of a selection in
4697 characterwise Visual mode. If the cursor is at
4698 the end of a characterwise Visual area, "v" refers
4699 to the start of the same Visual area. And if the
4700 cursor is at the start of a characterwise Visual
4701 area, "v" refers to the end of the same Visual
4702 area. "v" differs from |'<| and |'>| in that it's
4703 updated right away.
4704 Note that a mark in another file can be used. The line number
4705 then applies to another buffer.
4706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004707 The result is a |List| with four numbers:
4708 [bufnum, lnum, col, off]
4709 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4710 is the buffer number of the mark.
4711 "lnum" and "col" are the position in the buffer. The first
4712 column is 1.
4713 The "off" number is zero, unless 'virtualedit' is used. Then
4714 it is the offset in screen columns from the start of the
4715 character. E.g., a position within a <Tab> or after the last
4716 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004717
4718 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004719 The column number in the returned List is the byte position
4720 within the line. To get the character position in the line,
4721 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004722
4723 Note that for '< and '> Visual mode matters: when it is "V"
4724 (visual line mode) the column of '< is zero and the column of
4725 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004726 A very large column number equal to |v:maxcol| can be returned,
4727 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004728 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004730 This can be used to save and restore the position of a mark: >
4731 let save_a_mark = getpos("'a")
4732 ...
4733 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004734<
4735 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004736
4737 Can also be used as a |method|: >
4738 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004739<
4740 Return type: list<number>
4741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004742
4743getqflist([{what}]) *getqflist()*
4744 Returns a |List| with all the current quickfix errors. Each
4745 list item is a dictionary with these entries:
4746 bufnr number of buffer that has the file name, use
4747 bufname() to get the name
4748 module module name
4749 lnum line number in the buffer (first line is 1)
4750 end_lnum
4751 end of line number if the item is multiline
4752 col column number (first column is 1)
4753 end_col end of column number if the item has range
4754 vcol |TRUE|: "col" is visual column
4755 |FALSE|: "col" is byte index
4756 nr error number
h-east84ac2122024-06-17 18:12:30 +02004757 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004758 text description of the error
4759 type type of the error, 'E', '1', etc.
4760 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004761 user_data
4762 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004763 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004764
4765 When there is no error list or it's empty, an empty list is
4766 returned. Quickfix list entries with a non-existing buffer
4767 number are returned with "bufnr" set to zero (Note: some
4768 functions accept buffer number zero for the alternate buffer,
4769 you may need to explicitly check for zero).
4770
4771 Useful application: Find pattern matches in multiple files and
4772 do something with them: >
4773 :vimgrep /theword/jg *.c
4774 :for d in getqflist()
4775 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4776 :endfor
4777<
4778 If the optional {what} dictionary argument is supplied, then
4779 returns only the items listed in {what} as a dictionary. The
4780 following string items are supported in {what}:
4781 changedtick get the total number of changes made
4782 to the list |quickfix-changedtick|
4783 context get the |quickfix-context|
4784 efm errorformat to use when parsing "lines". If
4785 not present, then the 'errorformat' option
4786 value is used.
4787 id get information for the quickfix list with
4788 |quickfix-ID|; zero means the id for the
4789 current list or the list specified by "nr"
4790 idx get information for the quickfix entry at this
4791 index in the list specified by 'id' or 'nr'.
4792 If set to zero, then uses the current entry.
4793 See |quickfix-index|
4794 items quickfix list entries
4795 lines parse a list of lines using 'efm' and return
4796 the resulting entries. Only a |List| type is
4797 accepted. The current quickfix list is not
4798 modified. See |quickfix-parse|.
4799 nr get information for this quickfix list; zero
4800 means the current quickfix list and "$" means
4801 the last quickfix list
4802 qfbufnr number of the buffer displayed in the quickfix
4803 window. Returns 0 if the quickfix buffer is
4804 not present. See |quickfix-buffer|.
4805 size number of entries in the quickfix list
4806 title get the list title |quickfix-title|
4807 winid get the quickfix |window-ID|
4808 all all of the above quickfix properties
4809 Non-string items in {what} are ignored. To get the value of a
4810 particular item, set it to zero.
4811 If "nr" is not present then the current quickfix list is used.
4812 If both "nr" and a non-zero "id" are specified, then the list
4813 specified by "id" is used.
4814 To get the number of lists in the quickfix stack, set "nr" to
4815 "$" in {what}. The "nr" value in the returned dictionary
4816 contains the quickfix stack size.
4817 When "lines" is specified, all the other items except "efm"
4818 are ignored. The returned dictionary contains the entry
4819 "items" with the list of entries.
4820
4821 The returned dictionary contains the following entries:
4822 changedtick total number of changes made to the
4823 list |quickfix-changedtick|
4824 context quickfix list context. See |quickfix-context|
4825 If not present, set to "".
4826 id quickfix list ID |quickfix-ID|. If not
4827 present, set to 0.
4828 idx index of the quickfix entry in the list. If not
4829 present, set to 0.
4830 items quickfix list entries. If not present, set to
4831 an empty list.
4832 nr quickfix list number. If not present, set to 0
4833 qfbufnr number of the buffer displayed in the quickfix
4834 window. If not present, set to 0.
4835 size number of entries in the quickfix list. If not
4836 present, set to 0.
4837 title quickfix list title text. If not present, set
4838 to "".
4839 winid quickfix |window-ID|. If not present, set to 0
4840
4841 Examples (See also |getqflist-examples|): >
4842 :echo getqflist({'all': 1})
4843 :echo getqflist({'nr': 2, 'title': 1})
4844 :echo getqflist({'lines' : ["F1:10:L10"]})
4845<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004846 Return type: list<dict<any>> or list<any>
4847
4848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004849getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4850 The result is a String, which is the contents of register
4851 {regname}. Example: >
4852 :let cliptext = getreg('*')
4853< When register {regname} was not set the result is an empty
4854 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004855 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004856
4857 getreg('=') returns the last evaluated value of the expression
4858 register. (For use in maps.)
4859 getreg('=', 1) returns the expression itself, so that it can
4860 be restored with |setreg()|. For other registers the extra
4861 argument is ignored, thus you can always give it.
4862
4863 If {list} is present and |TRUE|, the result type is changed
4864 to |List|. Each list item is one text line. Use it if you care
4865 about zero bytes possibly present inside register: without
4866 third argument both NLs and zero bytes are represented as NLs
4867 (see |NL-used-for-Nul|).
4868 When the register was not set an empty list is returned.
4869
4870 If {regname} is "", the unnamed register '"' is used.
4871 If {regname} is not specified, |v:register| is used.
4872 In |Vim9-script| {regname} must be one character.
4873
4874 Can also be used as a |method|: >
4875 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004876<
4877 Return type: |String|
4878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004879
4880getreginfo([{regname}]) *getreginfo()*
4881 Returns detailed information about register {regname} as a
4882 Dictionary with the following entries:
4883 regcontents List of lines contained in register
4884 {regname}, like
4885 |getreg|({regname}, 1, 1).
4886 regtype the type of register {regname}, as in
4887 |getregtype()|.
4888 isunnamed Boolean flag, v:true if this register
4889 is currently pointed to by the unnamed
4890 register.
4891 points_to for the unnamed register, gives the
4892 single letter name of the register
4893 currently pointed to (see |quotequote|).
4894 For example, after deleting a line
4895 with `dd`, this field will be "1",
4896 which is the register that got the
4897 deleted text.
4898
4899 The {regname} argument is a string. If {regname} is invalid
4900 or not set, an empty Dictionary will be returned.
4901 If {regname} is "" or "@", the unnamed register '"' is used.
4902 If {regname} is not specified, |v:register| is used.
4903 The returned Dictionary can be passed to |setreg()|.
4904 In |Vim9-script| {regname} must be one character.
4905
4906 Can also be used as a |method|: >
4907 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004908<
4909 Return type: dict<any>
4910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004911
Shougo Matsushita19b71882024-02-28 22:48:12 +01004912getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004913 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004914 buffer.
4915
4916 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004917 See |getpos()| for the format of the list. It's possible
4918 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004919 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004920
4921 The optional argument {opts} is a Dict and supports the
4922 following items:
4923
zeertzjqafc22952024-05-24 19:07:12 +02004924 type Specify the region's selection type.
4925 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004926 except that the width can be omitted
4927 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004928 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004929
zeertzjq87410ab2024-03-02 06:00:23 +08004930 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004931 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004932 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004933
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004934 You can get the last selection type by |visualmode()|.
4935 If Visual mode is active, use |mode()| to get the Visual mode
4936 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004937 This function is useful to get text starting and ending in
4938 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004939
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004940 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004941 Note that:
4942 - Order of {pos1} and {pos2} doesn't matter, it will always
4943 return content from the upper left position to the lower
4944 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004945 - If 'virtualedit' is enabled and the region is past the end
4946 of the lines, resulting lines are padded with spaces.
4947 - If the region is blockwise and it starts or ends in the
4948 middle of a multi-cell character, it is not included but
4949 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004950 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004951 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004952 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004953 - It is evaluated in current window context, which makes a
4954 difference if the buffer is displayed in a window with
4955 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004956
4957 Examples: >
4958 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004959 \ <Cmd>echow getregion(
4960 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004961<
4962 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004963 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004964<
4965 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004966
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004967
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004968getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4969 Same as |getregion()|, but returns a list of positions
4970 describing the buffer text segments bound by {pos1} and
4971 {pos2}.
4972 The segments are a pair of positions for every line: >
4973 [[{start_pos}, {end_pos}], ...]
4974<
4975 The position is a |List| with four numbers:
4976 [bufnum, lnum, col, off]
4977 "bufnum" is the buffer number.
4978 "lnum" and "col" are the position in the buffer. The first
4979 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004980 If the "off" number of a starting position is non-zero, it is
4981 the offset in screen columns from the start of the character.
4982 E.g., a position within a <Tab> or after the last character.
4983 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004984 the offset of the character's first cell not included in the
4985 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004986
zeertzjq2b09de92024-05-24 07:48:51 +02004987 Apart from the options supported by |getregion()|, {opts} also
4988 supports the following:
4989
4990 eol If |TRUE|, indicate positions beyond
4991 the end of a line with "col" values
4992 one more than the length of the line.
4993 If |FALSE|, positions are limited
4994 within their lines, and if a line is
4995 empty or the selection is entirely
4996 beyond the end of a line, a "col"
4997 value of 0 is used for both positions.
4998 (default: |FALSE|)
4999
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005000 Can also be used as a |method|: >
5001 getpos('.')->getregionpos(getpos("'a"))
5002<
Christian Brabandt83d74402025-03-19 21:55:59 +01005003 For an example, see the highlight-yank plugin |52.6|
5004
zeertzjqd4d12072024-07-16 20:34:16 +02005005 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005006
5007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005008getregtype([{regname}]) *getregtype()*
5009 The result is a String, which is type of register {regname}.
5010 The value will be one of:
5011 "v" for |characterwise| text
5012 "V" for |linewise| text
5013 "<CTRL-V>{width}" for |blockwise-visual| text
5014 "" for an empty or unknown register
5015 <CTRL-V> is one character with value 0x16.
5016 The {regname} argument is a string. If {regname} is "", the
5017 unnamed register '"' is used. If {regname} is not specified,
5018 |v:register| is used.
5019 In |Vim9-script| {regname} must be one character.
5020
5021 Can also be used as a |method|: >
5022 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005023<
5024 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005025
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005026
Bram Moolenaar71badf92023-04-22 22:40:14 +01005027getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005028 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005029 scripts in the order they were sourced, like what
5030 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005031
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005032 The optional Dict argument {opts} supports the following
5033 optional items:
5034 name Script name match pattern. If specified,
5035 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005036 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005037 "name" are returned.
5038 sid Script ID |<SID>|. If specified, only
5039 information about the script with ID "sid" is
5040 returned and "name" is ignored.
5041
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005042 Each item in the returned List is a |Dict| with the following
5043 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005044 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005045 `import autoload` but was not actually sourced
5046 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005047 functions List of script-local function names defined in
5048 the script. Present only when a particular
5049 script is specified using the "sid" item in
5050 {opts}.
5051 name Vim script file name.
5052 sid Script ID |<SID>|.
5053 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005054 this script name links to, if any, otherwise
5055 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005056 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005057 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005058 specified using the "sid" item in {opts}.
5059 Note that this is a copy, the value of
5060 script-local variables cannot be changed using
5061 this dictionary.
h_east59858792023-10-25 22:47:05 +09005062 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005063
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005064 Examples: >
5065 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005066 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005067<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005068 Return type: list<dict<any>>
5069
5070
ichizok663d18d2025-01-02 18:06:00 +01005071getstacktrace() *getstacktrace()*
5072 Returns the current stack trace of Vim scripts.
5073 Stack trace is a |List|, of which each item is a |Dictionary|
5074 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005075 funcref The funcref if the stack is at a function,
5076 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005077 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005078 stack is at an autocmd event, otherwise this
5079 item is omitted.
5080 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005081 filepath The file path of the script on the stack.
5082
5083 Return type: list<dict<any>>
5084
5085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005086gettabinfo([{tabnr}]) *gettabinfo()*
5087 If {tabnr} is not specified, then information about all the
5088 tab pages is returned as a |List|. Each List item is a
5089 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5090 number and information about that one is returned. If the tab
5091 page does not exist an empty List is returned.
5092
5093 Each List item is a |Dictionary| with the following entries:
5094 tabnr tab page number.
5095 variables a reference to the dictionary with
5096 tabpage-local variables
5097 windows List of |window-ID|s in the tab page.
5098
5099 Can also be used as a |method|: >
5100 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005101<
5102 Return type: list<dict<any>>
5103
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005104
5105gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5106 Get the value of a tab-local variable {varname} in tab page
5107 {tabnr}. |t:var|
5108 Tabs are numbered starting with one.
5109 The {varname} argument is a string. When {varname} is empty a
5110 dictionary with all tab-local variables is returned.
5111 Note that the name without "t:" must be used.
5112 When the tab or variable doesn't exist {def} or an empty
5113 string is returned, there is no error message.
5114
5115 Can also be used as a |method|: >
5116 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005117<
5118 Return type: any, depending on {varname}
5119
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005120
5121gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5122 Get the value of window-local variable {varname} in window
5123 {winnr} in tab page {tabnr}.
5124 The {varname} argument is a string. When {varname} is empty a
5125 dictionary with all window-local variables is returned.
5126 When {varname} is equal to "&" get the values of all
5127 window-local options in a |Dictionary|.
5128 Otherwise, when {varname} starts with "&" get the value of a
5129 window-local option.
5130 Note that {varname} must be the name without "w:".
5131 Tabs are numbered starting with one. For the current tabpage
5132 use |getwinvar()|.
5133 {winnr} can be the window number or the |window-ID|.
5134 When {winnr} is zero the current window is used.
5135 This also works for a global option, buffer-local option and
5136 window-local option, but it doesn't work for a global variable
5137 or buffer-local variable.
5138 When the tab, window or variable doesn't exist {def} or an
5139 empty string is returned, there is no error message.
5140 Examples: >
5141 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005142 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005143<
5144 To obtain all window-local variables use: >
5145 gettabwinvar({tabnr}, {winnr}, '&')
5146
5147< Can also be used as a |method|: >
5148 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005149<
5150 Return type: any, depending on {varname}
5151
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005152
5153gettagstack([{winnr}]) *gettagstack()*
5154 The result is a Dict, which is the tag stack of window {winnr}.
5155 {winnr} can be the window number or the |window-ID|.
5156 When {winnr} is not specified, the current window is used.
5157 When window {winnr} doesn't exist, an empty Dict is returned.
5158
5159 The returned dictionary contains the following entries:
5160 curidx Current index in the stack. When at
5161 top of the stack, set to (length + 1).
5162 Index of bottom of the stack is 1.
5163 items List of items in the stack. Each item
5164 is a dictionary containing the
5165 entries described below.
5166 length Number of entries in the stack.
5167
5168 Each item in the stack is a dictionary with the following
5169 entries:
5170 bufnr buffer number of the current jump
5171 from cursor position before the tag jump.
5172 See |getpos()| for the format of the
5173 returned list.
5174 matchnr current matching tag number. Used when
5175 multiple matching tags are found for a
5176 name.
5177 tagname name of the tag
5178
5179 See |tagstack| for more information about the tag stack.
5180
5181 Can also be used as a |method|: >
5182 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005183<
5184 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005185
5186
Christ van Willegence0ef912024-06-20 23:41:59 +02005187gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005188 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005189 This is intended for use in Vim scripts. When generating
5190 message translations the {text} is extracted by `xgettext`,
5191 the translator can add translated messages into the .po file
5192 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005193 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005194 `xgettext` does not support single quoted escaped text.
5195
Christ van Willegence0ef912024-06-20 23:41:59 +02005196 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005197 for that specific package. This is mainly required for
5198 third-party Vim scripts. You need to specify a path to the
5199 translations with the |bindtextdomain()| function before
5200 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005201
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005202 Return type: |String|
5203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005204
5205getwininfo([{winid}]) *getwininfo()*
5206 Returns information about windows as a |List| with Dictionaries.
5207
5208 If {winid} is given Information about the window with that ID
5209 is returned, as a |List| with one item. If the window does not
5210 exist the result is an empty list.
5211
5212 Without {winid} information about all the windows in all the
5213 tab pages is returned.
5214
5215 Each List item is a |Dictionary| with the following entries:
5216 botline last complete displayed buffer line
5217 bufnr number of buffer in the window
5218 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005219 leftcol first column displayed; only used when
5220 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005221 loclist 1 if showing a location list
5222 {only with the +quickfix feature}
5223 quickfix 1 if quickfix or location list window
5224 {only with the +quickfix feature}
5225 terminal 1 if a terminal window
5226 {only with the +terminal feature}
5227 tabnr tab page number
5228 topline first displayed buffer line
5229 variables a reference to the dictionary with
5230 window-local variables
5231 width window width
5232 winbar 1 if the window has a toolbar, 0
5233 otherwise
5234 wincol leftmost screen column of the window;
5235 "col" from |win_screenpos()|
5236 textoff number of columns occupied by any
5237 'foldcolumn', 'signcolumn' and line
5238 number in front of the text
5239 winid |window-ID|
5240 winnr window number
5241 winrow topmost screen line of the window;
5242 "row" from |win_screenpos()|
5243
5244 Can also be used as a |method|: >
5245 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005246<
5247 Return type: list<dict<any>>
5248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005249
5250getwinpos([{timeout}]) *getwinpos()*
5251 The result is a |List| with two numbers, the result of
5252 |getwinposx()| and |getwinposy()| combined:
5253 [x-pos, y-pos]
5254 {timeout} can be used to specify how long to wait in msec for
5255 a response from the terminal. When omitted 100 msec is used.
5256 Use a longer time for a remote terminal.
5257 When using a value less than 10 and no response is received
5258 within that time, a previously reported position is returned,
5259 if available. This can be used to poll for the position and
5260 do some work in the meantime: >
5261 while 1
5262 let res = getwinpos(1)
5263 if res[0] >= 0
5264 break
5265 endif
5266 " Do some work here
5267 endwhile
5268<
5269
5270 Can also be used as a |method|: >
5271 GetTimeout()->getwinpos()
5272<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005273 Return type: list<number>
5274
5275
5276getwinposx() *getwinposx()*
5277 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005278 the left hand side of the GUI Vim window. Also works for an
5279 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005280 The result will be -1 if the information is not available
5281 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005282 The value can be used with `:winpos`.
5283
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005284 Return type: |Number|
5285
5286
5287getwinposy() *getwinposy()*
5288 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005289 the top of the GUI Vim window. Also works for an xterm (uses
5290 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005291 The result will be -1 if the information is not available
5292 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005293 The value can be used with `:winpos`.
5294
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005295 Return type: |Number|
5296
5297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005298getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5299 Like |gettabwinvar()| for the current tabpage.
5300 Examples: >
5301 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005302 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005303
5304< Can also be used as a |method|: >
5305 GetWinnr()->getwinvar(varname)
5306<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005307 Return type: any, depending on {varname}
5308
5309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005310glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5311 Expand the file wildcards in {expr}. See |wildcards| for the
5312 use of special characters.
5313
5314 Unless the optional {nosuf} argument is given and is |TRUE|,
5315 the 'suffixes' and 'wildignore' options apply: Names matching
5316 one of the patterns in 'wildignore' will be skipped and
5317 'suffixes' affect the ordering of matches.
5318 'wildignorecase' always applies.
5319
5320 When {list} is present and it is |TRUE| the result is a |List|
5321 with all matching files. The advantage of using a List is,
5322 you also get filenames containing newlines correctly.
5323 Otherwise the result is a String and when there are several
5324 matches, they are separated by <NL> characters.
5325
5326 If the expansion fails, the result is an empty String or List.
5327
5328 You can also use |readdir()| if you need to do complicated
5329 things, such as limiting the number of matches.
5330
5331 A name for a non-existing file is not included. A symbolic
5332 link is only included if it points to an existing file.
5333 However, when the {alllinks} argument is present and it is
5334 |TRUE| then all symbolic links are included.
5335
5336 For most systems backticks can be used to get files names from
5337 any external command. Example: >
5338 :let tagfiles = glob("`find . -name tags -print`")
5339 :let &tags = substitute(tagfiles, "\n", ",", "g")
5340< The result of the program inside the backticks should be one
5341 item per line. Spaces inside an item are allowed.
5342
5343 See |expand()| for expanding special Vim variables. See
5344 |system()| for getting the raw output of an external command.
5345
5346 Can also be used as a |method|: >
5347 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005348<
5349 Return type: |String| or list<string> or list<any> depending
5350 on {list}
5351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005352
h-east624bb832024-11-09 18:37:32 +01005353glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005354 Convert a file pattern, as used by glob(), into a search
5355 pattern. The result can be used to match with a string that
5356 is a file name. E.g. >
5357 if filename =~ glob2regpat('Make*.mak')
5358< This is equivalent to: >
5359 if filename =~ '^Make.*\.mak$'
5360< When {string} is an empty string the result is "^$", match an
5361 empty string.
5362 Note that the result depends on the system. On MS-Windows
5363 a backslash usually means a path separator.
5364
5365 Can also be used as a |method|: >
5366 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005367<
5368 Return type: |String|
5369
5370 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005371globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5372 Perform glob() for String {expr} on all directories in {path}
5373 and concatenate the results. Example: >
5374 :echo globpath(&rtp, "syntax/c.vim")
5375<
5376 {path} is a comma-separated list of directory names. Each
5377 directory name is prepended to {expr} and expanded like with
5378 |glob()|. A path separator is inserted when needed.
5379 To add a comma inside a directory name escape it with a
5380 backslash. Note that on MS-Windows a directory may have a
5381 trailing backslash, remove it if you put a comma after it.
5382 If the expansion fails for one of the directories, there is no
5383 error message.
5384
5385 Unless the optional {nosuf} argument is given and is |TRUE|,
5386 the 'suffixes' and 'wildignore' options apply: Names matching
5387 one of the patterns in 'wildignore' will be skipped and
5388 'suffixes' affect the ordering of matches.
5389
5390 When {list} is present and it is |TRUE| the result is a |List|
5391 with all matching files. The advantage of using a List is, you
5392 also get filenames containing newlines correctly. Otherwise
5393 the result is a String and when there are several matches,
5394 they are separated by <NL> characters. Example: >
5395 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5396<
5397 {alllinks} is used as with |glob()|.
5398
5399 The "**" item can be used to search in a directory tree.
5400 For example, to find all "README.txt" files in the directories
5401 in 'runtimepath' and below: >
5402 :echo globpath(&rtp, "**/README.txt")
5403< Upwards search and limiting the depth of "**" is not
5404 supported, thus using 'path' will not always work properly.
5405
5406 Can also be used as a |method|, the base is passed as the
5407 second argument: >
5408 GetExpr()->globpath(&rtp)
5409<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005410 Return type: |String| or list<string> or list<any> depending
5411 on {list}
5412
5413
5414has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005415 When {check} is omitted or is zero: The result is a Number,
5416 which is 1 if the feature {feature} is supported, zero
5417 otherwise. The {feature} argument is a string, case is
5418 ignored. See |feature-list| below.
5419
5420 When {check} is present and not zero: The result is a Number,
5421 which is 1 if the feature {feature} could ever be supported,
5422 zero otherwise. This is useful to check for a typo in
5423 {feature} and to detect dead code. Keep in mind that an older
5424 Vim version will not know about a feature added later and
5425 features that have been abandoned will not be known by the
5426 current Vim version.
5427
5428 Also see |exists()| and |exists_compiled()|.
5429
5430 Note that to skip code that has a syntax error when the
5431 feature is not available, Vim may skip the rest of the line
5432 and miss a following `endif`. Therefore put the `endif` on a
5433 separate line: >
5434 if has('feature')
5435 let x = this->breaks->without->the->feature
5436 endif
5437< If the `endif` would be moved to the second line as "| endif" it
5438 would not be found.
5439
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005440 Return type: |Number|
5441
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005442
5443has_key({dict}, {key}) *has_key()*
5444 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005445 has an entry with key {key}. FALSE otherwise.
5446 The {key} argument is a string. In |Vim9| script a number is
5447 also accepted (and converted to a string) but no other types.
5448 In legacy script the usual automatic conversion to string is
5449 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005450
5451 Can also be used as a |method|: >
5452 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005453<
5454 Return type: |Number|
5455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005456
5457haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5458 The result is a Number:
5459 1 when the window has set a local directory via |:lcd|
5460 2 when the tab-page has set a local directory via |:tcd|
5461 0 otherwise.
5462
5463 Without arguments use the current window.
5464 With {winnr} use this window in the current tab page.
5465 With {winnr} and {tabnr} use the window in the specified tab
5466 page.
5467 {winnr} can be the window number or the |window-ID|.
5468 If {winnr} is -1 it is ignored and only the tabpage is used.
5469 Return 0 if the arguments are invalid.
5470 Examples: >
5471 if haslocaldir() == 1
5472 " window local directory case
5473 elseif haslocaldir() == 2
5474 " tab-local directory case
5475 else
5476 " global directory case
5477 endif
5478
5479 " current window
5480 :echo haslocaldir()
5481 :echo haslocaldir(0)
5482 :echo haslocaldir(0, 0)
5483 " window n in current tab page
5484 :echo haslocaldir(n)
5485 :echo haslocaldir(n, 0)
5486 " window n in tab page m
5487 :echo haslocaldir(n, m)
5488 " tab page m
5489 :echo haslocaldir(-1, m)
5490<
5491 Can also be used as a |method|: >
5492 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005493<
5494 Return type: |Number|
5495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005496
5497hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5498 The result is a Number, which is TRUE if there is a mapping
5499 that contains {what} in somewhere in the rhs (what it is
5500 mapped to) and this mapping exists in one of the modes
5501 indicated by {mode}.
5502 The arguments {what} and {mode} are strings.
5503 When {abbr} is there and it is |TRUE| use abbreviations
5504 instead of mappings. Don't forget to specify Insert and/or
5505 Command-line mode.
5506 Both the global mappings and the mappings local to the current
5507 buffer are checked for a match.
5508 If no matching mapping is found FALSE is returned.
5509 The following characters are recognized in {mode}:
5510 n Normal mode
5511 v Visual and Select mode
5512 x Visual mode
5513 s Select mode
5514 o Operator-pending mode
5515 i Insert mode
5516 l Language-Argument ("r", "f", "t", etc.)
5517 c Command-line mode
5518 When {mode} is omitted, "nvo" is used.
5519
5520 This function is useful to check if a mapping already exists
5521 to a function in a Vim script. Example: >
5522 :if !hasmapto('\ABCdoit')
5523 : map <Leader>d \ABCdoit
5524 :endif
5525< This installs the mapping to "\ABCdoit" only if there isn't
5526 already a mapping to "\ABCdoit".
5527
5528 Can also be used as a |method|: >
5529 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005530<
5531 Return type: |Number|
5532
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005533
5534histadd({history}, {item}) *histadd()*
5535 Add the String {item} to the history {history} which can be
5536 one of: *hist-names*
5537 "cmd" or ":" command line history
5538 "search" or "/" search pattern history
5539 "expr" or "=" typed expression history
5540 "input" or "@" input line history
5541 "debug" or ">" debug command history
5542 empty the current or last used history
5543 The {history} string does not need to be the whole name, one
5544 character is sufficient.
5545 If {item} does already exist in the history, it will be
5546 shifted to become the newest entry.
5547 The result is a Number: TRUE if the operation was successful,
5548 otherwise FALSE is returned.
5549
5550 Example: >
5551 :call histadd("input", strftime("%Y %b %d"))
5552 :let date=input("Enter date: ")
5553< This function is not available in the |sandbox|.
5554
5555 Can also be used as a |method|, the base is passed as the
5556 second argument: >
5557 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005558<
5559 Return type: |Number|
5560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005561
5562histdel({history} [, {item}]) *histdel()*
5563 Clear {history}, i.e. delete all its entries. See |hist-names|
5564 for the possible values of {history}.
5565
5566 If the parameter {item} evaluates to a String, it is used as a
5567 regular expression. All entries matching that expression will
5568 be removed from the history (if there are any).
5569 Upper/lowercase must match, unless "\c" is used |/\c|.
5570 If {item} evaluates to a Number, it will be interpreted as
5571 an index, see |:history-indexing|. The respective entry will
5572 be removed if it exists.
5573
5574 The result is TRUE for a successful operation, otherwise FALSE
5575 is returned.
5576
5577 Examples:
5578 Clear expression register history: >
5579 :call histdel("expr")
5580<
5581 Remove all entries starting with "*" from the search history: >
5582 :call histdel("/", '^\*')
5583<
5584 The following three are equivalent: >
5585 :call histdel("search", histnr("search"))
5586 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005587 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005588<
5589 To delete the last search pattern and use the last-but-one for
5590 the "n" command and 'hlsearch': >
5591 :call histdel("search", -1)
5592 :let @/ = histget("search", -1)
5593<
5594 Can also be used as a |method|: >
5595 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005596<
5597 Return type: |Number|
5598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005599
5600histget({history} [, {index}]) *histget()*
5601 The result is a String, the entry with Number {index} from
5602 {history}. See |hist-names| for the possible values of
5603 {history}, and |:history-indexing| for {index}. If there is
5604 no such entry, an empty String is returned. When {index} is
5605 omitted, the most recent item from the history is used.
5606
5607 Examples:
5608 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005609 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005610
5611< Define an Ex command ":H {num}" that supports re-execution of
5612 the {num}th entry from the output of |:history|. >
5613 :command -nargs=1 H execute histget("cmd", 0+<args>)
5614<
5615 Can also be used as a |method|: >
5616 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005617<
5618 Return type: |String|
5619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005620
5621histnr({history}) *histnr()*
5622 The result is the Number of the current entry in {history}.
5623 See |hist-names| for the possible values of {history}.
5624 If an error occurred, -1 is returned.
5625
5626 Example: >
5627 :let inp_index = histnr("expr")
5628
5629< Can also be used as a |method|: >
5630 GetHistory()->histnr()
5631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005632 Return type: |Number|
5633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005634hlexists({name}) *hlexists()*
5635 The result is a Number, which is TRUE if a highlight group
5636 called {name} exists. This is when the group has been
5637 defined in some way. Not necessarily when highlighting has
5638 been defined for it, it may also have been used for a syntax
5639 item.
5640 *highlight_exists()*
5641 Obsolete name: highlight_exists().
5642
5643 Can also be used as a |method|: >
5644 GetName()->hlexists()
5645<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005646 Return type: |Number|
5647
5648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005649hlget([{name} [, {resolve}]]) *hlget()*
5650 Returns a List of all the highlight group attributes. If the
5651 optional {name} is specified, then returns a List with only
5652 the attributes of the specified highlight group. Returns an
5653 empty List if the highlight group {name} is not present.
5654
5655 If the optional {resolve} argument is set to v:true and the
5656 highlight group {name} is linked to another group, then the
5657 link is resolved recursively and the attributes of the
5658 resolved highlight group are returned.
5659
5660 Each entry in the returned List is a Dictionary with the
5661 following items:
5662 cleared boolean flag, set to v:true if the highlight
5663 group attributes are cleared or not yet
5664 specified. See |highlight-clear|.
5665 cterm cterm attributes. See |highlight-cterm|.
5666 ctermbg cterm background color.
5667 See |highlight-ctermbg|.
5668 ctermfg cterm foreground color.
5669 See |highlight-ctermfg|.
5670 ctermul cterm underline color. See |highlight-ctermul|.
5671 default boolean flag, set to v:true if the highlight
5672 group link is a default link. See
5673 |highlight-default|.
5674 font highlight group font. See |highlight-font|.
5675 gui gui attributes. See |highlight-gui|.
5676 guibg gui background color. See |highlight-guibg|.
5677 guifg gui foreground color. See |highlight-guifg|.
5678 guisp gui special color. See |highlight-guisp|.
5679 id highlight group ID.
5680 linksto linked highlight group name.
5681 See |:highlight-link|.
5682 name highlight group name. See |group-name|.
5683 start start terminal keycode. See |highlight-start|.
5684 stop stop terminal keycode. See |highlight-stop|.
5685 term term attributes. See |highlight-term|.
5686
5687 The 'term', 'cterm' and 'gui' items in the above Dictionary
5688 have a dictionary value with the following optional boolean
5689 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5690 'reverse', 'inverse' and 'strikethrough'.
5691
5692 Example(s): >
5693 :echo hlget()
5694 :echo hlget('ModeMsg')
5695 :echo hlget('Number', v:true)
5696<
5697 Can also be used as a |method|: >
5698 GetName()->hlget()
5699<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005700 Return type: list<dict<any>>
5701
5702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005703hlset({list}) *hlset()*
5704 Creates or modifies the attributes of a List of highlight
5705 groups. Each item in {list} is a dictionary containing the
5706 attributes of a highlight group. See |hlget()| for the list of
5707 supported items in this dictionary.
5708
5709 In addition to the items described in |hlget()|, the following
5710 additional items are supported in the dictionary:
5711
5712 force boolean flag to force the creation of
5713 a link for an existing highlight group
5714 with attributes.
5715
5716 The highlight group is identified using the 'name' item and
5717 the 'id' item (if supplied) is ignored. If a highlight group
5718 with a specified name doesn't exist, then it is created.
5719 Otherwise the attributes of an existing highlight group are
5720 modified.
5721
5722 If an empty dictionary value is used for the 'term' or 'cterm'
5723 or 'gui' entries, then the corresponding attributes are
5724 cleared. If the 'cleared' item is set to v:true, then all the
5725 attributes of the highlight group are cleared.
5726
5727 The 'linksto' item can be used to link a highlight group to
5728 another highlight group. See |:highlight-link|.
5729
5730 Returns zero for success, -1 for failure.
5731
5732 Example(s): >
5733 " add bold attribute to the Visual highlight group
5734 :call hlset([#{name: 'Visual',
5735 \ term: #{reverse: 1 , bold: 1}}])
5736 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5737 :let l = hlget()
5738 :call hlset(l)
5739 " clear the Search highlight group
5740 :call hlset([#{name: 'Search', cleared: v:true}])
5741 " clear the 'term' attributes for a highlight group
5742 :call hlset([#{name: 'Title', term: {}}])
5743 " create the MyHlg group linking it to DiffAdd
5744 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5745 " remove the MyHlg group link
5746 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5747 " clear the attributes and a link
5748 :call hlset([#{name: 'MyHlg', cleared: v:true,
5749 \ linksto: 'NONE'}])
5750<
5751 Can also be used as a |method|: >
5752 GetAttrList()->hlset()
5753<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005754 Return type: |Number|
5755
5756hlID({name}) *hlID()*
5757 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005758 with name {name}. When the highlight group doesn't exist,
5759 zero is returned.
5760 This can be used to retrieve information about the highlight
5761 group. For example, to get the background color of the
5762 "Comment" group: >
5763 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5764< *highlightID()*
5765 Obsolete name: highlightID().
5766
5767 Can also be used as a |method|: >
5768 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005769<
5770 Return type: |Number|
5771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005772
5773hostname() *hostname()*
5774 The result is a String, which is the name of the machine on
5775 which Vim is currently running. Machine names greater than
5776 256 characters long are truncated.
5777
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005778 Return type: |String|
5779
5780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005781iconv({string}, {from}, {to}) *iconv()*
5782 The result is a String, which is the text {string} converted
5783 from encoding {from} to encoding {to}.
5784 When the conversion completely fails an empty string is
5785 returned. When some characters could not be converted they
5786 are replaced with "?".
5787 The encoding names are whatever the iconv() library function
5788 can accept, see ":!man 3 iconv".
5789 Most conversions require Vim to be compiled with the |+iconv|
5790 feature. Otherwise only UTF-8 to latin1 conversion and back
5791 can be done.
5792 This can be used to display messages with special characters,
5793 no matter what 'encoding' is set to. Write the message in
5794 UTF-8 and use: >
5795 echo iconv(utf8_str, "utf-8", &enc)
5796< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5797 from/to UCS-2 is automatically changed to use UTF-8. You
5798 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5799
5800 Can also be used as a |method|: >
5801 GetText()->iconv('latin1', 'utf-8')
5802<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005803 Return type: |String|
5804
5805
h-east624bb832024-11-09 18:37:32 +01005806id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005807 The result is a unique String associated with the {item} and
5808 not with the {item}'s contents. It is only valid while the
5809 {item} exists and is referenced. It is valid only in the
5810 instance of vim that produces the result. The whole idea is
5811 that `id({item})` does not change if the contents of {item}
5812 changes. This is useful as a `key` for creating an identity
5813 dictionary, rather than one based on equals.
5814
5815 This operation does not reference {item} and there is no
5816 function to convert the `id` to the {item}. It may be useful to
5817 have a map of `id` to {item}. The following >
5818 var referenceMap: dict<any>
5819 var id = item->id()
5820 referenceMap[id] = item
5821< prevents {item} from being garbage collected and provides a
5822 way to get the {item} from the `id`.
5823
5824 {item} may be a List, Dictionary, Object, Job, Channel or
5825 Blob. If the item is not a permitted type, or it is a null
5826 value, then an empty String is returned.
5827
5828 Can also be used as a |method|: >
5829 GetItem()->id()
5830<
5831 Return type: |String|
5832
5833
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005834indent({lnum}) *indent()*
5835 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005836 current buffer. The indent is counted in spaces, the value
5837 of 'tabstop' is relevant. {lnum} is used just like in
5838 |getline()|.
5839 When {lnum} is invalid -1 is returned. In |Vim9| script an
5840 error is given.
5841
5842 Can also be used as a |method|: >
5843 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005844<
5845 Return type: |Number|
5846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005847
5848index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005849 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005850 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005852 If {object} is a |List| return the lowest index where the item
5853 has a value equal to {expr}. There is no automatic
5854 conversion, so the String "4" is different from the Number 4.
5855 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005856 of 'ignorecase' is not used here, case matters as indicated by
5857 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005858
5859 If {object} is |Blob| return the lowest index where the byte
5860 value is equal to {expr}.
5861
5862 If {start} is given then start looking at the item with index
5863 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005864
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005865 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5866 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005868 -1 is returned when {expr} is not found in {object}.
5869 Example: >
5870 :let idx = index(words, "the")
5871 :if index(numbers, 123) >= 0
5872
5873< Can also be used as a |method|: >
5874 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005875<
5876 Return type: |Number|
5877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005878
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005879indexof({object}, {expr} [, {opts}]) *indexof()*
5880 Returns the index of an item in {object} where {expr} is
5881 v:true. {object} must be a |List| or a |Blob|.
5882
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005883 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005884 List until the expression is v:true and return the index of
5885 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005886
5887 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005888 Blob until the expression is v:true and return the index of
5889 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005890
5891 {expr} must be a |string| or |Funcref|.
5892
5893 If {expr} is a |string|: If {object} is a |List|, inside
5894 {expr} |v:key| has the index of the current List item and
5895 |v:val| has the value of the item. If {object} is a |Blob|,
5896 inside {expr} |v:key| has the index of the current byte and
5897 |v:val| has the byte value.
5898
5899 If {expr} is a |Funcref| it must take two arguments:
5900 1. the key or the index of the current item.
5901 2. the value of the current item.
5902 The function must return |TRUE| if the item is found and the
5903 search should stop.
5904
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005905 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005906 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005907 startidx start evaluating {expr} at the item with this
5908 index; may be negative for an item relative to
5909 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005910 Returns -1 when {expr} evaluates to v:false for all the items.
5911 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005912 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5913 :echo indexof(l, "v:val.n == 20")
5914 :echo indexof(l, {i, v -> v.n == 30})
5915 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005916
5917< Can also be used as a |method|: >
5918 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005919<
5920 Return type: |Number|
5921
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005923input({prompt} [, {text} [, {completion}]]) *input()*
5924 The result is a String, which is whatever the user typed on
5925 the command-line. The {prompt} argument is either a prompt
5926 string, or a blank string (for no prompt). A '\n' can be used
5927 in the prompt to start a new line.
5928 The highlighting set with |:echohl| is used for the prompt.
5929 The input is entered just like a command-line, with the same
5930 editing commands and mappings. There is a separate history
5931 for lines typed for input().
5932 Example: >
5933 :if input("Coffee or beer? ") == "beer"
5934 : echo "Cheers!"
5935 :endif
5936<
5937 If the optional {text} argument is present and not empty, this
5938 is used for the default reply, as if the user typed this.
5939 Example: >
5940 :let color = input("Color? ", "white")
5941
5942< The optional {completion} argument specifies the type of
5943 completion supported for the input. Without it completion is
5944 not performed. The supported completion types are the same as
5945 that can be supplied to a user-defined command using the
5946 "-complete=" argument. Refer to |:command-completion| for
5947 more information. Example: >
5948 let fname = input("File: ", "", "file")
5949<
5950 NOTE: This function must not be used in a startup file, for
5951 the versions that only run in GUI mode (e.g., the Win32 GUI).
5952 Note: When input() is called from within a mapping it will
5953 consume remaining characters from that mapping, because a
5954 mapping is handled like the characters were typed.
5955 Use |inputsave()| before input() and |inputrestore()|
5956 after input() to avoid that. Another solution is to avoid
5957 that further characters follow in the mapping, e.g., by using
5958 |:execute| or |:normal|.
5959
5960 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005961 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005962 :function GetFoo()
5963 : call inputsave()
5964 : let g:Foo = input("enter search pattern: ")
5965 : call inputrestore()
5966 :endfunction
5967
5968< Can also be used as a |method|: >
5969 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005970<
5971 Return type: |String|
5972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005973
5974inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5975 Like |input()|, but when the GUI is running and text dialogs
5976 are supported, a dialog window pops up to input the text.
5977 Example: >
5978 :let n = inputdialog("value for shiftwidth", shiftwidth())
5979 :if n != ""
5980 : let &sw = n
5981 :endif
5982< When the dialog is cancelled {cancelreturn} is returned. When
5983 omitted an empty string is returned.
5984 Hitting <Enter> works like pressing the OK button. Hitting
5985 <Esc> works like pressing the Cancel button.
5986 NOTE: Command-line completion is not supported.
5987
5988 Can also be used as a |method|: >
5989 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005990<
5991 Return type: |String|
5992
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005993
5994inputlist({textlist}) *inputlist()*
5995 {textlist} must be a |List| of strings. This |List| is
5996 displayed, one string per line. The user will be prompted to
5997 enter a number, which is returned.
5998 The user can also select an item by clicking on it with the
5999 mouse, if the mouse is enabled in the command line ('mouse' is
6000 "a" or includes "c"). For the first string 0 is returned.
6001 When clicking above the first item a negative number is
6002 returned. When clicking on the prompt one more than the
6003 length of {textlist} is returned.
6004 Make sure {textlist} has less than 'lines' entries, otherwise
6005 it won't work. It's a good idea to put the entry number at
6006 the start of the string. And put a prompt in the first item.
6007 Example: >
6008 let color = inputlist(['Select color:', '1. red',
6009 \ '2. green', '3. blue'])
6010
6011< Can also be used as a |method|: >
6012 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006013<
6014 Return type: |Number|
6015
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006016
6017inputrestore() *inputrestore()*
6018 Restore typeahead that was saved with a previous |inputsave()|.
6019 Should be called the same number of times inputsave() is
6020 called. Calling it more often is harmless though.
6021 Returns TRUE when there is nothing to restore, FALSE otherwise.
6022
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006023 Return type: |Number|
6024
6025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006026inputsave() *inputsave()*
6027 Preserve typeahead (also from mappings) and clear it, so that
6028 a following prompt gets input from the user. Should be
6029 followed by a matching inputrestore() after the prompt. Can
6030 be used several times, in which case there must be just as
6031 many inputrestore() calls.
6032 Returns TRUE when out of memory, FALSE otherwise.
6033
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006034 Return type: |Number|
6035
6036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006037inputsecret({prompt} [, {text}]) *inputsecret()*
6038 This function acts much like the |input()| function with but
6039 two exceptions:
6040 a) the user's response will be displayed as a sequence of
6041 asterisks ("*") thereby keeping the entry secret, and
6042 b) the user's response will not be recorded on the input
6043 |history| stack.
6044 The result is a String, which is whatever the user actually
6045 typed on the command-line in response to the issued prompt.
6046 NOTE: Command-line completion is not supported.
6047
6048 Can also be used as a |method|: >
6049 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006050<
6051 Return type: |String|
6052
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006053
6054insert({object}, {item} [, {idx}]) *insert()*
6055 When {object} is a |List| or a |Blob| insert {item} at the start
6056 of it.
6057
6058 If {idx} is specified insert {item} before the item with index
6059 {idx}. If {idx} is zero it goes before the first item, just
6060 like omitting {idx}. A negative {idx} is also possible, see
6061 |list-index|. -1 inserts just before the last item.
6062
6063 Returns the resulting |List| or |Blob|. Examples: >
6064 :let mylist = insert([2, 3, 5], 1)
6065 :call insert(mylist, 4, -1)
6066 :call insert(mylist, 6, len(mylist))
6067< The last example can be done simpler with |add()|.
6068 Note that when {item} is a |List| it is inserted as a single
6069 item. Use |extend()| to concatenate |Lists|.
6070
6071 Can also be used as a |method|: >
6072 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006073<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006074 Return type: |Number|
6075
6076
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006077 *instanceof()* *E614* *E616* *E693*
6078instanceof({object}, {class})
6079 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006080 argument is a direct or indirect instance of a |Class|,
6081 |Interface|, or class |:type| alias specified by {class}.
6082 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006083 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006084 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006085 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006086
6087< Can also be used as a |method|: >
6088 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006089<
6090 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006092interrupt() *interrupt()*
6093 Interrupt script execution. It works more or less like the
6094 user typing CTRL-C, most commands won't execute and control
6095 returns to the user. This is useful to abort execution
6096 from lower down, e.g. in an autocommand. Example: >
6097 :function s:check_typoname(file)
6098 : if fnamemodify(a:file, ':t') == '['
6099 : echomsg 'Maybe typo'
6100 : call interrupt()
6101 : endif
6102 :endfunction
6103 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006104<
6105 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006106
6107invert({expr}) *invert()*
6108 Bitwise invert. The argument is converted to a number. A
6109 List, Dict or Float argument causes an error. Example: >
6110 :let bits = invert(bits)
6111< Can also be used as a |method|: >
6112 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006113<
6114 Return type: |Number|
6115
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006116
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006117isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006118 The result is a Number, which is |TRUE| when {path} is an
6119 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006120 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006121 On MS-Windows, it is considered absolute when it starts with an
6122 optional drive prefix and is followed by a '\' or '/'. UNC paths
6123 are always absolute.
6124 Example: >
6125 echo isabsolutepath('/usr/share/') " 1
6126 echo isabsolutepath('./foobar') " 0
6127 echo isabsolutepath('C:\Windows') " 1
6128 echo isabsolutepath('foobar') " 0
6129 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006130<
LemonBoydca1d402022-04-28 15:26:33 +01006131 Can also be used as a |method|: >
6132 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006133<
6134 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006135
6136
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006137isdirectory({directory}) *isdirectory()*
6138 The result is a Number, which is |TRUE| when a directory
6139 with the name {directory} exists. If {directory} doesn't
6140 exist, or isn't a directory, the result is |FALSE|. {directory}
6141 is any expression, which is used as a String.
6142
6143 Can also be used as a |method|: >
6144 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006145<
6146 Return type: |Number|
6147
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006148
6149isinf({expr}) *isinf()*
6150 Return 1 if {expr} is a positive infinity, or -1 a negative
6151 infinity, otherwise 0. >
6152 :echo isinf(1.0 / 0.0)
6153< 1 >
6154 :echo isinf(-1.0 / 0.0)
6155< -1
6156
6157 Can also be used as a |method|: >
6158 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006159<
6160 Return type: |Number|
6161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006162
6163islocked({expr}) *islocked()* *E786*
6164 The result is a Number, which is |TRUE| when {expr} is the
6165 name of a locked variable.
6166 The string argument {expr} must be the name of a variable,
6167 |List| item or |Dictionary| entry, not the variable itself!
6168 Example: >
6169 :let alist = [0, ['a', 'b'], 2, 3]
6170 :lockvar 1 alist
6171 :echo islocked('alist') " 1
6172 :echo islocked('alist[1]') " 0
6173
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006174< When {expr} is a variable that does not exist -1 is returned.
6175 If {expr} uses a range, list or dict index that is out of
6176 range or does not exist you get an error message. Use
6177 |exists()| to check for existence.
6178 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006179
6180 Can also be used as a |method|: >
6181 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006182<
6183 Return type: |Number|
6184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006185
6186isnan({expr}) *isnan()*
6187 Return |TRUE| if {expr} is a float with value NaN. >
6188 echo isnan(0.0 / 0.0)
6189< 1
6190
6191 Can also be used as a |method|: >
6192 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006193<
6194 Return type: |Number|
6195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006196
6197items({dict}) *items()*
6198 Return a |List| with all the key-value pairs of {dict}. Each
6199 |List| item is a list with two items: the key of a {dict}
6200 entry and the value of this entry. The |List| is in arbitrary
6201 order. Also see |keys()| and |values()|.
6202 Example: >
6203 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006204 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006205 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006206<
6207 A List or a String argument is also supported. In these
6208 cases, items() returns a List with the index and the value at
6209 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006210
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006211 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006212 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006213<
6214 Return type: list<list<any>> or list<any>
6215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006216
6217job_ functions are documented here: |job-functions-details|
6218
6219
6220join({list} [, {sep}]) *join()*
6221 Join the items in {list} together into one String.
6222 When {sep} is specified it is put in between the items. If
6223 {sep} is omitted a single space is used.
6224 Note that {sep} is not added at the end. You might want to
6225 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006226 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006227< String items are used as-is. |Lists| and |Dictionaries| are
6228 converted into a string like with |string()|.
6229 The opposite function is |split()|.
6230
6231 Can also be used as a |method|: >
6232 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006233<
6234 Return type: |String|
6235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006236
6237js_decode({string}) *js_decode()*
6238 This is similar to |json_decode()| with these differences:
6239 - Object key names do not have to be in quotes.
6240 - Strings can be in single quotes.
6241 - Empty items in an array (between two commas) are allowed and
6242 result in v:none items.
6243
6244 Can also be used as a |method|: >
6245 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006246<
6247 Return type: any, depending on {varname}
6248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006249
6250js_encode({expr}) *js_encode()*
6251 This is similar to |json_encode()| with these differences:
6252 - Object key names are not in quotes.
6253 - v:none items in an array result in an empty item between
6254 commas.
6255 For example, the Vim object:
6256 [1,v:none,{"one":1},v:none] ~
6257 Will be encoded as:
6258 [1,,{one:1},,] ~
6259 While json_encode() would produce:
6260 [1,null,{"one":1},null] ~
6261 This encoding is valid for JavaScript. It is more efficient
6262 than JSON, especially when using an array with optional items.
6263
6264 Can also be used as a |method|: >
6265 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006266<
6267 Return type: |String|
6268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006269
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006270json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006271 This parses a JSON formatted string and returns the equivalent
6272 in Vim values. See |json_encode()| for the relation between
6273 JSON and Vim values.
6274 The decoding is permissive:
6275 - A trailing comma in an array and object is ignored, e.g.
6276 "[1, 2, ]" is the same as "[1, 2]".
6277 - Integer keys are accepted in objects, e.g. {1:2} is the
6278 same as {"1":2}.
6279 - More floating point numbers are recognized, e.g. "1." for
6280 "1.0", or "001.2" for "1.2". Special floating point values
6281 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6282 are accepted.
6283 - Leading zeroes in integer numbers are ignored, e.g. "012"
6284 for "12" or "-012" for "-12".
6285 - Capitalization is ignored in literal names null, true or
6286 false, e.g. "NULL" for "null", "True" for "true".
6287 - Control characters U+0000 through U+001F which are not
6288 escaped in strings are accepted, e.g. " " (tab
6289 character in string) for "\t".
6290 - An empty JSON expression or made of only spaces is accepted
6291 and results in v:none.
6292 - Backslash in an invalid 2-character sequence escape is
6293 ignored, e.g. "\a" is decoded as "a".
6294 - A correct surrogate pair in JSON strings should normally be
6295 a 12 character sequence such as "\uD834\uDD1E", but
6296 json_decode() silently accepts truncated surrogate pairs
6297 such as "\uD834" or "\uD834\u"
6298 *E938*
6299 A duplicate key in an object, valid in rfc7159, is not
6300 accepted by json_decode() as the result must be a valid Vim
6301 type, e.g. this fails: {"a":"b", "a":"c"}
6302
6303 Can also be used as a |method|: >
6304 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006305<
6306 Return type: any, depending on {varname}
6307
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006308
6309json_encode({expr}) *json_encode()*
6310 Encode {expr} as JSON and return this as a string.
6311 The encoding is specified in:
6312 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006313 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006314 |Number| decimal number
6315 |Float| floating point number
6316 Float nan "NaN"
6317 Float inf "Infinity"
6318 Float -inf "-Infinity"
6319 |String| in double quotes (possibly null)
6320 |Funcref| not possible, error
6321 |List| as an array (possibly null); when
6322 used recursively: []
6323 |Dict| as an object (possibly null); when
6324 used recursively: {}
6325 |Blob| as an array of the individual bytes
6326 v:false "false"
6327 v:true "true"
6328 v:none "null"
6329 v:null "null"
6330 Note that NaN and Infinity are passed on as values. This is
6331 missing in the JSON standard, but several implementations do
6332 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006333 If a string contains an illegal character then the replacement
6334 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006335
6336 Can also be used as a |method|: >
6337 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006338<
6339 Return type: |String|
6340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006341
6342keys({dict}) *keys()*
6343 Return a |List| with all the keys of {dict}. The |List| is in
6344 arbitrary order. Also see |items()| and |values()|.
6345
6346 Can also be used as a |method|: >
6347 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006348<
6349 Return type: list<string>
6350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006351
zeertzjqcdc83932022-09-12 13:38:41 +01006352keytrans({string}) *keytrans()*
6353 Turn the internal byte representation of keys into a form that
6354 can be used for |:map|. E.g. >
6355 :let xx = "\<C-Home>"
6356 :echo keytrans(xx)
6357< <C-Home>
6358
6359 Can also be used as a |method|: >
6360 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006361<
6362 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006363
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006364
6365len({expr}) *len()* *E701*
6366 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006367 When {expr} is a String or a Number the length in bytes is
6368 used, as with |strlen()|.
6369 When {expr} is a |List| the number of items in the |List| is
6370 returned.
6371 When {expr} is a |Blob| the number of bytes is returned.
6372 When {expr} is a |Dictionary| the number of entries in the
6373 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006374 When {expr} is an |Object|, invokes the len() method in the
6375 object (if present) to get the length (|object-len()|).
6376 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006377
6378 Can also be used as a |method|: >
6379 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006380<
6381 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006382
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006383
6384 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006385libcall({libname}, {funcname}, {argument})
6386 Call function {funcname} in the run-time library {libname}
6387 with single argument {argument}.
6388 This is useful to call functions in a library that you
6389 especially made to be used with Vim. Since only one argument
6390 is possible, calling standard library functions is rather
6391 limited.
6392 The result is the String returned by the function. If the
6393 function returns NULL, this will appear as an empty string ""
6394 to Vim.
6395 If the function returns a number, use libcallnr()!
6396 If {argument} is a number, it is passed to the function as an
6397 int; if {argument} is a string, it is passed as a
6398 null-terminated string.
6399 This function will fail in |restricted-mode|.
6400
6401 libcall() allows you to write your own 'plug-in' extensions to
6402 Vim without having to recompile the program. It is NOT a
6403 means to call system functions! If you try to do so Vim will
6404 very probably crash.
6405
6406 For Win32, the functions you write must be placed in a DLL
6407 and use the normal C calling convention (NOT Pascal which is
6408 used in Windows System DLLs). The function must take exactly
6409 one parameter, either a character pointer or a long integer,
6410 and must return a character pointer or NULL. The character
6411 pointer returned must point to memory that will remain valid
6412 after the function has returned (e.g. in static data in the
6413 DLL). If it points to allocated memory, that memory will
6414 leak away. Using a static buffer in the function should work,
6415 it's then freed when the DLL is unloaded.
6416
6417 WARNING: If the function returns a non-valid pointer, Vim may
6418 crash! This also happens if the function returns a number,
6419 because Vim thinks it's a pointer.
6420 For Win32 systems, {libname} should be the filename of the DLL
6421 without the ".DLL" suffix. A full path is only required if
6422 the DLL is not in the usual places.
6423 For Unix: When compiling your own plugins, remember that the
6424 object code must be compiled as position-independent ('PIC').
6425 {only in Win32 and some Unix versions, when the |+libcall|
6426 feature is present}
6427 Examples: >
6428 :echo libcall("libc.so", "getenv", "HOME")
6429
6430< Can also be used as a |method|, the base is passed as the
6431 third argument: >
6432 GetValue()->libcall("libc.so", "getenv")
6433<
6434 *libcallnr()*
6435libcallnr({libname}, {funcname}, {argument})
6436 Just like |libcall()|, but used for a function that returns an
6437 int instead of a string.
6438 {only in Win32 on some Unix versions, when the |+libcall|
6439 feature is present}
6440 Examples: >
6441 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6442 :call libcallnr("libc.so", "printf", "Hello World!\n")
6443 :call libcallnr("libc.so", "sleep", 10)
6444<
6445 Can also be used as a |method|, the base is passed as the
6446 third argument: >
6447 GetValue()->libcallnr("libc.so", "printf")
6448<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006449 Return type: |String|
6450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006451
6452line({expr} [, {winid}]) *line()*
6453 The result is a Number, which is the line number of the file
6454 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006455 See |getpos()| for accepted positions.
6456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006457 To get the column number use |col()|. To get both use
6458 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006459
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006460 With the optional {winid} argument the values are obtained for
6461 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006462
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006463 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006465 Examples: >
6466 line(".") line number of the cursor
6467 line(".", winid) idem, in window "winid"
6468 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006469 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006470<
6471 To jump to the last known position when opening a file see
6472 |last-position-jump|.
6473
6474 Can also be used as a |method|: >
6475 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006476<
6477 Return type: |Number|
6478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006479
6480line2byte({lnum}) *line2byte()*
6481 Return the byte count from the start of the buffer for line
6482 {lnum}. This includes the end-of-line character, depending on
6483 the 'fileformat' option for the current buffer. The first
6484 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6485 This can also be used to get the byte count for the line just
6486 below the last line: >
6487 line2byte(line("$") + 1)
6488< This is the buffer size plus one. If 'fileencoding' is empty
6489 it is the file size plus one. {lnum} is used like with
6490 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6491 feature has been disabled at compile time, -1 is returned.
6492 Also see |byte2line()|, |go| and |:goto|.
6493
6494 Can also be used as a |method|: >
6495 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006496<
6497 Return type: |Number|
6498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006499
6500lispindent({lnum}) *lispindent()*
6501 Get the amount of indent for line {lnum} according the lisp
6502 indenting rules, as with 'lisp'.
6503 The indent is counted in spaces, the value of 'tabstop' is
6504 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006505 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006506 error is given.
6507
6508 Can also be used as a |method|: >
6509 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006510<
6511 Return type: |Number|
6512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006513
6514list2blob({list}) *list2blob()*
6515 Return a Blob concatenating all the number values in {list}.
6516 Examples: >
6517 list2blob([1, 2, 3, 4]) returns 0z01020304
6518 list2blob([]) returns 0z
6519< Returns an empty Blob on error. If one of the numbers is
6520 negative or more than 255 error *E1239* is given.
6521
6522 |blob2list()| does the opposite.
6523
6524 Can also be used as a |method|: >
6525 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006526<
6527 Return type: |Blob|
6528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006529
6530list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006531 Convert each number in {list} to a character string and
6532 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006533 list2str([32]) returns " "
6534 list2str([65, 66, 67]) returns "ABC"
6535< The same can be done (slowly) with: >
6536 join(map(list, {nr, val -> nr2char(val)}), '')
6537< |str2list()| does the opposite.
6538
6539 When {utf8} is omitted or zero, the current 'encoding' is used.
6540 When {utf8} is TRUE, always return UTF-8 characters.
6541 With UTF-8 composing characters work as expected: >
6542 list2str([97, 769]) returns "á"
6543<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006544 Returns an empty string on error.
6545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006546 Can also be used as a |method|: >
6547 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006548<
6549 Return type: |String|
6550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006551
6552listener_add({callback} [, {buf}]) *listener_add()*
6553 Add a callback function that will be invoked when changes have
6554 been made to buffer {buf}.
6555 {buf} refers to a buffer name or number. For the accepted
6556 values, see |bufname()|. When {buf} is omitted the current
6557 buffer is used.
6558 Returns a unique ID that can be passed to |listener_remove()|.
6559
6560 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006561 bufnr the buffer that was changed
6562 start first changed line number
6563 end first line number below the change
6564 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006565 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006566 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006567
6568 Example: >
6569 func Listener(bufnr, start, end, added, changes)
6570 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6571 endfunc
6572 call listener_add('Listener', bufnr)
6573
Bram Moolenaar944697a2022-02-20 19:48:20 +00006574< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006575 dictionary with these entries:
6576 lnum the first line number of the change
6577 end the first line below the change
6578 added number of lines added; negative if lines were
6579 deleted
6580 col first column in "lnum" that was affected by
6581 the change; one if unknown or the whole line
6582 was affected; this is a byte index, first
6583 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006584 When lines are inserted (not when a line is split, e.g. by
6585 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006586 lnum line above which the new line is added
6587 end equal to "lnum"
6588 added number of lines inserted
6589 col 1
6590 When lines are deleted the values are:
6591 lnum the first deleted line
6592 end the line below the first deleted line, before
6593 the deletion was done
6594 added negative, number of lines deleted
6595 col 1
6596 When lines are changed:
6597 lnum the first changed line
6598 end the line below the last changed line
6599 added 0
6600 col first column with a change or 1
6601
6602 The entries are in the order the changes were made, thus the
6603 most recent change is at the end. The line numbers are valid
6604 when the callback is invoked, but later changes may make them
6605 invalid, thus keeping a copy for later might not work.
6606
6607 The {callback} is invoked just before the screen is updated,
6608 when |listener_flush()| is called or when a change is being
6609 made that changes the line count in a way it causes a line
6610 number in the list of changes to become invalid.
6611
6612 The {callback} is invoked with the text locked, see
6613 |textlock|. If you do need to make changes to the buffer, use
6614 a timer to do this later |timer_start()|.
6615
6616 The {callback} is not invoked when the buffer is first loaded.
6617 Use the |BufReadPost| autocmd event to handle the initial text
6618 of a buffer.
6619 The {callback} is also not invoked when the buffer is
6620 unloaded, use the |BufUnload| autocmd event for that.
6621
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006622 Returns zero if {callback} or {buf} is invalid.
6623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006624 Can also be used as a |method|, the base is passed as the
6625 second argument: >
6626 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006627<
6628 Return type: |Number|
6629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006630
6631listener_flush([{buf}]) *listener_flush()*
6632 Invoke listener callbacks for buffer {buf}. If there are no
6633 pending changes then no callbacks are invoked.
6634
6635 {buf} refers to a buffer name or number. For the accepted
6636 values, see |bufname()|. When {buf} is omitted the current
6637 buffer is used.
6638
6639 Can also be used as a |method|: >
6640 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006641<
6642 Return type: |Number|
6643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006644
6645listener_remove({id}) *listener_remove()*
6646 Remove a listener previously added with listener_add().
6647 Returns FALSE when {id} could not be found, TRUE when {id} was
6648 removed.
6649
6650 Can also be used as a |method|: >
6651 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006652<
6653 Return type: |Number|
6654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006655
6656localtime() *localtime()*
6657 Return the current time, measured as seconds since 1st Jan
6658 1970. See also |strftime()|, |strptime()| and |getftime()|.
6659
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006660 Return type: |Number|
6661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006662
6663log({expr}) *log()*
6664 Return the natural logarithm (base e) of {expr} as a |Float|.
6665 {expr} must evaluate to a |Float| or a |Number| in the range
6666 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006667 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006668 Examples: >
6669 :echo log(10)
6670< 2.302585 >
6671 :echo log(exp(5))
6672< 5.0
6673
6674 Can also be used as a |method|: >
6675 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006676<
6677 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006678
6679
6680log10({expr}) *log10()*
6681 Return the logarithm of Float {expr} to base 10 as a |Float|.
6682 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006683 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006684 Examples: >
6685 :echo log10(1000)
6686< 3.0 >
6687 :echo log10(0.01)
6688< -2.0
6689
6690 Can also be used as a |method|: >
6691 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006692<
6693 Return type: |Float|
6694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006695
6696luaeval({expr} [, {expr}]) *luaeval()*
6697 Evaluate Lua expression {expr} and return its result converted
6698 to Vim data structures. Second {expr} may hold additional
6699 argument accessible as _A inside first {expr}.
6700 Strings are returned as they are.
6701 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006702 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006703 Dictionaries and lists obtained by vim.eval() are returned
6704 as-is.
6705 Other objects are returned as zero without any errors.
6706 See |lua-luaeval| for more details.
6707 Note that in a `:def` function local variables are not visible
6708 to {expr}.
6709
6710 Can also be used as a |method|: >
6711 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006712<
6713 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006714
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006715 {only available when compiled with the |+lua| feature}
6716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006717
6718map({expr1}, {expr2}) *map()*
6719 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006720 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006721 item in {expr1} with the result of evaluating {expr2}.
6722 For a |Blob| each byte is replaced.
6723 For a |String|, each character, including composing
6724 characters, is replaced.
6725 If the item type changes you may want to use |mapnew()| to
6726 create a new List or Dictionary. This is required when using
6727 Vim9 script.
6728
6729 {expr2} must be a |String| or |Funcref|.
6730
6731 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6732 of the current item. For a |Dictionary| |v:key| has the key
6733 of the current item and for a |List| |v:key| has the index of
6734 the current item. For a |Blob| |v:key| has the index of the
6735 current byte. For a |String| |v:key| has the index of the
6736 current character.
6737 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006738 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006739< This puts "> " before and " <" after each item in "mylist".
6740
6741 Note that {expr2} is the result of an expression and is then
6742 used as an expression again. Often it is good to use a
6743 |literal-string| to avoid having to double backslashes. You
6744 still have to double ' quotes
6745
6746 If {expr2} is a |Funcref| it is called with two arguments:
6747 1. The key or the index of the current item.
6748 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006749 With a legacy script lambda you don't get an error if it only
6750 accepts one argument, but with a Vim9 lambda you get "E1106:
6751 One argument too many", the number of arguments must match.
6752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006753 The function must return the new value of the item. Example
6754 that changes each value by "key-value": >
6755 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006756 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006757 endfunc
6758 call map(myDict, function('KeyValue'))
6759< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006760 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006761< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006762 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006763< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006764 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006765<
6766 The operation is done in-place for a |List| and |Dictionary|.
6767 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006768 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006769
6770< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6771 or a new |Blob| or |String|.
6772 When an error is encountered while evaluating {expr2} no
6773 further items in {expr1} are processed.
6774 When {expr2} is a Funcref errors inside a function are ignored,
6775 unless it was defined with the "abort" flag.
6776
6777 Can also be used as a |method|: >
6778 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006779<
6780 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6781 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006782
6783
6784maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6785 When {dict} is omitted or zero: Return the rhs of mapping
6786 {name} in mode {mode}. The returned String has special
6787 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006788 listing. When {dict} is TRUE a dictionary is returned, see
6789 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006790
6791 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006792 returned if {dict} is FALSE, otherwise returns an empty Dict.
6793 When the mapping for {name} is empty, then "<Nop>" is
6794 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006795
6796 The {name} can have special key names, like in the ":map"
6797 command.
6798
6799 {mode} can be one of these strings:
6800 "n" Normal
6801 "v" Visual (including Select)
6802 "o" Operator-pending
6803 "i" Insert
6804 "c" Cmd-line
6805 "s" Select
6806 "x" Visual
6807 "l" langmap |language-mapping|
6808 "t" Terminal-Job
6809 "" Normal, Visual and Operator-pending
6810 When {mode} is omitted, the modes for "" are used.
6811
6812 When {abbr} is there and it is |TRUE| use abbreviations
6813 instead of mappings.
6814
6815 When {dict} is there and it is |TRUE| return a dictionary
6816 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006817 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006818 "lhs" The {lhs} of the mapping as it would be typed
6819 "lhsraw" The {lhs} of the mapping as raw bytes
6820 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6821 form, only present when it differs from "lhsraw"
6822 "rhs" The {rhs} of the mapping as typed.
6823 "silent" 1 for a |:map-silent| mapping, else 0.
6824 "noremap" 1 if the {rhs} of the mapping is not remappable.
6825 "script" 1 if mapping was defined with <script>.
6826 "expr" 1 for an expression mapping (|:map-<expr>|).
6827 "buffer" 1 for a buffer local mapping (|:map-local|).
6828 "mode" Modes for which the mapping is defined. In
6829 addition to the modes mentioned above, these
6830 characters will be used:
6831 " " Normal, Visual and Operator-pending
6832 "!" Insert and Commandline mode
6833 (|mapmode-ic|)
6834 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006835 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006836 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006837 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006838 "lnum" The line number in "sid", zero if unknown.
6839 "nowait" Do not wait for other, longer mappings.
6840 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006841 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006842 "mode_bits" Vim's internal binary representation of "mode".
6843 |mapset()| ignores this; only "mode" is used.
6844 See |maplist()| for usage examples. The values
6845 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006846
6847 The dictionary can be used to restore a mapping with
6848 |mapset()|.
6849
6850 The mappings local to the current buffer are checked first,
6851 then the global mappings.
6852 This function can be used to map a key even when it's already
6853 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006854 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006855
6856< Can also be used as a |method|: >
6857 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006858<
6859 Return type: |String| or dict<any> depending on {dict}
6860
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006861
6862mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6863 Check if there is a mapping that matches with {name} in mode
6864 {mode}. See |maparg()| for {mode} and special names in
6865 {name}.
6866 When {abbr} is there and it is |TRUE| use abbreviations
6867 instead of mappings.
6868 A match happens with a mapping that starts with {name} and
6869 with a mapping which is equal to the start of {name}.
6870
6871 matches mapping "a" "ab" "abc" ~
6872 mapcheck("a") yes yes yes
6873 mapcheck("abc") yes yes yes
6874 mapcheck("ax") yes no no
6875 mapcheck("b") no no no
6876
6877 The difference with maparg() is that mapcheck() finds a
6878 mapping that matches with {name}, while maparg() only finds a
6879 mapping for {name} exactly.
6880 When there is no mapping that starts with {name}, an empty
6881 String is returned. If there is one, the RHS of that mapping
6882 is returned. If there are several mappings that start with
6883 {name}, the RHS of one of them is returned. This will be
6884 "<Nop>" if the RHS is empty.
6885 The mappings local to the current buffer are checked first,
6886 then the global mappings.
6887 This function can be used to check if a mapping can be added
6888 without being ambiguous. Example: >
6889 :if mapcheck("_vv") == ""
6890 : map _vv :set guifont=7x13<CR>
6891 :endif
6892< This avoids adding the "_vv" mapping when there already is a
6893 mapping for "_v" or for "_vvv".
6894
6895 Can also be used as a |method|: >
6896 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006897<
6898 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006899
6900
Ernie Rael09661202022-04-25 14:40:44 +01006901maplist([{abbr}]) *maplist()*
6902 Returns a |List| of all mappings. Each List item is a |Dict|,
6903 the same as what is returned by |maparg()|, see
6904 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6905 abbreviations instead of mappings.
6906
6907 Example to show all mappings with 'MultiMatch' in rhs: >
6908 vim9script
6909 echo maplist()->filter(
6910 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006911< It can be tricky to find mappings for particular |:map-modes|.
6912 |mapping-dict|'s "mode_bits" can simplify this. For example,
6913 the mode_bits for Normal, Insert or Command-line modes are
6914 0x19. To find all the mappings available in those modes you
6915 can do: >
6916 vim9script
6917 var saved_maps = []
6918 for m in maplist()
6919 if and(m.mode_bits, 0x19) != 0
6920 saved_maps->add(m)
6921 endif
6922 endfor
6923 echo saved_maps->mapnew((_, m) => m.lhs)
6924< The values of the mode_bits are defined in Vim's src/vim.h
6925 file and they can be discovered at runtime using
6926 |:map-commands| and "maplist()". Example: >
6927 vim9script
6928 omap xyzzy <Nop>
6929 var op_bit = maplist()->filter(
6930 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6931 ounmap xyzzy
6932 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006933<
6934 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006935
6936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006937mapnew({expr1}, {expr2}) *mapnew()*
6938 Like |map()| but instead of replacing items in {expr1} a new
6939 List or Dictionary is created and returned. {expr1} remains
6940 unchanged. Items can still be changed by {expr2}, if you
6941 don't want that use |deepcopy()| first.
6942
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006943 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6944 depending on {expr1}
6945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006946
6947mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006948mapset({dict})
6949 Restore a mapping from a dictionary, possibly returned by
6950 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6951 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006952 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006953 feature allows copying mappings from one buffer to another.
6954 The dict.mode value may restore a single mapping that covers
6955 more than one mode, like with mode values of '!', ' ', 'nox',
6956 or 'v'. *E1276*
6957
6958 In the first form, {mode} and {abbr} should be the same as
6959 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006960 {mode} is used to define the mode in which the mapping is set,
6961 not the "mode" entry in {dict}.
6962 Example for saving and restoring a mapping: >
6963 let save_map = maparg('K', 'n', 0, 1)
6964 nnoremap K somethingelse
6965 ...
6966 call mapset('n', 0, save_map)
6967< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006968 e.g. with `:map!`, you need to save/restore the mapping for
6969 all of them, when they might differ.
6970
6971 In the second form, with {dict} as the only argument, mode
6972 and abbr are taken from the dict.
6973 Example: >
6974 vim9script
6975 var save_maps = maplist()->filter(
6976 (_, m) => m.lhs == 'K')
6977 nnoremap K somethingelse
6978 cnoremap K somethingelse2
6979 # ...
6980 unmap K
6981 for d in save_maps
6982 mapset(d)
6983 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006984<
6985 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006986
6987
6988match({expr}, {pat} [, {start} [, {count}]]) *match()*
6989 When {expr} is a |List| then this returns the index of the
6990 first item where {pat} matches. Each item is used as a
6991 String, |Lists| and |Dictionaries| are used as echoed.
6992
6993 Otherwise, {expr} is used as a String. The result is a
6994 Number, which gives the index (byte offset) in {expr} where
6995 {pat} matches.
6996
6997 A match at the first character or |List| item returns zero.
6998 If there is no match -1 is returned.
6999
7000 For getting submatches see |matchlist()|.
7001 Example: >
7002 :echo match("testing", "ing") " results in 4
7003 :echo match([1, 'x'], '\a') " results in 1
7004< See |string-match| for how {pat} is used.
7005 *strpbrk()*
7006 Vim doesn't have a strpbrk() function. But you can do: >
7007 :let sepidx = match(line, '[.,;: \t]')
7008< *strcasestr()*
7009 Vim doesn't have a strcasestr() function. But you can add
7010 "\c" to the pattern to ignore case: >
7011 :let idx = match(haystack, '\cneedle')
7012<
7013 If {start} is given, the search starts from byte index
7014 {start} in a String or item {start} in a |List|.
7015 The result, however, is still the index counted from the
7016 first character/item. Example: >
7017 :echo match("testing", "ing", 2)
7018< result is again "4". >
7019 :echo match("testing", "ing", 4)
7020< result is again "4". >
7021 :echo match("testing", "t", 2)
7022< result is "3".
7023 For a String, if {start} > 0 then it is like the string starts
7024 {start} bytes later, thus "^" will match at {start}. Except
7025 when {count} is given, then it's like matches before the
7026 {start} byte are ignored (this is a bit complicated to keep it
7027 backwards compatible).
7028 For a String, if {start} < 0, it will be set to 0. For a list
7029 the index is counted from the end.
7030 If {start} is out of range ({start} > strlen({expr}) for a
7031 String or {start} > len({expr}) for a |List|) -1 is returned.
7032
7033 When {count} is given use the {count}'th match. When a match
7034 is found in a String the search for the next one starts one
7035 character further. Thus this example results in 1: >
7036 echo match("testing", "..", 0, 2)
7037< In a |List| the search continues in the next item.
7038 Note that when {count} is added the way {start} works changes,
7039 see above.
7040
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007041 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007042 See |pattern| for the patterns that are accepted.
7043 The 'ignorecase' option is used to set the ignore-caseness of
7044 the pattern. 'smartcase' is NOT used. The matching is always
7045 done like 'magic' is set and 'cpoptions' is empty.
7046 Note that a match at the start is preferred, thus when the
7047 pattern is using "*" (any number of matches) it tends to find
7048 zero matches at the start instead of a number of matches
7049 further down in the text.
7050
7051 Can also be used as a |method|: >
7052 GetText()->match('word')
7053 GetList()->match('word')
7054<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007055 Return type: |Number|
7056
7057
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007058 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007059matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7060 Defines a pattern to be highlighted in the current window (a
7061 "match"). It will be highlighted with {group}. Returns an
7062 identification number (ID), which can be used to delete the
7063 match using |matchdelete()|. The ID is bound to the window.
7064 Matching is case sensitive and magic, unless case sensitivity
7065 or magicness are explicitly overridden in {pattern}. The
7066 'magic', 'smartcase' and 'ignorecase' options are not used.
7067 The "Conceal" value is special, it causes the match to be
7068 concealed.
7069
7070 The optional {priority} argument assigns a priority to the
7071 match. A match with a high priority will have its
7072 highlighting overrule that of a match with a lower priority.
7073 A priority is specified as an integer (negative numbers are no
7074 exception). If the {priority} argument is not specified, the
7075 default priority is 10. The priority of 'hlsearch' is zero,
7076 hence all matches with a priority greater than zero will
7077 overrule it. Syntax highlighting (see 'syntax') is a separate
7078 mechanism, and regardless of the chosen priority a match will
7079 always overrule syntax highlighting.
7080
7081 The optional {id} argument allows the request for a specific
7082 match ID. If a specified ID is already taken, an error
7083 message will appear and the match will not be added. An ID
7084 is specified as a positive integer (zero excluded). IDs 1, 2
7085 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007086 respectively. 3 is reserved for use by the |matchparen|
7087 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007088 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007089 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007090
7091 The optional {dict} argument allows for further custom
7092 values. Currently this is used to specify a match specific
7093 conceal character that will be shown for |hl-Conceal|
7094 highlighted matches. The dict can have the following members:
7095
7096 conceal Special character to show instead of the
7097 match (only for |hl-Conceal| highlighted
7098 matches, see |:syn-cchar|)
7099 window Instead of the current window use the
7100 window with this number or window ID.
7101
7102 The number of matches is not limited, as it is the case with
7103 the |:match| commands.
7104
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007105 Returns -1 on error.
7106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007107 Example: >
7108 :highlight MyGroup ctermbg=green guibg=green
7109 :let m = matchadd("MyGroup", "TODO")
7110< Deletion of the pattern: >
7111 :call matchdelete(m)
7112
7113< A list of matches defined by |matchadd()| and |:match| are
7114 available from |getmatches()|. All matches can be deleted in
7115 one operation by |clearmatches()|.
7116
7117 Can also be used as a |method|: >
7118 GetGroup()->matchadd('TODO')
7119<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007120 Return type: |Number|
7121
7122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007123 *matchaddpos()*
7124matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7125 Same as |matchadd()|, but requires a list of positions {pos}
7126 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007127 because it does not handle regular expressions and it sets
7128 buffer line boundaries to redraw screen. It is supposed to be
7129 used when fast match additions and deletions are required, for
7130 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007131
7132 {pos} is a list of positions. Each position can be one of
7133 these:
7134 - A number. This whole line will be highlighted. The first
7135 line has number 1.
7136 - A list with one number, e.g., [23]. The whole line with this
7137 number will be highlighted.
7138 - A list with two numbers, e.g., [23, 11]. The first number is
7139 the line number, the second one is the column number (first
7140 column is 1, the value must correspond to the byte index as
7141 |col()| would return). The character at this position will
7142 be highlighted.
7143 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7144 the third number gives the length of the highlight in bytes.
7145
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007146 Returns -1 on error.
7147
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007148 Example: >
7149 :highlight MyGroup ctermbg=green guibg=green
7150 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7151< Deletion of the pattern: >
7152 :call matchdelete(m)
7153
7154< Matches added by |matchaddpos()| are returned by
7155 |getmatches()|.
7156
7157 Can also be used as a |method|: >
7158 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007159<
7160 Return type: |Number|
7161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007162
7163matcharg({nr}) *matcharg()*
7164 Selects the {nr} match item, as set with a |:match|,
7165 |:2match| or |:3match| command.
7166 Return a |List| with two elements:
7167 The name of the highlight group used
7168 The pattern used.
7169 When {nr} is not 1, 2 or 3 returns an empty |List|.
7170 When there is no match item set returns ['', ''].
7171 This is useful to save and restore a |:match|.
7172 Highlighting matches using the |:match| commands are limited
7173 to three matches. |matchadd()| does not have this limitation.
7174
7175 Can also be used as a |method|: >
7176 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007177<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007178 Return type: list<string>
7179
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007180 *matchbufline()*
7181matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7182 Returns the |List| of matches in lines from {lnum} to {end} in
7183 buffer {buf} where {pat} matches.
7184
7185 {lnum} and {end} can either be a line number or the string "$"
7186 to refer to the last line in {buf}.
7187
7188 The {dict} argument supports following items:
7189 submatches include submatch information (|/\(|)
7190
7191 For each match, a |Dict| with the following items is returned:
7192 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007193 lnum line number where there is a match
7194 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007195 Note that there can be multiple matches in a single line.
7196
7197 This function works only for loaded buffers. First call
7198 |bufload()| if needed.
7199
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007200 See |match-pattern| for information about the effect of some
7201 option settings on the pattern.
7202
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007203 When {buf} is not a valid buffer, the buffer is not loaded or
7204 {lnum} or {end} is not valid then an error is given and an
7205 empty |List| is returned.
7206
7207 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007208 " Assuming line 3 in buffer 5 contains "a"
7209 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7210 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7211 " Assuming line 4 in buffer 10 contains "tik tok"
7212 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7213 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007214<
7215 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007216 "\1", "\2", etc. are also returned. Example: >
7217 " Assuming line 2 in buffer 2 contains "acd"
7218 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007219 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007220 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007221< The "submatches" List always contains 9 items. If a submatch
7222 is not found, then an empty string is returned for that
7223 submatch.
7224
7225 Can also be used as a |method|: >
7226 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007227<
7228 Return type: list<dict<any>> or list<any>
7229
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007230
h-east624bb832024-11-09 18:37:32 +01007231matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007232 Deletes a match with ID {id} previously defined by |matchadd()|
7233 or one of the |:match| commands. Returns 0 if successful,
7234 otherwise -1. See example for |matchadd()|. All matches can
7235 be deleted in one operation by |clearmatches()|.
7236 If {win} is specified, use the window with this number or
7237 window ID instead of the current window.
7238
7239 Can also be used as a |method|: >
7240 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007241<
7242 Return type: |Number|
7243
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007244
7245matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7246 Same as |match()|, but return the index of first character
7247 after the match. Example: >
7248 :echo matchend("testing", "ing")
7249< results in "7".
7250 *strspn()* *strcspn()*
7251 Vim doesn't have a strspn() or strcspn() function, but you can
7252 do it with matchend(): >
7253 :let span = matchend(line, '[a-zA-Z]')
7254 :let span = matchend(line, '[^a-zA-Z]')
7255< Except that -1 is returned when there are no matches.
7256
7257 The {start}, if given, has the same meaning as for |match()|. >
7258 :echo matchend("testing", "ing", 2)
7259< results in "7". >
7260 :echo matchend("testing", "ing", 5)
7261< result is "-1".
7262 When {expr} is a |List| the result is equal to |match()|.
7263
7264 Can also be used as a |method|: >
7265 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007266<
7267 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007268
7269
7270matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7271 If {list} is a list of strings, then returns a |List| with all
7272 the strings in {list} that fuzzy match {str}. The strings in
7273 the returned list are sorted based on the matching score.
7274
7275 The optional {dict} argument always supports the following
7276 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007277 matchseq When this item is present return only matches
7278 that contain the characters in {str} in the
7279 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007280 limit Maximum number of matches in {list} to be
7281 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007282 camelcase Use enhanced camel case scoring making results
7283 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007284 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007285
7286 If {list} is a list of dictionaries, then the optional {dict}
7287 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007288 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007289 {str}. The value of this item should be a
7290 string.
7291 text_cb |Funcref| that will be called for every item
7292 in {list} to get the text for fuzzy matching.
7293 This should accept a dictionary item as the
7294 argument and return the text for that item to
7295 use for fuzzy matching.
7296
7297 {str} is treated as a literal string and regular expression
7298 matching is NOT supported. The maximum supported {str} length
7299 is 256.
7300
7301 When {str} has multiple words each separated by white space,
7302 then the list of strings that have all the words is returned.
7303
7304 If there are no matching strings or there is an error, then an
7305 empty list is returned. If length of {str} is greater than
7306 256, then returns an empty list.
7307
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007308 When {limit} is given, matchfuzzy() will find up to this
7309 number of matches in {list} and return them in sorted order.
7310
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007311 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007312 matching strings.
7313
7314 Example: >
7315 :echo matchfuzzy(["clay", "crow"], "cay")
7316< results in ["clay"]. >
7317 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7318< results in a list of buffer names fuzzy matching "ndl". >
7319 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7320< results in a list of buffer information dicts with buffer
7321 names fuzzy matching "ndl". >
7322 :echo getbufinfo()->matchfuzzy("spl",
7323 \ {'text_cb' : {v -> v.name}})
7324< results in a list of buffer information dicts with buffer
7325 names fuzzy matching "spl". >
7326 :echo v:oldfiles->matchfuzzy("test")
7327< results in a list of file names fuzzy matching "test". >
7328 :let l = readfile("buffer.c")->matchfuzzy("str")
7329< results in a list of lines in "buffer.c" fuzzy matching "str". >
7330 :echo ['one two', 'two one']->matchfuzzy('two one')
7331< results in ['two one', 'one two']. >
7332 :echo ['one two', 'two one']->matchfuzzy('two one',
7333 \ {'matchseq': 1})
7334< results in ['two one'].
7335
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007336 Return type: list<string> or list<any>
7337
7338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007339matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7340 Same as |matchfuzzy()|, but returns the list of matched
7341 strings, the list of character positions where characters
7342 in {str} matches and a list of matching scores. You can
7343 use |byteidx()| to convert a character position to a byte
7344 position.
7345
7346 If {str} matches multiple times in a string, then only the
7347 positions for the best match is returned.
7348
7349 If there are no matching strings or there is an error, then a
7350 list with three empty list items is returned.
7351
7352 Example: >
7353 :echo matchfuzzypos(['testing'], 'tsg')
7354< results in [['testing'], [[0, 2, 6]], [99]] >
7355 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7356< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7357 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7358< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7359
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007360 Return type: list<list<any>>
7361
7362
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007363matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7364 Same as |match()|, but return a |List|. The first item in the
7365 list is the matched string, same as what matchstr() would
7366 return. Following items are submatches, like "\1", "\2", etc.
7367 in |:substitute|. When an optional submatch didn't match an
7368 empty string is used. Example: >
7369 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7370< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7371 When there is no match an empty list is returned.
7372
7373 You can pass in a List, but that is not very useful.
7374
7375 Can also be used as a |method|: >
7376 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007377<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007378 Return type: list<string> or list<any>
7379
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007380 *matchstrlist()*
7381matchstrlist({list}, {pat} [, {dict}])
7382 Returns the |List| of matches in {list} where {pat} matches.
7383 {list} is a |List| of strings. {pat} is matched against each
7384 string in {list}.
7385
7386 The {dict} argument supports following items:
7387 submatches include submatch information (|/\(|)
7388
7389 For each match, a |Dict| with the following items is returned:
7390 byteidx starting byte index of the match.
7391 idx index in {list} of the match.
7392 text matched string
7393 submatches a List of submatches. Present only if
7394 "submatches" is set to v:true in {dict}.
7395
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007396 See |match-pattern| for information about the effect of some
7397 option settings on the pattern.
7398
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007399 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007400 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7401 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7402 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7403 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007404<
7405 If "submatches" is present and is v:true, then submatches like
7406 "\1", "\2", etc. are also returned. Example: >
7407 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7408 \ #{submatches: v:true})
7409 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7410< The "submatches" List always contains 9 items. If a submatch
7411 is not found, then an empty string is returned for that
7412 submatch.
7413
7414 Can also be used as a |method|: >
7415 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007416<
7417 Return type: list<dict<any>> or list<any>
7418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007419
7420matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7421 Same as |match()|, but return the matched string. Example: >
7422 :echo matchstr("testing", "ing")
7423< results in "ing".
7424 When there is no match "" is returned.
7425 The {start}, if given, has the same meaning as for |match()|. >
7426 :echo matchstr("testing", "ing", 2)
7427< results in "ing". >
7428 :echo matchstr("testing", "ing", 5)
7429< result is "".
7430 When {expr} is a |List| then the matching item is returned.
7431 The type isn't changed, it's not necessarily a String.
7432
7433 Can also be used as a |method|: >
7434 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007435<
7436 Return type: |String|
7437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007438
7439matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7440 Same as |matchstr()|, but return the matched string, the start
7441 position and the end position of the match. Example: >
7442 :echo matchstrpos("testing", "ing")
7443< results in ["ing", 4, 7].
7444 When there is no match ["", -1, -1] is returned.
7445 The {start}, if given, has the same meaning as for |match()|. >
7446 :echo matchstrpos("testing", "ing", 2)
7447< results in ["ing", 4, 7]. >
7448 :echo matchstrpos("testing", "ing", 5)
7449< result is ["", -1, -1].
7450 When {expr} is a |List| then the matching item, the index
7451 of first item where {pat} matches, the start position and the
7452 end position of the match are returned. >
7453 :echo matchstrpos([1, '__x'], '\a')
7454< result is ["x", 1, 2, 3].
7455 The type isn't changed, it's not necessarily a String.
7456
7457 Can also be used as a |method|: >
7458 GetText()->matchstrpos('word')
7459<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007460 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007461
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007462
7463max({expr}) *max()*
7464 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007465 echo max([apples, pears, oranges])
7466
7467< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7468 it returns the maximum of all values in the Dictionary.
7469 If {expr} is neither a List nor a Dictionary, or one of the
7470 items in {expr} cannot be used as a Number this results in
7471 an error. An empty |List| or |Dictionary| results in zero.
7472
7473 Can also be used as a |method|: >
7474 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007475<
7476 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007477
7478
7479menu_info({name} [, {mode}]) *menu_info()*
7480 Return information about the specified menu {name} in
7481 mode {mode}. The menu name should be specified without the
7482 shortcut character ('&'). If {name} is "", then the top-level
7483 menu names are returned.
7484
7485 {mode} can be one of these strings:
7486 "n" Normal
7487 "v" Visual (including Select)
7488 "o" Operator-pending
7489 "i" Insert
7490 "c" Cmd-line
7491 "s" Select
7492 "x" Visual
7493 "t" Terminal-Job
7494 "" Normal, Visual and Operator-pending
7495 "!" Insert and Cmd-line
7496 When {mode} is omitted, the modes for "" are used.
7497
7498 Returns a |Dictionary| containing the following items:
7499 accel menu item accelerator text |menu-text|
7500 display display name (name without '&')
7501 enabled v:true if this menu item is enabled
7502 Refer to |:menu-enable|
7503 icon name of the icon file (for toolbar)
7504 |toolbar-icon|
7505 iconidx index of a built-in icon
7506 modes modes for which the menu is defined. In
7507 addition to the modes mentioned above, these
7508 characters will be used:
7509 " " Normal, Visual and Operator-pending
7510 name menu item name.
7511 noremenu v:true if the {rhs} of the menu item is not
7512 remappable else v:false.
7513 priority menu order priority |menu-priority|
7514 rhs right-hand-side of the menu item. The returned
7515 string has special characters translated like
7516 in the output of the ":menu" command listing.
7517 When the {rhs} of a menu item is empty, then
7518 "<Nop>" is returned.
7519 script v:true if script-local remapping of {rhs} is
7520 allowed else v:false. See |:menu-script|.
7521 shortcut shortcut key (character after '&' in
7522 the menu name) |menu-shortcut|
7523 silent v:true if the menu item is created
7524 with <silent> argument |:menu-silent|
7525 submenus |List| containing the names of
7526 all the submenus. Present only if the menu
7527 item has submenus.
7528
7529 Returns an empty dictionary if the menu item is not found.
7530
7531 Examples: >
7532 :echo menu_info('Edit.Cut')
7533 :echo menu_info('File.Save', 'n')
7534
7535 " Display the entire menu hierarchy in a buffer
7536 func ShowMenu(name, pfx)
7537 let m = menu_info(a:name)
7538 call append(line('$'), a:pfx .. m.display)
7539 for child in m->get('submenus', [])
7540 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7541 \ a:pfx .. ' ')
7542 endfor
7543 endfunc
7544 new
7545 for topmenu in menu_info('').submenus
7546 call ShowMenu(topmenu, '')
7547 endfor
7548<
7549 Can also be used as a |method|: >
7550 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007551<
7552 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007553
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007554min({expr}) *min()*
7555 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007556 echo min([apples, pears, oranges])
7557
7558< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7559 it returns the minimum of all values in the Dictionary.
7560 If {expr} is neither a List nor a Dictionary, or one of the
7561 items in {expr} cannot be used as a Number this results in
7562 an error. An empty |List| or |Dictionary| results in zero.
7563
7564 Can also be used as a |method|: >
7565 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007566<
7567 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007568
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007569
7570mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007571 Create directory {name}.
7572
Bram Moolenaar938ae282023-02-20 20:44:55 +00007573 When {flags} is present it must be a string. An empty string
7574 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007575
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007576 {flags} can contain these character flags:
7577 "p" intermediate directories will be created as necessary
7578 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007579 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007580 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007581 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007582
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007583 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007584 some directories may already exist. Only the first one that
7585 is created and what it contains is scheduled to be deleted.
7586 E.g. when using: >
7587 call mkdir('subdir/tmp/autoload', 'pR')
7588< and "subdir" already exists then "subdir/tmp" will be
7589 scheduled for deletion, like with: >
7590 defer delete('subdir/tmp', 'rf')
7591< Note that if scheduling the defer fails the directory is not
7592 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007593
7594 If {prot} is given it is used to set the protection bits of
7595 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7596 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007597 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007598 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007599 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007600 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007601
7602< This function is not available in the |sandbox|.
7603
7604 There is no error if the directory already exists and the "p"
7605 flag is passed (since patch 8.0.1708). However, without the
7606 "p" option the call will fail.
7607
7608 The function result is a Number, which is TRUE if the call was
7609 successful or FALSE if the directory creation failed or partly
7610 failed.
7611
7612 Not available on all systems. To check use: >
7613 :if exists("*mkdir")
7614
7615< Can also be used as a |method|: >
7616 GetName()->mkdir()
7617<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007618 Return type: |Number|
7619
7620
7621mode([{expr}]) *mode()*
7622 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007623 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007624 a non-empty String (|non-zero-arg|), then the full mode is
7625 returned, otherwise only the first letter is returned.
7626 Also see |state()|.
7627
7628 n Normal
7629 no Operator-pending
7630 nov Operator-pending (forced characterwise |o_v|)
7631 noV Operator-pending (forced linewise |o_V|)
7632 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7633 CTRL-V is one character
7634 niI Normal using |i_CTRL-O| in |Insert-mode|
7635 niR Normal using |i_CTRL-O| in |Replace-mode|
7636 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7637 nt Terminal-Normal (insert goes to Terminal-Job mode)
7638 v Visual by character
7639 vs Visual by character using |v_CTRL-O| in Select mode
7640 V Visual by line
7641 Vs Visual by line using |v_CTRL-O| in Select mode
7642 CTRL-V Visual blockwise
7643 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7644 s Select by character
7645 S Select by line
7646 CTRL-S Select blockwise
7647 i Insert
7648 ic Insert mode completion |compl-generic|
7649 ix Insert mode |i_CTRL-X| completion
7650 R Replace |R|
7651 Rc Replace mode completion |compl-generic|
7652 Rx Replace mode |i_CTRL-X| completion
7653 Rv Virtual Replace |gR|
7654 Rvc Virtual Replace mode completion |compl-generic|
7655 Rvx Virtual Replace mode |i_CTRL-X| completion
7656 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007657 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007658 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007659 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007660 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007661 ce Normal Ex mode |Q|
7662 r Hit-enter prompt
7663 rm The -- more -- prompt
7664 r? A |:confirm| query of some sort
7665 ! Shell or external command is executing
7666 t Terminal-Job mode: keys go to the job
7667
7668 This is useful in the 'statusline' option or when used
7669 with |remote_expr()| In most other places it always returns
7670 "c" or "n".
7671 Note that in the future more modes and more specific modes may
7672 be added. It's better not to compare the whole string but only
7673 the leading character(s).
7674 Also see |visualmode()|.
7675
7676 Can also be used as a |method|: >
7677 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007678<
7679 Return type: |String|
7680
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007681
7682mzeval({expr}) *mzeval()*
7683 Evaluate MzScheme expression {expr} and return its result
7684 converted to Vim data structures.
7685 Numbers and strings are returned as they are.
7686 Pairs (including lists and improper lists) and vectors are
7687 returned as Vim |Lists|.
7688 Hash tables are represented as Vim |Dictionary| type with keys
7689 converted to strings.
7690 All other types are converted to string with display function.
7691 Examples: >
7692 :mz (define l (list 1 2 3))
7693 :mz (define h (make-hash)) (hash-set! h "list" l)
7694 :echo mzeval("l")
7695 :echo mzeval("h")
7696<
7697 Note that in a `:def` function local variables are not visible
7698 to {expr}.
7699
7700 Can also be used as a |method|: >
7701 GetExpr()->mzeval()
7702<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007703 Return type: any, depending on {expr}
7704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007705 {only available when compiled with the |+mzscheme| feature}
7706
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007707
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007708nextnonblank({lnum}) *nextnonblank()*
7709 Return the line number of the first line at or below {lnum}
7710 that is not blank. Example: >
7711 if getline(nextnonblank(1)) =~ "Java"
7712< When {lnum} is invalid or there is no non-blank line at or
7713 below it, zero is returned.
7714 {lnum} is used like with |getline()|.
7715 See also |prevnonblank()|.
7716
7717 Can also be used as a |method|: >
7718 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007719<
7720 Return type: |Number|
7721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007722
Christ van Willegenc0786752025-02-01 15:42:16 +01007723ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7724 Return a string that contains the correct value for a
7725 message based on the rules for plural form(s) in
7726 a language. Examples: >
7727 ngettext("File", "Files", 2) # returns "Files"
7728<
7729 Can be used as a |method|: >
7730 1->ngettext("File", "Files") # returns "File"
7731<
7732 See |gettext()| for information on the domain parameter.
7733
7734 Return type: |String|
7735
7736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007737nr2char({expr} [, {utf8}]) *nr2char()*
7738 Return a string with a single character, which has the number
7739 value {expr}. Examples: >
7740 nr2char(64) returns "@"
7741 nr2char(32) returns " "
7742< When {utf8} is omitted or zero, the current 'encoding' is used.
7743 Example for "utf-8": >
7744 nr2char(300) returns I with bow character
7745< When {utf8} is TRUE, always return UTF-8 characters.
7746 Note that a NUL character in the file is specified with
7747 nr2char(10), because NULs are represented with newline
7748 characters. nr2char(0) is a real NUL and terminates the
7749 string, thus results in an empty string.
7750 To turn a list of character numbers into a string: >
7751 let list = [65, 66, 67]
7752 let str = join(map(list, {_, val -> nr2char(val)}), '')
7753< Result: "ABC"
7754
7755 Can also be used as a |method|: >
7756 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007757<
7758 Return type: |String|
7759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007760
7761or({expr}, {expr}) *or()*
7762 Bitwise OR on the two arguments. The arguments are converted
7763 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007764 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007765 Example: >
7766 :let bits = or(bits, 0x80)
7767< Can also be used as a |method|: >
7768 :let bits = bits->or(0x80)
7769
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007770< Rationale: The reason this is a function and not using the "|"
7771 character like many languages, is that Vi has always used "|"
7772 to separate commands. In many places it would not be clear if
7773 "|" is an operator or a command separator.
7774
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007775 Return type: |Number|
7776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007777
7778pathshorten({path} [, {len}]) *pathshorten()*
7779 Shorten directory names in the path {path} and return the
7780 result. The tail, the file name, is kept as-is. The other
7781 components in the path are reduced to {len} letters in length.
7782 If {len} is omitted or smaller than 1 then 1 is used (single
7783 letters). Leading '~' and '.' characters are kept. Examples: >
7784 :echo pathshorten('~/.vim/autoload/myfile.vim')
7785< ~/.v/a/myfile.vim ~
7786>
7787 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7788< ~/.vi/au/myfile.vim ~
7789 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007790 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007791
7792 Can also be used as a |method|: >
7793 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007794<
7795 Return type: |String|
7796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007797
7798perleval({expr}) *perleval()*
7799 Evaluate Perl expression {expr} in scalar context and return
7800 its result converted to Vim data structures. If value can't be
7801 converted, it is returned as a string Perl representation.
7802 Note: If you want an array or hash, {expr} must return a
7803 reference to it.
7804 Example: >
7805 :echo perleval('[1 .. 4]')
7806< [1, 2, 3, 4]
7807
7808 Note that in a `:def` function local variables are not visible
7809 to {expr}.
7810
7811 Can also be used as a |method|: >
7812 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007813<
7814 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007815
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007816 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007817
7818
7819popup_ functions are documented here: |popup-functions|
7820
7821
7822pow({x}, {y}) *pow()*
7823 Return the power of {x} to the exponent {y} as a |Float|.
7824 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007825 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007826 Examples: >
7827 :echo pow(3, 3)
7828< 27.0 >
7829 :echo pow(2, 16)
7830< 65536.0 >
7831 :echo pow(32, 0.20)
7832< 2.0
7833
7834 Can also be used as a |method|: >
7835 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007836<
7837 Return type: |Number|
7838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007839
7840prevnonblank({lnum}) *prevnonblank()*
7841 Return the line number of the first line at or above {lnum}
7842 that is not blank. Example: >
7843 let ind = indent(prevnonblank(v:lnum - 1))
7844< When {lnum} is invalid or there is no non-blank line at or
7845 above it, zero is returned.
7846 {lnum} is used like with |getline()|.
7847 Also see |nextnonblank()|.
7848
7849 Can also be used as a |method|: >
7850 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007851<
7852 Return type: |Number|
7853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007854
7855printf({fmt}, {expr1} ...) *printf()*
7856 Return a String with {fmt}, where "%" items are replaced by
7857 the formatted form of their respective arguments. Example: >
7858 printf("%4d: E%d %.30s", lnum, errno, msg)
7859< May result in:
7860 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7861
7862 When used as a |method| the base is passed as the second
7863 argument: >
7864 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007865<
7866 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007867
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007868 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007869 %s string
7870 %6S string right-aligned in 6 display cells
7871 %6s string right-aligned in 6 bytes
7872 %.9s string truncated to 9 bytes
7873 %c single byte
7874 %d decimal number
7875 %5d decimal number padded with spaces to 5 characters
7876 %x hex number
7877 %04x hex number padded with zeros to at least 4 characters
7878 %X hex number using upper case letters
7879 %o octal number
7880 %08b binary number padded with zeros to at least 8 chars
7881 %f floating point number as 12.23, inf, -inf or nan
7882 %F floating point number as 12.23, INF, -INF or NAN
7883 %e floating point number as 1.23e3, inf, -inf or nan
7884 %E floating point number as 1.23E3, INF, -INF or NAN
7885 %g floating point number, as %f or %e depending on value
7886 %G floating point number, as %F or %E depending on value
7887 %% the % character itself
7888
7889 Conversion specifications start with '%' and end with the
7890 conversion type. All other characters are copied unchanged to
7891 the result.
7892
7893 The "%" starts a conversion specification. The following
7894 arguments appear in sequence:
7895
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007896 % [pos-argument] [flags] [field-width] [.precision] type
7897
7898 pos-argument
7899 At most one positional argument specifier. These
7900 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007901
7902 flags
7903 Zero or more of the following flags:
7904
7905 # The value should be converted to an "alternate
7906 form". For c, d, and s conversions, this option
7907 has no effect. For o conversions, the precision
7908 of the number is increased to force the first
7909 character of the output string to a zero (except
7910 if a zero value is printed with an explicit
7911 precision of zero).
7912 For b and B conversions, a non-zero result has
7913 the string "0b" (or "0B" for B conversions)
7914 prepended to it.
7915 For x and X conversions, a non-zero result has
7916 the string "0x" (or "0X" for X conversions)
7917 prepended to it.
7918
7919 0 (zero) Zero padding. For all conversions the converted
7920 value is padded on the left with zeros rather
7921 than blanks. If a precision is given with a
7922 numeric conversion (d, b, B, o, x, and X), the 0
7923 flag is ignored.
7924
7925 - A negative field width flag; the converted value
7926 is to be left adjusted on the field boundary.
7927 The converted value is padded on the right with
7928 blanks, rather than on the left with blanks or
7929 zeros. A - overrides a 0 if both are given.
7930
7931 ' ' (space) A blank should be left before a positive
7932 number produced by a signed conversion (d).
7933
7934 + A sign must always be placed before a number
7935 produced by a signed conversion. A + overrides
7936 a space if both are used.
7937
7938 field-width
7939 An optional decimal digit string specifying a minimum
7940 field width. If the converted value has fewer bytes
7941 than the field width, it will be padded with spaces on
7942 the left (or right, if the left-adjustment flag has
7943 been given) to fill out the field width. For the S
7944 conversion the count is in cells.
7945
7946 .precision
7947 An optional precision, in the form of a period '.'
7948 followed by an optional digit string. If the digit
7949 string is omitted, the precision is taken as zero.
7950 This gives the minimum number of digits to appear for
7951 d, o, x, and X conversions, the maximum number of
7952 bytes to be printed from a string for s conversions,
7953 or the maximum number of cells to be printed from a
7954 string for S conversions.
7955 For floating point it is the number of digits after
7956 the decimal point.
7957
7958 type
7959 A character that specifies the type of conversion to
7960 be applied, see below.
7961
7962 A field width or precision, or both, may be indicated by an
7963 asterisk '*' instead of a digit string. In this case, a
7964 Number argument supplies the field width or precision. A
7965 negative field width is treated as a left adjustment flag
7966 followed by a positive field width; a negative precision is
7967 treated as though it were missing. Example: >
7968 :echo printf("%d: %.*s", nr, width, line)
7969< This limits the length of the text used from "line" to
7970 "width" bytes.
7971
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007972 If the argument to be formatted is specified using a
7973 positional argument specifier, and a '*' is used to indicate
7974 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007975 precision, the argument(s) to be used must also be specified
7976 using a {n$} positional argument specifier. See |printf-$|.
7977
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007978 The conversion specifiers and their meanings are:
7979
7980 *printf-d* *printf-b* *printf-B* *printf-o*
7981 *printf-x* *printf-X*
7982 dbBoxX The Number argument is converted to signed decimal
7983 (d), unsigned binary (b and B), unsigned octal (o), or
7984 unsigned hexadecimal (x and X) notation. The letters
7985 "abcdef" are used for x conversions; the letters
7986 "ABCDEF" are used for X conversions.
7987 The precision, if any, gives the minimum number of
7988 digits that must appear; if the converted value
7989 requires fewer digits, it is padded on the left with
7990 zeros.
7991 In no case does a non-existent or small field width
7992 cause truncation of a numeric field; if the result of
7993 a conversion is wider than the field width, the field
7994 is expanded to contain the conversion result.
7995 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007996 The 'l' modifier indicates the argument is a long
7997 integer. The size will be 32 bits or 64 bits
7998 depending on your platform.
7999 The "ll" modifier indicates the argument is 64 bits.
8000 The b and B conversion specifiers never take a width
8001 modifier and always assume their argument is a 64 bit
8002 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008003 Generally, these modifiers are not useful. They are
8004 ignored when type is known from the argument.
8005
8006 i alias for d
8007 D alias for ld
8008 U alias for lu
8009 O alias for lo
8010
8011 *printf-c*
8012 c The Number argument is converted to a byte, and the
8013 resulting character is written.
8014
8015 *printf-s*
8016 s The text of the String argument is used. If a
8017 precision is specified, no more bytes than the number
8018 specified are used.
8019 If the argument is not a String type, it is
8020 automatically converted to text with the same format
8021 as ":echo".
8022 *printf-S*
8023 S The text of the String argument is used. If a
8024 precision is specified, no more display cells than the
8025 number specified are used.
8026
8027 *printf-f* *E807*
8028 f F The Float argument is converted into a string of the
8029 form 123.456. The precision specifies the number of
8030 digits after the decimal point. When the precision is
8031 zero the decimal point is omitted. When the precision
8032 is not specified 6 is used. A really big number
8033 (out of range or dividing by zero) results in "inf"
8034 or "-inf" with %f (INF or -INF with %F).
8035 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8036 Example: >
8037 echo printf("%.2f", 12.115)
8038< 12.12
8039 Note that roundoff depends on the system libraries.
8040 Use |round()| when in doubt.
8041
8042 *printf-e* *printf-E*
8043 e E The Float argument is converted into a string of the
8044 form 1.234e+03 or 1.234E+03 when using 'E'. The
8045 precision specifies the number of digits after the
8046 decimal point, like with 'f'.
8047
8048 *printf-g* *printf-G*
8049 g G The Float argument is converted like with 'f' if the
8050 value is between 0.001 (inclusive) and 10000000.0
8051 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8052 for 'G'. When no precision is specified superfluous
8053 zeroes and '+' signs are removed, except for the zero
8054 immediately after the decimal point. Thus 10000000.0
8055 results in 1.0e7.
8056
8057 *printf-%*
8058 % A '%' is written. No argument is converted. The
8059 complete conversion specification is "%%".
8060
8061 When a Number argument is expected a String argument is also
8062 accepted and automatically converted.
8063 When a Float or String argument is expected a Number argument
8064 is also accepted and automatically converted.
8065 Any other argument type results in an error message.
8066
8067 *E766* *E767*
8068 The number of {exprN} arguments must exactly match the number
8069 of "%" items. If there are not sufficient or too many
8070 arguments an error is given. Up to 18 arguments can be used.
8071
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008072 *printf-$*
8073 In certain languages, error and informative messages are
8074 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008075 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008076 having a different word order, positional arguments may be
8077 used to indicate this. For instance: >
8078
h_east596a9f22023-11-21 21:24:23 +09008079 #, c-format
8080 msgid "%s returning %s"
8081 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008082<
h_east596a9f22023-11-21 21:24:23 +09008083 In this example, the sentence has its 2 string arguments
8084 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008085
h_east596a9f22023-11-21 21:24:23 +09008086 echo printf(
8087 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8088 "Bram", "Moolenaar")
8089< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008090
h_east596a9f22023-11-21 21:24:23 +09008091 echo printf(
8092 "In Belgium, vim's creator's name is: %2$s %1$s",
8093 "Bram", "Moolenaar")
8094< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008095
8096 Width (and precision) can be specified using the '*' specifier.
8097 In this case, you must specify the field width position in the
8098 argument list. >
8099
h_east596a9f22023-11-21 21:24:23 +09008100 echo printf("%1$*2$.*3$d", 1, 2, 3)
8101< 001 >
8102 echo printf("%2$*3$.*1$d", 1, 2, 3)
8103< 2 >
8104 echo printf("%3$*1$.*2$d", 1, 2, 3)
8105< 03 >
8106 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8107< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008108
8109 You can mix specifying the width and/or precision directly
8110 and via positional arguments: >
8111
h_east596a9f22023-11-21 21:24:23 +09008112 echo printf("%1$4.*2$f", 1.4142135, 6)
8113< 1.414214 >
8114 echo printf("%1$*2$.4f", 1.4142135, 6)
8115< 1.4142 >
8116 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8117< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008118
Christ van Willegenc35fc032024-03-14 18:30:41 +01008119 You will get an overflow error |E1510|, when the field-width
8120 or precision will result in a string longer than 6400 chars.
8121
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008122 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008123 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008124 echo printf("%s%1$s", "One", "Two")
8125< E1500: Cannot mix positional and non-positional arguments:
8126 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008127
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008128 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008129 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008130 echo printf("%3$s%1$s", "One", "Two", "Three")
8131< E1501: format argument 2 unused in $-style format:
8132 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008133
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008134 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008135 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008136 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8137< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008138
8139 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008140 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8141< E1502: Positional argument 2 used as field width reused as
8142 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008143
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008144 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008145 When a positional argument is used, but not the correct number
8146 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008147 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8148< E1503: Positional argument 3 out of bounds: %1$d at width
8149 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008150
8151 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008152 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8153< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8154 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008155
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008156 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008157 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008158 echo printf("%1$s %2$s %1$s", "One", "Two")
8159< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008160
8161 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008162 echo printf("%1$s %2$s %1$d", "One", "Two")
8163< E1504: Positional argument 1 type used inconsistently:
8164 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008165
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008166 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008167 Various other errors that lead to a format string being
8168 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008169 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8170< E1505: Invalid format specifier: %1$d at width %2$d is:
8171 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008172
Christ van Willegenea746f92023-10-05 20:48:36 +02008173 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008174 This internal error indicates that the logic to parse a
8175 positional format argument ran into a problem that couldn't be
8176 otherwise reported. Please file a bug against Vim if you run
8177 into this, copying the exact format string and parameters that
8178 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008179
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008180 Return type: |String|
8181
Christ van Willegenea746f92023-10-05 20:48:36 +02008182
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008183prompt_getprompt({buf}) *prompt_getprompt()*
8184 Returns the effective prompt text for buffer {buf}. {buf} can
8185 be a buffer name or number. See |prompt-buffer|.
8186
8187 If the buffer doesn't exist or isn't a prompt buffer, an empty
8188 string is returned.
8189
8190 Can also be used as a |method|: >
8191 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008192<
8193 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008194
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008195 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008196
8197
8198prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8199 Set prompt callback for buffer {buf} to {expr}. When {expr}
8200 is an empty string the callback is removed. This has only
8201 effect if {buf} has 'buftype' set to "prompt".
8202
8203 The callback is invoked when pressing Enter. The current
8204 buffer will always be the prompt buffer. A new line for a
8205 prompt is added before invoking the callback, thus the prompt
8206 for which the callback was invoked will be in the last but one
8207 line.
8208 If the callback wants to add text to the buffer, it must
8209 insert it above the last line, since that is where the current
8210 prompt is. This can also be done asynchronously.
8211 The callback is invoked with one argument, which is the text
8212 that was entered at the prompt. This can be an empty string
8213 if the user only typed Enter.
8214 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008215 func s:TextEntered(text)
8216 if a:text == 'exit' || a:text == 'quit'
8217 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008218 " Reset 'modified' to allow the buffer to be closed.
8219 " We assume there is nothing useful to be saved.
8220 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008221 close
8222 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008223 " Do something useful with "a:text". In this example
8224 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008225 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008226 endif
8227 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008228 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008229
8230< Can also be used as a |method|: >
8231 GetBuffer()->prompt_setcallback(callback)
8232
8233< {only available when compiled with the |+channel| feature}
8234
8235prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8236 Set a callback for buffer {buf} to {expr}. When {expr} is an
8237 empty string the callback is removed. This has only effect if
8238 {buf} has 'buftype' set to "prompt".
8239
8240 This callback will be invoked when pressing CTRL-C in Insert
8241 mode. Without setting a callback Vim will exit Insert mode,
8242 as in any buffer.
8243
8244 Can also be used as a |method|: >
8245 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008246<
8247 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008248
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008249 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008250
8251prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8252 Set prompt for buffer {buf} to {text}. You most likely want
8253 {text} to end in a space.
8254 The result is only visible if {buf} has 'buftype' set to
8255 "prompt". Example: >
8256 call prompt_setprompt(bufnr(), 'command: ')
8257<
8258 Can also be used as a |method|: >
8259 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008260<
8261 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008262
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008263 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008264
8265prop_ functions are documented here: |text-prop-functions|
8266
8267pum_getpos() *pum_getpos()*
8268 If the popup menu (see |ins-completion-menu|) is not visible,
8269 returns an empty |Dictionary|, otherwise, returns a
8270 |Dictionary| with the following keys:
8271 height nr of items visible
8272 width screen cells
8273 row top screen row (0 first row)
8274 col leftmost screen column (0 first col)
8275 size total nr of items
8276 scrollbar |TRUE| if scrollbar is visible
8277
8278 The values are the same as in |v:event| during
8279 |CompleteChanged|.
8280
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008281 Return type: dict<any>
8282
8283
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008284pumvisible() *pumvisible()*
8285 Returns non-zero when the popup menu is visible, zero
8286 otherwise. See |ins-completion-menu|.
8287 This can be used to avoid some things that would remove the
8288 popup menu.
8289
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008290 Return type: |Number|
8291
8292
zeertzjq7c515282024-11-10 20:26:12 +01008293py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008294 Evaluate Python expression {expr} and return its result
8295 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008296 If a {locals} |Dictionary| is given, it defines set of local
8297 variables available in the expression. The keys are variable
8298 names and the values are the variable values. |Dictionary| and
8299 |List| values are referenced, and may be updated by the
8300 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008301 Numbers and strings are returned as they are (strings are
8302 copied though, Unicode strings are additionally converted to
8303 'encoding').
8304 Lists are represented as Vim |List| type.
8305 Dictionaries are represented as Vim |Dictionary| type with
8306 keys converted to strings.
8307 Note that in a `:def` function local variables are not visible
8308 to {expr}.
8309
8310 Can also be used as a |method|: >
8311 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008312 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008313<
8314 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008315
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008316 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008317
8318 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008319pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008320 Evaluate Python expression {expr} and return its result
8321 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008322 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008323 Numbers and strings are returned as they are (strings are
8324 copied though).
8325 Lists are represented as Vim |List| type.
8326 Dictionaries are represented as Vim |Dictionary| type,
8327 non-string keys result in error.
8328 Note that in a `:def` function local variables are not visible
8329 to {expr}.
8330
8331 Can also be used as a |method|: >
8332 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008333<
8334 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008335
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008336 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008337
zeertzjq7c515282024-11-10 20:26:12 +01008338pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008339 Evaluate Python expression {expr} and return its result
8340 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008341 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008342 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8343 See also: |pyeval()|, |py3eval()|
8344
8345 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008346 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008347<
8348 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008349
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008350 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008351 |+python3| feature}
8352
8353rand([{expr}]) *rand()* *random*
8354 Return a pseudo-random Number generated with an xoshiro128**
8355 algorithm using seed {expr}. The returned number is 32 bits,
8356 also on 64 bits systems, for consistency.
8357 {expr} can be initialized by |srand()| and will be updated by
8358 rand(). If {expr} is omitted, an internal seed value is used
8359 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008360 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008361
8362 Examples: >
8363 :echo rand()
8364 :let seed = srand()
8365 :echo rand(seed)
8366 :echo rand(seed) % 16 " random number 0 - 15
8367<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008368 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008369
8370 *E726* *E727*
8371range({expr} [, {max} [, {stride}]]) *range()*
8372 Returns a |List| with Numbers:
8373 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8374 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8375 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8376 {max}] (increasing {expr} with {stride} each time, not
8377 producing a value past {max}).
8378 When the maximum is one before the start the result is an
8379 empty list. When the maximum is more than one before the
8380 start this is an error.
8381 Examples: >
8382 range(4) " [0, 1, 2, 3]
8383 range(2, 4) " [2, 3, 4]
8384 range(2, 9, 3) " [2, 5, 8]
8385 range(2, -2, -1) " [2, 1, 0, -1, -2]
8386 range(0) " []
8387 range(2, 0) " error!
8388<
8389 Can also be used as a |method|: >
8390 GetExpr()->range()
8391<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008392 Return type: list<number>
8393
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008394
K.Takata11df3ae2022-10-19 14:02:40 +01008395readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008396 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008397 If {offset} is specified, read the file from the specified
8398 offset. If it is a negative value, it is used as an offset
8399 from the end of the file. E.g., to read the last 12 bytes: >
8400 readblob('file.bin', -12)
8401< If {size} is specified, only the specified size will be read.
8402 E.g. to read the first 100 bytes of a file: >
8403 readblob('file.bin', 0, 100)
8404< If {size} is -1 or omitted, the whole data starting from
8405 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008406 This can be also used to read the data from a character device
8407 on Unix when {size} is explicitly set. Only if the device
8408 supports seeking {offset} can be used. Otherwise it should be
8409 zero. E.g. to read 10 bytes from a serial console: >
8410 readblob('/dev/ttyS0', 0, 10)
8411< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008412 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008413 When the offset is beyond the end of the file the result is an
8414 empty blob.
8415 When trying to read more bytes than are available the result
8416 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008417 Also see |readfile()| and |writefile()|.
8418
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008419 Return type: |Blob|
8420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008421
8422readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8423 Return a list with file and directory names in {directory}.
8424 You can also use |glob()| if you don't need to do complicated
8425 things, such as limiting the number of matches.
8426 The list will be sorted (case sensitive), see the {dict}
8427 argument below for changing the sort order.
8428
8429 When {expr} is omitted all entries are included.
8430 When {expr} is given, it is evaluated to check what to do:
8431 If {expr} results in -1 then no further entries will
8432 be handled.
8433 If {expr} results in 0 then this entry will not be
8434 added to the list.
8435 If {expr} results in 1 then this entry will be added
8436 to the list.
8437 The entries "." and ".." are always excluded.
8438 Each time {expr} is evaluated |v:val| is set to the entry name.
8439 When {expr} is a function the name is passed as the argument.
8440 For example, to get a list of files ending in ".txt": >
8441 readdir(dirname, {n -> n =~ '.txt$'})
8442< To skip hidden and backup files: >
8443 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008444< *E857*
8445 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008446 values. Currently this is used to specify if and how sorting
8447 should be performed. The dict can have the following members:
8448
8449 sort How to sort the result returned from the system.
8450 Valid values are:
8451 "none" do not sort (fastest method)
8452 "case" sort case sensitive (byte value of
8453 each character, technically, using
8454 strcmp()) (default)
8455 "icase" sort case insensitive (technically
8456 using strcasecmp())
8457 "collate" sort using the collation order
8458 of the "POSIX" or "C" |locale|
8459 (technically using strcoll())
8460 Other values are silently ignored.
8461
8462 For example, to get a list of all files in the current
8463 directory without sorting the individual entries: >
8464 readdir('.', '1', #{sort: 'none'})
8465< If you want to get a directory tree: >
8466 function! s:tree(dir)
8467 return {a:dir : map(readdir(a:dir),
8468 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008469 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008470 endfunction
8471 echo s:tree(".")
8472<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008473 Returns an empty List on error.
8474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008475 Can also be used as a |method|: >
8476 GetDirName()->readdir()
8477<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008478 Return type: list<string> or list<any>
8479
8480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008481readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8482 Extended version of |readdir()|.
8483 Return a list of Dictionaries with file and directory
8484 information in {directory}.
8485 This is useful if you want to get the attributes of file and
8486 directory at the same time as getting a list of a directory.
8487 This is much faster than calling |readdir()| then calling
8488 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8489 each file and directory especially on MS-Windows.
8490 The list will by default be sorted by name (case sensitive),
8491 the sorting can be changed by using the optional {dict}
8492 argument, see |readdir()|.
8493
8494 The Dictionary for file and directory information has the
8495 following items:
8496 group Group name of the entry. (Only on Unix)
8497 name Name of the entry.
8498 perm Permissions of the entry. See |getfperm()|.
8499 size Size of the entry. See |getfsize()|.
8500 time Timestamp of the entry. See |getftime()|.
8501 type Type of the entry.
8502 On Unix, almost same as |getftype()| except:
8503 Symlink to a dir "linkd"
8504 Other symlink "link"
8505 On MS-Windows:
8506 Normal file "file"
8507 Directory "dir"
8508 Junction "junction"
8509 Symlink to a dir "linkd"
8510 Other symlink "link"
8511 Other reparse point "reparse"
8512 user User name of the entry's owner. (Only on Unix)
8513 On Unix, if the entry is a symlink, the Dictionary includes
8514 the information of the target (except the "type" item).
8515 On MS-Windows, it includes the information of the symlink
8516 itself because of performance reasons.
8517
8518 When {expr} is omitted all entries are included.
8519 When {expr} is given, it is evaluated to check what to do:
8520 If {expr} results in -1 then no further entries will
8521 be handled.
8522 If {expr} results in 0 then this entry will not be
8523 added to the list.
8524 If {expr} results in 1 then this entry will be added
8525 to the list.
8526 The entries "." and ".." are always excluded.
8527 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8528 of the entry.
8529 When {expr} is a function the entry is passed as the argument.
8530 For example, to get a list of files ending in ".txt": >
8531 readdirex(dirname, {e -> e.name =~ '.txt$'})
8532<
8533 For example, to get a list of all files in the current
8534 directory without sorting the individual entries: >
8535 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008536<
8537 Can also be used as a |method|: >
8538 GetDirName()->readdirex()
8539<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008540 Return type: list<dict<any>> or list<any>
8541
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008542
8543 *readfile()*
8544readfile({fname} [, {type} [, {max}]])
8545 Read file {fname} and return a |List|, each line of the file
8546 as an item. Lines are broken at NL characters. Macintosh
8547 files separated with CR will result in a single long line
8548 (unless a NL appears somewhere).
8549 All NUL characters are replaced with a NL character.
8550 When {type} contains "b" binary mode is used:
8551 - When the last line ends in a NL an extra empty list item is
8552 added.
8553 - No CR characters are removed.
8554 Otherwise:
8555 - CR characters that appear before a NL are removed.
8556 - Whether the last line ends in a NL or not does not matter.
8557 - When 'encoding' is Unicode any UTF-8 byte order mark is
8558 removed from the text.
8559 When {max} is given this specifies the maximum number of lines
8560 to be read. Useful if you only want to check the first ten
8561 lines of a file: >
8562 :for line in readfile(fname, '', 10)
8563 : if line =~ 'Date' | echo line | endif
8564 :endfor
8565< When {max} is negative -{max} lines from the end of the file
8566 are returned, or as many as there are.
8567 When {max} is zero the result is an empty list.
8568 Note that without {max} the whole file is read into memory.
8569 Also note that there is no recognition of encoding. Read a
8570 file into a buffer if you need to.
8571 Deprecated (use |readblob()| instead): When {type} contains
8572 "B" a |Blob| is returned with the binary data of the file
8573 unmodified.
8574 When the file can't be opened an error message is given and
8575 the result is an empty list.
8576 Also see |writefile()|.
8577
8578 Can also be used as a |method|: >
8579 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008580<
8581 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582
8583reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8584 {func} is called for every item in {object}, which can be a
8585 |String|, |List| or a |Blob|. {func} is called with two
8586 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008587 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008588
8589 {initial} is the initial result. When omitted, the first item
8590 in {object} is used and {func} is first called for the second
8591 item. If {initial} is not given and {object} is empty no
8592 result can be computed, an E998 error is given.
8593
8594 Examples: >
8595 echo reduce([1, 3, 5], { acc, val -> acc + val })
8596 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8597 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8598 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8599<
8600 Can also be used as a |method|: >
8601 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008602<
8603 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8604 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008605
8606
8607reg_executing() *reg_executing()*
8608 Returns the single letter name of the register being executed.
8609 Returns an empty string when no register is being executed.
8610 See |@|.
8611
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008612 Return type: |String|
8613
8614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008615reg_recording() *reg_recording()*
8616 Returns the single letter name of the register being recorded.
8617 Returns an empty string when not recording. See |q|.
8618
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008619 Return type: |String|
8620
8621
8622reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008623reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008624reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008625 Return an item that represents a time value. The item is a
8626 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008627 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008628 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008629 string or |reltimefloat()| to convert to a Float. For
8630 example, to see the time spent in function Work(): >
8631 var startTime = reltime()
8632 Work()
8633 echo startTime->reltime()->reltimestr()
8634<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008635 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008636 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008637 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008638 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008639 specified in the argument.
8640 With two arguments it returns the time passed between {start}
8641 and {end}.
8642
8643 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008644 reltime(). If there is an error an empty List is returned in
8645 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008646
8647 Can also be used as a |method|: >
8648 GetStart()->reltime()
8649<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008650 Return type: list<number>
8651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008652 {only available when compiled with the |+reltime| feature}
8653
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008655reltimefloat({time}) *reltimefloat()*
8656 Return a Float that represents the time value of {time}.
8657 Example: >
8658 let start = reltime()
8659 call MyFunction()
8660 let seconds = reltimefloat(reltime(start))
8661< See the note of reltimestr() about overhead.
8662 Also see |profiling|.
8663 If there is an error 0.0 is returned in legacy script, in Vim9
8664 script an error is given.
8665
8666 Can also be used as a |method|: >
8667 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008668<
8669 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008670
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008671 {only available when compiled with the |+reltime| feature}
8672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008673
8674reltimestr({time}) *reltimestr()*
8675 Return a String that represents the time value of {time}.
8676 This is the number of seconds, a dot and the number of
8677 microseconds. Example: >
8678 let start = reltime()
8679 call MyFunction()
8680 echo reltimestr(reltime(start))
8681< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008682 The accuracy depends on the system. Use reltimefloat() for the
8683 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008684 Leading spaces are used to make the string align nicely. You
8685 can use split() to remove it. >
8686 echo split(reltimestr(reltime(start)))[0]
8687< Also see |profiling|.
8688 If there is an error an empty string is returned in legacy
8689 script, in Vim9 script an error is given.
8690
8691 Can also be used as a |method|: >
8692 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008693<
8694 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008695
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008696 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008697
8698 *remote_expr()* *E449*
8699remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008700 Send the {string} to {server}. The {server} argument is a
8701 string, also see |{server}|.
8702
8703 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008704 after evaluation. The result must be a String or a |List|
8705 other types will be converted to String. A |List| is turned
8706 into a String by joining the items with a line break in
8707 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008709 If {idvar} is present and not empty, it is taken as the name
8710 of a variable and a {serverid} for later use with
8711 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008713 If {timeout} is given the read times out after this many
8714 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008716 See also |clientserver| |RemoteReply|.
8717 This function is not available in the |sandbox|.
8718 {only available when compiled with the |+clientserver| feature}
8719 Note: Any errors will cause a local error message to be issued
8720 and the result will be the empty string.
8721
8722 Variables will be evaluated in the global namespace,
8723 independent of a function currently being active. Except
8724 when in debug mode, then local function variables and
8725 arguments can be evaluated.
8726
8727 Examples: >
8728 :echo remote_expr("gvim", "2+2")
8729 :echo remote_expr("gvim1", "b:current_syntax")
8730<
8731 Can also be used as a |method|: >
8732 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008733<
8734 Return type: |String| or list<{type}>
8735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736
8737remote_foreground({server}) *remote_foreground()*
8738 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008739 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008740 This works like: >
8741 remote_expr({server}, "foreground()")
8742< Except that on Win32 systems the client does the work, to work
8743 around the problem that the OS doesn't always allow the server
8744 to bring itself to the foreground.
8745 Note: This does not restore the window if it was minimized,
8746 like foreground() does.
8747 This function is not available in the |sandbox|.
8748
8749 Can also be used as a |method|: >
8750 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008751<
8752 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008753
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008754 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008755 Win32 console version}
8756
8757
8758remote_peek({serverid} [, {retvar}]) *remote_peek()*
8759 Returns a positive number if there are available strings
8760 from {serverid}. Copies any reply string into the variable
8761 {retvar} if specified. {retvar} must be a string with the
8762 name of a variable.
8763 Returns zero if none are available.
8764 Returns -1 if something is wrong.
8765 See also |clientserver|.
8766 This function is not available in the |sandbox|.
8767 {only available when compiled with the |+clientserver| feature}
8768 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008769 :let repl = ""
8770 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008771
8772< Can also be used as a |method|: >
8773 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008774<
8775 Return type: |Number|
8776
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008777
8778remote_read({serverid}, [{timeout}]) *remote_read()*
8779 Return the oldest available reply from {serverid} and consume
8780 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008781 reply is available. Returns an empty string, if a reply is
8782 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008783 See also |clientserver|.
8784 This function is not available in the |sandbox|.
8785 {only available when compiled with the |+clientserver| feature}
8786 Example: >
8787 :echo remote_read(id)
8788
8789< Can also be used as a |method|: >
8790 ServerId()->remote_read()
8791<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008792 Return type: |String|
8793
8794
8795remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008796 Send the {string} to {server}. The {server} argument is a
8797 string, also see |{server}|.
8798
8799 The string is sent as input keys and the function returns
8800 immediately. At the Vim server the keys are not mapped
8801 |:map|.
8802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008803 If {idvar} is present, it is taken as the name of a variable
8804 and a {serverid} for later use with remote_read() is stored
8805 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008807 See also |clientserver| |RemoteReply|.
8808 This function is not available in the |sandbox|.
8809 {only available when compiled with the |+clientserver| feature}
8810
8811 Note: Any errors will be reported in the server and may mess
8812 up the display.
8813 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008814 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008815 \ remote_read(serverid)
8816
8817 :autocmd NONE RemoteReply *
8818 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008819 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008820 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8821<
8822 Can also be used as a |method|: >
8823 ServerName()->remote_send(keys)
8824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008825 Return type: |String|
8826
8827
8828remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008829 Become the server {name}. {name} must be a non-empty string.
8830 This fails if already running as a server, when |v:servername|
8831 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008832
8833 Can also be used as a |method|: >
8834 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008835<
8836 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008837
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008838 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008839
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008840
8841remove({list}, {idx}) *remove()*
8842remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008843 Without {end}: Remove the item at {idx} from |List| {list} and
8844 return the item.
8845 With {end}: Remove items from {idx} to {end} (inclusive) and
8846 return a |List| with these items. When {idx} points to the same
8847 item as {end} a list with one item is returned. When {end}
8848 points to an item before {idx} this is an error.
8849 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008850 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008851 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008852 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008853 :call remove(mylist, 0, 9)
8854<
8855 Use |delete()| to remove a file.
8856
8857 Can also be used as a |method|: >
8858 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008859<
8860 Return type: any, depending on {list}
8861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008862
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008863remove({blob}, {idx})
8864remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008865 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8866 return the byte.
8867 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8868 return a |Blob| with these bytes. When {idx} points to the same
8869 byte as {end} a |Blob| with one byte is returned. When {end}
8870 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008871 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008872 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008873 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008874 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008875<
8876 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008877
8878remove({dict}, {key})
8879 Remove the entry from {dict} with key {key} and return it.
8880 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008881 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008882< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008883 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008884
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008885 Return type: any, depending on {dict}
8886
8887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008888rename({from}, {to}) *rename()*
8889 Rename the file by the name {from} to the name {to}. This
8890 should also work to move files across file systems. The
8891 result is a Number, which is 0 if the file was renamed
8892 successfully, and non-zero when the renaming failed.
8893 NOTE: If {to} exists it is overwritten without warning.
8894 This function is not available in the |sandbox|.
8895
8896 Can also be used as a |method|: >
8897 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008898<
8899 Return type: |Number|
8900
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008901
8902repeat({expr}, {count}) *repeat()*
8903 Repeat {expr} {count} times and return the concatenated
8904 result. Example: >
8905 :let separator = repeat('-', 80)
8906< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008907 When {expr} is a |List| or a |Blob| the result is {expr}
8908 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008909 :let longlist = repeat(['a', 'b'], 3)
8910< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8911
8912 Can also be used as a |method|: >
8913 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008914<
8915 Return type: |String|, |Blob| or list<{type}> depending on
8916 {expr}
8917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008918
8919resolve({filename}) *resolve()* *E655*
8920 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8921 returns the path the shortcut points to in a simplified form.
8922 When {filename} is a symbolic link or junction point, return
8923 the full path to the target. If the target of junction is
8924 removed, return {filename}.
8925 On Unix, repeat resolving symbolic links in all path
8926 components of {filename} and return the simplified result.
8927 To cope with link cycles, resolving of symbolic links is
8928 stopped after 100 iterations.
8929 On other systems, return the simplified {filename}.
8930 The simplification step is done as by |simplify()|.
8931 resolve() keeps a leading path component specifying the
8932 current directory (provided the result is still a relative
8933 path name) and also keeps a trailing path separator.
8934
8935 Can also be used as a |method|: >
8936 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008937<
8938 Return type: |String|
8939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008940
8941reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008942 Reverse the order of items in {object}. {object} can be a
8943 |List|, a |Blob| or a |String|. For a List and a Blob the
8944 items are reversed in-place and {object} is returned.
8945 For a String a new String is returned.
8946 Returns zero if {object} is not a List, Blob or a String.
8947 If you want a List or Blob to remain unmodified make a copy
8948 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008949 :let revlist = reverse(copy(mylist))
8950< Can also be used as a |method|: >
8951 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008952<
8953 Return type: |String|, |Blob| or list<{type}> depending on
8954 {object}
8955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008956
8957round({expr}) *round()*
8958 Round off {expr} to the nearest integral value and return it
8959 as a |Float|. If {expr} lies halfway between two integral
8960 values, then use the larger one (away from zero).
8961 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008962 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008963 Examples: >
8964 echo round(0.456)
8965< 0.0 >
8966 echo round(4.5)
8967< 5.0 >
8968 echo round(-4.5)
8969< -5.0
8970
8971 Can also be used as a |method|: >
8972 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008973<
8974 Return type: |Float|
8975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008976
8977rubyeval({expr}) *rubyeval()*
8978 Evaluate Ruby expression {expr} and return its result
8979 converted to Vim data structures.
8980 Numbers, floats and strings are returned as they are (strings
8981 are copied though).
8982 Arrays are represented as Vim |List| type.
8983 Hashes are represented as Vim |Dictionary| type.
8984 Other objects are represented as strings resulted from their
8985 "Object#to_s" method.
8986 Note that in a `:def` function local variables are not visible
8987 to {expr}.
8988
8989 Can also be used as a |method|: >
8990 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008991<
8992 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008993
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008994 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008995
8996screenattr({row}, {col}) *screenattr()*
8997 Like |screenchar()|, but return the attribute. This is a rather
8998 arbitrary number that can only be used to compare to the
8999 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009000 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009001
9002 Can also be used as a |method|: >
9003 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009004<
9005 Return type: |Number|
9006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009007
9008screenchar({row}, {col}) *screenchar()*
9009 The result is a Number, which is the character at position
9010 [row, col] on the screen. This works for every possible
9011 screen position, also status lines, window separators and the
9012 command line. The top left position is row one, column one
9013 The character excludes composing characters. For double-byte
9014 encodings it may only be the first byte.
9015 This is mainly to be used for testing.
9016 Returns -1 when row or col is out of range.
9017
9018 Can also be used as a |method|: >
9019 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009020<
9021 Return type: |Number|
9022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009023
9024screenchars({row}, {col}) *screenchars()*
9025 The result is a |List| of Numbers. The first number is the same
9026 as what |screenchar()| returns. Further numbers are
9027 composing characters on top of the base character.
9028 This is mainly to be used for testing.
9029 Returns an empty List when row or col is out of range.
9030
9031 Can also be used as a |method|: >
9032 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009033<
9034 Return type: list<number> or list<any>
9035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009036
9037screencol() *screencol()*
9038 The result is a Number, which is the current screen column of
9039 the cursor. The leftmost column has number 1.
9040 This function is mainly used for testing.
9041
9042 Note: Always returns the current screen column, thus if used
9043 in a command (e.g. ":echo screencol()") it will return the
9044 column inside the command line, which is 1 when the command is
9045 executed. To get the cursor position in the file use one of
9046 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009047 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009048 nnoremap <silent> GG :echom screencol()<CR>
9049 nnoremap GG <Cmd>echom screencol()<CR>
9050<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009051 Return type: |Number|
9052
9053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009054screenpos({winid}, {lnum}, {col}) *screenpos()*
9055 The result is a Dict with the screen position of the text
9056 character in window {winid} at buffer line {lnum} and column
9057 {col}. {col} is a one-based byte index.
9058 The Dict has these members:
9059 row screen row
9060 col first screen column
9061 endcol last screen column
9062 curscol cursor screen column
9063 If the specified position is not visible, all values are zero.
9064 The "endcol" value differs from "col" when the character
9065 occupies more than one screen cell. E.g. for a Tab "col" can
9066 be 1 and "endcol" can be 8.
9067 The "curscol" value is where the cursor would be placed. For
9068 a Tab it would be the same as "endcol", while for a double
9069 width character it would be the same as "col".
9070 The |conceal| feature is ignored here, the column numbers are
9071 as if 'conceallevel' is zero. You can set the cursor to the
9072 right position and use |screencol()| to get the value with
9073 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009074 If the position is in a closed fold the screen position of the
9075 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009076 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009077
9078 Can also be used as a |method|: >
9079 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009080<
9081 Return type: dict<number> or dict<any>
9082
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009083
9084screenrow() *screenrow()*
9085 The result is a Number, which is the current screen row of the
9086 cursor. The top line has number one.
9087 This function is mainly used for testing.
9088 Alternatively you can use |winline()|.
9089
9090 Note: Same restrictions as with |screencol()|.
9091
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009092 Return type: |Number|
9093
9094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009095screenstring({row}, {col}) *screenstring()*
9096 The result is a String that contains the base character and
9097 any composing characters at position [row, col] on the screen.
9098 This is like |screenchars()| but returning a String with the
9099 characters.
9100 This is mainly to be used for testing.
9101 Returns an empty String when row or col is out of range.
9102
9103 Can also be used as a |method|: >
9104 GetRow()->screenstring(col)
9105<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009106 Return type: |String|
9107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009108 *search()*
9109search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9110 Search for regexp pattern {pattern}. The search starts at the
9111 cursor position (you can use |cursor()| to set it).
9112
9113 When a match has been found its line number is returned.
9114 If there is no match a 0 is returned and the cursor doesn't
9115 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009116 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009117
9118 {flags} is a String, which can contain these character flags:
9119 'b' search Backward instead of forward
9120 'c' accept a match at the Cursor position
9121 'e' move to the End of the match
9122 'n' do Not move the cursor
9123 'p' return number of matching sub-Pattern (see below)
9124 's' Set the ' mark at the previous location of the cursor
9125 'w' Wrap around the end of the file
9126 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009127 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009128 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9129
9130 If the 's' flag is supplied, the ' mark is set, only if the
9131 cursor is moved. The 's' flag cannot be combined with the 'n'
9132 flag.
9133
9134 'ignorecase', 'smartcase' and 'magic' are used.
9135
9136 When the 'z' flag is not given, forward searching always
9137 starts in column zero and then matches before the cursor are
9138 skipped. When the 'c' flag is present in 'cpo' the next
9139 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009140 search starts one column after the start of the match. This
9141 matters for overlapping matches. See |cpo-c|. You can also
9142 insert "\ze" to change where the match ends, see |/\ze|.
9143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009144 When searching backwards and the 'z' flag is given then the
9145 search starts in column zero, thus no match in the current
9146 line will be found (unless wrapping around the end of the
9147 file).
9148
9149 When the {stopline} argument is given then the search stops
9150 after searching this line. This is useful to restrict the
9151 search to a range of lines. Examples: >
9152 let match = search('(', 'b', line("w0"))
9153 let end = search('END', '', line("w$"))
9154< When {stopline} is used and it is not zero this also implies
9155 that the search does not wrap around the end of the file.
9156 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009157 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009158 When the {timeout} argument is given the search stops when
9159 more than this many milliseconds have passed. Thus when
9160 {timeout} is 500 the search stops after half a second.
9161 The value must not be negative. A zero value is like not
9162 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009163
9164 Note: the timeout is only considered when searching, not
9165 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009166 {only available when compiled with the |+reltime| feature}
9167
9168 If the {skip} expression is given it is evaluated with the
9169 cursor positioned on the start of a match. If it evaluates to
9170 non-zero this match is skipped. This can be used, for
9171 example, to skip a match in a comment or a string.
9172 {skip} can be a string, which is evaluated as an expression, a
9173 function reference or a lambda.
9174 When {skip} is omitted or empty, every match is accepted.
9175 When evaluating {skip} causes an error the search is aborted
9176 and -1 returned.
9177 *search()-sub-match*
9178 With the 'p' flag the returned value is one more than the
9179 first sub-match in \(\). One if none of them matched but the
9180 whole pattern did match.
9181 To get the column number too use |searchpos()|.
9182
9183 The cursor will be positioned at the match, unless the 'n'
9184 flag is used.
9185
9186 Example (goes over all files in the argument list): >
9187 :let n = 1
9188 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009189 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009190 : " start at the last char in the file and wrap for the
9191 : " first search to find match at start of file
9192 : normal G$
9193 : let flags = "w"
9194 : while search("foo", flags) > 0
9195 : s/foo/bar/g
9196 : let flags = "W"
9197 : endwhile
9198 : update " write the file if modified
9199 : let n = n + 1
9200 :endwhile
9201<
9202 Example for using some flags: >
9203 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9204< This will search for the keywords "if", "else", and "endif"
9205 under or after the cursor. Because of the 'p' flag, it
9206 returns 1, 2, or 3 depending on which keyword is found, or 0
9207 if the search fails. With the cursor on the first word of the
9208 line:
9209 if (foo == 0) | let foo = foo + 1 | endif ~
9210 the function returns 1. Without the 'c' flag, the function
9211 finds the "endif" and returns 3. The same thing happens
9212 without the 'e' flag if the cursor is on the "f" of "if".
9213 The 'n' flag tells the function not to move the cursor.
9214
9215 Can also be used as a |method|: >
9216 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009217<
9218 Return type: |Number|
9219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009220
9221searchcount([{options}]) *searchcount()*
9222 Get or update the last search count, like what is displayed
9223 without the "S" flag in 'shortmess'. This works even if
9224 'shortmess' does contain the "S" flag.
9225
9226 This returns a |Dictionary|. The dictionary is empty if the
9227 previous pattern was not set and "pattern" was not specified.
9228
9229 key type meaning ~
9230 current |Number| current position of match;
9231 0 if the cursor position is
9232 before the first match
9233 exact_match |Boolean| 1 if "current" is matched on
9234 "pos", otherwise 0
9235 total |Number| total count of matches found
9236 incomplete |Number| 0: search was fully completed
9237 1: recomputing was timed out
9238 2: max count exceeded
9239
9240 For {options} see further down.
9241
9242 To get the last search count when |n| or |N| was pressed, call
9243 this function with `recompute: 0` . This sometimes returns
9244 wrong information because |n| and |N|'s maximum count is 99.
9245 If it exceeded 99 the result must be max count + 1 (100). If
9246 you want to get correct information, specify `recompute: 1`: >
9247
9248 " result == maxcount + 1 (100) when many matches
9249 let result = searchcount(#{recompute: 0})
9250
9251 " Below returns correct result (recompute defaults
9252 " to 1)
9253 let result = searchcount()
9254<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009255 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009256 function! LastSearchCount() abort
9257 let result = searchcount(#{recompute: 0})
9258 if empty(result)
9259 return ''
9260 endif
9261 if result.incomplete ==# 1 " timed out
9262 return printf(' /%s [?/??]', @/)
9263 elseif result.incomplete ==# 2 " max count exceeded
9264 if result.total > result.maxcount &&
9265 \ result.current > result.maxcount
9266 return printf(' /%s [>%d/>%d]', @/,
9267 \ result.current, result.total)
9268 elseif result.total > result.maxcount
9269 return printf(' /%s [%d/>%d]', @/,
9270 \ result.current, result.total)
9271 endif
9272 endif
9273 return printf(' /%s [%d/%d]', @/,
9274 \ result.current, result.total)
9275 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009276 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009277
9278 " Or if you want to show the count only when
9279 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009280 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009281 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9282<
9283 You can also update the search count, which can be useful in a
9284 |CursorMoved| or |CursorMovedI| autocommand: >
9285
9286 autocmd CursorMoved,CursorMovedI *
9287 \ let s:searchcount_timer = timer_start(
9288 \ 200, function('s:update_searchcount'))
9289 function! s:update_searchcount(timer) abort
9290 if a:timer ==# s:searchcount_timer
9291 call searchcount(#{
9292 \ recompute: 1, maxcount: 0, timeout: 100})
9293 redrawstatus
9294 endif
9295 endfunction
9296<
9297 This can also be used to count matched texts with specified
9298 pattern in the current buffer using "pattern": >
9299
9300 " Count '\<foo\>' in this buffer
9301 " (Note that it also updates search count)
9302 let result = searchcount(#{pattern: '\<foo\>'})
9303
9304 " To restore old search count by old pattern,
9305 " search again
9306 call searchcount()
9307<
9308 {options} must be a |Dictionary|. It can contain:
9309 key type meaning ~
9310 recompute |Boolean| if |TRUE|, recompute the count
9311 like |n| or |N| was executed.
9312 otherwise returns the last
9313 computed result (when |n| or
9314 |N| was used when "S" is not
9315 in 'shortmess', or this
9316 function was called).
9317 (default: |TRUE|)
9318 pattern |String| recompute if this was given
9319 and different with |@/|.
9320 this works as same as the
9321 below command is executed
9322 before calling this function >
9323 let @/ = pattern
9324< (default: |@/|)
9325 timeout |Number| 0 or negative number is no
9326 timeout. timeout milliseconds
9327 for recomputing the result
9328 (default: 0)
9329 maxcount |Number| 0 or negative number is no
9330 limit. max count of matched
9331 text while recomputing the
9332 result. if search exceeded
9333 total count, "total" value
9334 becomes `maxcount + 1`
9335 (default: 99)
9336 pos |List| `[lnum, col, off]` value
9337 when recomputing the result.
9338 this changes "current" result
9339 value. see |cursor()|,
9340 |getpos()|
9341 (default: cursor's position)
9342
9343 Can also be used as a |method|: >
9344 GetSearchOpts()->searchcount()
9345<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009346 Return type: dict<number>
9347
9348
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009349searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9350 Search for the declaration of {name}.
9351
9352 With a non-zero {global} argument it works like |gD|, find
9353 first match in the file. Otherwise it works like |gd|, find
9354 first match in the function.
9355
9356 With a non-zero {thisblock} argument matches in a {} block
9357 that ends before the cursor position are ignored. Avoids
9358 finding variable declarations only valid in another scope.
9359
9360 Moves the cursor to the found match.
9361 Returns zero for success, non-zero for failure.
9362 Example: >
9363 if searchdecl('myvar') == 0
9364 echo getline('.')
9365 endif
9366<
9367 Can also be used as a |method|: >
9368 GetName()->searchdecl()
9369<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009370 Return type: |Number|
9371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009372 *searchpair()*
9373searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9374 [, {stopline} [, {timeout}]]]])
9375 Search for the match of a nested start-end pair. This can be
9376 used to find the "endif" that matches an "if", while other
9377 if/endif pairs in between are ignored.
9378 The search starts at the cursor. The default is to search
9379 forward, include 'b' in {flags} to search backward.
9380 If a match is found, the cursor is positioned at it and the
9381 line number is returned. If no match is found 0 or -1 is
9382 returned and the cursor doesn't move. No error message is
9383 given.
9384
9385 {start}, {middle} and {end} are patterns, see |pattern|. They
9386 must not contain \( \) pairs. Use of \%( \) is allowed. When
9387 {middle} is not empty, it is found when searching from either
9388 direction, but only when not in a nested start-end pair. A
9389 typical use is: >
9390 searchpair('\<if\>', '\<else\>', '\<endif\>')
9391< By leaving {middle} empty the "else" is skipped.
9392
9393 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9394 |search()|. Additionally:
9395 'r' Repeat until no more matches found; will find the
9396 outer pair. Implies the 'W' flag.
9397 'm' Return number of matches instead of line number with
9398 the match; will be > 1 when 'r' is used.
9399 Note: it's nearly always a good idea to use the 'W' flag, to
9400 avoid wrapping around the end of the file.
9401
9402 When a match for {start}, {middle} or {end} is found, the
9403 {skip} expression is evaluated with the cursor positioned on
9404 the start of the match. It should return non-zero if this
9405 match is to be skipped. E.g., because it is inside a comment
9406 or a string.
9407 When {skip} is omitted or empty, every match is accepted.
9408 When evaluating {skip} causes an error the search is aborted
9409 and -1 returned.
9410 {skip} can be a string, a lambda, a funcref or a partial.
9411 Anything else makes the function fail.
9412 In a `:def` function when the {skip} argument is a string
9413 constant it is compiled into instructions.
9414
9415 For {stopline} and {timeout} see |search()|.
9416
9417 The value of 'ignorecase' is used. 'magic' is ignored, the
9418 patterns are used like it's on.
9419
9420 The search starts exactly at the cursor. A match with
9421 {start}, {middle} or {end} at the next character, in the
9422 direction of searching, is the first one found. Example: >
9423 if 1
9424 if 2
9425 endif 2
9426 endif 1
9427< When starting at the "if 2", with the cursor on the "i", and
9428 searching forwards, the "endif 2" is found. When starting on
9429 the character just before the "if 2", the "endif 1" will be
9430 found. That's because the "if 2" will be found first, and
9431 then this is considered to be a nested if/endif from "if 2" to
9432 "endif 2".
9433 When searching backwards and {end} is more than one character,
9434 it may be useful to put "\zs" at the end of the pattern, so
9435 that when the cursor is inside a match with the end it finds
9436 the matching start.
9437
9438 Example, to find the "endif" command in a Vim script: >
9439
9440 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9441 \ 'getline(".") =~ "^\\s*\""')
9442
9443< The cursor must be at or after the "if" for which a match is
9444 to be found. Note that single-quote strings are used to avoid
9445 having to double the backslashes. The skip expression only
9446 catches comments at the start of a line, not after a command.
9447 Also, a word "en" or "if" halfway a line is considered a
9448 match.
9449 Another example, to search for the matching "{" of a "}": >
9450
9451 :echo searchpair('{', '', '}', 'bW')
9452
9453< This works when the cursor is at or before the "}" for which a
9454 match is to be found. To reject matches that syntax
9455 highlighting recognized as strings: >
9456
9457 :echo searchpair('{', '', '}', 'bW',
9458 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9459<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009460 Return type: |Number|
9461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009462 *searchpairpos()*
9463searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9464 [, {stopline} [, {timeout}]]]])
9465 Same as |searchpair()|, but returns a |List| with the line and
9466 column position of the match. The first element of the |List|
9467 is the line number and the second element is the byte index of
9468 the column position of the match. If no match is found,
9469 returns [0, 0]. >
9470
9471 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9472<
9473 See |match-parens| for a bigger and more useful example.
9474
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009475 Return type: list<number>
9476
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009477 *searchpos()*
9478searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9479 Same as |search()|, but returns a |List| with the line and
9480 column position of the match. The first element of the |List|
9481 is the line number and the second element is the byte index of
9482 the column position of the match. If no match is found,
9483 returns [0, 0].
9484 Example: >
9485 :let [lnum, col] = searchpos('mypattern', 'n')
9486
9487< When the 'p' flag is given then there is an extra item with
9488 the sub-pattern match number |search()-sub-match|. Example: >
9489 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9490< In this example "submatch" is 2 when a lowercase letter is
9491 found |/\l|, 3 when an uppercase letter is found |/\u|.
9492
9493 Can also be used as a |method|: >
9494 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009495<
9496 Return type: list<number>
9497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009498
9499server2client({clientid}, {string}) *server2client()*
9500 Send a reply string to {clientid}. The most recent {clientid}
9501 that sent a string can be retrieved with expand("<client>").
9502 {only available when compiled with the |+clientserver| feature}
9503 Returns zero for success, -1 for failure.
9504 Note:
9505 This id has to be stored before the next command can be
9506 received. I.e. before returning from the received command and
9507 before calling any commands that waits for input.
9508 See also |clientserver|.
9509 Example: >
9510 :echo server2client(expand("<client>"), "HELLO")
9511
9512< Can also be used as a |method|: >
9513 GetClientId()->server2client(string)
9514<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009515 Return type: |Number|
9516
9517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009518serverlist() *serverlist()*
9519 Return a list of available server names, one per line.
9520 When there are no servers or the information is not available
9521 an empty string is returned. See also |clientserver|.
9522 {only available when compiled with the |+clientserver| feature}
9523 Example: >
9524 :echo serverlist()
9525<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009526 Return type: |String|
9527
9528
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009529setbufline({buf}, {lnum}, {text}) *setbufline()*
9530 Set line {lnum} to {text} in buffer {buf}. This works like
9531 |setline()| for the specified buffer.
9532
9533 This function works only for loaded buffers. First call
9534 |bufload()| if needed.
9535
9536 To insert lines use |appendbufline()|.
9537 Any text properties in {lnum} are cleared.
9538
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009539 {text} can be a string to set one line, or a List of strings
9540 to set multiple lines. If the List extends below the last
9541 line then those lines are added. If the List is empty then
9542 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009543
9544 For the use of {buf}, see |bufname()| above.
9545
9546 {lnum} is used like with |setline()|.
9547 Use "$" to refer to the last line in buffer {buf}.
9548 When {lnum} is just below the last line the {text} will be
9549 added below the last line.
9550
9551 When {buf} is not a valid buffer, the buffer is not loaded or
9552 {lnum} is not valid then 1 is returned. In |Vim9| script an
9553 error is given.
9554 On success 0 is returned.
9555
9556 Can also be used as a |method|, the base is passed as the
9557 third argument: >
9558 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009559<
9560 Return type: |Number|
9561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009562
9563setbufvar({buf}, {varname}, {val}) *setbufvar()*
9564 Set option or local variable {varname} in buffer {buf} to
9565 {val}.
9566 This also works for a global or local window option, but it
9567 doesn't work for a global or local window variable.
9568 For a local window option the global value is unchanged.
9569 For the use of {buf}, see |bufname()| above.
9570 The {varname} argument is a string.
9571 Note that the variable name without "b:" must be used.
9572 Examples: >
9573 :call setbufvar(1, "&mod", 1)
9574 :call setbufvar("todo", "myvar", "foobar")
9575< This function is not available in the |sandbox|.
9576
9577 Can also be used as a |method|, the base is passed as the
9578 third argument: >
9579 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009580<
9581 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009582
9583
9584setcellwidths({list}) *setcellwidths()*
9585 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009586 tells Vim how wide characters are when displayed in the
9587 terminal, counted in screen cells. The values override
9588 'ambiwidth'. Example: >
9589 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009590 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009591 \ [0x2194, 0x2199, 2],
9592 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009593
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009594< The {list} argument is a List of Lists with each three
9595 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9596 {low} and {high} can be the same, in which case this refers to
9597 one character. Otherwise it is the range of characters from
9598 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009599 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009600
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009601 {width} must be either 1 or 2, indicating the character width
9602 in screen cells. *E1112*
9603 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009604 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009606 If the new value causes 'fillchars' or 'listchars' to become
9607 invalid it is rejected and an error is given.
9608
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009609 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009610 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009612< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009613 the effect for known emoji characters. Move the cursor
9614 through the text to check if the cell widths of your terminal
9615 match with what Vim knows about each emoji. If it doesn't
9616 look right you need to adjust the {list} argument.
9617
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009618 Return type: |Number|
9619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009620
9621setcharpos({expr}, {list}) *setcharpos()*
9622 Same as |setpos()| but uses the specified column number as the
9623 character index instead of the byte index in the line.
9624
9625 Example:
9626 With the text "여보세요" in line 8: >
9627 call setcharpos('.', [0, 8, 4, 0])
9628< positions the cursor on the fourth character '요'. >
9629 call setpos('.', [0, 8, 4, 0])
9630< positions the cursor on the second character '보'.
9631
9632 Can also be used as a |method|: >
9633 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009634<
9635 Return type: |Number|
9636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009637
9638setcharsearch({dict}) *setcharsearch()*
9639 Set the current character search information to {dict},
9640 which contains one or more of the following entries:
9641
9642 char character which will be used for a subsequent
9643 |,| or |;| command; an empty string clears the
9644 character search
9645 forward direction of character search; 1 for forward,
9646 0 for backward
9647 until type of character search; 1 for a |t| or |T|
9648 character search, 0 for an |f| or |F|
9649 character search
9650
9651 This can be useful to save/restore a user's character search
9652 from a script: >
9653 :let prevsearch = getcharsearch()
9654 :" Perform a command which clobbers user's search
9655 :call setcharsearch(prevsearch)
9656< Also see |getcharsearch()|.
9657
9658 Can also be used as a |method|: >
9659 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009660<
9661 Return type: dict<any>
9662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009663
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009664setcmdline({str} [, {pos}]) *setcmdline()*
9665 Set the command line to {str} and set the cursor position to
9666 {pos}.
9667 If {pos} is omitted, the cursor is positioned after the text.
9668 Returns 0 when successful, 1 when not editing the command
9669 line.
9670
9671 Can also be used as a |method|: >
9672 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009673<
9674 Return type: |Number|
9675
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009677setcmdpos({pos}) *setcmdpos()*
9678 Set the cursor position in the command line to byte position
9679 {pos}. The first position is 1.
9680 Use |getcmdpos()| to obtain the current position.
9681 Only works while editing the command line, thus you must use
9682 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9683 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9684 set after the command line is set to the expression. For
9685 |c_CTRL-R_=| it is set after evaluating the expression but
9686 before inserting the resulting text.
9687 When the number is too big the cursor is put at the end of the
9688 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009689 Returns 0 when successful, 1 when not editing the command
9690 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009691
9692 Can also be used as a |method|: >
9693 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009694<
9695 Return type: |Number|
9696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009697
9698setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9699setcursorcharpos({list})
9700 Same as |cursor()| but uses the specified column number as the
9701 character index instead of the byte index in the line.
9702
9703 Example:
9704 With the text "여보세요" in line 4: >
9705 call setcursorcharpos(4, 3)
9706< positions the cursor on the third character '세'. >
9707 call cursor(4, 3)
9708< positions the cursor on the first character '여'.
9709
9710 Can also be used as a |method|: >
9711 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009712<
9713 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009714
9715
9716setenv({name}, {val}) *setenv()*
9717 Set environment variable {name} to {val}. Example: >
9718 call setenv('HOME', '/home/myhome')
9719
9720< When {val} is |v:null| the environment variable is deleted.
9721 See also |expr-env|.
9722
9723 Can also be used as a |method|, the base is passed as the
9724 second argument: >
9725 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009726<
9727 Return type: |Number|
9728
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009729
9730setfperm({fname}, {mode}) *setfperm()* *chmod*
9731 Set the file permissions for {fname} to {mode}.
9732 {mode} must be a string with 9 characters. It is of the form
9733 "rwxrwxrwx", where each group of "rwx" flags represent, in
9734 turn, the permissions of the owner of the file, the group the
9735 file belongs to, and other users. A '-' character means the
9736 permission is off, any other character means on. Multi-byte
9737 characters are not supported.
9738
9739 For example "rw-r-----" means read-write for the user,
9740 readable by the group, not accessible by others. "xx-x-----"
9741 would do the same thing.
9742
9743 Returns non-zero for success, zero for failure.
9744
9745 Can also be used as a |method|: >
9746 GetFilename()->setfperm(mode)
9747<
9748 To read permissions see |getfperm()|.
9749
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009750 Return type: |Number|
9751
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009752
9753setline({lnum}, {text}) *setline()*
9754 Set line {lnum} of the current buffer to {text}. To insert
9755 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009756 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009757 Any text properties in {lnum} are cleared. See
9758 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009759
9760 {lnum} is used like with |getline()|.
9761 When {lnum} is just below the last line the {text} will be
9762 added below the last line.
9763 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009764 converted to a String. When {text} is an empty List then
9765 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009766
9767 If this succeeds, FALSE is returned. If this fails (most likely
9768 because {lnum} is invalid) TRUE is returned.
9769 In |Vim9| script an error is given if {lnum} is invalid.
9770
9771 Example: >
9772 :call setline(5, strftime("%c"))
9773
9774< When {text} is a |List| then line {lnum} and following lines
9775 will be set to the items in the list. Example: >
9776 :call setline(5, ['aaa', 'bbb', 'ccc'])
9777< This is equivalent to: >
9778 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9779 : call setline(n, l)
9780 :endfor
9781
9782< Note: The '[ and '] marks are not set.
9783
9784 Can also be used as a |method|, the base is passed as the
9785 second argument: >
9786 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009787<
9788 Return type: |Number|
9789
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009790
9791setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9792 Create or replace or add to the location list for window {nr}.
9793 {nr} can be the window number or the |window-ID|.
9794 When {nr} is zero the current window is used.
9795
9796 For a location list window, the displayed location list is
9797 modified. For an invalid window number {nr}, -1 is returned.
9798 Otherwise, same as |setqflist()|.
9799 Also see |location-list|.
9800
9801 For {action} see |setqflist-action|.
9802
9803 If the optional {what} dictionary argument is supplied, then
9804 only the items listed in {what} are set. Refer to |setqflist()|
9805 for the list of supported keys in {what}.
9806
9807 Can also be used as a |method|, the base is passed as the
9808 second argument: >
9809 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009810<
9811 Return type: |Number|
9812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009813
9814setmatches({list} [, {win}]) *setmatches()*
9815 Restores a list of matches saved by |getmatches()| for the
9816 current window. Returns 0 if successful, otherwise -1. All
9817 current matches are cleared before the list is restored. See
9818 example for |getmatches()|.
9819 If {win} is specified, use the window with this number or
9820 window ID instead of the current window.
9821
9822 Can also be used as a |method|: >
9823 GetMatches()->setmatches()
9824<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009825 Return type: |Number|
9826
9827
9828setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009829 Set the position for String {expr}. Possible values:
9830 . the cursor
9831 'x mark x
9832
9833 {list} must be a |List| with four or five numbers:
9834 [bufnum, lnum, col, off]
9835 [bufnum, lnum, col, off, curswant]
9836
9837 "bufnum" is the buffer number. Zero can be used for the
9838 current buffer. When setting an uppercase mark "bufnum" is
9839 used for the mark position. For other marks it specifies the
9840 buffer to set the mark in. You can use the |bufnr()| function
9841 to turn a file name into a buffer number.
9842 For setting the cursor and the ' mark "bufnum" is ignored,
9843 since these are associated with a window, not a buffer.
9844 Does not change the jumplist.
9845
9846 "lnum" and "col" are the position in the buffer. The first
9847 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9848 smaller than 1 then 1 is used. To use the character count
9849 instead of the byte count, use |setcharpos()|.
9850
9851 The "off" number is only used when 'virtualedit' is set. Then
9852 it is the offset in screen columns from the start of the
9853 character. E.g., a position within a <Tab> or after the last
9854 character.
9855
9856 The "curswant" number is only used when setting the cursor
9857 position. It sets the preferred column for when moving the
9858 cursor vertically. When the "curswant" number is missing the
9859 preferred column is not set. When it is present and setting a
9860 mark position it is not used.
9861
9862 Note that for '< and '> changing the line number may result in
9863 the marks to be effectively be swapped, so that '< is always
9864 before '>.
9865
9866 Returns 0 when the position could be set, -1 otherwise.
9867 An error message is given if {expr} is invalid.
9868
9869 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9870
9871 This does not restore the preferred column for moving
9872 vertically; if you set the cursor position with this, |j| and
9873 |k| motions will jump to previous columns! Use |cursor()| to
9874 also set the preferred column. Also see the "curswant" key in
9875 |winrestview()|.
9876
9877 Can also be used as a |method|: >
9878 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009879<
9880 Return type: |Number|
9881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009882
9883setqflist({list} [, {action} [, {what}]]) *setqflist()*
9884 Create or replace or add to the quickfix list.
9885
9886 If the optional {what} dictionary argument is supplied, then
9887 only the items listed in {what} are set. The first {list}
9888 argument is ignored. See below for the supported items in
9889 {what}.
9890 *setqflist-what*
9891 When {what} is not present, the items in {list} are used. Each
9892 item must be a dictionary. Non-dictionary items in {list} are
9893 ignored. Each dictionary item can contain the following
9894 entries:
9895
9896 bufnr buffer number; must be the number of a valid
9897 buffer
9898 filename name of a file; only used when "bufnr" is not
9899 present or it is invalid.
9900 module name of a module; if given it will be used in
9901 quickfix error window instead of the filename.
9902 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009903 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009904 pattern search pattern used to locate the error
9905 col column number
9906 vcol when non-zero: "col" is visual column
9907 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009908 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009909 nr error number
9910 text description of the error
9911 type single-character error type, 'E', 'W', etc.
9912 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009913 user_data custom data associated with the item, can be
9914 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009915
9916 The "col", "vcol", "nr", "type" and "text" entries are
9917 optional. Either "lnum" or "pattern" entry can be used to
9918 locate a matching error line.
9919 If the "filename" and "bufnr" entries are not present or
9920 neither the "lnum" or "pattern" entries are present, then the
9921 item will not be handled as an error line.
9922 If both "pattern" and "lnum" are present then "pattern" will
9923 be used.
9924 If the "valid" entry is not supplied, then the valid flag is
9925 set when "bufnr" is a valid buffer or "filename" exists.
9926 If you supply an empty {list}, the quickfix list will be
9927 cleared.
9928 Note that the list is not exactly the same as what
9929 |getqflist()| returns.
9930
9931 {action} values: *setqflist-action* *E927*
9932 'a' The items from {list} are added to the existing
9933 quickfix list. If there is no existing list, then a
9934 new list is created.
9935
9936 'r' The items from the current quickfix list are replaced
9937 with the items from {list}. This can also be used to
9938 clear the list: >
9939 :call setqflist([], 'r')
9940<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009941 'u' Like 'r', but tries to preserve the current selection
9942 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009943 'f' All the quickfix lists in the quickfix stack are
9944 freed.
9945
9946 If {action} is not present or is set to ' ', then a new list
9947 is created. The new quickfix list is added after the current
9948 quickfix list in the stack and all the following lists are
9949 freed. To add a new quickfix list at the end of the stack,
9950 set "nr" in {what} to "$".
9951
9952 The following items can be specified in dictionary {what}:
9953 context quickfix list context. See |quickfix-context|
9954 efm errorformat to use when parsing text from
9955 "lines". If this is not present, then the
9956 'errorformat' option value is used.
9957 See |quickfix-parse|
9958 id quickfix list identifier |quickfix-ID|
9959 idx index of the current entry in the quickfix
9960 list specified by 'id' or 'nr'. If set to '$',
9961 then the last entry in the list is set as the
9962 current entry. See |quickfix-index|
9963 items list of quickfix entries. Same as the {list}
9964 argument.
9965 lines use 'errorformat' to parse a list of lines and
9966 add the resulting entries to the quickfix list
9967 {nr} or {id}. Only a |List| value is supported.
9968 See |quickfix-parse|
9969 nr list number in the quickfix stack; zero
9970 means the current quickfix list and "$" means
9971 the last quickfix list.
9972 quickfixtextfunc
9973 function to get the text to display in the
9974 quickfix window. The value can be the name of
9975 a function or a funcref or a lambda. Refer to
9976 |quickfix-window-function| for an explanation
9977 of how to write the function and an example.
9978 title quickfix list title text. See |quickfix-title|
9979 Unsupported keys in {what} are ignored.
9980 If the "nr" item is not present, then the current quickfix list
9981 is modified. When creating a new quickfix list, "nr" can be
9982 set to a value one greater than the quickfix stack size.
9983 When modifying a quickfix list, to guarantee that the correct
9984 list is modified, "id" should be used instead of "nr" to
9985 specify the list.
9986
9987 Examples (See also |setqflist-examples|): >
9988 :call setqflist([], 'r', {'title': 'My search'})
9989 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9990 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9991<
9992 Returns zero for success, -1 for failure.
9993
9994 This function can be used to create a quickfix list
9995 independent of the 'errorformat' setting. Use a command like
9996 `:cc 1` to jump to the first position.
9997
9998 Can also be used as a |method|, the base is passed as the
9999 second argument: >
10000 GetErrorlist()->setqflist()
10001<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010002 Return type: |Number|
10003
10004
10005setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010006 Set the register {regname} to {value}.
10007 If {regname} is "" or "@", the unnamed register '"' is used.
10008 The {regname} argument is a string. In |Vim9-script|
10009 {regname} must be one character.
10010
10011 {value} may be any value returned by |getreg()| or
10012 |getreginfo()|, including a |List| or |Dict|.
10013 If {options} contains "a" or {regname} is upper case,
10014 then the value is appended.
10015
10016 {options} can also contain a register type specification:
10017 "c" or "v" |characterwise| mode
10018 "l" or "V" |linewise| mode
10019 "b" or "<CTRL-V>" |blockwise-visual| mode
10020 If a number immediately follows "b" or "<CTRL-V>" then this is
10021 used as the width of the selection - if it is not specified
10022 then the width of the block is set to the number of characters
10023 in the longest line (counting a <Tab> as 1 character).
10024
10025 If {options} contains no register settings, then the default
10026 is to use character mode unless {value} ends in a <NL> for
10027 string {value} and linewise mode for list {value}. Blockwise
10028 mode is never selected automatically.
10029 Returns zero for success, non-zero for failure.
10030
10031 *E883*
10032 Note: you may not use |List| containing more than one item to
10033 set search and expression registers. Lists containing no
10034 items act like empty strings.
10035
10036 Examples: >
10037 :call setreg(v:register, @*)
10038 :call setreg('*', @%, 'ac')
10039 :call setreg('a', "1\n2\n3", 'b5')
10040 :call setreg('"', { 'points_to': 'a'})
10041
10042< This example shows using the functions to save and restore a
10043 register: >
10044 :let var_a = getreginfo()
10045 :call setreg('a', var_a)
10046< or: >
10047 :let var_a = getreg('a', 1, 1)
10048 :let var_amode = getregtype('a')
10049 ....
10050 :call setreg('a', var_a, var_amode)
10051< Note: you may not reliably restore register value
10052 without using the third argument to |getreg()| as without it
10053 newlines are represented as newlines AND Nul bytes are
10054 represented as newlines as well, see |NL-used-for-Nul|.
10055
10056 You can also change the type of a register by appending
10057 nothing: >
10058 :call setreg('a', '', 'al')
10059
10060< Can also be used as a |method|, the base is passed as the
10061 second argument: >
10062 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010063<
10064 Return type: |Number|
10065
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010066
10067settabvar({tabnr}, {varname}, {val}) *settabvar()*
10068 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10069 |t:var|
10070 The {varname} argument is a string.
10071 Note that autocommands are blocked, side effects may not be
10072 triggered, e.g. when setting 'filetype'.
10073 Note that the variable name without "t:" must be used.
10074 Tabs are numbered starting with one.
10075 This function is not available in the |sandbox|.
10076
10077 Can also be used as a |method|, the base is passed as the
10078 third argument: >
10079 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010080<
10081 Return type: |Number|
10082
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010083
10084settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10085 Set option or local variable {varname} in window {winnr} to
10086 {val}.
10087 Tabs are numbered starting with one. For the current tabpage
10088 use |setwinvar()|.
10089 {winnr} can be the window number or the |window-ID|.
10090 When {winnr} is zero the current window is used.
10091 Note that autocommands are blocked, side effects may not be
10092 triggered, e.g. when setting 'filetype' or 'syntax'.
10093 This also works for a global or local buffer option, but it
10094 doesn't work for a global or local buffer variable.
10095 For a local buffer option the global value is unchanged.
10096 Note that the variable name without "w:" must be used.
10097 Examples: >
10098 :call settabwinvar(1, 1, "&list", 0)
10099 :call settabwinvar(3, 2, "myvar", "foobar")
10100< This function is not available in the |sandbox|.
10101
10102 Can also be used as a |method|, the base is passed as the
10103 fourth argument: >
10104 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010105<
10106 Return type: |Number|
10107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010108
10109settagstack({nr}, {dict} [, {action}]) *settagstack()*
10110 Modify the tag stack of the window {nr} using {dict}.
10111 {nr} can be the window number or the |window-ID|.
10112
10113 For a list of supported items in {dict}, refer to
10114 |gettagstack()|. "curidx" takes effect before changing the tag
10115 stack.
10116 *E962*
10117 How the tag stack is modified depends on the {action}
10118 argument:
10119 - If {action} is not present or is set to 'r', then the tag
10120 stack is replaced.
10121 - If {action} is set to 'a', then new entries from {dict} are
10122 pushed (added) onto the tag stack.
10123 - If {action} is set to 't', then all the entries from the
10124 current entry in the tag stack or "curidx" in {dict} are
10125 removed and then new entries are pushed to the stack.
10126
10127 The current index is set to one after the length of the tag
10128 stack after the modification.
10129
10130 Returns zero for success, -1 for failure.
10131
10132 Examples (for more examples see |tagstack-examples|):
10133 Empty the tag stack of window 3: >
10134 call settagstack(3, {'items' : []})
10135
10136< Save and restore the tag stack: >
10137 let stack = gettagstack(1003)
10138 " do something else
10139 call settagstack(1003, stack)
10140 unlet stack
10141<
10142 Can also be used as a |method|, the base is passed as the
10143 second argument: >
10144 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010145<
10146 Return type: |Number|
10147
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010148
10149setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10150 Like |settabwinvar()| for the current tab page.
10151 Examples: >
10152 :call setwinvar(1, "&list", 0)
10153 :call setwinvar(2, "myvar", "foobar")
10154
10155< Can also be used as a |method|, the base is passed as the
10156 third argument: >
10157 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010158<
10159 Return type: |Number|
10160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010161
10162sha256({string}) *sha256()*
10163 Returns a String with 64 hex characters, which is the SHA256
10164 checksum of {string}.
10165
10166 Can also be used as a |method|: >
10167 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010168<
10169 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010170
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010171 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010172
10173shellescape({string} [, {special}]) *shellescape()*
10174 Escape {string} for use as a shell command argument.
10175 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010176 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010177 in single quotes and will double up all internal single
10178 quotes.
10179 On MS-Windows, when 'shellslash' is not set, it will enclose
10180 {string} in double quotes and double all double quotes within
10181 {string}.
10182 Otherwise it will enclose {string} in single quotes and
10183 replace all "'" with "'\''".
10184
Enno5faeb602024-05-15 21:54:19 +020010185 The {special} argument adds additional escaping of keywords
10186 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010187 number or a non-empty String (|non-zero-arg|), then special
10188 items such as "!", "%", "#" and "<cword>" (as listed in
10189 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010190 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010191
10192 The "!" character will be escaped (again with a |non-zero-arg|
10193 {special}) when 'shell' contains "csh" in the tail. That is
10194 because for csh and tcsh "!" is used for history replacement
10195 even when inside single quotes.
10196
10197 With a |non-zero-arg| {special} the <NL> character is also
10198 escaped. When 'shell' containing "csh" in the tail it's
10199 escaped a second time.
10200
10201 The "\" character will be escaped when 'shell' contains "fish"
10202 in the tail. That is because for fish "\" is used as an escape
10203 character inside single quotes.
10204
10205 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010206 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010207< This results in a directory listing for the file under the
10208 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010209 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010210< See also |::S|.
10211
10212 Can also be used as a |method|: >
10213 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010214<
10215 Return type: |String|
10216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010217
10218shiftwidth([{col}]) *shiftwidth()*
10219 Returns the effective value of 'shiftwidth'. This is the
10220 'shiftwidth' value unless it is zero, in which case it is the
10221 'tabstop' value. This function was introduced with patch
10222 7.3.694 in 2012, everybody should have it by now (however it
10223 did not allow for the optional {col} argument until 8.1.542).
10224
10225 When there is one argument {col} this is used as column number
10226 for which to return the 'shiftwidth' value. This matters for the
10227 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10228 no {col} argument is given, column 1 will be assumed.
10229
10230 Can also be used as a |method|: >
10231 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010232<
10233 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010234
10235sign_ functions are documented here: |sign-functions-details|
10236
10237
10238simplify({filename}) *simplify()*
10239 Simplify the file name as much as possible without changing
10240 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10241 Unix) are not resolved. If the first path component in
10242 {filename} designates the current directory, this will be
10243 valid for the result as well. A trailing path separator is
10244 not removed either. On Unix "//path" is unchanged, but
10245 "///path" is simplified to "/path" (this follows the Posix
10246 standard).
10247 Example: >
10248 simplify("./dir/.././/file/") == "./file/"
10249< Note: The combination "dir/.." is only removed if "dir" is
10250 a searchable directory or does not exist. On Unix, it is also
10251 removed when "dir" is a symbolic link within the same
10252 directory. In order to resolve all the involved symbolic
10253 links before simplifying the path name, use |resolve()|.
10254
10255 Can also be used as a |method|: >
10256 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010257<
10258 Return type: |String|
10259
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010260
10261sin({expr}) *sin()*
10262 Return the sine of {expr}, measured in radians, as a |Float|.
10263 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010264 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010265 Examples: >
10266 :echo sin(100)
10267< -0.506366 >
10268 :echo sin(-4.01)
10269< 0.763301
10270
10271 Can also be used as a |method|: >
10272 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010273<
10274 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010275
10276
10277sinh({expr}) *sinh()*
10278 Return the hyperbolic sine of {expr} as a |Float| in the range
10279 [-inf, inf].
10280 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010281 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010282 Examples: >
10283 :echo sinh(0.5)
10284< 0.521095 >
10285 :echo sinh(-0.9)
10286< -1.026517
10287
10288 Can also be used as a |method|: >
10289 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010290<
10291 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010292
10293
10294slice({expr}, {start} [, {end}]) *slice()*
10295 Similar to using a |slice| "expr[start : end]", but "end" is
10296 used exclusive. And for a string the indexes are used as
10297 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010298 |vim9script|. Also, composing characters are treated as a
10299 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010300 When {end} is omitted the slice continues to the last item.
10301 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010302 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010303
10304 Can also be used as a |method|: >
10305 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010306<
10307 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010308
10309
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010310sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010311 Sort the items in {list} in-place. Returns {list}.
10312
10313 If you want a list to remain unmodified make a copy first: >
10314 :let sortedlist = sort(copy(mylist))
10315
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010316< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010317 string representation of each item to sort on. Numbers sort
10318 after Strings, |Lists| after Numbers. For sorting text in the
10319 current buffer use |:sort|.
10320
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010321 When {how} is given and it is 'i' then case is ignored.
10322 In legacy script, for backwards compatibility, the value one
10323 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010324
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010325 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010326 locale is used for ordering. Implementation details: strcoll()
10327 is used to compare strings. See |:language| check or set the
10328 collation locale. |v:collate| can also be used to check the
10329 current locale. Sorting using the locale typically ignores
10330 case. Example: >
10331 " ö is sorted similarly to o with English locale.
10332 :language collate en_US.UTF8
10333 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10334< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10335>
10336 " ö is sorted after z with Swedish locale.
10337 :language collate sv_SE.UTF8
10338 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10339< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10340 This does not work properly on Mac.
10341
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010342 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010343 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010344 strtod() function to parse numbers. Strings, Lists, Dicts and
10345 Funcrefs will be considered as being 0). Note that this won't
10346 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010347
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010348 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010349 sorted numerical. This is like 'n' but a string containing
10350 digits will be used as the number they represent.
10351
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010352 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010353 sorted numerical. All values must be a Number or a Float.
10354
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010355 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010356 is called to compare items. The function is invoked with two
10357 items as argument and must return zero if they are equal, 1 or
10358 bigger if the first one sorts after the second one, -1 or
10359 smaller if the first one sorts before the second one.
10360
10361 {dict} is for functions with the "dict" attribute. It will be
10362 used to set the local variable "self". |Dictionary-function|
10363
10364 The sort is stable, items which compare equal (as number or as
10365 string) will keep their relative position. E.g., when sorting
10366 on numbers, text strings will sort next to each other, in the
10367 same order as they were originally.
10368
10369 Can also be used as a |method|: >
10370 mylist->sort()
10371
10372< Also see |uniq()|.
10373
10374 Example: >
10375 func MyCompare(i1, i2)
10376 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10377 endfunc
10378 eval mylist->sort("MyCompare")
10379< A shorter compare version for this specific simple case, which
10380 ignores overflow: >
10381 func MyCompare(i1, i2)
10382 return a:i1 - a:i2
10383 endfunc
10384< For a simple expression you can use a lambda: >
10385 eval mylist->sort({i1, i2 -> i1 - i2})
10386<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010387 Return type: list<{type}>
10388
10389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010390sound_clear() *sound_clear()*
10391 Stop playing all sounds.
10392
10393 On some Linux systems you may need the libcanberra-pulse
10394 package, otherwise sound may not stop.
10395
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010396 Return type: |Number|
10397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398 {only available when compiled with the |+sound| feature}
10399
10400 *sound_playevent()*
10401sound_playevent({name} [, {callback}])
10402 Play a sound identified by {name}. Which event names are
10403 supported depends on the system. Often the XDG sound names
10404 are used. On Ubuntu they may be found in
10405 /usr/share/sounds/freedesktop/stereo. Example: >
10406 call sound_playevent('bell')
10407< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10408 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10409 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010410 On macOS, {name} refers to files located in
10411 /System/Library/Sounds (e.g. "Tink"). It will also work for
10412 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010413
10414 When {callback} is specified it is invoked when the sound is
10415 finished. The first argument is the sound ID, the second
10416 argument is the status:
10417 0 sound was played to the end
10418 1 sound was interrupted
10419 2 error occurred after sound started
10420 Example: >
10421 func Callback(id, status)
10422 echomsg "sound " .. a:id .. " finished with " .. a:status
10423 endfunc
10424 call sound_playevent('bell', 'Callback')
10425
10426< MS-Windows: {callback} doesn't work for this function.
10427
10428 Returns the sound ID, which can be passed to `sound_stop()`.
10429 Returns zero if the sound could not be played.
10430
10431 Can also be used as a |method|: >
10432 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010433<
10434 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010435
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010436 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010437
10438 *sound_playfile()*
10439sound_playfile({path} [, {callback}])
10440 Like `sound_playevent()` but play sound file {path}. {path}
10441 must be a full path. On Ubuntu you may find files to play
10442 with this command: >
10443 :!find /usr/share/sounds -type f | grep -v index.theme
10444
10445< Can also be used as a |method|: >
10446 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010447<
10448 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010449
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010450 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010451
10452
10453sound_stop({id}) *sound_stop()*
10454 Stop playing sound {id}. {id} must be previously returned by
10455 `sound_playevent()` or `sound_playfile()`.
10456
10457 On some Linux systems you may need the libcanberra-pulse
10458 package, otherwise sound may not stop.
10459
10460 On MS-Windows, this does not work for event sound started by
10461 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10462
10463 Can also be used as a |method|: >
10464 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010465<
10466 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010467
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010468 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010469
10470 *soundfold()*
10471soundfold({word})
10472 Return the sound-folded equivalent of {word}. Uses the first
10473 language in 'spelllang' for the current window that supports
10474 soundfolding. 'spell' must be set. When no sound folding is
10475 possible the {word} is returned unmodified.
10476 This can be used for making spelling suggestions. Note that
10477 the method can be quite slow.
10478
10479 Can also be used as a |method|: >
10480 GetWord()->soundfold()
10481<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010482 Return type: |String|
10483
10484
10485spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010486 Without argument: The result is the badly spelled word under
10487 or after the cursor. The cursor is moved to the start of the
10488 bad word. When no bad word is found in the cursor line the
10489 result is an empty string and the cursor doesn't move.
10490
10491 With argument: The result is the first word in {sentence} that
10492 is badly spelled. If there are no spelling mistakes the
10493 result is an empty string.
10494
10495 The return value is a list with two items:
10496 - The badly spelled word or an empty string.
10497 - The type of the spelling error:
10498 "bad" spelling mistake
10499 "rare" rare word
10500 "local" word only valid in another region
10501 "caps" word should start with Capital
10502 Example: >
10503 echo spellbadword("the quik brown fox")
10504< ['quik', 'bad'] ~
10505
10506 The spelling information for the current window and the value
10507 of 'spelllang' are used.
10508
10509 Can also be used as a |method|: >
10510 GetText()->spellbadword()
10511<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010512 Return type: list<string>
10513
10514
10515spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010516 Return a |List| with spelling suggestions to replace {word}.
10517 When {max} is given up to this number of suggestions are
10518 returned. Otherwise up to 25 suggestions are returned.
10519
10520 When the {capital} argument is given and it's non-zero only
10521 suggestions with a leading capital will be given. Use this
10522 after a match with 'spellcapcheck'.
10523
10524 {word} can be a badly spelled word followed by other text.
10525 This allows for joining two words that were split. The
10526 suggestions also include the following text, thus you can
10527 replace a line.
10528
10529 {word} may also be a good word. Similar words will then be
10530 returned. {word} itself is not included in the suggestions,
10531 although it may appear capitalized.
10532
10533 The spelling information for the current window is used. The
10534 values of 'spelllang' and 'spellsuggest' are used.
10535
10536 Can also be used as a |method|: >
10537 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010538<
10539 Return type: list<string> or list<any>
10540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010541
10542split({string} [, {pattern} [, {keepempty}]]) *split()*
10543 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010544 empty each white space separated sequence of characters
10545 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010546 Otherwise the string is split where {pattern} matches,
10547 removing the matched characters. 'ignorecase' is not used
10548 here, add \c to ignore case. |/\c|
10549 When the first or last item is empty it is omitted, unless the
10550 {keepempty} argument is given and it's non-zero.
10551 Other empty items are kept when {pattern} matches at least one
10552 character or when {keepempty} is non-zero.
10553 Example: >
10554 :let words = split(getline('.'), '\W\+')
10555< To split a string in individual characters: >
10556 :for c in split(mystring, '\zs')
10557< If you want to keep the separator you can also use '\zs' at
10558 the end of the pattern: >
10559 :echo split('abc:def:ghi', ':\zs')
10560< ['abc:', 'def:', 'ghi'] ~
10561 Splitting a table where the first element can be empty: >
10562 :let items = split(line, ':', 1)
10563< The opposite function is |join()|.
10564
10565 Can also be used as a |method|: >
10566 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010567<
10568 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010569
10570sqrt({expr}) *sqrt()*
10571 Return the non-negative square root of Float {expr} as a
10572 |Float|.
10573 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010574 is negative the result is NaN (Not a Number). Returns 0.0 if
10575 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010576 Examples: >
10577 :echo sqrt(100)
10578< 10.0 >
10579 :echo sqrt(-4.01)
10580< nan
10581 "nan" may be different, it depends on system libraries.
10582
10583 Can also be used as a |method|: >
10584 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010585<
10586 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010587
10588
10589srand([{expr}]) *srand()*
10590 Initialize seed used by |rand()|:
10591 - If {expr} is not given, seed values are initialized by
10592 reading from /dev/urandom, if possible, or using time(NULL)
10593 a.k.a. epoch time otherwise; this only has second accuracy.
10594 - If {expr} is given it must be a Number. It is used to
10595 initialize the seed values. This is useful for testing or
10596 when a predictable sequence is intended.
10597
10598 Examples: >
10599 :let seed = srand()
10600 :let seed = srand(userinput)
10601 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010602<
10603 Return type: list<number>
10604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010605
10606state([{what}]) *state()*
10607 Return a string which contains characters indicating the
10608 current state. Mostly useful in callbacks that want to do
10609 work that may not always be safe. Roughly this works like:
10610 - callback uses state() to check if work is safe to do.
10611 Yes: then do it right away.
10612 No: add to work queue and add a |SafeState| and/or
10613 |SafeStateAgain| autocommand (|SafeState| triggers at
10614 toplevel, |SafeStateAgain| triggers after handling
10615 messages and callbacks).
10616 - When SafeState or SafeStateAgain is triggered and executes
10617 your autocommand, check with `state()` if the work can be
10618 done now, and if yes remove it from the queue and execute.
10619 Remove the autocommand if the queue is now empty.
10620 Also see |mode()|.
10621
10622 When {what} is given only characters in this string will be
10623 added. E.g, this checks if the screen has scrolled: >
10624 if state('s') == ''
10625 " screen has not scrolled
10626<
10627 These characters indicate the state, generally indicating that
10628 something is busy:
10629 m halfway a mapping, :normal command, feedkeys() or
10630 stuffed command
10631 o operator pending, e.g. after |d|
10632 a Insert mode autocomplete active
10633 x executing an autocommand
10634 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10635 ch_readraw() when reading json
10636 S not triggering SafeState or SafeStateAgain, e.g. after
10637 |f| or a count
10638 c callback invoked, including timer (repeats for
10639 recursiveness up to "ccc")
10640 s screen has scrolled for messages
10641
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010642 Return type: |String|
10643
10644
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010645str2blob({list} [, {options}]) *str2blob()*
10646 Return a Blob by converting the characters in the List of
10647 strings in {list} into bytes.
10648
10649 A <NL> byte is added to the blob after each list item. A
10650 newline character in the string is translated into a <NUL>
10651 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010652
10653 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010654 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010655
10656 The argument {options} is a |Dict| and supports the following
10657 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010658 encoding Convert the characters using this encoding
10659 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010660 The value is a |String|. See |encoding-names|
10661 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010662
10663 An error is given and an empty blob is returned if the
10664 character encoding fails.
10665
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010666 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010667
10668 See also |blob2str()|
10669
10670 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010671 str2blob(["ab"]) returns 0z6162
10672 str2blob(["«»"]) returns 0zC2ABC2BB
10673 str2blob(["a\nb"]) returns 0z610062
10674 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010675 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010676 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010677<
10678 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010679 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010680<
10681 Return type: |Blob|
10682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010683str2float({string} [, {quoted}]) *str2float()*
10684 Convert String {string} to a Float. This mostly works the
10685 same as when using a floating point number in an expression,
10686 see |floating-point-format|. But it's a bit more permissive.
10687 E.g., "1e40" is accepted, while in an expression you need to
10688 write "1.0e40". The hexadecimal form "0x123" is also
10689 accepted, but not others, like binary or octal.
10690 When {quoted} is present and non-zero then embedded single
10691 quotes before the dot are ignored, thus "1'000.0" is a
10692 thousand.
10693 Text after the number is silently ignored.
10694 The decimal point is always '.', no matter what the locale is
10695 set to. A comma ends the number: "12,345.67" is converted to
10696 12.0. You can strip out thousands separators with
10697 |substitute()|: >
10698 let f = str2float(substitute(text, ',', '', 'g'))
10699<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010700 Returns 0.0 if the conversion fails.
10701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010702 Can also be used as a |method|: >
10703 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010704<
10705 Return type: |Float|
10706
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010707
10708str2list({string} [, {utf8}]) *str2list()*
10709 Return a list containing the number values which represent
10710 each character in String {string}. Examples: >
10711 str2list(" ") returns [32]
10712 str2list("ABC") returns [65, 66, 67]
10713< |list2str()| does the opposite.
10714
10715 When {utf8} is omitted or zero, the current 'encoding' is used.
10716 When {utf8} is TRUE, always treat the String as UTF-8
10717 characters. With UTF-8 composing characters are handled
10718 properly: >
10719 str2list("á") returns [97, 769]
10720
10721< Can also be used as a |method|: >
10722 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010723<
10724 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010725
10726
10727str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10728 Convert string {string} to a number.
10729 {base} is the conversion base, it can be 2, 8, 10 or 16.
10730 When {quoted} is present and non-zero then embedded single
10731 quotes are ignored, thus "1'000'000" is a million.
10732
10733 When {base} is omitted base 10 is used. This also means that
10734 a leading zero doesn't cause octal conversion to be used, as
10735 with the default String to Number conversion. Example: >
10736 let nr = str2nr('0123')
10737<
10738 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10739 different base the result will be zero. Similarly, when
10740 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10741 {base} is 2 a leading "0b" or "0B" is ignored.
10742 Text after the number is silently ignored.
10743
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010744 Returns 0 if {string} is empty or on error.
10745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010746 Can also be used as a |method|: >
10747 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010748<
10749 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010750
10751
10752strcharlen({string}) *strcharlen()*
10753 The result is a Number, which is the number of characters
10754 in String {string}. Composing characters are ignored.
10755 |strchars()| can count the number of characters, counting
10756 composing characters separately.
10757
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010758 Returns 0 if {string} is empty or on error.
10759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010760 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10761
10762 Can also be used as a |method|: >
10763 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010764<
10765 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010766
10767
10768strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10769 Like |strpart()| but using character index and length instead
10770 of byte index and length.
10771 When {skipcc} is omitted or zero, composing characters are
10772 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010773 When {skipcc} set to 1, composing characters are treated as a
10774 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010775 When a character index is used where a character does not
10776 exist it is omitted and counted as one character. For
10777 example: >
10778 strcharpart('abc', -1, 2)
10779< results in 'a'.
10780
Bram Moolenaard592deb2022-06-17 15:42:40 +010010781 Returns an empty string on error.
10782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010783 Can also be used as a |method|: >
10784 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010785<
10786 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010787
10788
10789strchars({string} [, {skipcc}]) *strchars()*
10790 The result is a Number, which is the number of characters
10791 in String {string}.
10792 When {skipcc} is omitted or zero, composing characters are
10793 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010794 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010795 |strcharlen()| always does this.
10796
Bram Moolenaard592deb2022-06-17 15:42:40 +010010797 Returns zero on error.
10798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010799 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10800
10801 {skipcc} is only available after 7.4.755. For backward
10802 compatibility, you can define a wrapper function: >
10803 if has("patch-7.4.755")
10804 function s:strchars(str, skipcc)
10805 return strchars(a:str, a:skipcc)
10806 endfunction
10807 else
10808 function s:strchars(str, skipcc)
10809 if a:skipcc
10810 return strlen(substitute(a:str, ".", "x", "g"))
10811 else
10812 return strchars(a:str)
10813 endif
10814 endfunction
10815 endif
10816<
10817 Can also be used as a |method|: >
10818 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010819<
10820 Return type: |Number|
10821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010822
10823strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10824 The result is a Number, which is the number of display cells
10825 String {string} occupies on the screen when it starts at {col}
10826 (first column is zero). When {col} is omitted zero is used.
10827 Otherwise it is the screen column where to start. This
10828 matters for Tab characters.
10829 The option settings of the current window are used. This
10830 matters for anything that's displayed differently, such as
10831 'tabstop' and 'display'.
10832 When {string} contains characters with East Asian Width Class
10833 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010834 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010835 Also see |strlen()|, |strwidth()| and |strchars()|.
10836
10837 Can also be used as a |method|: >
10838 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010839<
10840 Return type: |Number|
10841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010842
10843strftime({format} [, {time}]) *strftime()*
10844 The result is a String, which is a formatted date and time, as
10845 specified by the {format} string. The given {time} is used,
10846 or the current time if no time is given. The accepted
10847 {format} depends on your system, thus this is not portable!
10848 See the manual page of the C function strftime() for the
10849 format. The maximum length of the result is 80 characters.
10850 See also |localtime()|, |getftime()| and |strptime()|.
10851 The language can be changed with the |:language| command.
10852 Examples: >
10853 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10854 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10855 :echo strftime("%y%m%d %T") 970427 11:53:55
10856 :echo strftime("%H:%M") 11:55
10857 :echo strftime("%c", getftime("file.c"))
10858 Show mod time of file.c.
10859< Not available on all systems. To check use: >
10860 :if exists("*strftime")
10861
10862< Can also be used as a |method|: >
10863 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010864<
10865 Return type: |String|
10866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010867
10868strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010869 Get a Number corresponding to the character at {index} in
10870 {str}. This uses a zero-based character index, not a byte
10871 index. Composing characters are considered separate
10872 characters here. Use |nr2char()| to convert the Number to a
10873 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010874 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010875 Also see |strcharpart()| and |strchars()|.
10876
10877 Can also be used as a |method|: >
10878 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010879<
10880 Return type: |Number|
10881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010882
10883stridx({haystack}, {needle} [, {start}]) *stridx()*
10884 The result is a Number, which gives the byte index in
10885 {haystack} of the first occurrence of the String {needle}.
10886 If {start} is specified, the search starts at index {start}.
10887 This can be used to find a second match: >
10888 :let colon1 = stridx(line, ":")
10889 :let colon2 = stridx(line, ":", colon1 + 1)
10890< The search is done case-sensitive.
10891 For pattern searches use |match()|.
10892 -1 is returned if the {needle} does not occur in {haystack}.
10893 See also |strridx()|.
10894 Examples: >
10895 :echo stridx("An Example", "Example") 3
10896 :echo stridx("Starting point", "Start") 0
10897 :echo stridx("Starting point", "start") -1
10898< *strstr()* *strchr()*
10899 stridx() works similar to the C function strstr(). When used
10900 with a single character it works similar to strchr().
10901
10902 Can also be used as a |method|: >
10903 GetHaystack()->stridx(needle)
10904<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010905 Return type: |Number|
10906
10907
10908string({expr}) *string()*
10909 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010910 Float, String, Blob or a composition of them, then the result
10911 can be parsed back with |eval()|.
10912 {expr} type result ~
10913 String 'string' (single quotes are doubled)
10914 Number 123
10915 Float 123.123456 or 1.123456e8
10916 Funcref function('name')
10917 Blob 0z00112233.44556677.8899
10918 List [item, item]
10919 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010920 Class class SomeName
10921 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010922 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010923 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010924
10925 When a |List| or |Dictionary| has a recursive reference it is
10926 replaced by "[...]" or "{...}". Using eval() on the result
10927 will then fail.
10928
mityu7f0bba22024-03-29 10:14:41 +010010929 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010930 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010931 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010933 Can also be used as a |method|: >
10934 mylist->string()
10935
10936< Also see |strtrans()|.
10937
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010938 Return type: |String|
10939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010940
10941strlen({string}) *strlen()*
10942 The result is a Number, which is the length of the String
10943 {string} in bytes.
10944 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010945 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010946 If you want to count the number of multibyte characters use
10947 |strchars()|.
10948 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10949
10950 Can also be used as a |method|: >
10951 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010952<
10953 Return type: |Number|
10954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010955
10956strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10957 The result is a String, which is part of {src}, starting from
10958 byte {start}, with the byte length {len}.
10959 When {chars} is present and TRUE then {len} is the number of
10960 characters positions (composing characters are not counted
10961 separately, thus "1" means one base character and any
10962 following composing characters).
10963 To count {start} as characters instead of bytes use
10964 |strcharpart()|.
10965
10966 When bytes are selected which do not exist, this doesn't
10967 result in an error, the bytes are simply omitted.
10968 If {len} is missing, the copy continues from {start} till the
10969 end of the {src}. >
10970 strpart("abcdefg", 3, 2) == "de"
10971 strpart("abcdefg", -2, 4) == "ab"
10972 strpart("abcdefg", 5, 4) == "fg"
10973 strpart("abcdefg", 3) == "defg"
10974
10975< Note: To get the first character, {start} must be 0. For
10976 example, to get the character under the cursor: >
10977 strpart(getline("."), col(".") - 1, 1, v:true)
10978<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010979 Returns an empty string on error.
10980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010981 Can also be used as a |method|: >
10982 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010983<
10984 Return type: |String|
10985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010986
10987strptime({format}, {timestring}) *strptime()*
10988 The result is a Number, which is a unix timestamp representing
10989 the date and time in {timestring}, which is expected to match
10990 the format specified in {format}.
10991
10992 The accepted {format} depends on your system, thus this is not
10993 portable! See the manual page of the C function strptime()
10994 for the format. Especially avoid "%c". The value of $TZ also
10995 matters.
10996
10997 If the {timestring} cannot be parsed with {format} zero is
10998 returned. If you do not know the format of {timestring} you
10999 can try different {format} values until you get a non-zero
11000 result.
11001
11002 See also |strftime()|.
11003 Examples: >
11004 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11005< 862156163 >
11006 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11007< Sun Apr 27 11:53:55 1997 >
11008 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11009< Sun Apr 27 12:53:55 1997
11010
11011 Can also be used as a |method|: >
11012 GetFormat()->strptime(timestring)
11013<
11014 Not available on all systems. To check use: >
11015 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011016<
11017 Return type: |Number|
11018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011019
11020strridx({haystack}, {needle} [, {start}]) *strridx()*
11021 The result is a Number, which gives the byte index in
11022 {haystack} of the last occurrence of the String {needle}.
11023 When {start} is specified, matches beyond this index are
11024 ignored. This can be used to find a match before a previous
11025 match: >
11026 :let lastcomma = strridx(line, ",")
11027 :let comma2 = strridx(line, ",", lastcomma - 1)
11028< The search is done case-sensitive.
11029 For pattern searches use |match()|.
11030 -1 is returned if the {needle} does not occur in {haystack}.
11031 If the {needle} is empty the length of {haystack} is returned.
11032 See also |stridx()|. Examples: >
11033 :echo strridx("an angry armadillo", "an") 3
11034< *strrchr()*
11035 When used with a single character it works similar to the C
11036 function strrchr().
11037
11038 Can also be used as a |method|: >
11039 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011040<
11041 Return type: |Number|
11042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011043
11044strtrans({string}) *strtrans()*
11045 The result is a String, which is {string} with all unprintable
11046 characters translated into printable characters |'isprint'|.
11047 Like they are shown in a window. Example: >
11048 echo strtrans(@a)
11049< This displays a newline in register a as "^@" instead of
11050 starting a new line.
11051
Bram Moolenaard592deb2022-06-17 15:42:40 +010011052 Returns an empty string on error.
11053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011054 Can also be used as a |method|: >
11055 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011056<
11057 Return type: |String|
11058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011059
Christian Brabandt67672ef2023-04-24 21:09:54 +010011060strutf16len({string} [, {countcc}]) *strutf16len()*
11061 The result is a Number, which is the number of UTF-16 code
11062 units in String {string} (after converting it to UTF-16).
11063
11064 When {countcc} is TRUE, composing characters are counted
11065 separately.
11066 When {countcc} is omitted or FALSE, composing characters are
11067 ignored.
11068
11069 Returns zero on error.
11070
11071 Also see |strlen()| and |strcharlen()|.
11072 Examples: >
11073 echo strutf16len('a') returns 1
11074 echo strutf16len('©') returns 1
11075 echo strutf16len('😊') returns 2
11076 echo strutf16len('ą́') returns 1
11077 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011078<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011079 Can also be used as a |method|: >
11080 GetText()->strutf16len()
11081<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011082 Return type: |Number|
11083
11084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011085strwidth({string}) *strwidth()*
11086 The result is a Number, which is the number of display cells
11087 String {string} occupies. A Tab character is counted as one
11088 cell, alternatively use |strdisplaywidth()|.
11089 When {string} contains characters with East Asian Width Class
11090 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011091 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011092 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11093
11094 Can also be used as a |method|: >
11095 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011096<
11097 Return type: |Number|
11098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011099
11100submatch({nr} [, {list}]) *submatch()* *E935*
11101 Only for an expression in a |:substitute| command or
11102 substitute() function.
11103 Returns the {nr}'th submatch of the matched text. When {nr}
11104 is 0 the whole matched text is returned.
11105 Note that a NL in the string can stand for a line break of a
11106 multi-line match or a NUL character in the text.
11107 Also see |sub-replace-expression|.
11108
11109 If {list} is present and non-zero then submatch() returns
11110 a list of strings, similar to |getline()| with two arguments.
11111 NL characters in the text represent NUL characters in the
11112 text.
11113 Only returns more than one item for |:substitute|, inside
11114 |substitute()| this list will always contain one or zero
11115 items, since there are no real line breaks.
11116
11117 When substitute() is used recursively only the submatches in
11118 the current (deepest) call can be obtained.
11119
Bram Moolenaard592deb2022-06-17 15:42:40 +010011120 Returns an empty string or list on error.
11121
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011122 Examples: >
11123 :s/\d\+/\=submatch(0) + 1/
11124 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11125< This finds the first number in the line and adds one to it.
11126 A line break is included as a newline character.
11127
11128 Can also be used as a |method|: >
11129 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011130<
11131 Return type: |String| or list<string> depending on {list}
11132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011133
11134substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11135 The result is a String, which is a copy of {string}, in which
11136 the first match of {pat} is replaced with {sub}.
11137 When {flags} is "g", all matches of {pat} in {string} are
11138 replaced. Otherwise {flags} should be "".
11139
11140 This works like the ":substitute" command (without any flags).
11141 But the matching with {pat} is always done like the 'magic'
11142 option is set and 'cpoptions' is empty (to make scripts
11143 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11144 if you want to ignore or match case and ignore 'ignorecase'.
11145 'smartcase' is not used. See |string-match| for how {pat} is
11146 used.
11147
11148 A "~" in {sub} is not replaced with the previous {sub}.
11149 Note that some codes in {sub} have a special meaning
11150 |sub-replace-special|. For example, to replace something with
11151 "\n" (two characters), use "\\\\n" or '\\n'.
11152
11153 When {pat} does not match in {string}, {string} is returned
11154 unmodified.
11155
11156 Example: >
11157 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11158< This removes the last component of the 'path' option. >
11159 :echo substitute("testing", ".*", "\\U\\0", "")
11160< results in "TESTING".
11161
11162 When {sub} starts with "\=", the remainder is interpreted as
11163 an expression. See |sub-replace-expression|. Example: >
11164 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011165 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011166
11167< When {sub} is a Funcref that function is called, with one
11168 optional argument. Example: >
11169 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11170< The optional argument is a list which contains the whole
11171 matched string and up to nine submatches, like what
11172 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011173 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011174
Bram Moolenaard592deb2022-06-17 15:42:40 +010011175< Returns an empty string on error.
11176
11177 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011178 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011179<
11180 Return type: |String|
11181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011182
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011183swapfilelist() *swapfilelist()*
11184 Returns a list of swap file names, like what "vim -r" shows.
11185 See the |-r| command argument. The 'directory' option is used
11186 for the directories to inspect. If you only want to get a
11187 list of swap files in the current directory then temporarily
11188 set 'directory' to a dot: >
11189 let save_dir = &directory
11190 let &directory = '.'
11191 let swapfiles = swapfilelist()
11192 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011193<
11194 Return type: list<string>
11195
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011197swapinfo({fname}) *swapinfo()*
11198 The result is a dictionary, which holds information about the
11199 swapfile {fname}. The available fields are:
11200 version Vim version
11201 user user name
11202 host host name
11203 fname original file name
11204 pid PID of the Vim process that created the swap
11205 file
11206 mtime last modification time in seconds
11207 inode Optional: INODE number of the file
11208 dirty 1 if file was modified, 0 if not
11209 Note that "user" and "host" are truncated to at most 39 bytes.
11210 In case of failure an "error" item is added with the reason:
11211 Cannot open file: file not found or in accessible
11212 Cannot read file: cannot read first block
11213 Not a swap file: does not contain correct block ID
11214 Magic number mismatch: Info in first block is invalid
11215
11216 Can also be used as a |method|: >
11217 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011218<
11219 Return type: dict<any> or dict<string>
11220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011221
11222swapname({buf}) *swapname()*
11223 The result is the swap file path of the buffer {expr}.
11224 For the use of {buf}, see |bufname()| above.
11225 If buffer {buf} is the current buffer, the result is equal to
11226 |:swapname| (unless there is no swap file).
11227 If buffer {buf} has no swap file, returns an empty string.
11228
11229 Can also be used as a |method|: >
11230 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011231<
11232 Return type: |String|
11233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011234
11235synID({lnum}, {col}, {trans}) *synID()*
11236 The result is a Number, which is the syntax ID at the position
11237 {lnum} and {col} in the current window.
11238 The syntax ID can be used with |synIDattr()| and
11239 |synIDtrans()| to obtain syntax information about text.
11240
11241 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11242 line. 'synmaxcol' applies, in a longer line zero is returned.
11243 Note that when the position is after the last character,
11244 that's where the cursor can be in Insert mode, synID() returns
11245 zero. {lnum} is used like with |getline()|.
11246
11247 When {trans} is |TRUE|, transparent items are reduced to the
11248 item that they reveal. This is useful when wanting to know
11249 the effective color. When {trans} is |FALSE|, the transparent
11250 item is returned. This is useful when wanting to know which
11251 syntax item is effective (e.g. inside parens).
11252 Warning: This function can be very slow. Best speed is
11253 obtained by going through the file in forward direction.
11254
Bram Moolenaard592deb2022-06-17 15:42:40 +010011255 Returns zero on error.
11256
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011257 Example (echoes the name of the syntax item under the cursor): >
11258 :echo synIDattr(synID(line("."), col("."), 1), "name")
11259<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011260 Return type: |Number|
11261
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011262
11263synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11264 The result is a String, which is the {what} attribute of
11265 syntax ID {synID}. This can be used to obtain information
11266 about a syntax item.
11267 {mode} can be "gui", "cterm" or "term", to get the attributes
11268 for that mode. When {mode} is omitted, or an invalid value is
11269 used, the attributes for the currently active highlighting are
11270 used (GUI, cterm or term).
11271 Use synIDtrans() to follow linked highlight groups.
11272 {what} result
11273 "name" the name of the syntax item
11274 "fg" foreground color (GUI: color name used to set
11275 the color, cterm: color number as a string,
11276 term: empty string)
11277 "bg" background color (as with "fg")
11278 "font" font name (only available in the GUI)
11279 |highlight-font|
11280 "sp" special color for the GUI (as with "fg")
11281 |highlight-guisp|
11282 "ul" underline color for cterm: number as a string
11283 "fg#" like "fg", but for the GUI and the GUI is
11284 running the name in "#RRGGBB" form
11285 "bg#" like "fg#" for "bg"
11286 "sp#" like "fg#" for "sp"
11287 "bold" "1" if bold
11288 "italic" "1" if italic
11289 "reverse" "1" if reverse
11290 "inverse" "1" if inverse (= reverse)
11291 "standout" "1" if standout
11292 "underline" "1" if underlined
11293 "undercurl" "1" if undercurled
11294 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011295 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011296
Bram Moolenaard592deb2022-06-17 15:42:40 +010011297 Returns an empty string on error.
11298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011299 Example (echoes the color of the syntax item under the
11300 cursor): >
11301 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11302<
11303 Can also be used as a |method|: >
11304 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011305<
11306 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011307
11308
11309synIDtrans({synID}) *synIDtrans()*
11310 The result is a Number, which is the translated syntax ID of
11311 {synID}. This is the syntax group ID of what is being used to
11312 highlight the character. Highlight links given with
11313 ":highlight link" are followed.
11314
Bram Moolenaard592deb2022-06-17 15:42:40 +010011315 Returns zero on error.
11316
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011317 Can also be used as a |method|: >
11318 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011319<
11320 Return type: |Number|
11321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011322
11323synconcealed({lnum}, {col}) *synconcealed()*
11324 The result is a |List| with currently three items:
11325 1. The first item in the list is 0 if the character at the
11326 position {lnum} and {col} is not part of a concealable
11327 region, 1 if it is. {lnum} is used like with |getline()|.
11328 2. The second item in the list is a string. If the first item
11329 is 1, the second item contains the text which will be
11330 displayed in place of the concealed text, depending on the
11331 current setting of 'conceallevel' and 'listchars'.
11332 3. The third and final item in the list is a number
11333 representing the specific syntax region matched in the
11334 line. When the character is not concealed the value is
11335 zero. This allows detection of the beginning of a new
11336 concealable region if there are two consecutive regions
11337 with the same replacement character. For an example, if
11338 the text is "123456" and both "23" and "45" are concealed
11339 and replaced by the character "X", then:
11340 call returns ~
11341 synconcealed(lnum, 1) [0, '', 0]
11342 synconcealed(lnum, 2) [1, 'X', 1]
11343 synconcealed(lnum, 3) [1, 'X', 1]
11344 synconcealed(lnum, 4) [1, 'X', 2]
11345 synconcealed(lnum, 5) [1, 'X', 2]
11346 synconcealed(lnum, 6) [0, '', 0]
11347
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011348 Note: Doesn't consider |matchadd()| highlighting items,
11349 since syntax and matching highlighting are two different
11350 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011351
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011352 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011353
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011354
11355synstack({lnum}, {col}) *synstack()*
11356 Return a |List|, which is the stack of syntax items at the
11357 position {lnum} and {col} in the current window. {lnum} is
11358 used like with |getline()|. Each item in the List is an ID
11359 like what |synID()| returns.
11360 The first item in the List is the outer region, following are
11361 items contained in that one. The last one is what |synID()|
11362 returns, unless not the whole item is highlighted or it is a
11363 transparent item.
11364 This function is useful for debugging a syntax file.
11365 Example that shows the syntax stack under the cursor: >
11366 for id in synstack(line("."), col("."))
11367 echo synIDattr(id, "name")
11368 endfor
11369< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011370 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011371 character in a line and the first column in an empty line are
11372 valid positions.
11373
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011374 Return type: list<number> or list<any>
11375
11376
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011377system({expr} [, {input}]) *system()* *E677*
11378 Get the output of the shell command {expr} as a |String|. See
11379 |systemlist()| to get the output as a |List|.
11380
11381 When {input} is given and is a |String| this string is written
11382 to a file and passed as stdin to the command. The string is
11383 written as-is, you need to take care of using the correct line
11384 separators yourself.
11385 If {input} is given and is a |List| it is written to the file
11386 in a way |writefile()| does with {binary} set to "b" (i.e.
11387 with a newline between each list item with newlines inside
11388 list items converted to NULs).
11389 When {input} is given and is a number that is a valid id for
11390 an existing buffer then the content of the buffer is written
11391 to the file line by line, each line terminated by a NL and
11392 NULs characters where the text has a NL.
11393
11394 Pipes are not used, the 'shelltemp' option is not used.
11395
11396 When prepended by |:silent| the terminal will not be set to
11397 cooked mode. This is meant to be used for commands that do
11398 not need the user to type. It avoids stray characters showing
11399 up on the screen which require |CTRL-L| to remove. >
11400 :silent let f = system('ls *.vim')
11401<
11402 Note: Use |shellescape()| or |::S| with |expand()| or
11403 |fnamemodify()| to escape special characters in a command
11404 argument. Newlines in {expr} may cause the command to fail.
11405 The characters in 'shellquote' and 'shellxquote' may also
11406 cause trouble.
11407 This is not to be used for interactive commands.
11408
11409 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011410 :let files = system('ls ' .. shellescape(expand('%:h')))
11411 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011412
11413< To make the result more system-independent, the shell output
11414 is filtered to replace <CR> with <NL> for Macintosh, and
11415 <CR><NL> with <NL> for DOS-like systems.
11416 To avoid the string being truncated at a NUL, all NUL
11417 characters are replaced with SOH (0x01).
11418
11419 The command executed is constructed using several options:
11420 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11421 ({tmp} is an automatically generated file name).
11422 For Unix, braces are put around {expr} to allow for
11423 concatenated commands.
11424
11425 The command will be executed in "cooked" mode, so that a
11426 CTRL-C will interrupt the command (on Unix at least).
11427
11428 The resulting error code can be found in |v:shell_error|.
11429 This function will fail in |restricted-mode|.
11430
11431 Note that any wrong value in the options mentioned above may
11432 make the function fail. It has also been reported to fail
11433 when using a security agent application.
11434 Unlike ":!cmd" there is no automatic check for changed files.
11435 Use |:checktime| to force a check.
11436
11437 Can also be used as a |method|: >
11438 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011439<
11440 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011441
11442
11443systemlist({expr} [, {input}]) *systemlist()*
11444 Same as |system()|, but returns a |List| with lines (parts of
11445 output separated by NL) with NULs transformed into NLs. Output
11446 is the same as |readfile()| will output with {binary} argument
11447 set to "b", except that there is no extra empty item when the
11448 result ends in a NL.
11449 Note that on MS-Windows you may get trailing CR characters.
11450
11451 To see the difference between "echo hello" and "echo -n hello"
11452 use |system()| and |split()|: >
11453 echo system('echo hello')->split('\n', 1)
11454<
11455 Returns an empty string on error.
11456
11457 Can also be used as a |method|: >
11458 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011459<
11460 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011461
11462
11463tabpagebuflist([{arg}]) *tabpagebuflist()*
11464 The result is a |List|, where each item is the number of the
11465 buffer associated with each window in the current tab page.
11466 {arg} specifies the number of the tab page to be used. When
11467 omitted the current tab page is used.
11468 When {arg} is invalid the number zero is returned.
11469 To get a list of all buffers in all tabs use this: >
11470 let buflist = []
11471 for i in range(tabpagenr('$'))
11472 call extend(buflist, tabpagebuflist(i + 1))
11473 endfor
11474< Note that a buffer may appear in more than one window.
11475
11476 Can also be used as a |method|: >
11477 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011478<
11479 Return type: list<number>
11480
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011481
11482tabpagenr([{arg}]) *tabpagenr()*
11483 The result is a Number, which is the number of the current
11484 tab page. The first tab page has number 1.
11485
11486 The optional argument {arg} supports the following values:
11487 $ the number of the last tab page (the tab page
11488 count).
11489 # the number of the last accessed tab page
11490 (where |g<Tab>| goes to). if there is no
11491 previous tab page 0 is returned.
11492 The number can be used with the |:tab| command.
11493
Bram Moolenaard592deb2022-06-17 15:42:40 +010011494 Returns zero on error.
11495
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011496 Return type: |Number|
11497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011498
11499tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11500 Like |winnr()| but for tab page {tabarg}.
11501 {tabarg} specifies the number of tab page to be used.
11502 {arg} is used like with |winnr()|:
11503 - When omitted the current window number is returned. This is
11504 the window which will be used when going to this tab page.
11505 - When "$" the number of windows is returned.
11506 - When "#" the previous window nr is returned.
11507 Useful examples: >
11508 tabpagewinnr(1) " current window of tab page 1
11509 tabpagewinnr(4, '$') " number of windows in tab page 4
11510< When {tabarg} is invalid zero is returned.
11511
11512 Can also be used as a |method|: >
11513 GetTabpage()->tabpagewinnr()
11514<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011515 Return type: |Number|
11516
11517
11518tagfiles() *tagfiles()*
11519 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011520 for the current buffer. This is the 'tags' option expanded.
11521
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011522 Return type: list<string> or list<any>
11523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011524
11525taglist({expr} [, {filename}]) *taglist()*
11526 Returns a |List| of tags matching the regular expression {expr}.
11527
11528 If {filename} is passed it is used to prioritize the results
11529 in the same way that |:tselect| does. See |tag-priority|.
11530 {filename} should be the full path of the file.
11531
11532 Each list item is a dictionary with at least the following
11533 entries:
11534 name Name of the tag.
11535 filename Name of the file where the tag is
11536 defined. It is either relative to the
11537 current directory or a full path.
11538 cmd Ex command used to locate the tag in
11539 the file.
11540 kind Type of the tag. The value for this
11541 entry depends on the language specific
11542 kind values. Only available when
11543 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011544 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011545 static A file specific tag. Refer to
11546 |static-tag| for more information.
11547 More entries may be present, depending on the content of the
11548 tags file: access, implementation, inherits and signature.
11549 Refer to the ctags documentation for information about these
11550 fields. For C code the fields "struct", "class" and "enum"
11551 may appear, they give the name of the entity the tag is
11552 contained in.
11553
11554 The ex-command "cmd" can be either an ex search pattern, a
11555 line number or a line number followed by a byte number.
11556
11557 If there are no matching tags, then an empty list is returned.
11558
11559 To get an exact tag match, the anchors '^' and '$' should be
11560 used in {expr}. This also make the function work faster.
11561 Refer to |tag-regexp| for more information about the tag
11562 search regular expression pattern.
11563
11564 Refer to |'tags'| for information about how the tags file is
11565 located by Vim. Refer to |tags-file-format| for the format of
11566 the tags file generated by the different ctags tools.
11567
11568 Can also be used as a |method|: >
11569 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011570<
11571 Return type: list<dict<any>> or list<any>
11572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011573
11574tan({expr}) *tan()*
11575 Return the tangent of {expr}, measured in radians, as a |Float|
11576 in the range [-inf, inf].
11577 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011578 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011579 Examples: >
11580 :echo tan(10)
11581< 0.648361 >
11582 :echo tan(-4.01)
11583< -1.181502
11584
11585 Can also be used as a |method|: >
11586 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011587<
11588 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011589
11590
11591tanh({expr}) *tanh()*
11592 Return the hyperbolic tangent of {expr} as a |Float| in the
11593 range [-1, 1].
11594 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011595 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011596 Examples: >
11597 :echo tanh(0.5)
11598< 0.462117 >
11599 :echo tanh(-1)
11600< -0.761594
11601
11602 Can also be used as a |method|: >
11603 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011604<
11605 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011606
11607
11608tempname() *tempname()* *temp-file-name*
11609 The result is a String, which is the name of a file that
11610 doesn't exist. It can be used for a temporary file. The name
11611 is different for at least 26 consecutive calls. Example: >
11612 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011613 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011614< For Unix, the file will be in a private directory |tempfile|
11615 that is recursively deleted when Vim exits, on other systems
11616 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011617 For MS-Windows forward slashes are used when the 'shellslash'
11618 option is set, or when 'shellcmdflag' starts with '-' and
11619 'shell' does not contain powershell or pwsh.
11620
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011621 Return type: |String|
11622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011623
11624term_ functions are documented here: |terminal-function-details|
11625
11626
11627terminalprops() *terminalprops()*
11628 Returns a |Dictionary| with properties of the terminal that Vim
11629 detected from the response to |t_RV| request. See
11630 |v:termresponse| for the response itself. If |v:termresponse|
11631 is empty most values here will be 'u' for unknown.
11632 cursor_style whether sending |t_RS| works **
11633 cursor_blink_mode whether sending |t_RC| works **
11634 underline_rgb whether |t_8u| works **
11635 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011636 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011637
11638 ** value 'u' for unknown, 'y' for yes, 'n' for no
11639
11640 If the |+termresponse| feature is missing then the result is
11641 an empty dictionary.
11642
11643 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11644 current cursor style.
11645 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11646 request the cursor blink status.
11647 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11648 is not empty, Vim will detect the working of sending |t_RS|
11649 and |t_RC| on startup.
11650
11651 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11652 This avoids sending it to xterm, which would clear the colors.
11653
11654 For "mouse" the value 'u' is unknown
11655
11656 Also see:
11657 - 'ambiwidth' - detected by using |t_u7|.
11658 - |v:termstyleresp| and |v:termblinkresp| for the response to
11659 |t_RS| and |t_RC|.
11660
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011661 Return type: dict<string>
11662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011663
11664test_ functions are documented here: |test-functions-details|
11665
11666
11667 *timer_info()*
11668timer_info([{id}])
11669 Return a list with information about timers.
11670 When {id} is given only information about this timer is
11671 returned. When timer {id} does not exist an empty list is
11672 returned.
11673 When {id} is omitted information about all timers is returned.
11674
11675 For each timer the information is stored in a |Dictionary| with
11676 these items:
11677 "id" the timer ID
11678 "time" time the timer was started with
11679 "remaining" time until the timer fires
11680 "repeat" number of times the timer will still fire;
11681 -1 means forever
11682 "callback" the callback
11683 "paused" 1 if the timer is paused, 0 otherwise
11684
11685 Can also be used as a |method|: >
11686 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011687<
11688 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011689
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011690 {only available when compiled with the |+timers| feature}
11691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011692
11693timer_pause({timer}, {paused}) *timer_pause()*
11694 Pause or unpause a timer. A paused timer does not invoke its
11695 callback when its time expires. Unpausing a timer may cause
11696 the callback to be invoked almost immediately if enough time
11697 has passed.
11698
11699 Pausing a timer is useful to avoid the callback to be called
11700 for a short time.
11701
11702 If {paused} evaluates to a non-zero Number or a non-empty
11703 String, then the timer is paused, otherwise it is unpaused.
11704 See |non-zero-arg|.
11705
11706 Can also be used as a |method|: >
11707 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011708<
11709 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011710
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011711 {only available when compiled with the |+timers| feature}
11712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011713
11714 *timer_start()* *timer* *timers*
11715timer_start({time}, {callback} [, {options}])
11716 Create a timer and return the timer ID.
11717
11718 {time} is the waiting time in milliseconds. This is the
11719 minimum time before invoking the callback. When the system is
11720 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011721 Zero can be used to execute the callback when Vim is back in
11722 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011723
11724 {callback} is the function to call. It can be the name of a
11725 function or a |Funcref|. It is called with one argument, which
11726 is the timer ID. The callback is only invoked when Vim is
11727 waiting for input.
11728 If you want to show a message look at |popup_notification()|
11729 to avoid interfering with what the user is doing.
11730
11731 {options} is a dictionary. Supported entries:
11732 "repeat" Number of times to repeat calling the
11733 callback. -1 means forever. When not present
11734 the callback will be called once.
11735 If the timer causes an error three times in a
11736 row the repeat is cancelled. This avoids that
11737 Vim becomes unusable because of all the error
11738 messages.
11739
Bram Moolenaard592deb2022-06-17 15:42:40 +010011740 Returns -1 on error.
11741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011742 Example: >
11743 func MyHandler(timer)
11744 echo 'Handler called'
11745 endfunc
11746 let timer = timer_start(500, 'MyHandler',
11747 \ {'repeat': 3})
11748< This will invoke MyHandler() three times at 500 msec
11749 intervals.
11750
11751 Can also be used as a |method|: >
11752 GetMsec()->timer_start(callback)
11753
11754< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011755
11756 Return type: |Number|
11757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011758 {only available when compiled with the |+timers| feature}
11759
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011761timer_stop({timer}) *timer_stop()*
11762 Stop a timer. The timer callback will no longer be invoked.
11763 {timer} is an ID returned by timer_start(), thus it must be a
11764 Number. If {timer} does not exist there is no error.
11765
11766 Can also be used as a |method|: >
11767 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011768<
11769 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011770
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011771 {only available when compiled with the |+timers| feature}
11772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011773
11774timer_stopall() *timer_stopall()*
11775 Stop all timers. The timer callbacks will no longer be
11776 invoked. Useful if a timer is misbehaving. If there are no
11777 timers there is no error.
11778
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011779 Return type: |Number|
11780
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011781 {only available when compiled with the |+timers| feature}
11782
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011784tolower({expr}) *tolower()*
11785 The result is a copy of the String given, with all uppercase
11786 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011787 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011788
11789 Can also be used as a |method|: >
11790 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011791<
11792 Return type: |String|
11793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011794
11795toupper({expr}) *toupper()*
11796 The result is a copy of the String given, with all lowercase
11797 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011798 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011799
11800 Can also be used as a |method|: >
11801 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011802<
11803 Return type: |String|
11804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011805
11806tr({src}, {fromstr}, {tostr}) *tr()*
11807 The result is a copy of the {src} string with all characters
11808 which appear in {fromstr} replaced by the character in that
11809 position in the {tostr} string. Thus the first character in
11810 {fromstr} is translated into the first character in {tostr}
11811 and so on. Exactly like the unix "tr" command.
11812 This code also deals with multibyte characters properly.
11813
Bram Moolenaard592deb2022-06-17 15:42:40 +010011814 Returns an empty string on error.
11815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011816 Examples: >
11817 echo tr("hello there", "ht", "HT")
11818< returns "Hello THere" >
11819 echo tr("<blob>", "<>", "{}")
11820< returns "{blob}"
11821
11822 Can also be used as a |method|: >
11823 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011824<
11825 Return type: |String|
11826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011827
11828trim({text} [, {mask} [, {dir}]]) *trim()*
11829 Return {text} as a String where any character in {mask} is
11830 removed from the beginning and/or end of {text}.
11831
Illia Bobyr80799172023-10-17 18:00:50 +020011832 If {mask} is not given, or is an empty string, {mask} is all
11833 characters up to 0x20, which includes Tab, space, NL and CR,
11834 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011835
11836 The optional {dir} argument specifies where to remove the
11837 characters:
11838 0 remove from the beginning and end of {text}
11839 1 remove only at the beginning of {text}
11840 2 remove only at the end of {text}
11841 When omitted both ends are trimmed.
11842
11843 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011844 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011845
11846 Examples: >
11847 echo trim(" some text ")
11848< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011849 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011850< returns "RESERVE_TAIL" >
11851 echo trim("rm<Xrm<>X>rrm", "rm<>")
11852< returns "Xrm<>X" (characters in the middle are not removed) >
11853 echo trim(" vim ", " ", 2)
11854< returns " vim"
11855
11856 Can also be used as a |method|: >
11857 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011858<
11859 Return type: |String|
11860
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011861
11862trunc({expr}) *trunc()*
11863 Return the largest integral value with magnitude less than or
11864 equal to {expr} as a |Float| (truncate towards zero).
11865 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011866 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011867 Examples: >
11868 echo trunc(1.456)
11869< 1.0 >
11870 echo trunc(-5.456)
11871< -5.0 >
11872 echo trunc(4.0)
11873< 4.0
11874
11875 Can also be used as a |method|: >
11876 Compute()->trunc()
11877<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011878 Return type: |Float|
11879
11880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011881 *type()*
11882type({expr}) The result is a Number representing the type of {expr}.
11883 Instead of using the number directly, it is better to use the
11884 v:t_ variable that has the value:
11885 Number: 0 |v:t_number|
11886 String: 1 |v:t_string|
11887 Funcref: 2 |v:t_func|
11888 List: 3 |v:t_list|
11889 Dictionary: 4 |v:t_dict|
11890 Float: 5 |v:t_float|
11891 Boolean: 6 |v:t_bool| (v:false and v:true)
11892 None: 7 |v:t_none| (v:null and v:none)
11893 Job: 8 |v:t_job|
11894 Channel: 9 |v:t_channel|
11895 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011896 Class: 12 |v:t_class|
11897 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011898 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011899 Enum: 15 |v:t_enum|
11900 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011901 For backward compatibility, this method can be used: >
11902 :if type(myvar) == type(0)
11903 :if type(myvar) == type("")
11904 :if type(myvar) == type(function("tr"))
11905 :if type(myvar) == type([])
11906 :if type(myvar) == type({})
11907 :if type(myvar) == type(0.0)
11908 :if type(myvar) == type(v:false)
11909 :if type(myvar) == type(v:none)
11910< To check if the v:t_ variables exist use this: >
11911 :if exists('v:t_number')
11912
11913< Can also be used as a |method|: >
11914 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011915<
11916 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011917
11918
11919typename({expr}) *typename()*
11920 Return a string representation of the type of {expr}.
11921 Example: >
11922 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011923< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011924
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011925 Return type: |String|
11926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011927
11928undofile({name}) *undofile()*
11929 Return the name of the undo file that would be used for a file
11930 with name {name} when writing. This uses the 'undodir'
11931 option, finding directories that exist. It does not check if
11932 the undo file exists.
11933 {name} is always expanded to the full path, since that is what
11934 is used internally.
11935 If {name} is empty undofile() returns an empty string, since a
11936 buffer without a file name will not write an undo file.
11937 Useful in combination with |:wundo| and |:rundo|.
11938 When compiled without the |+persistent_undo| option this always
11939 returns an empty string.
11940
11941 Can also be used as a |method|: >
11942 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011943<
11944 Return type: |String|
11945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011946
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011947undotree([{buf}]) *undotree()*
11948 Return the current state of the undo tree for the current
11949 buffer, or for a specific buffer if {buf} is given. The
11950 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011951 "seq_last" The highest undo sequence number used.
11952 "seq_cur" The sequence number of the current position in
11953 the undo tree. This differs from "seq_last"
11954 when some changes were undone.
11955 "time_cur" Time last used for |:earlier| and related
11956 commands. Use |strftime()| to convert to
11957 something readable.
11958 "save_last" Number of the last file write. Zero when no
11959 write yet.
11960 "save_cur" Number of the current position in the undo
11961 tree.
11962 "synced" Non-zero when the last undo block was synced.
11963 This happens when waiting from input from the
11964 user. See |undo-blocks|.
11965 "entries" A list of dictionaries with information about
11966 undo blocks.
11967
11968 The first item in the "entries" list is the oldest undo item.
11969 Each List item is a |Dictionary| with these items:
11970 "seq" Undo sequence number. Same as what appears in
11971 |:undolist|.
11972 "time" Timestamp when the change happened. Use
11973 |strftime()| to convert to something readable.
11974 "newhead" Only appears in the item that is the last one
11975 that was added. This marks the last change
11976 and where further changes will be added.
11977 "curhead" Only appears in the item that is the last one
11978 that was undone. This marks the current
11979 position in the undo tree, the block that will
11980 be used by a redo command. When nothing was
11981 undone after the last change this item will
11982 not appear anywhere.
11983 "save" Only appears on the last block before a file
11984 write. The number is the write count. The
11985 first write has number 1, the last one the
11986 "save_last" mentioned above.
11987 "alt" Alternate entry. This is again a List of undo
11988 blocks. Each item may again have an "alt"
11989 item.
11990
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011991 Return type: dict<any>
11992
11993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011994uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11995 Remove second and succeeding copies of repeated adjacent
11996 {list} items in-place. Returns {list}. If you want a list
11997 to remain unmodified make a copy first: >
11998 :let newlist = uniq(copy(mylist))
11999< The default compare function uses the string representation of
12000 each item. For the use of {func} and {dict} see |sort()|.
12001
Bram Moolenaard592deb2022-06-17 15:42:40 +010012002 Returns zero if {list} is not a |List|.
12003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012004 Can also be used as a |method|: >
12005 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012006<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012007 Return type: list<{type}>
12008
12009
Christian Brabandt67672ef2023-04-24 21:09:54 +010012010 *utf16idx()*
12011utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012012 Same as |charidx()| but returns the UTF-16 code unit index of
12013 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012014
12015 When {charidx} is present and TRUE, {idx} is used as the
12016 character index in the String {string} instead of as the byte
12017 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012018 An {idx} in the middle of a UTF-8 sequence is rounded
12019 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012020
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012021 Returns -1 if the arguments are invalid or if there are less
12022 than {idx} bytes in {string}. If there are exactly {idx} bytes
12023 the length of the string in UTF-16 code units is returned.
12024
Christian Brabandt67672ef2023-04-24 21:09:54 +010012025 See |byteidx()| and |byteidxcomp()| for getting the byte index
12026 from the UTF-16 index and |charidx()| for getting the
12027 character index from the UTF-16 index.
12028 Refer to |string-offset-encoding| for more information.
12029 Examples: >
12030 echo utf16idx('a😊😊', 3) returns 2
12031 echo utf16idx('a😊😊', 7) returns 4
12032 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12033 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12034 echo utf16idx('aą́c', 6) returns 2
12035 echo utf16idx('aą́c', 6, 1) returns 4
12036 echo utf16idx('a😊😊', 9) returns -1
12037<
12038 Can also be used as a |method|: >
12039 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012040<
12041 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012042
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012043
12044values({dict}) *values()*
12045 Return a |List| with all the values of {dict}. The |List| is
12046 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012047 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012048
12049 Can also be used as a |method|: >
12050 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012051<
12052 Return type: list<any>
12053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012054
zeertzjq825cf812023-08-17 22:55:25 +020012055virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012056 The result is a Number, which is the screen column of the file
12057 position given with {expr}. That is, the last screen position
12058 occupied by the character at that position, when the screen
12059 would be of unlimited width. When there is a <Tab> at the
12060 position, the returned Number will be the column at the end of
12061 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12062 set to 8, it returns 8. |conceal| is ignored.
12063 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012064
zeertzjq02f3eba2024-06-12 20:45:24 +020012065 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012066 When {expr} is "$", it means the end of the cursor line, so
12067 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012068
12069 When 'virtualedit' is used {expr} can be [lnum, col, off],
12070 where "off" is the offset in screen columns from the start of
12071 the character. E.g., a position within a <Tab> or after the
12072 last character. When "off" is omitted zero is used. When
12073 Virtual editing is active in the current mode, a position
12074 beyond the end of the line can be returned. Also see
12075 |'virtualedit'|
12076
zeertzjq825cf812023-08-17 22:55:25 +020012077 If {list} is present and non-zero then virtcol() returns a
12078 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012079 character.
12080
zeertzjq825cf812023-08-17 22:55:25 +020012081 With the optional {winid} argument the values are obtained for
12082 that window instead of the current window.
12083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012084 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012086 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012087 " With text "foo^Lbar" and cursor on the "^L":
12088
12089 virtcol(".") " returns 5
12090 virtcol(".", 1) " returns [4, 5]
12091 virtcol("$") " returns 9
12092
12093 " With text " there", with 't at 'h':
12094
12095 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012096<
12097 The first column is 1. 0 or [0, 0] is returned for an error.
12098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012099 A more advanced example that echoes the maximum length of
12100 all lines: >
12101 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12102
12103< Can also be used as a |method|: >
12104 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012105<
12106 Return type: |Number|
12107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012108
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012109virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12110 The result is a Number, which is the byte index of the
12111 character in window {winid} at buffer line {lnum} and virtual
12112 column {col}.
12113
zeertzjqb583eda2023-10-14 11:32:28 +020012114 If buffer line {lnum} is an empty line, 0 is returned.
12115
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012116 If {col} is greater than the last virtual column in line
12117 {lnum}, then the byte index of the character at the last
12118 virtual column is returned.
12119
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012120 For a multi-byte character, the column number of the first
12121 byte in the character is returned.
12122
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012123 The {winid} argument can be the window number or the
12124 |window-ID|. If this is zero, then the current window is used.
12125
12126 Returns -1 if the window {winid} doesn't exist or the buffer
12127 line {lnum} or virtual column {col} is invalid.
12128
12129 See also |screenpos()|, |virtcol()| and |col()|.
12130
12131 Can also be used as a |method|: >
12132 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012133<
12134 Return type: |Number|
12135
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012136
12137visualmode([{expr}]) *visualmode()*
12138 The result is a String, which describes the last Visual mode
12139 used in the current buffer. Initially it returns an empty
12140 string, but once Visual mode has been used, it returns "v",
12141 "V", or "<CTRL-V>" (a single CTRL-V character) for
12142 character-wise, line-wise, or block-wise Visual mode
12143 respectively.
12144 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012145 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012146< This enters the same Visual mode as before. It is also useful
12147 in scripts if you wish to act differently depending on the
12148 Visual mode that was used.
12149 If Visual mode is active, use |mode()| to get the Visual mode
12150 (e.g., in a |:vmap|).
12151 If {expr} is supplied and it evaluates to a non-zero Number or
12152 a non-empty String, then the Visual mode will be cleared and
12153 the old value is returned. See |non-zero-arg|.
12154
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012155 Return type: |String|
12156
12157
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012158wildmenumode() *wildmenumode()*
12159 Returns |TRUE| when the wildmenu is active and |FALSE|
12160 otherwise. See 'wildmenu' and 'wildmode'.
12161 This can be used in mappings to handle the 'wildcharm' option
12162 gracefully. (Makes only sense with |mapmode-c| mappings).
12163
12164 For example to make <c-j> work like <down> in wildmode, use: >
12165 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12166<
Milly6c2fc372024-10-16 22:11:17 +020012167 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012168
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012169 Return type: |Number|
12170
12171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012172win_execute({id}, {command} [, {silent}]) *win_execute()*
12173 Like `execute()` but in the context of window {id}.
12174 The window will temporarily be made the current window,
12175 without triggering autocommands or changing directory. When
12176 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012177 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012178 Example: >
12179 call win_execute(winid, 'set syntax=python')
12180< Doing the same with `setwinvar()` would not trigger
12181 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012182 *E994*
12183 Not all commands are allowed in popup windows.
12184 When window {id} does not exist then no error is given and
12185 an empty string is returned.
12186
12187 Can also be used as a |method|, the base is passed as the
12188 second argument: >
12189 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012190<
12191 Return type: |String|
12192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012193
12194win_findbuf({bufnr}) *win_findbuf()*
12195 Returns a |List| with |window-ID|s for windows that contain
12196 buffer {bufnr}. When there is none the list is empty.
12197
12198 Can also be used as a |method|: >
12199 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012200<
12201 Return type: list<number> or list<any>
12202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012203
12204win_getid([{win} [, {tab}]]) *win_getid()*
12205 Get the |window-ID| for the specified window.
12206 When {win} is missing use the current window.
12207 With {win} this is the window number. The top window has
12208 number 1.
12209 Without {tab} use the current tab, otherwise the tab with
12210 number {tab}. The first tab has number one.
12211 Return zero if the window cannot be found.
12212
12213 Can also be used as a |method|: >
12214 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012215<
12216 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012217
12218
12219win_gettype([{nr}]) *win_gettype()*
12220 Return the type of the window:
12221 "autocmd" autocommand window. Temporary window
12222 used to execute autocommands.
12223 "command" command-line window |cmdwin|
12224 (empty) normal window
12225 "loclist" |location-list-window|
12226 "popup" popup window |popup|
12227 "preview" preview window |preview-window|
12228 "quickfix" |quickfix-window|
12229 "unknown" window {nr} not found
12230
12231 When {nr} is omitted return the type of the current window.
12232 When {nr} is given return the type of this window by number or
12233 |window-ID|.
12234
12235 Also see the 'buftype' option. When running a terminal in a
12236 popup window then 'buftype' is "terminal" and win_gettype()
12237 returns "popup".
12238
12239 Can also be used as a |method|: >
12240 GetWinid()->win_gettype()
12241<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012242 Return type: |String|
12243
12244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012245win_gotoid({expr}) *win_gotoid()*
12246 Go to window with ID {expr}. This may also change the current
12247 tabpage.
12248 Return TRUE if successful, FALSE if the window cannot be found.
12249
12250 Can also be used as a |method|: >
12251 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012252<
12253 Return type: |Number|
12254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012255
12256win_id2tabwin({expr}) *win_id2tabwin()*
12257 Return a list with the tab number and window number of window
12258 with ID {expr}: [tabnr, winnr].
12259 Return [0, 0] if the window cannot be found.
12260
12261 Can also be used as a |method|: >
12262 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012263<
12264 Return type: list<number>
12265
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012266
12267win_id2win({expr}) *win_id2win()*
12268 Return the window number of window with ID {expr}.
12269 Return 0 if the window cannot be found in the current tabpage.
12270
12271 Can also be used as a |method|: >
12272 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012273<
12274 Return type: |Number|
12275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012276
Daniel Steinbergee630312022-01-10 13:36:34 +000012277win_move_separator({nr}, {offset}) *win_move_separator()*
12278 Move window {nr}'s vertical separator (i.e., the right border)
12279 by {offset} columns, as if being dragged by the mouse. {nr}
12280 can be a window number or |window-ID|. A positive {offset}
12281 moves right and a negative {offset} moves left. Moving a
12282 window's vertical separator will change the width of the
12283 window and the width of other windows adjacent to the vertical
12284 separator. The magnitude of movement may be smaller than
12285 specified (e.g., as a consequence of maintaining
12286 'winminwidth'). Returns TRUE if the window can be found and
12287 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012288 This will fail for the rightmost window and a full-width
12289 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012290 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012291
12292 Can also be used as a |method|: >
12293 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012294<
12295 Return type: |Number|
12296
Daniel Steinbergee630312022-01-10 13:36:34 +000012297
12298win_move_statusline({nr}, {offset}) *win_move_statusline()*
12299 Move window {nr}'s status line (i.e., the bottom border) by
12300 {offset} rows, as if being dragged by the mouse. {nr} can be a
12301 window number or |window-ID|. A positive {offset} moves down
12302 and a negative {offset} moves up. Moving a window's status
12303 line will change the height of the window and the height of
12304 other windows adjacent to the status line. The magnitude of
12305 movement may be smaller than specified (e.g., as a consequence
12306 of maintaining 'winminheight'). Returns TRUE if the window can
12307 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012308 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012309
12310 Can also be used as a |method|: >
12311 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012312<
12313 Return type: |Number|
12314
Daniel Steinbergee630312022-01-10 13:36:34 +000012315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012316win_screenpos({nr}) *win_screenpos()*
12317 Return the screen position of window {nr} as a list with two
12318 numbers: [row, col]. The first window always has position
12319 [1, 1], unless there is a tabline, then it is [2, 1].
12320 {nr} can be the window number or the |window-ID|. Use zero
12321 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012322 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012323
12324 Can also be used as a |method|: >
12325 GetWinid()->win_screenpos()
12326<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012327 Return type: list<number>
12328
12329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012330win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012331 Temporarily switch to window {target}, then move window {nr}
12332 to a new split adjacent to {target}.
12333 Unlike commands such as |:split|, no new windows are created
12334 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012335
12336 Both {nr} and {target} can be window numbers or |window-ID|s.
12337 Both must be in the current tab page.
12338
12339 Returns zero for success, non-zero for failure.
12340
12341 {options} is a |Dictionary| with the following optional entries:
12342 "vertical" When TRUE, the split is created vertically,
12343 like with |:vsplit|.
12344 "rightbelow" When TRUE, the split is made below or to the
12345 right (if vertical). When FALSE, it is done
12346 above or to the left (if vertical). When not
12347 present, the values of 'splitbelow' and
12348 'splitright' are used.
12349
12350 Can also be used as a |method|: >
12351 GetWinid()->win_splitmove(target)
12352<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012353 Return type: |Number|
12354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012355
12356 *winbufnr()*
12357winbufnr({nr}) The result is a Number, which is the number of the buffer
12358 associated with window {nr}. {nr} can be the window number or
12359 the |window-ID|.
12360 When {nr} is zero, the number of the buffer in the current
12361 window is returned.
12362 When window {nr} doesn't exist, -1 is returned.
12363 Example: >
12364 :echo "The file in the current window is " . bufname(winbufnr(0))
12365<
12366 Can also be used as a |method|: >
12367 FindWindow()->winbufnr()->bufname()
12368<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012369 Return type: |Number|
12370
12371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012372 *wincol()*
12373wincol() The result is a Number, which is the virtual column of the
12374 cursor in the window. This is counting screen cells from the
12375 left side of the window. The leftmost column is one.
12376
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012377 Return type: |Number|
12378
12379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012380 *windowsversion()*
12381windowsversion()
12382 The result is a String. For MS-Windows it indicates the OS
12383 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12384 Windows XP is "5.1". For non-MS-Windows systems the result is
12385 an empty string.
12386
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012387 Return type: |String|
12388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012389winheight({nr}) *winheight()*
12390 The result is a Number, which is the height of window {nr}.
12391 {nr} can be the window number or the |window-ID|.
12392 When {nr} is zero, the height of the current window is
12393 returned. When window {nr} doesn't exist, -1 is returned.
12394 An existing window always has a height of zero or more.
12395 This excludes any window toolbar line.
12396 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012397 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012398
12399< Can also be used as a |method|: >
12400 GetWinid()->winheight()
12401<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012402 Return type: |Number|
12403
12404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012405winlayout([{tabnr}]) *winlayout()*
12406 The result is a nested List containing the layout of windows
12407 in a tabpage.
12408
12409 Without {tabnr} use the current tabpage, otherwise the tabpage
12410 with number {tabnr}. If the tabpage {tabnr} is not found,
12411 returns an empty list.
12412
12413 For a leaf window, it returns:
12414 ['leaf', {winid}]
12415 For horizontally split windows, which form a column, it
12416 returns:
12417 ['col', [{nested list of windows}]]
12418 For vertically split windows, which form a row, it returns:
12419 ['row', [{nested list of windows}]]
12420
12421 Example: >
12422 " Only one window in the tab page
12423 :echo winlayout()
12424 ['leaf', 1000]
12425 " Two horizontally split windows
12426 :echo winlayout()
12427 ['col', [['leaf', 1000], ['leaf', 1001]]]
12428 " The second tab page, with three horizontally split
12429 " windows, with two vertically split windows in the
12430 " middle window
12431 :echo winlayout(2)
12432 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12433 ['leaf', 1001]]], ['leaf', 1000]]]
12434<
12435 Can also be used as a |method|: >
12436 GetTabnr()->winlayout()
12437<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012438 Return type: list<any>
12439
12440
12441winline() *winline()*
12442 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012443 in the window. This is counting screen lines from the top of
12444 the window. The first line is one.
12445 If the cursor was moved the view on the file will be updated
12446 first, this may cause a scroll.
12447
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012448 Return type: |Number|
12449
12450
12451winnr([{arg}]) *winnr()*
12452 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012453 window. The top window has number 1.
12454 Returns zero for a popup window.
12455
12456 The optional argument {arg} supports the following values:
12457 $ the number of the last window (the window
12458 count).
12459 # the number of the last accessed window (where
12460 |CTRL-W_p| goes to). If there is no previous
12461 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012462 returned. May refer to the current window in
12463 some cases (e.g. when evaluating 'statusline'
12464 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012465 {N}j the number of the Nth window below the
12466 current window (where |CTRL-W_j| goes to).
12467 {N}k the number of the Nth window above the current
12468 window (where |CTRL-W_k| goes to).
12469 {N}h the number of the Nth window left of the
12470 current window (where |CTRL-W_h| goes to).
12471 {N}l the number of the Nth window right of the
12472 current window (where |CTRL-W_l| goes to).
12473 The number can be used with |CTRL-W_w| and ":wincmd w"
12474 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012475 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012476 Also see |tabpagewinnr()| and |win_getid()|.
12477 Examples: >
12478 let window_count = winnr('$')
12479 let prev_window = winnr('#')
12480 let wnum = winnr('3k')
12481
12482< Can also be used as a |method|: >
12483 GetWinval()->winnr()
12484<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012485 Return type: |Number|
12486
12487
12488winrestcmd() *winrestcmd()*
12489 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012490 the current window sizes. Only works properly when no windows
12491 are opened or closed and the current window and tab page is
12492 unchanged.
12493 Example: >
12494 :let cmd = winrestcmd()
12495 :call MessWithWindowSizes()
12496 :exe cmd
12497<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012498 Return type: |String|
12499
12500
12501winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012502 Uses the |Dictionary| returned by |winsaveview()| to restore
12503 the view of the current window.
12504 Note: The {dict} does not have to contain all values, that are
12505 returned by |winsaveview()|. If values are missing, those
12506 settings won't be restored. So you can use: >
12507 :call winrestview({'curswant': 4})
12508<
12509 This will only set the curswant value (the column the cursor
12510 wants to move on vertical movements) of the cursor to column 5
12511 (yes, that is 5), while all other settings will remain the
12512 same. This is useful, if you set the cursor position manually.
12513
12514 If you have changed the values the result is unpredictable.
12515 If the window size changed the result won't be the same.
12516
12517 Can also be used as a |method|: >
12518 GetView()->winrestview()
12519<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012520 Return type: |Number|
12521
12522
12523winsaveview() *winsaveview()*
12524 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012525 the view of the current window. Use |winrestview()| to
12526 restore the view.
12527 This is useful if you have a mapping that jumps around in the
12528 buffer and you want to go back to the original view.
12529 This does not save fold information. Use the 'foldenable'
12530 option to temporarily switch off folding, so that folds are
12531 not opened when moving around. This may have side effects.
12532 The return value includes:
12533 lnum cursor line number
12534 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012535 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012536 returns)
12537 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012538 curswant column for vertical movement (Note:
12539 the first column is zero, as opposed
12540 to what |getcurpos()| returns). After
12541 |$| command it will be a very large
12542 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012543 topline first line in the window
12544 topfill filler lines, only in diff mode
12545 leftcol first column displayed; only used when
12546 'wrap' is off
12547 skipcol columns skipped
12548 Note that no option values are saved.
12549
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012550 Return type: dict<number>
12551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012552
12553winwidth({nr}) *winwidth()*
12554 The result is a Number, which is the width of window {nr}.
12555 {nr} can be the window number or the |window-ID|.
12556 When {nr} is zero, the width of the current window is
12557 returned. When window {nr} doesn't exist, -1 is returned.
12558 An existing window always has a width of zero or more.
12559 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012560 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012561 :if winwidth(0) <= 50
12562 : 50 wincmd |
12563 :endif
12564< For getting the terminal or screen size, see the 'columns'
12565 option.
12566
12567 Can also be used as a |method|: >
12568 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012569<
12570 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012571
12572
12573wordcount() *wordcount()*
12574 The result is a dictionary of byte/chars/word statistics for
12575 the current buffer. This is the same info as provided by
12576 |g_CTRL-G|
12577 The return value includes:
12578 bytes Number of bytes in the buffer
12579 chars Number of chars in the buffer
12580 words Number of words in the buffer
12581 cursor_bytes Number of bytes before cursor position
12582 (not in Visual mode)
12583 cursor_chars Number of chars before cursor position
12584 (not in Visual mode)
12585 cursor_words Number of words before cursor position
12586 (not in Visual mode)
12587 visual_bytes Number of bytes visually selected
12588 (only in Visual mode)
12589 visual_chars Number of chars visually selected
12590 (only in Visual mode)
12591 visual_words Number of words visually selected
12592 (only in Visual mode)
12593
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012594 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012595
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012596
12597writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012598 When {object} is a |List| write it to file {fname}. Each list
12599 item is separated with a NL. Each list item must be a String
12600 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012601 All NL characters are replaced with a NUL character.
12602 Inserting CR characters needs to be done before passing {list}
12603 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012604
12605 When {object} is a |Blob| write the bytes to file {fname}
12606 unmodified, also when binary mode is not specified.
12607
12608 {flags} must be a String. These characters are recognized:
12609
12610 'b' Binary mode is used: There will not be a NL after the
12611 last list item. An empty item at the end does cause the
12612 last line in the file to end in a NL.
12613
12614 'a' Append mode is used, lines are appended to the file: >
12615 :call writefile(["foo"], "event.log", "a")
12616 :call writefile(["bar"], "event.log", "a")
12617<
12618 'D' Delete the file when the current function ends. This
12619 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012620 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012621< Fails when not in a function. Also see |:defer|.
12622
12623 's' fsync() is called after writing the file. This flushes
12624 the file to disk, if possible. This takes more time but
12625 avoids losing the file if the system crashes.
12626
12627 'S' fsync() is not called, even when 'fsync' is set.
12628
12629 When {flags} does not contain "S" or "s" then fsync() is
12630 called if the 'fsync' option is set.
12631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012632 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012634 When the write fails -1 is returned, otherwise 0. There is an
12635 error message if the file can't be created or when writing
12636 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012638 Also see |readfile()|.
12639 To copy a file byte for byte: >
12640 :let fl = readfile("foo", "b")
12641 :call writefile(fl, "foocopy", "b")
12642
12643< Can also be used as a |method|: >
12644 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012645<
12646 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012647
12648
12649xor({expr}, {expr}) *xor()*
12650 Bitwise XOR on the two arguments. The arguments are converted
12651 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012652 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012653 Example: >
12654 :let bits = xor(bits, 0x80)
12655<
12656 Can also be used as a |method|: >
12657 :let bits = bits->xor(0x80)
12658<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012659 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012660
12661==============================================================================
126623. Feature list *feature-list*
12663
12664There are three types of features:
126651. Features that are only supported when they have been enabled when Vim
12666 was compiled |+feature-list|. Example: >
12667 :if has("cindent")
12668< *gui_running*
126692. Features that are only supported when certain conditions have been met.
12670 Example: >
12671 :if has("gui_running")
12672< *has-patch*
126733. Beyond a certain version or at a certain version and including a specific
12674 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12675 later, or it is version 7.4 and patch 248 was included. Example: >
12676 :if has("patch-7.4.248")
12677< Note that it's possible for patch 248 to be omitted even though 249 is
12678 included. Only happens when cherry-picking patches.
12679 Note that this form only works for patch 7.4.237 and later, before that
12680 you need to check for the patch and the v:version. Example (checking
12681 version 6.2.148 or later): >
12682 :if v:version > 602 || (v:version == 602 && has("patch148"))
12683
12684Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12685use: `if exists('+shellslash')`
12686
12687
12688acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012689all_builtin_terms Compiled with all builtin terminals enabled. (always
12690 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012691amiga Amiga version of Vim.
12692arabic Compiled with Arabic support |Arabic|.
12693arp Compiled with ARP support (Amiga).
12694autocmd Compiled with autocommand support. (always true)
12695autochdir Compiled with support for 'autochdir'
12696autoservername Automatically enable |clientserver|
12697balloon_eval Compiled with |balloon-eval| support.
12698balloon_multiline GUI supports multiline balloons.
12699beos BeOS version of Vim.
12700browse Compiled with |:browse| support, and browse() will
12701 work.
12702browsefilter Compiled with support for |browsefilter|.
12703bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012704builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012705byte_offset Compiled with support for 'o' in 'statusline'
12706channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012707cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012708clientserver Compiled with remote invocation support |clientserver|.
12709clipboard Compiled with 'clipboard' support.
12710clipboard_working Compiled with 'clipboard' support and it can be used.
12711cmdline_compl Compiled with |cmdline-completion| support.
12712cmdline_hist Compiled with |cmdline-history| support.
12713cmdline_info Compiled with 'showcmd' and 'ruler' support.
12714comments Compiled with |'comments'| support.
12715compatible Compiled to be very Vi compatible.
12716conpty Platform where |ConPTY| can be used.
12717cryptv Compiled with encryption support |encryption|.
12718cscope Compiled with |cscope| support.
12719cursorbind Compiled with |'cursorbind'| (always true)
12720debug Compiled with "DEBUG" defined.
12721dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012722dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012723dialog_gui Compiled with GUI dialog support.
12724diff Compiled with |vimdiff| and 'diff' support.
12725digraphs Compiled with support for digraphs.
12726directx Compiled with support for DirectX and 'renderoptions'.
12727dnd Compiled with support for the "~ register |quote_~|.
12728drop_file Compiled with |drop_file| support.
12729ebcdic Compiled on a machine with ebcdic character set.
12730emacs_tags Compiled with support for Emacs tags.
12731eval Compiled with expression evaluation support. Always
12732 true, of course!
12733ex_extra |+ex_extra| (always true)
12734extra_search Compiled with support for |'incsearch'| and
12735 |'hlsearch'|
12736farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012737file_in_path Compiled with support for |gf| and |<cfile>| (always
12738 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012739filterpipe When 'shelltemp' is off pipes are used for shell
12740 read/write/filter commands
12741find_in_path Compiled with support for include file searches
12742 |+find_in_path|.
12743float Compiled with support for |Float|.
12744fname_case Case in file names matters (for Amiga and MS-Windows
12745 this is not present).
12746folding Compiled with |folding| support.
12747footer Compiled with GUI footer support. |gui-footer|
12748fork Compiled to use fork()/exec() instead of system().
12749gettext Compiled with message translation |multi-lang|
12750gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012751gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012752gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12753gui_gtk Compiled with GTK+ GUI (any version).
12754gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12755gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12756gui_haiku Compiled with Haiku GUI.
12757gui_mac Compiled with Macintosh GUI.
12758gui_motif Compiled with Motif GUI.
12759gui_photon Compiled with Photon GUI.
12760gui_running Vim is running in the GUI, or it will start soon.
12761gui_win32 Compiled with MS-Windows Win32 GUI.
12762gui_win32s idem, and Win32s system being used (Windows 3.1)
12763haiku Haiku version of Vim.
12764hangul_input Compiled with Hangul input support. |hangul|
12765hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012766hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012767iconv Can use iconv() for conversion.
12768insert_expand Compiled with support for CTRL-X expansion commands in
12769 Insert mode. (always true)
12770job Compiled with support for |channel| and |job|
12771ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012772jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012773keymap Compiled with 'keymap' support.
12774lambda Compiled with |lambda| support.
12775langmap Compiled with 'langmap' support.
12776libcall Compiled with |libcall()| support.
12777linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12778 'breakindent' support.
12779linux Linux version of Vim.
12780lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012781 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012782listcmds Compiled with commands for the buffer list |:files|
12783 and the argument list |arglist|.
12784localmap Compiled with local mappings and abbr. |:map-local|
12785lua Compiled with Lua interface |Lua|.
12786mac Any Macintosh version of Vim cf. osx
12787macunix Synonym for osxdarwin
12788menu Compiled with support for |:menu|.
12789mksession Compiled with support for |:mksession|.
12790modify_fname Compiled with file name modifiers. |filename-modifiers|
12791 (always true)
12792mouse Compiled with support for mouse.
12793mouse_dec Compiled with support for Dec terminal mouse.
12794mouse_gpm Compiled with support for gpm (Linux console mouse)
12795mouse_gpm_enabled GPM mouse is working
12796mouse_netterm Compiled with support for netterm mouse.
12797mouse_pterm Compiled with support for qnx pterm mouse.
12798mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12799mouse_sgr Compiled with support for sgr mouse.
12800mouse_urxvt Compiled with support for urxvt mouse.
12801mouse_xterm Compiled with support for xterm mouse.
12802mouseshape Compiled with support for 'mouseshape'.
12803multi_byte Compiled with support for 'encoding' (always true)
12804multi_byte_encoding 'encoding' is set to a multibyte encoding.
12805multi_byte_ime Compiled with support for IME input method.
12806multi_lang Compiled with support for multiple languages.
12807mzscheme Compiled with MzScheme interface |mzscheme|.
12808nanotime Compiled with sub-second time stamp checks.
12809netbeans_enabled Compiled with support for |netbeans| and connected.
12810netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012811num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012812ole Compiled with OLE automation support for Win32.
12813osx Compiled for macOS cf. mac
12814osxdarwin Compiled for macOS, with |mac-darwin-feature|
12815packages Compiled with |packages| support.
12816path_extra Compiled with up/downwards search in 'path' and 'tags'
12817perl Compiled with Perl interface.
12818persistent_undo Compiled with support for persistent undo history.
12819postscript Compiled with PostScript file printing.
12820printer Compiled with |:hardcopy| support.
12821profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012822prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012823python Python 2.x interface available. |has-python|
12824python_compiled Compiled with Python 2.x interface. |has-python|
12825python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12826python3 Python 3.x interface available. |has-python|
12827python3_compiled Compiled with Python 3.x interface. |has-python|
12828python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012829python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012830pythonx Python 2.x and/or 3.x interface available. |python_x|
12831qnx QNX version of Vim.
12832quickfix Compiled with |quickfix| support.
12833reltime Compiled with |reltime()| support.
12834rightleft Compiled with 'rightleft' support.
12835ruby Compiled with Ruby interface |ruby|.
12836scrollbind Compiled with 'scrollbind' support. (always true)
12837showcmd Compiled with 'showcmd' support.
12838signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012839smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012840sodium Compiled with libsodium for better crypt support
12841sound Compiled with sound support, e.g. `sound_playevent()`
12842spell Compiled with spell checking support |spell|.
12843startuptime Compiled with |--startuptime| support.
12844statusline Compiled with support for 'statusline', 'rulerformat'
12845 and special formats of 'titlestring' and 'iconstring'.
12846sun SunOS version of Vim.
12847sun_workshop Support for Sun |workshop| has been removed.
12848syntax Compiled with syntax highlighting support |syntax|.
12849syntax_items There are active syntax highlighting items for the
12850 current buffer.
12851system Compiled to use system() instead of fork()/exec().
12852tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012853 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012854tag_old_static Support for old static tags was removed, see
12855 |tag-old-static|.
12856tcl Compiled with Tcl interface.
12857termguicolors Compiled with true color in terminal support.
12858terminal Compiled with |terminal| support.
12859terminfo Compiled with terminfo instead of termcap.
12860termresponse Compiled with support for |t_RV| and |v:termresponse|.
12861textobjects Compiled with support for |text-objects|.
12862textprop Compiled with support for |text-properties|.
12863tgetent Compiled with tgetent support, able to use a termcap
12864 or terminfo file.
12865timers Compiled with |timer_start()| support.
12866title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012867 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012868toolbar Compiled with support for |gui-toolbar|.
12869ttyin input is a terminal (tty)
12870ttyout output is a terminal (tty)
12871unix Unix version of Vim. *+unix*
12872unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12873user_commands User-defined commands. (always true)
12874vartabs Compiled with variable tabstop support |'vartabstop'|.
12875vcon Win32: Virtual console support is working, can use
12876 'termguicolors'. Also see |+vtp|.
12877vertsplit Compiled with vertically split windows |:vsplit|.
12878 (always true)
12879vim_starting True while initial source'ing takes place. |startup|
12880 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012881vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012882viminfo Compiled with viminfo support.
12883vimscript-1 Compiled Vim script version 1 support
12884vimscript-2 Compiled Vim script version 2 support
12885vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012886vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012887virtualedit Compiled with 'virtualedit' option. (always true)
12888visual Compiled with Visual mode. (always true)
12889visualextra Compiled with extra Visual mode commands. (always
12890 true) |blockwise-operators|.
12891vms VMS version of Vim.
12892vreplace Compiled with |gR| and |gr| commands. (always true)
12893vtp Compiled for vcon support |+vtp| (check vcon to find
12894 out if it works in the current console).
12895wildignore Compiled with 'wildignore' option.
12896wildmenu Compiled with 'wildmenu' option.
12897win16 old version for MS-Windows 3.1 (always false)
12898win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12899 64 bits)
12900win32unix Win32 version of Vim, using Unix files (Cygwin)
12901win64 Win64 version of Vim (MS-Windows 64 bit).
12902win95 Win32 version for MS-Windows 95/98/ME (always false)
12903winaltkeys Compiled with 'winaltkeys' option.
12904windows Compiled with support for more than one window.
12905 (always true)
12906writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012907xattr Compiled with extended attributes support |xattr|
12908 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012909xfontset Compiled with X fontset support |xfontset|.
12910xim Compiled with X input method support |xim|.
12911xpm Compiled with pixmap support.
12912xpm_w32 Compiled with pixmap support for Win32. (Only for
12913 backward compatibility. Use "xpm" instead.)
12914xsmp Compiled with X session management support.
12915xsmp_interact Compiled with interactive X session management support.
12916xterm_clipboard Compiled with support for xterm clipboard.
12917xterm_save Compiled with support for saving and restoring the
12918 xterm screen.
12919x11 Compiled with X11 support.
12920
12921
12922==============================================================================
129234. Matching a pattern in a String *string-match*
12924
12925This is common between several functions. A regexp pattern as explained at
12926|pattern| is normally used to find a match in the buffer lines. When a
12927pattern is used to find a match in a String, almost everything works in the
12928same way. The difference is that a String is handled like it is one line.
12929When it contains a "\n" character, this is not seen as a line break for the
12930pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12931>
12932 :let a = "aaaa\nxxxx"
12933 :echo matchstr(a, "..\n..")
12934 aa
12935 xx
12936 :echo matchstr(a, "a.x")
12937 a
12938 x
12939
12940Don't forget that "^" will only match at the first character of the String and
12941"$" at the last character of the string. They don't match after or before a
12942"\n".
12943
12944 vim:tw=78:ts=8:noet:ft=help:norl: