blob: 717f13a6ffe31d3cd4f3f59cacbf4e5881792b18 [file] [log] [blame]
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02001*builtin.txt* For Vim version 9.1. Last change: 2025 May 14
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Girish Palya92f68e22025-04-21 11:12:41 +0200132cmdcomplete_info() Dict get current cmdline completion
133 information
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000134col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000135complete({startcol}, {matches}) none set Insert mode completion
136complete_add({expr}) Number add completion match
137complete_check() Number check for key typed during completion
138complete_info([{what}]) Dict get current completion information
glepnirbcd59952025-04-24 21:48:35 +0200139complete_match([{lnum}, {col}]) List get completion column and trigger text
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000140confirm({msg} [, {choices} [, {default} [, {type}]]])
141 Number number of choice picked by user
142copy({expr}) any make a shallow copy of {expr}
143cos({expr}) Float cosine of {expr}
144cosh({expr}) Float hyperbolic cosine of {expr}
145count({comp}, {expr} [, {ic} [, {start}]])
146 Number count how many {expr} are in {comp}
147cscope_connection([{num}, {dbpath} [, {prepend}]])
148 Number checks existence of cscope connection
149cursor({lnum}, {col} [, {off}])
150 Number move cursor to {lnum}, {col}, {off}
151cursor({list}) Number move cursor to position in {list}
152debugbreak({pid}) Number interrupt process being debugged
153deepcopy({expr} [, {noref}]) any make a full copy of {expr}
154delete({fname} [, {flags}]) Number delete the file or directory {fname}
155deletebufline({buf}, {first} [, {last}])
156 Number delete lines from buffer {buf}
157did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100158diff({fromlist}, {tolist} [, {options}])
159 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000160diff_filler({lnum}) Number diff filler lines about {lnum}
161diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
162digraph_get({chars}) String get the |digraph| of {chars}
163digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200164digraph_set({chars}, {digraph}) Bool register |digraph|
165digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000166echoraw({expr}) none output {expr} as-is
167empty({expr}) Number |TRUE| if {expr} is empty
168environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100169err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000170escape({string}, {chars}) String escape {chars} in {string} with '\'
171eval({string}) any evaluate {string} into its value
172eventhandler() Number |TRUE| if inside an event handler
173executable({expr}) Number 1 if executable {expr} exists
174execute({command}) String execute {command} and get the output
175exepath({expr}) String full path of the command {expr}
176exists({expr}) Number |TRUE| if {expr} exists
177exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
178exp({expr}) Float exponential of {expr}
179expand({expr} [, {nosuf} [, {list}]])
180 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100181expandcmd({string} [, {options}])
182 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000183extend({expr1}, {expr2} [, {expr3}])
184 List/Dict insert items of {expr2} into {expr1}
185extendnew({expr1}, {expr2} [, {expr3}])
186 List/Dict like |extend()| but creates a new
187 List or Dictionary
188feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200189filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
190 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000191filereadable({file}) Number |TRUE| if {file} is a readable file
192filewritable({file}) Number |TRUE| if {file} is a writable file
193filter({expr1}, {expr2}) List/Dict/Blob/String
194 remove items from {expr1} where
195 {expr2} is 0
196finddir({name} [, {path} [, {count}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000197findfile({name} [, {path} [, {count}]])
Christian Brabandt17ad8522025-05-09 00:03:20 +0200198 String/List find dir/file {name} in {path}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000199flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
200flattennew({list} [, {maxdepth}])
201 List flatten a copy of {list}
202float2nr({expr}) Number convert Float {expr} to a Number
203floor({expr}) Float round {expr} down
204fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
205fnameescape({fname}) String escape special characters in {fname}
206fnamemodify({fname}, {mods}) String modify file name
207foldclosed({lnum}) Number first line of fold at {lnum} if closed
208foldclosedend({lnum}) Number last line of fold at {lnum} if closed
209foldlevel({lnum}) Number fold level at {lnum}
210foldtext() String line displayed for closed fold
211foldtextresult({lnum}) String text for closed fold at {lnum}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100212foreach({expr1}, {expr2}) List/Tuple/Dict/Blob/String
Ernie Raele79e2072024-01-13 11:47:33 +0100213 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100215fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000216funcref({name} [, {arglist}] [, {dict}])
217 Funcref reference to function {name}
218function({name} [, {arglist}] [, {dict}])
219 Funcref named reference to function {name}
220garbagecollect([{atexit}]) none free memory, breaking cyclic references
221get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
222get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
223get({func}, {what}) any get property of funcref/partial {func}
224getbufinfo([{buf}]) List information about buffers
225getbufline({buf}, {lnum} [, {end}])
226 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000227getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000228getbufvar({buf}, {varname} [, {def}])
229 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100230getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000231getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100233getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000234 get one character from the user
235getcharmod() Number modifiers for the last typed character
236getcharpos({expr}) List position of cursor, mark, etc.
237getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100238getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200239getcmdcomplpat() String return the completion pattern of the
240 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100241getcmdcompltype() String return the type of the current
242 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000244getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200245getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100246getcmdscreenpos() Number return cursor screen position in
247 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000248getcmdtype() String return current command-line type
249getcmdwintype() String return current command-line window type
250getcompletion({pat}, {type} [, {filtered}])
251 List list of cmdline completion matches
252getcurpos([{winnr}]) List position of the cursor
253getcursorcharpos([{winnr}]) List character position of the cursor
254getcwd([{winnr} [, {tabnr}]]) String get the current working directory
255getenv({name}) String return environment variable
256getfontname([{name}]) String name of font being used
257getfperm({fname}) String file permissions of file {fname}
258getfsize({fname}) Number size in bytes of file {fname}
259getftime({fname}) Number last modification time of file
260getftype({fname}) String description of type of file {fname}
261getimstatus() Number |TRUE| if the IME status is active
262getjumplist([{winnr} [, {tabnr}]])
263 List list of jump list items
264getline({lnum}) String line {lnum} of current buffer
265getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
266getloclist({nr}) List list of location list items
267getloclist({nr}, {what}) Dict get specific location list properties
268getmarklist([{buf}]) List list of global/local marks
269getmatches([{win}]) List list of current matches
270getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000271getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000272getpid() Number process ID of Vim
273getpos({expr}) List position of cursor, mark, etc.
274getqflist() List list of quickfix items
275getqflist({what}) Dict get specific quickfix list properties
276getreg([{regname} [, 1 [, {list}]]])
277 String or List contents of a register
278getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100279getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100280 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200281getregionpos({pos1}, {pos2} [, {opts}])
282 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000283getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100284getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100285getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000286gettabinfo([{expr}]) List list of tab pages
287gettabvar({nr}, {varname} [, {def}])
288 any variable {varname} in tab {nr} or {def}
289gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
290 any {name} in {winnr} in tab page {tabnr}
291gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200292gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000294getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000295getwinposx() Number X coord in pixels of the Vim window
296getwinposy() Number Y coord in pixels of the Vim window
297getwinvar({nr}, {varname} [, {def}])
298 any variable {varname} in window {nr}
299glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
300 any expand file wildcards in {expr}
301glob2regpat({expr}) String convert a glob pat into a search pat
302globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
303 String do glob({expr}) for all dirs in {path}
304has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
305has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
306haslocaldir([{winnr} [, {tabnr}]])
307 Number |TRUE| if the window executed |:lcd|
308 or |:tcd|
309hasmapto({what} [, {mode} [, {abbr}]])
310 Number |TRUE| if mapping to {what} exists
311histadd({history}, {item}) Number add an item to a history
312histdel({history} [, {item}]) Number remove an item from a history
313histget({history} [, {index}]) String get the item {index} from a history
314histnr({history}) Number highest index of a history
315hlID({name}) Number syntax ID of highlight group {name}
316hlexists({name}) Number |TRUE| if highlight group {name} exists
317hlget([{name} [, {resolve}]]) List get highlight group attributes
318hlset({list}) Number set highlight group attributes
319hostname() String name of the machine Vim is running on
320iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200321id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000322indent({lnum}) Number indent of line {lnum}
323index({object}, {expr} [, {start} [, {ic}]])
324 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100325indexof({object}, {expr} [, {opts}]])
326 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000327input({prompt} [, {text} [, {completion}]])
328 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100329inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000330 String like input() but in a GUI dialog
331inputlist({textlist}) Number let the user pick from a choice list
332inputrestore() Number restore typeahead
333inputsave() Number save and clear typeahead
334inputsecret({prompt} [, {text}]) String like input() but hiding the text
335insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200336instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000337interrupt() none interrupt script execution
338invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100339isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000340isdirectory({directory}) Number |TRUE| if {directory} is a directory
341isinf({expr}) Number determine if {expr} is infinity value
342 (positive or negative)
343islocked({expr}) Number |TRUE| if {expr} is locked
344isnan({expr}) Number |TRUE| if {expr} is NaN
345items({dict}) List key-value pairs in {dict}
346job_getchannel({job}) Channel get the channel handle for {job}
347job_info([{job}]) Dict get information about {job}
348job_setoptions({job}, {options}) none set options for {job}
349job_start({command} [, {options}])
350 Job start a job
351job_status({job}) String get the status of {job}
352job_stop({job} [, {how}]) Number stop {job}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100353join({expr} [, {sep}]) String join items in {expr} into one String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000354js_decode({string}) any decode JS style JSON
355js_encode({expr}) String encode JS style JSON
356json_decode({string}) any decode JSON
357json_encode({expr}) String encode JSON
358keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100359keytrans({string}) String translate internal keycodes to a form
360 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000361len({expr}) Number the length of {expr}
362libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
363libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
364line({expr} [, {winid}]) Number line nr of cursor, last line or mark
365line2byte({lnum}) Number byte count of line {lnum}
366lispindent({lnum}) Number Lisp indent for line {lnum}
367list2blob({list}) Blob turn {list} of numbers into a Blob
368list2str({list} [, {utf8}]) String turn {list} of numbers into a String
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100369list2tuple({list}) Tuple turn {list} of items into a tuple
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000370listener_add({callback} [, {buf}])
371 Number add a callback to listen to changes
372listener_flush([{buf}]) none invoke listener callbacks
373listener_remove({id}) none remove a listener callback
374localtime() Number current time
375log({expr}) Float natural logarithm (base e) of {expr}
376log10({expr}) Float logarithm of Float {expr} to base 10
377luaeval({expr} [, {expr}]) any evaluate |Lua| expression
378map({expr1}, {expr2}) List/Dict/Blob/String
379 change each item in {expr1} to {expr2}
380maparg({name} [, {mode} [, {abbr} [, {dict}]]])
381 String or Dict
382 rhs of mapping {name} in mode {mode}
383mapcheck({name} [, {mode} [, {abbr}]])
384 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100385maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000386mapnew({expr1}, {expr2}) List/Dict/Blob/String
387 like |map()| but creates a new List or
388 Dictionary
389mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
390match({expr}, {pat} [, {start} [, {count}]])
391 Number position where {pat} matches in {expr}
392matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
393 Number highlight {pattern} with {group}
394matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
395 Number highlight positions with {group}
396matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100397matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
398 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000399matchdelete({id} [, {win}]) Number delete match identified by {id}
400matchend({expr}, {pat} [, {start} [, {count}]])
401 Number position where {pat} ends in {expr}
402matchfuzzy({list}, {str} [, {dict}])
403 List fuzzy match {str} in {list}
404matchfuzzypos({list}, {str} [, {dict}])
405 List fuzzy match {str} in {list}
406matchlist({expr}, {pat} [, {start} [, {count}]])
407 List match and submatches of {pat} in {expr}
408matchstr({expr}, {pat} [, {start} [, {count}]])
409 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100410matchstrlist({list}, {pat} [, {dict})
411 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000412matchstrpos({expr}, {pat} [, {start} [, {count}]])
413 List {count}'th match of {pat} in {expr}
414max({expr}) Number maximum value of items in {expr}
415menu_info({name} [, {mode}]) Dict get menu item information
416min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000417mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000418 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200419mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000420mzeval({expr}) any evaluate |MzScheme| expression
421nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100422ngettext({single}, {plural}, {number}[, {domain}])
423 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000424nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
425or({expr}, {expr}) Number bitwise OR
426pathshorten({expr} [, {len}]) String shorten directory names in a path
427perleval({expr}) any evaluate |Perl| expression
428popup_atcursor({what}, {options}) Number create popup window near the cursor
429popup_beval({what}, {options}) Number create popup window for 'ballooneval'
430popup_clear() none close all popup windows
431popup_close({id} [, {result}]) none close popup window {id}
432popup_create({what}, {options}) Number create a popup window
433popup_dialog({what}, {options}) Number create a popup window used as a dialog
434popup_filter_menu({id}, {key}) Number filter for a menu popup window
435popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100436popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000437popup_findinfo() Number get window ID of info popup window
438popup_findpreview() Number get window ID of preview popup window
439popup_getoptions({id}) Dict get options of popup window {id}
440popup_getpos({id}) Dict get position of popup window {id}
441popup_hide({id}) none hide popup menu {id}
442popup_list() List get a list of window IDs of all popups
443popup_locate({row}, {col}) Number get window ID of popup at position
444popup_menu({what}, {options}) Number create a popup window used as a menu
445popup_move({id}, {options}) none set position of popup window {id}
446popup_notification({what}, {options})
447 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200448popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000449popup_setoptions({id}, {options})
450 none set options for popup window {id}
451popup_settext({id}, {text}) none set the text of popup window {id}
452popup_show({id}) none unhide popup window {id}
453pow({x}, {y}) Float {x} to the power of {y}
454prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
455printf({fmt}, {expr1}...) String format text
456prompt_getprompt({buf}) String get prompt text
457prompt_setcallback({buf}, {expr}) none set prompt callback function
458prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
459prompt_setprompt({buf}, {text}) none set prompt text
460prop_add({lnum}, {col}, {props}) none add one text property
461prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
462 none add multiple text properties
463prop_clear({lnum} [, {lnum-end} [, {props}]])
464 none remove all text properties
465prop_find({props} [, {direction}])
466 Dict search for a text property
467prop_list({lnum} [, {props}]) List text properties in {lnum}
468prop_remove({props} [, {lnum} [, {lnum-end}]])
469 Number remove a text property
470prop_type_add({name}, {props}) none define a new property type
471prop_type_change({name}, {props})
472 none change an existing property type
473prop_type_delete({name} [, {props}])
474 none delete a property type
475prop_type_get({name} [, {props}])
476 Dict get property type values
477prop_type_list([{props}]) List get list of property types
478pum_getpos() Dict position and size of pum if visible
479pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100480py3eval({expr} [, {locals}]) any evaluate |python3| expression
481pyeval({expr} [, {locals}]) any evaluate |Python| expression
482pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000483rand([{expr}]) Number get pseudo-random number
484range({expr} [, {max} [, {stride}]])
485 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100486readblob({fname} [, {offset} [, {size}]])
487 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000488readdir({dir} [, {expr} [, {dict}]])
489 List file names in {dir} selected by {expr}
490readdirex({dir} [, {expr} [, {dict}]])
491 List file info in {dir} selected by {expr}
492readfile({fname} [, {type} [, {max}]])
493 List get list of lines from file {fname}
494reduce({object}, {func} [, {initial}])
495 any reduce {object} using {func}
496reg_executing() String get the executing register name
497reg_recording() String get the recording register name
498reltime([{start} [, {end}]]) List get time value
499reltimefloat({time}) Float turn the time value into a Float
500reltimestr({time}) String turn time value into a String
501remote_expr({server}, {string} [, {idvar} [, {timeout}]])
502 String send expression
503remote_foreground({server}) Number bring Vim server to the foreground
504remote_peek({serverid} [, {retvar}])
505 Number check for reply string
506remote_read({serverid} [, {timeout}])
507 String read reply string
508remote_send({server}, {string} [, {idvar}])
509 String send key sequence
510remote_startserver({name}) none become server {name}
511remove({list}, {idx} [, {end}]) any/List
512 remove items {idx}-{end} from {list}
513remove({blob}, {idx} [, {end}]) Number/Blob
514 remove bytes {idx}-{end} from {blob}
515remove({dict}, {key}) any remove entry {key} from {dict}
516rename({from}, {to}) Number rename (move) file from {from} to {to}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100517repeat({expr}, {count}) List/Tuple/Blob/String
Bakudankun375141e2022-09-09 18:46:47 +0100518 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000519resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100520reverse({obj}) List/Tuple/Blob/String
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100521 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000522round({expr}) Float round off {expr}
523rubyeval({expr}) any evaluate |Ruby| expression
524screenattr({row}, {col}) Number attribute at screen position
525screenchar({row}, {col}) Number character at screen position
526screenchars({row}, {col}) List List of characters at screen position
527screencol() Number current cursor column
528screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
529screenrow() Number current cursor row
530screenstring({row}, {col}) String characters at screen position
531search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
532 Number search for {pattern}
533searchcount([{options}]) Dict get or update search stats
534searchdecl({name} [, {global} [, {thisblock}]])
535 Number search for variable declaration
536searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
537 Number search for other end of start/end pair
538searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
539 List search for other end of start/end pair
540searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
541 List search for {pattern}
542server2client({clientid}, {string})
543 Number send reply string
544serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700545setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000546 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700547 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000548setbufvar({buf}, {varname}, {val})
549 none set {varname} in buffer {buf} to {val}
550setcellwidths({list}) none set character cell width overrides
551setcharpos({expr}, {list}) Number set the {expr} position to {list}
552setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100553setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000554setcmdpos({pos}) Number set cursor position in command-line
555setcursorcharpos({list}) Number move cursor to position in {list}
556setenv({name}, {val}) none set environment variable
557setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
558setline({lnum}, {line}) Number set line {lnum} to {line}
559setloclist({nr}, {list} [, {action}])
560 Number modify location list using {list}
561setloclist({nr}, {list}, {action}, {what})
562 Number modify specific location list props
563setmatches({list} [, {win}]) Number restore a list of matches
564setpos({expr}, {list}) Number set the {expr} position to {list}
565setqflist({list} [, {action}]) Number modify quickfix list using {list}
566setqflist({list}, {action}, {what})
567 Number modify specific quickfix list props
568setreg({n}, {v} [, {opt}]) Number set register to value and type
569settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
570settabwinvar({tabnr}, {winnr}, {varname}, {val})
571 none set {varname} in window {winnr} in tab
572 page {tabnr} to {val}
573settagstack({nr}, {dict} [, {action}])
574 Number modify tag stack using {dict}
575setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
576sha256({string}) String SHA256 checksum of {string}
577shellescape({string} [, {special}])
578 String escape {string} for use as shell
579 command argument
580shiftwidth([{col}]) Number effective value of 'shiftwidth'
581sign_define({name} [, {dict}]) Number define or update a sign
582sign_define({list}) List define or update a list of signs
583sign_getdefined([{name}]) List get a list of defined signs
584sign_getplaced([{buf} [, {dict}]])
585 List get a list of placed signs
586sign_jump({id}, {group}, {buf})
587 Number jump to a sign
588sign_place({id}, {group}, {name}, {buf} [, {dict}])
589 Number place a sign
590sign_placelist({list}) List place a list of signs
591sign_undefine([{name}]) Number undefine a sign
592sign_undefine({list}) List undefine a list of signs
593sign_unplace({group} [, {dict}])
594 Number unplace a sign
595sign_unplacelist({list}) List unplace a list of signs
596simplify({filename}) String simplify filename as much as possible
597sin({expr}) Float sine of {expr}
598sinh({expr}) Float hyperbolic sine of {expr}
599slice({expr}, {start} [, {end}]) String, List or Blob
600 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000601sort({list} [, {how} [, {dict}]])
602 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000603sound_clear() none stop playing all sounds
604sound_playevent({name} [, {callback}])
605 Number play an event sound
606sound_playfile({path} [, {callback}])
607 Number play sound file {path}
608sound_stop({id}) none stop playing sound {id}
609soundfold({word}) String sound-fold {word}
610spellbadword() String badly spelled word at cursor
611spellsuggest({word} [, {max} [, {capital}]])
612 List spelling suggestions
613split({expr} [, {pat} [, {keepempty}]])
614 List make |List| from {pat} separated {expr}
615sqrt({expr}) Float square root of {expr}
616srand([{expr}]) List get seed for |rand()|
617state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100618str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000619str2float({expr} [, {quoted}]) Float convert String to Float
620str2list({expr} [, {utf8}]) List convert each character of {expr} to
621 ASCII/UTF-8 value
622str2nr({expr} [, {base} [, {quoted}]])
623 Number convert String to Number
624strcharlen({expr}) Number character length of the String {expr}
625strcharpart({str}, {start} [, {len} [, {skipcc}]])
626 String {len} characters of {str} at
627 character {start}
628strchars({expr} [, {skipcc}]) Number character count of the String {expr}
629strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
630strftime({format} [, {time}]) String format time with a specified format
631strgetchar({str}, {index}) Number get char {index} from {str}
632stridx({haystack}, {needle} [, {start}])
633 Number index of {needle} in {haystack}
634string({expr}) String String representation of {expr} value
635strlen({expr}) Number length of the String {expr}
636strpart({str}, {start} [, {len} [, {chars}]])
637 String {len} bytes/chars of {str} at
638 byte {start}
639strptime({format}, {timestring})
640 Number Convert {timestring} to unix timestamp
641strridx({haystack}, {needle} [, {start}])
642 Number last index of {needle} in {haystack}
643strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100644strutf16len({string} [, {countcc}])
645 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000646strwidth({expr}) Number display cell length of the String {expr}
647submatch({nr} [, {list}]) String or List
648 specific match in ":s" or substitute()
649substitute({expr}, {pat}, {sub}, {flags})
650 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000651swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000652swapinfo({fname}) Dict information about swap file {fname}
653swapname({buf}) String swap file of buffer {buf}
654synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
655synIDattr({synID}, {what} [, {mode}])
656 String attribute {what} of syntax ID {synID}
657synIDtrans({synID}) Number translated syntax ID of {synID}
658synconcealed({lnum}, {col}) List info about concealing
659synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
660system({expr} [, {input}]) String output of shell command/filter {expr}
661systemlist({expr} [, {input}]) List output of shell command/filter {expr}
662tabpagebuflist([{arg}]) List list of buffer numbers in tab page
663tabpagenr([{arg}]) Number number of current or last tab page
664tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
665tagfiles() List tags files used
666taglist({expr} [, {filename}]) List list of tags matching {expr}
667tan({expr}) Float tangent of {expr}
668tanh({expr}) Float hyperbolic tangent of {expr}
669tempname() String name for a temporary file
670term_dumpdiff({filename}, {filename} [, {options}])
671 Number display difference between two dumps
672term_dumpload({filename} [, {options}])
673 Number displaying a screen dump
674term_dumpwrite({buf}, {filename} [, {options}])
675 none dump terminal window contents
676term_getaltscreen({buf}) Number get the alternate screen flag
677term_getansicolors({buf}) List get ANSI palette in GUI color mode
678term_getattr({attr}, {what}) Number get the value of attribute {what}
679term_getcursor({buf}) List get the cursor position of a terminal
680term_getjob({buf}) Job get the job associated with a terminal
681term_getline({buf}, {row}) String get a line of text from a terminal
682term_getscrolled({buf}) Number get the scroll count of a terminal
683term_getsize({buf}) List get the size of a terminal
684term_getstatus({buf}) String get the status of a terminal
685term_gettitle({buf}) String get the title of a terminal
686term_gettty({buf}, [{input}]) String get the tty name of a terminal
687term_list() List get the list of terminal buffers
688term_scrape({buf}, {row}) List get row of a terminal screen
689term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
690term_setansicolors({buf}, {colors})
691 none set ANSI palette in GUI color mode
692term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
693term_setkill({buf}, {how}) none set signal to stop job in terminal
694term_setrestore({buf}, {command}) none set command to restore terminal
695term_setsize({buf}, {rows}, {cols})
696 none set the size of a terminal
697term_start({cmd} [, {options}]) Number open a terminal window and run a job
698term_wait({buf} [, {time}]) Number wait for screen to be updated
699terminalprops() Dict properties of the terminal
700test_alloc_fail({id}, {countdown}, {repeat})
701 none make memory allocation fail
702test_autochdir() none enable 'autochdir' during startup
703test_feedinput({string}) none add key sequence to input buffer
704test_garbagecollect_now() none free memory right now for testing
705test_garbagecollect_soon() none free memory soon for testing
706test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000707test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000709test_mswin_event({event}, {args})
710 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000711test_null_blob() Blob null value for testing
712test_null_channel() Channel null value for testing
713test_null_dict() Dict null value for testing
714test_null_function() Funcref null value for testing
715test_null_job() Job null value for testing
716test_null_list() List null value for testing
717test_null_partial() Funcref null value for testing
718test_null_string() String null value for testing
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100719test_null_tuple() Tuple null value for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000720test_option_not_set({name}) none reset flag indicating option was set
721test_override({expr}, {val}) none test with Vim internal overrides
722test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000723test_setmouse({row}, {col}) none set the mouse position for testing
724test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200725test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000726test_unknown() any unknown value for testing
727test_void() any void value for testing
728timer_info([{id}]) List information about timers
729timer_pause({id}, {pause}) none pause or unpause a timer
730timer_start({time}, {callback} [, {options}])
731 Number create a timer
732timer_stop({timer}) none stop a timer
733timer_stopall() none stop all timers
734tolower({expr}) String the String {expr} switched to lowercase
735toupper({expr}) String the String {expr} switched to uppercase
736tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
737 to chars in {tostr}
738trim({text} [, {mask} [, {dir}]])
739 String trim characters in {mask} from {text}
740trunc({expr}) Float truncate Float {expr}
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +0100741tuple2list({tuple}) List turn {tuple} of items into a list
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000742type({expr}) Number type of value {expr}
743typename({expr}) String representation of the type of {expr}
744undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500745undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000746uniq({list} [, {func} [, {dict}]])
747 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100748utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
749 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000750values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200751virtcol({expr} [, {list} [, {winid}])
752 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100753 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100754virtcol2col({winid}, {lnum}, {col})
755 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200756visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000757wildmenumode() Number whether 'wildmenu' mode is active
758win_execute({id}, {command} [, {silent}])
759 String execute {command} in window {id}
760win_findbuf({bufnr}) List find windows containing {bufnr}
761win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
762win_gettype([{nr}]) String type of window {nr}
763win_gotoid({expr}) Number go to window with ID {expr}
764win_id2tabwin({expr}) List get tab and window nr from window ID
765win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000766win_move_separator({nr}) Number move window vertical separator
767win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000768win_screenpos({nr}) List get screen position of window {nr}
769win_splitmove({nr}, {target} [, {options}])
770 Number move window {nr} to split of {target}
771winbufnr({nr}) Number buffer number of window {nr}
772wincol() Number window column of the cursor
773windowsversion() String MS-Windows OS version
774winheight({nr}) Number height of window {nr}
775winlayout([{tabnr}]) List layout of windows in tab {tabnr}
776winline() Number window line of the cursor
777winnr([{expr}]) Number number of current window
778winrestcmd() String returns command to restore window sizes
779winrestview({dict}) none restore view of current window
780winsaveview() Dict save view of current window
781winwidth({nr}) Number width of window {nr}
782wordcount() Dict get byte/char/word statistics
783writefile({object}, {fname} [, {flags}])
784 Number write |Blob| or |List| of lines to file
785xor({expr}, {expr}) Number bitwise XOR
786
787==============================================================================
7882. Details *builtin-function-details*
789
790Not all functions are here, some have been moved to a help file covering the
791specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200792Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000793
794abs({expr}) *abs()*
795 Return the absolute value of {expr}. When {expr} evaluates to
796 a |Float| abs() returns a |Float|. When {expr} can be
797 converted to a |Number| abs() returns a |Number|. Otherwise
798 abs() gives an error message and returns -1.
799 Examples: >
800 echo abs(1.456)
801< 1.456 >
802 echo abs(-5.456)
803< 5.456 >
804 echo abs(-4)
805< 4
806
807 Can also be used as a |method|: >
808 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200809<
810 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812
813acos({expr}) *acos()*
814 Return the arc cosine of {expr} measured in radians, as a
815 |Float| in the range of [0, pi].
816 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100817 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000818 Examples: >
819 :echo acos(0)
820< 1.570796 >
821 :echo acos(-0.5)
822< 2.094395
823
824 Can also be used as a |method|: >
825 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200826<
827 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000829
830add({object}, {expr}) *add()*
831 Append the item {expr} to |List| or |Blob| {object}. Returns
832 the resulting |List| or |Blob|. Examples: >
833 :let alist = add([1, 2, 3], item)
834 :call add(mylist, "woodstock")
835< Note that when {expr} is a |List| it is appended as a single
836 item. Use |extend()| to concatenate |Lists|.
837 When {object} is a |Blob| then {expr} must be a number.
838 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100839 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000840
841 Can also be used as a |method|: >
842 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200843<
844 Return type: list<{type}> (depending on the given |List|) or
845 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846
847
848and({expr}, {expr}) *and()*
849 Bitwise AND on the two arguments. The arguments are converted
850 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100851 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000852 Example: >
853 :let flag = and(bits, 0x80)
854< Can also be used as a |method|: >
855 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200856<
857 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000858
859
860append({lnum}, {text}) *append()*
861 When {text} is a |List|: Append each item of the |List| as a
862 text line below line {lnum} in the current buffer.
863 Otherwise append {text} as one text line below line {lnum} in
864 the current buffer.
865 Any type of item is accepted and converted to a String.
866 {lnum} can be zero to insert a line before the first one.
867 {lnum} is used like with |getline()|.
868 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000869 0 for success. When {text} is an empty list zero is returned,
870 no matter the value of {lnum}.
871 In |Vim9| script an invalid argument or negative number
872 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000873 :let failed = append(line('$'), "# THE END")
874 :let failed = append(0, ["Chapter 1", "the beginning"])
875
876< Can also be used as a |method| after a List, the base is
877 passed as the second argument: >
878 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200879<
880 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000881
882
883appendbufline({buf}, {lnum}, {text}) *appendbufline()*
884 Like |append()| but append the text in buffer {buf}.
885
886 This function works only for loaded buffers. First call
887 |bufload()| if needed.
888
889 For the use of {buf}, see |bufname()|.
890
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000891 {lnum} is the line number to append below. Note that using
892 |line()| would use the current buffer, not the one appending
893 to. Use "$" to append at the end of the buffer. Other string
894 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000895
896 On success 0 is returned, on failure 1 is returned.
897 In |Vim9| script an error is given for an invalid {lnum}.
898
899 If {buf} is not a valid buffer or {lnum} is not valid, an
900 error message is given. Example: >
901 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000902< However, when {text} is an empty list then no error is given
903 for an invalid {lnum}, since {lnum} isn't actually used.
904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905 Can also be used as a |method| after a List, the base is
906 passed as the second argument: >
907 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200908<
909 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000910
911
912argc([{winid}]) *argc()*
913 The result is the number of files in the argument list. See
914 |arglist|.
915 If {winid} is not supplied, the argument list of the current
916 window is used.
917 If {winid} is -1, the global argument list is used.
918 Otherwise {winid} specifies the window of which the argument
919 list is used: either the window number or the window ID.
920 Returns -1 if the {winid} argument is invalid.
921
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200922 Return type: |Number|
923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924 *argidx()*
925argidx() The result is the current index in the argument list. 0 is
926 the first file. argc() - 1 is the last one. See |arglist|.
927
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200928 Return type: |Number|
929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000930 *arglistid()*
931arglistid([{winnr} [, {tabnr}]])
932 Return the argument list ID. This is a number which
933 identifies the argument list being used. Zero is used for the
934 global argument list. See |arglist|.
935 Returns -1 if the arguments are invalid.
936
937 Without arguments use the current window.
938 With {winnr} only use this window in the current tab page.
939 With {winnr} and {tabnr} use the window in the specified tab
940 page.
941 {winnr} can be the window number or the |window-ID|.
942
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200943 Return type: |Number|
944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000945 *argv()*
946argv([{nr} [, {winid}]])
947 The result is the {nr}th file in the argument list. See
948 |arglist|. "argv(0)" is the first one. Example: >
949 :let i = 0
950 :while i < argc()
951 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000952 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000953 : let i = i + 1
954 :endwhile
955< Without the {nr} argument, or when {nr} is -1, a |List| with
956 the whole |arglist| is returned.
957
958 The {winid} argument specifies the window ID, see |argc()|.
959 For the Vim command line arguments see |v:argv|.
960
Bram Moolenaar016188f2022-06-06 20:52:59 +0100961 Returns an empty string if {nr}th argument is not present in
962 the argument list. Returns an empty List if the {winid}
963 argument is invalid.
964
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200965 Return type: |String|
966
967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000968asin({expr}) *asin()*
969 Return the arc sine of {expr} measured in radians, as a |Float|
970 in the range of [-pi/2, pi/2].
971 {expr} must evaluate to a |Float| or a |Number| in the range
972 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100973 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
974 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000975 Examples: >
976 :echo asin(0.8)
977< 0.927295 >
978 :echo asin(-0.5)
979< -0.523599
980
981 Can also be used as a |method|: >
982 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200983<
984 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000985
986assert_ functions are documented here: |assert-functions-details|
987
988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000989atan({expr}) *atan()*
990 Return the principal value of the arc tangent of {expr}, in
991 the range [-pi/2, +pi/2] radians, as a |Float|.
992 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100993 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000994 Examples: >
995 :echo atan(100)
996< 1.560797 >
997 :echo atan(-4.01)
998< -1.326405
999
1000 Can also be used as a |method|: >
1001 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001002<
1003 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001004
1005
1006atan2({expr1}, {expr2}) *atan2()*
1007 Return the arc tangent of {expr1} / {expr2}, measured in
1008 radians, as a |Float| in the range [-pi, pi].
1009 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001010 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1011 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001012 Examples: >
1013 :echo atan2(-1, 1)
1014< -0.785398 >
1015 :echo atan2(1, -1)
1016< 2.356194
1017
1018 Can also be used as a |method|: >
1019 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001020<
1021 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001022
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001023
1024autocmd_add({acmds}) *autocmd_add()*
1025 Adds a List of autocmds and autocmd groups.
1026
1027 The {acmds} argument is a List where each item is a Dict with
1028 the following optional items:
1029 bufnr buffer number to add a buffer-local autocmd.
1030 If this item is specified, then the "pattern"
1031 item is ignored.
1032 cmd Ex command to execute for this autocmd event
1033 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001034 This can be either a String with a single
1035 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001036 group autocmd group name. Refer to |autocmd-groups|.
1037 If this group doesn't exist then it is
1038 created. If not specified or empty, then the
1039 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001040 nested boolean flag, set to v:true to add a nested
1041 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001042 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001043 which executes only once. Refer to
1044 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001045 pattern autocmd pattern string. Refer to
1046 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001047 present, then this item is ignored. This can
1048 be a String with a single pattern or a List of
1049 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001050 replace boolean flag, set to v:true to remove all the
1051 commands associated with the specified autocmd
1052 event and group and add the {cmd}. This is
1053 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001054 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001055
1056 Returns v:true on success and v:false on failure.
1057 Examples: >
1058 " Create a buffer-local autocmd for buffer 5
1059 let acmd = {}
1060 let acmd.group = 'MyGroup'
1061 let acmd.event = 'BufEnter'
1062 let acmd.bufnr = 5
1063 let acmd.cmd = 'call BufEnterFunc()'
1064 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001065<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001066 Can also be used as a |method|: >
1067 GetAutocmdList()->autocmd_add()
1068<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001069 Return type: |vim9-boolean|
1070
1071
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001072autocmd_delete({acmds}) *autocmd_delete()*
1073 Deletes a List of autocmds and autocmd groups.
1074
1075 The {acmds} argument is a List where each item is a Dict with
1076 the following optional items:
1077 bufnr buffer number to delete a buffer-local autocmd.
1078 If this item is specified, then the "pattern"
1079 item is ignored.
1080 cmd Ex command for this autocmd event
1081 event autocmd event name. Refer to |autocmd-events|.
1082 If '*' then all the autocmd events in this
1083 group are deleted.
1084 group autocmd group name. Refer to |autocmd-groups|.
1085 If not specified or empty, then the default
1086 group is used.
1087 nested set to v:true for a nested autocmd.
1088 Refer to |autocmd-nested|.
1089 once set to v:true for an autocmd which executes
1090 only once. Refer to |autocmd-once|.
1091 pattern autocmd pattern string. Refer to
1092 |autocmd-patterns|. If "bufnr" item is
1093 present, then this item is ignored.
1094
1095 If only {group} is specified in a {acmds} entry and {event},
1096 {pattern} and {cmd} are not specified, then that autocmd group
1097 is deleted.
1098
Bram Moolenaar016188f2022-06-06 20:52:59 +01001099 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001100 Examples: >
1101 " :autocmd! BufLeave *.vim
1102 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1103 call autocmd_delete([acmd]})
1104 " :autocmd! MyGroup1 BufLeave
1105 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1106 call autocmd_delete([acmd])
1107 " :autocmd! MyGroup2 BufEnter *.c
1108 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1109 \ pattern: '*.c'}
1110 " :autocmd! MyGroup2 * *.c
1111 let acmd = #{group: 'MyGroup2', event: '*',
1112 \ pattern: '*.c'}
1113 call autocmd_delete([acmd])
1114 " :autocmd! MyGroup3
1115 let acmd = #{group: 'MyGroup3'}
1116 call autocmd_delete([acmd])
1117<
1118 Can also be used as a |method|: >
1119 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001120<
1121 Return type: |vim9-boolean|
1122
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001123
1124autocmd_get([{opts}]) *autocmd_get()*
1125 Returns a |List| of autocmds. If {opts} is not supplied, then
1126 returns the autocmds for all the events in all the groups.
1127
1128 The optional {opts} Dict argument supports the following
1129 items:
1130 group Autocmd group name. If specified, returns only
1131 the autocmds defined in this group. If the
1132 specified group doesn't exist, results in an
1133 error message. If set to an empty string,
1134 then the default autocmd group is used.
1135 event Autocmd event name. If specified, returns only
1136 the autocmds defined for this event. If set
1137 to "*", then returns autocmds for all the
1138 events. If the specified event doesn't exist,
1139 results in an error message.
1140 pattern Autocmd pattern. If specified, returns only
1141 the autocmds defined for this pattern.
1142 A combination of the above three times can be supplied in
1143 {opts}.
1144
1145 Each Dict in the returned List contains the following items:
1146 bufnr For buffer-local autocmds, buffer number where
1147 the autocmd is defined.
1148 cmd Command executed for this autocmd.
1149 event Autocmd event name.
1150 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001151 nested Boolean flag, set to v:true for a nested
1152 autocmd. See |autocmd-nested|.
1153 once Boolean flag, set to v:true, if the autocmd
1154 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001155 pattern Autocmd pattern. For a buffer-local
1156 autocmd, this will be of the form "<buffer=n>".
1157 If there are multiple commands for an autocmd event in a
1158 group, then separate items are returned for each command.
1159
Bram Moolenaar016188f2022-06-06 20:52:59 +01001160 Returns an empty List if an autocmd with the specified group
1161 or event or pattern is not found.
1162
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001163 Examples: >
1164 " :autocmd MyGroup
1165 echo autocmd_get(#{group: 'Mygroup'})
1166 " :autocmd G BufUnload
1167 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1168 " :autocmd G * *.ts
1169 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1170 echo autocmd_get(acmd)
1171 " :autocmd Syntax
1172 echo autocmd_get(#{event: 'Syntax'})
1173 " :autocmd G BufEnter *.ts
1174 let acmd = #{group: 'G', event: 'BufEnter',
1175 \ pattern: '*.ts'}
1176 echo autocmd_get(acmd)
1177<
1178 Can also be used as a |method|: >
1179 Getopts()->autocmd_get()
1180<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001181 Return type: list<dict<any>>
1182
1183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001184balloon_gettext() *balloon_gettext()*
1185 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001186 not used for the List. Returns an empty string if balloon
1187 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001188
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001189 Return type: |String|
1190
1191
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001192balloon_show({expr}) *balloon_show()*
1193 Show {expr} inside the balloon. For the GUI {expr} is used as
1194 a string. For a terminal {expr} can be a list, which contains
1195 the lines of the balloon. If {expr} is not a list it will be
1196 split with |balloon_split()|.
1197 If {expr} is an empty string any existing balloon is removed.
1198
1199 Example: >
1200 func GetBalloonContent()
1201 " ... initiate getting the content
1202 return ''
1203 endfunc
1204 set balloonexpr=GetBalloonContent()
1205
1206 func BalloonCallback(result)
1207 call balloon_show(a:result)
1208 endfunc
1209< Can also be used as a |method|: >
1210 GetText()->balloon_show()
1211<
1212 The intended use is that fetching the content of the balloon
1213 is initiated from 'balloonexpr'. It will invoke an
1214 asynchronous method, in which a callback invokes
1215 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001216 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001217
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001218 When showing a balloon is not possible then nothing happens,
1219 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001220 {only available when compiled with the |+balloon_eval| or
1221 |+balloon_eval_term| feature}
1222
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001223 Return type: |Number|
1224
1225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001226balloon_split({msg}) *balloon_split()*
1227 Split String {msg} into lines to be displayed in a balloon.
1228 The splits are made for the current window size and optimize
1229 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001230 Returns a |List| with the split lines. Returns an empty List
1231 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001232 Can also be used as a |method|: >
1233 GetText()->balloon_split()->balloon_show()
1234
1235< {only available when compiled with the |+balloon_eval_term|
1236 feature}
1237
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001238 Return type: list<any> or list<string>
1239
h-easte80f3452025-01-02 10:40:29 +01001240base64_decode({string}) *base64_decode()*
1241 Return a Blob containing the bytes decoded from the base64
1242 encoded characters in {string}.
1243
1244 The {string} argument should contain only base64-encoded
1245 characters and should have a length that is a multiple of 4.
1246
1247 Returns an empty blob on error.
1248
1249 Examples: >
1250 " Write the decoded contents to a binary file
1251 call writefile(base64_decode(s), 'tools.bmp')
1252 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001253 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001254<
1255 Can also be used as a |method|: >
1256 GetEncodedString()->base64_decode()
1257<
1258 Return type: |Blob|
1259
1260
1261base64_encode({blob}) *base64_encode()*
1262 Return a base64-encoded String representing the bytes in
1263 {blob}. The base64 alphabet defined in RFC 4648 is used.
1264
1265 Examples: >
1266 " Encode the contents of a binary file
1267 echo base64_encode(readblob('somefile.bin'))
1268 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001269 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001270<
1271 Can also be used as a |method|: >
1272 GetBinaryData()->base64_encode()
1273<
1274 Return type: |String|
1275
1276
Christ van Willegence0ef912024-06-20 23:41:59 +02001277bindtextdomain({package}, {path}) *bindtextdomain()*
1278 Bind a specific {package} to a {path} so that the
1279 |gettext()| function can be used to get language-specific
1280 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001281 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001282
Christ van Willegen8252ef12024-07-11 21:36:21 +02001283 Returns v:true on success and v:false on failure (out of
1284 memory).
1285
1286 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001287
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001288blob2list({blob}) *blob2list()*
1289 Return a List containing the number value of each byte in Blob
1290 {blob}. Examples: >
1291 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1292 blob2list(0z) returns []
1293< Returns an empty List on error. |list2blob()| does the
1294 opposite.
1295
1296 Can also be used as a |method|: >
1297 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001299 Return type: list<any> or list<number>
1300
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001301
1302blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001303 Return a List of Strings in the current 'encoding' by
1304 converting the bytes in {blob} into characters.
1305
1306 Each <NL> byte in the blob is interpreted as the end of a
1307 string and a new list item is added. Each <NUL> byte in the
1308 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001309
1310 If {options} is not supplied, the current 'encoding' value is
1311 used to decode the bytes in {blob}.
1312
1313 The argument {options} is a |Dict| and supports the following
1314 items:
1315 encoding Decode the bytes in {blob} using this
1316 encoding. The value is a |String|. See
Bakudankunb3854bf2025-02-23 20:29:21 +01001317 |encoding-names| for the supported values
1318 (plus the special value "none").
Christian Brabandtd5afc742025-03-18 20:55:42 +01001319 *E1515* *E1516*
Bakudankunb3854bf2025-02-23 20:29:21 +01001320 When current 'encoding' is "utf-8", an error is given and an
1321 empty List is returned if an invalid byte sequence is
1322 encountered in {blob}. To suppress this validation and get
1323 potentially invalid string, set "encoding" in {options} to
1324 "none".
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001325
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001326 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001327
1328 See also |str2blob()|
1329
1330 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +01001331 blob2str(0z6162) returns ['ab']
1332 blob2str(0zC2ABC2BB) returns ['«»']
1333 blob2str(0z610A62) returns ['a', 'b']
1334 blob2str(0z610062) returns ['a\nb']
1335 blob2str(0zABBB, {'encoding': 'latin1'}) returns ['«»']
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001336<
1337 Can also be used as a |method|: >
1338 GetBlob()->blob2str()
1339<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001340 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001341
1342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001343 *browse()*
1344browse({save}, {title}, {initdir}, {default})
1345 Put up a file requester. This only works when "has("browse")"
1346 returns |TRUE| (only in some GUI versions).
1347 The input fields are:
1348 {save} when |TRUE|, select file to write
1349 {title} title for the requester
1350 {initdir} directory to start browsing in
1351 {default} default file name
1352 An empty string is returned when the "Cancel" button is hit,
1353 something went wrong, or browsing is not possible.
1354
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001355 Return type: |String|
1356
1357
1358browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001359 Put up a directory requester. This only works when
1360 "has("browse")" returns |TRUE| (only in some GUI versions).
1361 On systems where a directory browser is not supported a file
1362 browser is used. In that case: select a file in the directory
1363 to be used.
1364 The input fields are:
1365 {title} title for the requester
1366 {initdir} directory to start browsing in
1367 When the "Cancel" button is hit, something went wrong, or
1368 browsing is not possible, an empty string is returned.
1369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001370 Return type: |String|
1371
1372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001373bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001374 Add a buffer to the buffer list with name {name} (must be a
1375 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001376 If a buffer for file {name} already exists, return that buffer
1377 number. Otherwise return the buffer number of the newly
1378 created buffer. When {name} is an empty string then a new
1379 buffer is always created.
1380 The buffer will not have 'buflisted' set and not be loaded
1381 yet. To add some text to the buffer use this: >
1382 let bufnr = bufadd('someName')
1383 call bufload(bufnr)
1384 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001385< Returns 0 on error.
1386 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001387 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001388<
1389 Return type: |Number|
1390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001391
1392bufexists({buf}) *bufexists()*
1393 The result is a Number, which is |TRUE| if a buffer called
1394 {buf} exists.
1395 If the {buf} argument is a number, buffer numbers are used.
1396 Number zero is the alternate buffer for the current window.
1397
1398 If the {buf} argument is a string it must match a buffer name
1399 exactly. The name can be:
1400 - Relative to the current directory.
1401 - A full path.
1402 - The name of a buffer with 'buftype' set to "nofile".
1403 - A URL name.
1404 Unlisted buffers will be found.
1405 Note that help files are listed by their short name in the
1406 output of |:buffers|, but bufexists() requires using their
1407 long name to be able to find them.
1408 bufexists() may report a buffer exists, but to use the name
1409 with a |:buffer| command you may need to use |expand()|. Esp
1410 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1411 Use "bufexists(0)" to test for the existence of an alternate
1412 file name.
1413
1414 Can also be used as a |method|: >
1415 let exists = 'somename'->bufexists()
1416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417 Return type: |Number|
1418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001419 Obsolete name: buffer_exists(). *buffer_exists()*
1420
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001422buflisted({buf}) *buflisted()*
1423 The result is a Number, which is |TRUE| if a buffer called
1424 {buf} exists and is listed (has the 'buflisted' option set).
1425 The {buf} argument is used like with |bufexists()|.
1426
1427 Can also be used as a |method|: >
1428 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001429<
1430 Return type: |Number|
1431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001432
1433bufload({buf}) *bufload()*
1434 Ensure the buffer {buf} is loaded. When the buffer name
1435 refers to an existing file then the file is read. Otherwise
1436 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001437 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001438 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001439 If there is an existing swap file for the file of the buffer,
1440 there will be no dialog, the buffer will be loaded anyway.
1441 The {buf} argument is used like with |bufexists()|.
1442
1443 Can also be used as a |method|: >
1444 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001445<
1446 Return type: |Number|
1447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001448
1449bufloaded({buf}) *bufloaded()*
1450 The result is a Number, which is |TRUE| if a buffer called
1451 {buf} exists and is loaded (shown in a window or hidden).
1452 The {buf} argument is used like with |bufexists()|.
1453
1454 Can also be used as a |method|: >
1455 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001456<
1457 Return type: |Number|
1458
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001459
1460bufname([{buf}]) *bufname()*
1461 The result is the name of a buffer. Mostly as it is displayed
1462 by the `:ls` command, but not using special names such as
1463 "[No Name]".
1464 If {buf} is omitted the current buffer is used.
1465 If {buf} is a Number, that buffer number's name is given.
1466 Number zero is the alternate buffer for the current window.
1467 If {buf} is a String, it is used as a |file-pattern| to match
1468 with the buffer names. This is always done like 'magic' is
1469 set and 'cpoptions' is empty. When there is more than one
1470 match an empty string is returned.
1471 "" or "%" can be used for the current buffer, "#" for the
1472 alternate buffer.
1473 A full match is preferred, otherwise a match at the start, end
1474 or middle of the buffer name is accepted. If you only want a
1475 full match then put "^" at the start and "$" at the end of the
1476 pattern.
1477 Listed buffers are found first. If there is a single match
1478 with a listed buffer, that one is returned. Next unlisted
1479 buffers are searched for.
1480 If the {buf} is a String, but you want to use it as a buffer
1481 number, force it to be a Number by adding zero to it: >
1482 :echo bufname("3" + 0)
1483< Can also be used as a |method|: >
1484 echo bufnr->bufname()
1485
1486< If the buffer doesn't exist, or doesn't have a name, an empty
1487 string is returned. >
1488 bufname("#") alternate buffer name
1489 bufname(3) name of buffer 3
1490 bufname("%") name of current buffer
1491 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001492<
1493 Return type: |String|
1494 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001495 Obsolete name: buffer_name().
1496
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001497
1498bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001499 The result is the number of a buffer, as it is displayed by
1500 the `:ls` command. For the use of {buf}, see |bufname()|
1501 above.
1502
1503 If the buffer doesn't exist, -1 is returned. Or, if the
1504 {create} argument is present and TRUE, a new, unlisted,
1505 buffer is created and its number is returned. Example: >
1506 let newbuf = bufnr('Scratch001', 1)
1507< Using an empty name uses the current buffer. To create a new
1508 buffer with an empty name use |bufadd()|.
1509
1510 bufnr("$") is the last buffer: >
1511 :let last_buffer = bufnr("$")
1512< The result is a Number, which is the highest buffer number
1513 of existing buffers. Note that not all buffers with a smaller
1514 number necessarily exist, because ":bwipeout" may have removed
1515 them. Use bufexists() to test for the existence of a buffer.
1516
1517 Can also be used as a |method|: >
1518 echo bufref->bufnr()
1519<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001520 Return type: |Number|
1521
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522 Obsolete name: buffer_number(). *buffer_number()*
1523 *last_buffer_nr()*
1524 Obsolete name for bufnr("$"): last_buffer_nr().
1525
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001527bufwinid({buf}) *bufwinid()*
1528 The result is a Number, which is the |window-ID| of the first
1529 window associated with buffer {buf}. For the use of {buf},
1530 see |bufname()| above. If buffer {buf} doesn't exist or
1531 there is no such window, -1 is returned. Example: >
1532
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001533 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001534<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001535 Only deals with the current tab page. See |win_findbuf()| for
1536 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001537
1538 Can also be used as a |method|: >
1539 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001540<
1541 Return type: |Number|
1542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001543
1544bufwinnr({buf}) *bufwinnr()*
1545 Like |bufwinid()| but return the window number instead of the
1546 |window-ID|.
1547 If buffer {buf} doesn't exist or there is no such window, -1
1548 is returned. Example: >
1549
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001550 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001551
1552< The number can be used with |CTRL-W_w| and ":wincmd w"
1553 |:wincmd|.
1554
1555 Can also be used as a |method|: >
1556 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001557<
1558 Return type: |Number|
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560
1561byte2line({byte}) *byte2line()*
1562 Return the line number that contains the character at byte
1563 count {byte} in the current buffer. This includes the
1564 end-of-line character, depending on the 'fileformat' option
1565 for the current buffer. The first character has byte count
1566 one.
1567 Also see |line2byte()|, |go| and |:goto|.
1568
Bram Moolenaar016188f2022-06-06 20:52:59 +01001569 Returns -1 if the {byte} value is invalid.
1570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001571 Can also be used as a |method|: >
1572 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001573<
1574 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001576 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001577 feature}
1578
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001579
Christian Brabandt67672ef2023-04-24 21:09:54 +01001580byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581 Return byte index of the {nr}'th character in the String
1582 {expr}. Use zero for the first character, it then returns
1583 zero.
1584 If there are no multibyte characters the returned value is
1585 equal to {nr}.
1586 Composing characters are not counted separately, their byte
1587 length is added to the preceding base character. See
1588 |byteidxcomp()| below for counting composing characters
1589 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001590 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1591 index in the String {expr} instead of as the character index.
1592 The UTF-16 index is the index in the string when it is encoded
1593 with 16-bit words. If the specified UTF-16 index is in the
1594 middle of a character (e.g. in a 4-byte character), then the
1595 byte index of the first byte in the character is returned.
1596 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001597 Example : >
1598 echo matchstr(str, ".", byteidx(str, 3))
1599< will display the fourth character. Another way to do the
1600 same: >
1601 let s = strpart(str, byteidx(str, 3))
1602 echo strpart(s, 0, byteidx(s, 1))
1603< Also see |strgetchar()| and |strcharpart()|.
1604
1605 If there are less than {nr} characters -1 is returned.
1606 If there are exactly {nr} characters the length of the string
1607 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001608 See |charidx()| and |utf16idx()| for getting the character and
1609 UTF-16 index respectively from the byte index.
1610 Examples: >
1611 echo byteidx('a😊😊', 2) returns 5
1612 echo byteidx('a😊😊', 2, 1) returns 1
1613 echo byteidx('a😊😊', 3, 1) returns 5
1614<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001615 Can also be used as a |method|: >
1616 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001617<
1618 Return type: |Number|
1619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001620
Christian Brabandt67672ef2023-04-24 21:09:54 +01001621byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001622 Like byteidx(), except that a composing character is counted
1623 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001624 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001625 echo byteidx(s, 1)
1626 echo byteidxcomp(s, 1)
1627 echo byteidxcomp(s, 2)
1628< The first and third echo result in 3 ('e' plus composing
1629 character is 3 bytes), the second echo results in 1 ('e' is
1630 one byte).
1631 Only works differently from byteidx() when 'encoding' is set
1632 to a Unicode encoding.
1633
1634 Can also be used as a |method|: >
1635 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001636<
1637 Return type: |Number|
1638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001639
1640call({func}, {arglist} [, {dict}]) *call()* *E699*
1641 Call function {func} with the items in |List| {arglist} as
1642 arguments.
1643 {func} can either be a |Funcref| or the name of a function.
1644 a:firstline and a:lastline are set to the cursor line.
1645 Returns the return value of the called function.
1646 {dict} is for functions with the "dict" attribute. It will be
1647 used to set the local variable "self". |Dictionary-function|
1648
1649 Can also be used as a |method|: >
1650 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001651<
1652 Return type: any, depending on {func}
1653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001654
1655ceil({expr}) *ceil()*
1656 Return the smallest integral value greater than or equal to
1657 {expr} as a |Float| (round up).
1658 {expr} must evaluate to a |Float| or a |Number|.
1659 Examples: >
1660 echo ceil(1.456)
1661< 2.0 >
1662 echo ceil(-5.456)
1663< -5.0 >
1664 echo ceil(4.0)
1665< 4.0
1666
Bram Moolenaar016188f2022-06-06 20:52:59 +01001667 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001669 Can also be used as a |method|: >
1670 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001671<
1672 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
1674
1675ch_ functions are documented here: |channel-functions-details|
1676
1677
1678changenr() *changenr()*
1679 Return the number of the most recent change. This is the same
1680 number as what is displayed with |:undolist| and can be used
1681 with the |:undo| command.
1682 When a change was made it is the number of that change. After
1683 redo it is the number of the redone change. After undo it is
1684 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001685 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001686
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001687 Return type: |Number|
1688
1689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001690char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001691 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001692 Examples: >
1693 char2nr(" ") returns 32
1694 char2nr("ABC") returns 65
1695< When {utf8} is omitted or zero, the current 'encoding' is used.
1696 Example for "utf-8": >
1697 char2nr("á") returns 225
1698 char2nr("á"[0]) returns 195
1699< When {utf8} is TRUE, always treat as UTF-8 characters.
1700 A combining character is a separate character.
1701 |nr2char()| does the opposite.
1702 To turn a string into a list of character numbers: >
1703 let str = "ABC"
1704 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1705< Result: [65, 66, 67]
1706
Bram Moolenaar016188f2022-06-06 20:52:59 +01001707 Returns 0 if {string} is not a |String|.
1708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709 Can also be used as a |method|: >
1710 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001711<
1712 Return type: |Number|
1713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715charclass({string}) *charclass()*
1716 Return the character class of the first character in {string}.
1717 The character class is one of:
1718 0 blank
1719 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001720 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001721 3 emoji
1722 other specific Unicode class
1723 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001724 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001725
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001726 Return type: |Number|
1727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001728
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001729charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730 Same as |col()| but returns the character index of the column
1731 position given with {expr} instead of the byte position.
1732
1733 Example:
1734 With the cursor on '세' in line 5 with text "여보세요": >
1735 charcol('.') returns 3
1736 col('.') returns 7
1737
1738< Can also be used as a |method|: >
1739 GetPos()->col()
1740<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001741 Return type: |Number|
1742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001743 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001744charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001745 Return the character index of the byte at {idx} in {string}.
1746 The index of the first character is zero.
1747 If there are no multibyte characters the returned value is
1748 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001750 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001751 are not counted separately, their byte length is added to the
1752 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001753 When {countcc} is |TRUE|, then composing characters are
1754 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001755
1756 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1757 index in the String {expr} instead of as the byte index.
1758
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001759 Returns -1 if the arguments are invalid or if there are less
1760 than {idx} bytes. If there are exactly {idx} bytes the length
1761 of the string in characters is returned.
1762
1763 An error is given and -1 is returned if the first argument is
1764 not a string, the second argument is not a number or when the
1765 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001767 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001768 from the character index and |utf16idx()| for getting the
1769 UTF-16 index from the character index.
1770 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771 Examples: >
1772 echo charidx('áb́ć', 3) returns 1
1773 echo charidx('áb́ć', 6, 1) returns 4
1774 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001775 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001776<
1777 Can also be used as a |method|: >
1778 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001779<
1780 Return type: |Number|
1781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001782
1783chdir({dir}) *chdir()*
1784 Change the current working directory to {dir}. The scope of
1785 the directory change depends on the directory of the current
1786 window:
1787 - If the current window has a window-local directory
1788 (|:lcd|), then changes the window local directory.
1789 - Otherwise, if the current tabpage has a local
1790 directory (|:tcd|) then changes the tabpage local
1791 directory.
1792 - Otherwise, changes the global directory.
1793 {dir} must be a String.
1794 If successful, returns the previous working directory. Pass
1795 this to another chdir() to restore the directory.
1796 On failure, returns an empty string.
1797
1798 Example: >
1799 let save_dir = chdir(newdir)
1800 if save_dir != ""
1801 " ... do some work
1802 call chdir(save_dir)
1803 endif
1804
1805< Can also be used as a |method|: >
1806 GetDir()->chdir()
1807<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001808 Return type: |String|
1809
1810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811cindent({lnum}) *cindent()*
1812 Get the amount of indent for line {lnum} according the C
1813 indenting rules, as with 'cindent'.
1814 The indent is counted in spaces, the value of 'tabstop' is
1815 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001816 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001817 See |C-indenting|.
1818
1819 Can also be used as a |method|: >
1820 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821<
1822 Return type: |Number|
1823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001824
1825clearmatches([{win}]) *clearmatches()*
1826 Clears all matches previously defined for the current window
1827 by |matchadd()| and the |:match| commands.
1828 If {win} is specified, use the window with this number or
1829 window ID instead of the current window.
1830
1831 Can also be used as a |method|: >
1832 GetWin()->clearmatches()
1833<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001834 Return type: |Number|
1835
1836
Girish Palya5c3d1e32025-04-22 19:52:16 +02001837cmdcomplete_info() *cmdcomplete_info()*
Girish Palya92f68e22025-04-21 11:12:41 +02001838 Returns a |Dictionary| with information about cmdline
1839 completion. See |cmdline-completion|.
1840 The items are:
1841 cmdline_orig The original command-line string before
1842 completion began.
1843 pum_visible |TRUE| if popup menu is visible.
1844 See |pumvisible()|.
1845 matches List of all completion candidates. Each item
1846 is a string.
1847 selected Selected item index. First index is zero.
1848 Index is -1 if no item is selected (showing
1849 typed text only, or the last completion after
1850 no item is selected when using the <Up> or
1851 <Down> keys)
1852
1853 Returns an empty |Dictionary| if no completion was attempted,
1854 if there was only one candidate and it was fully completed, or
1855 if an error occurred.
1856
1857 Return type: dict<any>
1858
1859
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001860col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001861 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001862 position given with {expr}.
1863 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001864 When {expr} is "$", it means the end of the cursor line, so
1865 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001866 Additionally {expr} can be [lnum, col]: a |List| with the line
1867 and column number. Most useful when the column is "$", to get
1868 the last column of a specific line. When "lnum" or "col" is
1869 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001870
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001871 With the optional {winid} argument the values are obtained for
1872 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001874 To get the line number use |line()|. To get both use
1875 |getpos()|.
1876 For the screen column position use |virtcol()|. For the
1877 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001879 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001881 Examples: >
1882 col(".") column of cursor
1883 col("$") length of cursor line plus one
1884 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001885 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001886<
1887 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001888 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001889 For an uppercase mark the column may actually be in another
1890 buffer.
1891 For the cursor position, when 'virtualedit' is active, the
1892 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001893 line. Also, when using a <Cmd> mapping the cursor isn't
1894 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001895 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001896
1897< Can also be used as a |method|: >
1898 GetPos()->col()
1899<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001900 Return type: |Number|
1901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001902
1903complete({startcol}, {matches}) *complete()* *E785*
1904 Set the matches for Insert mode completion.
1905 Can only be used in Insert mode. You need to use a mapping
1906 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1907 or with an expression mapping.
1908 {startcol} is the byte offset in the line where the completed
1909 text start. The text up to the cursor is the original text
1910 that will be replaced by the matches. Use col('.') for an
1911 empty string. "col('.') - 1" will replace one character by a
1912 match.
1913 {matches} must be a |List|. Each |List| item is one match.
1914 See |complete-items| for the kind of items that are possible.
1915 "longest" in 'completeopt' is ignored.
1916 Note that the after calling this function you need to avoid
1917 inserting anything that would cause completion to stop.
1918 The match can be selected with CTRL-N and CTRL-P as usual with
1919 Insert mode completion. The popup menu will appear if
1920 specified, see |ins-completion-menu|.
1921 Example: >
1922 inoremap <F5> <C-R>=ListMonths()<CR>
1923
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001924 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001925 call complete(col('.'), ['January', 'February', 'March',
1926 \ 'April', 'May', 'June', 'July', 'August', 'September',
1927 \ 'October', 'November', 'December'])
1928 return ''
1929 endfunc
1930< This isn't very useful, but it shows how it works. Note that
1931 an empty string is returned to avoid a zero being inserted.
1932
1933 Can also be used as a |method|, the base is passed as the
1934 second argument: >
1935 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001936<
1937 Return type: |Number|
1938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001939
1940complete_add({expr}) *complete_add()*
1941 Add {expr} to the list of matches. Only to be used by the
1942 function specified with the 'completefunc' option.
1943 Returns 0 for failure (empty string or out of memory),
1944 1 when the match was added, 2 when the match was already in
1945 the list.
1946 See |complete-functions| for an explanation of {expr}. It is
1947 the same as one item in the list that 'omnifunc' would return.
1948
1949 Can also be used as a |method|: >
1950 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001951<
1952 Return type: |Number|
1953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954
1955complete_check() *complete_check()*
1956 Check for a key typed while looking for completion matches.
1957 This is to be used when looking for matches takes some time.
1958 Returns |TRUE| when searching for matches is to be aborted,
1959 zero otherwise.
1960 Only to be used by the function specified with the
1961 'completefunc' option.
1962
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001963 Return type: |Number|
1964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001965
1966complete_info([{what}]) *complete_info()*
1967 Returns a |Dictionary| with information about Insert mode
1968 completion. See |ins-completion|.
1969 The items are:
1970 mode Current completion mode name string.
1971 See |complete_info_mode| for the values.
1972 pum_visible |TRUE| if popup menu is visible.
1973 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001974 items List of all completion candidates. Each item
1975 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001976 "abbr", "menu", "kind", "info" and "user_data".
1977 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001978 matches Same as "items", but only returns items that
1979 are matching current query. If both "matches"
1980 and "items" are in "what", the returned list
1981 will still be named "items", but each item
1982 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001983 selected Selected item index. First index is zero.
1984 Index is -1 if no item is selected (showing
1985 typed text only, or the last completion after
1986 no item is selected when using the <Up> or
1987 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001988 completed Return a dictionary containing the entries of
1989 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001990
1991 *complete_info_mode*
1992 mode values are:
1993 "" Not in completion mode
1994 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1995 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1996 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1997 |i_CTRL-X_CTRL-Y|
1998 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1999 "files" File names |i_CTRL-X_CTRL-F|
2000 "tags" Tags |i_CTRL-X_CTRL-]|
2001 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
2002 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
2003 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
2004 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
2005 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
2006 "function" User defined completion |i_CTRL-X_CTRL-U|
2007 "omni" Omni completion |i_CTRL-X_CTRL-O|
2008 "spell" Spelling suggestions |i_CTRL-X_s|
2009 "eval" |complete()| completion
2010 "unknown" Other internal modes
2011
2012 If the optional {what} list argument is supplied, then only
2013 the items listed in {what} are returned. Unsupported items in
2014 {what} are silently ignored.
2015
2016 To get the position and size of the popup menu, see
2017 |pum_getpos()|. It's also available in |v:event| during the
2018 |CompleteChanged| event.
2019
Bram Moolenaar016188f2022-06-06 20:52:59 +01002020 Returns an empty |Dictionary| on error.
2021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002022 Examples: >
2023 " Get all items
2024 call complete_info()
2025 " Get only 'mode'
2026 call complete_info(['mode'])
2027 " Get only 'mode' and 'pum_visible'
2028 call complete_info(['mode', 'pum_visible'])
2029
2030< Can also be used as a |method|: >
2031 GetItems()->complete_info()
2032<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002033 Return type: dict<any>
2034
glepnirbcd59952025-04-24 21:48:35 +02002035complete_match([{lnum}, {col}]) *complete_match()*
glepnirffc89e42025-04-27 14:59:17 +02002036 Searches backward from the given position and returns a List
2037 of matches according to the 'isexpand' option. When no
2038 arguments are provided, uses the current cursor position.
2039
2040 Each match is represented as a List containing
glepnirbcd59952025-04-24 21:48:35 +02002041 [startcol, trigger_text] where:
2042 - startcol: column position where completion should start,
2043 or -1 if no trigger position is found. For multi-character
2044 triggers, returns the column of the first character.
2045 - trigger_text: the matching trigger string from 'isexpand',
2046 or empty string if no match was found or when using the
2047 default 'iskeyword' pattern.
2048
2049 When 'isexpand' is empty, uses the 'iskeyword' pattern
2050 "\k\+$" to find the start of the current keyword.
2051
glepnirbcd59952025-04-24 21:48:35 +02002052 Examples: >
2053 set isexpand=.,->,/,/*,abc
2054 func CustomComplete()
2055 let res = complete_match()
2056 if res->len() == 0 | return | endif
2057 let [col, trigger] = res[0]
2058 let items = []
2059 if trigger == '/*'
2060 let items = ['/** */']
2061 elseif trigger == '/'
2062 let items = ['/*! */', '// TODO:', '// fixme:']
2063 elseif trigger == '.'
2064 let items = ['length()']
2065 elseif trigger =~ '^\->'
2066 let items = ['map()', 'reduce()']
2067 elseif trigger =~ '^\abc'
2068 let items = ['def', 'ghk']
2069 endif
2070 if items->len() > 0
2071 let startcol = trigger =~ '^/' ? col : col + len(trigger)
2072 call complete(startcol, items)
2073 endif
2074 endfunc
2075 inoremap <Tab> <Cmd>call CustomComplete()<CR>
2076<
2077 Return type: list<list<any>>
2078
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002079 *confirm()*
2080confirm({msg} [, {choices} [, {default} [, {type}]]])
2081 confirm() offers the user a dialog, from which a choice can be
2082 made. It returns the number of the choice. For the first
2083 choice this is 1.
2084 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002085 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002086
2087 {msg} is displayed in a |dialog| with {choices} as the
2088 alternatives. When {choices} is missing or empty, "&OK" is
2089 used (and translated).
2090 {msg} is a String, use '\n' to include a newline. Only on
2091 some systems the string is wrapped when it doesn't fit.
2092
2093 {choices} is a String, with the individual choices separated
2094 by '\n', e.g. >
2095 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2096< The letter after the '&' is the shortcut key for that choice.
2097 Thus you can type 'c' to select "Cancel". The shortcut does
2098 not need to be the first letter: >
2099 confirm("file has been modified", "&Save\nSave &All")
2100< For the console, the first letter of each choice is used as
2101 the default shortcut key. Case is ignored.
2102
2103 The optional {default} argument is the number of the choice
2104 that is made if the user hits <CR>. Use 1 to make the first
2105 choice the default one. Use 0 to not set a default. If
2106 {default} is omitted, 1 is used.
2107
2108 The optional {type} String argument gives the type of dialog.
2109 This is only used for the icon of the GTK, Mac, Motif and
2110 Win32 GUI. It can be one of these values: "Error",
2111 "Question", "Info", "Warning" or "Generic". Only the first
2112 character is relevant. When {type} is omitted, "Generic" is
2113 used.
2114
2115 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2116 or another valid interrupt key, confirm() returns 0.
2117
2118 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002119 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002120 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002121 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002122 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002123 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002124 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002125 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002126 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002127 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002128< In a GUI dialog, buttons are used. The layout of the buttons
2129 depends on the 'v' flag in 'guioptions'. If it is included,
2130 the buttons are always put vertically. Otherwise, confirm()
2131 tries to put the buttons in one horizontal line. If they
2132 don't fit, a vertical layout is used anyway. For some systems
2133 the horizontal layout is always used.
2134
2135 Can also be used as a |method|in: >
2136 BuildMessage()->confirm("&Yes\n&No")
2137<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002138 Return type: |Number|
2139
2140
2141copy({expr}) *copy()*
2142 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002143 different from using {expr} directly.
2144 When {expr} is a |List| a shallow copy is created. This means
2145 that the original |List| can be changed without changing the
2146 copy, and vice versa. But the items are identical, thus
2147 changing an item changes the contents of both |Lists|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002148 A |Tuple| or |Dictionary| is copied in a similar way as a
2149 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002150 Also see |deepcopy()|.
2151 Can also be used as a |method|: >
2152 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002153<
2154 Return type: any, depending on {expr}
2155
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002156
2157cos({expr}) *cos()*
2158 Return the cosine of {expr}, measured in radians, as a |Float|.
2159 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002160 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002161 Examples: >
2162 :echo cos(100)
2163< 0.862319 >
2164 :echo cos(-4.01)
2165< -0.646043
2166
2167 Can also be used as a |method|: >
2168 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002169<
2170 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002171
2172
2173cosh({expr}) *cosh()*
2174 Return the hyperbolic cosine of {expr} as a |Float| in the range
2175 [1, inf].
2176 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002177 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002178 Examples: >
2179 :echo cosh(0.5)
2180< 1.127626 >
2181 :echo cosh(-0.5)
2182< -1.127626
2183
2184 Can also be used as a |method|: >
2185 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002186<
2187 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002188
2189
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002190count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002191 Return the number of times an item with value {expr} appears
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002192 in |String|, |List|, |Tuple| or |Dictionary| {comp}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002193
2194 If {start} is given then start with the item with this index.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002195 {start} can only be used with a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002196
2197 When {ic} is given and it's |TRUE| then case is ignored.
2198
2199 When {comp} is a string then the number of not overlapping
2200 occurrences of {expr} is returned. Zero is returned when
2201 {expr} is an empty string.
2202
2203 Can also be used as a |method|: >
2204 mylist->count(val)
2205<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002206 Return type: |Number|
2207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002208 *cscope_connection()*
2209cscope_connection([{num} , {dbpath} [, {prepend}]])
2210 Checks for the existence of a |cscope| connection. If no
2211 parameters are specified, then the function returns:
2212 0, if cscope was not available (not compiled in), or
2213 if there are no cscope connections;
2214 1, if there is at least one cscope connection.
2215
2216 If parameters are specified, then the value of {num}
2217 determines how existence of a cscope connection is checked:
2218
2219 {num} Description of existence check
2220 ----- ------------------------------
2221 0 Same as no parameters (e.g., "cscope_connection()").
2222 1 Ignore {prepend}, and use partial string matches for
2223 {dbpath}.
2224 2 Ignore {prepend}, and use exact string matches for
2225 {dbpath}.
2226 3 Use {prepend}, use partial string matches for both
2227 {dbpath} and {prepend}.
2228 4 Use {prepend}, use exact string matches for both
2229 {dbpath} and {prepend}.
2230
2231 Note: All string comparisons are case sensitive!
2232
2233 Examples. Suppose we had the following (from ":cs show"): >
2234
2235 # pid database name prepend path
2236 0 27664 cscope.out /usr/local
2237<
2238 Invocation Return Val ~
2239 ---------- ---------- >
2240 cscope_connection() 1
2241 cscope_connection(1, "out") 1
2242 cscope_connection(2, "out") 0
2243 cscope_connection(3, "out") 0
2244 cscope_connection(3, "out", "local") 1
2245 cscope_connection(4, "out") 0
2246 cscope_connection(4, "out", "local") 0
2247 cscope_connection(4, "cscope.out", "/usr/local") 1
2248<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002249 Return type: |Number|
2250
2251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002252cursor({lnum}, {col} [, {off}]) *cursor()*
2253cursor({list})
2254 Positions the cursor at the column (byte count) {col} in the
2255 line {lnum}. The first column is one.
2256
2257 When there is one argument {list} this is used as a |List|
2258 with two, three or four item:
2259 [{lnum}, {col}]
2260 [{lnum}, {col}, {off}]
2261 [{lnum}, {col}, {off}, {curswant}]
2262 This is like the return value of |getpos()| or |getcurpos()|,
2263 but without the first item.
2264
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002265 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002266 |setcursorcharpos()|.
2267
2268 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002269 {lnum} is used like with |getline()|, except that if {lnum} is
2270 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002271 If {lnum} is greater than the number of lines in the buffer,
2272 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002273 If {col} is greater than the number of bytes in the line,
2274 the cursor will be positioned at the last character in the
2275 line.
2276 If {col} is zero, the cursor will stay in the current column.
2277 If {curswant} is given it is used to set the preferred column
2278 for vertical movement. Otherwise {col} is used.
2279
2280 When 'virtualedit' is used {off} specifies the offset in
2281 screen columns from the start of the character. E.g., a
2282 position within a <Tab> or after the last character.
2283 Returns 0 when the position could be set, -1 otherwise.
2284
2285 Can also be used as a |method|: >
2286 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002287<
2288 Return type: |Number|
2289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002290
2291debugbreak({pid}) *debugbreak()*
2292 Specifically used to interrupt a program being debugged. It
2293 will cause process {pid} to get a SIGTRAP. Behavior for other
2294 processes is undefined. See |terminal-debugger|.
2295 {only available on MS-Windows}
2296
Bram Moolenaar016188f2022-06-06 20:52:59 +01002297 Returns |TRUE| if successfully interrupted the program.
2298 Otherwise returns |FALSE|.
2299
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002300 Can also be used as a |method|: >
2301 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002302<
2303 Return type: |Number|
2304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002305
2306deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2307 Make a copy of {expr}. For Numbers and Strings this isn't
2308 different from using {expr} directly.
2309 When {expr} is a |List| a full copy is created. This means
2310 that the original |List| can be changed without changing the
2311 copy, and vice versa. When an item is a |List| or
2312 |Dictionary|, a copy for it is made, recursively. Thus
2313 changing an item in the copy does not change the contents of
2314 the original |List|.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002315 A |Tuple| or |Dictionary| is copied in a similar way as a
2316 |List|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002317
2318 When {noref} is omitted or zero a contained |List| or
2319 |Dictionary| is only copied once. All references point to
2320 this single copy. With {noref} set to 1 every occurrence of a
2321 |List| or |Dictionary| results in a new copy. This also means
2322 that a cyclic reference causes deepcopy() to fail.
2323 *E724*
2324 Nesting is possible up to 100 levels. When there is an item
2325 that refers back to a higher level making a deep copy with
2326 {noref} set to 1 will fail.
2327 Also see |copy()|.
2328
2329 Can also be used as a |method|: >
2330 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002331<
2332 Return type: any, depending on {expr}
2333
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002334
2335delete({fname} [, {flags}]) *delete()*
2336 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002337 name {fname}.
2338
2339 This also works when {fname} is a symbolic link. The symbolic
2340 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002341
2342 When {flags} is "d": Deletes the directory by the name
2343 {fname}. This fails when directory {fname} is not empty.
2344
2345 When {flags} is "rf": Deletes the directory by the name
2346 {fname} and everything in it, recursively. BE CAREFUL!
2347 Note: on MS-Windows it is not possible to delete a directory
2348 that is being used.
2349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002350 The result is a Number, which is 0/false if the delete
2351 operation was successful and -1/true when the deletion failed
2352 or partly failed.
2353
2354 Use |remove()| to delete an item from a |List|.
2355 To delete a line from the buffer use |:delete| or
2356 |deletebufline()|.
2357
2358 Can also be used as a |method|: >
2359 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002360<
2361 Return type: |Number|
2362
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002363
2364deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2365 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2366 If {last} is omitted then delete line {first} only.
2367 On success 0 is returned, on failure 1 is returned.
2368
2369 This function works only for loaded buffers. First call
2370 |bufload()| if needed.
2371
2372 For the use of {buf}, see |bufname()| above.
2373
2374 {first} and {last} are used like with |getline()|. Note that
2375 when using |line()| this refers to the current buffer. Use "$"
2376 to refer to the last line in buffer {buf}.
2377
2378 Can also be used as a |method|: >
2379 GetBuffer()->deletebufline(1)
2380<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002381 Return type: |Number|
2382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002383 *did_filetype()*
2384did_filetype() Returns |TRUE| when autocommands are being executed and the
2385 FileType event has been triggered at least once. Can be used
2386 to avoid triggering the FileType event again in the scripts
2387 that detect the file type. |FileType|
2388 Returns |FALSE| when `:setf FALLBACK` was used.
2389 When editing another file, the counter is reset, thus this
2390 really checks if the FileType event has been triggered for the
2391 current buffer. This allows an autocommand that starts
2392 editing another buffer to set 'filetype' and load a syntax
2393 file.
2394
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002395 Return type: |Number|
2396
2397
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002398diff({fromlist}, {tolist} [, {options}]) *diff()*
2399 Returns a String or a List containing the diff between the
2400 strings in {fromlist} and {tolist}. Uses the Vim internal
2401 diff library to compute the diff.
2402
2403 *E106*
2404 The optional "output" item in {options} specifies the returned
2405 diff format. The following values are supported:
2406 indices Return a List of the starting and ending
2407 indices and a count of the strings in each
2408 diff hunk.
2409 unified Return the unified diff output as a String.
2410 This is the default.
2411
2412 If the "output" item in {options} is "indices", then a List is
2413 returned. Each List item contains a Dict with the following
2414 items for each diff hunk:
2415 from_idx start index in {fromlist} for this diff hunk.
2416 from_count number of strings in {fromlist} that are
2417 added/removed/modified in this diff hunk.
2418 to_idx start index in {tolist} for this diff hunk.
2419 to_count number of strings in {tolist} that are
2420 added/removed/modified in this diff hunk.
2421
2422 The {options} Dict argument also specifies diff options
2423 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002424 algorithm Dict specifying the diff algorithm to
2425 use. Supported boolean items are
2426 "myers", "minimal", "patience" and
2427 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002428 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002429 iblank ignore changes where lines are all
2430 blank.
2431 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002432 indent-heuristic use the indent heuristic for the
2433 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002434 iwhite ignore changes in amount of white
2435 space.
2436 iwhiteall ignore all white space changes.
2437 iwhiteeol ignore white space changes at end of
2438 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002439 For more information about these options, refer to 'diffopt'.
2440
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002441 To compute the unified diff, all the items in {fromlist} are
2442 concatenated into a string using a newline separator and the
2443 same for {tolist}. The unified diff output uses line numbers.
2444
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002445 Returns an empty List or String if {fromlist} and {tolist} are
2446 identical.
2447
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002448 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002449 :echo diff(['abc'], ['xxx'])
2450 @@ -1 +1 @@
2451 -abc
2452 +xxx
2453
2454 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2455 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2456 :echo diff(readfile('oldfile'), readfile('newfile'))
2457 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002458<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002459 For more examples, refer to |diff-func-examples|
2460
2461 Can also be used as a |method|: >
2462 GetFromList->diff(to_list)
2463<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002464 Return type: |String| or list<dict<number>> or list<any>
2465 depending on {options}
2466
2467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002468diff_filler({lnum}) *diff_filler()*
2469 Returns the number of filler lines above line {lnum}.
2470 These are the lines that were inserted at this point in
2471 another diff'ed window. These filler lines are shown in the
2472 display but don't exist in the buffer.
2473 {lnum} is used like with |getline()|. Thus "." is the current
2474 line, "'m" mark m, etc.
2475 Returns 0 if the current window is not in diff mode.
2476
2477 Can also be used as a |method|: >
2478 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002479<
2480 Return type: |Number|
2481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002482
2483diff_hlID({lnum}, {col}) *diff_hlID()*
2484 Returns the highlight ID for diff mode at line {lnum} column
2485 {col} (byte index). When the current line does not have a
2486 diff change zero is returned.
2487 {lnum} is used like with |getline()|. Thus "." is the current
2488 line, "'m" mark m, etc.
2489 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2490 line.
2491 The highlight ID can be used with |synIDattr()| to obtain
2492 syntax information about the highlighting.
2493
2494 Can also be used as a |method|: >
2495 GetLnum()->diff_hlID(col)
2496<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002497 Return type: |Number|
2498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002499
2500digraph_get({chars}) *digraph_get()* *E1214*
2501 Return the digraph of {chars}. This should be a string with
2502 exactly two characters. If {chars} are not just two
2503 characters, or the digraph of {chars} does not exist, an error
2504 is given and an empty string is returned.
2505
2506 The character will be converted from Unicode to 'encoding'
2507 when needed. This does require the conversion to be
2508 available, it might fail.
2509
2510 Also see |digraph_getlist()|.
2511
2512 Examples: >
2513 " Get a built-in digraph
2514 :echo digraph_get('00') " Returns '∞'
2515
2516 " Get a user-defined digraph
2517 :call digraph_set('aa', 'あ')
2518 :echo digraph_get('aa') " Returns 'あ'
2519<
2520 Can also be used as a |method|: >
2521 GetChars()->digraph_get()
2522<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002523 Return type: |String|
2524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002525 This function works only when compiled with the |+digraphs|
2526 feature. If this feature is disabled, this function will
2527 display an error message.
2528
2529
2530digraph_getlist([{listall}]) *digraph_getlist()*
2531 Return a list of digraphs. If the {listall} argument is given
2532 and it is TRUE, return all digraphs, including the default
2533 digraphs. Otherwise, return only user-defined digraphs.
2534
2535 The characters will be converted from Unicode to 'encoding'
2536 when needed. This does require the conservation to be
2537 available, it might fail.
2538
2539 Also see |digraph_get()|.
2540
2541 Examples: >
2542 " Get user-defined digraphs
2543 :echo digraph_getlist()
2544
2545 " Get all the digraphs, including default digraphs
2546 :echo digraph_getlist(1)
2547<
2548 Can also be used as a |method|: >
2549 GetNumber()->digraph_getlist()
2550<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002551 Return type: list<list<string>>
2552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002553 This function works only when compiled with the |+digraphs|
2554 feature. If this feature is disabled, this function will
2555 display an error message.
2556
2557
Bram Moolenaara2baa732022-02-04 16:09:54 +00002558digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002559 Add digraph {chars} to the list. {chars} must be a string
2560 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002561 encoded character. *E1215*
2562 Be careful, composing characters are NOT ignored. This
2563 function is similar to |:digraphs| command, but useful to add
2564 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002565
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002566 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002567 this fails an error message is given and v:false is returned.
2568
2569 If you want to define multiple digraphs at once, you can use
2570 |digraph_setlist()|.
2571
2572 Example: >
2573 call digraph_set(' ', 'あ')
2574<
2575 Can be used as a |method|: >
2576 GetString()->digraph_set('あ')
2577<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002578 Return type: |vim9-boolean|
2579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002580 This function works only when compiled with the |+digraphs|
2581 feature. If this feature is disabled, this function will
2582 display an error message.
2583
2584
2585digraph_setlist({digraphlist}) *digraph_setlist()*
2586 Similar to |digraph_set()| but this function can add multiple
2587 digraphs at once. {digraphlist} is a list composed of lists,
2588 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002589 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002590 Example: >
2591 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2592<
2593 It is similar to the following: >
2594 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2595 call digraph_set(chars, digraph)
2596 endfor
2597< Except that the function returns after the first error,
2598 following digraphs will not be added.
2599
2600 Can be used as a |method|: >
2601 GetList()->digraph_setlist()
2602<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002603 Return type: |vim9-boolean|
2604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002605 This function works only when compiled with the |+digraphs|
2606 feature. If this feature is disabled, this function will
2607 display an error message.
2608
2609
2610echoraw({string}) *echoraw()*
2611 Output {string} as-is, including unprintable characters.
2612 This can be used to output a terminal code. For example, to
2613 disable modifyOtherKeys: >
2614 call echoraw(&t_TE)
2615< and to enable it again: >
2616 call echoraw(&t_TI)
2617< Use with care, you can mess up the terminal this way.
2618
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002619 Return type: |Number|
2620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621
2622empty({expr}) *empty()*
2623 Return the Number 1 if {expr} is empty, zero otherwise.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002624 - A |List|, |Tuple| or |Dictionary| is empty when it does
2625 not have any items.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002626 - A |String| is empty when its length is zero.
2627 - A |Number| and |Float| are empty when their value is zero.
2628 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2629 - A |Job| is empty when it failed to start.
2630 - A |Channel| is empty when it is closed.
2631 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002632 - An |Object| is empty, when the empty() method in the object
2633 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002634
2635 For a long |List| this is much faster than comparing the
2636 length with zero.
2637
2638 Can also be used as a |method|: >
2639 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002640<
2641 Return type: |Number|
2642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002643
2644environ() *environ()*
2645 Return all of environment variables as dictionary. You can
2646 check if an environment variable exists like this: >
2647 :echo has_key(environ(), 'HOME')
2648< Note that the variable name may be CamelCase; to ignore case
2649 use this: >
2650 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002651<
2652 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002653
Bram Moolenaar416bd912023-07-07 23:19:18 +01002654
2655err_teapot([{expr}]) *err_teapot()*
2656 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002657 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002658 If {expr} is present and it is TRUE error 503 is given,
2659 indicating that coffee is temporarily not available.
2660 If {expr} is present it must be a String.
2661
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002662 Return type: |Number|
2663
Bram Moolenaar416bd912023-07-07 23:19:18 +01002664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002665escape({string}, {chars}) *escape()*
2666 Escape the characters in {chars} that occur in {string} with a
2667 backslash. Example: >
2668 :echo escape('c:\program files\vim', ' \')
2669< results in: >
2670 c:\\program\ files\\vim
2671< Also see |shellescape()| and |fnameescape()|.
2672
2673 Can also be used as a |method|: >
2674 GetText()->escape(' \')
2675<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002676 Return type: |String|
2677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002678 *eval()*
2679eval({string}) Evaluate {string} and return the result. Especially useful to
2680 turn the result of |string()| back into the original value.
2681 This works for Numbers, Floats, Strings, Blobs and composites
2682 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002683 functions. In |Vim9| script, it can be used to obtain |enum|
2684 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002685
2686 Can also be used as a |method|: >
2687 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002688<
2689 Return type: any, depending on {string}
2690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002691
2692eventhandler() *eventhandler()*
2693 Returns 1 when inside an event handler. That is that Vim got
2694 interrupted while waiting for the user to type a character,
2695 e.g., when dropping a file on Vim. This means interactive
2696 commands cannot be used. Otherwise zero is returned.
2697
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002698 Return type: |Number|
2699
2700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002701executable({expr}) *executable()*
2702 This function checks if an executable with the name {expr}
2703 exists. {expr} must be the name of the program without any
2704 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002706 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002707 searchpath for programs.
2708 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002709 On MS-Windows the ".exe", ".bat", etc. can optionally be
2710 included. Then the extensions in $PATHEXT are tried. Thus if
2711 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2712 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2713 by itself can be used in $PATHEXT to try using the name
2714 without an extension. When 'shell' looks like a Unix shell,
2715 then the name is also tried without adding an extension.
2716 On MS-Windows it only checks if the file exists and is not a
2717 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002718 On MS-Windows an executable in the same directory as the Vim
2719 executable is always found. Since this directory is added to
2720 $PATH it should also work to execute it |win32-PATH|.
2721 *NoDefaultCurrentDirectoryInExePath*
2722 On MS-Windows an executable in Vim's current working directory
2723 is also normally found, but this can be disabled by setting
2724 the $NoDefaultCurrentDirectoryInExePath environment variable.
2725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002726 The result is a Number:
2727 1 exists
2728 0 does not exist
2729 -1 not implemented on this system
2730 |exepath()| can be used to get the full path of an executable.
2731
2732 Can also be used as a |method|: >
2733 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002734<
2735 Return type: |Number|
2736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002737
2738execute({command} [, {silent}]) *execute()*
2739 Execute an Ex command or commands and return the output as a
2740 string.
2741 {command} can be a string or a List. In case of a List the
2742 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002743 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002744 redir => var
2745 {command}
2746 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002747< Except that line continuation in {command} is not recognized.
2748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002749 The optional {silent} argument can have these values:
2750 "" no `:silent` used
2751 "silent" `:silent` used
2752 "silent!" `:silent!` used
2753 The default is "silent". Note that with "silent!", unlike
2754 `:redir`, error messages are dropped. When using an external
2755 command the screen may be messed up, use `system()` instead.
2756 *E930*
2757 It is not possible to use `:redir` anywhere in {command}.
2758
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002759 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002760 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002761
2762< To execute a command in another window than the current one
2763 use `win_execute()`.
2764
2765 When used recursively the output of the recursive call is not
2766 included in the output of the higher level call.
2767
2768 Can also be used as a |method|: >
2769 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002770<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002771 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002773
2774exepath({expr}) *exepath()*
2775 If {expr} is an executable and is either an absolute path, a
2776 relative path or found in $PATH, return the full path.
2777 Note that the current directory is used when {expr} starts
2778 with "./", which may be a problem for Vim: >
2779 echo exepath(v:progpath)
2780< If {expr} cannot be found in $PATH or is not executable then
2781 an empty string is returned.
2782
2783 Can also be used as a |method|: >
2784 GetCommand()->exepath()
2785<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002786 Return type: |String|
2787
2788
2789exists({expr}) *exists()*
2790 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002791 zero otherwise.
2792
2793 Note: In a compiled |:def| function the evaluation is done at
2794 runtime. Use `exists_compiled()` to evaluate the expression
2795 at compile time.
2796
2797 For checking for a supported feature use |has()|.
2798 For checking if a file exists use |filereadable()|.
2799
2800 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002801 varname internal variable (see
2802 dict.key |internal-variables|). Also works
2803 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002804 import.Func entries, |List| items, class and
2805 class.Func object methods, imported items, etc.
2806 object.Func Does not work for local variables in a
2807 class.varname compiled `:def` function.
2808 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002809 script, since it can be used as a
2810 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002811 Beware that evaluating an index may
2812 cause an error message for an invalid
2813 expression. E.g.: >
2814 :let l = [1, 2, 3]
2815 :echo exists("l[5]")
2816< 0 >
2817 :echo exists("l[xx]")
2818< E121: Undefined variable: xx
2819 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002820 &option-name Vim option (only checks if it exists,
2821 not if it really works)
2822 +option-name Vim option that works.
2823 $ENVNAME environment variable (could also be
2824 done by comparing with an empty
2825 string)
2826 *funcname built-in function (see |functions|)
2827 or user defined function (see
2828 |user-functions|) that is implemented.
2829 Also works for a variable that is a
2830 Funcref.
2831 ?funcname built-in function that could be
2832 implemented; to be used to check if
2833 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002834 :cmdname Ex command: built-in command, user
2835 command or command modifier |:command|.
2836 Returns:
2837 1 for match with start of a command
2838 2 full match with a command
2839 3 matches several user commands
2840 To check for a supported command
2841 always check the return value to be 2.
2842 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002843 :3match The |:3match| command (but you
2844 probably should not use it, it is
2845 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002846 #event autocommand defined for this event
2847 #event#pattern autocommand defined for this event and
2848 pattern (the pattern is taken
2849 literally and compared to the
2850 autocommand patterns character by
2851 character)
2852 #group autocommand group exists
2853 #group#event autocommand defined for this group and
2854 event.
2855 #group#event#pattern
2856 autocommand defined for this group,
2857 event and pattern.
2858 ##event autocommand for this event is
2859 supported.
2860
2861 Examples: >
2862 exists("&shortname")
2863 exists("$HOSTNAME")
2864 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002865 exists("*s:MyFunc") " only for legacy script
2866 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 exists("bufcount")
2868 exists(":Make")
2869 exists("#CursorHold")
2870 exists("#BufReadPre#*.gz")
2871 exists("#filetypeindent")
2872 exists("#filetypeindent#FileType")
2873 exists("#filetypeindent#FileType#*")
2874 exists("##ColorScheme")
2875< There must be no space between the symbol (&/$/*/#) and the
2876 name.
2877 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002878 a few cases this is ignored. That may become stricter in the
2879 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002880 Working example: >
2881 exists(":make")
2882< NOT working example: >
2883 exists(":make install")
2884
2885< Note that the argument must be a string, not the name of the
2886 variable itself. For example: >
2887 exists(bufcount)
2888< This doesn't check for existence of the "bufcount" variable,
2889 but gets the value of "bufcount", and checks if that exists.
2890
2891 Can also be used as a |method|: >
2892 Varname()->exists()
2893<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002894 Return type: |String|
2895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002896
2897exists_compiled({expr}) *exists_compiled()*
2898 Like `exists()` but evaluated at compile time. This is useful
2899 to skip a block where a function is used that would otherwise
2900 give an error: >
2901 if exists_compiled('*ThatFunction')
2902 ThatFunction('works')
2903 endif
2904< If `exists()` were used then a compilation error would be
2905 given if ThatFunction() is not defined.
2906
2907 {expr} must be a literal string. *E1232*
2908 Can only be used in a |:def| function. *E1233*
2909 This does not work to check for arguments or local variables.
2910
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002911 Return type: |String|
2912
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002913
2914exp({expr}) *exp()*
2915 Return the exponential of {expr} as a |Float| in the range
2916 [0, inf].
2917 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002918 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002919 Examples: >
2920 :echo exp(2)
2921< 7.389056 >
2922 :echo exp(-1)
2923< 0.367879
2924
2925 Can also be used as a |method|: >
2926 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002927<
2928 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002929
2930
2931expand({string} [, {nosuf} [, {list}]]) *expand()*
2932 Expand wildcards and the following special keywords in
2933 {string}. 'wildignorecase' applies.
2934
2935 If {list} is given and it is |TRUE|, a List will be returned.
2936 Otherwise the result is a String and when there are several
2937 matches, they are separated by <NL> characters. [Note: in
2938 version 5.0 a space was used, which caused problems when a
2939 file name contains a space]
2940
2941 If the expansion fails, the result is an empty string. A name
2942 for a non-existing file is not included, unless {string} does
2943 not start with '%', '#' or '<', see below.
2944
Christian Brabandtec9c3262024-02-21 20:40:05 +01002945 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002946 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002948 When {string} starts with '%', '#' or '<', the expansion is
2949 done like for the |cmdline-special| variables with their
2950 associated modifiers. Here is a short overview:
2951
2952 % current file name
2953 # alternate file name
2954 #n alternate file name n
2955 <cfile> file name under the cursor
2956 <afile> autocmd file name
2957 <abuf> autocmd buffer number (as a String!)
2958 <amatch> autocmd matched name
2959 <cexpr> C expression under the cursor
2960 <sfile> sourced script file or function name
2961 <slnum> sourced script line number or function
2962 line number
2963 <sflnum> script file line number, also when in
2964 a function
2965 <SID> "<SNR>123_" where "123" is the
2966 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002967 <script> sourced script file, or script file
2968 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002969 <stack> call stack
2970 <cword> word under the cursor
2971 <cWORD> WORD under the cursor
2972 <client> the {clientid} of the last received
2973 message |server2client()|
2974 Modifiers:
2975 :p expand to full path
2976 :h head (last path component removed)
2977 :t tail (last path component only)
2978 :r root (one extension removed)
2979 :e extension only
2980
2981 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002982 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002983< Note that when expanding a string that starts with '%', '#' or
2984 '<', any following text is ignored. This does NOT work: >
2985 :let doesntwork = expand("%:h.bak")
2986< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002987 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002988< Also note that expanding "<cfile>" and others only returns the
2989 referenced file name without further expansion. If "<cfile>"
2990 is "~/.cshrc", you need to do another expand() to have the
2991 "~/" expanded into the path of the home directory: >
2992 :echo expand(expand("<cfile>"))
2993<
2994 There cannot be white space between the variables and the
2995 following modifier. The |fnamemodify()| function can be used
2996 to modify normal file names.
2997
2998 When using '%' or '#', and the current or alternate file name
2999 is not defined, an empty string is used. Using "%:p" in a
3000 buffer with no name, results in the current directory, with a
3001 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01003002 When 'verbose' is set then expanding '%', '#' and <> items
3003 will result in an error message if the argument cannot be
3004 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003005
3006 When {string} does not start with '%', '#' or '<', it is
3007 expanded like a file name is expanded on the command line.
3008 'suffixes' and 'wildignore' are used, unless the optional
3009 {nosuf} argument is given and it is |TRUE|.
3010 Names for non-existing files are included. The "**" item can
3011 be used to search in a directory tree. For example, to find
3012 all "README" files in the current directory and below: >
3013 :echo expand("**/README")
3014<
3015 expand() can also be used to expand variables and environment
3016 variables that are only known in a shell. But this can be
3017 slow, because a shell may be used to do the expansion. See
3018 |expr-env-expand|.
3019 The expanded variable is still handled like a list of file
3020 names. When an environment variable cannot be expanded, it is
3021 left unchanged. Thus ":echo expand('$FOOBAR')" results in
3022 "$FOOBAR".
3023
3024 See |glob()| for finding existing files. See |system()| for
3025 getting the raw output of an external command.
3026
3027 Can also be used as a |method|: >
3028 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003029<
3030 Return type: |String| or list<string> depending on {list}
3031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003032
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003033expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003034 Expand special items in String {string} like what is done for
3035 an Ex command such as `:edit`. This expands special keywords,
3036 like with |expand()|, and environment variables, anywhere in
3037 {string}. "~user" and "~/path" are only expanded at the
3038 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003039
3040 The following items are supported in the {options} Dict
3041 argument:
3042 errmsg If set to TRUE, error messages are displayed
3043 if an error is encountered during expansion.
3044 By default, error messages are not displayed.
3045
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003046 Returns the expanded string. If an error is encountered
3047 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003048
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003049 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003050 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01003051 make /path/runtime/doc/builtin.o
3052 :echo expandcmd('make %<.o', {'errmsg': v:true})
3053<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01003054 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003055 GetCommand()->expandcmd()
3056<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003057 Return type: |String| or list<string> depending on {list}
3058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003059extend({expr1}, {expr2} [, {expr3}]) *extend()*
3060 {expr1} and {expr2} must be both |Lists| or both
3061 |Dictionaries|.
3062
3063 If they are |Lists|: Append {expr2} to {expr1}.
3064 If {expr3} is given insert the items of {expr2} before the
3065 item with index {expr3} in {expr1}. When {expr3} is zero
3066 insert before the first item. When {expr3} is equal to
3067 len({expr1}) then {expr2} is appended.
3068 Examples: >
3069 :echo sort(extend(mylist, [7, 5]))
3070 :call extend(mylist, [2, 3], 1)
3071< When {expr1} is the same List as {expr2} then the number of
3072 items copied is equal to the original length of the List.
3073 E.g., when {expr3} is 1 you get N new copies of the first item
3074 (where N is the original length of the List).
3075 Use |add()| to concatenate one item to a list. To concatenate
3076 two lists into a new list use the + operator: >
3077 :let newlist = [1, 2, 3] + [4, 5]
3078<
3079 If they are |Dictionaries|:
3080 Add all entries from {expr2} to {expr1}.
3081 If a key exists in both {expr1} and {expr2} then {expr3} is
3082 used to decide what to do:
3083 {expr3} = "keep": keep the value of {expr1}
3084 {expr3} = "force": use the value of {expr2}
3085 {expr3} = "error": give an error message *E737*
3086 When {expr3} is omitted then "force" is assumed.
3087
3088 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003089 make a copy of {expr1} first or use |extendnew()| to return a
3090 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003091 {expr2} remains unchanged.
3092 When {expr1} is locked and {expr2} is not empty the operation
3093 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003094 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003095
3096 Can also be used as a |method|: >
3097 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003098<
3099 Return type: list<{type}> or dict<{type}> depending on {expr1}
3100 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003101
3102
3103extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3104 Like |extend()| but instead of adding items to {expr1} a new
3105 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003106 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003107
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003108 Return type: list<{type}> or dict<{type}> depending on {expr1}
3109 and {expr2}, in case of error: |Number|
3110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003111
3112feedkeys({string} [, {mode}]) *feedkeys()*
3113 Characters in {string} are queued for processing as if they
3114 come from a mapping or were typed by the user.
3115
3116 By default the string is added to the end of the typeahead
3117 buffer, thus if a mapping is still being executed the
3118 characters come after them. Use the 'i' flag to insert before
3119 other characters, they will be executed next, before any
3120 characters from a mapping.
3121
3122 The function does not wait for processing of keys contained in
3123 {string}.
3124
3125 To include special keys into {string}, use double-quotes
3126 and "\..." notation |expr-quote|. For example,
3127 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3128 feedkeys('\<CR>') pushes 5 characters.
3129 A special code that might be useful is <Ignore>, it exits the
3130 wait for a character without doing anything. *<Ignore>*
3131
3132 {mode} is a String, which can contain these character flags:
3133 'm' Remap keys. This is default. If {mode} is absent,
3134 keys are remapped.
3135 'n' Do not remap keys.
3136 't' Handle keys as if typed; otherwise they are handled as
3137 if coming from a mapping. This matters for undo,
3138 opening folds, etc.
3139 'L' Lowlevel input. Only works for Unix or when using the
3140 GUI. Keys are used as if they were coming from the
3141 terminal. Other flags are not used. *E980*
3142 When a CTRL-C interrupts and 't' is included it sets
3143 the internal "got_int" flag.
3144 'i' Insert the string instead of appending (see above).
3145 'x' Execute commands until typeahead is empty. This is
3146 similar to using ":normal!". You can call feedkeys()
3147 several times without 'x' and then one time with 'x'
3148 (possibly with an empty {string}) to execute all the
3149 typeahead. Note that when Vim ends in Insert mode it
3150 will behave as if <Esc> is typed, to avoid getting
3151 stuck, waiting for a character to be typed before the
3152 script continues.
3153 Note that if you manage to call feedkeys() while
3154 executing commands, thus calling it recursively, then
3155 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003156 'c' Remove any script context when executing, so that
3157 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003158 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003159 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003160 '!' When used with 'x' will not end Insert mode. Can be
3161 used in a test when a timer is set to exit Insert mode
3162 a little later. Useful for testing CursorHoldI.
3163
3164 Return value is always 0.
3165
3166 Can also be used as a |method|: >
3167 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003168<
Christian Brabandt17ad8522025-05-09 00:03:20 +02003169 Return type: |Number|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003171
Shougo Matsushita60c87432024-06-03 22:59:27 +02003172filecopy({from}, {to}) *filecopy()*
3173 Copy the file pointed to by the name {from} to {to}. The
3174 result is a Number, which is |TRUE| if the file was copied
3175 successfully, and |FALSE| when it failed.
3176 If a file with name {to} already exists, it will fail.
3177 Note that it does not handle directories (yet).
3178
3179 This function is not available in the |sandbox|.
3180
3181 Can also be used as a |method|: >
3182 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003183<
3184 Return type: |Number|
3185
Shougo Matsushita60c87432024-06-03 22:59:27 +02003186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003187filereadable({file}) *filereadable()*
3188 The result is a Number, which is |TRUE| when a file with the
3189 name {file} exists, and can be read. If {file} doesn't exist,
3190 or is a directory, the result is |FALSE|. {file} is any
3191 expression, which is used as a String.
3192 If you don't care about the file being readable you can use
3193 |glob()|.
3194 {file} is used as-is, you may want to expand wildcards first: >
3195 echo filereadable('~/.vimrc')
3196 0
3197 echo filereadable(expand('~/.vimrc'))
3198 1
3199
3200< Can also be used as a |method|: >
3201 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003202<
3203 Return type: |Number|
3204
3205 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003206 Obsolete name: file_readable().
3207
3208
3209filewritable({file}) *filewritable()*
3210 The result is a Number, which is 1 when a file with the
3211 name {file} exists, and can be written. If {file} doesn't
3212 exist, or is not writable, the result is 0. If {file} is a
3213 directory, and we can write to it, the result is 2.
3214
3215 Can also be used as a |method|: >
3216 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003217<
3218 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003219
3220
3221filter({expr1}, {expr2}) *filter()*
3222 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3223 For each item in {expr1} evaluate {expr2} and when the result
3224 is zero or false remove the item from the |List| or
3225 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003226 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003227
3228 {expr2} must be a |string| or |Funcref|.
3229
3230 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3231 of the current item. For a |Dictionary| |v:key| has the key
3232 of the current item and for a |List| |v:key| has the index of
3233 the current item. For a |Blob| |v:key| has the index of the
3234 current byte. For a |String| |v:key| has the index of the
3235 current character.
3236 Examples: >
3237 call filter(mylist, 'v:val !~ "OLD"')
3238< Removes the items where "OLD" appears. >
3239 call filter(mydict, 'v:key >= 8')
3240< Removes the items with a key below 8. >
3241 call filter(var, 0)
3242< Removes all the items, thus clears the |List| or |Dictionary|.
3243
3244 Note that {expr2} is the result of expression and is then
3245 used as an expression again. Often it is good to use a
3246 |literal-string| to avoid having to double backslashes.
3247
3248 If {expr2} is a |Funcref| it must take two arguments:
3249 1. the key or the index of the current item.
3250 2. the value of the current item.
3251 The function must return |TRUE| if the item should be kept.
3252 Example that keeps the odd items of a list: >
3253 func Odd(idx, val)
3254 return a:idx % 2 == 1
3255 endfunc
3256 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003257< It is shorter when using a |lambda|. In |Vim9| syntax: >
3258 call filter(myList, (idx, val) => idx * val <= 42)
3259< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003260 call filter(myList, {idx, val -> idx * val <= 42})
3261< If you do not use "val" you can leave it out: >
3262 call filter(myList, {idx -> idx % 2 == 1})
3263<
3264 In |Vim9| script the result must be true, false, zero or one.
3265 Other values will result in a type error.
3266
3267 For a |List| and a |Dictionary| the operation is done
3268 in-place. If you want it to remain unmodified make a copy
3269 first: >
3270 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3271
3272< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003273 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003274 When an error is encountered while evaluating {expr2} no
3275 further items in {expr1} are processed.
3276 When {expr2} is a Funcref errors inside a function are ignored,
3277 unless it was defined with the "abort" flag.
3278
3279 Can also be used as a |method|: >
3280 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003281<
3282 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3283 depending on {expr1}
3284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003285
3286finddir({name} [, {path} [, {count}]]) *finddir()*
3287 Find directory {name} in {path}. Supports both downwards and
3288 upwards recursive directory searches. See |file-searching|
3289 for the syntax of {path}.
3290
3291 Returns the path of the first found match. When the found
3292 directory is below the current directory a relative path is
3293 returned. Otherwise a full path is returned.
3294 If {path} is omitted or empty then 'path' is used.
3295
3296 If the optional {count} is given, find {count}'s occurrence of
3297 {name} in {path} instead of the first one.
3298 When {count} is negative return all the matches in a |List|.
3299
Bram Moolenaar016188f2022-06-06 20:52:59 +01003300 Returns an empty string if the directory is not found.
3301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003302 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003303
3304 Can also be used as a |method|: >
3305 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003306<
Christian Brabandtb753d802025-04-21 11:31:58 +02003307 Return type: list<string> if {count} is negative, |String|
3308 otherwise
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003310
3311findfile({name} [, {path} [, {count}]]) *findfile()*
3312 Just like |finddir()|, but find a file instead of a directory.
3313 Uses 'suffixesadd'.
3314 Example: >
3315 :echo findfile("tags.vim", ".;")
3316< Searches from the directory of the current file upwards until
3317 it finds the file "tags.vim".
3318
3319 Can also be used as a |method|: >
3320 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003321<
Christian Brabandtb753d802025-04-21 11:31:58 +02003322 Return type: list<string> if {count} is negative, |String|
3323 otherwise
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003325
3326flatten({list} [, {maxdepth}]) *flatten()*
3327 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3328 the result is a |List| without nesting, as if {maxdepth} is
3329 a very large number.
3330 The {list} is changed in place, use |flattennew()| if you do
3331 not want that.
3332 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003333 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003334 *E900*
3335 {maxdepth} means how deep in nested lists changes are made.
3336 {list} is not modified when {maxdepth} is 0.
3337 {maxdepth} must be positive number.
3338
3339 If there is an error the number zero is returned.
3340
3341 Example: >
3342 :echo flatten([1, [2, [3, 4]], 5])
3343< [1, 2, 3, 4, 5] >
3344 :echo flatten([1, [2, [3, 4]], 5], 1)
3345< [1, 2, [3, 4], 5]
3346
3347 Can also be used as a |method|: >
3348 mylist->flatten()
3349<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003350 Return type: list<{type}>
3351
3352
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003353flattennew({list} [, {maxdepth}]) *flattennew()*
3354 Like |flatten()| but first make a copy of {list}.
3355
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003356 Return type: list<{type}>
3357
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003358
3359float2nr({expr}) *float2nr()*
3360 Convert {expr} to a Number by omitting the part after the
3361 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003362 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003363 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003364 When the value of {expr} is out of range for a |Number| the
3365 result is truncated to 0x7fffffff or -0x7fffffff (or when
3366 64-bit Number support is enabled, 0x7fffffffffffffff or
3367 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3368 64-bit Number support is enabled, -0x8000000000000000).
3369 Examples: >
3370 echo float2nr(3.95)
3371< 3 >
3372 echo float2nr(-23.45)
3373< -23 >
3374 echo float2nr(1.0e100)
3375< 2147483647 (or 9223372036854775807) >
3376 echo float2nr(-1.0e150)
3377< -2147483647 (or -9223372036854775807) >
3378 echo float2nr(1.0e-100)
3379< 0
3380
3381 Can also be used as a |method|: >
3382 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003383<
3384 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003385
3386
3387floor({expr}) *floor()*
3388 Return the largest integral value less than or equal to
3389 {expr} as a |Float| (round down).
3390 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003391 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003392 Examples: >
3393 echo floor(1.856)
3394< 1.0 >
3395 echo floor(-5.456)
3396< -6.0 >
3397 echo floor(4.0)
3398< 4.0
3399
3400 Can also be used as a |method|: >
3401 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003402<
3403 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003404
3405
3406fmod({expr1}, {expr2}) *fmod()*
3407 Return the remainder of {expr1} / {expr2}, even if the
3408 division is not representable. Returns {expr1} - i * {expr2}
3409 for some integer i such that if {expr2} is non-zero, the
3410 result has the same sign as {expr1} and magnitude less than
3411 the magnitude of {expr2}. If {expr2} is zero, the value
3412 returned is zero. The value returned is a |Float|.
3413 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003414 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3415 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003416 Examples: >
3417 :echo fmod(12.33, 1.22)
3418< 0.13 >
3419 :echo fmod(-12.33, 1.22)
3420< -0.13
3421
3422 Can also be used as a |method|: >
3423 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003424<
3425 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003426
3427
3428fnameescape({string}) *fnameescape()*
3429 Escape {string} for use as file name command argument. All
3430 characters that have a special meaning, such as '%' and '|'
3431 are escaped with a backslash.
3432 For most systems the characters escaped are
3433 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3434 appears in a filename, it depends on the value of 'isfname'.
3435 A leading '+' and '>' is also escaped (special after |:edit|
3436 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003437 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003438 Example: >
3439 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003440 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003441< results in executing: >
3442 edit \+some\ str\%nge\|name
3443<
3444 Can also be used as a |method|: >
3445 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003446<
3447 Return type: |String|
3448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003449
3450fnamemodify({fname}, {mods}) *fnamemodify()*
3451 Modify file name {fname} according to {mods}. {mods} is a
3452 string of characters like it is used for file names on the
3453 command line. See |filename-modifiers|.
3454 Example: >
3455 :echo fnamemodify("main.c", ":p:h")
3456< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003457 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003458< If {mods} is empty or an unsupported modifier is used then
3459 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003460 When {fname} is empty then with {mods} ":h" returns ".", so
3461 that `:cd` can be used with it. This is different from
3462 expand('%:h') without a buffer name, which returns an empty
3463 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003464 Note: Environment variables don't work in {fname}, use
3465 |expand()| first then.
3466
3467 Can also be used as a |method|: >
3468 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003469<
3470 Return type: |String|
3471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003472
3473foldclosed({lnum}) *foldclosed()*
3474 The result is a Number. If the line {lnum} is in a closed
3475 fold, the result is the number of the first line in that fold.
3476 If the line {lnum} is not in a closed fold, -1 is returned.
3477 {lnum} is used like with |getline()|. Thus "." is the current
3478 line, "'m" mark m, etc.
3479
3480 Can also be used as a |method|: >
3481 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003482<
3483 Return type: |Number|
3484
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003485
3486foldclosedend({lnum}) *foldclosedend()*
3487 The result is a Number. If the line {lnum} is in a closed
3488 fold, the result is the number of the last line in that fold.
3489 If the line {lnum} is not in a closed fold, -1 is returned.
3490 {lnum} is used like with |getline()|. Thus "." is the current
3491 line, "'m" mark m, etc.
3492
3493 Can also be used as a |method|: >
3494 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003495<
3496 Return type: |Number|
3497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003498
3499foldlevel({lnum}) *foldlevel()*
3500 The result is a Number, which is the foldlevel of line {lnum}
3501 in the current buffer. For nested folds the deepest level is
3502 returned. If there is no fold at line {lnum}, zero is
3503 returned. It doesn't matter if the folds are open or closed.
3504 When used while updating folds (from 'foldexpr') -1 is
3505 returned for lines where folds are still to be updated and the
3506 foldlevel is unknown. As a special case the level of the
3507 previous line is usually available.
3508 {lnum} is used like with |getline()|. Thus "." is the current
3509 line, "'m" mark m, etc.
3510
3511 Can also be used as a |method|: >
3512 GetLnum()->foldlevel()
3513<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003514 Return type: |Number|
3515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003516 *foldtext()*
3517foldtext() Returns a String, to be displayed for a closed fold. This is
3518 the default function used for the 'foldtext' option and should
3519 only be called from evaluating 'foldtext'. It uses the
3520 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3521 The returned string looks like this: >
3522 +-- 45 lines: abcdef
3523< The number of leading dashes depends on the foldlevel. The
3524 "45" is the number of lines in the fold. "abcdef" is the text
3525 in the first non-blank line of the fold. Leading white space,
3526 "//" or "/*" and the text from the 'foldmarker' and
3527 'commentstring' options is removed.
3528 When used to draw the actual foldtext, the rest of the line
3529 will be filled with the fold char from the 'fillchars'
3530 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003531 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003532
3533 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003534 {not available when compiled without the |+folding| feature}
3535
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003537foldtextresult({lnum}) *foldtextresult()*
3538 Returns the text that is displayed for the closed fold at line
3539 {lnum}. Evaluates 'foldtext' in the appropriate context.
3540 When there is no closed fold at {lnum} an empty string is
3541 returned.
3542 {lnum} is used like with |getline()|. Thus "." is the current
3543 line, "'m" mark m, etc.
3544 Useful when exporting folded text, e.g., to HTML.
3545 {not available when compiled without the |+folding| feature}
3546
3547
3548 Can also be used as a |method|: >
3549 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003550<
3551 Return type: |String|
3552
Ernie Raele79e2072024-01-13 11:47:33 +01003553
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003554foreach({expr1}, {expr2}) *foreach()* *E1525*
3555 {expr1} must be a |List|, |Tuple|, |String|, |Blob| or
3556 |Dictionary|.
Ernie Raele79e2072024-01-13 11:47:33 +01003557 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003558 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003559 See |map()| and |filter()| to modify {expr1}.
3560
3561 {expr2} must be a |string| or |Funcref|.
3562
3563 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3564 of the current item. For a |Dictionary| |v:key| has the key
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003565 of the current item and for a |List| or a |Tuple| |v:key| has
3566 the index of the current item. For a |Blob| |v:key| has the
3567 index of the current byte. For a |String| |v:key| has the
3568 index of the current character.
Ernie Raele79e2072024-01-13 11:47:33 +01003569 Examples: >
3570 call foreach(mylist, 'used[v:val] = true')
3571< This records the items that are in the {expr1} list.
3572
3573 Note that {expr2} is the result of expression and is then used
3574 as a command. Often it is good to use a |literal-string| to
3575 avoid having to double backslashes.
3576
3577 If {expr2} is a |Funcref| it must take two arguments:
3578 1. the key or the index of the current item.
3579 2. the value of the current item.
3580 With a legacy script lambda you don't get an error if it only
3581 accepts one argument, but with a Vim9 lambda you get "E1106:
3582 One argument too many", the number of arguments must match.
3583 If the function returns a value, it is ignored.
3584
3585 Returns {expr1} in all cases.
3586 When an error is encountered while executing {expr2} no
3587 further items in {expr1} are processed.
3588 When {expr2} is a Funcref errors inside a function are ignored,
3589 unless it was defined with the "abort" flag.
3590
3591 Can also be used as a |method|: >
3592 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003593<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003594 Return type: |String|, |Blob|, list<{type}>, tuple<{type}> or
3595 dict<{type}> depending on {expr1}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003597 *foreground()*
3598foreground() Move the Vim window to the foreground. Useful when sent from
3599 a client to a Vim server. |remote_send()|
3600 On Win32 systems this might not work, the OS does not always
3601 allow a window to bring itself to the foreground. Use
3602 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003603
3604 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003605 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003606 Win32 console version}
3607
Bram Moolenaaraa534142022-09-15 21:46:02 +01003608fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003609 Get the full command name from a short abbreviated command
3610 name; see |20.2| for details on command abbreviations.
3611
3612 The string argument {name} may start with a `:` and can
3613 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003614 Returns an empty string if a command doesn't exist, if it's
3615 ambiguous (for user-defined commands) or cannot be shortened
3616 this way. |vim9-no-shorten|
3617
3618 Without the {vim9} argument uses the current script version.
3619 If {vim9} is present and FALSE then legacy script rules are
3620 used. When {vim9} is present and TRUE then Vim9 rules are
3621 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003622
3623 For example `fullcommand('s')`, `fullcommand('sub')`,
3624 `fullcommand(':%substitute')` all return "substitute".
3625
3626 Can also be used as a |method|: >
3627 GetName()->fullcommand()
3628<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003629 Return type: |String|
3630
3631
3632funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003633 Just like |function()|, but the returned Funcref will lookup
3634 the function by reference, not by name. This matters when the
3635 function {name} is redefined later.
3636
3637 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003638 It only works for an autoloaded function if it has already
3639 been loaded (to avoid mistakenly loading the autoload script
3640 when only intending to use the function name, use |function()|
3641 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003642 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003643
3644 Can also be used as a |method|: >
3645 GetFuncname()->funcref([arg])
3646<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003647 Return type: func(...): any or |Number| on error
3648
Dominique Pellee764d1b2023-03-12 21:20:59 +00003649 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003650function({name} [, {arglist}] [, {dict}])
3651 Return a |Funcref| variable that refers to function {name}.
3652 {name} can be the name of a user defined function or an
3653 internal function.
3654
3655 {name} can also be a Funcref or a partial. When it is a
3656 partial the dict stored in it will be used and the {dict}
3657 argument is not allowed. E.g.: >
3658 let FuncWithArg = function(dict.Func, [arg])
3659 let Broken = function(dict.Func, [arg], dict)
3660<
3661 When using the Funcref the function will be found by {name},
3662 also when it was redefined later. Use |funcref()| to keep the
3663 same function.
3664
3665 When {arglist} or {dict} is present this creates a partial.
3666 That means the argument list and/or the dictionary is stored in
3667 the Funcref and will be used when the Funcref is called.
3668
3669 The arguments are passed to the function in front of other
3670 arguments, but after any argument from |method|. Example: >
3671 func Callback(arg1, arg2, name)
3672 ...
3673 let Partial = function('Callback', ['one', 'two'])
3674 ...
3675 call Partial('name')
3676< Invokes the function as with: >
3677 call Callback('one', 'two', 'name')
3678
3679< With a |method|: >
3680 func Callback(one, two, three)
3681 ...
3682 let Partial = function('Callback', ['two'])
3683 ...
3684 eval 'one'->Partial('three')
3685< Invokes the function as with: >
3686 call Callback('one', 'two', 'three')
3687
3688< The function() call can be nested to add more arguments to the
3689 Funcref. The extra arguments are appended to the list of
3690 arguments. Example: >
3691 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003692 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003693 let Func = function('Callback', ['one'])
3694 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003695 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003696 call Func2('name')
3697< Invokes the function as with: >
3698 call Callback('one', 'two', 'name')
3699
3700< The Dictionary is only useful when calling a "dict" function.
3701 In that case the {dict} is passed in as "self". Example: >
3702 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003703 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003704 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003705 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003706 let context = {"name": "example"}
3707 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003708 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003709 call Func() " will echo: called for example
3710< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003711 arguments, these two are equivalent, if Callback() is defined
3712 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003713 let Func = function('Callback', context)
3714 let Func = context.Callback
3715
3716< The argument list and the Dictionary can be combined: >
3717 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003718 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003719 let context = {"name": "example"}
3720 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003721 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722 call Func(500)
3723< Invokes the function as with: >
3724 call context.Callback('one', 500)
3725<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003726 Returns 0 on error.
3727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003728 Can also be used as a |method|: >
3729 GetFuncname()->function([arg])
3730
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003731<
3732 Return type: func(...): any or |Number| on error
3733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003734
3735garbagecollect([{atexit}]) *garbagecollect()*
3736 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3737 that have circular references.
3738
3739 There is hardly ever a need to invoke this function, as it is
3740 automatically done when Vim runs out of memory or is waiting
3741 for the user to press a key after 'updatetime'. Items without
3742 circular references are always freed when they become unused.
3743 This is useful if you have deleted a very big |List| and/or
3744 |Dictionary| with circular references in a script that runs
3745 for a long time.
3746
3747 When the optional {atexit} argument is one, garbage
3748 collection will also be done when exiting Vim, if it wasn't
3749 done before. This is useful when checking for memory leaks.
3750
3751 The garbage collection is not done immediately but only when
3752 it's safe to perform. This is when waiting for the user to
3753 type a character. To force garbage collection immediately use
3754 |test_garbagecollect_now()|.
3755
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003756 Return type: |String|
3757
3758
LemonBoy48b7d052024-07-09 18:24:59 +02003759get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003760 Get item {idx} from |List| {list}. When this item is not
3761 available return {default}. Return zero when {default} is
3762 omitted.
3763 Preferably used as a |method|: >
3764 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003765<
3766 Return type: any, depending on {list}
3767
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01003768get({tuple}, {idx} [, {default}]) *get()-tuple*
3769 Get item {idx} from |Tuple| {tuple}. When this item is not
3770 available return {default}. Return zero when {default} is
3771 omitted.
3772 Preferably used as a |method|: >
3773 mytuple->get(idx)
3774<
3775 Return type: any, depending on {tuple}
3776
LemonBoy48b7d052024-07-09 18:24:59 +02003777get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003778 Get byte {idx} from |Blob| {blob}. When this byte is not
3779 available return {default}. Return -1 when {default} is
3780 omitted.
3781 Preferably used as a |method|: >
3782 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003783<
3784 Return type: |Number|
3785
LemonBoy48b7d052024-07-09 18:24:59 +02003786get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003787 Get item with key {key} from |Dictionary| {dict}. When this
3788 item is not available return {default}. Return zero when
3789 {default} is omitted. Useful example: >
3790 let val = get(g:, 'var_name', 'default')
3791< This gets the value of g:var_name if it exists, and uses
3792 'default' when it does not exist.
3793 Preferably used as a |method|: >
3794 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003795<
h-east84ac2122024-06-17 18:12:30 +02003796 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003797
LemonBoy48b7d052024-07-09 18:24:59 +02003798get({func}, {what}) *get()-func*
3799 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003800 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003801 "name" The function name
3802 "func" The function
3803 "dict" The dictionary
3804 "args" The list with arguments
3805 "arity" A dictionary with information about the number of
3806 arguments accepted by the function (minus the
3807 {arglist}) with the following fields:
3808 required the number of positional arguments
3809 optional the number of optional arguments,
3810 in addition to the required ones
3811 varargs |TRUE| if the function accepts a
3812 variable number of arguments |...|
3813
3814 Note: There is no error, if the {arglist} of
3815 the Funcref contains more arguments than the
3816 Funcref expects, it's not validated.
3817
Bram Moolenaar016188f2022-06-06 20:52:59 +01003818 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003820 Preferably used as a |method|: >
3821 myfunc->get(what)
3822<
LemonBoy48b7d052024-07-09 18:24:59 +02003823 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003824
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003825 *getbufinfo()*
3826getbufinfo([{buf}])
3827getbufinfo([{dict}])
3828 Get information about buffers as a List of Dictionaries.
3829
3830 Without an argument information about all the buffers is
3831 returned.
3832
3833 When the argument is a |Dictionary| only the buffers matching
3834 the specified criteria are returned. The following keys can
3835 be specified in {dict}:
3836 buflisted include only listed buffers.
3837 bufloaded include only loaded buffers.
3838 bufmodified include only modified buffers.
3839
3840 Otherwise, {buf} specifies a particular buffer to return
3841 information for. For the use of {buf}, see |bufname()|
3842 above. If the buffer is found the returned List has one item.
3843 Otherwise the result is an empty list.
3844
3845 Each returned List item is a dictionary with the following
3846 entries:
3847 bufnr Buffer number.
3848 changed TRUE if the buffer is modified.
3849 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003850 command TRUE if the buffer belongs to the
3851 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003852 hidden TRUE if the buffer is hidden.
3853 lastused Timestamp in seconds, like
3854 |localtime()|, when the buffer was
3855 last used.
3856 {only with the |+viminfo| feature}
3857 listed TRUE if the buffer is listed.
3858 lnum Line number used for the buffer when
3859 opened in the current window.
3860 Only valid if the buffer has been
3861 displayed in the window in the past.
3862 If you want the line number of the
3863 last known cursor position in a given
3864 window, use |line()|: >
3865 :echo line('.', {winid})
3866<
3867 linecount Number of lines in the buffer (only
3868 valid when loaded)
3869 loaded TRUE if the buffer is loaded.
3870 name Full path to the file in the buffer.
3871 signs List of signs placed in the buffer.
3872 Each list item is a dictionary with
3873 the following fields:
3874 id sign identifier
3875 lnum line number
3876 name sign name
3877 variables A reference to the dictionary with
3878 buffer-local variables.
3879 windows List of |window-ID|s that display this
3880 buffer
3881 popups List of popup |window-ID|s that
3882 display this buffer
3883
3884 Examples: >
3885 for buf in getbufinfo()
3886 echo buf.name
3887 endfor
3888 for buf in getbufinfo({'buflisted':1})
3889 if buf.changed
3890 ....
3891 endif
3892 endfor
3893<
3894 To get buffer-local options use: >
3895 getbufvar({bufnr}, '&option_name')
3896<
3897 Can also be used as a |method|: >
3898 GetBufnr()->getbufinfo()
3899<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003900 Return type: list<dict<any>>
3901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003902
3903 *getbufline()*
3904getbufline({buf}, {lnum} [, {end}])
3905 Return a |List| with the lines starting from {lnum} to {end}
3906 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003907 |List| with only the line {lnum} is returned. See
3908 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003909
3910 For the use of {buf}, see |bufname()| above.
3911
3912 For {lnum} and {end} "$" can be used for the last line of the
3913 buffer. Otherwise a number must be used.
3914
3915 When {lnum} is smaller than 1 or bigger than the number of
3916 lines in the buffer, an empty |List| is returned.
3917
3918 When {end} is greater than the number of lines in the buffer,
3919 it is treated as {end} is set to the number of lines in the
3920 buffer. When {end} is before {lnum} an empty |List| is
3921 returned.
3922
3923 This function works only for loaded buffers. For unloaded and
3924 non-existing buffers, an empty |List| is returned.
3925
3926 Example: >
3927 :let lines = getbufline(bufnr("myfile"), 1, "$")
3928
3929< Can also be used as a |method|: >
3930 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003931<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003932 Return type: list<string>
3933
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003934 *getbufoneline()*
3935getbufoneline({buf}, {lnum})
3936 Just like `getbufline()` but only get one line and return it
3937 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003938
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003939 Return type: |String|
3940
3941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003942getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3943 The result is the value of option or local buffer variable
3944 {varname} in buffer {buf}. Note that the name without "b:"
3945 must be used.
3946 The {varname} argument is a string.
3947 When {varname} is empty returns a |Dictionary| with all the
3948 buffer-local variables.
3949 When {varname} is equal to "&" returns a |Dictionary| with all
3950 the buffer-local options.
3951 Otherwise, when {varname} starts with "&" returns the value of
3952 a buffer-local option.
3953 This also works for a global or buffer-local option, but it
3954 doesn't work for a global variable, window-local variable or
3955 window-local option.
3956 For the use of {buf}, see |bufname()| above.
3957 When the buffer or variable doesn't exist {def} or an empty
3958 string is returned, there is no error message.
3959 Examples: >
3960 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003961 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003962
3963< Can also be used as a |method|: >
3964 GetBufnr()->getbufvar(varname)
3965<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003966 Return type: any, depending on {varname}
3967
3968
mikoto20001083cae2024-11-11 21:24:14 +01003969getcellpixels() *getcellpixels()*
3970 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003971 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003972
3973 Only works on Unix (terminal and gVim) and Windows (gVim only).
3974 Returns [] on other systems or on failure.
3975 Note that there could be variations across different terminals.
3976 On macOS, system Terminal.app returns sizes in points (before
3977 Retina scaling), whereas third-party terminals return raw pixel
3978 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003979
mikoto2000de094dc2024-11-14 22:13:48 +01003980 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003981
3982
Kota Kato66bb9ae2023-01-17 18:31:56 +00003983getcellwidths() *getcellwidths()*
3984 Returns a |List| of cell widths of character ranges overridden
3985 by |setcellwidths()|. The format is equal to the argument of
3986 |setcellwidths()|. If no character ranges have their cell
3987 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003988
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003989 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003990
3991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003992getchangelist([{buf}]) *getchangelist()*
3993 Returns the |changelist| for the buffer {buf}. For the use
3994 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3995 exist, an empty list is returned.
3996
3997 The returned list contains two entries: a list with the change
3998 locations and the current position in the list. Each
3999 entry in the change list is a dictionary with the following
4000 entries:
4001 col column number
4002 coladd column offset for 'virtualedit'
4003 lnum line number
4004 If buffer {buf} is the current buffer, then the current
4005 position refers to the position in the list. For other
4006 buffers, it is set to the length of the list.
4007
4008 Can also be used as a |method|: >
4009 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004010<
4011 Return type: list<any>
4012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004013
zeertzjqe0a2ab32025-02-02 09:14:35 +01004014getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004015 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01004016 If {expr} is omitted or is -1, wait until a character is
4017 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004018 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004019 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004020 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004021 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01004022 If you prefer always getting a string use |getcharstr()|, or
4023 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004024
Doug Kearns9cd9e752024-04-07 17:42:17 +02004025 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004026 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01004027 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004028 Otherwise a String is returned with the encoded character.
4029 For a special key it's a String with a sequence of bytes
4030 starting with 0x80 (decimal: 128). This is the same value as
4031 the String "\<Key>", e.g., "\<Left>". The returned value is
4032 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01004033 that is not included in the character. |keytrans()| can also
4034 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004035
Doug Kearns9cd9e752024-04-07 17:42:17 +02004036 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004037 while Vim waits to see if this is the start of an escape
4038 sequence.
4039
Doug Kearns9cd9e752024-04-07 17:42:17 +02004040 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004041 one-byte character it is the character itself as a number.
4042 Use nr2char() to convert it to a String.
4043
4044 Use getcharmod() to obtain any additional modifiers.
4045
zeertzjqe0a2ab32025-02-02 09:14:35 +01004046 The optional argument {opts} is a Dict and supports the
4047 following items:
4048
zeertzjqedf0f7d2025-02-02 19:01:01 +01004049 cursor A String specifying cursor behavior
4050 when waiting for a character.
4051 "hide": hide the cursor.
4052 "keep": keep current cursor unchanged.
4053 "msg": move cursor to message area.
4054 (default: "msg")
4055
zeertzjqe0a2ab32025-02-02 09:14:35 +01004056 number If |TRUE|, return a Number when getting
4057 a single character.
4058 If |FALSE|, the return value is always
4059 converted to a String, and an empty
4060 String (instead of 0) is returned when
4061 no character is available.
4062 (default: |TRUE|)
4063
4064 simplify If |TRUE|, include modifiers in the
4065 character if possible. E.g., return
4066 the same value for CTRL-I and <Tab>.
4067 If |FALSE|, don't include modifiers in
4068 the character.
4069 (default: |TRUE|)
4070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004071 When the user clicks a mouse button, the mouse event will be
4072 returned. The position can then be found in |v:mouse_col|,
4073 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
4074 |getmousepos()| can also be used. Mouse move events will be
4075 ignored.
4076 This example positions the mouse as it would normally happen: >
4077 let c = getchar()
4078 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004079 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004080 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00004081 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004082 endif
4083<
4084 When using bracketed paste only the first character is
4085 returned, the rest of the pasted text is dropped.
4086 |xterm-bracketed-paste|.
4087
4088 There is no prompt, you will somehow have to make clear to the
4089 user that a character has to be typed. The screen is not
4090 redrawn, e.g. when resizing the window. When using a popup
4091 window it should work better with a |popup-filter|.
4092
4093 There is no mapping for the character.
4094 Key codes are replaced, thus when the user presses the <Del>
4095 key you get the code for the <Del> key, not the raw character
4096 sequence. Examples: >
4097 getchar() == "\<Del>"
4098 getchar() == "\<S-Left>"
4099< This example redefines "f" to ignore case: >
4100 :nmap f :call FindChar()<CR>
4101 :function FindChar()
4102 : let c = nr2char(getchar())
4103 : while col('.') < col('$') - 1
4104 : normal l
4105 : if getline('.')[col('.') - 1] ==? c
4106 : break
4107 : endif
4108 : endwhile
4109 :endfunction
4110<
4111 You may also receive synthetic characters, such as
4112 |<CursorHold>|. Often you will want to ignore this and get
4113 another character: >
4114 :function GetKey()
4115 : let c = getchar()
4116 : while c == "\<CursorHold>"
4117 : let c = getchar()
4118 : endwhile
4119 : return c
4120 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004121<
4122 Return type: |Number| or |String|
4123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004124
4125getcharmod() *getcharmod()*
4126 The result is a Number which is the state of the modifiers for
4127 the last obtained character with getchar() or in another way.
4128 These values are added together:
4129 2 shift
4130 4 control
4131 8 alt (meta)
4132 16 meta (when it's different from ALT)
4133 32 mouse double click
4134 64 mouse triple click
4135 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004136 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004137 Only the modifiers that have not been included in the
4138 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004139 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004140
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004141 Return type: |Number|
4142
4143
4144getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004145 Get the position for String {expr}. Same as |getpos()| but the
4146 column number in the returned List is a character index
4147 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004148 If |getpos()| returns a very large column number, equal to
4149 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004150 of the last character.
4151
4152 Example:
4153 With the cursor on '세' in line 5 with text "여보세요": >
4154 getcharpos('.') returns [0, 5, 3, 0]
4155 getpos('.') returns [0, 5, 7, 0]
4156<
4157 Can also be used as a |method|: >
4158 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004159<
4160 Return type: list<number>
4161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004162
4163getcharsearch() *getcharsearch()*
4164 Return the current character search information as a {dict}
4165 with the following entries:
4166
4167 char character previously used for a character
4168 search (|t|, |f|, |T|, or |F|); empty string
4169 if no character search has been performed
4170 forward direction of character search; 1 for forward,
4171 0 for backward
4172 until type of character search; 1 for a |t| or |T|
4173 character search, 0 for an |f| or |F|
4174 character search
4175
4176 This can be useful to always have |;| and |,| search
4177 forward/backward regardless of the direction of the previous
4178 character search: >
4179 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4180 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4181< Also see |setcharsearch()|.
4182
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004183 Return type: dict<any>
4184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004185
zeertzjqe0a2ab32025-02-02 09:14:35 +01004186getcharstr([{expr} [, {opts}]]) *getcharstr()*
4187 The same as |getchar()|, except that this always returns a
4188 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004189
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004190 Return type: |String|
4191
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004192getcmdcomplpat() *getcmdcomplpat()*
4193 Return completion pattern of the current command-line.
4194 Only works when the command line is being edited, thus
4195 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4196 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4197 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4198 Returns an empty string when completion is not defined.
4199
4200 Return type: |String|
4201
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004202
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004203getcmdcompltype() *getcmdcompltype()*
4204 Return the type of the current command-line completion.
4205 Only works when the command line is being edited, thus
4206 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004207 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004208 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004209 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004210 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004212 Return type: |String|
4213
4214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004216 Return the current command-line input. Only works when the
4217 command line is being edited, thus requires use of
4218 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004219 Example: >
4220 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004221< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4222 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004223 Returns an empty string when entering a password or using
4224 |inputsecret()|.
4225
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004226 Return type: |String|
4227
4228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004229getcmdpos() *getcmdpos()*
4230 Return the position of the cursor in the command line as a
4231 byte count. The first column is 1.
4232 Only works when editing the command line, thus requires use of
4233 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4234 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004235 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4236 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004237
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004238 Return type: |Number|
4239
4240
Shougo Matsushita69084282024-09-23 20:34:47 +02004241getcmdprompt() *getcmdprompt()*
4242 Return the current command-line prompt when using functions
4243 like |input()| or |confirm()|.
4244 Only works when the command line is being edited, thus
4245 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4246 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4247 |setcmdpos()| and |setcmdline()|.
4248
4249 Return type: |String|
4250
4251
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004252getcmdscreenpos() *getcmdscreenpos()*
4253 Return the screen position of the cursor in the command line
4254 as a byte count. The first column is 1.
4255 Instead of |getcmdpos()|, it adds the prompt position.
4256 Only works when editing the command line, thus requires use of
4257 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4258 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004259 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4260 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004261
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004262 Return type: |Number|
4263
4264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004265getcmdtype() *getcmdtype()*
4266 Return the current command-line type. Possible return values
4267 are:
4268 : normal Ex command
4269 > debug mode command |debug-mode|
4270 / forward search command
4271 ? backward search command
4272 @ |input()| command
4273 - |:insert| or |:append| command
4274 = |i_CTRL-R_=|
4275 Only works when editing the command line, thus requires use of
4276 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4277 Returns an empty string otherwise.
4278 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4279
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004280 Return type: |String|
4281
4282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004283getcmdwintype() *getcmdwintype()*
4284 Return the current |command-line-window| type. Possible return
4285 values are the same as |getcmdtype()|. Returns an empty string
4286 when not in the command-line window.
4287
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004288 Return type: |String|
4289
4290
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004291getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4292 Return a list of command-line completion matches. The String
4293 {type} argument specifies what for. The following completion
4294 types are supported:
4295
4296 arglist file names in argument list
4297 augroup autocmd groups
4298 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004299 behave |:behave| suboptions
4300 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004301 color color schemes
4302 command Ex command
4303 cmdline |cmdline-completion| result
4304 compiler compilers
4305 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004306 custom,{func} custom completion, defined via {func}
4307 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004308 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004309 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004310 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004311 environment environment variable names
4312 event autocommand events
4313 expression Vim expression
4314 file file and directory names
4315 file_in_path file and directory names in |'path'|
4316 filetype filetype names |'filetype'|
Christian Brabandta3422aa2025-04-23 21:04:24 +02004317 filetypecmd |:filetype| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004318 function function name
4319 help help subjects
4320 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004321 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004322 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004323 locale locale names (as output of locale -a)
4324 mapclear buffer argument
4325 mapping mapping name
4326 menu menus
4327 messages |:messages| suboptions
4328 option options
4329 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004330 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004331 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004332 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004333 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004334 sign |:sign| suboptions
4335 syntax syntax file names |'syntax'|
4336 syntime |:syntime| suboptions
4337 tag tags
4338 tag_listfiles tags, file names
4339 user user names
4340 var user variables
4341
4342 If {pat} is an empty string, then all the matches are
4343 returned. Otherwise only items matching {pat} are returned.
4344 See |wildcards| for the use of special characters in {pat}.
4345
4346 If the optional {filtered} flag is set to 1, then 'wildignore'
4347 is applied to filter the results. Otherwise all the matches
4348 are returned. The 'wildignorecase' option always applies.
4349
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004350 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4351 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004352 regular expression matching is used. Thus this function
4353 follows the user preference, what happens on the command line.
4354 If you do not want this you can make 'wildoptions' empty
4355 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004357 If {type} is "cmdline", then the |cmdline-completion| result is
4358 returned. For example, to complete the possible values after
4359 a ":call" command: >
4360 echo getcompletion('call ', 'cmdline')
4361<
4362 If there are no matches, an empty list is returned. An
4363 invalid value for {type} produces an error.
4364
4365 Can also be used as a |method|: >
4366 GetPattern()->getcompletion('color')
4367<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004368 Return type: list<string>
4369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004370 *getcurpos()*
4371getcurpos([{winid}])
4372 Get the position of the cursor. This is like getpos('.'), but
4373 includes an extra "curswant" item in the list:
4374 [0, lnum, col, off, curswant] ~
4375 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004376 cursor vertically. After |$| command it will be a very large
4377 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004378 |getpos()|.
4379 The first "bufnum" item is always zero. The byte position of
4380 the cursor is returned in 'col'. To get the character
4381 position, use |getcursorcharpos()|.
4382
4383 The optional {winid} argument can specify the window. It can
4384 be the window number or the |window-ID|. The last known
4385 cursor position is returned, this may be invalid for the
4386 current value of the buffer if it is not the current window.
4387 If {winid} is invalid a list with zeroes is returned.
4388
4389 This can be used to save and restore the cursor position: >
4390 let save_cursor = getcurpos()
4391 MoveTheCursorAround
4392 call setpos('.', save_cursor)
4393< Note that this only works within the window. See
4394 |winrestview()| for restoring more state.
4395
4396 Can also be used as a |method|: >
4397 GetWinid()->getcurpos()
4398<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004399 Return type: list<number>
4400
4401
4402getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004403 Same as |getcurpos()| but the column number in the returned
4404 List is a character index instead of a byte index.
4405
4406 Example:
4407 With the cursor on '보' in line 3 with text "여보세요": >
4408 getcursorcharpos() returns [0, 3, 2, 0, 3]
4409 getcurpos() returns [0, 3, 4, 0, 3]
4410<
4411 Can also be used as a |method|: >
4412 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004413<
4414 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004415
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004416
4417getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004418 The result is a String, which is the name of the current
4419 working directory. 'autochdir' is ignored.
4420
4421 With {winnr} return the local current directory of this window
4422 in the current tab page. {winnr} can be the window number or
4423 the |window-ID|.
4424 If {winnr} is -1 return the name of the global working
4425 directory. See also |haslocaldir()|.
4426
4427 With {winnr} and {tabnr} return the local current directory of
4428 the window in the specified tab page. If {winnr} is -1 return
4429 the working directory of the tabpage.
4430 If {winnr} is zero use the current window, if {tabnr} is zero
4431 use the current tabpage.
4432 Without any arguments, return the actual working directory of
4433 the current window.
4434 Return an empty string if the arguments are invalid.
4435
4436 Examples: >
4437 " Get the working directory of the current window
4438 :echo getcwd()
4439 :echo getcwd(0)
4440 :echo getcwd(0, 0)
4441 " Get the working directory of window 3 in tabpage 2
4442 :echo getcwd(3, 2)
4443 " Get the global working directory
4444 :echo getcwd(-1)
4445 " Get the working directory of tabpage 3
4446 :echo getcwd(-1, 3)
4447 " Get the working directory of current tabpage
4448 :echo getcwd(-1, 0)
4449
4450< Can also be used as a |method|: >
4451 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004452<
4453 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004454
4455getenv({name}) *getenv()*
4456 Return the value of environment variable {name}. The {name}
4457 argument is a string, without a leading '$'. Example: >
4458 myHome = getenv('HOME')
4459
4460< When the variable does not exist |v:null| is returned. That
4461 is different from a variable set to an empty string, although
4462 some systems interpret the empty value as the variable being
4463 deleted. See also |expr-env|.
4464
4465 Can also be used as a |method|: >
4466 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004467<
4468 Return type: |String| or |Number|
4469
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004470
4471getfontname([{name}]) *getfontname()*
4472 Without an argument returns the name of the normal font being
4473 used. Like what is used for the Normal highlight group
4474 |hl-Normal|.
4475 With an argument a check is done whether String {name} is a
4476 valid font name. If not then an empty string is returned.
4477 Otherwise the actual font name is returned, or {name} if the
4478 GUI does not support obtaining the real name.
4479 Only works when the GUI is running, thus not in your vimrc or
4480 gvimrc file. Use the |GUIEnter| autocommand to use this
4481 function just after the GUI has started.
4482 Note that the GTK GUI accepts any font name, thus checking for
4483 a valid name does not work.
4484
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004485 Return type: |String|
4486
4487
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004488getfperm({fname}) *getfperm()*
4489 The result is a String, which is the read, write, and execute
4490 permissions of the given file {fname}.
4491 If {fname} does not exist or its directory cannot be read, an
4492 empty string is returned.
4493 The result is of the form "rwxrwxrwx", where each group of
4494 "rwx" flags represent, in turn, the permissions of the owner
4495 of the file, the group the file belongs to, and other users.
4496 If a user does not have a given permission the flag for this
4497 is replaced with the string "-". Examples: >
4498 :echo getfperm("/etc/passwd")
4499 :echo getfperm(expand("~/.vimrc"))
4500< This will hopefully (from a security point of view) display
4501 the string "rw-r--r--" or even "rw-------".
4502
4503 Can also be used as a |method|: >
4504 GetFilename()->getfperm()
4505<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004506 Return type: |String|
4507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004508 For setting permissions use |setfperm()|.
4509
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004511getfsize({fname}) *getfsize()*
4512 The result is a Number, which is the size in bytes of the
4513 given file {fname}.
4514 If {fname} is a directory, 0 is returned.
4515 If the file {fname} can't be found, -1 is returned.
4516 If the size of {fname} is too big to fit in a Number then -2
4517 is returned.
4518
4519 Can also be used as a |method|: >
4520 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004521<
4522 Return type: |Number|
4523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004524
4525getftime({fname}) *getftime()*
4526 The result is a Number, which is the last modification time of
4527 the given file {fname}. The value is measured as seconds
4528 since 1st Jan 1970, and may be passed to strftime(). See also
4529 |localtime()| and |strftime()|.
4530 If the file {fname} can't be found -1 is returned.
4531
4532 Can also be used as a |method|: >
4533 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004534<
4535 Return type: |Number|
4536
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004537
4538getftype({fname}) *getftype()*
4539 The result is a String, which is a description of the kind of
4540 file of the given file {fname}.
4541 If {fname} does not exist an empty string is returned.
4542 Here is a table over different kinds of files and their
4543 results:
4544 Normal file "file"
4545 Directory "dir"
4546 Symbolic link "link"
4547 Block device "bdev"
4548 Character device "cdev"
4549 Socket "socket"
4550 FIFO "fifo"
4551 All other "other"
4552 Example: >
4553 getftype("/home")
4554< Note that a type such as "link" will only be returned on
4555 systems that support it. On some systems only "dir" and
4556 "file" are returned. On MS-Windows a symbolic link to a
4557 directory returns "dir" instead of "link".
4558
4559 Can also be used as a |method|: >
4560 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004561<
4562 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004563
4564getimstatus() *getimstatus()*
4565 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004566 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004567 See 'imstatusfunc'.
4568
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004569 Return type: |Number|
4570
4571
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004572getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4573 Returns the |jumplist| for the specified window.
4574
4575 Without arguments use the current window.
4576 With {winnr} only use this window in the current tab page.
4577 {winnr} can also be a |window-ID|.
4578 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004579 page. If {winnr} or {tabnr} is invalid, an empty list is
4580 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004581
4582 The returned list contains two entries: a list with the jump
4583 locations and the last used jump position number in the list.
4584 Each entry in the jump location list is a dictionary with
4585 the following entries:
4586 bufnr buffer number
4587 col column number
4588 coladd column offset for 'virtualedit'
4589 filename filename if available
4590 lnum line number
4591
4592 Can also be used as a |method|: >
4593 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004594<
4595 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004596
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004597 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004598getline({lnum} [, {end}])
4599 Without {end} the result is a String, which is line {lnum}
4600 from the current buffer. Example: >
4601 getline(1)
4602< When {lnum} is a String that doesn't start with a
4603 digit, |line()| is called to translate the String into a Number.
4604 To get the line under the cursor: >
4605 getline(".")
4606< When {lnum} is a number smaller than 1 or bigger than the
4607 number of lines in the buffer, an empty string is returned.
4608
4609 When {end} is given the result is a |List| where each item is
4610 a line from the current buffer in the range {lnum} to {end},
4611 including line {end}.
4612 {end} is used in the same way as {lnum}.
4613 Non-existing lines are silently omitted.
4614 When {end} is before {lnum} an empty |List| is returned.
4615 Example: >
4616 :let start = line('.')
4617 :let end = search("^$") - 1
4618 :let lines = getline(start, end)
4619
4620< Can also be used as a |method|: >
4621 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004622<
4623 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004624
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004625 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004626 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004627
4628getloclist({nr} [, {what}]) *getloclist()*
4629 Returns a |List| with all the entries in the location list for
4630 window {nr}. {nr} can be the window number or the |window-ID|.
4631 When {nr} is zero the current window is used.
4632
4633 For a location list window, the displayed location list is
4634 returned. For an invalid window number {nr}, an empty list is
4635 returned. Otherwise, same as |getqflist()|.
4636
4637 If the optional {what} dictionary argument is supplied, then
4638 returns the items listed in {what} as a dictionary. Refer to
4639 |getqflist()| for the supported items in {what}.
4640
4641 In addition to the items supported by |getqflist()| in {what},
4642 the following item is supported by |getloclist()|:
4643
4644 filewinid id of the window used to display files
4645 from the location list. This field is
4646 applicable only when called from a
4647 location list window. See
4648 |location-list-file-window| for more
4649 details.
4650
4651 Returns a |Dictionary| with default values if there is no
4652 location list for the window {nr}.
4653 Returns an empty Dictionary if window {nr} does not exist.
4654
4655 Examples (See also |getqflist-examples|): >
4656 :echo getloclist(3, {'all': 0})
4657 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004658<
4659 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004660
4661
4662getmarklist([{buf}]) *getmarklist()*
4663 Without the {buf} argument returns a |List| with information
4664 about all the global marks. |mark|
4665
4666 If the optional {buf} argument is specified, returns the
4667 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004668 see |bufname()|. If {buf} is invalid, an empty list is
4669 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004670
4671 Each item in the returned List is a |Dict| with the following:
4672 mark name of the mark prefixed by "'"
4673 pos a |List| with the position of the mark:
4674 [bufnum, lnum, col, off]
4675 Refer to |getpos()| for more information.
4676 file file name
4677
4678 Refer to |getpos()| for getting information about a specific
4679 mark.
4680
4681 Can also be used as a |method|: >
4682 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004683<
4684 Return type: list<dict<any>> or list<any>
4685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004686
4687getmatches([{win}]) *getmatches()*
4688 Returns a |List| with all matches previously defined for the
4689 current window by |matchadd()| and the |:match| commands.
4690 |getmatches()| is useful in combination with |setmatches()|,
4691 as |setmatches()| can restore a list of matches saved by
4692 |getmatches()|.
4693 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004694 window ID instead of the current window. If {win} is invalid,
4695 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004696 Example: >
4697 :echo getmatches()
4698< [{'group': 'MyGroup1', 'pattern': 'TODO',
4699 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4700 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4701 :let m = getmatches()
4702 :call clearmatches()
4703 :echo getmatches()
4704< [] >
4705 :call setmatches(m)
4706 :echo getmatches()
4707< [{'group': 'MyGroup1', 'pattern': 'TODO',
4708 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4709 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4710 :unlet m
4711<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004712 Return type: list<dict<any>> or list<any>
4713
4714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004715getmousepos() *getmousepos()*
4716 Returns a |Dictionary| with the last known position of the
4717 mouse. This can be used in a mapping for a mouse click or in
4718 a filter of a popup window. The items are:
4719 screenrow screen row
4720 screencol screen column
4721 winid Window ID of the click
4722 winrow row inside "winid"
4723 wincol column inside "winid"
4724 line text line inside "winid"
4725 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004726 coladd offset (in screen columns) from the
4727 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004728 All numbers are 1-based.
4729
4730 If not over a window, e.g. when in the command line, then only
4731 "screenrow" and "screencol" are valid, the others are zero.
4732
Naruhiko Nishinobe5bd4d2025-05-14 21:20:28 +02004733 When on the |tabpanel|, "wincol" value is zero.
4734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004735 When on the status line below a window or the vertical
4736 separator right of a window, the "line" and "column" values
4737 are zero.
4738
4739 When the position is after the text then "column" is the
4740 length of the text in bytes plus one.
4741
4742 If the mouse is over a popup window then that window is used.
4743
4744 When using |getchar()| the Vim variables |v:mouse_lnum|,
4745 |v:mouse_col| and |v:mouse_winid| also provide these values.
4746
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004747 Return type: dict<number>
4748
4749
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004750getmouseshape() *getmouseshape()*
4751 Returns the name of the currently showing mouse pointer.
4752 When the |+mouseshape| feature is not supported or the shape
4753 is unknown an empty string is returned.
4754 This function is mainly intended for testing.
4755
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004756 Return type: |String|
4757
4758
4759getpid() *getpid()*
4760 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004761 On Unix and MS-Windows this is a unique number, until Vim
4762 exits.
4763
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004764 Return type: |Number|
4765
4766
4767getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004768 Get the position for String {expr}.
4769 The accepted values for {expr} are: *E1209*
4770 . The cursor position.
4771 $ The last line in the current buffer.
4772 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004773 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004774 w0 First line visible in current window (one if the
4775 display isn't updated, e.g. in silent Ex mode).
4776 w$ Last line visible in current window (this is one
4777 less than "w0" if no lines are visible).
4778 v When not in Visual mode, returns the cursor
4779 position. In Visual mode, returns the other end
4780 of the Visual area. A good way to think about
4781 this is that in Visual mode "v" and "." complement
4782 each other. While "." refers to the cursor
4783 position, "v" refers to where |v_o| would move the
4784 cursor. As a result, you can use "v" and "."
4785 together to work on all of a selection in
4786 characterwise Visual mode. If the cursor is at
4787 the end of a characterwise Visual area, "v" refers
4788 to the start of the same Visual area. And if the
4789 cursor is at the start of a characterwise Visual
4790 area, "v" refers to the end of the same Visual
4791 area. "v" differs from |'<| and |'>| in that it's
4792 updated right away.
4793 Note that a mark in another file can be used. The line number
4794 then applies to another buffer.
4795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004796 The result is a |List| with four numbers:
4797 [bufnum, lnum, col, off]
4798 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4799 is the buffer number of the mark.
4800 "lnum" and "col" are the position in the buffer. The first
4801 column is 1.
4802 The "off" number is zero, unless 'virtualedit' is used. Then
4803 it is the offset in screen columns from the start of the
4804 character. E.g., a position within a <Tab> or after the last
4805 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004806
4807 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004808 The column number in the returned List is the byte position
4809 within the line. To get the character position in the line,
4810 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004811
4812 Note that for '< and '> Visual mode matters: when it is "V"
4813 (visual line mode) the column of '< is zero and the column of
4814 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004815 A very large column number equal to |v:maxcol| can be returned,
4816 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004817 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004819 This can be used to save and restore the position of a mark: >
4820 let save_a_mark = getpos("'a")
4821 ...
4822 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004823<
4824 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004825
4826 Can also be used as a |method|: >
4827 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004828<
4829 Return type: list<number>
4830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004831
4832getqflist([{what}]) *getqflist()*
4833 Returns a |List| with all the current quickfix errors. Each
4834 list item is a dictionary with these entries:
4835 bufnr number of buffer that has the file name, use
4836 bufname() to get the name
4837 module module name
4838 lnum line number in the buffer (first line is 1)
4839 end_lnum
4840 end of line number if the item is multiline
4841 col column number (first column is 1)
4842 end_col end of column number if the item has range
4843 vcol |TRUE|: "col" is visual column
4844 |FALSE|: "col" is byte index
4845 nr error number
h-east84ac2122024-06-17 18:12:30 +02004846 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004847 text description of the error
4848 type type of the error, 'E', '1', etc.
4849 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004850 user_data
4851 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004852 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004853
4854 When there is no error list or it's empty, an empty list is
4855 returned. Quickfix list entries with a non-existing buffer
4856 number are returned with "bufnr" set to zero (Note: some
4857 functions accept buffer number zero for the alternate buffer,
4858 you may need to explicitly check for zero).
4859
4860 Useful application: Find pattern matches in multiple files and
4861 do something with them: >
4862 :vimgrep /theword/jg *.c
4863 :for d in getqflist()
4864 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4865 :endfor
4866<
4867 If the optional {what} dictionary argument is supplied, then
4868 returns only the items listed in {what} as a dictionary. The
4869 following string items are supported in {what}:
4870 changedtick get the total number of changes made
4871 to the list |quickfix-changedtick|
4872 context get the |quickfix-context|
4873 efm errorformat to use when parsing "lines". If
4874 not present, then the 'errorformat' option
4875 value is used.
4876 id get information for the quickfix list with
4877 |quickfix-ID|; zero means the id for the
4878 current list or the list specified by "nr"
4879 idx get information for the quickfix entry at this
4880 index in the list specified by 'id' or 'nr'.
4881 If set to zero, then uses the current entry.
4882 See |quickfix-index|
4883 items quickfix list entries
4884 lines parse a list of lines using 'efm' and return
4885 the resulting entries. Only a |List| type is
4886 accepted. The current quickfix list is not
4887 modified. See |quickfix-parse|.
4888 nr get information for this quickfix list; zero
4889 means the current quickfix list and "$" means
4890 the last quickfix list
4891 qfbufnr number of the buffer displayed in the quickfix
4892 window. Returns 0 if the quickfix buffer is
4893 not present. See |quickfix-buffer|.
4894 size number of entries in the quickfix list
4895 title get the list title |quickfix-title|
4896 winid get the quickfix |window-ID|
4897 all all of the above quickfix properties
4898 Non-string items in {what} are ignored. To get the value of a
4899 particular item, set it to zero.
4900 If "nr" is not present then the current quickfix list is used.
4901 If both "nr" and a non-zero "id" are specified, then the list
4902 specified by "id" is used.
4903 To get the number of lists in the quickfix stack, set "nr" to
4904 "$" in {what}. The "nr" value in the returned dictionary
4905 contains the quickfix stack size.
4906 When "lines" is specified, all the other items except "efm"
4907 are ignored. The returned dictionary contains the entry
4908 "items" with the list of entries.
4909
4910 The returned dictionary contains the following entries:
4911 changedtick total number of changes made to the
4912 list |quickfix-changedtick|
4913 context quickfix list context. See |quickfix-context|
4914 If not present, set to "".
4915 id quickfix list ID |quickfix-ID|. If not
4916 present, set to 0.
4917 idx index of the quickfix entry in the list. If not
4918 present, set to 0.
4919 items quickfix list entries. If not present, set to
4920 an empty list.
4921 nr quickfix list number. If not present, set to 0
4922 qfbufnr number of the buffer displayed in the quickfix
4923 window. If not present, set to 0.
4924 size number of entries in the quickfix list. If not
4925 present, set to 0.
4926 title quickfix list title text. If not present, set
4927 to "".
4928 winid quickfix |window-ID|. If not present, set to 0
4929
4930 Examples (See also |getqflist-examples|): >
4931 :echo getqflist({'all': 1})
4932 :echo getqflist({'nr': 2, 'title': 1})
4933 :echo getqflist({'lines' : ["F1:10:L10"]})
4934<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004935 Return type: list<dict<any>> or list<any>
4936
4937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004938getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4939 The result is a String, which is the contents of register
4940 {regname}. Example: >
4941 :let cliptext = getreg('*')
4942< When register {regname} was not set the result is an empty
4943 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004944 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004945
4946 getreg('=') returns the last evaluated value of the expression
4947 register. (For use in maps.)
4948 getreg('=', 1) returns the expression itself, so that it can
4949 be restored with |setreg()|. For other registers the extra
4950 argument is ignored, thus you can always give it.
4951
4952 If {list} is present and |TRUE|, the result type is changed
4953 to |List|. Each list item is one text line. Use it if you care
4954 about zero bytes possibly present inside register: without
4955 third argument both NLs and zero bytes are represented as NLs
4956 (see |NL-used-for-Nul|).
4957 When the register was not set an empty list is returned.
4958
4959 If {regname} is "", the unnamed register '"' is used.
4960 If {regname} is not specified, |v:register| is used.
4961 In |Vim9-script| {regname} must be one character.
4962
4963 Can also be used as a |method|: >
4964 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004965<
Christian Brabandt17ad8522025-05-09 00:03:20 +02004966 Return type: |String| or list<string> depending on {list}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004968
4969getreginfo([{regname}]) *getreginfo()*
4970 Returns detailed information about register {regname} as a
4971 Dictionary with the following entries:
4972 regcontents List of lines contained in register
4973 {regname}, like
4974 |getreg|({regname}, 1, 1).
4975 regtype the type of register {regname}, as in
4976 |getregtype()|.
4977 isunnamed Boolean flag, v:true if this register
4978 is currently pointed to by the unnamed
4979 register.
4980 points_to for the unnamed register, gives the
4981 single letter name of the register
4982 currently pointed to (see |quotequote|).
4983 For example, after deleting a line
4984 with `dd`, this field will be "1",
4985 which is the register that got the
4986 deleted text.
4987
4988 The {regname} argument is a string. If {regname} is invalid
4989 or not set, an empty Dictionary will be returned.
4990 If {regname} is "" or "@", the unnamed register '"' is used.
4991 If {regname} is not specified, |v:register| is used.
4992 The returned Dictionary can be passed to |setreg()|.
4993 In |Vim9-script| {regname} must be one character.
4994
4995 Can also be used as a |method|: >
4996 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004997<
4998 Return type: dict<any>
4999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005000
Shougo Matsushita19b71882024-02-28 22:48:12 +01005001getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005002 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01005003 buffer.
5004
5005 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005006 See |getpos()| for the format of the list. It's possible
5007 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01005008 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01005009
5010 The optional argument {opts} is a Dict and supports the
5011 following items:
5012
zeertzjqafc22952024-05-24 19:07:12 +02005013 type Specify the region's selection type.
5014 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02005015 except that the width can be omitted
5016 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02005017 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01005018
zeertzjq87410ab2024-03-02 06:00:23 +08005019 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02005020 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08005021 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01005022
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005023 You can get the last selection type by |visualmode()|.
5024 If Visual mode is active, use |mode()| to get the Visual mode
5025 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08005026 This function is useful to get text starting and ending in
5027 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005028
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005029 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005030 Note that:
5031 - Order of {pos1} and {pos2} doesn't matter, it will always
5032 return content from the upper left position to the lower
5033 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08005034 - If 'virtualedit' is enabled and the region is past the end
5035 of the lines, resulting lines are padded with spaces.
5036 - If the region is blockwise and it starts or ends in the
5037 middle of a multi-cell character, it is not included but
5038 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005039 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01005040 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01005041 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01005042 - It is evaluated in current window context, which makes a
5043 difference if the buffer is displayed in a window with
5044 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005045
5046 Examples: >
5047 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01005048 \ <Cmd>echow getregion(
5049 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01005050<
5051 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01005052 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02005053<
5054 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005055
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005056
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005057getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
5058 Same as |getregion()|, but returns a list of positions
5059 describing the buffer text segments bound by {pos1} and
5060 {pos2}.
5061 The segments are a pair of positions for every line: >
5062 [[{start_pos}, {end_pos}], ...]
5063<
5064 The position is a |List| with four numbers:
5065 [bufnum, lnum, col, off]
5066 "bufnum" is the buffer number.
5067 "lnum" and "col" are the position in the buffer. The first
5068 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02005069 If the "off" number of a starting position is non-zero, it is
5070 the offset in screen columns from the start of the character.
5071 E.g., a position within a <Tab> or after the last character.
5072 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02005073 the offset of the character's first cell not included in the
5074 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005075
zeertzjq2b09de92024-05-24 07:48:51 +02005076 Apart from the options supported by |getregion()|, {opts} also
5077 supports the following:
5078
5079 eol If |TRUE|, indicate positions beyond
5080 the end of a line with "col" values
5081 one more than the length of the line.
5082 If |FALSE|, positions are limited
5083 within their lines, and if a line is
5084 empty or the selection is entirely
5085 beyond the end of a line, a "col"
5086 value of 0 is used for both positions.
5087 (default: |FALSE|)
5088
Shougo Matsushitab4757e62024-05-07 20:49:24 +02005089 Can also be used as a |method|: >
5090 getpos('.')->getregionpos(getpos("'a"))
5091<
Christian Brabandt83d74402025-03-19 21:55:59 +01005092 For an example, see the highlight-yank plugin |52.6|
5093
zeertzjqd4d12072024-07-16 20:34:16 +02005094 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005095
5096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005097getregtype([{regname}]) *getregtype()*
5098 The result is a String, which is type of register {regname}.
5099 The value will be one of:
5100 "v" for |characterwise| text
5101 "V" for |linewise| text
5102 "<CTRL-V>{width}" for |blockwise-visual| text
5103 "" for an empty or unknown register
5104 <CTRL-V> is one character with value 0x16.
5105 The {regname} argument is a string. If {regname} is "", the
5106 unnamed register '"' is used. If {regname} is not specified,
5107 |v:register| is used.
5108 In |Vim9-script| {regname} must be one character.
5109
5110 Can also be used as a |method|: >
5111 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005112<
5113 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005114
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005115
Bram Moolenaar71badf92023-04-22 22:40:14 +01005116getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005117 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005118 scripts in the order they were sourced, like what
5119 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005120
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005121 The optional Dict argument {opts} supports the following
5122 optional items:
5123 name Script name match pattern. If specified,
5124 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005125 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005126 "name" are returned.
5127 sid Script ID |<SID>|. If specified, only
5128 information about the script with ID "sid" is
5129 returned and "name" is ignored.
5130
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005131 Each item in the returned List is a |Dict| with the following
5132 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005133 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005134 `import autoload` but was not actually sourced
5135 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005136 functions List of script-local function names defined in
5137 the script. Present only when a particular
5138 script is specified using the "sid" item in
5139 {opts}.
5140 name Vim script file name.
5141 sid Script ID |<SID>|.
5142 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005143 this script name links to, if any, otherwise
5144 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005145 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005146 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005147 specified using the "sid" item in {opts}.
5148 Note that this is a copy, the value of
5149 script-local variables cannot be changed using
5150 this dictionary.
h_east59858792023-10-25 22:47:05 +09005151 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005152
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005153 Examples: >
5154 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005155 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005156<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005157 Return type: list<dict<any>>
5158
5159
ichizok663d18d2025-01-02 18:06:00 +01005160getstacktrace() *getstacktrace()*
5161 Returns the current stack trace of Vim scripts.
5162 Stack trace is a |List|, of which each item is a |Dictionary|
5163 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005164 funcref The funcref if the stack is at a function,
5165 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005166 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005167 stack is at an autocmd event, otherwise this
5168 item is omitted.
5169 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005170 filepath The file path of the script on the stack.
5171
5172 Return type: list<dict<any>>
5173
5174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005175gettabinfo([{tabnr}]) *gettabinfo()*
5176 If {tabnr} is not specified, then information about all the
5177 tab pages is returned as a |List|. Each List item is a
5178 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5179 number and information about that one is returned. If the tab
5180 page does not exist an empty List is returned.
5181
5182 Each List item is a |Dictionary| with the following entries:
5183 tabnr tab page number.
5184 variables a reference to the dictionary with
5185 tabpage-local variables
5186 windows List of |window-ID|s in the tab page.
5187
5188 Can also be used as a |method|: >
5189 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005190<
5191 Return type: list<dict<any>>
5192
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005193
5194gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5195 Get the value of a tab-local variable {varname} in tab page
5196 {tabnr}. |t:var|
5197 Tabs are numbered starting with one.
5198 The {varname} argument is a string. When {varname} is empty a
5199 dictionary with all tab-local variables is returned.
5200 Note that the name without "t:" must be used.
5201 When the tab or variable doesn't exist {def} or an empty
5202 string is returned, there is no error message.
5203
5204 Can also be used as a |method|: >
5205 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005206<
5207 Return type: any, depending on {varname}
5208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005209
5210gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5211 Get the value of window-local variable {varname} in window
5212 {winnr} in tab page {tabnr}.
5213 The {varname} argument is a string. When {varname} is empty a
5214 dictionary with all window-local variables is returned.
5215 When {varname} is equal to "&" get the values of all
5216 window-local options in a |Dictionary|.
5217 Otherwise, when {varname} starts with "&" get the value of a
5218 window-local option.
5219 Note that {varname} must be the name without "w:".
5220 Tabs are numbered starting with one. For the current tabpage
5221 use |getwinvar()|.
5222 {winnr} can be the window number or the |window-ID|.
5223 When {winnr} is zero the current window is used.
5224 This also works for a global option, buffer-local option and
5225 window-local option, but it doesn't work for a global variable
5226 or buffer-local variable.
5227 When the tab, window or variable doesn't exist {def} or an
5228 empty string is returned, there is no error message.
5229 Examples: >
5230 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005231 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005232<
5233 To obtain all window-local variables use: >
5234 gettabwinvar({tabnr}, {winnr}, '&')
5235
5236< Can also be used as a |method|: >
5237 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005238<
5239 Return type: any, depending on {varname}
5240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005241
5242gettagstack([{winnr}]) *gettagstack()*
5243 The result is a Dict, which is the tag stack of window {winnr}.
5244 {winnr} can be the window number or the |window-ID|.
5245 When {winnr} is not specified, the current window is used.
5246 When window {winnr} doesn't exist, an empty Dict is returned.
5247
5248 The returned dictionary contains the following entries:
5249 curidx Current index in the stack. When at
5250 top of the stack, set to (length + 1).
5251 Index of bottom of the stack is 1.
5252 items List of items in the stack. Each item
5253 is a dictionary containing the
5254 entries described below.
5255 length Number of entries in the stack.
5256
5257 Each item in the stack is a dictionary with the following
5258 entries:
5259 bufnr buffer number of the current jump
5260 from cursor position before the tag jump.
5261 See |getpos()| for the format of the
5262 returned list.
5263 matchnr current matching tag number. Used when
5264 multiple matching tags are found for a
5265 name.
5266 tagname name of the tag
5267
5268 See |tagstack| for more information about the tag stack.
5269
5270 Can also be used as a |method|: >
5271 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005272<
5273 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005274
5275
Christ van Willegence0ef912024-06-20 23:41:59 +02005276gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005277 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005278 This is intended for use in Vim scripts. When generating
5279 message translations the {text} is extracted by `xgettext`,
5280 the translator can add translated messages into the .po file
5281 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005282 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005283 `xgettext` does not support single quoted escaped text.
5284
Christ van Willegence0ef912024-06-20 23:41:59 +02005285 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005286 for that specific package. This is mainly required for
5287 third-party Vim scripts. You need to specify a path to the
5288 translations with the |bindtextdomain()| function before
5289 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005290
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005291 Return type: |String|
5292
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005293
5294getwininfo([{winid}]) *getwininfo()*
5295 Returns information about windows as a |List| with Dictionaries.
5296
5297 If {winid} is given Information about the window with that ID
5298 is returned, as a |List| with one item. If the window does not
5299 exist the result is an empty list.
5300
5301 Without {winid} information about all the windows in all the
5302 tab pages is returned.
5303
5304 Each List item is a |Dictionary| with the following entries:
5305 botline last complete displayed buffer line
5306 bufnr number of buffer in the window
5307 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005308 leftcol first column displayed; only used when
5309 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005310 loclist 1 if showing a location list
5311 {only with the +quickfix feature}
5312 quickfix 1 if quickfix or location list window
5313 {only with the +quickfix feature}
5314 terminal 1 if a terminal window
5315 {only with the +terminal feature}
5316 tabnr tab page number
5317 topline first displayed buffer line
5318 variables a reference to the dictionary with
5319 window-local variables
5320 width window width
5321 winbar 1 if the window has a toolbar, 0
5322 otherwise
5323 wincol leftmost screen column of the window;
5324 "col" from |win_screenpos()|
5325 textoff number of columns occupied by any
5326 'foldcolumn', 'signcolumn' and line
5327 number in front of the text
5328 winid |window-ID|
5329 winnr window number
5330 winrow topmost screen line of the window;
5331 "row" from |win_screenpos()|
5332
5333 Can also be used as a |method|: >
5334 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005335<
5336 Return type: list<dict<any>>
5337
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005338
5339getwinpos([{timeout}]) *getwinpos()*
5340 The result is a |List| with two numbers, the result of
5341 |getwinposx()| and |getwinposy()| combined:
5342 [x-pos, y-pos]
5343 {timeout} can be used to specify how long to wait in msec for
5344 a response from the terminal. When omitted 100 msec is used.
5345 Use a longer time for a remote terminal.
5346 When using a value less than 10 and no response is received
5347 within that time, a previously reported position is returned,
5348 if available. This can be used to poll for the position and
5349 do some work in the meantime: >
5350 while 1
5351 let res = getwinpos(1)
5352 if res[0] >= 0
5353 break
5354 endif
5355 " Do some work here
5356 endwhile
5357<
5358
5359 Can also be used as a |method|: >
5360 GetTimeout()->getwinpos()
5361<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005362 Return type: list<number>
5363
5364
5365getwinposx() *getwinposx()*
5366 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005367 the left hand side of the GUI Vim window. Also works for an
5368 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005369 The result will be -1 if the information is not available
5370 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005371 The value can be used with `:winpos`.
5372
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005373 Return type: |Number|
5374
5375
5376getwinposy() *getwinposy()*
5377 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005378 the top of the GUI Vim window. Also works for an xterm (uses
5379 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005380 The result will be -1 if the information is not available
5381 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005382 The value can be used with `:winpos`.
5383
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005384 Return type: |Number|
5385
5386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005387getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5388 Like |gettabwinvar()| for the current tabpage.
5389 Examples: >
5390 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005391 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005392
5393< Can also be used as a |method|: >
5394 GetWinnr()->getwinvar(varname)
5395<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005396 Return type: any, depending on {varname}
5397
5398
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005399glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5400 Expand the file wildcards in {expr}. See |wildcards| for the
5401 use of special characters.
5402
5403 Unless the optional {nosuf} argument is given and is |TRUE|,
5404 the 'suffixes' and 'wildignore' options apply: Names matching
5405 one of the patterns in 'wildignore' will be skipped and
5406 'suffixes' affect the ordering of matches.
5407 'wildignorecase' always applies.
5408
5409 When {list} is present and it is |TRUE| the result is a |List|
5410 with all matching files. The advantage of using a List is,
5411 you also get filenames containing newlines correctly.
5412 Otherwise the result is a String and when there are several
5413 matches, they are separated by <NL> characters.
5414
5415 If the expansion fails, the result is an empty String or List.
5416
5417 You can also use |readdir()| if you need to do complicated
5418 things, such as limiting the number of matches.
5419
5420 A name for a non-existing file is not included. A symbolic
5421 link is only included if it points to an existing file.
5422 However, when the {alllinks} argument is present and it is
5423 |TRUE| then all symbolic links are included.
5424
5425 For most systems backticks can be used to get files names from
5426 any external command. Example: >
5427 :let tagfiles = glob("`find . -name tags -print`")
5428 :let &tags = substitute(tagfiles, "\n", ",", "g")
5429< The result of the program inside the backticks should be one
5430 item per line. Spaces inside an item are allowed.
5431
5432 See |expand()| for expanding special Vim variables. See
5433 |system()| for getting the raw output of an external command.
5434
5435 Can also be used as a |method|: >
5436 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005437<
5438 Return type: |String| or list<string> or list<any> depending
5439 on {list}
5440
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005441
h-east624bb832024-11-09 18:37:32 +01005442glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005443 Convert a file pattern, as used by glob(), into a search
5444 pattern. The result can be used to match with a string that
5445 is a file name. E.g. >
5446 if filename =~ glob2regpat('Make*.mak')
5447< This is equivalent to: >
5448 if filename =~ '^Make.*\.mak$'
5449< When {string} is an empty string the result is "^$", match an
5450 empty string.
5451 Note that the result depends on the system. On MS-Windows
5452 a backslash usually means a path separator.
5453
5454 Can also be used as a |method|: >
5455 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005456<
5457 Return type: |String|
5458
5459 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005460globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5461 Perform glob() for String {expr} on all directories in {path}
5462 and concatenate the results. Example: >
5463 :echo globpath(&rtp, "syntax/c.vim")
5464<
5465 {path} is a comma-separated list of directory names. Each
5466 directory name is prepended to {expr} and expanded like with
5467 |glob()|. A path separator is inserted when needed.
5468 To add a comma inside a directory name escape it with a
5469 backslash. Note that on MS-Windows a directory may have a
5470 trailing backslash, remove it if you put a comma after it.
5471 If the expansion fails for one of the directories, there is no
5472 error message.
5473
5474 Unless the optional {nosuf} argument is given and is |TRUE|,
5475 the 'suffixes' and 'wildignore' options apply: Names matching
5476 one of the patterns in 'wildignore' will be skipped and
5477 'suffixes' affect the ordering of matches.
5478
5479 When {list} is present and it is |TRUE| the result is a |List|
5480 with all matching files. The advantage of using a List is, you
5481 also get filenames containing newlines correctly. Otherwise
5482 the result is a String and when there are several matches,
5483 they are separated by <NL> characters. Example: >
5484 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5485<
5486 {alllinks} is used as with |glob()|.
5487
5488 The "**" item can be used to search in a directory tree.
5489 For example, to find all "README.txt" files in the directories
5490 in 'runtimepath' and below: >
5491 :echo globpath(&rtp, "**/README.txt")
5492< Upwards search and limiting the depth of "**" is not
5493 supported, thus using 'path' will not always work properly.
5494
5495 Can also be used as a |method|, the base is passed as the
5496 second argument: >
5497 GetExpr()->globpath(&rtp)
5498<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005499 Return type: |String| or list<string> or list<any> depending
5500 on {list}
5501
5502
5503has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005504 When {check} is omitted or is zero: The result is a Number,
5505 which is 1 if the feature {feature} is supported, zero
5506 otherwise. The {feature} argument is a string, case is
5507 ignored. See |feature-list| below.
5508
5509 When {check} is present and not zero: The result is a Number,
5510 which is 1 if the feature {feature} could ever be supported,
5511 zero otherwise. This is useful to check for a typo in
5512 {feature} and to detect dead code. Keep in mind that an older
5513 Vim version will not know about a feature added later and
5514 features that have been abandoned will not be known by the
5515 current Vim version.
5516
5517 Also see |exists()| and |exists_compiled()|.
5518
5519 Note that to skip code that has a syntax error when the
5520 feature is not available, Vim may skip the rest of the line
5521 and miss a following `endif`. Therefore put the `endif` on a
5522 separate line: >
5523 if has('feature')
5524 let x = this->breaks->without->the->feature
5525 endif
5526< If the `endif` would be moved to the second line as "| endif" it
5527 would not be found.
5528
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005529 Return type: |Number|
5530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005531
5532has_key({dict}, {key}) *has_key()*
5533 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005534 has an entry with key {key}. FALSE otherwise.
5535 The {key} argument is a string. In |Vim9| script a number is
5536 also accepted (and converted to a string) but no other types.
5537 In legacy script the usual automatic conversion to string is
5538 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005539
5540 Can also be used as a |method|: >
5541 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005542<
5543 Return type: |Number|
5544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005545
5546haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5547 The result is a Number:
5548 1 when the window has set a local directory via |:lcd|
5549 2 when the tab-page has set a local directory via |:tcd|
5550 0 otherwise.
5551
5552 Without arguments use the current window.
5553 With {winnr} use this window in the current tab page.
5554 With {winnr} and {tabnr} use the window in the specified tab
5555 page.
5556 {winnr} can be the window number or the |window-ID|.
5557 If {winnr} is -1 it is ignored and only the tabpage is used.
5558 Return 0 if the arguments are invalid.
5559 Examples: >
5560 if haslocaldir() == 1
5561 " window local directory case
5562 elseif haslocaldir() == 2
5563 " tab-local directory case
5564 else
5565 " global directory case
5566 endif
5567
5568 " current window
5569 :echo haslocaldir()
5570 :echo haslocaldir(0)
5571 :echo haslocaldir(0, 0)
5572 " window n in current tab page
5573 :echo haslocaldir(n)
5574 :echo haslocaldir(n, 0)
5575 " window n in tab page m
5576 :echo haslocaldir(n, m)
5577 " tab page m
5578 :echo haslocaldir(-1, m)
5579<
5580 Can also be used as a |method|: >
5581 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005582<
5583 Return type: |Number|
5584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005585
5586hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5587 The result is a Number, which is TRUE if there is a mapping
5588 that contains {what} in somewhere in the rhs (what it is
5589 mapped to) and this mapping exists in one of the modes
5590 indicated by {mode}.
5591 The arguments {what} and {mode} are strings.
5592 When {abbr} is there and it is |TRUE| use abbreviations
5593 instead of mappings. Don't forget to specify Insert and/or
5594 Command-line mode.
5595 Both the global mappings and the mappings local to the current
5596 buffer are checked for a match.
5597 If no matching mapping is found FALSE is returned.
5598 The following characters are recognized in {mode}:
5599 n Normal mode
5600 v Visual and Select mode
5601 x Visual mode
5602 s Select mode
5603 o Operator-pending mode
5604 i Insert mode
5605 l Language-Argument ("r", "f", "t", etc.)
5606 c Command-line mode
5607 When {mode} is omitted, "nvo" is used.
5608
5609 This function is useful to check if a mapping already exists
5610 to a function in a Vim script. Example: >
5611 :if !hasmapto('\ABCdoit')
5612 : map <Leader>d \ABCdoit
5613 :endif
5614< This installs the mapping to "\ABCdoit" only if there isn't
5615 already a mapping to "\ABCdoit".
5616
5617 Can also be used as a |method|: >
5618 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005619<
5620 Return type: |Number|
5621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005622
5623histadd({history}, {item}) *histadd()*
5624 Add the String {item} to the history {history} which can be
5625 one of: *hist-names*
5626 "cmd" or ":" command line history
5627 "search" or "/" search pattern history
5628 "expr" or "=" typed expression history
5629 "input" or "@" input line history
5630 "debug" or ">" debug command history
5631 empty the current or last used history
5632 The {history} string does not need to be the whole name, one
5633 character is sufficient.
5634 If {item} does already exist in the history, it will be
5635 shifted to become the newest entry.
5636 The result is a Number: TRUE if the operation was successful,
5637 otherwise FALSE is returned.
5638
5639 Example: >
5640 :call histadd("input", strftime("%Y %b %d"))
5641 :let date=input("Enter date: ")
5642< This function is not available in the |sandbox|.
5643
5644 Can also be used as a |method|, the base is passed as the
5645 second argument: >
5646 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005647<
5648 Return type: |Number|
5649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005650
5651histdel({history} [, {item}]) *histdel()*
5652 Clear {history}, i.e. delete all its entries. See |hist-names|
5653 for the possible values of {history}.
5654
5655 If the parameter {item} evaluates to a String, it is used as a
5656 regular expression. All entries matching that expression will
5657 be removed from the history (if there are any).
5658 Upper/lowercase must match, unless "\c" is used |/\c|.
5659 If {item} evaluates to a Number, it will be interpreted as
5660 an index, see |:history-indexing|. The respective entry will
5661 be removed if it exists.
5662
5663 The result is TRUE for a successful operation, otherwise FALSE
5664 is returned.
5665
5666 Examples:
5667 Clear expression register history: >
5668 :call histdel("expr")
5669<
5670 Remove all entries starting with "*" from the search history: >
5671 :call histdel("/", '^\*')
5672<
5673 The following three are equivalent: >
5674 :call histdel("search", histnr("search"))
5675 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005676 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005677<
5678 To delete the last search pattern and use the last-but-one for
5679 the "n" command and 'hlsearch': >
5680 :call histdel("search", -1)
5681 :let @/ = histget("search", -1)
5682<
5683 Can also be used as a |method|: >
5684 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005685<
5686 Return type: |Number|
5687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005688
5689histget({history} [, {index}]) *histget()*
5690 The result is a String, the entry with Number {index} from
5691 {history}. See |hist-names| for the possible values of
5692 {history}, and |:history-indexing| for {index}. If there is
5693 no such entry, an empty String is returned. When {index} is
5694 omitted, the most recent item from the history is used.
5695
5696 Examples:
5697 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005698 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005699
5700< Define an Ex command ":H {num}" that supports re-execution of
5701 the {num}th entry from the output of |:history|. >
5702 :command -nargs=1 H execute histget("cmd", 0+<args>)
5703<
5704 Can also be used as a |method|: >
5705 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005706<
5707 Return type: |String|
5708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005709
5710histnr({history}) *histnr()*
5711 The result is the Number of the current entry in {history}.
5712 See |hist-names| for the possible values of {history}.
5713 If an error occurred, -1 is returned.
5714
5715 Example: >
5716 :let inp_index = histnr("expr")
5717
5718< Can also be used as a |method|: >
5719 GetHistory()->histnr()
5720<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005721 Return type: |Number|
5722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005723hlexists({name}) *hlexists()*
5724 The result is a Number, which is TRUE if a highlight group
5725 called {name} exists. This is when the group has been
5726 defined in some way. Not necessarily when highlighting has
5727 been defined for it, it may also have been used for a syntax
5728 item.
5729 *highlight_exists()*
5730 Obsolete name: highlight_exists().
5731
5732 Can also be used as a |method|: >
5733 GetName()->hlexists()
5734<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005735 Return type: |Number|
5736
5737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005738hlget([{name} [, {resolve}]]) *hlget()*
5739 Returns a List of all the highlight group attributes. If the
5740 optional {name} is specified, then returns a List with only
5741 the attributes of the specified highlight group. Returns an
5742 empty List if the highlight group {name} is not present.
5743
5744 If the optional {resolve} argument is set to v:true and the
5745 highlight group {name} is linked to another group, then the
5746 link is resolved recursively and the attributes of the
5747 resolved highlight group are returned.
5748
5749 Each entry in the returned List is a Dictionary with the
5750 following items:
5751 cleared boolean flag, set to v:true if the highlight
5752 group attributes are cleared or not yet
5753 specified. See |highlight-clear|.
5754 cterm cterm attributes. See |highlight-cterm|.
5755 ctermbg cterm background color.
5756 See |highlight-ctermbg|.
5757 ctermfg cterm foreground color.
5758 See |highlight-ctermfg|.
5759 ctermul cterm underline color. See |highlight-ctermul|.
5760 default boolean flag, set to v:true if the highlight
5761 group link is a default link. See
5762 |highlight-default|.
5763 font highlight group font. See |highlight-font|.
5764 gui gui attributes. See |highlight-gui|.
5765 guibg gui background color. See |highlight-guibg|.
5766 guifg gui foreground color. See |highlight-guifg|.
5767 guisp gui special color. See |highlight-guisp|.
5768 id highlight group ID.
5769 linksto linked highlight group name.
5770 See |:highlight-link|.
5771 name highlight group name. See |group-name|.
5772 start start terminal keycode. See |highlight-start|.
5773 stop stop terminal keycode. See |highlight-stop|.
5774 term term attributes. See |highlight-term|.
5775
5776 The 'term', 'cterm' and 'gui' items in the above Dictionary
5777 have a dictionary value with the following optional boolean
5778 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5779 'reverse', 'inverse' and 'strikethrough'.
5780
5781 Example(s): >
5782 :echo hlget()
5783 :echo hlget('ModeMsg')
5784 :echo hlget('Number', v:true)
5785<
5786 Can also be used as a |method|: >
5787 GetName()->hlget()
5788<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005789 Return type: list<dict<any>>
5790
5791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005792hlset({list}) *hlset()*
5793 Creates or modifies the attributes of a List of highlight
5794 groups. Each item in {list} is a dictionary containing the
5795 attributes of a highlight group. See |hlget()| for the list of
5796 supported items in this dictionary.
5797
5798 In addition to the items described in |hlget()|, the following
5799 additional items are supported in the dictionary:
5800
5801 force boolean flag to force the creation of
5802 a link for an existing highlight group
5803 with attributes.
5804
5805 The highlight group is identified using the 'name' item and
5806 the 'id' item (if supplied) is ignored. If a highlight group
5807 with a specified name doesn't exist, then it is created.
5808 Otherwise the attributes of an existing highlight group are
5809 modified.
5810
5811 If an empty dictionary value is used for the 'term' or 'cterm'
5812 or 'gui' entries, then the corresponding attributes are
5813 cleared. If the 'cleared' item is set to v:true, then all the
5814 attributes of the highlight group are cleared.
5815
5816 The 'linksto' item can be used to link a highlight group to
5817 another highlight group. See |:highlight-link|.
5818
5819 Returns zero for success, -1 for failure.
5820
5821 Example(s): >
5822 " add bold attribute to the Visual highlight group
5823 :call hlset([#{name: 'Visual',
5824 \ term: #{reverse: 1 , bold: 1}}])
5825 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5826 :let l = hlget()
5827 :call hlset(l)
5828 " clear the Search highlight group
5829 :call hlset([#{name: 'Search', cleared: v:true}])
5830 " clear the 'term' attributes for a highlight group
5831 :call hlset([#{name: 'Title', term: {}}])
5832 " create the MyHlg group linking it to DiffAdd
5833 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5834 " remove the MyHlg group link
5835 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5836 " clear the attributes and a link
5837 :call hlset([#{name: 'MyHlg', cleared: v:true,
5838 \ linksto: 'NONE'}])
5839<
5840 Can also be used as a |method|: >
5841 GetAttrList()->hlset()
5842<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005843 Return type: |Number|
5844
5845hlID({name}) *hlID()*
5846 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005847 with name {name}. When the highlight group doesn't exist,
5848 zero is returned.
5849 This can be used to retrieve information about the highlight
5850 group. For example, to get the background color of the
5851 "Comment" group: >
5852 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5853< *highlightID()*
5854 Obsolete name: highlightID().
5855
5856 Can also be used as a |method|: >
5857 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005858<
5859 Return type: |Number|
5860
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005861
5862hostname() *hostname()*
5863 The result is a String, which is the name of the machine on
5864 which Vim is currently running. Machine names greater than
5865 256 characters long are truncated.
5866
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005867 Return type: |String|
5868
5869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005870iconv({string}, {from}, {to}) *iconv()*
5871 The result is a String, which is the text {string} converted
5872 from encoding {from} to encoding {to}.
5873 When the conversion completely fails an empty string is
5874 returned. When some characters could not be converted they
5875 are replaced with "?".
5876 The encoding names are whatever the iconv() library function
5877 can accept, see ":!man 3 iconv".
5878 Most conversions require Vim to be compiled with the |+iconv|
5879 feature. Otherwise only UTF-8 to latin1 conversion and back
5880 can be done.
5881 This can be used to display messages with special characters,
5882 no matter what 'encoding' is set to. Write the message in
5883 UTF-8 and use: >
5884 echo iconv(utf8_str, "utf-8", &enc)
5885< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5886 from/to UCS-2 is automatically changed to use UTF-8. You
5887 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5888
5889 Can also be used as a |method|: >
5890 GetText()->iconv('latin1', 'utf-8')
5891<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005892 Return type: |String|
5893
5894
h-east624bb832024-11-09 18:37:32 +01005895id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005896 The result is a unique String associated with the {item} and
5897 not with the {item}'s contents. It is only valid while the
5898 {item} exists and is referenced. It is valid only in the
5899 instance of vim that produces the result. The whole idea is
5900 that `id({item})` does not change if the contents of {item}
5901 changes. This is useful as a `key` for creating an identity
5902 dictionary, rather than one based on equals.
5903
5904 This operation does not reference {item} and there is no
5905 function to convert the `id` to the {item}. It may be useful to
5906 have a map of `id` to {item}. The following >
5907 var referenceMap: dict<any>
5908 var id = item->id()
5909 referenceMap[id] = item
5910< prevents {item} from being garbage collected and provides a
5911 way to get the {item} from the `id`.
5912
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005913 {item} may be a List, Tuple, Dictionary, Object, Job, Channel
5914 or Blob. If the item is not a permitted type, or it is a null
Ernie Raelc8e158b2024-07-09 18:39:52 +02005915 value, then an empty String is returned.
5916
5917 Can also be used as a |method|: >
5918 GetItem()->id()
5919<
5920 Return type: |String|
5921
5922
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005923indent({lnum}) *indent()*
5924 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005925 current buffer. The indent is counted in spaces, the value
5926 of 'tabstop' is relevant. {lnum} is used just like in
5927 |getline()|.
5928 When {lnum} is invalid -1 is returned. In |Vim9| script an
5929 error is given.
5930
5931 Can also be used as a |method|: >
5932 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005933<
5934 Return type: |Number|
5935
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005936
5937index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005938 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005939 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005940
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005941 If {object} is a |List| or a |Tuple| return the lowest index
5942 where the item has a value equal to {expr}. There is no
5943 automatic conversion, so the String "4" is different from the
5944 Number 4. And the number 4 is different from the Float 4.0.
5945 The value of 'ignorecase' is not used here, case matters as
5946 indicated by the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005947
5948 If {object} is |Blob| return the lowest index where the byte
5949 value is equal to {expr}.
5950
5951 If {start} is given then start looking at the item with index
5952 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005954 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5955 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005956
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005957 -1 is returned when {expr} is not found in {object}.
5958 Example: >
5959 :let idx = index(words, "the")
5960 :if index(numbers, 123) >= 0
5961
5962< Can also be used as a |method|: >
5963 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005964<
5965 Return type: |Number|
5966
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005967
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005968indexof({object}, {expr} [, {opts}]) *indexof()*
5969 Returns the index of an item in {object} where {expr} is
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005970 v:true. {object} must be a |List|, a |Tuple| or a |Blob|.
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005971
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005972 If {object} is a |List| or a |Tuple|, evaluate {expr} for each
Christ van Willegen92e109f2025-03-24 20:12:37 +01005973 item in the List or Tuple until the expression is v:true
5974 and return the index of this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005975
5976 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005977 Blob until the expression is v:true and return the index of
5978 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005979
5980 {expr} must be a |string| or |Funcref|.
5981
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01005982 If {expr} is a |string|: If {object} is a |List| or a |Tuple|,
5983 inside {expr} |v:key| has the index of the current List or
5984 Tuple item and |v:val| has the value of the item. If {object}
5985 is a |Blob|, inside {expr} |v:key| has the index of the
5986 current byte and |v:val| has the byte value.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005987
5988 If {expr} is a |Funcref| it must take two arguments:
5989 1. the key or the index of the current item.
5990 2. the value of the current item.
5991 The function must return |TRUE| if the item is found and the
5992 search should stop.
5993
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005994 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005995 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005996 startidx start evaluating {expr} at the item with this
5997 index; may be negative for an item relative to
5998 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005999 Returns -1 when {expr} evaluates to v:false for all the items.
6000 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01006001 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
6002 :echo indexof(l, "v:val.n == 20")
6003 :echo indexof(l, {i, v -> v.n == 30})
6004 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01006005
6006< Can also be used as a |method|: >
6007 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006008<
6009 Return type: |Number|
6010
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01006011
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006012input({prompt} [, {text} [, {completion}]]) *input()*
6013 The result is a String, which is whatever the user typed on
6014 the command-line. The {prompt} argument is either a prompt
6015 string, or a blank string (for no prompt). A '\n' can be used
6016 in the prompt to start a new line.
6017 The highlighting set with |:echohl| is used for the prompt.
6018 The input is entered just like a command-line, with the same
6019 editing commands and mappings. There is a separate history
6020 for lines typed for input().
6021 Example: >
6022 :if input("Coffee or beer? ") == "beer"
6023 : echo "Cheers!"
6024 :endif
6025<
6026 If the optional {text} argument is present and not empty, this
6027 is used for the default reply, as if the user typed this.
6028 Example: >
6029 :let color = input("Color? ", "white")
6030
6031< The optional {completion} argument specifies the type of
6032 completion supported for the input. Without it completion is
6033 not performed. The supported completion types are the same as
6034 that can be supplied to a user-defined command using the
6035 "-complete=" argument. Refer to |:command-completion| for
6036 more information. Example: >
6037 let fname = input("File: ", "", "file")
6038<
6039 NOTE: This function must not be used in a startup file, for
6040 the versions that only run in GUI mode (e.g., the Win32 GUI).
6041 Note: When input() is called from within a mapping it will
6042 consume remaining characters from that mapping, because a
6043 mapping is handled like the characters were typed.
6044 Use |inputsave()| before input() and |inputrestore()|
6045 after input() to avoid that. Another solution is to avoid
6046 that further characters follow in the mapping, e.g., by using
6047 |:execute| or |:normal|.
6048
6049 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006050 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006051 :function GetFoo()
6052 : call inputsave()
6053 : let g:Foo = input("enter search pattern: ")
6054 : call inputrestore()
6055 :endfunction
6056
6057< Can also be used as a |method|: >
6058 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006059<
6060 Return type: |String|
6061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006062
6063inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
6064 Like |input()|, but when the GUI is running and text dialogs
6065 are supported, a dialog window pops up to input the text.
6066 Example: >
6067 :let n = inputdialog("value for shiftwidth", shiftwidth())
6068 :if n != ""
6069 : let &sw = n
6070 :endif
6071< When the dialog is cancelled {cancelreturn} is returned. When
6072 omitted an empty string is returned.
6073 Hitting <Enter> works like pressing the OK button. Hitting
6074 <Esc> works like pressing the Cancel button.
6075 NOTE: Command-line completion is not supported.
6076
6077 Can also be used as a |method|: >
6078 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006079<
6080 Return type: |String|
6081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006082
6083inputlist({textlist}) *inputlist()*
6084 {textlist} must be a |List| of strings. This |List| is
6085 displayed, one string per line. The user will be prompted to
6086 enter a number, which is returned.
6087 The user can also select an item by clicking on it with the
6088 mouse, if the mouse is enabled in the command line ('mouse' is
6089 "a" or includes "c"). For the first string 0 is returned.
6090 When clicking above the first item a negative number is
6091 returned. When clicking on the prompt one more than the
6092 length of {textlist} is returned.
6093 Make sure {textlist} has less than 'lines' entries, otherwise
6094 it won't work. It's a good idea to put the entry number at
6095 the start of the string. And put a prompt in the first item.
6096 Example: >
6097 let color = inputlist(['Select color:', '1. red',
6098 \ '2. green', '3. blue'])
6099
6100< Can also be used as a |method|: >
6101 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006102<
6103 Return type: |Number|
6104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006105
6106inputrestore() *inputrestore()*
6107 Restore typeahead that was saved with a previous |inputsave()|.
6108 Should be called the same number of times inputsave() is
6109 called. Calling it more often is harmless though.
6110 Returns TRUE when there is nothing to restore, FALSE otherwise.
6111
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006112 Return type: |Number|
6113
6114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006115inputsave() *inputsave()*
6116 Preserve typeahead (also from mappings) and clear it, so that
6117 a following prompt gets input from the user. Should be
6118 followed by a matching inputrestore() after the prompt. Can
6119 be used several times, in which case there must be just as
6120 many inputrestore() calls.
6121 Returns TRUE when out of memory, FALSE otherwise.
6122
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006123 Return type: |Number|
6124
6125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006126inputsecret({prompt} [, {text}]) *inputsecret()*
6127 This function acts much like the |input()| function with but
6128 two exceptions:
6129 a) the user's response will be displayed as a sequence of
6130 asterisks ("*") thereby keeping the entry secret, and
6131 b) the user's response will not be recorded on the input
6132 |history| stack.
6133 The result is a String, which is whatever the user actually
6134 typed on the command-line in response to the issued prompt.
6135 NOTE: Command-line completion is not supported.
6136
6137 Can also be used as a |method|: >
6138 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006139<
6140 Return type: |String|
6141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006142
6143insert({object}, {item} [, {idx}]) *insert()*
6144 When {object} is a |List| or a |Blob| insert {item} at the start
6145 of it.
6146
6147 If {idx} is specified insert {item} before the item with index
6148 {idx}. If {idx} is zero it goes before the first item, just
6149 like omitting {idx}. A negative {idx} is also possible, see
6150 |list-index|. -1 inserts just before the last item.
6151
6152 Returns the resulting |List| or |Blob|. Examples: >
6153 :let mylist = insert([2, 3, 5], 1)
6154 :call insert(mylist, 4, -1)
6155 :call insert(mylist, 6, len(mylist))
6156< The last example can be done simpler with |add()|.
6157 Note that when {item} is a |List| it is inserted as a single
6158 item. Use |extend()| to concatenate |Lists|.
6159
6160 Can also be used as a |method|: >
6161 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006162<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006163 Return type: |Number|
6164
6165
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006166 *instanceof()* *E614* *E616* *E693*
6167instanceof({object}, {class})
6168 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006169 argument is a direct or indirect instance of a |Class|,
6170 |Interface|, or class |:type| alias specified by {class}.
6171 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006172 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006173 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006174 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006175
6176< Can also be used as a |method|: >
6177 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006178<
6179 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006181interrupt() *interrupt()*
6182 Interrupt script execution. It works more or less like the
6183 user typing CTRL-C, most commands won't execute and control
6184 returns to the user. This is useful to abort execution
6185 from lower down, e.g. in an autocommand. Example: >
6186 :function s:check_typoname(file)
6187 : if fnamemodify(a:file, ':t') == '['
6188 : echomsg 'Maybe typo'
6189 : call interrupt()
6190 : endif
6191 :endfunction
6192 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006193<
6194 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006195
6196invert({expr}) *invert()*
6197 Bitwise invert. The argument is converted to a number. A
6198 List, Dict or Float argument causes an error. Example: >
6199 :let bits = invert(bits)
6200< Can also be used as a |method|: >
6201 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006202<
6203 Return type: |Number|
6204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006205
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006206isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006207 The result is a Number, which is |TRUE| when {path} is an
6208 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006209 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006210 On MS-Windows, it is considered absolute when it starts with an
6211 optional drive prefix and is followed by a '\' or '/'. UNC paths
6212 are always absolute.
6213 Example: >
6214 echo isabsolutepath('/usr/share/') " 1
6215 echo isabsolutepath('./foobar') " 0
6216 echo isabsolutepath('C:\Windows') " 1
6217 echo isabsolutepath('foobar') " 0
6218 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006219<
LemonBoydca1d402022-04-28 15:26:33 +01006220 Can also be used as a |method|: >
6221 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006222<
6223 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006224
6225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006226isdirectory({directory}) *isdirectory()*
6227 The result is a Number, which is |TRUE| when a directory
6228 with the name {directory} exists. If {directory} doesn't
6229 exist, or isn't a directory, the result is |FALSE|. {directory}
6230 is any expression, which is used as a String.
6231
6232 Can also be used as a |method|: >
6233 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006234<
6235 Return type: |Number|
6236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006237
6238isinf({expr}) *isinf()*
6239 Return 1 if {expr} is a positive infinity, or -1 a negative
6240 infinity, otherwise 0. >
6241 :echo isinf(1.0 / 0.0)
6242< 1 >
6243 :echo isinf(-1.0 / 0.0)
6244< -1
6245
6246 Can also be used as a |method|: >
6247 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006248<
6249 Return type: |Number|
6250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006251
6252islocked({expr}) *islocked()* *E786*
6253 The result is a Number, which is |TRUE| when {expr} is the
6254 name of a locked variable.
6255 The string argument {expr} must be the name of a variable,
6256 |List| item or |Dictionary| entry, not the variable itself!
6257 Example: >
6258 :let alist = [0, ['a', 'b'], 2, 3]
6259 :lockvar 1 alist
6260 :echo islocked('alist') " 1
6261 :echo islocked('alist[1]') " 0
6262
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006263< When {expr} is a variable that does not exist -1 is returned.
6264 If {expr} uses a range, list or dict index that is out of
6265 range or does not exist you get an error message. Use
6266 |exists()| to check for existence.
6267 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006268
6269 Can also be used as a |method|: >
6270 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006271<
6272 Return type: |Number|
6273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006274
6275isnan({expr}) *isnan()*
6276 Return |TRUE| if {expr} is a float with value NaN. >
6277 echo isnan(0.0 / 0.0)
6278< 1
6279
6280 Can also be used as a |method|: >
6281 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006282<
6283 Return type: |Number|
6284
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006285
6286items({dict}) *items()*
6287 Return a |List| with all the key-value pairs of {dict}. Each
6288 |List| item is a list with two items: the key of a {dict}
6289 entry and the value of this entry. The |List| is in arbitrary
6290 order. Also see |keys()| and |values()|.
6291 Example: >
6292 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006293 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006294 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006295<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006296 A |List|, a |Tuple| or a |String| argument is also supported.
6297 In these cases, items() returns a List with the index and the
6298 value at the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006299
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006300 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006301 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006302<
6303 Return type: list<list<any>> or list<any>
6304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006305
6306job_ functions are documented here: |job-functions-details|
6307
6308
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006309join({expr} [, {sep}]) *join()*
6310 Join the items in {expr} together into one String. {expr} can
6311 be a |List| or a |Tuple|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006312 When {sep} is specified it is put in between the items. If
6313 {sep} is omitted a single space is used.
6314 Note that {sep} is not added at the end. You might want to
6315 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006316 let lines = join(mylist, "\n") .. "\n"
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006317< String items are used as-is. |Lists|, |Tuples| and
6318 |Dictionaries| are converted into a string like with
6319 |string()|. The opposite function is |split()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006320
6321 Can also be used as a |method|: >
6322 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006323<
6324 Return type: |String|
6325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006326
6327js_decode({string}) *js_decode()*
6328 This is similar to |json_decode()| with these differences:
6329 - Object key names do not have to be in quotes.
6330 - Strings can be in single quotes.
6331 - Empty items in an array (between two commas) are allowed and
6332 result in v:none items.
6333
6334 Can also be used as a |method|: >
6335 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006336<
6337 Return type: any, depending on {varname}
6338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006339
6340js_encode({expr}) *js_encode()*
6341 This is similar to |json_encode()| with these differences:
6342 - Object key names are not in quotes.
6343 - v:none items in an array result in an empty item between
6344 commas.
6345 For example, the Vim object:
6346 [1,v:none,{"one":1},v:none] ~
6347 Will be encoded as:
6348 [1,,{one:1},,] ~
6349 While json_encode() would produce:
6350 [1,null,{"one":1},null] ~
6351 This encoding is valid for JavaScript. It is more efficient
6352 than JSON, especially when using an array with optional items.
6353
6354 Can also be used as a |method|: >
6355 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006356<
6357 Return type: |String|
6358
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006359
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006360json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006361 This parses a JSON formatted string and returns the equivalent
6362 in Vim values. See |json_encode()| for the relation between
6363 JSON and Vim values.
6364 The decoding is permissive:
6365 - A trailing comma in an array and object is ignored, e.g.
6366 "[1, 2, ]" is the same as "[1, 2]".
6367 - Integer keys are accepted in objects, e.g. {1:2} is the
6368 same as {"1":2}.
6369 - More floating point numbers are recognized, e.g. "1." for
6370 "1.0", or "001.2" for "1.2". Special floating point values
6371 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6372 are accepted.
6373 - Leading zeroes in integer numbers are ignored, e.g. "012"
6374 for "12" or "-012" for "-12".
6375 - Capitalization is ignored in literal names null, true or
6376 false, e.g. "NULL" for "null", "True" for "true".
6377 - Control characters U+0000 through U+001F which are not
6378 escaped in strings are accepted, e.g. " " (tab
6379 character in string) for "\t".
6380 - An empty JSON expression or made of only spaces is accepted
6381 and results in v:none.
6382 - Backslash in an invalid 2-character sequence escape is
6383 ignored, e.g. "\a" is decoded as "a".
6384 - A correct surrogate pair in JSON strings should normally be
6385 a 12 character sequence such as "\uD834\uDD1E", but
6386 json_decode() silently accepts truncated surrogate pairs
6387 such as "\uD834" or "\uD834\u"
6388 *E938*
6389 A duplicate key in an object, valid in rfc7159, is not
6390 accepted by json_decode() as the result must be a valid Vim
6391 type, e.g. this fails: {"a":"b", "a":"c"}
6392
6393 Can also be used as a |method|: >
6394 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006395<
6396 Return type: any, depending on {varname}
6397
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006398
6399json_encode({expr}) *json_encode()*
6400 Encode {expr} as JSON and return this as a string.
6401 The encoding is specified in:
6402 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006403 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006404 |Number| decimal number
6405 |Float| floating point number
6406 Float nan "NaN"
6407 Float inf "Infinity"
6408 Float -inf "-Infinity"
6409 |String| in double quotes (possibly null)
6410 |Funcref| not possible, error
6411 |List| as an array (possibly null); when
6412 used recursively: []
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006413 |Tuple| as an array (possibly null); when
6414 used recursively: []
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006415 |Dict| as an object (possibly null); when
6416 used recursively: {}
6417 |Blob| as an array of the individual bytes
6418 v:false "false"
6419 v:true "true"
6420 v:none "null"
6421 v:null "null"
6422 Note that NaN and Infinity are passed on as values. This is
6423 missing in the JSON standard, but several implementations do
6424 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006425 If a string contains an illegal character then the replacement
6426 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427
6428 Can also be used as a |method|: >
6429 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006430<
6431 Return type: |String|
6432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006433
6434keys({dict}) *keys()*
6435 Return a |List| with all the keys of {dict}. The |List| is in
6436 arbitrary order. Also see |items()| and |values()|.
6437
6438 Can also be used as a |method|: >
6439 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006440<
6441 Return type: list<string>
6442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006443
zeertzjqcdc83932022-09-12 13:38:41 +01006444keytrans({string}) *keytrans()*
6445 Turn the internal byte representation of keys into a form that
6446 can be used for |:map|. E.g. >
6447 :let xx = "\<C-Home>"
6448 :echo keytrans(xx)
6449< <C-Home>
6450
6451 Can also be used as a |method|: >
6452 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006453<
6454 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006455
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006456
6457len({expr}) *len()* *E701*
6458 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006459 When {expr} is a String or a Number the length in bytes is
6460 used, as with |strlen()|.
6461 When {expr} is a |List| the number of items in the |List| is
6462 returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006463 When {expr} is a |Tuple| the number of items in the |Tuple| is
6464 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006465 When {expr} is a |Blob| the number of bytes is returned.
6466 When {expr} is a |Dictionary| the number of entries in the
6467 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006468 When {expr} is an |Object|, invokes the len() method in the
6469 object (if present) to get the length (|object-len()|).
6470 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471
6472 Can also be used as a |method|: >
6473 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006474<
6475 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006477
6478 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006479libcall({libname}, {funcname}, {argument})
6480 Call function {funcname} in the run-time library {libname}
6481 with single argument {argument}.
6482 This is useful to call functions in a library that you
6483 especially made to be used with Vim. Since only one argument
6484 is possible, calling standard library functions is rather
6485 limited.
6486 The result is the String returned by the function. If the
6487 function returns NULL, this will appear as an empty string ""
6488 to Vim.
6489 If the function returns a number, use libcallnr()!
6490 If {argument} is a number, it is passed to the function as an
6491 int; if {argument} is a string, it is passed as a
6492 null-terminated string.
6493 This function will fail in |restricted-mode|.
6494
6495 libcall() allows you to write your own 'plug-in' extensions to
6496 Vim without having to recompile the program. It is NOT a
6497 means to call system functions! If you try to do so Vim will
6498 very probably crash.
6499
6500 For Win32, the functions you write must be placed in a DLL
6501 and use the normal C calling convention (NOT Pascal which is
6502 used in Windows System DLLs). The function must take exactly
6503 one parameter, either a character pointer or a long integer,
6504 and must return a character pointer or NULL. The character
6505 pointer returned must point to memory that will remain valid
6506 after the function has returned (e.g. in static data in the
6507 DLL). If it points to allocated memory, that memory will
6508 leak away. Using a static buffer in the function should work,
6509 it's then freed when the DLL is unloaded.
6510
6511 WARNING: If the function returns a non-valid pointer, Vim may
6512 crash! This also happens if the function returns a number,
6513 because Vim thinks it's a pointer.
6514 For Win32 systems, {libname} should be the filename of the DLL
6515 without the ".DLL" suffix. A full path is only required if
6516 the DLL is not in the usual places.
6517 For Unix: When compiling your own plugins, remember that the
6518 object code must be compiled as position-independent ('PIC').
6519 {only in Win32 and some Unix versions, when the |+libcall|
6520 feature is present}
6521 Examples: >
6522 :echo libcall("libc.so", "getenv", "HOME")
6523
6524< Can also be used as a |method|, the base is passed as the
6525 third argument: >
6526 GetValue()->libcall("libc.so", "getenv")
6527<
6528 *libcallnr()*
6529libcallnr({libname}, {funcname}, {argument})
6530 Just like |libcall()|, but used for a function that returns an
6531 int instead of a string.
6532 {only in Win32 on some Unix versions, when the |+libcall|
6533 feature is present}
6534 Examples: >
6535 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6536 :call libcallnr("libc.so", "printf", "Hello World!\n")
6537 :call libcallnr("libc.so", "sleep", 10)
6538<
6539 Can also be used as a |method|, the base is passed as the
6540 third argument: >
6541 GetValue()->libcallnr("libc.so", "printf")
6542<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006543 Return type: |String|
6544
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006545
6546line({expr} [, {winid}]) *line()*
6547 The result is a Number, which is the line number of the file
6548 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006549 See |getpos()| for accepted positions.
6550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006551 To get the column number use |col()|. To get both use
6552 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006554 With the optional {winid} argument the values are obtained for
6555 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006556
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006557 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006559 Examples: >
6560 line(".") line number of the cursor
6561 line(".", winid) idem, in window "winid"
6562 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006563 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006564<
6565 To jump to the last known position when opening a file see
6566 |last-position-jump|.
6567
6568 Can also be used as a |method|: >
6569 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006570<
6571 Return type: |Number|
6572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006573
6574line2byte({lnum}) *line2byte()*
6575 Return the byte count from the start of the buffer for line
6576 {lnum}. This includes the end-of-line character, depending on
6577 the 'fileformat' option for the current buffer. The first
6578 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6579 This can also be used to get the byte count for the line just
6580 below the last line: >
6581 line2byte(line("$") + 1)
6582< This is the buffer size plus one. If 'fileencoding' is empty
6583 it is the file size plus one. {lnum} is used like with
6584 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6585 feature has been disabled at compile time, -1 is returned.
6586 Also see |byte2line()|, |go| and |:goto|.
6587
6588 Can also be used as a |method|: >
6589 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006590<
6591 Return type: |Number|
6592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006593
6594lispindent({lnum}) *lispindent()*
6595 Get the amount of indent for line {lnum} according the lisp
6596 indenting rules, as with 'lisp'.
6597 The indent is counted in spaces, the value of 'tabstop' is
6598 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006599 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006600 error is given.
6601
6602 Can also be used as a |method|: >
6603 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006604<
6605 Return type: |Number|
6606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006607
6608list2blob({list}) *list2blob()*
6609 Return a Blob concatenating all the number values in {list}.
6610 Examples: >
6611 list2blob([1, 2, 3, 4]) returns 0z01020304
6612 list2blob([]) returns 0z
6613< Returns an empty Blob on error. If one of the numbers is
6614 negative or more than 255 error *E1239* is given.
6615
6616 |blob2list()| does the opposite.
6617
6618 Can also be used as a |method|: >
6619 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006620<
6621 Return type: |Blob|
6622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006623
6624list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006625 Convert each number in {list} to a character string and
6626 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006627 list2str([32]) returns " "
6628 list2str([65, 66, 67]) returns "ABC"
6629< The same can be done (slowly) with: >
6630 join(map(list, {nr, val -> nr2char(val)}), '')
6631< |str2list()| does the opposite.
6632
6633 When {utf8} is omitted or zero, the current 'encoding' is used.
6634 When {utf8} is TRUE, always return UTF-8 characters.
6635 With UTF-8 composing characters work as expected: >
6636 list2str([97, 769]) returns "á"
6637<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006638 Returns an empty string on error.
6639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006640 Can also be used as a |method|: >
6641 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006642<
6643 Return type: |String|
6644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006645
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01006646list2tuple({list}) *list2tuple()*
6647 Create a Tuple from a shallow copy of the list items.
6648 Examples: >
6649 list2tuple([1, 2, 3]) returns (1, 2, 3)
6650< |tuple2list()| does the opposite.
6651
6652 This function doesn't recursively convert all the List items
6653 in {list} to a Tuple. Note that the items are identical
6654 between the list and the tuple, changing an item changes the
6655 contents of both the tuple and the list.
6656
6657 Returns an empty tuple on error.
6658
6659 Can also be used as a |method|: >
6660 GetList()->list2tuple()
6661<
6662 Return type: tuple<{type}> (depending on the given |List|)
6663
6664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006665listener_add({callback} [, {buf}]) *listener_add()*
6666 Add a callback function that will be invoked when changes have
6667 been made to buffer {buf}.
6668 {buf} refers to a buffer name or number. For the accepted
6669 values, see |bufname()|. When {buf} is omitted the current
6670 buffer is used.
6671 Returns a unique ID that can be passed to |listener_remove()|.
6672
6673 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006674 bufnr the buffer that was changed
6675 start first changed line number
6676 end first line number below the change
6677 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006678 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006679 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006680
6681 Example: >
6682 func Listener(bufnr, start, end, added, changes)
6683 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6684 endfunc
6685 call listener_add('Listener', bufnr)
6686
Bram Moolenaar944697a2022-02-20 19:48:20 +00006687< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006688 dictionary with these entries:
6689 lnum the first line number of the change
6690 end the first line below the change
6691 added number of lines added; negative if lines were
6692 deleted
6693 col first column in "lnum" that was affected by
6694 the change; one if unknown or the whole line
6695 was affected; this is a byte index, first
6696 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006697 When lines are inserted (not when a line is split, e.g. by
6698 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006699 lnum line above which the new line is added
6700 end equal to "lnum"
6701 added number of lines inserted
6702 col 1
6703 When lines are deleted the values are:
6704 lnum the first deleted line
6705 end the line below the first deleted line, before
6706 the deletion was done
6707 added negative, number of lines deleted
6708 col 1
6709 When lines are changed:
6710 lnum the first changed line
6711 end the line below the last changed line
6712 added 0
6713 col first column with a change or 1
6714
6715 The entries are in the order the changes were made, thus the
6716 most recent change is at the end. The line numbers are valid
6717 when the callback is invoked, but later changes may make them
6718 invalid, thus keeping a copy for later might not work.
6719
6720 The {callback} is invoked just before the screen is updated,
6721 when |listener_flush()| is called or when a change is being
6722 made that changes the line count in a way it causes a line
6723 number in the list of changes to become invalid.
6724
6725 The {callback} is invoked with the text locked, see
6726 |textlock|. If you do need to make changes to the buffer, use
6727 a timer to do this later |timer_start()|.
6728
6729 The {callback} is not invoked when the buffer is first loaded.
6730 Use the |BufReadPost| autocmd event to handle the initial text
6731 of a buffer.
6732 The {callback} is also not invoked when the buffer is
6733 unloaded, use the |BufUnload| autocmd event for that.
6734
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006735 Returns zero if {callback} or {buf} is invalid.
6736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006737 Can also be used as a |method|, the base is passed as the
6738 second argument: >
6739 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006740<
6741 Return type: |Number|
6742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006743
6744listener_flush([{buf}]) *listener_flush()*
6745 Invoke listener callbacks for buffer {buf}. If there are no
6746 pending changes then no callbacks are invoked.
6747
6748 {buf} refers to a buffer name or number. For the accepted
6749 values, see |bufname()|. When {buf} is omitted the current
6750 buffer is used.
6751
6752 Can also be used as a |method|: >
6753 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006754<
6755 Return type: |Number|
6756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006757
6758listener_remove({id}) *listener_remove()*
6759 Remove a listener previously added with listener_add().
6760 Returns FALSE when {id} could not be found, TRUE when {id} was
6761 removed.
6762
6763 Can also be used as a |method|: >
6764 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006765<
6766 Return type: |Number|
6767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006768
6769localtime() *localtime()*
6770 Return the current time, measured as seconds since 1st Jan
6771 1970. See also |strftime()|, |strptime()| and |getftime()|.
6772
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006773 Return type: |Number|
6774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006775
6776log({expr}) *log()*
6777 Return the natural logarithm (base e) of {expr} as a |Float|.
6778 {expr} must evaluate to a |Float| or a |Number| in the range
6779 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006780 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006781 Examples: >
6782 :echo log(10)
6783< 2.302585 >
6784 :echo log(exp(5))
6785< 5.0
6786
6787 Can also be used as a |method|: >
6788 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006789<
6790 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006791
6792
6793log10({expr}) *log10()*
6794 Return the logarithm of Float {expr} to base 10 as a |Float|.
6795 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006796 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006797 Examples: >
6798 :echo log10(1000)
6799< 3.0 >
6800 :echo log10(0.01)
6801< -2.0
6802
6803 Can also be used as a |method|: >
6804 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006805<
6806 Return type: |Float|
6807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006808
6809luaeval({expr} [, {expr}]) *luaeval()*
6810 Evaluate Lua expression {expr} and return its result converted
6811 to Vim data structures. Second {expr} may hold additional
6812 argument accessible as _A inside first {expr}.
6813 Strings are returned as they are.
6814 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006815 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006816 Dictionaries and lists obtained by vim.eval() are returned
6817 as-is.
6818 Other objects are returned as zero without any errors.
6819 See |lua-luaeval| for more details.
6820 Note that in a `:def` function local variables are not visible
6821 to {expr}.
6822
6823 Can also be used as a |method|: >
6824 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006825<
6826 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006827
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006828 {only available when compiled with the |+lua| feature}
6829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006830
6831map({expr1}, {expr2}) *map()*
6832 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006833 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006834 item in {expr1} with the result of evaluating {expr2}.
6835 For a |Blob| each byte is replaced.
6836 For a |String|, each character, including composing
6837 characters, is replaced.
6838 If the item type changes you may want to use |mapnew()| to
6839 create a new List or Dictionary. This is required when using
6840 Vim9 script.
6841
6842 {expr2} must be a |String| or |Funcref|.
6843
6844 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6845 of the current item. For a |Dictionary| |v:key| has the key
6846 of the current item and for a |List| |v:key| has the index of
6847 the current item. For a |Blob| |v:key| has the index of the
6848 current byte. For a |String| |v:key| has the index of the
6849 current character.
6850 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006851 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006852< This puts "> " before and " <" after each item in "mylist".
6853
6854 Note that {expr2} is the result of an expression and is then
6855 used as an expression again. Often it is good to use a
6856 |literal-string| to avoid having to double backslashes. You
6857 still have to double ' quotes
6858
6859 If {expr2} is a |Funcref| it is called with two arguments:
6860 1. The key or the index of the current item.
6861 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006862 With a legacy script lambda you don't get an error if it only
6863 accepts one argument, but with a Vim9 lambda you get "E1106:
6864 One argument too many", the number of arguments must match.
6865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006866 The function must return the new value of the item. Example
6867 that changes each value by "key-value": >
6868 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006869 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006870 endfunc
6871 call map(myDict, function('KeyValue'))
6872< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006873 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006874< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006875 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006876< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006877 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006878<
6879 The operation is done in-place for a |List| and |Dictionary|.
6880 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006881 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006882
6883< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6884 or a new |Blob| or |String|.
6885 When an error is encountered while evaluating {expr2} no
6886 further items in {expr1} are processed.
6887 When {expr2} is a Funcref errors inside a function are ignored,
6888 unless it was defined with the "abort" flag.
6889
6890 Can also be used as a |method|: >
6891 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006892<
6893 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6894 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006895
6896
6897maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6898 When {dict} is omitted or zero: Return the rhs of mapping
6899 {name} in mode {mode}. The returned String has special
6900 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006901 listing. When {dict} is TRUE a dictionary is returned, see
6902 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006903
6904 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006905 returned if {dict} is FALSE, otherwise returns an empty Dict.
6906 When the mapping for {name} is empty, then "<Nop>" is
6907 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006908
6909 The {name} can have special key names, like in the ":map"
6910 command.
6911
6912 {mode} can be one of these strings:
6913 "n" Normal
6914 "v" Visual (including Select)
6915 "o" Operator-pending
6916 "i" Insert
6917 "c" Cmd-line
6918 "s" Select
6919 "x" Visual
6920 "l" langmap |language-mapping|
6921 "t" Terminal-Job
6922 "" Normal, Visual and Operator-pending
6923 When {mode} is omitted, the modes for "" are used.
6924
6925 When {abbr} is there and it is |TRUE| use abbreviations
6926 instead of mappings.
6927
6928 When {dict} is there and it is |TRUE| return a dictionary
6929 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006930 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006931 "lhs" The {lhs} of the mapping as it would be typed
6932 "lhsraw" The {lhs} of the mapping as raw bytes
6933 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6934 form, only present when it differs from "lhsraw"
6935 "rhs" The {rhs} of the mapping as typed.
6936 "silent" 1 for a |:map-silent| mapping, else 0.
6937 "noremap" 1 if the {rhs} of the mapping is not remappable.
6938 "script" 1 if mapping was defined with <script>.
6939 "expr" 1 for an expression mapping (|:map-<expr>|).
6940 "buffer" 1 for a buffer local mapping (|:map-local|).
6941 "mode" Modes for which the mapping is defined. In
6942 addition to the modes mentioned above, these
6943 characters will be used:
6944 " " Normal, Visual and Operator-pending
6945 "!" Insert and Commandline mode
6946 (|mapmode-ic|)
6947 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006948 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006949 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006950 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006951 "lnum" The line number in "sid", zero if unknown.
6952 "nowait" Do not wait for other, longer mappings.
6953 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006954 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006955 "mode_bits" Vim's internal binary representation of "mode".
6956 |mapset()| ignores this; only "mode" is used.
6957 See |maplist()| for usage examples. The values
6958 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006959
6960 The dictionary can be used to restore a mapping with
6961 |mapset()|.
6962
6963 The mappings local to the current buffer are checked first,
6964 then the global mappings.
6965 This function can be used to map a key even when it's already
6966 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006967 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006968
6969< Can also be used as a |method|: >
6970 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006971<
6972 Return type: |String| or dict<any> depending on {dict}
6973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006974
6975mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6976 Check if there is a mapping that matches with {name} in mode
6977 {mode}. See |maparg()| for {mode} and special names in
6978 {name}.
6979 When {abbr} is there and it is |TRUE| use abbreviations
6980 instead of mappings.
6981 A match happens with a mapping that starts with {name} and
6982 with a mapping which is equal to the start of {name}.
6983
6984 matches mapping "a" "ab" "abc" ~
6985 mapcheck("a") yes yes yes
6986 mapcheck("abc") yes yes yes
6987 mapcheck("ax") yes no no
6988 mapcheck("b") no no no
6989
6990 The difference with maparg() is that mapcheck() finds a
6991 mapping that matches with {name}, while maparg() only finds a
6992 mapping for {name} exactly.
6993 When there is no mapping that starts with {name}, an empty
6994 String is returned. If there is one, the RHS of that mapping
6995 is returned. If there are several mappings that start with
6996 {name}, the RHS of one of them is returned. This will be
6997 "<Nop>" if the RHS is empty.
6998 The mappings local to the current buffer are checked first,
6999 then the global mappings.
7000 This function can be used to check if a mapping can be added
7001 without being ambiguous. Example: >
7002 :if mapcheck("_vv") == ""
7003 : map _vv :set guifont=7x13<CR>
7004 :endif
7005< This avoids adding the "_vv" mapping when there already is a
7006 mapping for "_v" or for "_vvv".
7007
7008 Can also be used as a |method|: >
7009 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007010<
7011 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007012
7013
Ernie Rael09661202022-04-25 14:40:44 +01007014maplist([{abbr}]) *maplist()*
7015 Returns a |List| of all mappings. Each List item is a |Dict|,
7016 the same as what is returned by |maparg()|, see
7017 |mapping-dict|. When {abbr} is there and it is |TRUE| use
7018 abbreviations instead of mappings.
7019
7020 Example to show all mappings with 'MultiMatch' in rhs: >
7021 vim9script
7022 echo maplist()->filter(
7023 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01007024< It can be tricky to find mappings for particular |:map-modes|.
7025 |mapping-dict|'s "mode_bits" can simplify this. For example,
7026 the mode_bits for Normal, Insert or Command-line modes are
7027 0x19. To find all the mappings available in those modes you
7028 can do: >
7029 vim9script
7030 var saved_maps = []
7031 for m in maplist()
7032 if and(m.mode_bits, 0x19) != 0
7033 saved_maps->add(m)
7034 endif
7035 endfor
7036 echo saved_maps->mapnew((_, m) => m.lhs)
7037< The values of the mode_bits are defined in Vim's src/vim.h
7038 file and they can be discovered at runtime using
7039 |:map-commands| and "maplist()". Example: >
7040 vim9script
7041 omap xyzzy <Nop>
7042 var op_bit = maplist()->filter(
7043 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
7044 ounmap xyzzy
7045 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007046<
7047 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01007048
7049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007050mapnew({expr1}, {expr2}) *mapnew()*
7051 Like |map()| but instead of replacing items in {expr1} a new
7052 List or Dictionary is created and returned. {expr1} remains
7053 unchanged. Items can still be changed by {expr2}, if you
7054 don't want that use |deepcopy()| first.
7055
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007056 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
7057 depending on {expr1}
7058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007059
7060mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01007061mapset({dict})
7062 Restore a mapping from a dictionary, possibly returned by
7063 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
7064 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01007065 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01007066 feature allows copying mappings from one buffer to another.
7067 The dict.mode value may restore a single mapping that covers
7068 more than one mode, like with mode values of '!', ' ', 'nox',
7069 or 'v'. *E1276*
7070
7071 In the first form, {mode} and {abbr} should be the same as
7072 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007073 {mode} is used to define the mode in which the mapping is set,
7074 not the "mode" entry in {dict}.
7075 Example for saving and restoring a mapping: >
7076 let save_map = maparg('K', 'n', 0, 1)
7077 nnoremap K somethingelse
7078 ...
7079 call mapset('n', 0, save_map)
7080< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01007081 e.g. with `:map!`, you need to save/restore the mapping for
7082 all of them, when they might differ.
7083
7084 In the second form, with {dict} as the only argument, mode
7085 and abbr are taken from the dict.
7086 Example: >
7087 vim9script
7088 var save_maps = maplist()->filter(
7089 (_, m) => m.lhs == 'K')
7090 nnoremap K somethingelse
7091 cnoremap K somethingelse2
7092 # ...
7093 unmap K
7094 for d in save_maps
7095 mapset(d)
7096 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007097<
7098 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007099
7100
7101match({expr}, {pat} [, {start} [, {count}]]) *match()*
7102 When {expr} is a |List| then this returns the index of the
7103 first item where {pat} matches. Each item is used as a
7104 String, |Lists| and |Dictionaries| are used as echoed.
7105
7106 Otherwise, {expr} is used as a String. The result is a
7107 Number, which gives the index (byte offset) in {expr} where
7108 {pat} matches.
7109
7110 A match at the first character or |List| item returns zero.
7111 If there is no match -1 is returned.
7112
7113 For getting submatches see |matchlist()|.
7114 Example: >
7115 :echo match("testing", "ing") " results in 4
7116 :echo match([1, 'x'], '\a') " results in 1
7117< See |string-match| for how {pat} is used.
7118 *strpbrk()*
7119 Vim doesn't have a strpbrk() function. But you can do: >
7120 :let sepidx = match(line, '[.,;: \t]')
7121< *strcasestr()*
7122 Vim doesn't have a strcasestr() function. But you can add
7123 "\c" to the pattern to ignore case: >
7124 :let idx = match(haystack, '\cneedle')
7125<
7126 If {start} is given, the search starts from byte index
7127 {start} in a String or item {start} in a |List|.
7128 The result, however, is still the index counted from the
7129 first character/item. Example: >
7130 :echo match("testing", "ing", 2)
7131< result is again "4". >
7132 :echo match("testing", "ing", 4)
7133< result is again "4". >
7134 :echo match("testing", "t", 2)
7135< result is "3".
7136 For a String, if {start} > 0 then it is like the string starts
7137 {start} bytes later, thus "^" will match at {start}. Except
7138 when {count} is given, then it's like matches before the
7139 {start} byte are ignored (this is a bit complicated to keep it
7140 backwards compatible).
7141 For a String, if {start} < 0, it will be set to 0. For a list
7142 the index is counted from the end.
7143 If {start} is out of range ({start} > strlen({expr}) for a
7144 String or {start} > len({expr}) for a |List|) -1 is returned.
7145
7146 When {count} is given use the {count}'th match. When a match
7147 is found in a String the search for the next one starts one
7148 character further. Thus this example results in 1: >
7149 echo match("testing", "..", 0, 2)
7150< In a |List| the search continues in the next item.
7151 Note that when {count} is added the way {start} works changes,
7152 see above.
7153
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007154 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007155 See |pattern| for the patterns that are accepted.
7156 The 'ignorecase' option is used to set the ignore-caseness of
7157 the pattern. 'smartcase' is NOT used. The matching is always
7158 done like 'magic' is set and 'cpoptions' is empty.
7159 Note that a match at the start is preferred, thus when the
7160 pattern is using "*" (any number of matches) it tends to find
7161 zero matches at the start instead of a number of matches
7162 further down in the text.
7163
7164 Can also be used as a |method|: >
7165 GetText()->match('word')
7166 GetList()->match('word')
7167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007168 Return type: |Number|
7169
7170
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007171 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007172matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7173 Defines a pattern to be highlighted in the current window (a
7174 "match"). It will be highlighted with {group}. Returns an
7175 identification number (ID), which can be used to delete the
7176 match using |matchdelete()|. The ID is bound to the window.
7177 Matching is case sensitive and magic, unless case sensitivity
7178 or magicness are explicitly overridden in {pattern}. The
7179 'magic', 'smartcase' and 'ignorecase' options are not used.
7180 The "Conceal" value is special, it causes the match to be
7181 concealed.
7182
7183 The optional {priority} argument assigns a priority to the
7184 match. A match with a high priority will have its
7185 highlighting overrule that of a match with a lower priority.
7186 A priority is specified as an integer (negative numbers are no
7187 exception). If the {priority} argument is not specified, the
7188 default priority is 10. The priority of 'hlsearch' is zero,
7189 hence all matches with a priority greater than zero will
7190 overrule it. Syntax highlighting (see 'syntax') is a separate
7191 mechanism, and regardless of the chosen priority a match will
7192 always overrule syntax highlighting.
7193
7194 The optional {id} argument allows the request for a specific
7195 match ID. If a specified ID is already taken, an error
7196 message will appear and the match will not be added. An ID
7197 is specified as a positive integer (zero excluded). IDs 1, 2
7198 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007199 respectively. 3 is reserved for use by the |matchparen|
7200 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007201 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007202 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007203
7204 The optional {dict} argument allows for further custom
7205 values. Currently this is used to specify a match specific
7206 conceal character that will be shown for |hl-Conceal|
7207 highlighted matches. The dict can have the following members:
7208
7209 conceal Special character to show instead of the
7210 match (only for |hl-Conceal| highlighted
7211 matches, see |:syn-cchar|)
7212 window Instead of the current window use the
7213 window with this number or window ID.
7214
7215 The number of matches is not limited, as it is the case with
7216 the |:match| commands.
7217
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007218 Returns -1 on error.
7219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007220 Example: >
7221 :highlight MyGroup ctermbg=green guibg=green
7222 :let m = matchadd("MyGroup", "TODO")
7223< Deletion of the pattern: >
7224 :call matchdelete(m)
7225
7226< A list of matches defined by |matchadd()| and |:match| are
7227 available from |getmatches()|. All matches can be deleted in
7228 one operation by |clearmatches()|.
7229
7230 Can also be used as a |method|: >
7231 GetGroup()->matchadd('TODO')
7232<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007233 Return type: |Number|
7234
7235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007236 *matchaddpos()*
7237matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7238 Same as |matchadd()|, but requires a list of positions {pos}
7239 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007240 because it does not handle regular expressions and it sets
7241 buffer line boundaries to redraw screen. It is supposed to be
7242 used when fast match additions and deletions are required, for
7243 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007244
7245 {pos} is a list of positions. Each position can be one of
7246 these:
7247 - A number. This whole line will be highlighted. The first
7248 line has number 1.
7249 - A list with one number, e.g., [23]. The whole line with this
7250 number will be highlighted.
7251 - A list with two numbers, e.g., [23, 11]. The first number is
7252 the line number, the second one is the column number (first
7253 column is 1, the value must correspond to the byte index as
7254 |col()| would return). The character at this position will
7255 be highlighted.
7256 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7257 the third number gives the length of the highlight in bytes.
7258
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007259 Returns -1 on error.
7260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007261 Example: >
7262 :highlight MyGroup ctermbg=green guibg=green
7263 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7264< Deletion of the pattern: >
7265 :call matchdelete(m)
7266
7267< Matches added by |matchaddpos()| are returned by
7268 |getmatches()|.
7269
7270 Can also be used as a |method|: >
7271 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007272<
7273 Return type: |Number|
7274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007275
7276matcharg({nr}) *matcharg()*
7277 Selects the {nr} match item, as set with a |:match|,
7278 |:2match| or |:3match| command.
7279 Return a |List| with two elements:
7280 The name of the highlight group used
7281 The pattern used.
7282 When {nr} is not 1, 2 or 3 returns an empty |List|.
7283 When there is no match item set returns ['', ''].
7284 This is useful to save and restore a |:match|.
7285 Highlighting matches using the |:match| commands are limited
7286 to three matches. |matchadd()| does not have this limitation.
7287
7288 Can also be used as a |method|: >
7289 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007290<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007291 Return type: list<string>
7292
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007293 *matchbufline()*
7294matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7295 Returns the |List| of matches in lines from {lnum} to {end} in
7296 buffer {buf} where {pat} matches.
7297
7298 {lnum} and {end} can either be a line number or the string "$"
7299 to refer to the last line in {buf}.
7300
7301 The {dict} argument supports following items:
7302 submatches include submatch information (|/\(|)
7303
7304 For each match, a |Dict| with the following items is returned:
7305 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007306 lnum line number where there is a match
7307 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007308 Note that there can be multiple matches in a single line.
7309
7310 This function works only for loaded buffers. First call
7311 |bufload()| if needed.
7312
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007313 See |match-pattern| for information about the effect of some
7314 option settings on the pattern.
7315
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007316 When {buf} is not a valid buffer, the buffer is not loaded or
7317 {lnum} or {end} is not valid then an error is given and an
7318 empty |List| is returned.
7319
7320 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007321 " Assuming line 3 in buffer 5 contains "a"
7322 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7323 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7324 " Assuming line 4 in buffer 10 contains "tik tok"
7325 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7326 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007327<
7328 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007329 "\1", "\2", etc. are also returned. Example: >
7330 " Assuming line 2 in buffer 2 contains "acd"
7331 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007332 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007333 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007334< The "submatches" List always contains 9 items. If a submatch
7335 is not found, then an empty string is returned for that
7336 submatch.
7337
7338 Can also be used as a |method|: >
7339 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007340<
7341 Return type: list<dict<any>> or list<any>
7342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007343
h-east624bb832024-11-09 18:37:32 +01007344matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007345 Deletes a match with ID {id} previously defined by |matchadd()|
7346 or one of the |:match| commands. Returns 0 if successful,
7347 otherwise -1. See example for |matchadd()|. All matches can
7348 be deleted in one operation by |clearmatches()|.
7349 If {win} is specified, use the window with this number or
7350 window ID instead of the current window.
7351
7352 Can also be used as a |method|: >
7353 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007354<
7355 Return type: |Number|
7356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007357
7358matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7359 Same as |match()|, but return the index of first character
7360 after the match. Example: >
7361 :echo matchend("testing", "ing")
7362< results in "7".
7363 *strspn()* *strcspn()*
7364 Vim doesn't have a strspn() or strcspn() function, but you can
7365 do it with matchend(): >
7366 :let span = matchend(line, '[a-zA-Z]')
7367 :let span = matchend(line, '[^a-zA-Z]')
7368< Except that -1 is returned when there are no matches.
7369
7370 The {start}, if given, has the same meaning as for |match()|. >
7371 :echo matchend("testing", "ing", 2)
7372< results in "7". >
7373 :echo matchend("testing", "ing", 5)
7374< result is "-1".
7375 When {expr} is a |List| the result is equal to |match()|.
7376
7377 Can also be used as a |method|: >
7378 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007379<
7380 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007381
7382
7383matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7384 If {list} is a list of strings, then returns a |List| with all
7385 the strings in {list} that fuzzy match {str}. The strings in
7386 the returned list are sorted based on the matching score.
7387
7388 The optional {dict} argument always supports the following
7389 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007390 matchseq When this item is present return only matches
7391 that contain the characters in {str} in the
7392 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007393 limit Maximum number of matches in {list} to be
7394 returned. Zero means no limit.
glepnir28e40a72025-03-16 21:24:22 +01007395 camelcase Use enhanced camel case scoring making results
7396 better suited for completion related to
zeertzjqc4815c12025-03-18 20:28:00 +01007397 programming languages. Defaults to v:true.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007398
7399 If {list} is a list of dictionaries, then the optional {dict}
7400 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007401 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007402 {str}. The value of this item should be a
7403 string.
7404 text_cb |Funcref| that will be called for every item
7405 in {list} to get the text for fuzzy matching.
7406 This should accept a dictionary item as the
7407 argument and return the text for that item to
7408 use for fuzzy matching.
7409
7410 {str} is treated as a literal string and regular expression
7411 matching is NOT supported. The maximum supported {str} length
7412 is 256.
7413
7414 When {str} has multiple words each separated by white space,
7415 then the list of strings that have all the words is returned.
7416
7417 If there are no matching strings or there is an error, then an
7418 empty list is returned. If length of {str} is greater than
7419 256, then returns an empty list.
7420
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007421 When {limit} is given, matchfuzzy() will find up to this
7422 number of matches in {list} and return them in sorted order.
7423
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007424 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007425 matching strings.
7426
7427 Example: >
7428 :echo matchfuzzy(["clay", "crow"], "cay")
7429< results in ["clay"]. >
7430 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7431< results in a list of buffer names fuzzy matching "ndl". >
7432 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7433< results in a list of buffer information dicts with buffer
7434 names fuzzy matching "ndl". >
7435 :echo getbufinfo()->matchfuzzy("spl",
7436 \ {'text_cb' : {v -> v.name}})
7437< results in a list of buffer information dicts with buffer
7438 names fuzzy matching "spl". >
7439 :echo v:oldfiles->matchfuzzy("test")
7440< results in a list of file names fuzzy matching "test". >
7441 :let l = readfile("buffer.c")->matchfuzzy("str")
7442< results in a list of lines in "buffer.c" fuzzy matching "str". >
7443 :echo ['one two', 'two one']->matchfuzzy('two one')
7444< results in ['two one', 'one two']. >
7445 :echo ['one two', 'two one']->matchfuzzy('two one',
7446 \ {'matchseq': 1})
7447< results in ['two one'].
7448
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007449 Return type: list<string> or list<any>
7450
7451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007452matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7453 Same as |matchfuzzy()|, but returns the list of matched
7454 strings, the list of character positions where characters
7455 in {str} matches and a list of matching scores. You can
7456 use |byteidx()| to convert a character position to a byte
7457 position.
7458
7459 If {str} matches multiple times in a string, then only the
7460 positions for the best match is returned.
7461
7462 If there are no matching strings or there is an error, then a
7463 list with three empty list items is returned.
7464
7465 Example: >
7466 :echo matchfuzzypos(['testing'], 'tsg')
7467< results in [['testing'], [[0, 2, 6]], [99]] >
7468 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7469< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7470 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7471< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7472
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007473 Return type: list<list<any>>
7474
7475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007476matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7477 Same as |match()|, but return a |List|. The first item in the
7478 list is the matched string, same as what matchstr() would
7479 return. Following items are submatches, like "\1", "\2", etc.
7480 in |:substitute|. When an optional submatch didn't match an
7481 empty string is used. Example: >
7482 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7483< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7484 When there is no match an empty list is returned.
7485
7486 You can pass in a List, but that is not very useful.
7487
7488 Can also be used as a |method|: >
7489 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007490<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007491 Return type: list<string> or list<any>
7492
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007493 *matchstrlist()*
7494matchstrlist({list}, {pat} [, {dict}])
7495 Returns the |List| of matches in {list} where {pat} matches.
7496 {list} is a |List| of strings. {pat} is matched against each
7497 string in {list}.
7498
7499 The {dict} argument supports following items:
7500 submatches include submatch information (|/\(|)
7501
7502 For each match, a |Dict| with the following items is returned:
7503 byteidx starting byte index of the match.
7504 idx index in {list} of the match.
7505 text matched string
7506 submatches a List of submatches. Present only if
7507 "submatches" is set to v:true in {dict}.
7508
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007509 See |match-pattern| for information about the effect of some
7510 option settings on the pattern.
7511
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007512 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007513 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7514 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7515 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7516 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007517<
7518 If "submatches" is present and is v:true, then submatches like
7519 "\1", "\2", etc. are also returned. Example: >
7520 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7521 \ #{submatches: v:true})
7522 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7523< The "submatches" List always contains 9 items. If a submatch
7524 is not found, then an empty string is returned for that
7525 submatch.
7526
7527 Can also be used as a |method|: >
7528 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007529<
7530 Return type: list<dict<any>> or list<any>
7531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007532
7533matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7534 Same as |match()|, but return the matched string. Example: >
7535 :echo matchstr("testing", "ing")
7536< results in "ing".
7537 When there is no match "" is returned.
7538 The {start}, if given, has the same meaning as for |match()|. >
7539 :echo matchstr("testing", "ing", 2)
7540< results in "ing". >
7541 :echo matchstr("testing", "ing", 5)
7542< result is "".
7543 When {expr} is a |List| then the matching item is returned.
7544 The type isn't changed, it's not necessarily a String.
7545
7546 Can also be used as a |method|: >
7547 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007548<
7549 Return type: |String|
7550
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007551
7552matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7553 Same as |matchstr()|, but return the matched string, the start
7554 position and the end position of the match. Example: >
7555 :echo matchstrpos("testing", "ing")
7556< results in ["ing", 4, 7].
7557 When there is no match ["", -1, -1] is returned.
7558 The {start}, if given, has the same meaning as for |match()|. >
7559 :echo matchstrpos("testing", "ing", 2)
7560< results in ["ing", 4, 7]. >
7561 :echo matchstrpos("testing", "ing", 5)
7562< result is ["", -1, -1].
7563 When {expr} is a |List| then the matching item, the index
7564 of first item where {pat} matches, the start position and the
7565 end position of the match are returned. >
7566 :echo matchstrpos([1, '__x'], '\a')
7567< result is ["x", 1, 2, 3].
7568 The type isn't changed, it's not necessarily a String.
7569
7570 Can also be used as a |method|: >
7571 GetText()->matchstrpos('word')
7572<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007573 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007574
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007575
7576max({expr}) *max()*
7577 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007578 echo max([apples, pears, oranges])
7579
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007580< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7581 Dictionary, it returns the maximum of all values in the
7582 Dictionary. If {expr} is neither a List nor a Tuple nor a
7583 Dictionary, or one of the items in {expr} cannot be used as a
7584 Number this results in an error. An empty |List|, |Tuple|
7585 or |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007586
7587 Can also be used as a |method|: >
7588 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007589<
7590 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007591
7592
7593menu_info({name} [, {mode}]) *menu_info()*
7594 Return information about the specified menu {name} in
7595 mode {mode}. The menu name should be specified without the
7596 shortcut character ('&'). If {name} is "", then the top-level
7597 menu names are returned.
7598
7599 {mode} can be one of these strings:
7600 "n" Normal
7601 "v" Visual (including Select)
7602 "o" Operator-pending
7603 "i" Insert
7604 "c" Cmd-line
7605 "s" Select
7606 "x" Visual
7607 "t" Terminal-Job
7608 "" Normal, Visual and Operator-pending
7609 "!" Insert and Cmd-line
7610 When {mode} is omitted, the modes for "" are used.
7611
7612 Returns a |Dictionary| containing the following items:
7613 accel menu item accelerator text |menu-text|
7614 display display name (name without '&')
7615 enabled v:true if this menu item is enabled
7616 Refer to |:menu-enable|
7617 icon name of the icon file (for toolbar)
7618 |toolbar-icon|
7619 iconidx index of a built-in icon
7620 modes modes for which the menu is defined. In
7621 addition to the modes mentioned above, these
7622 characters will be used:
7623 " " Normal, Visual and Operator-pending
7624 name menu item name.
7625 noremenu v:true if the {rhs} of the menu item is not
7626 remappable else v:false.
7627 priority menu order priority |menu-priority|
7628 rhs right-hand-side of the menu item. The returned
7629 string has special characters translated like
7630 in the output of the ":menu" command listing.
7631 When the {rhs} of a menu item is empty, then
7632 "<Nop>" is returned.
7633 script v:true if script-local remapping of {rhs} is
7634 allowed else v:false. See |:menu-script|.
7635 shortcut shortcut key (character after '&' in
7636 the menu name) |menu-shortcut|
7637 silent v:true if the menu item is created
7638 with <silent> argument |:menu-silent|
7639 submenus |List| containing the names of
7640 all the submenus. Present only if the menu
7641 item has submenus.
7642
7643 Returns an empty dictionary if the menu item is not found.
7644
7645 Examples: >
7646 :echo menu_info('Edit.Cut')
7647 :echo menu_info('File.Save', 'n')
7648
7649 " Display the entire menu hierarchy in a buffer
7650 func ShowMenu(name, pfx)
7651 let m = menu_info(a:name)
7652 call append(line('$'), a:pfx .. m.display)
7653 for child in m->get('submenus', [])
7654 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7655 \ a:pfx .. ' ')
7656 endfor
7657 endfunc
7658 new
7659 for topmenu in menu_info('').submenus
7660 call ShowMenu(topmenu, '')
7661 endfor
7662<
7663 Can also be used as a |method|: >
7664 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007665<
7666 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007667
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007668min({expr}) *min()*
7669 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007670 echo min([apples, pears, oranges])
7671
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01007672< {expr} can be a |List|, a |Tuple| or a |Dictionary|. For a
7673 Dictionary, it returns the minimum of all values in the
7674 Dictionary. If {expr} is neither a List nor a Tuple nor a
7675 Dictionary, or one of the items in {expr} cannot be used as a
7676 Number this results in an error. An empty |List|, |Tuple| or
7677 |Dictionary| results in zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007678
7679 Can also be used as a |method|: >
7680 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007681<
7682 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007683
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007684
7685mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007686 Create directory {name}.
7687
Bram Moolenaar938ae282023-02-20 20:44:55 +00007688 When {flags} is present it must be a string. An empty string
7689 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007690
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007691 {flags} can contain these character flags:
7692 "p" intermediate directories will be created as necessary
7693 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007694 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007695 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007696 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007697
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007698 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007699 some directories may already exist. Only the first one that
7700 is created and what it contains is scheduled to be deleted.
7701 E.g. when using: >
7702 call mkdir('subdir/tmp/autoload', 'pR')
7703< and "subdir" already exists then "subdir/tmp" will be
7704 scheduled for deletion, like with: >
7705 defer delete('subdir/tmp', 'rf')
7706< Note that if scheduling the defer fails the directory is not
7707 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007708
7709 If {prot} is given it is used to set the protection bits of
7710 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7711 the user, readable for others). Use 0o700 to make it
Christian Brabandt0a336cc2025-03-11 21:14:31 +01007712 unreadable for others. This is used for the newly created
zeertzjqc1c3b5d2025-03-12 21:16:13 +01007713 directories. Note: umask is applied to {prot} (on Unix).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007714 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007715 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007716
7717< This function is not available in the |sandbox|.
7718
7719 There is no error if the directory already exists and the "p"
7720 flag is passed (since patch 8.0.1708). However, without the
7721 "p" option the call will fail.
7722
7723 The function result is a Number, which is TRUE if the call was
7724 successful or FALSE if the directory creation failed or partly
7725 failed.
7726
7727 Not available on all systems. To check use: >
7728 :if exists("*mkdir")
7729
7730< Can also be used as a |method|: >
7731 GetName()->mkdir()
7732<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007733 Return type: |Number|
7734
7735
7736mode([{expr}]) *mode()*
7737 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007738 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007739 a non-empty String (|non-zero-arg|), then the full mode is
7740 returned, otherwise only the first letter is returned.
7741 Also see |state()|.
7742
7743 n Normal
7744 no Operator-pending
7745 nov Operator-pending (forced characterwise |o_v|)
7746 noV Operator-pending (forced linewise |o_V|)
7747 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7748 CTRL-V is one character
7749 niI Normal using |i_CTRL-O| in |Insert-mode|
7750 niR Normal using |i_CTRL-O| in |Replace-mode|
7751 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7752 nt Terminal-Normal (insert goes to Terminal-Job mode)
7753 v Visual by character
7754 vs Visual by character using |v_CTRL-O| in Select mode
7755 V Visual by line
7756 Vs Visual by line using |v_CTRL-O| in Select mode
7757 CTRL-V Visual blockwise
7758 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7759 s Select by character
7760 S Select by line
7761 CTRL-S Select blockwise
7762 i Insert
7763 ic Insert mode completion |compl-generic|
7764 ix Insert mode |i_CTRL-X| completion
7765 R Replace |R|
7766 Rc Replace mode completion |compl-generic|
7767 Rx Replace mode |i_CTRL-X| completion
7768 Rv Virtual Replace |gR|
7769 Rvc Virtual Replace mode completion |compl-generic|
7770 Rvx Virtual Replace mode |i_CTRL-X| completion
7771 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007772 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007773 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007774 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007775 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007776 ce Normal Ex mode |Q|
7777 r Hit-enter prompt
7778 rm The -- more -- prompt
7779 r? A |:confirm| query of some sort
7780 ! Shell or external command is executing
7781 t Terminal-Job mode: keys go to the job
7782
7783 This is useful in the 'statusline' option or when used
7784 with |remote_expr()| In most other places it always returns
7785 "c" or "n".
7786 Note that in the future more modes and more specific modes may
7787 be added. It's better not to compare the whole string but only
7788 the leading character(s).
7789 Also see |visualmode()|.
7790
7791 Can also be used as a |method|: >
7792 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007793<
7794 Return type: |String|
7795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007796
7797mzeval({expr}) *mzeval()*
7798 Evaluate MzScheme expression {expr} and return its result
7799 converted to Vim data structures.
7800 Numbers and strings are returned as they are.
7801 Pairs (including lists and improper lists) and vectors are
7802 returned as Vim |Lists|.
7803 Hash tables are represented as Vim |Dictionary| type with keys
7804 converted to strings.
7805 All other types are converted to string with display function.
7806 Examples: >
7807 :mz (define l (list 1 2 3))
7808 :mz (define h (make-hash)) (hash-set! h "list" l)
7809 :echo mzeval("l")
7810 :echo mzeval("h")
7811<
7812 Note that in a `:def` function local variables are not visible
7813 to {expr}.
7814
7815 Can also be used as a |method|: >
7816 GetExpr()->mzeval()
7817<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007818 Return type: any, depending on {expr}
7819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007820 {only available when compiled with the |+mzscheme| feature}
7821
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007823nextnonblank({lnum}) *nextnonblank()*
7824 Return the line number of the first line at or below {lnum}
7825 that is not blank. Example: >
7826 if getline(nextnonblank(1)) =~ "Java"
7827< When {lnum} is invalid or there is no non-blank line at or
7828 below it, zero is returned.
7829 {lnum} is used like with |getline()|.
7830 See also |prevnonblank()|.
7831
7832 Can also be used as a |method|: >
7833 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007834<
7835 Return type: |Number|
7836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007837
Christ van Willegenc0786752025-02-01 15:42:16 +01007838ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7839 Return a string that contains the correct value for a
7840 message based on the rules for plural form(s) in
7841 a language. Examples: >
7842 ngettext("File", "Files", 2) # returns "Files"
7843<
7844 Can be used as a |method|: >
7845 1->ngettext("File", "Files") # returns "File"
7846<
7847 See |gettext()| for information on the domain parameter.
7848
7849 Return type: |String|
7850
7851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007852nr2char({expr} [, {utf8}]) *nr2char()*
7853 Return a string with a single character, which has the number
7854 value {expr}. Examples: >
7855 nr2char(64) returns "@"
7856 nr2char(32) returns " "
7857< When {utf8} is omitted or zero, the current 'encoding' is used.
7858 Example for "utf-8": >
7859 nr2char(300) returns I with bow character
7860< When {utf8} is TRUE, always return UTF-8 characters.
7861 Note that a NUL character in the file is specified with
7862 nr2char(10), because NULs are represented with newline
7863 characters. nr2char(0) is a real NUL and terminates the
7864 string, thus results in an empty string.
7865 To turn a list of character numbers into a string: >
7866 let list = [65, 66, 67]
7867 let str = join(map(list, {_, val -> nr2char(val)}), '')
7868< Result: "ABC"
7869
7870 Can also be used as a |method|: >
7871 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007872<
7873 Return type: |String|
7874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007875
7876or({expr}, {expr}) *or()*
7877 Bitwise OR on the two arguments. The arguments are converted
7878 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007879 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007880 Example: >
7881 :let bits = or(bits, 0x80)
7882< Can also be used as a |method|: >
7883 :let bits = bits->or(0x80)
7884
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007885< Rationale: The reason this is a function and not using the "|"
7886 character like many languages, is that Vi has always used "|"
7887 to separate commands. In many places it would not be clear if
7888 "|" is an operator or a command separator.
7889
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007890 Return type: |Number|
7891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007892
7893pathshorten({path} [, {len}]) *pathshorten()*
7894 Shorten directory names in the path {path} and return the
7895 result. The tail, the file name, is kept as-is. The other
7896 components in the path are reduced to {len} letters in length.
7897 If {len} is omitted or smaller than 1 then 1 is used (single
7898 letters). Leading '~' and '.' characters are kept. Examples: >
7899 :echo pathshorten('~/.vim/autoload/myfile.vim')
7900< ~/.v/a/myfile.vim ~
7901>
7902 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7903< ~/.vi/au/myfile.vim ~
7904 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007905 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007906
7907 Can also be used as a |method|: >
7908 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007909<
7910 Return type: |String|
7911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007912
7913perleval({expr}) *perleval()*
7914 Evaluate Perl expression {expr} in scalar context and return
7915 its result converted to Vim data structures. If value can't be
7916 converted, it is returned as a string Perl representation.
7917 Note: If you want an array or hash, {expr} must return a
7918 reference to it.
7919 Example: >
7920 :echo perleval('[1 .. 4]')
7921< [1, 2, 3, 4]
7922
7923 Note that in a `:def` function local variables are not visible
7924 to {expr}.
7925
7926 Can also be used as a |method|: >
7927 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007928<
7929 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007930
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007931 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007932
7933
7934popup_ functions are documented here: |popup-functions|
7935
7936
7937pow({x}, {y}) *pow()*
7938 Return the power of {x} to the exponent {y} as a |Float|.
7939 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007940 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007941 Examples: >
7942 :echo pow(3, 3)
7943< 27.0 >
7944 :echo pow(2, 16)
7945< 65536.0 >
7946 :echo pow(32, 0.20)
7947< 2.0
7948
7949 Can also be used as a |method|: >
7950 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007951<
7952 Return type: |Number|
7953
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007954
7955prevnonblank({lnum}) *prevnonblank()*
7956 Return the line number of the first line at or above {lnum}
7957 that is not blank. Example: >
7958 let ind = indent(prevnonblank(v:lnum - 1))
7959< When {lnum} is invalid or there is no non-blank line at or
7960 above it, zero is returned.
7961 {lnum} is used like with |getline()|.
7962 Also see |nextnonblank()|.
7963
7964 Can also be used as a |method|: >
7965 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007966<
7967 Return type: |Number|
7968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007969
7970printf({fmt}, {expr1} ...) *printf()*
7971 Return a String with {fmt}, where "%" items are replaced by
7972 the formatted form of their respective arguments. Example: >
7973 printf("%4d: E%d %.30s", lnum, errno, msg)
7974< May result in:
7975 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7976
7977 When used as a |method| the base is passed as the second
7978 argument: >
7979 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007980<
7981 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007982
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007983 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007984 %s string
7985 %6S string right-aligned in 6 display cells
7986 %6s string right-aligned in 6 bytes
7987 %.9s string truncated to 9 bytes
7988 %c single byte
7989 %d decimal number
7990 %5d decimal number padded with spaces to 5 characters
7991 %x hex number
7992 %04x hex number padded with zeros to at least 4 characters
7993 %X hex number using upper case letters
7994 %o octal number
7995 %08b binary number padded with zeros to at least 8 chars
7996 %f floating point number as 12.23, inf, -inf or nan
7997 %F floating point number as 12.23, INF, -INF or NAN
7998 %e floating point number as 1.23e3, inf, -inf or nan
7999 %E floating point number as 1.23E3, INF, -INF or NAN
8000 %g floating point number, as %f or %e depending on value
8001 %G floating point number, as %F or %E depending on value
8002 %% the % character itself
8003
8004 Conversion specifications start with '%' and end with the
8005 conversion type. All other characters are copied unchanged to
8006 the result.
8007
8008 The "%" starts a conversion specification. The following
8009 arguments appear in sequence:
8010
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008011 % [pos-argument] [flags] [field-width] [.precision] type
8012
8013 pos-argument
8014 At most one positional argument specifier. These
8015 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008016
8017 flags
8018 Zero or more of the following flags:
8019
8020 # The value should be converted to an "alternate
8021 form". For c, d, and s conversions, this option
8022 has no effect. For o conversions, the precision
8023 of the number is increased to force the first
8024 character of the output string to a zero (except
8025 if a zero value is printed with an explicit
8026 precision of zero).
8027 For b and B conversions, a non-zero result has
8028 the string "0b" (or "0B" for B conversions)
8029 prepended to it.
8030 For x and X conversions, a non-zero result has
8031 the string "0x" (or "0X" for X conversions)
8032 prepended to it.
8033
8034 0 (zero) Zero padding. For all conversions the converted
8035 value is padded on the left with zeros rather
8036 than blanks. If a precision is given with a
8037 numeric conversion (d, b, B, o, x, and X), the 0
8038 flag is ignored.
8039
8040 - A negative field width flag; the converted value
8041 is to be left adjusted on the field boundary.
8042 The converted value is padded on the right with
8043 blanks, rather than on the left with blanks or
8044 zeros. A - overrides a 0 if both are given.
8045
8046 ' ' (space) A blank should be left before a positive
8047 number produced by a signed conversion (d).
8048
8049 + A sign must always be placed before a number
8050 produced by a signed conversion. A + overrides
8051 a space if both are used.
8052
8053 field-width
8054 An optional decimal digit string specifying a minimum
8055 field width. If the converted value has fewer bytes
8056 than the field width, it will be padded with spaces on
8057 the left (or right, if the left-adjustment flag has
8058 been given) to fill out the field width. For the S
8059 conversion the count is in cells.
8060
8061 .precision
8062 An optional precision, in the form of a period '.'
8063 followed by an optional digit string. If the digit
8064 string is omitted, the precision is taken as zero.
8065 This gives the minimum number of digits to appear for
8066 d, o, x, and X conversions, the maximum number of
8067 bytes to be printed from a string for s conversions,
8068 or the maximum number of cells to be printed from a
8069 string for S conversions.
8070 For floating point it is the number of digits after
8071 the decimal point.
8072
8073 type
8074 A character that specifies the type of conversion to
8075 be applied, see below.
8076
8077 A field width or precision, or both, may be indicated by an
8078 asterisk '*' instead of a digit string. In this case, a
8079 Number argument supplies the field width or precision. A
8080 negative field width is treated as a left adjustment flag
8081 followed by a positive field width; a negative precision is
8082 treated as though it were missing. Example: >
8083 :echo printf("%d: %.*s", nr, width, line)
8084< This limits the length of the text used from "line" to
8085 "width" bytes.
8086
Dominique Pellé17dca3c2023-12-14 20:36:32 +01008087 If the argument to be formatted is specified using a
8088 positional argument specifier, and a '*' is used to indicate
8089 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008090 precision, the argument(s) to be used must also be specified
8091 using a {n$} positional argument specifier. See |printf-$|.
8092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008093 The conversion specifiers and their meanings are:
8094
8095 *printf-d* *printf-b* *printf-B* *printf-o*
8096 *printf-x* *printf-X*
8097 dbBoxX The Number argument is converted to signed decimal
8098 (d), unsigned binary (b and B), unsigned octal (o), or
8099 unsigned hexadecimal (x and X) notation. The letters
8100 "abcdef" are used for x conversions; the letters
8101 "ABCDEF" are used for X conversions.
8102 The precision, if any, gives the minimum number of
8103 digits that must appear; if the converted value
8104 requires fewer digits, it is padded on the left with
8105 zeros.
8106 In no case does a non-existent or small field width
8107 cause truncation of a numeric field; if the result of
8108 a conversion is wider than the field width, the field
8109 is expanded to contain the conversion result.
8110 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02008111 The 'l' modifier indicates the argument is a long
8112 integer. The size will be 32 bits or 64 bits
8113 depending on your platform.
8114 The "ll" modifier indicates the argument is 64 bits.
8115 The b and B conversion specifiers never take a width
8116 modifier and always assume their argument is a 64 bit
8117 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008118 Generally, these modifiers are not useful. They are
8119 ignored when type is known from the argument.
8120
8121 i alias for d
8122 D alias for ld
8123 U alias for lu
8124 O alias for lo
8125
8126 *printf-c*
8127 c The Number argument is converted to a byte, and the
8128 resulting character is written.
8129
8130 *printf-s*
8131 s The text of the String argument is used. If a
8132 precision is specified, no more bytes than the number
8133 specified are used.
8134 If the argument is not a String type, it is
8135 automatically converted to text with the same format
8136 as ":echo".
8137 *printf-S*
8138 S The text of the String argument is used. If a
8139 precision is specified, no more display cells than the
8140 number specified are used.
8141
8142 *printf-f* *E807*
8143 f F The Float argument is converted into a string of the
8144 form 123.456. The precision specifies the number of
8145 digits after the decimal point. When the precision is
8146 zero the decimal point is omitted. When the precision
8147 is not specified 6 is used. A really big number
8148 (out of range or dividing by zero) results in "inf"
8149 or "-inf" with %f (INF or -INF with %F).
8150 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8151 Example: >
8152 echo printf("%.2f", 12.115)
8153< 12.12
8154 Note that roundoff depends on the system libraries.
8155 Use |round()| when in doubt.
8156
8157 *printf-e* *printf-E*
8158 e E The Float argument is converted into a string of the
8159 form 1.234e+03 or 1.234E+03 when using 'E'. The
8160 precision specifies the number of digits after the
8161 decimal point, like with 'f'.
8162
8163 *printf-g* *printf-G*
8164 g G The Float argument is converted like with 'f' if the
8165 value is between 0.001 (inclusive) and 10000000.0
8166 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8167 for 'G'. When no precision is specified superfluous
8168 zeroes and '+' signs are removed, except for the zero
8169 immediately after the decimal point. Thus 10000000.0
8170 results in 1.0e7.
8171
8172 *printf-%*
8173 % A '%' is written. No argument is converted. The
8174 complete conversion specification is "%%".
8175
8176 When a Number argument is expected a String argument is also
8177 accepted and automatically converted.
8178 When a Float or String argument is expected a Number argument
8179 is also accepted and automatically converted.
8180 Any other argument type results in an error message.
8181
8182 *E766* *E767*
8183 The number of {exprN} arguments must exactly match the number
8184 of "%" items. If there are not sufficient or too many
8185 arguments an error is given. Up to 18 arguments can be used.
8186
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008187 *printf-$*
8188 In certain languages, error and informative messages are
8189 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008190 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008191 having a different word order, positional arguments may be
8192 used to indicate this. For instance: >
8193
h_east596a9f22023-11-21 21:24:23 +09008194 #, c-format
8195 msgid "%s returning %s"
8196 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008197<
h_east596a9f22023-11-21 21:24:23 +09008198 In this example, the sentence has its 2 string arguments
8199 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008200
h_east596a9f22023-11-21 21:24:23 +09008201 echo printf(
8202 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8203 "Bram", "Moolenaar")
8204< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008205
h_east596a9f22023-11-21 21:24:23 +09008206 echo printf(
8207 "In Belgium, vim's creator's name is: %2$s %1$s",
8208 "Bram", "Moolenaar")
8209< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008210
8211 Width (and precision) can be specified using the '*' specifier.
8212 In this case, you must specify the field width position in the
8213 argument list. >
8214
h_east596a9f22023-11-21 21:24:23 +09008215 echo printf("%1$*2$.*3$d", 1, 2, 3)
8216< 001 >
8217 echo printf("%2$*3$.*1$d", 1, 2, 3)
8218< 2 >
8219 echo printf("%3$*1$.*2$d", 1, 2, 3)
8220< 03 >
8221 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8222< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008223
8224 You can mix specifying the width and/or precision directly
8225 and via positional arguments: >
8226
h_east596a9f22023-11-21 21:24:23 +09008227 echo printf("%1$4.*2$f", 1.4142135, 6)
8228< 1.414214 >
8229 echo printf("%1$*2$.4f", 1.4142135, 6)
8230< 1.4142 >
8231 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8232< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008233
Christ van Willegenc35fc032024-03-14 18:30:41 +01008234 You will get an overflow error |E1510|, when the field-width
Hirohito Higashi0ed11ba2025-04-18 18:45:31 +02008235 or precision will result in a string longer than 1 MiB
zeertzjqe9a27ef2025-04-18 10:45:45 +02008236 (1024*1024 = 1048576) chars.
Christ van Willegenc35fc032024-03-14 18:30:41 +01008237
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008238 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008239 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008240 echo printf("%s%1$s", "One", "Two")
8241< E1500: Cannot mix positional and non-positional arguments:
8242 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008243
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008244 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008245 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008246 echo printf("%3$s%1$s", "One", "Two", "Three")
8247< E1501: format argument 2 unused in $-style format:
8248 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008249
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008250 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008251 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008252 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8253< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008254
8255 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008256 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8257< E1502: Positional argument 2 used as field width reused as
8258 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008259
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008260 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008261 When a positional argument is used, but not the correct number
8262 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008263 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8264< E1503: Positional argument 3 out of bounds: %1$d at width
8265 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008266
8267 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008268 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8269< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8270 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008271
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008272 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008273 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008274 echo printf("%1$s %2$s %1$s", "One", "Two")
8275< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008276
8277 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008278 echo printf("%1$s %2$s %1$d", "One", "Two")
8279< E1504: Positional argument 1 type used inconsistently:
8280 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008281
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008282 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008283 Various other errors that lead to a format string being
8284 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008285 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8286< E1505: Invalid format specifier: %1$d at width %2$d is:
8287 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008288
Christ van Willegenea746f92023-10-05 20:48:36 +02008289 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008290 This internal error indicates that the logic to parse a
8291 positional format argument ran into a problem that couldn't be
8292 otherwise reported. Please file a bug against Vim if you run
8293 into this, copying the exact format string and parameters that
8294 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008295
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008296 Return type: |String|
8297
Christ van Willegenea746f92023-10-05 20:48:36 +02008298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008299prompt_getprompt({buf}) *prompt_getprompt()*
8300 Returns the effective prompt text for buffer {buf}. {buf} can
8301 be a buffer name or number. See |prompt-buffer|.
8302
8303 If the buffer doesn't exist or isn't a prompt buffer, an empty
8304 string is returned.
8305
8306 Can also be used as a |method|: >
8307 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008308<
8309 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008311 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008312
8313
8314prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8315 Set prompt callback for buffer {buf} to {expr}. When {expr}
8316 is an empty string the callback is removed. This has only
8317 effect if {buf} has 'buftype' set to "prompt".
8318
8319 The callback is invoked when pressing Enter. The current
8320 buffer will always be the prompt buffer. A new line for a
8321 prompt is added before invoking the callback, thus the prompt
8322 for which the callback was invoked will be in the last but one
8323 line.
8324 If the callback wants to add text to the buffer, it must
8325 insert it above the last line, since that is where the current
8326 prompt is. This can also be done asynchronously.
8327 The callback is invoked with one argument, which is the text
8328 that was entered at the prompt. This can be an empty string
8329 if the user only typed Enter.
8330 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008331 func s:TextEntered(text)
8332 if a:text == 'exit' || a:text == 'quit'
8333 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008334 " Reset 'modified' to allow the buffer to be closed.
8335 " We assume there is nothing useful to be saved.
8336 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008337 close
8338 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008339 " Do something useful with "a:text". In this example
8340 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008341 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008342 endif
8343 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008344 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008345
8346< Can also be used as a |method|: >
8347 GetBuffer()->prompt_setcallback(callback)
8348
8349< {only available when compiled with the |+channel| feature}
8350
8351prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8352 Set a callback for buffer {buf} to {expr}. When {expr} is an
8353 empty string the callback is removed. This has only effect if
8354 {buf} has 'buftype' set to "prompt".
8355
8356 This callback will be invoked when pressing CTRL-C in Insert
8357 mode. Without setting a callback Vim will exit Insert mode,
8358 as in any buffer.
8359
8360 Can also be used as a |method|: >
8361 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008362<
8363 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008364
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008365 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008366
8367prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8368 Set prompt for buffer {buf} to {text}. You most likely want
8369 {text} to end in a space.
8370 The result is only visible if {buf} has 'buftype' set to
8371 "prompt". Example: >
8372 call prompt_setprompt(bufnr(), 'command: ')
8373<
8374 Can also be used as a |method|: >
8375 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008376<
8377 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008378
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008379 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008380
8381prop_ functions are documented here: |text-prop-functions|
8382
8383pum_getpos() *pum_getpos()*
8384 If the popup menu (see |ins-completion-menu|) is not visible,
8385 returns an empty |Dictionary|, otherwise, returns a
8386 |Dictionary| with the following keys:
8387 height nr of items visible
8388 width screen cells
8389 row top screen row (0 first row)
8390 col leftmost screen column (0 first col)
8391 size total nr of items
8392 scrollbar |TRUE| if scrollbar is visible
8393
8394 The values are the same as in |v:event| during
8395 |CompleteChanged|.
8396
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008397 Return type: dict<any>
8398
8399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008400pumvisible() *pumvisible()*
8401 Returns non-zero when the popup menu is visible, zero
8402 otherwise. See |ins-completion-menu|.
8403 This can be used to avoid some things that would remove the
8404 popup menu.
8405
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008406 Return type: |Number|
8407
8408
zeertzjq7c515282024-11-10 20:26:12 +01008409py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008410 Evaluate Python expression {expr} and return its result
8411 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008412 If a {locals} |Dictionary| is given, it defines set of local
8413 variables available in the expression. The keys are variable
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008414 names and the values are the variable values. |Dictionary|,
8415 |List| and |Tuple| values are referenced, and may be updated
8416 by the expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008417 Numbers and strings are returned as they are (strings are
8418 copied though, Unicode strings are additionally converted to
8419 'encoding').
8420 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008421 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008422 Dictionaries are represented as Vim |Dictionary| type with
8423 keys converted to strings.
8424 Note that in a `:def` function local variables are not visible
8425 to {expr}.
8426
8427 Can also be used as a |method|: >
8428 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008429 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008430<
8431 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008432
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008433 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008434
8435 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008436pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008437 Evaluate Python expression {expr} and return its result
8438 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008439 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008440 Numbers and strings are returned as they are (strings are
8441 copied though).
8442 Lists are represented as Vim |List| type.
Yegappan Lakshmanan038be272025-03-26 18:46:21 +01008443 Tuples are represented as Vim |Tuple| type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008444 Dictionaries are represented as Vim |Dictionary| type,
8445 non-string keys result in error.
8446 Note that in a `:def` function local variables are not visible
8447 to {expr}.
8448
8449 Can also be used as a |method|: >
8450 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008451<
8452 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008453
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008454 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008455
zeertzjq7c515282024-11-10 20:26:12 +01008456pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008457 Evaluate Python expression {expr} and return its result
8458 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008459 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008460 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8461 See also: |pyeval()|, |py3eval()|
8462
8463 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008464 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008465<
8466 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008467
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008468 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008469 |+python3| feature}
8470
8471rand([{expr}]) *rand()* *random*
8472 Return a pseudo-random Number generated with an xoshiro128**
8473 algorithm using seed {expr}. The returned number is 32 bits,
8474 also on 64 bits systems, for consistency.
8475 {expr} can be initialized by |srand()| and will be updated by
8476 rand(). If {expr} is omitted, an internal seed value is used
8477 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008478 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008479
8480 Examples: >
8481 :echo rand()
8482 :let seed = srand()
8483 :echo rand(seed)
8484 :echo rand(seed) % 16 " random number 0 - 15
8485<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008486 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008487
8488 *E726* *E727*
8489range({expr} [, {max} [, {stride}]]) *range()*
8490 Returns a |List| with Numbers:
8491 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8492 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8493 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8494 {max}] (increasing {expr} with {stride} each time, not
8495 producing a value past {max}).
8496 When the maximum is one before the start the result is an
8497 empty list. When the maximum is more than one before the
8498 start this is an error.
8499 Examples: >
8500 range(4) " [0, 1, 2, 3]
8501 range(2, 4) " [2, 3, 4]
8502 range(2, 9, 3) " [2, 5, 8]
8503 range(2, -2, -1) " [2, 1, 0, -1, -2]
8504 range(0) " []
8505 range(2, 0) " error!
8506<
8507 Can also be used as a |method|: >
8508 GetExpr()->range()
8509<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008510 Return type: list<number>
8511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008512
K.Takata11df3ae2022-10-19 14:02:40 +01008513readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008514 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008515 If {offset} is specified, read the file from the specified
8516 offset. If it is a negative value, it is used as an offset
8517 from the end of the file. E.g., to read the last 12 bytes: >
8518 readblob('file.bin', -12)
8519< If {size} is specified, only the specified size will be read.
8520 E.g. to read the first 100 bytes of a file: >
8521 readblob('file.bin', 0, 100)
8522< If {size} is -1 or omitted, the whole data starting from
8523 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008524 This can be also used to read the data from a character device
8525 on Unix when {size} is explicitly set. Only if the device
8526 supports seeking {offset} can be used. Otherwise it should be
8527 zero. E.g. to read 10 bytes from a serial console: >
8528 readblob('/dev/ttyS0', 0, 10)
8529< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008530 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008531 When the offset is beyond the end of the file the result is an
8532 empty blob.
8533 When trying to read more bytes than are available the result
8534 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008535 Also see |readfile()| and |writefile()|.
8536
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008537 Return type: |Blob|
8538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008539
8540readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8541 Return a list with file and directory names in {directory}.
8542 You can also use |glob()| if you don't need to do complicated
8543 things, such as limiting the number of matches.
8544 The list will be sorted (case sensitive), see the {dict}
8545 argument below for changing the sort order.
8546
8547 When {expr} is omitted all entries are included.
8548 When {expr} is given, it is evaluated to check what to do:
8549 If {expr} results in -1 then no further entries will
8550 be handled.
8551 If {expr} results in 0 then this entry will not be
8552 added to the list.
8553 If {expr} results in 1 then this entry will be added
8554 to the list.
8555 The entries "." and ".." are always excluded.
8556 Each time {expr} is evaluated |v:val| is set to the entry name.
8557 When {expr} is a function the name is passed as the argument.
8558 For example, to get a list of files ending in ".txt": >
8559 readdir(dirname, {n -> n =~ '.txt$'})
8560< To skip hidden and backup files: >
8561 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008562< *E857*
8563 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008564 values. Currently this is used to specify if and how sorting
8565 should be performed. The dict can have the following members:
8566
8567 sort How to sort the result returned from the system.
8568 Valid values are:
8569 "none" do not sort (fastest method)
8570 "case" sort case sensitive (byte value of
8571 each character, technically, using
8572 strcmp()) (default)
8573 "icase" sort case insensitive (technically
8574 using strcasecmp())
8575 "collate" sort using the collation order
8576 of the "POSIX" or "C" |locale|
8577 (technically using strcoll())
8578 Other values are silently ignored.
8579
8580 For example, to get a list of all files in the current
8581 directory without sorting the individual entries: >
8582 readdir('.', '1', #{sort: 'none'})
8583< If you want to get a directory tree: >
8584 function! s:tree(dir)
8585 return {a:dir : map(readdir(a:dir),
8586 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008587 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008588 endfunction
8589 echo s:tree(".")
8590<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008591 Returns an empty List on error.
8592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008593 Can also be used as a |method|: >
8594 GetDirName()->readdir()
8595<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008596 Return type: list<string> or list<any>
8597
8598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008599readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8600 Extended version of |readdir()|.
8601 Return a list of Dictionaries with file and directory
8602 information in {directory}.
8603 This is useful if you want to get the attributes of file and
8604 directory at the same time as getting a list of a directory.
8605 This is much faster than calling |readdir()| then calling
8606 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8607 each file and directory especially on MS-Windows.
8608 The list will by default be sorted by name (case sensitive),
8609 the sorting can be changed by using the optional {dict}
8610 argument, see |readdir()|.
8611
8612 The Dictionary for file and directory information has the
8613 following items:
8614 group Group name of the entry. (Only on Unix)
8615 name Name of the entry.
8616 perm Permissions of the entry. See |getfperm()|.
8617 size Size of the entry. See |getfsize()|.
8618 time Timestamp of the entry. See |getftime()|.
8619 type Type of the entry.
8620 On Unix, almost same as |getftype()| except:
8621 Symlink to a dir "linkd"
8622 Other symlink "link"
8623 On MS-Windows:
8624 Normal file "file"
8625 Directory "dir"
8626 Junction "junction"
8627 Symlink to a dir "linkd"
8628 Other symlink "link"
8629 Other reparse point "reparse"
8630 user User name of the entry's owner. (Only on Unix)
8631 On Unix, if the entry is a symlink, the Dictionary includes
8632 the information of the target (except the "type" item).
8633 On MS-Windows, it includes the information of the symlink
8634 itself because of performance reasons.
8635
8636 When {expr} is omitted all entries are included.
8637 When {expr} is given, it is evaluated to check what to do:
8638 If {expr} results in -1 then no further entries will
8639 be handled.
8640 If {expr} results in 0 then this entry will not be
8641 added to the list.
8642 If {expr} results in 1 then this entry will be added
8643 to the list.
8644 The entries "." and ".." are always excluded.
8645 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8646 of the entry.
8647 When {expr} is a function the entry is passed as the argument.
8648 For example, to get a list of files ending in ".txt": >
8649 readdirex(dirname, {e -> e.name =~ '.txt$'})
8650<
8651 For example, to get a list of all files in the current
8652 directory without sorting the individual entries: >
8653 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008654<
8655 Can also be used as a |method|: >
8656 GetDirName()->readdirex()
8657<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008658 Return type: list<dict<any>> or list<any>
8659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008660
8661 *readfile()*
8662readfile({fname} [, {type} [, {max}]])
8663 Read file {fname} and return a |List|, each line of the file
8664 as an item. Lines are broken at NL characters. Macintosh
8665 files separated with CR will result in a single long line
8666 (unless a NL appears somewhere).
8667 All NUL characters are replaced with a NL character.
8668 When {type} contains "b" binary mode is used:
8669 - When the last line ends in a NL an extra empty list item is
8670 added.
8671 - No CR characters are removed.
8672 Otherwise:
8673 - CR characters that appear before a NL are removed.
8674 - Whether the last line ends in a NL or not does not matter.
8675 - When 'encoding' is Unicode any UTF-8 byte order mark is
8676 removed from the text.
8677 When {max} is given this specifies the maximum number of lines
8678 to be read. Useful if you only want to check the first ten
8679 lines of a file: >
8680 :for line in readfile(fname, '', 10)
8681 : if line =~ 'Date' | echo line | endif
8682 :endfor
8683< When {max} is negative -{max} lines from the end of the file
8684 are returned, or as many as there are.
8685 When {max} is zero the result is an empty list.
8686 Note that without {max} the whole file is read into memory.
8687 Also note that there is no recognition of encoding. Read a
8688 file into a buffer if you need to.
8689 Deprecated (use |readblob()| instead): When {type} contains
8690 "B" a |Blob| is returned with the binary data of the file
8691 unmodified.
8692 When the file can't be opened an error message is given and
8693 the result is an empty list.
8694 Also see |writefile()|.
8695
8696 Can also be used as a |method|: >
8697 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008698<
8699 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008700
8701reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8702 {func} is called for every item in {object}, which can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01008703 |String|, |List|, |Tuple| or a |Blob|. {func} is called with
8704 two arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008705 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008706
8707 {initial} is the initial result. When omitted, the first item
8708 in {object} is used and {func} is first called for the second
8709 item. If {initial} is not given and {object} is empty no
8710 result can be computed, an E998 error is given.
8711
8712 Examples: >
8713 echo reduce([1, 3, 5], { acc, val -> acc + val })
8714 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8715 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8716 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8717<
8718 Can also be used as a |method|: >
8719 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008720<
8721 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8722 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008723
8724
8725reg_executing() *reg_executing()*
8726 Returns the single letter name of the register being executed.
8727 Returns an empty string when no register is being executed.
8728 See |@|.
8729
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008730 Return type: |String|
8731
8732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008733reg_recording() *reg_recording()*
8734 Returns the single letter name of the register being recorded.
8735 Returns an empty string when not recording. See |q|.
8736
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008737 Return type: |String|
8738
8739
8740reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008741reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008742reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008743 Return an item that represents a time value. The item is a
8744 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008745 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008746 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008747 string or |reltimefloat()| to convert to a Float. For
8748 example, to see the time spent in function Work(): >
8749 var startTime = reltime()
8750 Work()
8751 echo startTime->reltime()->reltimestr()
8752<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008753 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008754 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008755 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008756 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008757 specified in the argument.
8758 With two arguments it returns the time passed between {start}
8759 and {end}.
8760
8761 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008762 reltime(). If there is an error an empty List is returned in
8763 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008764
8765 Can also be used as a |method|: >
8766 GetStart()->reltime()
8767<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008768 Return type: list<number>
8769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008770 {only available when compiled with the |+reltime| feature}
8771
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008773reltimefloat({time}) *reltimefloat()*
8774 Return a Float that represents the time value of {time}.
8775 Example: >
8776 let start = reltime()
8777 call MyFunction()
8778 let seconds = reltimefloat(reltime(start))
8779< See the note of reltimestr() about overhead.
8780 Also see |profiling|.
8781 If there is an error 0.0 is returned in legacy script, in Vim9
8782 script an error is given.
8783
8784 Can also be used as a |method|: >
8785 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008786<
8787 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008788
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008789 {only available when compiled with the |+reltime| feature}
8790
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008791
8792reltimestr({time}) *reltimestr()*
8793 Return a String that represents the time value of {time}.
8794 This is the number of seconds, a dot and the number of
8795 microseconds. Example: >
8796 let start = reltime()
8797 call MyFunction()
8798 echo reltimestr(reltime(start))
8799< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008800 The accuracy depends on the system. Use reltimefloat() for the
8801 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008802 Leading spaces are used to make the string align nicely. You
8803 can use split() to remove it. >
8804 echo split(reltimestr(reltime(start)))[0]
8805< Also see |profiling|.
8806 If there is an error an empty string is returned in legacy
8807 script, in Vim9 script an error is given.
8808
8809 Can also be used as a |method|: >
8810 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008811<
8812 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008813
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008814 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008815
8816 *remote_expr()* *E449*
8817remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008818 Send the {string} to {server}. The {server} argument is a
8819 string, also see |{server}|.
8820
8821 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008822 after evaluation. The result must be a String or a |List|
8823 other types will be converted to String. A |List| is turned
8824 into a String by joining the items with a line break in
8825 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008827 If {idvar} is present and not empty, it is taken as the name
8828 of a variable and a {serverid} for later use with
8829 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008831 If {timeout} is given the read times out after this many
8832 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008834 See also |clientserver| |RemoteReply|.
8835 This function is not available in the |sandbox|.
8836 {only available when compiled with the |+clientserver| feature}
8837 Note: Any errors will cause a local error message to be issued
8838 and the result will be the empty string.
8839
8840 Variables will be evaluated in the global namespace,
8841 independent of a function currently being active. Except
8842 when in debug mode, then local function variables and
8843 arguments can be evaluated.
8844
8845 Examples: >
8846 :echo remote_expr("gvim", "2+2")
8847 :echo remote_expr("gvim1", "b:current_syntax")
8848<
8849 Can also be used as a |method|: >
8850 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008851<
8852 Return type: |String| or list<{type}>
8853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008854
8855remote_foreground({server}) *remote_foreground()*
8856 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008857 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008858 This works like: >
8859 remote_expr({server}, "foreground()")
8860< Except that on Win32 systems the client does the work, to work
8861 around the problem that the OS doesn't always allow the server
8862 to bring itself to the foreground.
8863 Note: This does not restore the window if it was minimized,
8864 like foreground() does.
8865 This function is not available in the |sandbox|.
8866
8867 Can also be used as a |method|: >
8868 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008869<
8870 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008871
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008872 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008873 Win32 console version}
8874
8875
8876remote_peek({serverid} [, {retvar}]) *remote_peek()*
8877 Returns a positive number if there are available strings
8878 from {serverid}. Copies any reply string into the variable
8879 {retvar} if specified. {retvar} must be a string with the
8880 name of a variable.
8881 Returns zero if none are available.
8882 Returns -1 if something is wrong.
8883 See also |clientserver|.
8884 This function is not available in the |sandbox|.
8885 {only available when compiled with the |+clientserver| feature}
8886 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008887 :let repl = ""
8888 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008889
8890< Can also be used as a |method|: >
8891 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008892<
8893 Return type: |Number|
8894
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008895
8896remote_read({serverid}, [{timeout}]) *remote_read()*
8897 Return the oldest available reply from {serverid} and consume
8898 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008899 reply is available. Returns an empty string, if a reply is
8900 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008901 See also |clientserver|.
8902 This function is not available in the |sandbox|.
8903 {only available when compiled with the |+clientserver| feature}
8904 Example: >
8905 :echo remote_read(id)
8906
8907< Can also be used as a |method|: >
8908 ServerId()->remote_read()
8909<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008910 Return type: |String|
8911
8912
8913remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008914 Send the {string} to {server}. The {server} argument is a
8915 string, also see |{server}|.
8916
8917 The string is sent as input keys and the function returns
8918 immediately. At the Vim server the keys are not mapped
8919 |:map|.
8920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008921 If {idvar} is present, it is taken as the name of a variable
8922 and a {serverid} for later use with remote_read() is stored
8923 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008925 See also |clientserver| |RemoteReply|.
8926 This function is not available in the |sandbox|.
8927 {only available when compiled with the |+clientserver| feature}
8928
8929 Note: Any errors will be reported in the server and may mess
8930 up the display.
8931 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008932 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008933 \ remote_read(serverid)
8934
8935 :autocmd NONE RemoteReply *
8936 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008937 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008938 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8939<
8940 Can also be used as a |method|: >
8941 ServerName()->remote_send(keys)
8942<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008943 Return type: |String|
8944
8945
8946remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008947 Become the server {name}. {name} must be a non-empty string.
8948 This fails if already running as a server, when |v:servername|
8949 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008950
8951 Can also be used as a |method|: >
8952 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008953<
8954 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008955
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008956 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008957
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008958
8959remove({list}, {idx}) *remove()*
8960remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008961 Without {end}: Remove the item at {idx} from |List| {list} and
8962 return the item.
8963 With {end}: Remove items from {idx} to {end} (inclusive) and
8964 return a |List| with these items. When {idx} points to the same
8965 item as {end} a list with one item is returned. When {end}
8966 points to an item before {idx} this is an error.
8967 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008968 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008969 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008970 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008971 :call remove(mylist, 0, 9)
8972<
8973 Use |delete()| to remove a file.
8974
8975 Can also be used as a |method|: >
8976 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008977<
8978 Return type: any, depending on {list}
8979
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008980
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008981remove({blob}, {idx})
8982remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008983 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8984 return the byte.
8985 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8986 return a |Blob| with these bytes. When {idx} points to the same
8987 byte as {end} a |Blob| with one byte is returned. When {end}
8988 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008989 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008990 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008991 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008992 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008993<
8994 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008995
8996remove({dict}, {key})
8997 Remove the entry from {dict} with key {key} and return it.
8998 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008999 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009000< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009001 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009002
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009003 Return type: any, depending on {dict}
9004
9005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009006rename({from}, {to}) *rename()*
9007 Rename the file by the name {from} to the name {to}. This
9008 should also work to move files across file systems. The
9009 result is a Number, which is 0 if the file was renamed
9010 successfully, and non-zero when the renaming failed.
9011 NOTE: If {to} exists it is overwritten without warning.
9012 This function is not available in the |sandbox|.
9013
9014 Can also be used as a |method|: >
9015 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009016<
9017 Return type: |Number|
9018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009019
9020repeat({expr}, {count}) *repeat()*
9021 Repeat {expr} {count} times and return the concatenated
9022 result. Example: >
9023 :let separator = repeat('-', 80)
9024< When {count} is zero or negative the result is empty.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009025 When {expr} is a |List|, a |Tuple| or a |Blob| the result is
9026 {expr} concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009027 :let longlist = repeat(['a', 'b'], 3)
9028< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
9029
9030 Can also be used as a |method|: >
9031 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009032<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009033 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
9034 depending on {expr}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009036
9037resolve({filename}) *resolve()* *E655*
9038 On MS-Windows, when {filename} is a shortcut (a .lnk file),
9039 returns the path the shortcut points to in a simplified form.
9040 When {filename} is a symbolic link or junction point, return
9041 the full path to the target. If the target of junction is
9042 removed, return {filename}.
9043 On Unix, repeat resolving symbolic links in all path
9044 components of {filename} and return the simplified result.
9045 To cope with link cycles, resolving of symbolic links is
9046 stopped after 100 iterations.
9047 On other systems, return the simplified {filename}.
9048 The simplification step is done as by |simplify()|.
9049 resolve() keeps a leading path component specifying the
9050 current directory (provided the result is still a relative
9051 path name) and also keeps a trailing path separator.
9052
9053 Can also be used as a |method|: >
9054 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009055<
9056 Return type: |String|
9057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009058
9059reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009060 Reverse the order of items in {object}. {object} can be a
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009061 |List|, a |Tuple|, a |Blob| or a |String|. For a List and a
9062 Blob the items are reversed in-place and {object} is returned.
9063 For a Tuple, a new Tuple is returned.
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01009064 For a String a new String is returned.
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009065 Returns zero if {object} is not a List, Tuple, Blob or a
9066 String. If you want a List or Blob to remain unmodified make
9067 a copy first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009068 :let revlist = reverse(copy(mylist))
9069< Can also be used as a |method|: >
9070 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009071<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01009072 Return type: |String|, |Blob|, list<{type}> or tuple<{type}>
9073 depending on {object}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009075
9076round({expr}) *round()*
9077 Round off {expr} to the nearest integral value and return it
9078 as a |Float|. If {expr} lies halfway between two integral
9079 values, then use the larger one (away from zero).
9080 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009081 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009082 Examples: >
9083 echo round(0.456)
9084< 0.0 >
9085 echo round(4.5)
9086< 5.0 >
9087 echo round(-4.5)
9088< -5.0
9089
9090 Can also be used as a |method|: >
9091 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009092<
9093 Return type: |Float|
9094
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009095
9096rubyeval({expr}) *rubyeval()*
9097 Evaluate Ruby expression {expr} and return its result
9098 converted to Vim data structures.
9099 Numbers, floats and strings are returned as they are (strings
9100 are copied though).
9101 Arrays are represented as Vim |List| type.
9102 Hashes are represented as Vim |Dictionary| type.
9103 Other objects are represented as strings resulted from their
9104 "Object#to_s" method.
9105 Note that in a `:def` function local variables are not visible
9106 to {expr}.
9107
9108 Can also be used as a |method|: >
9109 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009110<
9111 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009112
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009113 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009114
9115screenattr({row}, {col}) *screenattr()*
9116 Like |screenchar()|, but return the attribute. This is a rather
9117 arbitrary number that can only be used to compare to the
9118 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009119 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009120
9121 Can also be used as a |method|: >
9122 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009123<
9124 Return type: |Number|
9125
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009126
9127screenchar({row}, {col}) *screenchar()*
9128 The result is a Number, which is the character at position
9129 [row, col] on the screen. This works for every possible
9130 screen position, also status lines, window separators and the
9131 command line. The top left position is row one, column one
9132 The character excludes composing characters. For double-byte
9133 encodings it may only be the first byte.
9134 This is mainly to be used for testing.
9135 Returns -1 when row or col is out of range.
9136
9137 Can also be used as a |method|: >
9138 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009139<
9140 Return type: |Number|
9141
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009142
9143screenchars({row}, {col}) *screenchars()*
9144 The result is a |List| of Numbers. The first number is the same
9145 as what |screenchar()| returns. Further numbers are
9146 composing characters on top of the base character.
9147 This is mainly to be used for testing.
9148 Returns an empty List when row or col is out of range.
9149
9150 Can also be used as a |method|: >
9151 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009152<
9153 Return type: list<number> or list<any>
9154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009155
9156screencol() *screencol()*
9157 The result is a Number, which is the current screen column of
9158 the cursor. The leftmost column has number 1.
9159 This function is mainly used for testing.
9160
9161 Note: Always returns the current screen column, thus if used
9162 in a command (e.g. ":echo screencol()") it will return the
9163 column inside the command line, which is 1 when the command is
9164 executed. To get the cursor position in the file use one of
9165 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009166 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009167 nnoremap <silent> GG :echom screencol()<CR>
9168 nnoremap GG <Cmd>echom screencol()<CR>
9169<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009170 Return type: |Number|
9171
9172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009173screenpos({winid}, {lnum}, {col}) *screenpos()*
9174 The result is a Dict with the screen position of the text
9175 character in window {winid} at buffer line {lnum} and column
9176 {col}. {col} is a one-based byte index.
9177 The Dict has these members:
9178 row screen row
9179 col first screen column
9180 endcol last screen column
9181 curscol cursor screen column
9182 If the specified position is not visible, all values are zero.
9183 The "endcol" value differs from "col" when the character
9184 occupies more than one screen cell. E.g. for a Tab "col" can
9185 be 1 and "endcol" can be 8.
9186 The "curscol" value is where the cursor would be placed. For
9187 a Tab it would be the same as "endcol", while for a double
9188 width character it would be the same as "col".
9189 The |conceal| feature is ignored here, the column numbers are
9190 as if 'conceallevel' is zero. You can set the cursor to the
9191 right position and use |screencol()| to get the value with
9192 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009193 If the position is in a closed fold the screen position of the
9194 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009195 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009196
9197 Can also be used as a |method|: >
9198 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009199<
9200 Return type: dict<number> or dict<any>
9201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009202
9203screenrow() *screenrow()*
9204 The result is a Number, which is the current screen row of the
9205 cursor. The top line has number one.
9206 This function is mainly used for testing.
9207 Alternatively you can use |winline()|.
9208
9209 Note: Same restrictions as with |screencol()|.
9210
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009211 Return type: |Number|
9212
9213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009214screenstring({row}, {col}) *screenstring()*
9215 The result is a String that contains the base character and
9216 any composing characters at position [row, col] on the screen.
9217 This is like |screenchars()| but returning a String with the
9218 characters.
9219 This is mainly to be used for testing.
9220 Returns an empty String when row or col is out of range.
9221
9222 Can also be used as a |method|: >
9223 GetRow()->screenstring(col)
9224<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009225 Return type: |String|
9226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009227 *search()*
9228search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9229 Search for regexp pattern {pattern}. The search starts at the
9230 cursor position (you can use |cursor()| to set it).
9231
9232 When a match has been found its line number is returned.
9233 If there is no match a 0 is returned and the cursor doesn't
9234 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009235 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009236
9237 {flags} is a String, which can contain these character flags:
9238 'b' search Backward instead of forward
9239 'c' accept a match at the Cursor position
9240 'e' move to the End of the match
9241 'n' do Not move the cursor
9242 'p' return number of matching sub-Pattern (see below)
9243 's' Set the ' mark at the previous location of the cursor
9244 'w' Wrap around the end of the file
9245 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009246 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009247 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9248
9249 If the 's' flag is supplied, the ' mark is set, only if the
9250 cursor is moved. The 's' flag cannot be combined with the 'n'
9251 flag.
9252
9253 'ignorecase', 'smartcase' and 'magic' are used.
9254
9255 When the 'z' flag is not given, forward searching always
9256 starts in column zero and then matches before the cursor are
9257 skipped. When the 'c' flag is present in 'cpo' the next
9258 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009259 search starts one column after the start of the match. This
9260 matters for overlapping matches. See |cpo-c|. You can also
9261 insert "\ze" to change where the match ends, see |/\ze|.
9262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009263 When searching backwards and the 'z' flag is given then the
9264 search starts in column zero, thus no match in the current
9265 line will be found (unless wrapping around the end of the
9266 file).
9267
9268 When the {stopline} argument is given then the search stops
9269 after searching this line. This is useful to restrict the
9270 search to a range of lines. Examples: >
9271 let match = search('(', 'b', line("w0"))
9272 let end = search('END', '', line("w$"))
9273< When {stopline} is used and it is not zero this also implies
9274 that the search does not wrap around the end of the file.
9275 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009276 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009277 When the {timeout} argument is given the search stops when
9278 more than this many milliseconds have passed. Thus when
9279 {timeout} is 500 the search stops after half a second.
9280 The value must not be negative. A zero value is like not
9281 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009282
9283 Note: the timeout is only considered when searching, not
9284 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009285 {only available when compiled with the |+reltime| feature}
9286
9287 If the {skip} expression is given it is evaluated with the
9288 cursor positioned on the start of a match. If it evaluates to
9289 non-zero this match is skipped. This can be used, for
9290 example, to skip a match in a comment or a string.
9291 {skip} can be a string, which is evaluated as an expression, a
9292 function reference or a lambda.
9293 When {skip} is omitted or empty, every match is accepted.
9294 When evaluating {skip} causes an error the search is aborted
9295 and -1 returned.
9296 *search()-sub-match*
9297 With the 'p' flag the returned value is one more than the
9298 first sub-match in \(\). One if none of them matched but the
9299 whole pattern did match.
9300 To get the column number too use |searchpos()|.
9301
9302 The cursor will be positioned at the match, unless the 'n'
9303 flag is used.
9304
9305 Example (goes over all files in the argument list): >
9306 :let n = 1
9307 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009308 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009309 : " start at the last char in the file and wrap for the
9310 : " first search to find match at start of file
9311 : normal G$
9312 : let flags = "w"
9313 : while search("foo", flags) > 0
9314 : s/foo/bar/g
9315 : let flags = "W"
9316 : endwhile
9317 : update " write the file if modified
9318 : let n = n + 1
9319 :endwhile
9320<
9321 Example for using some flags: >
9322 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9323< This will search for the keywords "if", "else", and "endif"
9324 under or after the cursor. Because of the 'p' flag, it
9325 returns 1, 2, or 3 depending on which keyword is found, or 0
9326 if the search fails. With the cursor on the first word of the
9327 line:
9328 if (foo == 0) | let foo = foo + 1 | endif ~
9329 the function returns 1. Without the 'c' flag, the function
9330 finds the "endif" and returns 3. The same thing happens
9331 without the 'e' flag if the cursor is on the "f" of "if".
9332 The 'n' flag tells the function not to move the cursor.
9333
9334 Can also be used as a |method|: >
9335 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009336<
9337 Return type: |Number|
9338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339
9340searchcount([{options}]) *searchcount()*
9341 Get or update the last search count, like what is displayed
9342 without the "S" flag in 'shortmess'. This works even if
9343 'shortmess' does contain the "S" flag.
9344
9345 This returns a |Dictionary|. The dictionary is empty if the
9346 previous pattern was not set and "pattern" was not specified.
9347
9348 key type meaning ~
9349 current |Number| current position of match;
9350 0 if the cursor position is
9351 before the first match
9352 exact_match |Boolean| 1 if "current" is matched on
9353 "pos", otherwise 0
9354 total |Number| total count of matches found
9355 incomplete |Number| 0: search was fully completed
9356 1: recomputing was timed out
9357 2: max count exceeded
9358
9359 For {options} see further down.
9360
9361 To get the last search count when |n| or |N| was pressed, call
9362 this function with `recompute: 0` . This sometimes returns
9363 wrong information because |n| and |N|'s maximum count is 99.
9364 If it exceeded 99 the result must be max count + 1 (100). If
9365 you want to get correct information, specify `recompute: 1`: >
9366
9367 " result == maxcount + 1 (100) when many matches
9368 let result = searchcount(#{recompute: 0})
9369
9370 " Below returns correct result (recompute defaults
9371 " to 1)
9372 let result = searchcount()
9373<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009374 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009375 function! LastSearchCount() abort
9376 let result = searchcount(#{recompute: 0})
9377 if empty(result)
9378 return ''
9379 endif
9380 if result.incomplete ==# 1 " timed out
9381 return printf(' /%s [?/??]', @/)
9382 elseif result.incomplete ==# 2 " max count exceeded
9383 if result.total > result.maxcount &&
9384 \ result.current > result.maxcount
9385 return printf(' /%s [>%d/>%d]', @/,
9386 \ result.current, result.total)
9387 elseif result.total > result.maxcount
9388 return printf(' /%s [%d/>%d]', @/,
9389 \ result.current, result.total)
9390 endif
9391 endif
9392 return printf(' /%s [%d/%d]', @/,
9393 \ result.current, result.total)
9394 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009395 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009396
9397 " Or if you want to show the count only when
9398 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009399 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009400 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9401<
9402 You can also update the search count, which can be useful in a
9403 |CursorMoved| or |CursorMovedI| autocommand: >
9404
9405 autocmd CursorMoved,CursorMovedI *
9406 \ let s:searchcount_timer = timer_start(
9407 \ 200, function('s:update_searchcount'))
9408 function! s:update_searchcount(timer) abort
9409 if a:timer ==# s:searchcount_timer
9410 call searchcount(#{
9411 \ recompute: 1, maxcount: 0, timeout: 100})
9412 redrawstatus
9413 endif
9414 endfunction
9415<
9416 This can also be used to count matched texts with specified
9417 pattern in the current buffer using "pattern": >
9418
9419 " Count '\<foo\>' in this buffer
9420 " (Note that it also updates search count)
9421 let result = searchcount(#{pattern: '\<foo\>'})
9422
9423 " To restore old search count by old pattern,
9424 " search again
9425 call searchcount()
9426<
9427 {options} must be a |Dictionary|. It can contain:
9428 key type meaning ~
9429 recompute |Boolean| if |TRUE|, recompute the count
9430 like |n| or |N| was executed.
9431 otherwise returns the last
9432 computed result (when |n| or
9433 |N| was used when "S" is not
9434 in 'shortmess', or this
9435 function was called).
9436 (default: |TRUE|)
9437 pattern |String| recompute if this was given
9438 and different with |@/|.
9439 this works as same as the
9440 below command is executed
9441 before calling this function >
9442 let @/ = pattern
9443< (default: |@/|)
9444 timeout |Number| 0 or negative number is no
9445 timeout. timeout milliseconds
9446 for recomputing the result
9447 (default: 0)
9448 maxcount |Number| 0 or negative number is no
9449 limit. max count of matched
9450 text while recomputing the
9451 result. if search exceeded
9452 total count, "total" value
9453 becomes `maxcount + 1`
9454 (default: 99)
9455 pos |List| `[lnum, col, off]` value
9456 when recomputing the result.
9457 this changes "current" result
9458 value. see |cursor()|,
9459 |getpos()|
9460 (default: cursor's position)
9461
9462 Can also be used as a |method|: >
9463 GetSearchOpts()->searchcount()
9464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009465 Return type: dict<number>
9466
9467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009468searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9469 Search for the declaration of {name}.
9470
9471 With a non-zero {global} argument it works like |gD|, find
9472 first match in the file. Otherwise it works like |gd|, find
9473 first match in the function.
9474
9475 With a non-zero {thisblock} argument matches in a {} block
9476 that ends before the cursor position are ignored. Avoids
9477 finding variable declarations only valid in another scope.
9478
9479 Moves the cursor to the found match.
9480 Returns zero for success, non-zero for failure.
9481 Example: >
9482 if searchdecl('myvar') == 0
9483 echo getline('.')
9484 endif
9485<
9486 Can also be used as a |method|: >
9487 GetName()->searchdecl()
9488<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009489 Return type: |Number|
9490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009491 *searchpair()*
9492searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9493 [, {stopline} [, {timeout}]]]])
9494 Search for the match of a nested start-end pair. This can be
9495 used to find the "endif" that matches an "if", while other
9496 if/endif pairs in between are ignored.
9497 The search starts at the cursor. The default is to search
9498 forward, include 'b' in {flags} to search backward.
9499 If a match is found, the cursor is positioned at it and the
9500 line number is returned. If no match is found 0 or -1 is
9501 returned and the cursor doesn't move. No error message is
9502 given.
9503
9504 {start}, {middle} and {end} are patterns, see |pattern|. They
9505 must not contain \( \) pairs. Use of \%( \) is allowed. When
9506 {middle} is not empty, it is found when searching from either
9507 direction, but only when not in a nested start-end pair. A
9508 typical use is: >
9509 searchpair('\<if\>', '\<else\>', '\<endif\>')
9510< By leaving {middle} empty the "else" is skipped.
9511
9512 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9513 |search()|. Additionally:
9514 'r' Repeat until no more matches found; will find the
9515 outer pair. Implies the 'W' flag.
9516 'm' Return number of matches instead of line number with
9517 the match; will be > 1 when 'r' is used.
9518 Note: it's nearly always a good idea to use the 'W' flag, to
9519 avoid wrapping around the end of the file.
9520
9521 When a match for {start}, {middle} or {end} is found, the
9522 {skip} expression is evaluated with the cursor positioned on
9523 the start of the match. It should return non-zero if this
9524 match is to be skipped. E.g., because it is inside a comment
9525 or a string.
9526 When {skip} is omitted or empty, every match is accepted.
9527 When evaluating {skip} causes an error the search is aborted
9528 and -1 returned.
9529 {skip} can be a string, a lambda, a funcref or a partial.
9530 Anything else makes the function fail.
9531 In a `:def` function when the {skip} argument is a string
9532 constant it is compiled into instructions.
9533
9534 For {stopline} and {timeout} see |search()|.
9535
9536 The value of 'ignorecase' is used. 'magic' is ignored, the
9537 patterns are used like it's on.
9538
9539 The search starts exactly at the cursor. A match with
9540 {start}, {middle} or {end} at the next character, in the
9541 direction of searching, is the first one found. Example: >
9542 if 1
9543 if 2
9544 endif 2
9545 endif 1
9546< When starting at the "if 2", with the cursor on the "i", and
9547 searching forwards, the "endif 2" is found. When starting on
9548 the character just before the "if 2", the "endif 1" will be
9549 found. That's because the "if 2" will be found first, and
9550 then this is considered to be a nested if/endif from "if 2" to
9551 "endif 2".
9552 When searching backwards and {end} is more than one character,
9553 it may be useful to put "\zs" at the end of the pattern, so
9554 that when the cursor is inside a match with the end it finds
9555 the matching start.
9556
9557 Example, to find the "endif" command in a Vim script: >
9558
9559 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9560 \ 'getline(".") =~ "^\\s*\""')
9561
9562< The cursor must be at or after the "if" for which a match is
9563 to be found. Note that single-quote strings are used to avoid
9564 having to double the backslashes. The skip expression only
9565 catches comments at the start of a line, not after a command.
9566 Also, a word "en" or "if" halfway a line is considered a
9567 match.
9568 Another example, to search for the matching "{" of a "}": >
9569
9570 :echo searchpair('{', '', '}', 'bW')
9571
9572< This works when the cursor is at or before the "}" for which a
9573 match is to be found. To reject matches that syntax
9574 highlighting recognized as strings: >
9575
9576 :echo searchpair('{', '', '}', 'bW',
9577 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9578<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009579 Return type: |Number|
9580
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009581 *searchpairpos()*
9582searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9583 [, {stopline} [, {timeout}]]]])
9584 Same as |searchpair()|, but returns a |List| with the line and
9585 column position of the match. The first element of the |List|
9586 is the line number and the second element is the byte index of
9587 the column position of the match. If no match is found,
9588 returns [0, 0]. >
9589
9590 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9591<
9592 See |match-parens| for a bigger and more useful example.
9593
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009594 Return type: list<number>
9595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009596 *searchpos()*
9597searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9598 Same as |search()|, but returns a |List| with the line and
9599 column position of the match. The first element of the |List|
9600 is the line number and the second element is the byte index of
9601 the column position of the match. If no match is found,
9602 returns [0, 0].
9603 Example: >
9604 :let [lnum, col] = searchpos('mypattern', 'n')
9605
9606< When the 'p' flag is given then there is an extra item with
9607 the sub-pattern match number |search()-sub-match|. Example: >
9608 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9609< In this example "submatch" is 2 when a lowercase letter is
9610 found |/\l|, 3 when an uppercase letter is found |/\u|.
9611
9612 Can also be used as a |method|: >
9613 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009614<
9615 Return type: list<number>
9616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009617
9618server2client({clientid}, {string}) *server2client()*
9619 Send a reply string to {clientid}. The most recent {clientid}
9620 that sent a string can be retrieved with expand("<client>").
9621 {only available when compiled with the |+clientserver| feature}
9622 Returns zero for success, -1 for failure.
9623 Note:
9624 This id has to be stored before the next command can be
9625 received. I.e. before returning from the received command and
9626 before calling any commands that waits for input.
9627 See also |clientserver|.
9628 Example: >
9629 :echo server2client(expand("<client>"), "HELLO")
9630
9631< Can also be used as a |method|: >
9632 GetClientId()->server2client(string)
9633<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009634 Return type: |Number|
9635
9636
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009637serverlist() *serverlist()*
9638 Return a list of available server names, one per line.
9639 When there are no servers or the information is not available
9640 an empty string is returned. See also |clientserver|.
9641 {only available when compiled with the |+clientserver| feature}
9642 Example: >
9643 :echo serverlist()
9644<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009645 Return type: |String|
9646
9647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009648setbufline({buf}, {lnum}, {text}) *setbufline()*
9649 Set line {lnum} to {text} in buffer {buf}. This works like
9650 |setline()| for the specified buffer.
9651
9652 This function works only for loaded buffers. First call
9653 |bufload()| if needed.
9654
9655 To insert lines use |appendbufline()|.
9656 Any text properties in {lnum} are cleared.
9657
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009658 {text} can be a string to set one line, or a List of strings
9659 to set multiple lines. If the List extends below the last
9660 line then those lines are added. If the List is empty then
9661 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009662
9663 For the use of {buf}, see |bufname()| above.
9664
9665 {lnum} is used like with |setline()|.
9666 Use "$" to refer to the last line in buffer {buf}.
9667 When {lnum} is just below the last line the {text} will be
9668 added below the last line.
9669
9670 When {buf} is not a valid buffer, the buffer is not loaded or
9671 {lnum} is not valid then 1 is returned. In |Vim9| script an
9672 error is given.
9673 On success 0 is returned.
9674
9675 Can also be used as a |method|, the base is passed as the
9676 third argument: >
9677 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009678<
9679 Return type: |Number|
9680
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009681
9682setbufvar({buf}, {varname}, {val}) *setbufvar()*
9683 Set option or local variable {varname} in buffer {buf} to
9684 {val}.
9685 This also works for a global or local window option, but it
9686 doesn't work for a global or local window variable.
9687 For a local window option the global value is unchanged.
9688 For the use of {buf}, see |bufname()| above.
9689 The {varname} argument is a string.
9690 Note that the variable name without "b:" must be used.
9691 Examples: >
9692 :call setbufvar(1, "&mod", 1)
9693 :call setbufvar("todo", "myvar", "foobar")
9694< This function is not available in the |sandbox|.
9695
9696 Can also be used as a |method|, the base is passed as the
9697 third argument: >
9698 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009699<
9700 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009701
9702
9703setcellwidths({list}) *setcellwidths()*
9704 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009705 tells Vim how wide characters are when displayed in the
9706 terminal, counted in screen cells. The values override
9707 'ambiwidth'. Example: >
9708 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009709 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009710 \ [0x2194, 0x2199, 2],
9711 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009712
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009713< The {list} argument is a List of Lists with each three
9714 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9715 {low} and {high} can be the same, in which case this refers to
9716 one character. Otherwise it is the range of characters from
9717 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009718 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009719
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009720 {width} must be either 1 or 2, indicating the character width
9721 in screen cells. *E1112*
9722 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009723 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009725 If the new value causes 'fillchars' or 'listchars' to become
9726 invalid it is rejected and an error is given.
9727
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009728 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009729 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009731< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009732 the effect for known emoji characters. Move the cursor
9733 through the text to check if the cell widths of your terminal
9734 match with what Vim knows about each emoji. If it doesn't
9735 look right you need to adjust the {list} argument.
9736
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009737 Return type: |Number|
9738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009739
9740setcharpos({expr}, {list}) *setcharpos()*
9741 Same as |setpos()| but uses the specified column number as the
9742 character index instead of the byte index in the line.
9743
9744 Example:
9745 With the text "여보세요" in line 8: >
9746 call setcharpos('.', [0, 8, 4, 0])
9747< positions the cursor on the fourth character '요'. >
9748 call setpos('.', [0, 8, 4, 0])
9749< positions the cursor on the second character '보'.
9750
9751 Can also be used as a |method|: >
9752 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009753<
9754 Return type: |Number|
9755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009756
9757setcharsearch({dict}) *setcharsearch()*
9758 Set the current character search information to {dict},
9759 which contains one or more of the following entries:
9760
9761 char character which will be used for a subsequent
9762 |,| or |;| command; an empty string clears the
9763 character search
9764 forward direction of character search; 1 for forward,
9765 0 for backward
9766 until type of character search; 1 for a |t| or |T|
9767 character search, 0 for an |f| or |F|
9768 character search
9769
9770 This can be useful to save/restore a user's character search
9771 from a script: >
9772 :let prevsearch = getcharsearch()
9773 :" Perform a command which clobbers user's search
9774 :call setcharsearch(prevsearch)
9775< Also see |getcharsearch()|.
9776
9777 Can also be used as a |method|: >
9778 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009779<
9780 Return type: dict<any>
9781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009782
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009783setcmdline({str} [, {pos}]) *setcmdline()*
9784 Set the command line to {str} and set the cursor position to
9785 {pos}.
9786 If {pos} is omitted, the cursor is positioned after the text.
9787 Returns 0 when successful, 1 when not editing the command
9788 line.
9789
9790 Can also be used as a |method|: >
9791 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009792<
9793 Return type: |Number|
9794
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009795
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009796setcmdpos({pos}) *setcmdpos()*
9797 Set the cursor position in the command line to byte position
9798 {pos}. The first position is 1.
9799 Use |getcmdpos()| to obtain the current position.
9800 Only works while editing the command line, thus you must use
9801 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9802 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9803 set after the command line is set to the expression. For
9804 |c_CTRL-R_=| it is set after evaluating the expression but
9805 before inserting the resulting text.
9806 When the number is too big the cursor is put at the end of the
9807 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009808 Returns 0 when successful, 1 when not editing the command
9809 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009810
9811 Can also be used as a |method|: >
9812 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009813<
9814 Return type: |Number|
9815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009816
9817setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9818setcursorcharpos({list})
9819 Same as |cursor()| but uses the specified column number as the
9820 character index instead of the byte index in the line.
9821
9822 Example:
9823 With the text "여보세요" in line 4: >
9824 call setcursorcharpos(4, 3)
9825< positions the cursor on the third character '세'. >
9826 call cursor(4, 3)
9827< positions the cursor on the first character '여'.
9828
9829 Can also be used as a |method|: >
9830 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009831<
Christian Brabandt17ad8522025-05-09 00:03:20 +02009832 Returns 0 when the position could be set, -1 otherwise.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009833 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009834
9835
9836setenv({name}, {val}) *setenv()*
9837 Set environment variable {name} to {val}. Example: >
9838 call setenv('HOME', '/home/myhome')
9839
9840< When {val} is |v:null| the environment variable is deleted.
9841 See also |expr-env|.
9842
9843 Can also be used as a |method|, the base is passed as the
9844 second argument: >
9845 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009846<
9847 Return type: |Number|
9848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009849
9850setfperm({fname}, {mode}) *setfperm()* *chmod*
9851 Set the file permissions for {fname} to {mode}.
9852 {mode} must be a string with 9 characters. It is of the form
9853 "rwxrwxrwx", where each group of "rwx" flags represent, in
9854 turn, the permissions of the owner of the file, the group the
9855 file belongs to, and other users. A '-' character means the
9856 permission is off, any other character means on. Multi-byte
9857 characters are not supported.
9858
9859 For example "rw-r-----" means read-write for the user,
9860 readable by the group, not accessible by others. "xx-x-----"
9861 would do the same thing.
9862
9863 Returns non-zero for success, zero for failure.
9864
9865 Can also be used as a |method|: >
9866 GetFilename()->setfperm(mode)
9867<
9868 To read permissions see |getfperm()|.
9869
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009870 Return type: |Number|
9871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009872
9873setline({lnum}, {text}) *setline()*
9874 Set line {lnum} of the current buffer to {text}. To insert
9875 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009876 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009877 Any text properties in {lnum} are cleared. See
9878 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009879
9880 {lnum} is used like with |getline()|.
9881 When {lnum} is just below the last line the {text} will be
9882 added below the last line.
9883 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009884 converted to a String. When {text} is an empty List then
9885 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009886
9887 If this succeeds, FALSE is returned. If this fails (most likely
9888 because {lnum} is invalid) TRUE is returned.
9889 In |Vim9| script an error is given if {lnum} is invalid.
9890
9891 Example: >
9892 :call setline(5, strftime("%c"))
9893
9894< When {text} is a |List| then line {lnum} and following lines
9895 will be set to the items in the list. Example: >
9896 :call setline(5, ['aaa', 'bbb', 'ccc'])
9897< This is equivalent to: >
9898 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9899 : call setline(n, l)
9900 :endfor
9901
9902< Note: The '[ and '] marks are not set.
9903
9904 Can also be used as a |method|, the base is passed as the
9905 second argument: >
9906 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009907<
9908 Return type: |Number|
9909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009910
9911setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9912 Create or replace or add to the location list for window {nr}.
9913 {nr} can be the window number or the |window-ID|.
9914 When {nr} is zero the current window is used.
9915
9916 For a location list window, the displayed location list is
9917 modified. For an invalid window number {nr}, -1 is returned.
9918 Otherwise, same as |setqflist()|.
9919 Also see |location-list|.
9920
9921 For {action} see |setqflist-action|.
9922
9923 If the optional {what} dictionary argument is supplied, then
9924 only the items listed in {what} are set. Refer to |setqflist()|
9925 for the list of supported keys in {what}.
9926
9927 Can also be used as a |method|, the base is passed as the
9928 second argument: >
9929 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009930<
9931 Return type: |Number|
9932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009933
9934setmatches({list} [, {win}]) *setmatches()*
9935 Restores a list of matches saved by |getmatches()| for the
9936 current window. Returns 0 if successful, otherwise -1. All
9937 current matches are cleared before the list is restored. See
9938 example for |getmatches()|.
9939 If {win} is specified, use the window with this number or
9940 window ID instead of the current window.
9941
9942 Can also be used as a |method|: >
9943 GetMatches()->setmatches()
9944<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009945 Return type: |Number|
9946
9947
9948setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009949 Set the position for String {expr}. Possible values:
9950 . the cursor
9951 'x mark x
9952
9953 {list} must be a |List| with four or five numbers:
9954 [bufnum, lnum, col, off]
9955 [bufnum, lnum, col, off, curswant]
9956
9957 "bufnum" is the buffer number. Zero can be used for the
9958 current buffer. When setting an uppercase mark "bufnum" is
9959 used for the mark position. For other marks it specifies the
9960 buffer to set the mark in. You can use the |bufnr()| function
9961 to turn a file name into a buffer number.
9962 For setting the cursor and the ' mark "bufnum" is ignored,
9963 since these are associated with a window, not a buffer.
9964 Does not change the jumplist.
9965
9966 "lnum" and "col" are the position in the buffer. The first
9967 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9968 smaller than 1 then 1 is used. To use the character count
9969 instead of the byte count, use |setcharpos()|.
9970
9971 The "off" number is only used when 'virtualedit' is set. Then
9972 it is the offset in screen columns from the start of the
9973 character. E.g., a position within a <Tab> or after the last
9974 character.
9975
9976 The "curswant" number is only used when setting the cursor
9977 position. It sets the preferred column for when moving the
9978 cursor vertically. When the "curswant" number is missing the
9979 preferred column is not set. When it is present and setting a
9980 mark position it is not used.
9981
9982 Note that for '< and '> changing the line number may result in
9983 the marks to be effectively be swapped, so that '< is always
9984 before '>.
9985
9986 Returns 0 when the position could be set, -1 otherwise.
9987 An error message is given if {expr} is invalid.
9988
9989 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9990
9991 This does not restore the preferred column for moving
9992 vertically; if you set the cursor position with this, |j| and
9993 |k| motions will jump to previous columns! Use |cursor()| to
9994 also set the preferred column. Also see the "curswant" key in
9995 |winrestview()|.
9996
9997 Can also be used as a |method|: >
9998 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009999<
10000 Return type: |Number|
10001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010002
10003setqflist({list} [, {action} [, {what}]]) *setqflist()*
10004 Create or replace or add to the quickfix list.
10005
10006 If the optional {what} dictionary argument is supplied, then
10007 only the items listed in {what} are set. The first {list}
10008 argument is ignored. See below for the supported items in
10009 {what}.
10010 *setqflist-what*
10011 When {what} is not present, the items in {list} are used. Each
10012 item must be a dictionary. Non-dictionary items in {list} are
10013 ignored. Each dictionary item can contain the following
10014 entries:
10015
10016 bufnr buffer number; must be the number of a valid
10017 buffer
10018 filename name of a file; only used when "bufnr" is not
10019 present or it is invalid.
10020 module name of a module; if given it will be used in
10021 quickfix error window instead of the filename.
10022 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +000010023 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010024 pattern search pattern used to locate the error
10025 col column number
10026 vcol when non-zero: "col" is visual column
10027 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +000010028 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010029 nr error number
10030 text description of the error
10031 type single-character error type, 'E', 'W', etc.
10032 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +020010033 user_data custom data associated with the item, can be
10034 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010035
10036 The "col", "vcol", "nr", "type" and "text" entries are
10037 optional. Either "lnum" or "pattern" entry can be used to
10038 locate a matching error line.
10039 If the "filename" and "bufnr" entries are not present or
10040 neither the "lnum" or "pattern" entries are present, then the
10041 item will not be handled as an error line.
10042 If both "pattern" and "lnum" are present then "pattern" will
10043 be used.
10044 If the "valid" entry is not supplied, then the valid flag is
10045 set when "bufnr" is a valid buffer or "filename" exists.
10046 If you supply an empty {list}, the quickfix list will be
10047 cleared.
10048 Note that the list is not exactly the same as what
10049 |getqflist()| returns.
10050
10051 {action} values: *setqflist-action* *E927*
10052 'a' The items from {list} are added to the existing
10053 quickfix list. If there is no existing list, then a
10054 new list is created.
10055
10056 'r' The items from the current quickfix list are replaced
10057 with the items from {list}. This can also be used to
10058 clear the list: >
10059 :call setqflist([], 'r')
10060<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +020010061 'u' Like 'r', but tries to preserve the current selection
10062 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010063 'f' All the quickfix lists in the quickfix stack are
10064 freed.
10065
10066 If {action} is not present or is set to ' ', then a new list
10067 is created. The new quickfix list is added after the current
10068 quickfix list in the stack and all the following lists are
10069 freed. To add a new quickfix list at the end of the stack,
10070 set "nr" in {what} to "$".
10071
10072 The following items can be specified in dictionary {what}:
10073 context quickfix list context. See |quickfix-context|
10074 efm errorformat to use when parsing text from
10075 "lines". If this is not present, then the
10076 'errorformat' option value is used.
10077 See |quickfix-parse|
10078 id quickfix list identifier |quickfix-ID|
10079 idx index of the current entry in the quickfix
10080 list specified by 'id' or 'nr'. If set to '$',
10081 then the last entry in the list is set as the
10082 current entry. See |quickfix-index|
10083 items list of quickfix entries. Same as the {list}
10084 argument.
10085 lines use 'errorformat' to parse a list of lines and
10086 add the resulting entries to the quickfix list
10087 {nr} or {id}. Only a |List| value is supported.
10088 See |quickfix-parse|
10089 nr list number in the quickfix stack; zero
10090 means the current quickfix list and "$" means
10091 the last quickfix list.
10092 quickfixtextfunc
10093 function to get the text to display in the
10094 quickfix window. The value can be the name of
10095 a function or a funcref or a lambda. Refer to
10096 |quickfix-window-function| for an explanation
10097 of how to write the function and an example.
10098 title quickfix list title text. See |quickfix-title|
10099 Unsupported keys in {what} are ignored.
10100 If the "nr" item is not present, then the current quickfix list
10101 is modified. When creating a new quickfix list, "nr" can be
10102 set to a value one greater than the quickfix stack size.
10103 When modifying a quickfix list, to guarantee that the correct
10104 list is modified, "id" should be used instead of "nr" to
10105 specify the list.
10106
10107 Examples (See also |setqflist-examples|): >
10108 :call setqflist([], 'r', {'title': 'My search'})
10109 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
10110 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
10111<
10112 Returns zero for success, -1 for failure.
10113
10114 This function can be used to create a quickfix list
10115 independent of the 'errorformat' setting. Use a command like
10116 `:cc 1` to jump to the first position.
10117
10118 Can also be used as a |method|, the base is passed as the
10119 second argument: >
10120 GetErrorlist()->setqflist()
10121<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010122 Return type: |Number|
10123
10124
10125setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010126 Set the register {regname} to {value}.
10127 If {regname} is "" or "@", the unnamed register '"' is used.
10128 The {regname} argument is a string. In |Vim9-script|
10129 {regname} must be one character.
10130
10131 {value} may be any value returned by |getreg()| or
10132 |getreginfo()|, including a |List| or |Dict|.
10133 If {options} contains "a" or {regname} is upper case,
10134 then the value is appended.
10135
10136 {options} can also contain a register type specification:
10137 "c" or "v" |characterwise| mode
10138 "l" or "V" |linewise| mode
10139 "b" or "<CTRL-V>" |blockwise-visual| mode
10140 If a number immediately follows "b" or "<CTRL-V>" then this is
10141 used as the width of the selection - if it is not specified
10142 then the width of the block is set to the number of characters
10143 in the longest line (counting a <Tab> as 1 character).
10144
10145 If {options} contains no register settings, then the default
10146 is to use character mode unless {value} ends in a <NL> for
10147 string {value} and linewise mode for list {value}. Blockwise
10148 mode is never selected automatically.
10149 Returns zero for success, non-zero for failure.
10150
10151 *E883*
10152 Note: you may not use |List| containing more than one item to
10153 set search and expression registers. Lists containing no
10154 items act like empty strings.
10155
10156 Examples: >
10157 :call setreg(v:register, @*)
10158 :call setreg('*', @%, 'ac')
10159 :call setreg('a', "1\n2\n3", 'b5')
10160 :call setreg('"', { 'points_to': 'a'})
10161
10162< This example shows using the functions to save and restore a
10163 register: >
10164 :let var_a = getreginfo()
10165 :call setreg('a', var_a)
10166< or: >
10167 :let var_a = getreg('a', 1, 1)
10168 :let var_amode = getregtype('a')
10169 ....
10170 :call setreg('a', var_a, var_amode)
10171< Note: you may not reliably restore register value
10172 without using the third argument to |getreg()| as without it
10173 newlines are represented as newlines AND Nul bytes are
10174 represented as newlines as well, see |NL-used-for-Nul|.
10175
10176 You can also change the type of a register by appending
10177 nothing: >
10178 :call setreg('a', '', 'al')
10179
10180< Can also be used as a |method|, the base is passed as the
10181 second argument: >
10182 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010183<
10184 Return type: |Number|
10185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010186
10187settabvar({tabnr}, {varname}, {val}) *settabvar()*
10188 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10189 |t:var|
10190 The {varname} argument is a string.
10191 Note that autocommands are blocked, side effects may not be
10192 triggered, e.g. when setting 'filetype'.
10193 Note that the variable name without "t:" must be used.
10194 Tabs are numbered starting with one.
10195 This function is not available in the |sandbox|.
10196
10197 Can also be used as a |method|, the base is passed as the
10198 third argument: >
10199 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010200<
10201 Return type: |Number|
10202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010203
10204settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10205 Set option or local variable {varname} in window {winnr} to
10206 {val}.
10207 Tabs are numbered starting with one. For the current tabpage
10208 use |setwinvar()|.
10209 {winnr} can be the window number or the |window-ID|.
10210 When {winnr} is zero the current window is used.
10211 Note that autocommands are blocked, side effects may not be
10212 triggered, e.g. when setting 'filetype' or 'syntax'.
10213 This also works for a global or local buffer option, but it
10214 doesn't work for a global or local buffer variable.
10215 For a local buffer option the global value is unchanged.
10216 Note that the variable name without "w:" must be used.
10217 Examples: >
10218 :call settabwinvar(1, 1, "&list", 0)
10219 :call settabwinvar(3, 2, "myvar", "foobar")
10220< This function is not available in the |sandbox|.
10221
10222 Can also be used as a |method|, the base is passed as the
10223 fourth argument: >
10224 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010225<
10226 Return type: |Number|
10227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010228
10229settagstack({nr}, {dict} [, {action}]) *settagstack()*
10230 Modify the tag stack of the window {nr} using {dict}.
10231 {nr} can be the window number or the |window-ID|.
10232
10233 For a list of supported items in {dict}, refer to
10234 |gettagstack()|. "curidx" takes effect before changing the tag
10235 stack.
10236 *E962*
10237 How the tag stack is modified depends on the {action}
10238 argument:
10239 - If {action} is not present or is set to 'r', then the tag
10240 stack is replaced.
10241 - If {action} is set to 'a', then new entries from {dict} are
10242 pushed (added) onto the tag stack.
10243 - If {action} is set to 't', then all the entries from the
10244 current entry in the tag stack or "curidx" in {dict} are
10245 removed and then new entries are pushed to the stack.
10246
10247 The current index is set to one after the length of the tag
10248 stack after the modification.
10249
10250 Returns zero for success, -1 for failure.
10251
10252 Examples (for more examples see |tagstack-examples|):
10253 Empty the tag stack of window 3: >
10254 call settagstack(3, {'items' : []})
10255
10256< Save and restore the tag stack: >
10257 let stack = gettagstack(1003)
10258 " do something else
10259 call settagstack(1003, stack)
10260 unlet stack
10261<
10262 Can also be used as a |method|, the base is passed as the
10263 second argument: >
10264 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010265<
10266 Return type: |Number|
10267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010268
10269setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10270 Like |settabwinvar()| for the current tab page.
10271 Examples: >
10272 :call setwinvar(1, "&list", 0)
10273 :call setwinvar(2, "myvar", "foobar")
10274
10275< Can also be used as a |method|, the base is passed as the
10276 third argument: >
10277 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010278<
10279 Return type: |Number|
10280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010281
10282sha256({string}) *sha256()*
10283 Returns a String with 64 hex characters, which is the SHA256
10284 checksum of {string}.
10285
10286 Can also be used as a |method|: >
10287 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010288<
10289 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010290
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010291 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010292
10293shellescape({string} [, {special}]) *shellescape()*
10294 Escape {string} for use as a shell command argument.
10295 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010296 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010297 in single quotes and will double up all internal single
10298 quotes.
10299 On MS-Windows, when 'shellslash' is not set, it will enclose
10300 {string} in double quotes and double all double quotes within
10301 {string}.
10302 Otherwise it will enclose {string} in single quotes and
10303 replace all "'" with "'\''".
10304
Enno5faeb602024-05-15 21:54:19 +020010305 The {special} argument adds additional escaping of keywords
10306 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010307 number or a non-empty String (|non-zero-arg|), then special
10308 items such as "!", "%", "#" and "<cword>" (as listed in
10309 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010310 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010311
10312 The "!" character will be escaped (again with a |non-zero-arg|
10313 {special}) when 'shell' contains "csh" in the tail. That is
10314 because for csh and tcsh "!" is used for history replacement
10315 even when inside single quotes.
10316
10317 With a |non-zero-arg| {special} the <NL> character is also
10318 escaped. When 'shell' containing "csh" in the tail it's
10319 escaped a second time.
10320
10321 The "\" character will be escaped when 'shell' contains "fish"
10322 in the tail. That is because for fish "\" is used as an escape
10323 character inside single quotes.
10324
10325 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010326 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010327< This results in a directory listing for the file under the
10328 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010329 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010330< See also |::S|.
10331
10332 Can also be used as a |method|: >
10333 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010334<
10335 Return type: |String|
10336
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010337
10338shiftwidth([{col}]) *shiftwidth()*
10339 Returns the effective value of 'shiftwidth'. This is the
10340 'shiftwidth' value unless it is zero, in which case it is the
10341 'tabstop' value. This function was introduced with patch
10342 7.3.694 in 2012, everybody should have it by now (however it
10343 did not allow for the optional {col} argument until 8.1.542).
10344
10345 When there is one argument {col} this is used as column number
10346 for which to return the 'shiftwidth' value. This matters for the
10347 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10348 no {col} argument is given, column 1 will be assumed.
10349
10350 Can also be used as a |method|: >
10351 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010352<
10353 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010354
10355sign_ functions are documented here: |sign-functions-details|
10356
10357
10358simplify({filename}) *simplify()*
10359 Simplify the file name as much as possible without changing
10360 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10361 Unix) are not resolved. If the first path component in
10362 {filename} designates the current directory, this will be
10363 valid for the result as well. A trailing path separator is
10364 not removed either. On Unix "//path" is unchanged, but
10365 "///path" is simplified to "/path" (this follows the Posix
10366 standard).
10367 Example: >
10368 simplify("./dir/.././/file/") == "./file/"
10369< Note: The combination "dir/.." is only removed if "dir" is
10370 a searchable directory or does not exist. On Unix, it is also
10371 removed when "dir" is a symbolic link within the same
10372 directory. In order to resolve all the involved symbolic
10373 links before simplifying the path name, use |resolve()|.
10374
10375 Can also be used as a |method|: >
10376 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010377<
10378 Return type: |String|
10379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010380
10381sin({expr}) *sin()*
10382 Return the sine of {expr}, measured in radians, as a |Float|.
10383 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010384 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010385 Examples: >
10386 :echo sin(100)
10387< -0.506366 >
10388 :echo sin(-4.01)
10389< 0.763301
10390
10391 Can also be used as a |method|: >
10392 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010393<
10394 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010395
10396
10397sinh({expr}) *sinh()*
10398 Return the hyperbolic sine of {expr} as a |Float| in the range
10399 [-inf, inf].
10400 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010401 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010402 Examples: >
10403 :echo sinh(0.5)
10404< 0.521095 >
10405 :echo sinh(-0.9)
10406< -1.026517
10407
10408 Can also be used as a |method|: >
10409 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010410<
10411 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010412
10413
10414slice({expr}, {start} [, {end}]) *slice()*
10415 Similar to using a |slice| "expr[start : end]", but "end" is
10416 used exclusive. And for a string the indexes are used as
10417 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010418 |vim9script|. Also, composing characters are treated as a
10419 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010420 When {end} is omitted the slice continues to the last item.
10421 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010422 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010423
10424 Can also be used as a |method|: >
10425 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010426<
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010010427 Return type: list<{type}> or tuple<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010428
10429
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010430sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010431 Sort the items in {list} in-place. Returns {list}.
10432
10433 If you want a list to remain unmodified make a copy first: >
10434 :let sortedlist = sort(copy(mylist))
10435
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010436< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010437 string representation of each item to sort on. Numbers sort
10438 after Strings, |Lists| after Numbers. For sorting text in the
10439 current buffer use |:sort|.
10440
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010441 When {how} is given and it is 'i' then case is ignored.
10442 In legacy script, for backwards compatibility, the value one
10443 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010444
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010445 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010446 locale is used for ordering. Implementation details: strcoll()
10447 is used to compare strings. See |:language| check or set the
10448 collation locale. |v:collate| can also be used to check the
10449 current locale. Sorting using the locale typically ignores
10450 case. Example: >
10451 " ö is sorted similarly to o with English locale.
10452 :language collate en_US.UTF8
10453 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10454< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10455>
10456 " ö is sorted after z with Swedish locale.
10457 :language collate sv_SE.UTF8
10458 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10459< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10460 This does not work properly on Mac.
10461
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010462 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010463 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010464 strtod() function to parse numbers. Strings, Lists, Dicts and
10465 Funcrefs will be considered as being 0). Note that this won't
10466 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010467
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010468 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010469 sorted numerical. This is like 'n' but a string containing
10470 digits will be used as the number they represent.
10471
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010472 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010473 sorted numerical. All values must be a Number or a Float.
10474
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010475 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010476 is called to compare items. The function is invoked with two
10477 items as argument and must return zero if they are equal, 1 or
10478 bigger if the first one sorts after the second one, -1 or
10479 smaller if the first one sorts before the second one.
10480
10481 {dict} is for functions with the "dict" attribute. It will be
10482 used to set the local variable "self". |Dictionary-function|
10483
10484 The sort is stable, items which compare equal (as number or as
10485 string) will keep their relative position. E.g., when sorting
10486 on numbers, text strings will sort next to each other, in the
10487 same order as they were originally.
10488
10489 Can also be used as a |method|: >
10490 mylist->sort()
10491
10492< Also see |uniq()|.
10493
10494 Example: >
10495 func MyCompare(i1, i2)
10496 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10497 endfunc
10498 eval mylist->sort("MyCompare")
10499< A shorter compare version for this specific simple case, which
10500 ignores overflow: >
10501 func MyCompare(i1, i2)
10502 return a:i1 - a:i2
10503 endfunc
10504< For a simple expression you can use a lambda: >
10505 eval mylist->sort({i1, i2 -> i1 - i2})
10506<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010507 Return type: list<{type}>
10508
10509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010510sound_clear() *sound_clear()*
10511 Stop playing all sounds.
10512
10513 On some Linux systems you may need the libcanberra-pulse
10514 package, otherwise sound may not stop.
10515
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010516 Return type: |Number|
10517
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010518 {only available when compiled with the |+sound| feature}
10519
10520 *sound_playevent()*
10521sound_playevent({name} [, {callback}])
10522 Play a sound identified by {name}. Which event names are
10523 supported depends on the system. Often the XDG sound names
10524 are used. On Ubuntu they may be found in
10525 /usr/share/sounds/freedesktop/stereo. Example: >
10526 call sound_playevent('bell')
10527< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10528 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10529 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010530 On macOS, {name} refers to files located in
10531 /System/Library/Sounds (e.g. "Tink"). It will also work for
10532 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010533
10534 When {callback} is specified it is invoked when the sound is
10535 finished. The first argument is the sound ID, the second
10536 argument is the status:
10537 0 sound was played to the end
10538 1 sound was interrupted
10539 2 error occurred after sound started
10540 Example: >
10541 func Callback(id, status)
10542 echomsg "sound " .. a:id .. " finished with " .. a:status
10543 endfunc
10544 call sound_playevent('bell', 'Callback')
10545
10546< MS-Windows: {callback} doesn't work for this function.
10547
10548 Returns the sound ID, which can be passed to `sound_stop()`.
10549 Returns zero if the sound could not be played.
10550
10551 Can also be used as a |method|: >
10552 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010553<
10554 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010555
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010556 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010557
10558 *sound_playfile()*
10559sound_playfile({path} [, {callback}])
10560 Like `sound_playevent()` but play sound file {path}. {path}
10561 must be a full path. On Ubuntu you may find files to play
10562 with this command: >
10563 :!find /usr/share/sounds -type f | grep -v index.theme
10564
10565< Can also be used as a |method|: >
10566 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010567<
10568 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010569
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010570 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010571
10572
10573sound_stop({id}) *sound_stop()*
10574 Stop playing sound {id}. {id} must be previously returned by
10575 `sound_playevent()` or `sound_playfile()`.
10576
10577 On some Linux systems you may need the libcanberra-pulse
10578 package, otherwise sound may not stop.
10579
10580 On MS-Windows, this does not work for event sound started by
10581 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10582
10583 Can also be used as a |method|: >
10584 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010585<
10586 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010587
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010588 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010589
10590 *soundfold()*
10591soundfold({word})
10592 Return the sound-folded equivalent of {word}. Uses the first
10593 language in 'spelllang' for the current window that supports
10594 soundfolding. 'spell' must be set. When no sound folding is
10595 possible the {word} is returned unmodified.
10596 This can be used for making spelling suggestions. Note that
10597 the method can be quite slow.
10598
10599 Can also be used as a |method|: >
10600 GetWord()->soundfold()
10601<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010602 Return type: |String|
10603
10604
10605spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010606 Without argument: The result is the badly spelled word under
10607 or after the cursor. The cursor is moved to the start of the
10608 bad word. When no bad word is found in the cursor line the
10609 result is an empty string and the cursor doesn't move.
10610
10611 With argument: The result is the first word in {sentence} that
10612 is badly spelled. If there are no spelling mistakes the
10613 result is an empty string.
10614
10615 The return value is a list with two items:
10616 - The badly spelled word or an empty string.
10617 - The type of the spelling error:
10618 "bad" spelling mistake
10619 "rare" rare word
10620 "local" word only valid in another region
10621 "caps" word should start with Capital
10622 Example: >
10623 echo spellbadword("the quik brown fox")
10624< ['quik', 'bad'] ~
10625
10626 The spelling information for the current window and the value
10627 of 'spelllang' are used.
10628
10629 Can also be used as a |method|: >
10630 GetText()->spellbadword()
10631<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010632 Return type: list<string>
10633
10634
10635spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010636 Return a |List| with spelling suggestions to replace {word}.
10637 When {max} is given up to this number of suggestions are
10638 returned. Otherwise up to 25 suggestions are returned.
10639
10640 When the {capital} argument is given and it's non-zero only
10641 suggestions with a leading capital will be given. Use this
10642 after a match with 'spellcapcheck'.
10643
10644 {word} can be a badly spelled word followed by other text.
10645 This allows for joining two words that were split. The
10646 suggestions also include the following text, thus you can
10647 replace a line.
10648
10649 {word} may also be a good word. Similar words will then be
10650 returned. {word} itself is not included in the suggestions,
10651 although it may appear capitalized.
10652
10653 The spelling information for the current window is used. The
10654 values of 'spelllang' and 'spellsuggest' are used.
10655
10656 Can also be used as a |method|: >
10657 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010658<
10659 Return type: list<string> or list<any>
10660
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010661
10662split({string} [, {pattern} [, {keepempty}]]) *split()*
10663 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010664 empty each white space separated sequence of characters
10665 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010666 Otherwise the string is split where {pattern} matches,
10667 removing the matched characters. 'ignorecase' is not used
10668 here, add \c to ignore case. |/\c|
10669 When the first or last item is empty it is omitted, unless the
10670 {keepempty} argument is given and it's non-zero.
10671 Other empty items are kept when {pattern} matches at least one
10672 character or when {keepempty} is non-zero.
10673 Example: >
10674 :let words = split(getline('.'), '\W\+')
10675< To split a string in individual characters: >
10676 :for c in split(mystring, '\zs')
10677< If you want to keep the separator you can also use '\zs' at
10678 the end of the pattern: >
10679 :echo split('abc:def:ghi', ':\zs')
10680< ['abc:', 'def:', 'ghi'] ~
10681 Splitting a table where the first element can be empty: >
10682 :let items = split(line, ':', 1)
10683< The opposite function is |join()|.
10684
10685 Can also be used as a |method|: >
10686 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010687<
10688 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010689
10690sqrt({expr}) *sqrt()*
10691 Return the non-negative square root of Float {expr} as a
10692 |Float|.
10693 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010694 is negative the result is NaN (Not a Number). Returns 0.0 if
10695 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010696 Examples: >
10697 :echo sqrt(100)
10698< 10.0 >
10699 :echo sqrt(-4.01)
10700< nan
10701 "nan" may be different, it depends on system libraries.
10702
10703 Can also be used as a |method|: >
10704 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010705<
10706 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010707
10708
10709srand([{expr}]) *srand()*
10710 Initialize seed used by |rand()|:
10711 - If {expr} is not given, seed values are initialized by
10712 reading from /dev/urandom, if possible, or using time(NULL)
10713 a.k.a. epoch time otherwise; this only has second accuracy.
10714 - If {expr} is given it must be a Number. It is used to
10715 initialize the seed values. This is useful for testing or
10716 when a predictable sequence is intended.
10717
10718 Examples: >
10719 :let seed = srand()
10720 :let seed = srand(userinput)
10721 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010722<
10723 Return type: list<number>
10724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010725
10726state([{what}]) *state()*
10727 Return a string which contains characters indicating the
10728 current state. Mostly useful in callbacks that want to do
10729 work that may not always be safe. Roughly this works like:
10730 - callback uses state() to check if work is safe to do.
10731 Yes: then do it right away.
10732 No: add to work queue and add a |SafeState| and/or
10733 |SafeStateAgain| autocommand (|SafeState| triggers at
10734 toplevel, |SafeStateAgain| triggers after handling
10735 messages and callbacks).
10736 - When SafeState or SafeStateAgain is triggered and executes
10737 your autocommand, check with `state()` if the work can be
10738 done now, and if yes remove it from the queue and execute.
10739 Remove the autocommand if the queue is now empty.
10740 Also see |mode()|.
10741
10742 When {what} is given only characters in this string will be
10743 added. E.g, this checks if the screen has scrolled: >
10744 if state('s') == ''
10745 " screen has not scrolled
10746<
10747 These characters indicate the state, generally indicating that
10748 something is busy:
10749 m halfway a mapping, :normal command, feedkeys() or
10750 stuffed command
10751 o operator pending, e.g. after |d|
10752 a Insert mode autocomplete active
10753 x executing an autocommand
10754 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10755 ch_readraw() when reading json
10756 S not triggering SafeState or SafeStateAgain, e.g. after
10757 |f| or a count
10758 c callback invoked, including timer (repeats for
10759 recursiveness up to "ccc")
10760 s screen has scrolled for messages
10761
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010762 Return type: |String|
10763
10764
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010765str2blob({list} [, {options}]) *str2blob()*
10766 Return a Blob by converting the characters in the List of
10767 strings in {list} into bytes.
10768
10769 A <NL> byte is added to the blob after each list item. A
10770 newline character in the string is translated into a <NUL>
10771 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010772
10773 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010774 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010775
10776 The argument {options} is a |Dict| and supports the following
10777 items:
Bakudankunb3854bf2025-02-23 20:29:21 +010010778 encoding Convert the characters using this encoding
10779 before making the Blob.
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010780 The value is a |String|. See |encoding-names|
10781 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010782
10783 An error is given and an empty blob is returned if the
10784 character encoding fails.
10785
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010786 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010787
10788 See also |blob2str()|
10789
10790 Examples: >
Hirohito Higashi932a5352025-03-23 10:20:20 +010010791 str2blob(["ab"]) returns 0z6162
10792 str2blob(["«»"]) returns 0zC2ABC2BB
10793 str2blob(["a\nb"]) returns 0z610062
10794 str2blob(["a","b"]) returns 0z610A62
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010795 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Hirohito Higashi932a5352025-03-23 10:20:20 +010010796 str2blob(readfile('myfile.txt'))
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010797<
10798 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010799 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010800<
10801 Return type: |Blob|
10802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010803str2float({string} [, {quoted}]) *str2float()*
10804 Convert String {string} to a Float. This mostly works the
10805 same as when using a floating point number in an expression,
10806 see |floating-point-format|. But it's a bit more permissive.
10807 E.g., "1e40" is accepted, while in an expression you need to
10808 write "1.0e40". The hexadecimal form "0x123" is also
10809 accepted, but not others, like binary or octal.
10810 When {quoted} is present and non-zero then embedded single
10811 quotes before the dot are ignored, thus "1'000.0" is a
10812 thousand.
10813 Text after the number is silently ignored.
10814 The decimal point is always '.', no matter what the locale is
10815 set to. A comma ends the number: "12,345.67" is converted to
10816 12.0. You can strip out thousands separators with
10817 |substitute()|: >
10818 let f = str2float(substitute(text, ',', '', 'g'))
10819<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010820 Returns 0.0 if the conversion fails.
10821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010822 Can also be used as a |method|: >
10823 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010824<
10825 Return type: |Float|
10826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010827
10828str2list({string} [, {utf8}]) *str2list()*
10829 Return a list containing the number values which represent
10830 each character in String {string}. Examples: >
10831 str2list(" ") returns [32]
10832 str2list("ABC") returns [65, 66, 67]
10833< |list2str()| does the opposite.
10834
10835 When {utf8} is omitted or zero, the current 'encoding' is used.
10836 When {utf8} is TRUE, always treat the String as UTF-8
10837 characters. With UTF-8 composing characters are handled
10838 properly: >
10839 str2list("á") returns [97, 769]
10840
10841< Can also be used as a |method|: >
10842 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010843<
10844 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010845
10846
10847str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10848 Convert string {string} to a number.
10849 {base} is the conversion base, it can be 2, 8, 10 or 16.
10850 When {quoted} is present and non-zero then embedded single
10851 quotes are ignored, thus "1'000'000" is a million.
10852
10853 When {base} is omitted base 10 is used. This also means that
10854 a leading zero doesn't cause octal conversion to be used, as
10855 with the default String to Number conversion. Example: >
10856 let nr = str2nr('0123')
10857<
10858 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10859 different base the result will be zero. Similarly, when
10860 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10861 {base} is 2 a leading "0b" or "0B" is ignored.
10862 Text after the number is silently ignored.
10863
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010864 Returns 0 if {string} is empty or on error.
10865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010866 Can also be used as a |method|: >
10867 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010868<
10869 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010870
10871
10872strcharlen({string}) *strcharlen()*
10873 The result is a Number, which is the number of characters
10874 in String {string}. Composing characters are ignored.
10875 |strchars()| can count the number of characters, counting
10876 composing characters separately.
10877
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010878 Returns 0 if {string} is empty or on error.
10879
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010880 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10881
10882 Can also be used as a |method|: >
10883 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010884<
10885 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010886
10887
10888strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10889 Like |strpart()| but using character index and length instead
10890 of byte index and length.
10891 When {skipcc} is omitted or zero, composing characters are
10892 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010893 When {skipcc} set to 1, composing characters are treated as a
10894 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010895 When a character index is used where a character does not
10896 exist it is omitted and counted as one character. For
10897 example: >
10898 strcharpart('abc', -1, 2)
10899< results in 'a'.
10900
Bram Moolenaard592deb2022-06-17 15:42:40 +010010901 Returns an empty string on error.
10902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010903 Can also be used as a |method|: >
10904 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010905<
10906 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010907
10908
10909strchars({string} [, {skipcc}]) *strchars()*
10910 The result is a Number, which is the number of characters
10911 in String {string}.
10912 When {skipcc} is omitted or zero, composing characters are
10913 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010914 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010915 |strcharlen()| always does this.
10916
Bram Moolenaard592deb2022-06-17 15:42:40 +010010917 Returns zero on error.
10918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010919 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10920
10921 {skipcc} is only available after 7.4.755. For backward
10922 compatibility, you can define a wrapper function: >
10923 if has("patch-7.4.755")
10924 function s:strchars(str, skipcc)
10925 return strchars(a:str, a:skipcc)
10926 endfunction
10927 else
10928 function s:strchars(str, skipcc)
10929 if a:skipcc
10930 return strlen(substitute(a:str, ".", "x", "g"))
10931 else
10932 return strchars(a:str)
10933 endif
10934 endfunction
10935 endif
10936<
10937 Can also be used as a |method|: >
10938 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010939<
10940 Return type: |Number|
10941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010942
10943strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10944 The result is a Number, which is the number of display cells
10945 String {string} occupies on the screen when it starts at {col}
10946 (first column is zero). When {col} is omitted zero is used.
10947 Otherwise it is the screen column where to start. This
10948 matters for Tab characters.
10949 The option settings of the current window are used. This
10950 matters for anything that's displayed differently, such as
10951 'tabstop' and 'display'.
10952 When {string} contains characters with East Asian Width Class
10953 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010954 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010955 Also see |strlen()|, |strwidth()| and |strchars()|.
10956
10957 Can also be used as a |method|: >
10958 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010959<
10960 Return type: |Number|
10961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010962
10963strftime({format} [, {time}]) *strftime()*
10964 The result is a String, which is a formatted date and time, as
10965 specified by the {format} string. The given {time} is used,
10966 or the current time if no time is given. The accepted
10967 {format} depends on your system, thus this is not portable!
10968 See the manual page of the C function strftime() for the
10969 format. The maximum length of the result is 80 characters.
10970 See also |localtime()|, |getftime()| and |strptime()|.
10971 The language can be changed with the |:language| command.
10972 Examples: >
10973 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10974 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10975 :echo strftime("%y%m%d %T") 970427 11:53:55
10976 :echo strftime("%H:%M") 11:55
10977 :echo strftime("%c", getftime("file.c"))
10978 Show mod time of file.c.
10979< Not available on all systems. To check use: >
10980 :if exists("*strftime")
10981
10982< Can also be used as a |method|: >
10983 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010984<
10985 Return type: |String|
10986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010987
10988strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010989 Get a Number corresponding to the character at {index} in
10990 {str}. This uses a zero-based character index, not a byte
10991 index. Composing characters are considered separate
10992 characters here. Use |nr2char()| to convert the Number to a
10993 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010994 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010995 Also see |strcharpart()| and |strchars()|.
10996
10997 Can also be used as a |method|: >
10998 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010999<
11000 Return type: |Number|
11001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011002
11003stridx({haystack}, {needle} [, {start}]) *stridx()*
11004 The result is a Number, which gives the byte index in
11005 {haystack} of the first occurrence of the String {needle}.
11006 If {start} is specified, the search starts at index {start}.
11007 This can be used to find a second match: >
11008 :let colon1 = stridx(line, ":")
11009 :let colon2 = stridx(line, ":", colon1 + 1)
11010< The search is done case-sensitive.
11011 For pattern searches use |match()|.
11012 -1 is returned if the {needle} does not occur in {haystack}.
11013 See also |strridx()|.
11014 Examples: >
11015 :echo stridx("An Example", "Example") 3
11016 :echo stridx("Starting point", "Start") 0
11017 :echo stridx("Starting point", "start") -1
11018< *strstr()* *strchr()*
11019 stridx() works similar to the C function strstr(). When used
11020 with a single character it works similar to strchr().
11021
11022 Can also be used as a |method|: >
11023 GetHaystack()->stridx(needle)
11024<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011025 Return type: |Number|
11026
11027
11028string({expr}) *string()*
11029 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011030 Float, String, Blob or a composition of them, then the result
11031 can be parsed back with |eval()|.
11032 {expr} type result ~
11033 String 'string' (single quotes are doubled)
11034 Number 123
11035 Float 123.123456 or 1.123456e8
11036 Funcref function('name')
11037 Blob 0z00112233.44556677.8899
11038 List [item, item]
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011039 Tuple (item, item)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011040 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000011041 Class class SomeName
11042 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011043 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020011044 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011045
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010011046 When a |List|, |Tuple| or |Dictionary| has a recursive
11047 reference it is replaced by "[...]" or "(...)" or "{...}".
11048 Using eval() on the result will then fail.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011049
mityu7f0bba22024-03-29 10:14:41 +010011050 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011051 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010011052 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010011053
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011054 Can also be used as a |method|: >
11055 mylist->string()
11056
11057< Also see |strtrans()|.
11058
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011059 Return type: |String|
11060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011061
11062strlen({string}) *strlen()*
11063 The result is a Number, which is the length of the String
11064 {string} in bytes.
11065 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011066 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011067 If you want to count the number of multibyte characters use
11068 |strchars()|.
11069 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
11070
11071 Can also be used as a |method|: >
11072 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011073<
11074 Return type: |Number|
11075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011076
11077strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
11078 The result is a String, which is part of {src}, starting from
11079 byte {start}, with the byte length {len}.
11080 When {chars} is present and TRUE then {len} is the number of
11081 characters positions (composing characters are not counted
11082 separately, thus "1" means one base character and any
11083 following composing characters).
11084 To count {start} as characters instead of bytes use
11085 |strcharpart()|.
11086
11087 When bytes are selected which do not exist, this doesn't
11088 result in an error, the bytes are simply omitted.
11089 If {len} is missing, the copy continues from {start} till the
11090 end of the {src}. >
11091 strpart("abcdefg", 3, 2) == "de"
11092 strpart("abcdefg", -2, 4) == "ab"
11093 strpart("abcdefg", 5, 4) == "fg"
11094 strpart("abcdefg", 3) == "defg"
11095
11096< Note: To get the first character, {start} must be 0. For
11097 example, to get the character under the cursor: >
11098 strpart(getline("."), col(".") - 1, 1, v:true)
11099<
Bram Moolenaard592deb2022-06-17 15:42:40 +010011100 Returns an empty string on error.
11101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011102 Can also be used as a |method|: >
11103 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011104<
11105 Return type: |String|
11106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011107
11108strptime({format}, {timestring}) *strptime()*
11109 The result is a Number, which is a unix timestamp representing
11110 the date and time in {timestring}, which is expected to match
11111 the format specified in {format}.
11112
11113 The accepted {format} depends on your system, thus this is not
11114 portable! See the manual page of the C function strptime()
11115 for the format. Especially avoid "%c". The value of $TZ also
11116 matters.
11117
11118 If the {timestring} cannot be parsed with {format} zero is
11119 returned. If you do not know the format of {timestring} you
11120 can try different {format} values until you get a non-zero
11121 result.
11122
11123 See also |strftime()|.
11124 Examples: >
11125 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
11126< 862156163 >
11127 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
11128< Sun Apr 27 11:53:55 1997 >
11129 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
11130< Sun Apr 27 12:53:55 1997
11131
11132 Can also be used as a |method|: >
11133 GetFormat()->strptime(timestring)
11134<
11135 Not available on all systems. To check use: >
11136 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011137<
11138 Return type: |Number|
11139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011140
11141strridx({haystack}, {needle} [, {start}]) *strridx()*
11142 The result is a Number, which gives the byte index in
11143 {haystack} of the last occurrence of the String {needle}.
11144 When {start} is specified, matches beyond this index are
11145 ignored. This can be used to find a match before a previous
11146 match: >
11147 :let lastcomma = strridx(line, ",")
11148 :let comma2 = strridx(line, ",", lastcomma - 1)
11149< The search is done case-sensitive.
11150 For pattern searches use |match()|.
11151 -1 is returned if the {needle} does not occur in {haystack}.
11152 If the {needle} is empty the length of {haystack} is returned.
11153 See also |stridx()|. Examples: >
11154 :echo strridx("an angry armadillo", "an") 3
11155< *strrchr()*
11156 When used with a single character it works similar to the C
11157 function strrchr().
11158
11159 Can also be used as a |method|: >
11160 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011161<
11162 Return type: |Number|
11163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011164
11165strtrans({string}) *strtrans()*
11166 The result is a String, which is {string} with all unprintable
11167 characters translated into printable characters |'isprint'|.
11168 Like they are shown in a window. Example: >
11169 echo strtrans(@a)
11170< This displays a newline in register a as "^@" instead of
11171 starting a new line.
11172
Bram Moolenaard592deb2022-06-17 15:42:40 +010011173 Returns an empty string on error.
11174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011175 Can also be used as a |method|: >
11176 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011177<
11178 Return type: |String|
11179
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011180
Christian Brabandt67672ef2023-04-24 21:09:54 +010011181strutf16len({string} [, {countcc}]) *strutf16len()*
11182 The result is a Number, which is the number of UTF-16 code
11183 units in String {string} (after converting it to UTF-16).
11184
11185 When {countcc} is TRUE, composing characters are counted
11186 separately.
11187 When {countcc} is omitted or FALSE, composing characters are
11188 ignored.
11189
11190 Returns zero on error.
11191
11192 Also see |strlen()| and |strcharlen()|.
11193 Examples: >
11194 echo strutf16len('a') returns 1
11195 echo strutf16len('©') returns 1
11196 echo strutf16len('😊') returns 2
11197 echo strutf16len('ą́') returns 1
11198 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011199<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011200 Can also be used as a |method|: >
11201 GetText()->strutf16len()
11202<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011203 Return type: |Number|
11204
11205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011206strwidth({string}) *strwidth()*
11207 The result is a Number, which is the number of display cells
11208 String {string} occupies. A Tab character is counted as one
11209 cell, alternatively use |strdisplaywidth()|.
11210 When {string} contains characters with East Asian Width Class
11211 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011212 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011213 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11214
11215 Can also be used as a |method|: >
11216 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011217<
11218 Return type: |Number|
11219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011220
11221submatch({nr} [, {list}]) *submatch()* *E935*
11222 Only for an expression in a |:substitute| command or
11223 substitute() function.
11224 Returns the {nr}'th submatch of the matched text. When {nr}
11225 is 0 the whole matched text is returned.
11226 Note that a NL in the string can stand for a line break of a
11227 multi-line match or a NUL character in the text.
11228 Also see |sub-replace-expression|.
11229
11230 If {list} is present and non-zero then submatch() returns
11231 a list of strings, similar to |getline()| with two arguments.
11232 NL characters in the text represent NUL characters in the
11233 text.
11234 Only returns more than one item for |:substitute|, inside
11235 |substitute()| this list will always contain one or zero
11236 items, since there are no real line breaks.
11237
11238 When substitute() is used recursively only the submatches in
11239 the current (deepest) call can be obtained.
11240
Bram Moolenaard592deb2022-06-17 15:42:40 +010011241 Returns an empty string or list on error.
11242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011243 Examples: >
11244 :s/\d\+/\=submatch(0) + 1/
11245 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11246< This finds the first number in the line and adds one to it.
11247 A line break is included as a newline character.
11248
11249 Can also be used as a |method|: >
11250 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011251<
11252 Return type: |String| or list<string> depending on {list}
11253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011254
11255substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11256 The result is a String, which is a copy of {string}, in which
11257 the first match of {pat} is replaced with {sub}.
11258 When {flags} is "g", all matches of {pat} in {string} are
11259 replaced. Otherwise {flags} should be "".
11260
11261 This works like the ":substitute" command (without any flags).
11262 But the matching with {pat} is always done like the 'magic'
11263 option is set and 'cpoptions' is empty (to make scripts
11264 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11265 if you want to ignore or match case and ignore 'ignorecase'.
11266 'smartcase' is not used. See |string-match| for how {pat} is
11267 used.
11268
11269 A "~" in {sub} is not replaced with the previous {sub}.
11270 Note that some codes in {sub} have a special meaning
11271 |sub-replace-special|. For example, to replace something with
11272 "\n" (two characters), use "\\\\n" or '\\n'.
11273
11274 When {pat} does not match in {string}, {string} is returned
11275 unmodified.
11276
11277 Example: >
11278 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11279< This removes the last component of the 'path' option. >
11280 :echo substitute("testing", ".*", "\\U\\0", "")
11281< results in "TESTING".
11282
11283 When {sub} starts with "\=", the remainder is interpreted as
11284 an expression. See |sub-replace-expression|. Example: >
11285 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011286 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011287
11288< When {sub} is a Funcref that function is called, with one
11289 optional argument. Example: >
11290 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11291< The optional argument is a list which contains the whole
11292 matched string and up to nine submatches, like what
11293 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011294 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011295
Bram Moolenaard592deb2022-06-17 15:42:40 +010011296< Returns an empty string on error.
11297
11298 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011299 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011300<
11301 Return type: |String|
11302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011303
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011304swapfilelist() *swapfilelist()*
11305 Returns a list of swap file names, like what "vim -r" shows.
11306 See the |-r| command argument. The 'directory' option is used
11307 for the directories to inspect. If you only want to get a
11308 list of swap files in the current directory then temporarily
11309 set 'directory' to a dot: >
11310 let save_dir = &directory
11311 let &directory = '.'
11312 let swapfiles = swapfilelist()
11313 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011314<
11315 Return type: list<string>
11316
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011318swapinfo({fname}) *swapinfo()*
11319 The result is a dictionary, which holds information about the
11320 swapfile {fname}. The available fields are:
11321 version Vim version
11322 user user name
11323 host host name
11324 fname original file name
11325 pid PID of the Vim process that created the swap
11326 file
11327 mtime last modification time in seconds
11328 inode Optional: INODE number of the file
11329 dirty 1 if file was modified, 0 if not
11330 Note that "user" and "host" are truncated to at most 39 bytes.
11331 In case of failure an "error" item is added with the reason:
11332 Cannot open file: file not found or in accessible
11333 Cannot read file: cannot read first block
11334 Not a swap file: does not contain correct block ID
11335 Magic number mismatch: Info in first block is invalid
11336
11337 Can also be used as a |method|: >
11338 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011339<
11340 Return type: dict<any> or dict<string>
11341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011342
11343swapname({buf}) *swapname()*
11344 The result is the swap file path of the buffer {expr}.
11345 For the use of {buf}, see |bufname()| above.
11346 If buffer {buf} is the current buffer, the result is equal to
11347 |:swapname| (unless there is no swap file).
11348 If buffer {buf} has no swap file, returns an empty string.
11349
11350 Can also be used as a |method|: >
11351 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011352<
11353 Return type: |String|
11354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011355
11356synID({lnum}, {col}, {trans}) *synID()*
11357 The result is a Number, which is the syntax ID at the position
11358 {lnum} and {col} in the current window.
11359 The syntax ID can be used with |synIDattr()| and
11360 |synIDtrans()| to obtain syntax information about text.
11361
11362 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11363 line. 'synmaxcol' applies, in a longer line zero is returned.
11364 Note that when the position is after the last character,
11365 that's where the cursor can be in Insert mode, synID() returns
11366 zero. {lnum} is used like with |getline()|.
11367
11368 When {trans} is |TRUE|, transparent items are reduced to the
11369 item that they reveal. This is useful when wanting to know
11370 the effective color. When {trans} is |FALSE|, the transparent
11371 item is returned. This is useful when wanting to know which
11372 syntax item is effective (e.g. inside parens).
11373 Warning: This function can be very slow. Best speed is
11374 obtained by going through the file in forward direction.
11375
Bram Moolenaard592deb2022-06-17 15:42:40 +010011376 Returns zero on error.
11377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011378 Example (echoes the name of the syntax item under the cursor): >
11379 :echo synIDattr(synID(line("."), col("."), 1), "name")
11380<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011381 Return type: |Number|
11382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011383
11384synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11385 The result is a String, which is the {what} attribute of
11386 syntax ID {synID}. This can be used to obtain information
11387 about a syntax item.
11388 {mode} can be "gui", "cterm" or "term", to get the attributes
11389 for that mode. When {mode} is omitted, or an invalid value is
11390 used, the attributes for the currently active highlighting are
11391 used (GUI, cterm or term).
11392 Use synIDtrans() to follow linked highlight groups.
11393 {what} result
11394 "name" the name of the syntax item
11395 "fg" foreground color (GUI: color name used to set
11396 the color, cterm: color number as a string,
11397 term: empty string)
11398 "bg" background color (as with "fg")
11399 "font" font name (only available in the GUI)
11400 |highlight-font|
11401 "sp" special color for the GUI (as with "fg")
11402 |highlight-guisp|
11403 "ul" underline color for cterm: number as a string
11404 "fg#" like "fg", but for the GUI and the GUI is
11405 running the name in "#RRGGBB" form
11406 "bg#" like "fg#" for "bg"
11407 "sp#" like "fg#" for "sp"
11408 "bold" "1" if bold
11409 "italic" "1" if italic
11410 "reverse" "1" if reverse
11411 "inverse" "1" if inverse (= reverse)
11412 "standout" "1" if standout
11413 "underline" "1" if underlined
11414 "undercurl" "1" if undercurled
11415 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011416 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011417
Bram Moolenaard592deb2022-06-17 15:42:40 +010011418 Returns an empty string on error.
11419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011420 Example (echoes the color of the syntax item under the
11421 cursor): >
11422 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11423<
11424 Can also be used as a |method|: >
11425 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011426<
11427 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011428
11429
11430synIDtrans({synID}) *synIDtrans()*
11431 The result is a Number, which is the translated syntax ID of
11432 {synID}. This is the syntax group ID of what is being used to
11433 highlight the character. Highlight links given with
11434 ":highlight link" are followed.
11435
Bram Moolenaard592deb2022-06-17 15:42:40 +010011436 Returns zero on error.
11437
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011438 Can also be used as a |method|: >
11439 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011440<
11441 Return type: |Number|
11442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011443
11444synconcealed({lnum}, {col}) *synconcealed()*
11445 The result is a |List| with currently three items:
11446 1. The first item in the list is 0 if the character at the
11447 position {lnum} and {col} is not part of a concealable
11448 region, 1 if it is. {lnum} is used like with |getline()|.
11449 2. The second item in the list is a string. If the first item
11450 is 1, the second item contains the text which will be
11451 displayed in place of the concealed text, depending on the
11452 current setting of 'conceallevel' and 'listchars'.
11453 3. The third and final item in the list is a number
11454 representing the specific syntax region matched in the
11455 line. When the character is not concealed the value is
11456 zero. This allows detection of the beginning of a new
11457 concealable region if there are two consecutive regions
11458 with the same replacement character. For an example, if
11459 the text is "123456" and both "23" and "45" are concealed
11460 and replaced by the character "X", then:
11461 call returns ~
11462 synconcealed(lnum, 1) [0, '', 0]
11463 synconcealed(lnum, 2) [1, 'X', 1]
11464 synconcealed(lnum, 3) [1, 'X', 1]
11465 synconcealed(lnum, 4) [1, 'X', 2]
11466 synconcealed(lnum, 5) [1, 'X', 2]
11467 synconcealed(lnum, 6) [0, '', 0]
11468
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011469 Note: Doesn't consider |matchadd()| highlighting items,
11470 since syntax and matching highlighting are two different
11471 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011472
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011473 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011475
11476synstack({lnum}, {col}) *synstack()*
11477 Return a |List|, which is the stack of syntax items at the
11478 position {lnum} and {col} in the current window. {lnum} is
11479 used like with |getline()|. Each item in the List is an ID
11480 like what |synID()| returns.
11481 The first item in the List is the outer region, following are
11482 items contained in that one. The last one is what |synID()|
11483 returns, unless not the whole item is highlighted or it is a
11484 transparent item.
11485 This function is useful for debugging a syntax file.
11486 Example that shows the syntax stack under the cursor: >
11487 for id in synstack(line("."), col("."))
11488 echo synIDattr(id, "name")
11489 endfor
11490< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011491 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011492 character in a line and the first column in an empty line are
11493 valid positions.
11494
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011495 Return type: list<number> or list<any>
11496
11497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011498system({expr} [, {input}]) *system()* *E677*
11499 Get the output of the shell command {expr} as a |String|. See
11500 |systemlist()| to get the output as a |List|.
11501
11502 When {input} is given and is a |String| this string is written
11503 to a file and passed as stdin to the command. The string is
11504 written as-is, you need to take care of using the correct line
11505 separators yourself.
11506 If {input} is given and is a |List| it is written to the file
11507 in a way |writefile()| does with {binary} set to "b" (i.e.
11508 with a newline between each list item with newlines inside
11509 list items converted to NULs).
11510 When {input} is given and is a number that is a valid id for
11511 an existing buffer then the content of the buffer is written
11512 to the file line by line, each line terminated by a NL and
11513 NULs characters where the text has a NL.
11514
11515 Pipes are not used, the 'shelltemp' option is not used.
11516
11517 When prepended by |:silent| the terminal will not be set to
11518 cooked mode. This is meant to be used for commands that do
11519 not need the user to type. It avoids stray characters showing
11520 up on the screen which require |CTRL-L| to remove. >
11521 :silent let f = system('ls *.vim')
11522<
11523 Note: Use |shellescape()| or |::S| with |expand()| or
11524 |fnamemodify()| to escape special characters in a command
11525 argument. Newlines in {expr} may cause the command to fail.
11526 The characters in 'shellquote' and 'shellxquote' may also
11527 cause trouble.
11528 This is not to be used for interactive commands.
11529
11530 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011531 :let files = system('ls ' .. shellescape(expand('%:h')))
11532 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011533
11534< To make the result more system-independent, the shell output
11535 is filtered to replace <CR> with <NL> for Macintosh, and
11536 <CR><NL> with <NL> for DOS-like systems.
11537 To avoid the string being truncated at a NUL, all NUL
11538 characters are replaced with SOH (0x01).
11539
11540 The command executed is constructed using several options:
11541 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11542 ({tmp} is an automatically generated file name).
11543 For Unix, braces are put around {expr} to allow for
11544 concatenated commands.
11545
11546 The command will be executed in "cooked" mode, so that a
11547 CTRL-C will interrupt the command (on Unix at least).
11548
11549 The resulting error code can be found in |v:shell_error|.
11550 This function will fail in |restricted-mode|.
11551
11552 Note that any wrong value in the options mentioned above may
11553 make the function fail. It has also been reported to fail
11554 when using a security agent application.
11555 Unlike ":!cmd" there is no automatic check for changed files.
11556 Use |:checktime| to force a check.
11557
11558 Can also be used as a |method|: >
11559 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011560<
11561 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011562
11563
11564systemlist({expr} [, {input}]) *systemlist()*
11565 Same as |system()|, but returns a |List| with lines (parts of
11566 output separated by NL) with NULs transformed into NLs. Output
11567 is the same as |readfile()| will output with {binary} argument
11568 set to "b", except that there is no extra empty item when the
11569 result ends in a NL.
11570 Note that on MS-Windows you may get trailing CR characters.
11571
11572 To see the difference between "echo hello" and "echo -n hello"
11573 use |system()| and |split()|: >
11574 echo system('echo hello')->split('\n', 1)
11575<
11576 Returns an empty string on error.
11577
11578 Can also be used as a |method|: >
11579 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011580<
11581 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011582
11583
11584tabpagebuflist([{arg}]) *tabpagebuflist()*
11585 The result is a |List|, where each item is the number of the
11586 buffer associated with each window in the current tab page.
11587 {arg} specifies the number of the tab page to be used. When
11588 omitted the current tab page is used.
11589 When {arg} is invalid the number zero is returned.
11590 To get a list of all buffers in all tabs use this: >
11591 let buflist = []
11592 for i in range(tabpagenr('$'))
11593 call extend(buflist, tabpagebuflist(i + 1))
11594 endfor
11595< Note that a buffer may appear in more than one window.
11596
11597 Can also be used as a |method|: >
11598 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011599<
11600 Return type: list<number>
11601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011602
11603tabpagenr([{arg}]) *tabpagenr()*
11604 The result is a Number, which is the number of the current
11605 tab page. The first tab page has number 1.
11606
11607 The optional argument {arg} supports the following values:
11608 $ the number of the last tab page (the tab page
11609 count).
11610 # the number of the last accessed tab page
11611 (where |g<Tab>| goes to). if there is no
11612 previous tab page 0 is returned.
11613 The number can be used with the |:tab| command.
11614
Bram Moolenaard592deb2022-06-17 15:42:40 +010011615 Returns zero on error.
11616
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011617 Return type: |Number|
11618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011619
11620tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11621 Like |winnr()| but for tab page {tabarg}.
11622 {tabarg} specifies the number of tab page to be used.
11623 {arg} is used like with |winnr()|:
11624 - When omitted the current window number is returned. This is
11625 the window which will be used when going to this tab page.
11626 - When "$" the number of windows is returned.
11627 - When "#" the previous window nr is returned.
11628 Useful examples: >
11629 tabpagewinnr(1) " current window of tab page 1
11630 tabpagewinnr(4, '$') " number of windows in tab page 4
11631< When {tabarg} is invalid zero is returned.
11632
11633 Can also be used as a |method|: >
11634 GetTabpage()->tabpagewinnr()
11635<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011636 Return type: |Number|
11637
11638
11639tagfiles() *tagfiles()*
11640 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011641 for the current buffer. This is the 'tags' option expanded.
11642
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011643 Return type: list<string> or list<any>
11644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011645
11646taglist({expr} [, {filename}]) *taglist()*
11647 Returns a |List| of tags matching the regular expression {expr}.
11648
11649 If {filename} is passed it is used to prioritize the results
11650 in the same way that |:tselect| does. See |tag-priority|.
11651 {filename} should be the full path of the file.
11652
11653 Each list item is a dictionary with at least the following
11654 entries:
11655 name Name of the tag.
11656 filename Name of the file where the tag is
11657 defined. It is either relative to the
11658 current directory or a full path.
11659 cmd Ex command used to locate the tag in
11660 the file.
11661 kind Type of the tag. The value for this
11662 entry depends on the language specific
11663 kind values. Only available when
11664 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011665 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011666 static A file specific tag. Refer to
11667 |static-tag| for more information.
11668 More entries may be present, depending on the content of the
11669 tags file: access, implementation, inherits and signature.
11670 Refer to the ctags documentation for information about these
11671 fields. For C code the fields "struct", "class" and "enum"
11672 may appear, they give the name of the entity the tag is
11673 contained in.
11674
11675 The ex-command "cmd" can be either an ex search pattern, a
11676 line number or a line number followed by a byte number.
11677
11678 If there are no matching tags, then an empty list is returned.
11679
11680 To get an exact tag match, the anchors '^' and '$' should be
11681 used in {expr}. This also make the function work faster.
11682 Refer to |tag-regexp| for more information about the tag
11683 search regular expression pattern.
11684
11685 Refer to |'tags'| for information about how the tags file is
11686 located by Vim. Refer to |tags-file-format| for the format of
11687 the tags file generated by the different ctags tools.
11688
11689 Can also be used as a |method|: >
11690 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011691<
11692 Return type: list<dict<any>> or list<any>
11693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011694
11695tan({expr}) *tan()*
11696 Return the tangent of {expr}, measured in radians, as a |Float|
11697 in the range [-inf, inf].
11698 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011699 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011700 Examples: >
11701 :echo tan(10)
11702< 0.648361 >
11703 :echo tan(-4.01)
11704< -1.181502
11705
11706 Can also be used as a |method|: >
11707 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011708<
11709 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011710
11711
11712tanh({expr}) *tanh()*
11713 Return the hyperbolic tangent of {expr} as a |Float| in the
11714 range [-1, 1].
11715 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011716 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011717 Examples: >
11718 :echo tanh(0.5)
11719< 0.462117 >
11720 :echo tanh(-1)
11721< -0.761594
11722
11723 Can also be used as a |method|: >
11724 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011725<
11726 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011727
11728
11729tempname() *tempname()* *temp-file-name*
11730 The result is a String, which is the name of a file that
11731 doesn't exist. It can be used for a temporary file. The name
11732 is different for at least 26 consecutive calls. Example: >
11733 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011734 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011735< For Unix, the file will be in a private directory |tempfile|
11736 that is recursively deleted when Vim exits, on other systems
11737 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011738 For MS-Windows forward slashes are used when the 'shellslash'
11739 option is set, or when 'shellcmdflag' starts with '-' and
11740 'shell' does not contain powershell or pwsh.
11741
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011742 Return type: |String|
11743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011744
11745term_ functions are documented here: |terminal-function-details|
11746
11747
11748terminalprops() *terminalprops()*
11749 Returns a |Dictionary| with properties of the terminal that Vim
11750 detected from the response to |t_RV| request. See
11751 |v:termresponse| for the response itself. If |v:termresponse|
11752 is empty most values here will be 'u' for unknown.
11753 cursor_style whether sending |t_RS| works **
11754 cursor_blink_mode whether sending |t_RC| works **
11755 underline_rgb whether |t_8u| works **
11756 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011757 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011758
11759 ** value 'u' for unknown, 'y' for yes, 'n' for no
11760
11761 If the |+termresponse| feature is missing then the result is
11762 an empty dictionary.
11763
11764 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11765 current cursor style.
11766 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11767 request the cursor blink status.
11768 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11769 is not empty, Vim will detect the working of sending |t_RS|
11770 and |t_RC| on startup.
11771
11772 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11773 This avoids sending it to xterm, which would clear the colors.
11774
11775 For "mouse" the value 'u' is unknown
11776
11777 Also see:
11778 - 'ambiwidth' - detected by using |t_u7|.
11779 - |v:termstyleresp| and |v:termblinkresp| for the response to
11780 |t_RS| and |t_RC|.
11781
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011782 Return type: dict<string>
11783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011784
11785test_ functions are documented here: |test-functions-details|
11786
11787
11788 *timer_info()*
11789timer_info([{id}])
11790 Return a list with information about timers.
11791 When {id} is given only information about this timer is
11792 returned. When timer {id} does not exist an empty list is
11793 returned.
11794 When {id} is omitted information about all timers is returned.
11795
11796 For each timer the information is stored in a |Dictionary| with
11797 these items:
11798 "id" the timer ID
11799 "time" time the timer was started with
11800 "remaining" time until the timer fires
11801 "repeat" number of times the timer will still fire;
11802 -1 means forever
11803 "callback" the callback
11804 "paused" 1 if the timer is paused, 0 otherwise
11805
11806 Can also be used as a |method|: >
11807 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011808<
11809 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011810
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011811 {only available when compiled with the |+timers| feature}
11812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011813
11814timer_pause({timer}, {paused}) *timer_pause()*
11815 Pause or unpause a timer. A paused timer does not invoke its
11816 callback when its time expires. Unpausing a timer may cause
11817 the callback to be invoked almost immediately if enough time
11818 has passed.
11819
11820 Pausing a timer is useful to avoid the callback to be called
11821 for a short time.
11822
11823 If {paused} evaluates to a non-zero Number or a non-empty
11824 String, then the timer is paused, otherwise it is unpaused.
11825 See |non-zero-arg|.
11826
11827 Can also be used as a |method|: >
11828 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011829<
11830 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011831
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011832 {only available when compiled with the |+timers| feature}
11833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011834
11835 *timer_start()* *timer* *timers*
11836timer_start({time}, {callback} [, {options}])
11837 Create a timer and return the timer ID.
11838
11839 {time} is the waiting time in milliseconds. This is the
11840 minimum time before invoking the callback. When the system is
11841 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011842 Zero can be used to execute the callback when Vim is back in
11843 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011844
11845 {callback} is the function to call. It can be the name of a
11846 function or a |Funcref|. It is called with one argument, which
11847 is the timer ID. The callback is only invoked when Vim is
11848 waiting for input.
11849 If you want to show a message look at |popup_notification()|
11850 to avoid interfering with what the user is doing.
11851
11852 {options} is a dictionary. Supported entries:
11853 "repeat" Number of times to repeat calling the
11854 callback. -1 means forever. When not present
11855 the callback will be called once.
11856 If the timer causes an error three times in a
11857 row the repeat is cancelled. This avoids that
11858 Vim becomes unusable because of all the error
11859 messages.
11860
Bram Moolenaard592deb2022-06-17 15:42:40 +010011861 Returns -1 on error.
11862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011863 Example: >
11864 func MyHandler(timer)
11865 echo 'Handler called'
11866 endfunc
11867 let timer = timer_start(500, 'MyHandler',
11868 \ {'repeat': 3})
11869< This will invoke MyHandler() three times at 500 msec
11870 intervals.
11871
11872 Can also be used as a |method|: >
11873 GetMsec()->timer_start(callback)
11874
11875< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011876
11877 Return type: |Number|
11878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011879 {only available when compiled with the |+timers| feature}
11880
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011882timer_stop({timer}) *timer_stop()*
11883 Stop a timer. The timer callback will no longer be invoked.
11884 {timer} is an ID returned by timer_start(), thus it must be a
11885 Number. If {timer} does not exist there is no error.
11886
11887 Can also be used as a |method|: >
11888 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011889<
11890 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011891
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011892 {only available when compiled with the |+timers| feature}
11893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011894
11895timer_stopall() *timer_stopall()*
11896 Stop all timers. The timer callbacks will no longer be
11897 invoked. Useful if a timer is misbehaving. If there are no
11898 timers there is no error.
11899
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011900 Return type: |Number|
11901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011902 {only available when compiled with the |+timers| feature}
11903
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011905tolower({expr}) *tolower()*
11906 The result is a copy of the String given, with all uppercase
11907 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011908 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011909
11910 Can also be used as a |method|: >
11911 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011912<
11913 Return type: |String|
11914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011915
11916toupper({expr}) *toupper()*
11917 The result is a copy of the String given, with all lowercase
11918 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011919 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011920
11921 Can also be used as a |method|: >
11922 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011923<
11924 Return type: |String|
11925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011926
11927tr({src}, {fromstr}, {tostr}) *tr()*
11928 The result is a copy of the {src} string with all characters
11929 which appear in {fromstr} replaced by the character in that
11930 position in the {tostr} string. Thus the first character in
11931 {fromstr} is translated into the first character in {tostr}
11932 and so on. Exactly like the unix "tr" command.
11933 This code also deals with multibyte characters properly.
11934
Bram Moolenaard592deb2022-06-17 15:42:40 +010011935 Returns an empty string on error.
11936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011937 Examples: >
11938 echo tr("hello there", "ht", "HT")
11939< returns "Hello THere" >
11940 echo tr("<blob>", "<>", "{}")
11941< returns "{blob}"
11942
11943 Can also be used as a |method|: >
11944 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011945<
11946 Return type: |String|
11947
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011948
11949trim({text} [, {mask} [, {dir}]]) *trim()*
11950 Return {text} as a String where any character in {mask} is
11951 removed from the beginning and/or end of {text}.
11952
Illia Bobyr80799172023-10-17 18:00:50 +020011953 If {mask} is not given, or is an empty string, {mask} is all
11954 characters up to 0x20, which includes Tab, space, NL and CR,
11955 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011956
11957 The optional {dir} argument specifies where to remove the
11958 characters:
11959 0 remove from the beginning and end of {text}
11960 1 remove only at the beginning of {text}
11961 2 remove only at the end of {text}
11962 When omitted both ends are trimmed.
11963
11964 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011965 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011966
11967 Examples: >
11968 echo trim(" some text ")
11969< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011970 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011971< returns "RESERVE_TAIL" >
11972 echo trim("rm<Xrm<>X>rrm", "rm<>")
11973< returns "Xrm<>X" (characters in the middle are not removed) >
11974 echo trim(" vim ", " ", 2)
11975< returns " vim"
11976
11977 Can also be used as a |method|: >
11978 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011979<
11980 Return type: |String|
11981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011982
11983trunc({expr}) *trunc()*
11984 Return the largest integral value with magnitude less than or
11985 equal to {expr} as a |Float| (truncate towards zero).
11986 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011987 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011988 Examples: >
11989 echo trunc(1.456)
11990< 1.0 >
11991 echo trunc(-5.456)
11992< -5.0 >
11993 echo trunc(4.0)
11994< 4.0
11995
11996 Can also be used as a |method|: >
11997 Compute()->trunc()
11998<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011999 Return type: |Float|
12000
12001
Yegappan Lakshmanan1c2f4752025-03-30 15:37:24 +020012002tuple2list({tuple}) *tuple2list()*
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010012003 Create a List from a shallow copy of the tuple items.
12004 Examples: >
12005 tuple2list((1, 2, 3)) returns [1, 2, 3]
12006< |list2tuple()| does the opposite.
12007
12008 This function doesn't recursively convert all the Tuple items
12009 in {tuple} to a List. Note that the items are identical
12010 between the list and the tuple, changing an item changes the
12011 contents of both the tuple and the list.
12012
12013 Returns an empty list on error.
12014
12015 Can also be used as a |method|: >
12016 GetTuple()->tuple2list()
12017<
12018 Return type: list<{type}> (depending on the given |Tuple|)
12019
12020
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012021 *type()*
12022type({expr}) The result is a Number representing the type of {expr}.
12023 Instead of using the number directly, it is better to use the
12024 v:t_ variable that has the value:
12025 Number: 0 |v:t_number|
12026 String: 1 |v:t_string|
12027 Funcref: 2 |v:t_func|
12028 List: 3 |v:t_list|
12029 Dictionary: 4 |v:t_dict|
12030 Float: 5 |v:t_float|
12031 Boolean: 6 |v:t_bool| (v:false and v:true)
12032 None: 7 |v:t_none| (v:null and v:none)
12033 Job: 8 |v:t_job|
12034 Channel: 9 |v:t_channel|
12035 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090012036 Class: 12 |v:t_class|
12037 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010012038 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010012039 Enum: 15 |v:t_enum|
12040 EnumValue: 16 |v:t_enumvalue|
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010012041 Tuple: 17 |v:t_tuple|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012042 For backward compatibility, this method can be used: >
12043 :if type(myvar) == type(0)
12044 :if type(myvar) == type("")
12045 :if type(myvar) == type(function("tr"))
12046 :if type(myvar) == type([])
12047 :if type(myvar) == type({})
12048 :if type(myvar) == type(0.0)
12049 :if type(myvar) == type(v:false)
12050 :if type(myvar) == type(v:none)
12051< To check if the v:t_ variables exist use this: >
12052 :if exists('v:t_number')
12053
12054< Can also be used as a |method|: >
12055 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012056<
12057 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012058
12059
12060typename({expr}) *typename()*
12061 Return a string representation of the type of {expr}.
12062 Example: >
12063 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000012064< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012065
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012066 Return type: |String|
12067
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012068
12069undofile({name}) *undofile()*
12070 Return the name of the undo file that would be used for a file
12071 with name {name} when writing. This uses the 'undodir'
12072 option, finding directories that exist. It does not check if
12073 the undo file exists.
12074 {name} is always expanded to the full path, since that is what
12075 is used internally.
12076 If {name} is empty undofile() returns an empty string, since a
12077 buffer without a file name will not write an undo file.
12078 Useful in combination with |:wundo| and |:rundo|.
12079 When compiled without the |+persistent_undo| option this always
12080 returns an empty string.
12081
12082 Can also be used as a |method|: >
12083 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012084<
12085 Return type: |String|
12086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012087
Devin J. Pohly5fee1112023-04-23 20:26:59 -050012088undotree([{buf}]) *undotree()*
12089 Return the current state of the undo tree for the current
12090 buffer, or for a specific buffer if {buf} is given. The
12091 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012092 "seq_last" The highest undo sequence number used.
12093 "seq_cur" The sequence number of the current position in
12094 the undo tree. This differs from "seq_last"
12095 when some changes were undone.
12096 "time_cur" Time last used for |:earlier| and related
12097 commands. Use |strftime()| to convert to
12098 something readable.
12099 "save_last" Number of the last file write. Zero when no
12100 write yet.
12101 "save_cur" Number of the current position in the undo
12102 tree.
12103 "synced" Non-zero when the last undo block was synced.
12104 This happens when waiting from input from the
12105 user. See |undo-blocks|.
12106 "entries" A list of dictionaries with information about
12107 undo blocks.
12108
12109 The first item in the "entries" list is the oldest undo item.
12110 Each List item is a |Dictionary| with these items:
12111 "seq" Undo sequence number. Same as what appears in
12112 |:undolist|.
12113 "time" Timestamp when the change happened. Use
12114 |strftime()| to convert to something readable.
12115 "newhead" Only appears in the item that is the last one
12116 that was added. This marks the last change
12117 and where further changes will be added.
12118 "curhead" Only appears in the item that is the last one
12119 that was undone. This marks the current
12120 position in the undo tree, the block that will
12121 be used by a redo command. When nothing was
12122 undone after the last change this item will
12123 not appear anywhere.
12124 "save" Only appears on the last block before a file
12125 write. The number is the write count. The
12126 first write has number 1, the last one the
12127 "save_last" mentioned above.
12128 "alt" Alternate entry. This is again a List of undo
12129 blocks. Each item may again have an "alt"
12130 item.
12131
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012132 Return type: dict<any>
12133
12134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012135uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
12136 Remove second and succeeding copies of repeated adjacent
12137 {list} items in-place. Returns {list}. If you want a list
12138 to remain unmodified make a copy first: >
12139 :let newlist = uniq(copy(mylist))
12140< The default compare function uses the string representation of
12141 each item. For the use of {func} and {dict} see |sort()|.
12142
Bram Moolenaard592deb2022-06-17 15:42:40 +010012143 Returns zero if {list} is not a |List|.
12144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012145 Can also be used as a |method|: >
12146 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010012147<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012148 Return type: list<{type}>
12149
12150
Christian Brabandt67672ef2023-04-24 21:09:54 +010012151 *utf16idx()*
12152utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012153 Same as |charidx()| but returns the UTF-16 code unit index of
12154 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012155
12156 When {charidx} is present and TRUE, {idx} is used as the
12157 character index in the String {string} instead of as the byte
12158 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012159 An {idx} in the middle of a UTF-8 sequence is rounded
12160 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012161
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012162 Returns -1 if the arguments are invalid or if there are less
12163 than {idx} bytes in {string}. If there are exactly {idx} bytes
12164 the length of the string in UTF-16 code units is returned.
12165
Christian Brabandt67672ef2023-04-24 21:09:54 +010012166 See |byteidx()| and |byteidxcomp()| for getting the byte index
12167 from the UTF-16 index and |charidx()| for getting the
12168 character index from the UTF-16 index.
12169 Refer to |string-offset-encoding| for more information.
12170 Examples: >
12171 echo utf16idx('a😊😊', 3) returns 2
12172 echo utf16idx('a😊😊', 7) returns 4
12173 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12174 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12175 echo utf16idx('aą́c', 6) returns 2
12176 echo utf16idx('aą́c', 6, 1) returns 4
12177 echo utf16idx('a😊😊', 9) returns -1
12178<
12179 Can also be used as a |method|: >
12180 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012181<
12182 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012183
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012184
12185values({dict}) *values()*
12186 Return a |List| with all the values of {dict}. The |List| is
12187 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012188 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012189
12190 Can also be used as a |method|: >
12191 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012192<
12193 Return type: list<any>
12194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012195
zeertzjq825cf812023-08-17 22:55:25 +020012196virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012197 The result is a Number, which is the screen column of the file
12198 position given with {expr}. That is, the last screen position
12199 occupied by the character at that position, when the screen
12200 would be of unlimited width. When there is a <Tab> at the
12201 position, the returned Number will be the column at the end of
12202 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12203 set to 8, it returns 8. |conceal| is ignored.
12204 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012205
zeertzjq02f3eba2024-06-12 20:45:24 +020012206 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012207 When {expr} is "$", it means the end of the cursor line, so
12208 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012209
12210 When 'virtualedit' is used {expr} can be [lnum, col, off],
12211 where "off" is the offset in screen columns from the start of
12212 the character. E.g., a position within a <Tab> or after the
12213 last character. When "off" is omitted zero is used. When
12214 Virtual editing is active in the current mode, a position
12215 beyond the end of the line can be returned. Also see
12216 |'virtualedit'|
12217
zeertzjq825cf812023-08-17 22:55:25 +020012218 If {list} is present and non-zero then virtcol() returns a
12219 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012220 character.
12221
zeertzjq825cf812023-08-17 22:55:25 +020012222 With the optional {winid} argument the values are obtained for
12223 that window instead of the current window.
12224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012225 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012227 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012228 " With text "foo^Lbar" and cursor on the "^L":
12229
12230 virtcol(".") " returns 5
12231 virtcol(".", 1) " returns [4, 5]
12232 virtcol("$") " returns 9
12233
12234 " With text " there", with 't at 'h':
12235
12236 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012237<
12238 The first column is 1. 0 or [0, 0] is returned for an error.
12239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012240 A more advanced example that echoes the maximum length of
12241 all lines: >
12242 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12243
12244< Can also be used as a |method|: >
12245 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012246<
12247 Return type: |Number|
12248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012249
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012250virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12251 The result is a Number, which is the byte index of the
12252 character in window {winid} at buffer line {lnum} and virtual
12253 column {col}.
12254
zeertzjqb583eda2023-10-14 11:32:28 +020012255 If buffer line {lnum} is an empty line, 0 is returned.
12256
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012257 If {col} is greater than the last virtual column in line
12258 {lnum}, then the byte index of the character at the last
12259 virtual column is returned.
12260
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012261 For a multi-byte character, the column number of the first
12262 byte in the character is returned.
12263
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012264 The {winid} argument can be the window number or the
12265 |window-ID|. If this is zero, then the current window is used.
12266
12267 Returns -1 if the window {winid} doesn't exist or the buffer
12268 line {lnum} or virtual column {col} is invalid.
12269
12270 See also |screenpos()|, |virtcol()| and |col()|.
12271
12272 Can also be used as a |method|: >
12273 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012274<
12275 Return type: |Number|
12276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012277
12278visualmode([{expr}]) *visualmode()*
12279 The result is a String, which describes the last Visual mode
12280 used in the current buffer. Initially it returns an empty
12281 string, but once Visual mode has been used, it returns "v",
12282 "V", or "<CTRL-V>" (a single CTRL-V character) for
12283 character-wise, line-wise, or block-wise Visual mode
12284 respectively.
12285 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012286 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012287< This enters the same Visual mode as before. It is also useful
12288 in scripts if you wish to act differently depending on the
12289 Visual mode that was used.
12290 If Visual mode is active, use |mode()| to get the Visual mode
12291 (e.g., in a |:vmap|).
12292 If {expr} is supplied and it evaluates to a non-zero Number or
12293 a non-empty String, then the Visual mode will be cleared and
12294 the old value is returned. See |non-zero-arg|.
12295
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012296 Return type: |String|
12297
12298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012299wildmenumode() *wildmenumode()*
12300 Returns |TRUE| when the wildmenu is active and |FALSE|
12301 otherwise. See 'wildmenu' and 'wildmode'.
12302 This can be used in mappings to handle the 'wildcharm' option
12303 gracefully. (Makes only sense with |mapmode-c| mappings).
12304
12305 For example to make <c-j> work like <down> in wildmode, use: >
12306 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12307<
Milly6c2fc372024-10-16 22:11:17 +020012308 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012309
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012310 Return type: |Number|
12311
12312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012313win_execute({id}, {command} [, {silent}]) *win_execute()*
12314 Like `execute()` but in the context of window {id}.
12315 The window will temporarily be made the current window,
12316 without triggering autocommands or changing directory. When
12317 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012318 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012319 Example: >
12320 call win_execute(winid, 'set syntax=python')
12321< Doing the same with `setwinvar()` would not trigger
12322 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012323 *E994*
12324 Not all commands are allowed in popup windows.
12325 When window {id} does not exist then no error is given and
12326 an empty string is returned.
12327
12328 Can also be used as a |method|, the base is passed as the
12329 second argument: >
12330 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012331<
12332 Return type: |String|
12333
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012334
12335win_findbuf({bufnr}) *win_findbuf()*
12336 Returns a |List| with |window-ID|s for windows that contain
12337 buffer {bufnr}. When there is none the list is empty.
12338
12339 Can also be used as a |method|: >
12340 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012341<
12342 Return type: list<number> or list<any>
12343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012344
12345win_getid([{win} [, {tab}]]) *win_getid()*
12346 Get the |window-ID| for the specified window.
12347 When {win} is missing use the current window.
12348 With {win} this is the window number. The top window has
12349 number 1.
12350 Without {tab} use the current tab, otherwise the tab with
12351 number {tab}. The first tab has number one.
12352 Return zero if the window cannot be found.
12353
12354 Can also be used as a |method|: >
12355 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012356<
12357 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012358
12359
12360win_gettype([{nr}]) *win_gettype()*
12361 Return the type of the window:
12362 "autocmd" autocommand window. Temporary window
12363 used to execute autocommands.
12364 "command" command-line window |cmdwin|
12365 (empty) normal window
12366 "loclist" |location-list-window|
12367 "popup" popup window |popup|
12368 "preview" preview window |preview-window|
12369 "quickfix" |quickfix-window|
12370 "unknown" window {nr} not found
12371
12372 When {nr} is omitted return the type of the current window.
12373 When {nr} is given return the type of this window by number or
12374 |window-ID|.
12375
12376 Also see the 'buftype' option. When running a terminal in a
12377 popup window then 'buftype' is "terminal" and win_gettype()
12378 returns "popup".
12379
12380 Can also be used as a |method|: >
12381 GetWinid()->win_gettype()
12382<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012383 Return type: |String|
12384
12385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012386win_gotoid({expr}) *win_gotoid()*
12387 Go to window with ID {expr}. This may also change the current
12388 tabpage.
12389 Return TRUE if successful, FALSE if the window cannot be found.
12390
12391 Can also be used as a |method|: >
12392 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012393<
12394 Return type: |Number|
12395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012396
12397win_id2tabwin({expr}) *win_id2tabwin()*
12398 Return a list with the tab number and window number of window
12399 with ID {expr}: [tabnr, winnr].
12400 Return [0, 0] if the window cannot be found.
12401
12402 Can also be used as a |method|: >
12403 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012404<
12405 Return type: list<number>
12406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012407
12408win_id2win({expr}) *win_id2win()*
12409 Return the window number of window with ID {expr}.
12410 Return 0 if the window cannot be found in the current tabpage.
12411
12412 Can also be used as a |method|: >
12413 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012414<
12415 Return type: |Number|
12416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012417
Daniel Steinbergee630312022-01-10 13:36:34 +000012418win_move_separator({nr}, {offset}) *win_move_separator()*
12419 Move window {nr}'s vertical separator (i.e., the right border)
12420 by {offset} columns, as if being dragged by the mouse. {nr}
12421 can be a window number or |window-ID|. A positive {offset}
12422 moves right and a negative {offset} moves left. Moving a
12423 window's vertical separator will change the width of the
12424 window and the width of other windows adjacent to the vertical
12425 separator. The magnitude of movement may be smaller than
12426 specified (e.g., as a consequence of maintaining
12427 'winminwidth'). Returns TRUE if the window can be found and
12428 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012429 This will fail for the rightmost window and a full-width
12430 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012431 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012432
12433 Can also be used as a |method|: >
12434 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012435<
12436 Return type: |Number|
12437
Daniel Steinbergee630312022-01-10 13:36:34 +000012438
12439win_move_statusline({nr}, {offset}) *win_move_statusline()*
12440 Move window {nr}'s status line (i.e., the bottom border) by
12441 {offset} rows, as if being dragged by the mouse. {nr} can be a
12442 window number or |window-ID|. A positive {offset} moves down
12443 and a negative {offset} moves up. Moving a window's status
12444 line will change the height of the window and the height of
12445 other windows adjacent to the status line. The magnitude of
12446 movement may be smaller than specified (e.g., as a consequence
12447 of maintaining 'winminheight'). Returns TRUE if the window can
12448 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012449 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012450
12451 Can also be used as a |method|: >
12452 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012453<
12454 Return type: |Number|
12455
Daniel Steinbergee630312022-01-10 13:36:34 +000012456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012457win_screenpos({nr}) *win_screenpos()*
12458 Return the screen position of window {nr} as a list with two
12459 numbers: [row, col]. The first window always has position
12460 [1, 1], unless there is a tabline, then it is [2, 1].
12461 {nr} can be the window number or the |window-ID|. Use zero
12462 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012463 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012464
12465 Can also be used as a |method|: >
12466 GetWinid()->win_screenpos()
12467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012468 Return type: list<number>
12469
12470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012471win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012472 Temporarily switch to window {target}, then move window {nr}
12473 to a new split adjacent to {target}.
12474 Unlike commands such as |:split|, no new windows are created
12475 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012476
12477 Both {nr} and {target} can be window numbers or |window-ID|s.
12478 Both must be in the current tab page.
12479
12480 Returns zero for success, non-zero for failure.
12481
12482 {options} is a |Dictionary| with the following optional entries:
12483 "vertical" When TRUE, the split is created vertically,
12484 like with |:vsplit|.
12485 "rightbelow" When TRUE, the split is made below or to the
12486 right (if vertical). When FALSE, it is done
12487 above or to the left (if vertical). When not
12488 present, the values of 'splitbelow' and
12489 'splitright' are used.
12490
12491 Can also be used as a |method|: >
12492 GetWinid()->win_splitmove(target)
12493<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012494 Return type: |Number|
12495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012496
12497 *winbufnr()*
12498winbufnr({nr}) The result is a Number, which is the number of the buffer
12499 associated with window {nr}. {nr} can be the window number or
12500 the |window-ID|.
12501 When {nr} is zero, the number of the buffer in the current
12502 window is returned.
12503 When window {nr} doesn't exist, -1 is returned.
12504 Example: >
12505 :echo "The file in the current window is " . bufname(winbufnr(0))
12506<
12507 Can also be used as a |method|: >
12508 FindWindow()->winbufnr()->bufname()
12509<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012510 Return type: |Number|
12511
12512
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012513 *wincol()*
12514wincol() The result is a Number, which is the virtual column of the
12515 cursor in the window. This is counting screen cells from the
12516 left side of the window. The leftmost column is one.
12517
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012518 Return type: |Number|
12519
12520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012521 *windowsversion()*
12522windowsversion()
12523 The result is a String. For MS-Windows it indicates the OS
12524 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12525 Windows XP is "5.1". For non-MS-Windows systems the result is
12526 an empty string.
12527
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012528 Return type: |String|
12529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012530winheight({nr}) *winheight()*
12531 The result is a Number, which is the height of window {nr}.
12532 {nr} can be the window number or the |window-ID|.
12533 When {nr} is zero, the height of the current window is
12534 returned. When window {nr} doesn't exist, -1 is returned.
12535 An existing window always has a height of zero or more.
12536 This excludes any window toolbar line.
12537 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012538 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012539
12540< Can also be used as a |method|: >
12541 GetWinid()->winheight()
12542<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012543 Return type: |Number|
12544
12545
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012546winlayout([{tabnr}]) *winlayout()*
12547 The result is a nested List containing the layout of windows
12548 in a tabpage.
12549
12550 Without {tabnr} use the current tabpage, otherwise the tabpage
12551 with number {tabnr}. If the tabpage {tabnr} is not found,
12552 returns an empty list.
12553
12554 For a leaf window, it returns:
12555 ['leaf', {winid}]
12556 For horizontally split windows, which form a column, it
12557 returns:
12558 ['col', [{nested list of windows}]]
12559 For vertically split windows, which form a row, it returns:
12560 ['row', [{nested list of windows}]]
12561
12562 Example: >
12563 " Only one window in the tab page
12564 :echo winlayout()
12565 ['leaf', 1000]
12566 " Two horizontally split windows
12567 :echo winlayout()
12568 ['col', [['leaf', 1000], ['leaf', 1001]]]
12569 " The second tab page, with three horizontally split
12570 " windows, with two vertically split windows in the
12571 " middle window
12572 :echo winlayout(2)
12573 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12574 ['leaf', 1001]]], ['leaf', 1000]]]
12575<
12576 Can also be used as a |method|: >
12577 GetTabnr()->winlayout()
12578<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012579 Return type: list<any>
12580
12581
12582winline() *winline()*
12583 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012584 in the window. This is counting screen lines from the top of
12585 the window. The first line is one.
12586 If the cursor was moved the view on the file will be updated
12587 first, this may cause a scroll.
12588
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012589 Return type: |Number|
12590
12591
12592winnr([{arg}]) *winnr()*
12593 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012594 window. The top window has number 1.
12595 Returns zero for a popup window.
12596
12597 The optional argument {arg} supports the following values:
12598 $ the number of the last window (the window
12599 count).
12600 # the number of the last accessed window (where
12601 |CTRL-W_p| goes to). If there is no previous
12602 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012603 returned. May refer to the current window in
12604 some cases (e.g. when evaluating 'statusline'
12605 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012606 {N}j the number of the Nth window below the
12607 current window (where |CTRL-W_j| goes to).
12608 {N}k the number of the Nth window above the current
12609 window (where |CTRL-W_k| goes to).
12610 {N}h the number of the Nth window left of the
12611 current window (where |CTRL-W_h| goes to).
12612 {N}l the number of the Nth window right of the
12613 current window (where |CTRL-W_l| goes to).
12614 The number can be used with |CTRL-W_w| and ":wincmd w"
12615 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012616 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012617 Also see |tabpagewinnr()| and |win_getid()|.
12618 Examples: >
12619 let window_count = winnr('$')
12620 let prev_window = winnr('#')
12621 let wnum = winnr('3k')
12622
12623< Can also be used as a |method|: >
12624 GetWinval()->winnr()
12625<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012626 Return type: |Number|
12627
12628
12629winrestcmd() *winrestcmd()*
12630 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012631 the current window sizes. Only works properly when no windows
12632 are opened or closed and the current window and tab page is
12633 unchanged.
12634 Example: >
12635 :let cmd = winrestcmd()
12636 :call MessWithWindowSizes()
12637 :exe cmd
12638<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012639 Return type: |String|
12640
12641
12642winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012643 Uses the |Dictionary| returned by |winsaveview()| to restore
12644 the view of the current window.
12645 Note: The {dict} does not have to contain all values, that are
12646 returned by |winsaveview()|. If values are missing, those
12647 settings won't be restored. So you can use: >
12648 :call winrestview({'curswant': 4})
12649<
12650 This will only set the curswant value (the column the cursor
12651 wants to move on vertical movements) of the cursor to column 5
12652 (yes, that is 5), while all other settings will remain the
12653 same. This is useful, if you set the cursor position manually.
12654
12655 If you have changed the values the result is unpredictable.
12656 If the window size changed the result won't be the same.
12657
12658 Can also be used as a |method|: >
12659 GetView()->winrestview()
12660<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012661 Return type: |Number|
12662
12663
12664winsaveview() *winsaveview()*
12665 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012666 the view of the current window. Use |winrestview()| to
12667 restore the view.
12668 This is useful if you have a mapping that jumps around in the
12669 buffer and you want to go back to the original view.
12670 This does not save fold information. Use the 'foldenable'
12671 option to temporarily switch off folding, so that folds are
12672 not opened when moving around. This may have side effects.
12673 The return value includes:
12674 lnum cursor line number
12675 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012676 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012677 returns)
12678 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012679 curswant column for vertical movement (Note:
12680 the first column is zero, as opposed
12681 to what |getcurpos()| returns). After
12682 |$| command it will be a very large
12683 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012684 topline first line in the window
12685 topfill filler lines, only in diff mode
12686 leftcol first column displayed; only used when
12687 'wrap' is off
12688 skipcol columns skipped
12689 Note that no option values are saved.
12690
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012691 Return type: dict<number>
12692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012693
12694winwidth({nr}) *winwidth()*
12695 The result is a Number, which is the width of window {nr}.
12696 {nr} can be the window number or the |window-ID|.
12697 When {nr} is zero, the width of the current window is
12698 returned. When window {nr} doesn't exist, -1 is returned.
12699 An existing window always has a width of zero or more.
12700 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012701 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012702 :if winwidth(0) <= 50
12703 : 50 wincmd |
12704 :endif
12705< For getting the terminal or screen size, see the 'columns'
12706 option.
12707
12708 Can also be used as a |method|: >
12709 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012710<
12711 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012712
12713
12714wordcount() *wordcount()*
12715 The result is a dictionary of byte/chars/word statistics for
12716 the current buffer. This is the same info as provided by
12717 |g_CTRL-G|
12718 The return value includes:
12719 bytes Number of bytes in the buffer
12720 chars Number of chars in the buffer
12721 words Number of words in the buffer
12722 cursor_bytes Number of bytes before cursor position
12723 (not in Visual mode)
12724 cursor_chars Number of chars before cursor position
12725 (not in Visual mode)
12726 cursor_words Number of words before cursor position
12727 (not in Visual mode)
12728 visual_bytes Number of bytes visually selected
12729 (only in Visual mode)
12730 visual_chars Number of chars visually selected
12731 (only in Visual mode)
12732 visual_words Number of words visually selected
12733 (only in Visual mode)
12734
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012735 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012736
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012737
12738writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012739 When {object} is a |List| write it to file {fname}. Each list
12740 item is separated with a NL. Each list item must be a String
12741 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012742 All NL characters are replaced with a NUL character.
12743 Inserting CR characters needs to be done before passing {list}
12744 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012745
12746 When {object} is a |Blob| write the bytes to file {fname}
12747 unmodified, also when binary mode is not specified.
12748
12749 {flags} must be a String. These characters are recognized:
12750
12751 'b' Binary mode is used: There will not be a NL after the
12752 last list item. An empty item at the end does cause the
12753 last line in the file to end in a NL.
12754
12755 'a' Append mode is used, lines are appended to the file: >
12756 :call writefile(["foo"], "event.log", "a")
12757 :call writefile(["bar"], "event.log", "a")
12758<
12759 'D' Delete the file when the current function ends. This
12760 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012761 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012762< Fails when not in a function. Also see |:defer|.
12763
12764 's' fsync() is called after writing the file. This flushes
12765 the file to disk, if possible. This takes more time but
12766 avoids losing the file if the system crashes.
12767
12768 'S' fsync() is not called, even when 'fsync' is set.
12769
12770 When {flags} does not contain "S" or "s" then fsync() is
12771 called if the 'fsync' option is set.
12772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012773 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012774
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012775 When the write fails -1 is returned, otherwise 0. There is an
12776 error message if the file can't be created or when writing
12777 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012779 Also see |readfile()|.
12780 To copy a file byte for byte: >
12781 :let fl = readfile("foo", "b")
12782 :call writefile(fl, "foocopy", "b")
12783
12784< Can also be used as a |method|: >
12785 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012786<
12787 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012788
12789
12790xor({expr}, {expr}) *xor()*
12791 Bitwise XOR on the two arguments. The arguments are converted
12792 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012793 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012794 Example: >
12795 :let bits = xor(bits, 0x80)
12796<
12797 Can also be used as a |method|: >
12798 :let bits = bits->xor(0x80)
12799<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012800 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012801
12802==============================================================================
128033. Feature list *feature-list*
12804
12805There are three types of features:
128061. Features that are only supported when they have been enabled when Vim
12807 was compiled |+feature-list|. Example: >
12808 :if has("cindent")
12809< *gui_running*
128102. Features that are only supported when certain conditions have been met.
12811 Example: >
12812 :if has("gui_running")
12813< *has-patch*
128143. Beyond a certain version or at a certain version and including a specific
12815 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12816 later, or it is version 7.4 and patch 248 was included. Example: >
12817 :if has("patch-7.4.248")
12818< Note that it's possible for patch 248 to be omitted even though 249 is
12819 included. Only happens when cherry-picking patches.
12820 Note that this form only works for patch 7.4.237 and later, before that
12821 you need to check for the patch and the v:version. Example (checking
12822 version 6.2.148 or later): >
12823 :if v:version > 602 || (v:version == 602 && has("patch148"))
12824
12825Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12826use: `if exists('+shellslash')`
12827
12828
12829acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012830all_builtin_terms Compiled with all builtin terminals enabled. (always
12831 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012832amiga Amiga version of Vim.
12833arabic Compiled with Arabic support |Arabic|.
12834arp Compiled with ARP support (Amiga).
12835autocmd Compiled with autocommand support. (always true)
12836autochdir Compiled with support for 'autochdir'
12837autoservername Automatically enable |clientserver|
12838balloon_eval Compiled with |balloon-eval| support.
12839balloon_multiline GUI supports multiline balloons.
12840beos BeOS version of Vim.
12841browse Compiled with |:browse| support, and browse() will
12842 work.
12843browsefilter Compiled with support for |browsefilter|.
12844bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012845builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012846byte_offset Compiled with support for 'o' in 'statusline'
12847channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012848cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012849clientserver Compiled with remote invocation support |clientserver|.
12850clipboard Compiled with 'clipboard' support.
12851clipboard_working Compiled with 'clipboard' support and it can be used.
12852cmdline_compl Compiled with |cmdline-completion| support.
12853cmdline_hist Compiled with |cmdline-history| support.
12854cmdline_info Compiled with 'showcmd' and 'ruler' support.
12855comments Compiled with |'comments'| support.
12856compatible Compiled to be very Vi compatible.
12857conpty Platform where |ConPTY| can be used.
12858cryptv Compiled with encryption support |encryption|.
12859cscope Compiled with |cscope| support.
12860cursorbind Compiled with |'cursorbind'| (always true)
12861debug Compiled with "DEBUG" defined.
12862dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012863dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012864dialog_gui Compiled with GUI dialog support.
12865diff Compiled with |vimdiff| and 'diff' support.
12866digraphs Compiled with support for digraphs.
12867directx Compiled with support for DirectX and 'renderoptions'.
12868dnd Compiled with support for the "~ register |quote_~|.
12869drop_file Compiled with |drop_file| support.
12870ebcdic Compiled on a machine with ebcdic character set.
12871emacs_tags Compiled with support for Emacs tags.
12872eval Compiled with expression evaluation support. Always
12873 true, of course!
12874ex_extra |+ex_extra| (always true)
12875extra_search Compiled with support for |'incsearch'| and
12876 |'hlsearch'|
12877farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012878file_in_path Compiled with support for |gf| and |<cfile>| (always
12879 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012880filterpipe When 'shelltemp' is off pipes are used for shell
12881 read/write/filter commands
12882find_in_path Compiled with support for include file searches
12883 |+find_in_path|.
12884float Compiled with support for |Float|.
12885fname_case Case in file names matters (for Amiga and MS-Windows
12886 this is not present).
12887folding Compiled with |folding| support.
12888footer Compiled with GUI footer support. |gui-footer|
12889fork Compiled to use fork()/exec() instead of system().
12890gettext Compiled with message translation |multi-lang|
12891gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012892gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012893gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12894gui_gtk Compiled with GTK+ GUI (any version).
12895gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12896gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12897gui_haiku Compiled with Haiku GUI.
12898gui_mac Compiled with Macintosh GUI.
12899gui_motif Compiled with Motif GUI.
12900gui_photon Compiled with Photon GUI.
12901gui_running Vim is running in the GUI, or it will start soon.
12902gui_win32 Compiled with MS-Windows Win32 GUI.
12903gui_win32s idem, and Win32s system being used (Windows 3.1)
12904haiku Haiku version of Vim.
12905hangul_input Compiled with Hangul input support. |hangul|
12906hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012907hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012908iconv Can use iconv() for conversion.
12909insert_expand Compiled with support for CTRL-X expansion commands in
12910 Insert mode. (always true)
12911job Compiled with support for |channel| and |job|
12912ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012913jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012914keymap Compiled with 'keymap' support.
12915lambda Compiled with |lambda| support.
12916langmap Compiled with 'langmap' support.
12917libcall Compiled with |libcall()| support.
12918linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12919 'breakindent' support.
12920linux Linux version of Vim.
12921lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012922 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012923listcmds Compiled with commands for the buffer list |:files|
12924 and the argument list |arglist|.
12925localmap Compiled with local mappings and abbr. |:map-local|
12926lua Compiled with Lua interface |Lua|.
12927mac Any Macintosh version of Vim cf. osx
12928macunix Synonym for osxdarwin
12929menu Compiled with support for |:menu|.
12930mksession Compiled with support for |:mksession|.
12931modify_fname Compiled with file name modifiers. |filename-modifiers|
12932 (always true)
12933mouse Compiled with support for mouse.
12934mouse_dec Compiled with support for Dec terminal mouse.
12935mouse_gpm Compiled with support for gpm (Linux console mouse)
12936mouse_gpm_enabled GPM mouse is working
12937mouse_netterm Compiled with support for netterm mouse.
12938mouse_pterm Compiled with support for qnx pterm mouse.
12939mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12940mouse_sgr Compiled with support for sgr mouse.
12941mouse_urxvt Compiled with support for urxvt mouse.
12942mouse_xterm Compiled with support for xterm mouse.
12943mouseshape Compiled with support for 'mouseshape'.
12944multi_byte Compiled with support for 'encoding' (always true)
12945multi_byte_encoding 'encoding' is set to a multibyte encoding.
12946multi_byte_ime Compiled with support for IME input method.
12947multi_lang Compiled with support for multiple languages.
12948mzscheme Compiled with MzScheme interface |mzscheme|.
12949nanotime Compiled with sub-second time stamp checks.
12950netbeans_enabled Compiled with support for |netbeans| and connected.
12951netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012952num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012953ole Compiled with OLE automation support for Win32.
12954osx Compiled for macOS cf. mac
12955osxdarwin Compiled for macOS, with |mac-darwin-feature|
12956packages Compiled with |packages| support.
12957path_extra Compiled with up/downwards search in 'path' and 'tags'
12958perl Compiled with Perl interface.
12959persistent_undo Compiled with support for persistent undo history.
12960postscript Compiled with PostScript file printing.
12961printer Compiled with |:hardcopy| support.
12962profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012963prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012964python Python 2.x interface available. |has-python|
12965python_compiled Compiled with Python 2.x interface. |has-python|
12966python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12967python3 Python 3.x interface available. |has-python|
12968python3_compiled Compiled with Python 3.x interface. |has-python|
12969python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012970python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012971pythonx Python 2.x and/or 3.x interface available. |python_x|
12972qnx QNX version of Vim.
12973quickfix Compiled with |quickfix| support.
12974reltime Compiled with |reltime()| support.
12975rightleft Compiled with 'rightleft' support.
12976ruby Compiled with Ruby interface |ruby|.
12977scrollbind Compiled with 'scrollbind' support. (always true)
12978showcmd Compiled with 'showcmd' support.
12979signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012980smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012981sodium Compiled with libsodium for better crypt support
12982sound Compiled with sound support, e.g. `sound_playevent()`
12983spell Compiled with spell checking support |spell|.
12984startuptime Compiled with |--startuptime| support.
12985statusline Compiled with support for 'statusline', 'rulerformat'
12986 and special formats of 'titlestring' and 'iconstring'.
12987sun SunOS version of Vim.
12988sun_workshop Support for Sun |workshop| has been removed.
12989syntax Compiled with syntax highlighting support |syntax|.
12990syntax_items There are active syntax highlighting items for the
12991 current buffer.
12992system Compiled to use system() instead of fork()/exec().
12993tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012994 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012995tag_old_static Support for old static tags was removed, see
12996 |tag-old-static|.
12997tcl Compiled with Tcl interface.
12998termguicolors Compiled with true color in terminal support.
12999terminal Compiled with |terminal| support.
13000terminfo Compiled with terminfo instead of termcap.
13001termresponse Compiled with support for |t_RV| and |v:termresponse|.
13002textobjects Compiled with support for |text-objects|.
13003textprop Compiled with support for |text-properties|.
13004tgetent Compiled with tgetent support, able to use a termcap
13005 or terminfo file.
13006timers Compiled with |timer_start()| support.
13007title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010013008 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013009toolbar Compiled with support for |gui-toolbar|.
13010ttyin input is a terminal (tty)
13011ttyout output is a terminal (tty)
13012unix Unix version of Vim. *+unix*
13013unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
13014user_commands User-defined commands. (always true)
13015vartabs Compiled with variable tabstop support |'vartabstop'|.
13016vcon Win32: Virtual console support is working, can use
13017 'termguicolors'. Also see |+vtp|.
13018vertsplit Compiled with vertically split windows |:vsplit|.
13019 (always true)
13020vim_starting True while initial source'ing takes place. |startup|
13021 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000013022vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013023viminfo Compiled with viminfo support.
13024vimscript-1 Compiled Vim script version 1 support
13025vimscript-2 Compiled Vim script version 2 support
13026vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010013027vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013028virtualedit Compiled with 'virtualedit' option. (always true)
13029visual Compiled with Visual mode. (always true)
13030visualextra Compiled with extra Visual mode commands. (always
13031 true) |blockwise-operators|.
13032vms VMS version of Vim.
13033vreplace Compiled with |gR| and |gr| commands. (always true)
13034vtp Compiled for vcon support |+vtp| (check vcon to find
13035 out if it works in the current console).
13036wildignore Compiled with 'wildignore' option.
13037wildmenu Compiled with 'wildmenu' option.
13038win16 old version for MS-Windows 3.1 (always false)
13039win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
13040 64 bits)
13041win32unix Win32 version of Vim, using Unix files (Cygwin)
13042win64 Win64 version of Vim (MS-Windows 64 bit).
13043win95 Win32 version for MS-Windows 95/98/ME (always false)
13044winaltkeys Compiled with 'winaltkeys' option.
13045windows Compiled with support for more than one window.
13046 (always true)
13047writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020013048xattr Compiled with extended attributes support |xattr|
13049 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013050xfontset Compiled with X fontset support |xfontset|.
13051xim Compiled with X input method support |xim|.
13052xpm Compiled with pixmap support.
13053xpm_w32 Compiled with pixmap support for Win32. (Only for
13054 backward compatibility. Use "xpm" instead.)
13055xsmp Compiled with X session management support.
13056xsmp_interact Compiled with interactive X session management support.
13057xterm_clipboard Compiled with support for xterm clipboard.
13058xterm_save Compiled with support for saving and restoring the
13059 xterm screen.
13060x11 Compiled with X11 support.
13061
13062
13063==============================================================================
130644. Matching a pattern in a String *string-match*
13065
13066This is common between several functions. A regexp pattern as explained at
13067|pattern| is normally used to find a match in the buffer lines. When a
13068pattern is used to find a match in a String, almost everything works in the
13069same way. The difference is that a String is handled like it is one line.
13070When it contains a "\n" character, this is not seen as a line break for the
13071pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
13072>
13073 :let a = "aaaa\nxxxx"
13074 :echo matchstr(a, "..\n..")
13075 aa
13076 xx
13077 :echo matchstr(a, "a.x")
13078 a
13079 x
13080
13081Don't forget that "^" will only match at the first character of the String and
13082"$" at the last character of the string. They don't match after or before a
13083"\n".
13084
13085 vim:tw=78:ts=8:noet:ft=help:norl: