blob: 344dfdfd8866d6d6ab61e07aeebdf89bb81fe3f1 [file] [log] [blame]
Christian Brabandt5647c912025-02-17 21:33:30 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Feb 17
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000132col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000133complete({startcol}, {matches}) none set Insert mode completion
134complete_add({expr}) Number add completion match
135complete_check() Number check for key typed during completion
136complete_info([{what}]) Dict get current completion information
137confirm({msg} [, {choices} [, {default} [, {type}]]])
138 Number number of choice picked by user
139copy({expr}) any make a shallow copy of {expr}
140cos({expr}) Float cosine of {expr}
141cosh({expr}) Float hyperbolic cosine of {expr}
142count({comp}, {expr} [, {ic} [, {start}]])
143 Number count how many {expr} are in {comp}
144cscope_connection([{num}, {dbpath} [, {prepend}]])
145 Number checks existence of cscope connection
146cursor({lnum}, {col} [, {off}])
147 Number move cursor to {lnum}, {col}, {off}
148cursor({list}) Number move cursor to position in {list}
149debugbreak({pid}) Number interrupt process being debugged
150deepcopy({expr} [, {noref}]) any make a full copy of {expr}
151delete({fname} [, {flags}]) Number delete the file or directory {fname}
152deletebufline({buf}, {first} [, {last}])
153 Number delete lines from buffer {buf}
154did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100155diff({fromlist}, {tolist} [, {options}])
156 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000157diff_filler({lnum}) Number diff filler lines about {lnum}
158diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
159digraph_get({chars}) String get the |digraph| of {chars}
160digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200161digraph_set({chars}, {digraph}) Bool register |digraph|
162digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000163echoraw({expr}) none output {expr} as-is
164empty({expr}) Number |TRUE| if {expr} is empty
165environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100166err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000167escape({string}, {chars}) String escape {chars} in {string} with '\'
168eval({string}) any evaluate {string} into its value
169eventhandler() Number |TRUE| if inside an event handler
170executable({expr}) Number 1 if executable {expr} exists
171execute({command}) String execute {command} and get the output
172exepath({expr}) String full path of the command {expr}
173exists({expr}) Number |TRUE| if {expr} exists
174exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
175exp({expr}) Float exponential of {expr}
176expand({expr} [, {nosuf} [, {list}]])
177 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100178expandcmd({string} [, {options}])
179 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000180extend({expr1}, {expr2} [, {expr3}])
181 List/Dict insert items of {expr2} into {expr1}
182extendnew({expr1}, {expr2} [, {expr3}])
183 List/Dict like |extend()| but creates a new
184 List or Dictionary
185feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200186filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
187 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000188filereadable({file}) Number |TRUE| if {file} is a readable file
189filewritable({file}) Number |TRUE| if {file} is a writable file
190filter({expr1}, {expr2}) List/Dict/Blob/String
191 remove items from {expr1} where
192 {expr2} is 0
193finddir({name} [, {path} [, {count}]])
194 String find directory {name} in {path}
195findfile({name} [, {path} [, {count}]])
196 String find file {name} in {path}
197flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
198flattennew({list} [, {maxdepth}])
199 List flatten a copy of {list}
200float2nr({expr}) Number convert Float {expr} to a Number
201floor({expr}) Float round {expr} down
202fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
203fnameescape({fname}) String escape special characters in {fname}
204fnamemodify({fname}, {mods}) String modify file name
205foldclosed({lnum}) Number first line of fold at {lnum} if closed
206foldclosedend({lnum}) Number last line of fold at {lnum} if closed
207foldlevel({lnum}) Number fold level at {lnum}
208foldtext() String line displayed for closed fold
209foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100210foreach({expr1}, {expr2}) List/Dict/Blob/String
211 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100213fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214funcref({name} [, {arglist}] [, {dict}])
215 Funcref reference to function {name}
216function({name} [, {arglist}] [, {dict}])
217 Funcref named reference to function {name}
218garbagecollect([{atexit}]) none free memory, breaking cyclic references
219get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
220get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
221get({func}, {what}) any get property of funcref/partial {func}
222getbufinfo([{buf}]) List information about buffers
223getbufline({buf}, {lnum} [, {end}])
224 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000225getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getbufvar({buf}, {varname} [, {def}])
227 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100228getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000229getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getchangelist([{buf}]) List list of change list items
zeertzjqe0a2ab32025-02-02 09:14:35 +0100231getchar([{expr} [, {opts}]]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232 get one character from the user
233getcharmod() Number modifiers for the last typed character
234getcharpos({expr}) List position of cursor, mark, etc.
235getcharsearch() Dict last character search
zeertzjqe0a2ab32025-02-02 09:14:35 +0100236getcharstr([{expr} [, {opts}]]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200237getcmdcomplpat() String return the completion pattern of the
238 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100239getcmdcompltype() String return the type of the current
240 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200241getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100244getcmdscreenpos() Number return cursor screen position in
245 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000246getcmdtype() String return current command-line type
247getcmdwintype() String return current command-line window type
248getcompletion({pat}, {type} [, {filtered}])
249 List list of cmdline completion matches
250getcurpos([{winnr}]) List position of the cursor
251getcursorcharpos([{winnr}]) List character position of the cursor
252getcwd([{winnr} [, {tabnr}]]) String get the current working directory
253getenv({name}) String return environment variable
254getfontname([{name}]) String name of font being used
255getfperm({fname}) String file permissions of file {fname}
256getfsize({fname}) Number size in bytes of file {fname}
257getftime({fname}) Number last modification time of file
258getftype({fname}) String description of type of file {fname}
259getimstatus() Number |TRUE| if the IME status is active
260getjumplist([{winnr} [, {tabnr}]])
261 List list of jump list items
262getline({lnum}) String line {lnum} of current buffer
263getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
264getloclist({nr}) List list of location list items
265getloclist({nr}, {what}) Dict get specific location list properties
266getmarklist([{buf}]) List list of global/local marks
267getmatches([{win}]) List list of current matches
268getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000269getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000270getpid() Number process ID of Vim
271getpos({expr}) List position of cursor, mark, etc.
272getqflist() List list of quickfix items
273getqflist({what}) Dict get specific quickfix list properties
274getreg([{regname} [, 1 [, {list}]]])
275 String or List contents of a register
276getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100277getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100278 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200279getregionpos({pos1}, {pos2} [, {opts}])
280 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000281getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100282getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100283getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284gettabinfo([{expr}]) List list of tab pages
285gettabvar({nr}, {varname} [, {def}])
286 any variable {varname} in tab {nr} or {def}
287gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
288 any {name} in {winnr} in tab page {tabnr}
289gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200290gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000292getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwinposx() Number X coord in pixels of the Vim window
294getwinposy() Number Y coord in pixels of the Vim window
295getwinvar({nr}, {varname} [, {def}])
296 any variable {varname} in window {nr}
297glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
298 any expand file wildcards in {expr}
299glob2regpat({expr}) String convert a glob pat into a search pat
300globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
301 String do glob({expr}) for all dirs in {path}
302has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
303has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
304haslocaldir([{winnr} [, {tabnr}]])
305 Number |TRUE| if the window executed |:lcd|
306 or |:tcd|
307hasmapto({what} [, {mode} [, {abbr}]])
308 Number |TRUE| if mapping to {what} exists
309histadd({history}, {item}) Number add an item to a history
310histdel({history} [, {item}]) Number remove an item from a history
311histget({history} [, {index}]) String get the item {index} from a history
312histnr({history}) Number highest index of a history
313hlID({name}) Number syntax ID of highlight group {name}
314hlexists({name}) Number |TRUE| if highlight group {name} exists
315hlget([{name} [, {resolve}]]) List get highlight group attributes
316hlset({list}) Number set highlight group attributes
317hostname() String name of the machine Vim is running on
318iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200319id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320indent({lnum}) Number indent of line {lnum}
321index({object}, {expr} [, {start} [, {ic}]])
322 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100323indexof({object}, {expr} [, {opts}]])
324 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000325input({prompt} [, {text} [, {completion}]])
326 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100327inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000328 String like input() but in a GUI dialog
329inputlist({textlist}) Number let the user pick from a choice list
330inputrestore() Number restore typeahead
331inputsave() Number save and clear typeahead
332inputsecret({prompt} [, {text}]) String like input() but hiding the text
333insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200334instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000335interrupt() none interrupt script execution
336invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100337isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000338isdirectory({directory}) Number |TRUE| if {directory} is a directory
339isinf({expr}) Number determine if {expr} is infinity value
340 (positive or negative)
341islocked({expr}) Number |TRUE| if {expr} is locked
342isnan({expr}) Number |TRUE| if {expr} is NaN
343items({dict}) List key-value pairs in {dict}
344job_getchannel({job}) Channel get the channel handle for {job}
345job_info([{job}]) Dict get information about {job}
346job_setoptions({job}, {options}) none set options for {job}
347job_start({command} [, {options}])
348 Job start a job
349job_status({job}) String get the status of {job}
350job_stop({job} [, {how}]) Number stop {job}
351join({list} [, {sep}]) String join {list} items into one String
352js_decode({string}) any decode JS style JSON
353js_encode({expr}) String encode JS style JSON
354json_decode({string}) any decode JSON
355json_encode({expr}) String encode JSON
356keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100357keytrans({string}) String translate internal keycodes to a form
358 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000359len({expr}) Number the length of {expr}
360libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
361libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
362line({expr} [, {winid}]) Number line nr of cursor, last line or mark
363line2byte({lnum}) Number byte count of line {lnum}
364lispindent({lnum}) Number Lisp indent for line {lnum}
365list2blob({list}) Blob turn {list} of numbers into a Blob
366list2str({list} [, {utf8}]) String turn {list} of numbers into a String
367listener_add({callback} [, {buf}])
368 Number add a callback to listen to changes
369listener_flush([{buf}]) none invoke listener callbacks
370listener_remove({id}) none remove a listener callback
371localtime() Number current time
372log({expr}) Float natural logarithm (base e) of {expr}
373log10({expr}) Float logarithm of Float {expr} to base 10
374luaeval({expr} [, {expr}]) any evaluate |Lua| expression
375map({expr1}, {expr2}) List/Dict/Blob/String
376 change each item in {expr1} to {expr2}
377maparg({name} [, {mode} [, {abbr} [, {dict}]]])
378 String or Dict
379 rhs of mapping {name} in mode {mode}
380mapcheck({name} [, {mode} [, {abbr}]])
381 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100382maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000383mapnew({expr1}, {expr2}) List/Dict/Blob/String
384 like |map()| but creates a new List or
385 Dictionary
386mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
387match({expr}, {pat} [, {start} [, {count}]])
388 Number position where {pat} matches in {expr}
389matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
390 Number highlight {pattern} with {group}
391matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
392 Number highlight positions with {group}
393matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100394matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
395 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000396matchdelete({id} [, {win}]) Number delete match identified by {id}
397matchend({expr}, {pat} [, {start} [, {count}]])
398 Number position where {pat} ends in {expr}
399matchfuzzy({list}, {str} [, {dict}])
400 List fuzzy match {str} in {list}
401matchfuzzypos({list}, {str} [, {dict}])
402 List fuzzy match {str} in {list}
403matchlist({expr}, {pat} [, {start} [, {count}]])
404 List match and submatches of {pat} in {expr}
405matchstr({expr}, {pat} [, {start} [, {count}]])
406 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100407matchstrlist({list}, {pat} [, {dict})
408 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000409matchstrpos({expr}, {pat} [, {start} [, {count}]])
410 List {count}'th match of {pat} in {expr}
411max({expr}) Number maximum value of items in {expr}
412menu_info({name} [, {mode}]) Dict get menu item information
413min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000414mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000415 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200416mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000417mzeval({expr}) any evaluate |MzScheme| expression
418nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
Christ van Willegenc0786752025-02-01 15:42:16 +0100419ngettext({single}, {plural}, {number}[, {domain}])
420 String translate text based on {number}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000421nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
422or({expr}, {expr}) Number bitwise OR
423pathshorten({expr} [, {len}]) String shorten directory names in a path
424perleval({expr}) any evaluate |Perl| expression
425popup_atcursor({what}, {options}) Number create popup window near the cursor
426popup_beval({what}, {options}) Number create popup window for 'ballooneval'
427popup_clear() none close all popup windows
428popup_close({id} [, {result}]) none close popup window {id}
429popup_create({what}, {options}) Number create a popup window
430popup_dialog({what}, {options}) Number create a popup window used as a dialog
431popup_filter_menu({id}, {key}) Number filter for a menu popup window
432popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100433popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000434popup_findinfo() Number get window ID of info popup window
435popup_findpreview() Number get window ID of preview popup window
436popup_getoptions({id}) Dict get options of popup window {id}
437popup_getpos({id}) Dict get position of popup window {id}
438popup_hide({id}) none hide popup menu {id}
439popup_list() List get a list of window IDs of all popups
440popup_locate({row}, {col}) Number get window ID of popup at position
441popup_menu({what}, {options}) Number create a popup window used as a menu
442popup_move({id}, {options}) none set position of popup window {id}
443popup_notification({what}, {options})
444 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200445popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000446popup_setoptions({id}, {options})
447 none set options for popup window {id}
448popup_settext({id}, {text}) none set the text of popup window {id}
449popup_show({id}) none unhide popup window {id}
450pow({x}, {y}) Float {x} to the power of {y}
451prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
452printf({fmt}, {expr1}...) String format text
453prompt_getprompt({buf}) String get prompt text
454prompt_setcallback({buf}, {expr}) none set prompt callback function
455prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
456prompt_setprompt({buf}, {text}) none set prompt text
457prop_add({lnum}, {col}, {props}) none add one text property
458prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
459 none add multiple text properties
460prop_clear({lnum} [, {lnum-end} [, {props}]])
461 none remove all text properties
462prop_find({props} [, {direction}])
463 Dict search for a text property
464prop_list({lnum} [, {props}]) List text properties in {lnum}
465prop_remove({props} [, {lnum} [, {lnum-end}]])
466 Number remove a text property
467prop_type_add({name}, {props}) none define a new property type
468prop_type_change({name}, {props})
469 none change an existing property type
470prop_type_delete({name} [, {props}])
471 none delete a property type
472prop_type_get({name} [, {props}])
473 Dict get property type values
474prop_type_list([{props}]) List get list of property types
475pum_getpos() Dict position and size of pum if visible
476pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100477py3eval({expr} [, {locals}]) any evaluate |python3| expression
478pyeval({expr} [, {locals}]) any evaluate |Python| expression
479pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000480rand([{expr}]) Number get pseudo-random number
481range({expr} [, {max} [, {stride}]])
482 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100483readblob({fname} [, {offset} [, {size}]])
484 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000485readdir({dir} [, {expr} [, {dict}]])
486 List file names in {dir} selected by {expr}
487readdirex({dir} [, {expr} [, {dict}]])
488 List file info in {dir} selected by {expr}
489readfile({fname} [, {type} [, {max}]])
490 List get list of lines from file {fname}
491reduce({object}, {func} [, {initial}])
492 any reduce {object} using {func}
493reg_executing() String get the executing register name
494reg_recording() String get the recording register name
495reltime([{start} [, {end}]]) List get time value
496reltimefloat({time}) Float turn the time value into a Float
497reltimestr({time}) String turn time value into a String
498remote_expr({server}, {string} [, {idvar} [, {timeout}]])
499 String send expression
500remote_foreground({server}) Number bring Vim server to the foreground
501remote_peek({serverid} [, {retvar}])
502 Number check for reply string
503remote_read({serverid} [, {timeout}])
504 String read reply string
505remote_send({server}, {string} [, {idvar}])
506 String send key sequence
507remote_startserver({name}) none become server {name}
508remove({list}, {idx} [, {end}]) any/List
509 remove items {idx}-{end} from {list}
510remove({blob}, {idx} [, {end}]) Number/Blob
511 remove bytes {idx}-{end} from {blob}
512remove({dict}, {key}) any remove entry {key} from {dict}
513rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100514repeat({expr}, {count}) List/Blob/String
515 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000516resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100517reverse({obj}) List/Blob/String
518 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000519round({expr}) Float round off {expr}
520rubyeval({expr}) any evaluate |Ruby| expression
521screenattr({row}, {col}) Number attribute at screen position
522screenchar({row}, {col}) Number character at screen position
523screenchars({row}, {col}) List List of characters at screen position
524screencol() Number current cursor column
525screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
526screenrow() Number current cursor row
527screenstring({row}, {col}) String characters at screen position
528search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
529 Number search for {pattern}
530searchcount([{options}]) Dict get or update search stats
531searchdecl({name} [, {global} [, {thisblock}]])
532 Number search for variable declaration
533searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
534 Number search for other end of start/end pair
535searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
536 List search for other end of start/end pair
537searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
538 List search for {pattern}
539server2client({clientid}, {string})
540 Number send reply string
541serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700542setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000543 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700544 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000545setbufvar({buf}, {varname}, {val})
546 none set {varname} in buffer {buf} to {val}
547setcellwidths({list}) none set character cell width overrides
548setcharpos({expr}, {list}) Number set the {expr} position to {list}
549setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100550setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000551setcmdpos({pos}) Number set cursor position in command-line
552setcursorcharpos({list}) Number move cursor to position in {list}
553setenv({name}, {val}) none set environment variable
554setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
555setline({lnum}, {line}) Number set line {lnum} to {line}
556setloclist({nr}, {list} [, {action}])
557 Number modify location list using {list}
558setloclist({nr}, {list}, {action}, {what})
559 Number modify specific location list props
560setmatches({list} [, {win}]) Number restore a list of matches
561setpos({expr}, {list}) Number set the {expr} position to {list}
562setqflist({list} [, {action}]) Number modify quickfix list using {list}
563setqflist({list}, {action}, {what})
564 Number modify specific quickfix list props
565setreg({n}, {v} [, {opt}]) Number set register to value and type
566settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
567settabwinvar({tabnr}, {winnr}, {varname}, {val})
568 none set {varname} in window {winnr} in tab
569 page {tabnr} to {val}
570settagstack({nr}, {dict} [, {action}])
571 Number modify tag stack using {dict}
572setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
573sha256({string}) String SHA256 checksum of {string}
574shellescape({string} [, {special}])
575 String escape {string} for use as shell
576 command argument
577shiftwidth([{col}]) Number effective value of 'shiftwidth'
578sign_define({name} [, {dict}]) Number define or update a sign
579sign_define({list}) List define or update a list of signs
580sign_getdefined([{name}]) List get a list of defined signs
581sign_getplaced([{buf} [, {dict}]])
582 List get a list of placed signs
583sign_jump({id}, {group}, {buf})
584 Number jump to a sign
585sign_place({id}, {group}, {name}, {buf} [, {dict}])
586 Number place a sign
587sign_placelist({list}) List place a list of signs
588sign_undefine([{name}]) Number undefine a sign
589sign_undefine({list}) List undefine a list of signs
590sign_unplace({group} [, {dict}])
591 Number unplace a sign
592sign_unplacelist({list}) List unplace a list of signs
593simplify({filename}) String simplify filename as much as possible
594sin({expr}) Float sine of {expr}
595sinh({expr}) Float hyperbolic sine of {expr}
596slice({expr}, {start} [, {end}]) String, List or Blob
597 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000598sort({list} [, {how} [, {dict}]])
599 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000600sound_clear() none stop playing all sounds
601sound_playevent({name} [, {callback}])
602 Number play an event sound
603sound_playfile({path} [, {callback}])
604 Number play sound file {path}
605sound_stop({id}) none stop playing sound {id}
606soundfold({word}) String sound-fold {word}
607spellbadword() String badly spelled word at cursor
608spellsuggest({word} [, {max} [, {capital}]])
609 List spelling suggestions
610split({expr} [, {pat} [, {keepempty}]])
611 List make |List| from {pat} separated {expr}
612sqrt({expr}) Float square root of {expr}
613srand([{expr}]) List get seed for |rand()|
614state([{what}]) String current state of Vim
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100615str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000616str2float({expr} [, {quoted}]) Float convert String to Float
617str2list({expr} [, {utf8}]) List convert each character of {expr} to
618 ASCII/UTF-8 value
619str2nr({expr} [, {base} [, {quoted}]])
620 Number convert String to Number
621strcharlen({expr}) Number character length of the String {expr}
622strcharpart({str}, {start} [, {len} [, {skipcc}]])
623 String {len} characters of {str} at
624 character {start}
625strchars({expr} [, {skipcc}]) Number character count of the String {expr}
626strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
627strftime({format} [, {time}]) String format time with a specified format
628strgetchar({str}, {index}) Number get char {index} from {str}
629stridx({haystack}, {needle} [, {start}])
630 Number index of {needle} in {haystack}
631string({expr}) String String representation of {expr} value
632strlen({expr}) Number length of the String {expr}
633strpart({str}, {start} [, {len} [, {chars}]])
634 String {len} bytes/chars of {str} at
635 byte {start}
636strptime({format}, {timestring})
637 Number Convert {timestring} to unix timestamp
638strridx({haystack}, {needle} [, {start}])
639 Number last index of {needle} in {haystack}
640strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100641strutf16len({string} [, {countcc}])
642 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000643strwidth({expr}) Number display cell length of the String {expr}
644submatch({nr} [, {list}]) String or List
645 specific match in ":s" or substitute()
646substitute({expr}, {pat}, {sub}, {flags})
647 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000648swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000649swapinfo({fname}) Dict information about swap file {fname}
650swapname({buf}) String swap file of buffer {buf}
651synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
652synIDattr({synID}, {what} [, {mode}])
653 String attribute {what} of syntax ID {synID}
654synIDtrans({synID}) Number translated syntax ID of {synID}
655synconcealed({lnum}, {col}) List info about concealing
656synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
657system({expr} [, {input}]) String output of shell command/filter {expr}
658systemlist({expr} [, {input}]) List output of shell command/filter {expr}
659tabpagebuflist([{arg}]) List list of buffer numbers in tab page
660tabpagenr([{arg}]) Number number of current or last tab page
661tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
662tagfiles() List tags files used
663taglist({expr} [, {filename}]) List list of tags matching {expr}
664tan({expr}) Float tangent of {expr}
665tanh({expr}) Float hyperbolic tangent of {expr}
666tempname() String name for a temporary file
667term_dumpdiff({filename}, {filename} [, {options}])
668 Number display difference between two dumps
669term_dumpload({filename} [, {options}])
670 Number displaying a screen dump
671term_dumpwrite({buf}, {filename} [, {options}])
672 none dump terminal window contents
673term_getaltscreen({buf}) Number get the alternate screen flag
674term_getansicolors({buf}) List get ANSI palette in GUI color mode
675term_getattr({attr}, {what}) Number get the value of attribute {what}
676term_getcursor({buf}) List get the cursor position of a terminal
677term_getjob({buf}) Job get the job associated with a terminal
678term_getline({buf}, {row}) String get a line of text from a terminal
679term_getscrolled({buf}) Number get the scroll count of a terminal
680term_getsize({buf}) List get the size of a terminal
681term_getstatus({buf}) String get the status of a terminal
682term_gettitle({buf}) String get the title of a terminal
683term_gettty({buf}, [{input}]) String get the tty name of a terminal
684term_list() List get the list of terminal buffers
685term_scrape({buf}, {row}) List get row of a terminal screen
686term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
687term_setansicolors({buf}, {colors})
688 none set ANSI palette in GUI color mode
689term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
690term_setkill({buf}, {how}) none set signal to stop job in terminal
691term_setrestore({buf}, {command}) none set command to restore terminal
692term_setsize({buf}, {rows}, {cols})
693 none set the size of a terminal
694term_start({cmd} [, {options}]) Number open a terminal window and run a job
695term_wait({buf} [, {time}]) Number wait for screen to be updated
696terminalprops() Dict properties of the terminal
697test_alloc_fail({id}, {countdown}, {repeat})
698 none make memory allocation fail
699test_autochdir() none enable 'autochdir' during startup
700test_feedinput({string}) none add key sequence to input buffer
701test_garbagecollect_now() none free memory right now for testing
702test_garbagecollect_soon() none free memory soon for testing
703test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000704test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000705test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000706test_mswin_event({event}, {args})
707 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000708test_null_blob() Blob null value for testing
709test_null_channel() Channel null value for testing
710test_null_dict() Dict null value for testing
711test_null_function() Funcref null value for testing
712test_null_job() Job null value for testing
713test_null_list() List null value for testing
714test_null_partial() Funcref null value for testing
715test_null_string() String null value for testing
716test_option_not_set({name}) none reset flag indicating option was set
717test_override({expr}, {val}) none test with Vim internal overrides
718test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000719test_setmouse({row}, {col}) none set the mouse position for testing
720test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200721test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000722test_unknown() any unknown value for testing
723test_void() any void value for testing
724timer_info([{id}]) List information about timers
725timer_pause({id}, {pause}) none pause or unpause a timer
726timer_start({time}, {callback} [, {options}])
727 Number create a timer
728timer_stop({timer}) none stop a timer
729timer_stopall() none stop all timers
730tolower({expr}) String the String {expr} switched to lowercase
731toupper({expr}) String the String {expr} switched to uppercase
732tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
733 to chars in {tostr}
734trim({text} [, {mask} [, {dir}]])
735 String trim characters in {mask} from {text}
736trunc({expr}) Float truncate Float {expr}
737type({expr}) Number type of value {expr}
738typename({expr}) String representation of the type of {expr}
739undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500740undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000741uniq({list} [, {func} [, {dict}]])
742 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100743utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
744 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000745values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200746virtcol({expr} [, {list} [, {winid}])
747 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100748 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100749virtcol2col({winid}, {lnum}, {col})
750 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200751visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000752wildmenumode() Number whether 'wildmenu' mode is active
753win_execute({id}, {command} [, {silent}])
754 String execute {command} in window {id}
755win_findbuf({bufnr}) List find windows containing {bufnr}
756win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
757win_gettype([{nr}]) String type of window {nr}
758win_gotoid({expr}) Number go to window with ID {expr}
759win_id2tabwin({expr}) List get tab and window nr from window ID
760win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000761win_move_separator({nr}) Number move window vertical separator
762win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000763win_screenpos({nr}) List get screen position of window {nr}
764win_splitmove({nr}, {target} [, {options}])
765 Number move window {nr} to split of {target}
766winbufnr({nr}) Number buffer number of window {nr}
767wincol() Number window column of the cursor
768windowsversion() String MS-Windows OS version
769winheight({nr}) Number height of window {nr}
770winlayout([{tabnr}]) List layout of windows in tab {tabnr}
771winline() Number window line of the cursor
772winnr([{expr}]) Number number of current window
773winrestcmd() String returns command to restore window sizes
774winrestview({dict}) none restore view of current window
775winsaveview() Dict save view of current window
776winwidth({nr}) Number width of window {nr}
777wordcount() Dict get byte/char/word statistics
778writefile({object}, {fname} [, {flags}])
779 Number write |Blob| or |List| of lines to file
780xor({expr}, {expr}) Number bitwise XOR
781
782==============================================================================
7832. Details *builtin-function-details*
784
785Not all functions are here, some have been moved to a help file covering the
786specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200787Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000788
789abs({expr}) *abs()*
790 Return the absolute value of {expr}. When {expr} evaluates to
791 a |Float| abs() returns a |Float|. When {expr} can be
792 converted to a |Number| abs() returns a |Number|. Otherwise
793 abs() gives an error message and returns -1.
794 Examples: >
795 echo abs(1.456)
796< 1.456 >
797 echo abs(-5.456)
798< 5.456 >
799 echo abs(-4)
800< 4
801
802 Can also be used as a |method|: >
803 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200804<
805 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000807
808acos({expr}) *acos()*
809 Return the arc cosine of {expr} measured in radians, as a
810 |Float| in the range of [0, pi].
811 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100812 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000813 Examples: >
814 :echo acos(0)
815< 1.570796 >
816 :echo acos(-0.5)
817< 2.094395
818
819 Can also be used as a |method|: >
820 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200821<
822 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000824
825add({object}, {expr}) *add()*
826 Append the item {expr} to |List| or |Blob| {object}. Returns
827 the resulting |List| or |Blob|. Examples: >
828 :let alist = add([1, 2, 3], item)
829 :call add(mylist, "woodstock")
830< Note that when {expr} is a |List| it is appended as a single
831 item. Use |extend()| to concatenate |Lists|.
832 When {object} is a |Blob| then {expr} must be a number.
833 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100834 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000835
836 Can also be used as a |method|: >
837 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200838<
839 Return type: list<{type}> (depending on the given |List|) or
840 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000841
842
843and({expr}, {expr}) *and()*
844 Bitwise AND on the two arguments. The arguments are converted
845 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100846 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000847 Example: >
848 :let flag = and(bits, 0x80)
849< Can also be used as a |method|: >
850 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200851<
852 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000853
854
855append({lnum}, {text}) *append()*
856 When {text} is a |List|: Append each item of the |List| as a
857 text line below line {lnum} in the current buffer.
858 Otherwise append {text} as one text line below line {lnum} in
859 the current buffer.
860 Any type of item is accepted and converted to a String.
861 {lnum} can be zero to insert a line before the first one.
862 {lnum} is used like with |getline()|.
863 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000864 0 for success. When {text} is an empty list zero is returned,
865 no matter the value of {lnum}.
866 In |Vim9| script an invalid argument or negative number
867 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000868 :let failed = append(line('$'), "# THE END")
869 :let failed = append(0, ["Chapter 1", "the beginning"])
870
871< Can also be used as a |method| after a List, the base is
872 passed as the second argument: >
873 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200874<
875 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000876
877
878appendbufline({buf}, {lnum}, {text}) *appendbufline()*
879 Like |append()| but append the text in buffer {buf}.
880
881 This function works only for loaded buffers. First call
882 |bufload()| if needed.
883
884 For the use of {buf}, see |bufname()|.
885
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000886 {lnum} is the line number to append below. Note that using
887 |line()| would use the current buffer, not the one appending
888 to. Use "$" to append at the end of the buffer. Other string
889 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000890
891 On success 0 is returned, on failure 1 is returned.
892 In |Vim9| script an error is given for an invalid {lnum}.
893
894 If {buf} is not a valid buffer or {lnum} is not valid, an
895 error message is given. Example: >
896 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000897< However, when {text} is an empty list then no error is given
898 for an invalid {lnum}, since {lnum} isn't actually used.
899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000900 Can also be used as a |method| after a List, the base is
901 passed as the second argument: >
902 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200903<
904 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000905
906
907argc([{winid}]) *argc()*
908 The result is the number of files in the argument list. See
909 |arglist|.
910 If {winid} is not supplied, the argument list of the current
911 window is used.
912 If {winid} is -1, the global argument list is used.
913 Otherwise {winid} specifies the window of which the argument
914 list is used: either the window number or the window ID.
915 Returns -1 if the {winid} argument is invalid.
916
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200917 Return type: |Number|
918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000919 *argidx()*
920argidx() The result is the current index in the argument list. 0 is
921 the first file. argc() - 1 is the last one. See |arglist|.
922
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200923 Return type: |Number|
924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000925 *arglistid()*
926arglistid([{winnr} [, {tabnr}]])
927 Return the argument list ID. This is a number which
928 identifies the argument list being used. Zero is used for the
929 global argument list. See |arglist|.
930 Returns -1 if the arguments are invalid.
931
932 Without arguments use the current window.
933 With {winnr} only use this window in the current tab page.
934 With {winnr} and {tabnr} use the window in the specified tab
935 page.
936 {winnr} can be the window number or the |window-ID|.
937
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200938 Return type: |Number|
939
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000940 *argv()*
941argv([{nr} [, {winid}]])
942 The result is the {nr}th file in the argument list. See
943 |arglist|. "argv(0)" is the first one. Example: >
944 :let i = 0
945 :while i < argc()
946 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000947 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000948 : let i = i + 1
949 :endwhile
950< Without the {nr} argument, or when {nr} is -1, a |List| with
951 the whole |arglist| is returned.
952
953 The {winid} argument specifies the window ID, see |argc()|.
954 For the Vim command line arguments see |v:argv|.
955
Bram Moolenaar016188f2022-06-06 20:52:59 +0100956 Returns an empty string if {nr}th argument is not present in
957 the argument list. Returns an empty List if the {winid}
958 argument is invalid.
959
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200960 Return type: |String|
961
962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000963asin({expr}) *asin()*
964 Return the arc sine of {expr} measured in radians, as a |Float|
965 in the range of [-pi/2, pi/2].
966 {expr} must evaluate to a |Float| or a |Number| in the range
967 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100968 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
969 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000970 Examples: >
971 :echo asin(0.8)
972< 0.927295 >
973 :echo asin(-0.5)
974< -0.523599
975
976 Can also be used as a |method|: >
977 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200978<
979 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000980
981assert_ functions are documented here: |assert-functions-details|
982
983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000984atan({expr}) *atan()*
985 Return the principal value of the arc tangent of {expr}, in
986 the range [-pi/2, +pi/2] radians, as a |Float|.
987 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100988 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000989 Examples: >
990 :echo atan(100)
991< 1.560797 >
992 :echo atan(-4.01)
993< -1.326405
994
995 Can also be used as a |method|: >
996 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200997<
998 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000999
1000
1001atan2({expr1}, {expr2}) *atan2()*
1002 Return the arc tangent of {expr1} / {expr2}, measured in
1003 radians, as a |Float| in the range [-pi, pi].
1004 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001005 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1006 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001007 Examples: >
1008 :echo atan2(-1, 1)
1009< -0.785398 >
1010 :echo atan2(1, -1)
1011< 2.356194
1012
1013 Can also be used as a |method|: >
1014 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001015<
1016 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001017
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001018
1019autocmd_add({acmds}) *autocmd_add()*
1020 Adds a List of autocmds and autocmd groups.
1021
1022 The {acmds} argument is a List where each item is a Dict with
1023 the following optional items:
1024 bufnr buffer number to add a buffer-local autocmd.
1025 If this item is specified, then the "pattern"
1026 item is ignored.
1027 cmd Ex command to execute for this autocmd event
1028 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001029 This can be either a String with a single
1030 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001031 group autocmd group name. Refer to |autocmd-groups|.
1032 If this group doesn't exist then it is
1033 created. If not specified or empty, then the
1034 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001035 nested boolean flag, set to v:true to add a nested
1036 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001037 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001038 which executes only once. Refer to
1039 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001040 pattern autocmd pattern string. Refer to
1041 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001042 present, then this item is ignored. This can
1043 be a String with a single pattern or a List of
1044 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001045 replace boolean flag, set to v:true to remove all the
1046 commands associated with the specified autocmd
1047 event and group and add the {cmd}. This is
1048 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001049 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001050
1051 Returns v:true on success and v:false on failure.
1052 Examples: >
1053 " Create a buffer-local autocmd for buffer 5
1054 let acmd = {}
1055 let acmd.group = 'MyGroup'
1056 let acmd.event = 'BufEnter'
1057 let acmd.bufnr = 5
1058 let acmd.cmd = 'call BufEnterFunc()'
1059 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001060<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001061 Can also be used as a |method|: >
1062 GetAutocmdList()->autocmd_add()
1063<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001064 Return type: |vim9-boolean|
1065
1066
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001067autocmd_delete({acmds}) *autocmd_delete()*
1068 Deletes a List of autocmds and autocmd groups.
1069
1070 The {acmds} argument is a List where each item is a Dict with
1071 the following optional items:
1072 bufnr buffer number to delete a buffer-local autocmd.
1073 If this item is specified, then the "pattern"
1074 item is ignored.
1075 cmd Ex command for this autocmd event
1076 event autocmd event name. Refer to |autocmd-events|.
1077 If '*' then all the autocmd events in this
1078 group are deleted.
1079 group autocmd group name. Refer to |autocmd-groups|.
1080 If not specified or empty, then the default
1081 group is used.
1082 nested set to v:true for a nested autocmd.
1083 Refer to |autocmd-nested|.
1084 once set to v:true for an autocmd which executes
1085 only once. Refer to |autocmd-once|.
1086 pattern autocmd pattern string. Refer to
1087 |autocmd-patterns|. If "bufnr" item is
1088 present, then this item is ignored.
1089
1090 If only {group} is specified in a {acmds} entry and {event},
1091 {pattern} and {cmd} are not specified, then that autocmd group
1092 is deleted.
1093
Bram Moolenaar016188f2022-06-06 20:52:59 +01001094 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001095 Examples: >
1096 " :autocmd! BufLeave *.vim
1097 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1098 call autocmd_delete([acmd]})
1099 " :autocmd! MyGroup1 BufLeave
1100 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1101 call autocmd_delete([acmd])
1102 " :autocmd! MyGroup2 BufEnter *.c
1103 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1104 \ pattern: '*.c'}
1105 " :autocmd! MyGroup2 * *.c
1106 let acmd = #{group: 'MyGroup2', event: '*',
1107 \ pattern: '*.c'}
1108 call autocmd_delete([acmd])
1109 " :autocmd! MyGroup3
1110 let acmd = #{group: 'MyGroup3'}
1111 call autocmd_delete([acmd])
1112<
1113 Can also be used as a |method|: >
1114 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001115<
1116 Return type: |vim9-boolean|
1117
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001118
1119autocmd_get([{opts}]) *autocmd_get()*
1120 Returns a |List| of autocmds. If {opts} is not supplied, then
1121 returns the autocmds for all the events in all the groups.
1122
1123 The optional {opts} Dict argument supports the following
1124 items:
1125 group Autocmd group name. If specified, returns only
1126 the autocmds defined in this group. If the
1127 specified group doesn't exist, results in an
1128 error message. If set to an empty string,
1129 then the default autocmd group is used.
1130 event Autocmd event name. If specified, returns only
1131 the autocmds defined for this event. If set
1132 to "*", then returns autocmds for all the
1133 events. If the specified event doesn't exist,
1134 results in an error message.
1135 pattern Autocmd pattern. If specified, returns only
1136 the autocmds defined for this pattern.
1137 A combination of the above three times can be supplied in
1138 {opts}.
1139
1140 Each Dict in the returned List contains the following items:
1141 bufnr For buffer-local autocmds, buffer number where
1142 the autocmd is defined.
1143 cmd Command executed for this autocmd.
1144 event Autocmd event name.
1145 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001146 nested Boolean flag, set to v:true for a nested
1147 autocmd. See |autocmd-nested|.
1148 once Boolean flag, set to v:true, if the autocmd
1149 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001150 pattern Autocmd pattern. For a buffer-local
1151 autocmd, this will be of the form "<buffer=n>".
1152 If there are multiple commands for an autocmd event in a
1153 group, then separate items are returned for each command.
1154
Bram Moolenaar016188f2022-06-06 20:52:59 +01001155 Returns an empty List if an autocmd with the specified group
1156 or event or pattern is not found.
1157
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001158 Examples: >
1159 " :autocmd MyGroup
1160 echo autocmd_get(#{group: 'Mygroup'})
1161 " :autocmd G BufUnload
1162 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1163 " :autocmd G * *.ts
1164 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1165 echo autocmd_get(acmd)
1166 " :autocmd Syntax
1167 echo autocmd_get(#{event: 'Syntax'})
1168 " :autocmd G BufEnter *.ts
1169 let acmd = #{group: 'G', event: 'BufEnter',
1170 \ pattern: '*.ts'}
1171 echo autocmd_get(acmd)
1172<
1173 Can also be used as a |method|: >
1174 Getopts()->autocmd_get()
1175<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001176 Return type: list<dict<any>>
1177
1178
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001179balloon_gettext() *balloon_gettext()*
1180 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001181 not used for the List. Returns an empty string if balloon
1182 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001183
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001184 Return type: |String|
1185
1186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001187balloon_show({expr}) *balloon_show()*
1188 Show {expr} inside the balloon. For the GUI {expr} is used as
1189 a string. For a terminal {expr} can be a list, which contains
1190 the lines of the balloon. If {expr} is not a list it will be
1191 split with |balloon_split()|.
1192 If {expr} is an empty string any existing balloon is removed.
1193
1194 Example: >
1195 func GetBalloonContent()
1196 " ... initiate getting the content
1197 return ''
1198 endfunc
1199 set balloonexpr=GetBalloonContent()
1200
1201 func BalloonCallback(result)
1202 call balloon_show(a:result)
1203 endfunc
1204< Can also be used as a |method|: >
1205 GetText()->balloon_show()
1206<
1207 The intended use is that fetching the content of the balloon
1208 is initiated from 'balloonexpr'. It will invoke an
1209 asynchronous method, in which a callback invokes
1210 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001211 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001212
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001213 When showing a balloon is not possible then nothing happens,
1214 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001215 {only available when compiled with the |+balloon_eval| or
1216 |+balloon_eval_term| feature}
1217
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001218 Return type: |Number|
1219
1220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001221balloon_split({msg}) *balloon_split()*
1222 Split String {msg} into lines to be displayed in a balloon.
1223 The splits are made for the current window size and optimize
1224 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001225 Returns a |List| with the split lines. Returns an empty List
1226 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001227 Can also be used as a |method|: >
1228 GetText()->balloon_split()->balloon_show()
1229
1230< {only available when compiled with the |+balloon_eval_term|
1231 feature}
1232
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001233 Return type: list<any> or list<string>
1234
h-easte80f3452025-01-02 10:40:29 +01001235base64_decode({string}) *base64_decode()*
1236 Return a Blob containing the bytes decoded from the base64
1237 encoded characters in {string}.
1238
1239 The {string} argument should contain only base64-encoded
1240 characters and should have a length that is a multiple of 4.
1241
1242 Returns an empty blob on error.
1243
1244 Examples: >
1245 " Write the decoded contents to a binary file
1246 call writefile(base64_decode(s), 'tools.bmp')
1247 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001248 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001249<
1250 Can also be used as a |method|: >
1251 GetEncodedString()->base64_decode()
1252<
1253 Return type: |Blob|
1254
1255
1256base64_encode({blob}) *base64_encode()*
1257 Return a base64-encoded String representing the bytes in
1258 {blob}. The base64 alphabet defined in RFC 4648 is used.
1259
1260 Examples: >
1261 " Encode the contents of a binary file
1262 echo base64_encode(readblob('somefile.bin'))
1263 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001264 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001265<
1266 Can also be used as a |method|: >
1267 GetBinaryData()->base64_encode()
1268<
1269 Return type: |String|
1270
1271
Christ van Willegence0ef912024-06-20 23:41:59 +02001272bindtextdomain({package}, {path}) *bindtextdomain()*
1273 Bind a specific {package} to a {path} so that the
1274 |gettext()| function can be used to get language-specific
1275 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001276 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001277
Christ van Willegen8252ef12024-07-11 21:36:21 +02001278 Returns v:true on success and v:false on failure (out of
1279 memory).
1280
1281 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001283blob2list({blob}) *blob2list()*
1284 Return a List containing the number value of each byte in Blob
1285 {blob}. Examples: >
1286 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1287 blob2list(0z) returns []
1288< Returns an empty List on error. |list2blob()| does the
1289 opposite.
1290
1291 Can also be used as a |method|: >
1292 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001293<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001294 Return type: list<any> or list<number>
1295
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001296
1297blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001298 Return a List of Strings in the current 'encoding' by
1299 converting the bytes in {blob} into characters.
1300
1301 Each <NL> byte in the blob is interpreted as the end of a
1302 string and a new list item is added. Each <NUL> byte in the
1303 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001304
1305 If {options} is not supplied, the current 'encoding' value is
1306 used to decode the bytes in {blob}.
1307
1308 The argument {options} is a |Dict| and supports the following
1309 items:
1310 encoding Decode the bytes in {blob} using this
1311 encoding. The value is a |String|. See
1312 |encoding-names| for the supported values.
1313 *E1515*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001314 An error is given and an empty List is returned if
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001315 an invalid byte sequence is encountered in {blob},
1316
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001317 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001318
1319 See also |str2blob()|
1320
1321 Examples: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001322 blob2str(0z6162) returns ["ab"]
1323 blob2str(0zC2ABC2BB) returns ["«»"]
1324 blob2str(0zABBB, {'encoding': 'latin1'}) returns ["«»"]
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001325<
1326 Can also be used as a |method|: >
1327 GetBlob()->blob2str()
1328<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001329 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001330
1331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001332 *browse()*
1333browse({save}, {title}, {initdir}, {default})
1334 Put up a file requester. This only works when "has("browse")"
1335 returns |TRUE| (only in some GUI versions).
1336 The input fields are:
1337 {save} when |TRUE|, select file to write
1338 {title} title for the requester
1339 {initdir} directory to start browsing in
1340 {default} default file name
1341 An empty string is returned when the "Cancel" button is hit,
1342 something went wrong, or browsing is not possible.
1343
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001344 Return type: |String|
1345
1346
1347browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001348 Put up a directory requester. This only works when
1349 "has("browse")" returns |TRUE| (only in some GUI versions).
1350 On systems where a directory browser is not supported a file
1351 browser is used. In that case: select a file in the directory
1352 to be used.
1353 The input fields are:
1354 {title} title for the requester
1355 {initdir} directory to start browsing in
1356 When the "Cancel" button is hit, something went wrong, or
1357 browsing is not possible, an empty string is returned.
1358
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001359 Return type: |String|
1360
1361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001362bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001363 Add a buffer to the buffer list with name {name} (must be a
1364 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001365 If a buffer for file {name} already exists, return that buffer
1366 number. Otherwise return the buffer number of the newly
1367 created buffer. When {name} is an empty string then a new
1368 buffer is always created.
1369 The buffer will not have 'buflisted' set and not be loaded
1370 yet. To add some text to the buffer use this: >
1371 let bufnr = bufadd('someName')
1372 call bufload(bufnr)
1373 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001374< Returns 0 on error.
1375 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001376 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001377<
1378 Return type: |Number|
1379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001380
1381bufexists({buf}) *bufexists()*
1382 The result is a Number, which is |TRUE| if a buffer called
1383 {buf} exists.
1384 If the {buf} argument is a number, buffer numbers are used.
1385 Number zero is the alternate buffer for the current window.
1386
1387 If the {buf} argument is a string it must match a buffer name
1388 exactly. The name can be:
1389 - Relative to the current directory.
1390 - A full path.
1391 - The name of a buffer with 'buftype' set to "nofile".
1392 - A URL name.
1393 Unlisted buffers will be found.
1394 Note that help files are listed by their short name in the
1395 output of |:buffers|, but bufexists() requires using their
1396 long name to be able to find them.
1397 bufexists() may report a buffer exists, but to use the name
1398 with a |:buffer| command you may need to use |expand()|. Esp
1399 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1400 Use "bufexists(0)" to test for the existence of an alternate
1401 file name.
1402
1403 Can also be used as a |method|: >
1404 let exists = 'somename'->bufexists()
1405<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001406 Return type: |Number|
1407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001408 Obsolete name: buffer_exists(). *buffer_exists()*
1409
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001411buflisted({buf}) *buflisted()*
1412 The result is a Number, which is |TRUE| if a buffer called
1413 {buf} exists and is listed (has the 'buflisted' option set).
1414 The {buf} argument is used like with |bufexists()|.
1415
1416 Can also be used as a |method|: >
1417 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001418<
1419 Return type: |Number|
1420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001421
1422bufload({buf}) *bufload()*
1423 Ensure the buffer {buf} is loaded. When the buffer name
1424 refers to an existing file then the file is read. Otherwise
1425 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001426 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001427 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001428 If there is an existing swap file for the file of the buffer,
1429 there will be no dialog, the buffer will be loaded anyway.
1430 The {buf} argument is used like with |bufexists()|.
1431
1432 Can also be used as a |method|: >
1433 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001434<
1435 Return type: |Number|
1436
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001437
1438bufloaded({buf}) *bufloaded()*
1439 The result is a Number, which is |TRUE| if a buffer called
1440 {buf} exists and is loaded (shown in a window or hidden).
1441 The {buf} argument is used like with |bufexists()|.
1442
1443 Can also be used as a |method|: >
1444 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001445<
1446 Return type: |Number|
1447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001448
1449bufname([{buf}]) *bufname()*
1450 The result is the name of a buffer. Mostly as it is displayed
1451 by the `:ls` command, but not using special names such as
1452 "[No Name]".
1453 If {buf} is omitted the current buffer is used.
1454 If {buf} is a Number, that buffer number's name is given.
1455 Number zero is the alternate buffer for the current window.
1456 If {buf} is a String, it is used as a |file-pattern| to match
1457 with the buffer names. This is always done like 'magic' is
1458 set and 'cpoptions' is empty. When there is more than one
1459 match an empty string is returned.
1460 "" or "%" can be used for the current buffer, "#" for the
1461 alternate buffer.
1462 A full match is preferred, otherwise a match at the start, end
1463 or middle of the buffer name is accepted. If you only want a
1464 full match then put "^" at the start and "$" at the end of the
1465 pattern.
1466 Listed buffers are found first. If there is a single match
1467 with a listed buffer, that one is returned. Next unlisted
1468 buffers are searched for.
1469 If the {buf} is a String, but you want to use it as a buffer
1470 number, force it to be a Number by adding zero to it: >
1471 :echo bufname("3" + 0)
1472< Can also be used as a |method|: >
1473 echo bufnr->bufname()
1474
1475< If the buffer doesn't exist, or doesn't have a name, an empty
1476 string is returned. >
1477 bufname("#") alternate buffer name
1478 bufname(3) name of buffer 3
1479 bufname("%") name of current buffer
1480 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001481<
1482 Return type: |String|
1483 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001484 Obsolete name: buffer_name().
1485
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001486
1487bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001488 The result is the number of a buffer, as it is displayed by
1489 the `:ls` command. For the use of {buf}, see |bufname()|
1490 above.
1491
1492 If the buffer doesn't exist, -1 is returned. Or, if the
1493 {create} argument is present and TRUE, a new, unlisted,
1494 buffer is created and its number is returned. Example: >
1495 let newbuf = bufnr('Scratch001', 1)
1496< Using an empty name uses the current buffer. To create a new
1497 buffer with an empty name use |bufadd()|.
1498
1499 bufnr("$") is the last buffer: >
1500 :let last_buffer = bufnr("$")
1501< The result is a Number, which is the highest buffer number
1502 of existing buffers. Note that not all buffers with a smaller
1503 number necessarily exist, because ":bwipeout" may have removed
1504 them. Use bufexists() to test for the existence of a buffer.
1505
1506 Can also be used as a |method|: >
1507 echo bufref->bufnr()
1508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001509 Return type: |Number|
1510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001511 Obsolete name: buffer_number(). *buffer_number()*
1512 *last_buffer_nr()*
1513 Obsolete name for bufnr("$"): last_buffer_nr().
1514
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001516bufwinid({buf}) *bufwinid()*
1517 The result is a Number, which is the |window-ID| of the first
1518 window associated with buffer {buf}. For the use of {buf},
1519 see |bufname()| above. If buffer {buf} doesn't exist or
1520 there is no such window, -1 is returned. Example: >
1521
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001522 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001523<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001524 Only deals with the current tab page. See |win_findbuf()| for
1525 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001526
1527 Can also be used as a |method|: >
1528 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001529<
1530 Return type: |Number|
1531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001532
1533bufwinnr({buf}) *bufwinnr()*
1534 Like |bufwinid()| but return the window number instead of the
1535 |window-ID|.
1536 If buffer {buf} doesn't exist or there is no such window, -1
1537 is returned. Example: >
1538
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001539 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001540
1541< The number can be used with |CTRL-W_w| and ":wincmd w"
1542 |:wincmd|.
1543
1544 Can also be used as a |method|: >
1545 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001546<
1547 Return type: |Number|
1548
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001549
1550byte2line({byte}) *byte2line()*
1551 Return the line number that contains the character at byte
1552 count {byte} in the current buffer. This includes the
1553 end-of-line character, depending on the 'fileformat' option
1554 for the current buffer. The first character has byte count
1555 one.
1556 Also see |line2byte()|, |go| and |:goto|.
1557
Bram Moolenaar016188f2022-06-06 20:52:59 +01001558 Returns -1 if the {byte} value is invalid.
1559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001560 Can also be used as a |method|: >
1561 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001562<
1563 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001564
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001565 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001566 feature}
1567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001568
Christian Brabandt67672ef2023-04-24 21:09:54 +01001569byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001570 Return byte index of the {nr}'th character in the String
1571 {expr}. Use zero for the first character, it then returns
1572 zero.
1573 If there are no multibyte characters the returned value is
1574 equal to {nr}.
1575 Composing characters are not counted separately, their byte
1576 length is added to the preceding base character. See
1577 |byteidxcomp()| below for counting composing characters
1578 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001579 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1580 index in the String {expr} instead of as the character index.
1581 The UTF-16 index is the index in the string when it is encoded
1582 with 16-bit words. If the specified UTF-16 index is in the
1583 middle of a character (e.g. in a 4-byte character), then the
1584 byte index of the first byte in the character is returned.
1585 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001586 Example : >
1587 echo matchstr(str, ".", byteidx(str, 3))
1588< will display the fourth character. Another way to do the
1589 same: >
1590 let s = strpart(str, byteidx(str, 3))
1591 echo strpart(s, 0, byteidx(s, 1))
1592< Also see |strgetchar()| and |strcharpart()|.
1593
1594 If there are less than {nr} characters -1 is returned.
1595 If there are exactly {nr} characters the length of the string
1596 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001597 See |charidx()| and |utf16idx()| for getting the character and
1598 UTF-16 index respectively from the byte index.
1599 Examples: >
1600 echo byteidx('a😊😊', 2) returns 5
1601 echo byteidx('a😊😊', 2, 1) returns 1
1602 echo byteidx('a😊😊', 3, 1) returns 5
1603<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001604 Can also be used as a |method|: >
1605 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001606<
1607 Return type: |Number|
1608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001609
Christian Brabandt67672ef2023-04-24 21:09:54 +01001610byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001611 Like byteidx(), except that a composing character is counted
1612 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001613 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001614 echo byteidx(s, 1)
1615 echo byteidxcomp(s, 1)
1616 echo byteidxcomp(s, 2)
1617< The first and third echo result in 3 ('e' plus composing
1618 character is 3 bytes), the second echo results in 1 ('e' is
1619 one byte).
1620 Only works differently from byteidx() when 'encoding' is set
1621 to a Unicode encoding.
1622
1623 Can also be used as a |method|: >
1624 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001625<
1626 Return type: |Number|
1627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001628
1629call({func}, {arglist} [, {dict}]) *call()* *E699*
1630 Call function {func} with the items in |List| {arglist} as
1631 arguments.
1632 {func} can either be a |Funcref| or the name of a function.
1633 a:firstline and a:lastline are set to the cursor line.
1634 Returns the return value of the called function.
1635 {dict} is for functions with the "dict" attribute. It will be
1636 used to set the local variable "self". |Dictionary-function|
1637
1638 Can also be used as a |method|: >
1639 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001640<
1641 Return type: any, depending on {func}
1642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001643
1644ceil({expr}) *ceil()*
1645 Return the smallest integral value greater than or equal to
1646 {expr} as a |Float| (round up).
1647 {expr} must evaluate to a |Float| or a |Number|.
1648 Examples: >
1649 echo ceil(1.456)
1650< 2.0 >
1651 echo ceil(-5.456)
1652< -5.0 >
1653 echo ceil(4.0)
1654< 4.0
1655
Bram Moolenaar016188f2022-06-06 20:52:59 +01001656 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001658 Can also be used as a |method|: >
1659 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001660<
1661 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001662
1663
1664ch_ functions are documented here: |channel-functions-details|
1665
1666
1667changenr() *changenr()*
1668 Return the number of the most recent change. This is the same
1669 number as what is displayed with |:undolist| and can be used
1670 with the |:undo| command.
1671 When a change was made it is the number of that change. After
1672 redo it is the number of the redone change. After undo it is
1673 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001674 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001675
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001676 Return type: |Number|
1677
1678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001680 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001681 Examples: >
1682 char2nr(" ") returns 32
1683 char2nr("ABC") returns 65
1684< When {utf8} is omitted or zero, the current 'encoding' is used.
1685 Example for "utf-8": >
1686 char2nr("á") returns 225
1687 char2nr("á"[0]) returns 195
1688< When {utf8} is TRUE, always treat as UTF-8 characters.
1689 A combining character is a separate character.
1690 |nr2char()| does the opposite.
1691 To turn a string into a list of character numbers: >
1692 let str = "ABC"
1693 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1694< Result: [65, 66, 67]
1695
Bram Moolenaar016188f2022-06-06 20:52:59 +01001696 Returns 0 if {string} is not a |String|.
1697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001698 Can also be used as a |method|: >
1699 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001700<
1701 Return type: |Number|
1702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001703
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001704charclass({string}) *charclass()*
1705 Return the character class of the first character in {string}.
1706 The character class is one of:
1707 0 blank
1708 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001709 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001710 3 emoji
1711 other specific Unicode class
1712 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001713 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001714
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001715 Return type: |Number|
1716
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001717
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001718charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001719 Same as |col()| but returns the character index of the column
1720 position given with {expr} instead of the byte position.
1721
1722 Example:
1723 With the cursor on '세' in line 5 with text "여보세요": >
1724 charcol('.') returns 3
1725 col('.') returns 7
1726
1727< Can also be used as a |method|: >
1728 GetPos()->col()
1729<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001730 Return type: |Number|
1731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001732 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001733charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001734 Return the character index of the byte at {idx} in {string}.
1735 The index of the first character is zero.
1736 If there are no multibyte characters the returned value is
1737 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001739 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001740 are not counted separately, their byte length is added to the
1741 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001742 When {countcc} is |TRUE|, then composing characters are
1743 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001744
1745 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1746 index in the String {expr} instead of as the byte index.
1747
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001748 Returns -1 if the arguments are invalid or if there are less
1749 than {idx} bytes. If there are exactly {idx} bytes the length
1750 of the string in characters is returned.
1751
1752 An error is given and -1 is returned if the first argument is
1753 not a string, the second argument is not a number or when the
1754 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001756 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001757 from the character index and |utf16idx()| for getting the
1758 UTF-16 index from the character index.
1759 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001760 Examples: >
1761 echo charidx('áb́ć', 3) returns 1
1762 echo charidx('áb́ć', 6, 1) returns 4
1763 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001764 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001765<
1766 Can also be used as a |method|: >
1767 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001768<
1769 Return type: |Number|
1770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001771
1772chdir({dir}) *chdir()*
1773 Change the current working directory to {dir}. The scope of
1774 the directory change depends on the directory of the current
1775 window:
1776 - If the current window has a window-local directory
1777 (|:lcd|), then changes the window local directory.
1778 - Otherwise, if the current tabpage has a local
1779 directory (|:tcd|) then changes the tabpage local
1780 directory.
1781 - Otherwise, changes the global directory.
1782 {dir} must be a String.
1783 If successful, returns the previous working directory. Pass
1784 this to another chdir() to restore the directory.
1785 On failure, returns an empty string.
1786
1787 Example: >
1788 let save_dir = chdir(newdir)
1789 if save_dir != ""
1790 " ... do some work
1791 call chdir(save_dir)
1792 endif
1793
1794< Can also be used as a |method|: >
1795 GetDir()->chdir()
1796<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001797 Return type: |String|
1798
1799
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001800cindent({lnum}) *cindent()*
1801 Get the amount of indent for line {lnum} according the C
1802 indenting rules, as with 'cindent'.
1803 The indent is counted in spaces, the value of 'tabstop' is
1804 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001805 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001806 See |C-indenting|.
1807
1808 Can also be used as a |method|: >
1809 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001810<
1811 Return type: |Number|
1812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001813
1814clearmatches([{win}]) *clearmatches()*
1815 Clears all matches previously defined for the current window
1816 by |matchadd()| and the |:match| commands.
1817 If {win} is specified, use the window with this number or
1818 window ID instead of the current window.
1819
1820 Can also be used as a |method|: >
1821 GetWin()->clearmatches()
1822<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001823 Return type: |Number|
1824
1825
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001826col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001827 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001828 position given with {expr}.
1829 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001830 When {expr} is "$", it means the end of the cursor line, so
1831 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001832 Additionally {expr} can be [lnum, col]: a |List| with the line
1833 and column number. Most useful when the column is "$", to get
1834 the last column of a specific line. When "lnum" or "col" is
1835 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001836
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001837 With the optional {winid} argument the values are obtained for
1838 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001839
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001840 To get the line number use |line()|. To get both use
1841 |getpos()|.
1842 For the screen column position use |virtcol()|. For the
1843 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001845 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001847 Examples: >
1848 col(".") column of cursor
1849 col("$") length of cursor line plus one
1850 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001851 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001852<
1853 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001854 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001855 For an uppercase mark the column may actually be in another
1856 buffer.
1857 For the cursor position, when 'virtualedit' is active, the
1858 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001859 line. Also, when using a <Cmd> mapping the cursor isn't
1860 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001861 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001862
1863< Can also be used as a |method|: >
1864 GetPos()->col()
1865<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001866 Return type: |Number|
1867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001868
1869complete({startcol}, {matches}) *complete()* *E785*
1870 Set the matches for Insert mode completion.
1871 Can only be used in Insert mode. You need to use a mapping
1872 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1873 or with an expression mapping.
1874 {startcol} is the byte offset in the line where the completed
1875 text start. The text up to the cursor is the original text
1876 that will be replaced by the matches. Use col('.') for an
1877 empty string. "col('.') - 1" will replace one character by a
1878 match.
1879 {matches} must be a |List|. Each |List| item is one match.
1880 See |complete-items| for the kind of items that are possible.
1881 "longest" in 'completeopt' is ignored.
1882 Note that the after calling this function you need to avoid
1883 inserting anything that would cause completion to stop.
1884 The match can be selected with CTRL-N and CTRL-P as usual with
1885 Insert mode completion. The popup menu will appear if
1886 specified, see |ins-completion-menu|.
1887 Example: >
1888 inoremap <F5> <C-R>=ListMonths()<CR>
1889
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001890 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001891 call complete(col('.'), ['January', 'February', 'March',
1892 \ 'April', 'May', 'June', 'July', 'August', 'September',
1893 \ 'October', 'November', 'December'])
1894 return ''
1895 endfunc
1896< This isn't very useful, but it shows how it works. Note that
1897 an empty string is returned to avoid a zero being inserted.
1898
1899 Can also be used as a |method|, the base is passed as the
1900 second argument: >
1901 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001902<
1903 Return type: |Number|
1904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001905
1906complete_add({expr}) *complete_add()*
1907 Add {expr} to the list of matches. Only to be used by the
1908 function specified with the 'completefunc' option.
1909 Returns 0 for failure (empty string or out of memory),
1910 1 when the match was added, 2 when the match was already in
1911 the list.
1912 See |complete-functions| for an explanation of {expr}. It is
1913 the same as one item in the list that 'omnifunc' would return.
1914
1915 Can also be used as a |method|: >
1916 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001917<
1918 Return type: |Number|
1919
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001920
1921complete_check() *complete_check()*
1922 Check for a key typed while looking for completion matches.
1923 This is to be used when looking for matches takes some time.
1924 Returns |TRUE| when searching for matches is to be aborted,
1925 zero otherwise.
1926 Only to be used by the function specified with the
1927 'completefunc' option.
1928
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001929 Return type: |Number|
1930
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001931
1932complete_info([{what}]) *complete_info()*
1933 Returns a |Dictionary| with information about Insert mode
1934 completion. See |ins-completion|.
1935 The items are:
1936 mode Current completion mode name string.
1937 See |complete_info_mode| for the values.
1938 pum_visible |TRUE| if popup menu is visible.
1939 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001940 items List of all completion candidates. Each item
1941 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001942 "abbr", "menu", "kind", "info" and "user_data".
1943 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001944 matches Same as "items", but only returns items that
1945 are matching current query. If both "matches"
1946 and "items" are in "what", the returned list
1947 will still be named "items", but each item
1948 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001949 selected Selected item index. First index is zero.
1950 Index is -1 if no item is selected (showing
1951 typed text only, or the last completion after
1952 no item is selected when using the <Up> or
1953 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001954 completed Return a dictionary containing the entries of
1955 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001956
1957 *complete_info_mode*
1958 mode values are:
1959 "" Not in completion mode
1960 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1961 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1962 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1963 |i_CTRL-X_CTRL-Y|
1964 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1965 "files" File names |i_CTRL-X_CTRL-F|
1966 "tags" Tags |i_CTRL-X_CTRL-]|
1967 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1968 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1969 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1970 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1971 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1972 "function" User defined completion |i_CTRL-X_CTRL-U|
1973 "omni" Omni completion |i_CTRL-X_CTRL-O|
1974 "spell" Spelling suggestions |i_CTRL-X_s|
1975 "eval" |complete()| completion
1976 "unknown" Other internal modes
1977
1978 If the optional {what} list argument is supplied, then only
1979 the items listed in {what} are returned. Unsupported items in
1980 {what} are silently ignored.
1981
1982 To get the position and size of the popup menu, see
1983 |pum_getpos()|. It's also available in |v:event| during the
1984 |CompleteChanged| event.
1985
Bram Moolenaar016188f2022-06-06 20:52:59 +01001986 Returns an empty |Dictionary| on error.
1987
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001988 Examples: >
1989 " Get all items
1990 call complete_info()
1991 " Get only 'mode'
1992 call complete_info(['mode'])
1993 " Get only 'mode' and 'pum_visible'
1994 call complete_info(['mode', 'pum_visible'])
1995
1996< Can also be used as a |method|: >
1997 GetItems()->complete_info()
1998<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001999 Return type: dict<any>
2000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002001 *confirm()*
2002confirm({msg} [, {choices} [, {default} [, {type}]]])
2003 confirm() offers the user a dialog, from which a choice can be
2004 made. It returns the number of the choice. For the first
2005 choice this is 1.
2006 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002007 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002008
2009 {msg} is displayed in a |dialog| with {choices} as the
2010 alternatives. When {choices} is missing or empty, "&OK" is
2011 used (and translated).
2012 {msg} is a String, use '\n' to include a newline. Only on
2013 some systems the string is wrapped when it doesn't fit.
2014
2015 {choices} is a String, with the individual choices separated
2016 by '\n', e.g. >
2017 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2018< The letter after the '&' is the shortcut key for that choice.
2019 Thus you can type 'c' to select "Cancel". The shortcut does
2020 not need to be the first letter: >
2021 confirm("file has been modified", "&Save\nSave &All")
2022< For the console, the first letter of each choice is used as
2023 the default shortcut key. Case is ignored.
2024
2025 The optional {default} argument is the number of the choice
2026 that is made if the user hits <CR>. Use 1 to make the first
2027 choice the default one. Use 0 to not set a default. If
2028 {default} is omitted, 1 is used.
2029
2030 The optional {type} String argument gives the type of dialog.
2031 This is only used for the icon of the GTK, Mac, Motif and
2032 Win32 GUI. It can be one of these values: "Error",
2033 "Question", "Info", "Warning" or "Generic". Only the first
2034 character is relevant. When {type} is omitted, "Generic" is
2035 used.
2036
2037 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2038 or another valid interrupt key, confirm() returns 0.
2039
2040 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002041 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002042 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002043 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002044 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002045 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002046 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002047 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002048 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002049 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002050< In a GUI dialog, buttons are used. The layout of the buttons
2051 depends on the 'v' flag in 'guioptions'. If it is included,
2052 the buttons are always put vertically. Otherwise, confirm()
2053 tries to put the buttons in one horizontal line. If they
2054 don't fit, a vertical layout is used anyway. For some systems
2055 the horizontal layout is always used.
2056
2057 Can also be used as a |method|in: >
2058 BuildMessage()->confirm("&Yes\n&No")
2059<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002060 Return type: |Number|
2061
2062
2063copy({expr}) *copy()*
2064 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002065 different from using {expr} directly.
2066 When {expr} is a |List| a shallow copy is created. This means
2067 that the original |List| can be changed without changing the
2068 copy, and vice versa. But the items are identical, thus
2069 changing an item changes the contents of both |Lists|.
2070 A |Dictionary| is copied in a similar way as a |List|.
2071 Also see |deepcopy()|.
2072 Can also be used as a |method|: >
2073 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002074<
2075 Return type: any, depending on {expr}
2076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002077
2078cos({expr}) *cos()*
2079 Return the cosine of {expr}, measured in radians, as a |Float|.
2080 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002081 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002082 Examples: >
2083 :echo cos(100)
2084< 0.862319 >
2085 :echo cos(-4.01)
2086< -0.646043
2087
2088 Can also be used as a |method|: >
2089 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002090<
2091 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002092
2093
2094cosh({expr}) *cosh()*
2095 Return the hyperbolic cosine of {expr} as a |Float| in the range
2096 [1, inf].
2097 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002098 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002099 Examples: >
2100 :echo cosh(0.5)
2101< 1.127626 >
2102 :echo cosh(-0.5)
2103< -1.127626
2104
2105 Can also be used as a |method|: >
2106 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002107<
2108 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002109
2110
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002111count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002112 Return the number of times an item with value {expr} appears
2113 in |String|, |List| or |Dictionary| {comp}.
2114
2115 If {start} is given then start with the item with this index.
2116 {start} can only be used with a |List|.
2117
2118 When {ic} is given and it's |TRUE| then case is ignored.
2119
2120 When {comp} is a string then the number of not overlapping
2121 occurrences of {expr} is returned. Zero is returned when
2122 {expr} is an empty string.
2123
2124 Can also be used as a |method|: >
2125 mylist->count(val)
2126<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002127 Return type: |Number|
2128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002129 *cscope_connection()*
2130cscope_connection([{num} , {dbpath} [, {prepend}]])
2131 Checks for the existence of a |cscope| connection. If no
2132 parameters are specified, then the function returns:
2133 0, if cscope was not available (not compiled in), or
2134 if there are no cscope connections;
2135 1, if there is at least one cscope connection.
2136
2137 If parameters are specified, then the value of {num}
2138 determines how existence of a cscope connection is checked:
2139
2140 {num} Description of existence check
2141 ----- ------------------------------
2142 0 Same as no parameters (e.g., "cscope_connection()").
2143 1 Ignore {prepend}, and use partial string matches for
2144 {dbpath}.
2145 2 Ignore {prepend}, and use exact string matches for
2146 {dbpath}.
2147 3 Use {prepend}, use partial string matches for both
2148 {dbpath} and {prepend}.
2149 4 Use {prepend}, use exact string matches for both
2150 {dbpath} and {prepend}.
2151
2152 Note: All string comparisons are case sensitive!
2153
2154 Examples. Suppose we had the following (from ":cs show"): >
2155
2156 # pid database name prepend path
2157 0 27664 cscope.out /usr/local
2158<
2159 Invocation Return Val ~
2160 ---------- ---------- >
2161 cscope_connection() 1
2162 cscope_connection(1, "out") 1
2163 cscope_connection(2, "out") 0
2164 cscope_connection(3, "out") 0
2165 cscope_connection(3, "out", "local") 1
2166 cscope_connection(4, "out") 0
2167 cscope_connection(4, "out", "local") 0
2168 cscope_connection(4, "cscope.out", "/usr/local") 1
2169<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002170 Return type: |Number|
2171
2172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002173cursor({lnum}, {col} [, {off}]) *cursor()*
2174cursor({list})
2175 Positions the cursor at the column (byte count) {col} in the
2176 line {lnum}. The first column is one.
2177
2178 When there is one argument {list} this is used as a |List|
2179 with two, three or four item:
2180 [{lnum}, {col}]
2181 [{lnum}, {col}, {off}]
2182 [{lnum}, {col}, {off}, {curswant}]
2183 This is like the return value of |getpos()| or |getcurpos()|,
2184 but without the first item.
2185
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002186 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002187 |setcursorcharpos()|.
2188
2189 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002190 {lnum} is used like with |getline()|, except that if {lnum} is
2191 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002192 If {lnum} is greater than the number of lines in the buffer,
2193 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002194 If {col} is greater than the number of bytes in the line,
2195 the cursor will be positioned at the last character in the
2196 line.
2197 If {col} is zero, the cursor will stay in the current column.
2198 If {curswant} is given it is used to set the preferred column
2199 for vertical movement. Otherwise {col} is used.
2200
2201 When 'virtualedit' is used {off} specifies the offset in
2202 screen columns from the start of the character. E.g., a
2203 position within a <Tab> or after the last character.
2204 Returns 0 when the position could be set, -1 otherwise.
2205
2206 Can also be used as a |method|: >
2207 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002208<
2209 Return type: |Number|
2210
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002211
2212debugbreak({pid}) *debugbreak()*
2213 Specifically used to interrupt a program being debugged. It
2214 will cause process {pid} to get a SIGTRAP. Behavior for other
2215 processes is undefined. See |terminal-debugger|.
2216 {only available on MS-Windows}
2217
Bram Moolenaar016188f2022-06-06 20:52:59 +01002218 Returns |TRUE| if successfully interrupted the program.
2219 Otherwise returns |FALSE|.
2220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002221 Can also be used as a |method|: >
2222 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002223<
2224 Return type: |Number|
2225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002226
2227deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2228 Make a copy of {expr}. For Numbers and Strings this isn't
2229 different from using {expr} directly.
2230 When {expr} is a |List| a full copy is created. This means
2231 that the original |List| can be changed without changing the
2232 copy, and vice versa. When an item is a |List| or
2233 |Dictionary|, a copy for it is made, recursively. Thus
2234 changing an item in the copy does not change the contents of
2235 the original |List|.
2236 A |Dictionary| is copied in a similar way as a |List|.
2237
2238 When {noref} is omitted or zero a contained |List| or
2239 |Dictionary| is only copied once. All references point to
2240 this single copy. With {noref} set to 1 every occurrence of a
2241 |List| or |Dictionary| results in a new copy. This also means
2242 that a cyclic reference causes deepcopy() to fail.
2243 *E724*
2244 Nesting is possible up to 100 levels. When there is an item
2245 that refers back to a higher level making a deep copy with
2246 {noref} set to 1 will fail.
2247 Also see |copy()|.
2248
2249 Can also be used as a |method|: >
2250 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002251<
2252 Return type: any, depending on {expr}
2253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002254
2255delete({fname} [, {flags}]) *delete()*
2256 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002257 name {fname}.
2258
2259 This also works when {fname} is a symbolic link. The symbolic
2260 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002261
2262 When {flags} is "d": Deletes the directory by the name
2263 {fname}. This fails when directory {fname} is not empty.
2264
2265 When {flags} is "rf": Deletes the directory by the name
2266 {fname} and everything in it, recursively. BE CAREFUL!
2267 Note: on MS-Windows it is not possible to delete a directory
2268 that is being used.
2269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002270 The result is a Number, which is 0/false if the delete
2271 operation was successful and -1/true when the deletion failed
2272 or partly failed.
2273
2274 Use |remove()| to delete an item from a |List|.
2275 To delete a line from the buffer use |:delete| or
2276 |deletebufline()|.
2277
2278 Can also be used as a |method|: >
2279 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002280<
2281 Return type: |Number|
2282
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002283
2284deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2285 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2286 If {last} is omitted then delete line {first} only.
2287 On success 0 is returned, on failure 1 is returned.
2288
2289 This function works only for loaded buffers. First call
2290 |bufload()| if needed.
2291
2292 For the use of {buf}, see |bufname()| above.
2293
2294 {first} and {last} are used like with |getline()|. Note that
2295 when using |line()| this refers to the current buffer. Use "$"
2296 to refer to the last line in buffer {buf}.
2297
2298 Can also be used as a |method|: >
2299 GetBuffer()->deletebufline(1)
2300<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002301 Return type: |Number|
2302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002303 *did_filetype()*
2304did_filetype() Returns |TRUE| when autocommands are being executed and the
2305 FileType event has been triggered at least once. Can be used
2306 to avoid triggering the FileType event again in the scripts
2307 that detect the file type. |FileType|
2308 Returns |FALSE| when `:setf FALLBACK` was used.
2309 When editing another file, the counter is reset, thus this
2310 really checks if the FileType event has been triggered for the
2311 current buffer. This allows an autocommand that starts
2312 editing another buffer to set 'filetype' and load a syntax
2313 file.
2314
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002315 Return type: |Number|
2316
2317
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002318diff({fromlist}, {tolist} [, {options}]) *diff()*
2319 Returns a String or a List containing the diff between the
2320 strings in {fromlist} and {tolist}. Uses the Vim internal
2321 diff library to compute the diff.
2322
2323 *E106*
2324 The optional "output" item in {options} specifies the returned
2325 diff format. The following values are supported:
2326 indices Return a List of the starting and ending
2327 indices and a count of the strings in each
2328 diff hunk.
2329 unified Return the unified diff output as a String.
2330 This is the default.
2331
2332 If the "output" item in {options} is "indices", then a List is
2333 returned. Each List item contains a Dict with the following
2334 items for each diff hunk:
2335 from_idx start index in {fromlist} for this diff hunk.
2336 from_count number of strings in {fromlist} that are
2337 added/removed/modified in this diff hunk.
2338 to_idx start index in {tolist} for this diff hunk.
2339 to_count number of strings in {tolist} that are
2340 added/removed/modified in this diff hunk.
2341
2342 The {options} Dict argument also specifies diff options
2343 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002344 algorithm Dict specifying the diff algorithm to
2345 use. Supported boolean items are
2346 "myers", "minimal", "patience" and
2347 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002348 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002349 iblank ignore changes where lines are all
2350 blank.
2351 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002352 indent-heuristic use the indent heuristic for the
2353 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002354 iwhite ignore changes in amount of white
2355 space.
2356 iwhiteall ignore all white space changes.
2357 iwhiteeol ignore white space changes at end of
2358 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002359 For more information about these options, refer to 'diffopt'.
2360
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002361 To compute the unified diff, all the items in {fromlist} are
2362 concatenated into a string using a newline separator and the
2363 same for {tolist}. The unified diff output uses line numbers.
2364
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002365 Returns an empty List or String if {fromlist} and {tolist} are
2366 identical.
2367
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002368 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002369 :echo diff(['abc'], ['xxx'])
2370 @@ -1 +1 @@
2371 -abc
2372 +xxx
2373
2374 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2375 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2376 :echo diff(readfile('oldfile'), readfile('newfile'))
2377 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002378<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002379 For more examples, refer to |diff-func-examples|
2380
2381 Can also be used as a |method|: >
2382 GetFromList->diff(to_list)
2383<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002384 Return type: |String| or list<dict<number>> or list<any>
2385 depending on {options}
2386
2387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002388diff_filler({lnum}) *diff_filler()*
2389 Returns the number of filler lines above line {lnum}.
2390 These are the lines that were inserted at this point in
2391 another diff'ed window. These filler lines are shown in the
2392 display but don't exist in the buffer.
2393 {lnum} is used like with |getline()|. Thus "." is the current
2394 line, "'m" mark m, etc.
2395 Returns 0 if the current window is not in diff mode.
2396
2397 Can also be used as a |method|: >
2398 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002399<
2400 Return type: |Number|
2401
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002402
2403diff_hlID({lnum}, {col}) *diff_hlID()*
2404 Returns the highlight ID for diff mode at line {lnum} column
2405 {col} (byte index). When the current line does not have a
2406 diff change zero is returned.
2407 {lnum} is used like with |getline()|. Thus "." is the current
2408 line, "'m" mark m, etc.
2409 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2410 line.
2411 The highlight ID can be used with |synIDattr()| to obtain
2412 syntax information about the highlighting.
2413
2414 Can also be used as a |method|: >
2415 GetLnum()->diff_hlID(col)
2416<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002417 Return type: |Number|
2418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002419
2420digraph_get({chars}) *digraph_get()* *E1214*
2421 Return the digraph of {chars}. This should be a string with
2422 exactly two characters. If {chars} are not just two
2423 characters, or the digraph of {chars} does not exist, an error
2424 is given and an empty string is returned.
2425
2426 The character will be converted from Unicode to 'encoding'
2427 when needed. This does require the conversion to be
2428 available, it might fail.
2429
2430 Also see |digraph_getlist()|.
2431
2432 Examples: >
2433 " Get a built-in digraph
2434 :echo digraph_get('00') " Returns '∞'
2435
2436 " Get a user-defined digraph
2437 :call digraph_set('aa', 'あ')
2438 :echo digraph_get('aa') " Returns 'あ'
2439<
2440 Can also be used as a |method|: >
2441 GetChars()->digraph_get()
2442<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002443 Return type: |String|
2444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002445 This function works only when compiled with the |+digraphs|
2446 feature. If this feature is disabled, this function will
2447 display an error message.
2448
2449
2450digraph_getlist([{listall}]) *digraph_getlist()*
2451 Return a list of digraphs. If the {listall} argument is given
2452 and it is TRUE, return all digraphs, including the default
2453 digraphs. Otherwise, return only user-defined digraphs.
2454
2455 The characters will be converted from Unicode to 'encoding'
2456 when needed. This does require the conservation to be
2457 available, it might fail.
2458
2459 Also see |digraph_get()|.
2460
2461 Examples: >
2462 " Get user-defined digraphs
2463 :echo digraph_getlist()
2464
2465 " Get all the digraphs, including default digraphs
2466 :echo digraph_getlist(1)
2467<
2468 Can also be used as a |method|: >
2469 GetNumber()->digraph_getlist()
2470<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002471 Return type: list<list<string>>
2472
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002473 This function works only when compiled with the |+digraphs|
2474 feature. If this feature is disabled, this function will
2475 display an error message.
2476
2477
Bram Moolenaara2baa732022-02-04 16:09:54 +00002478digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002479 Add digraph {chars} to the list. {chars} must be a string
2480 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002481 encoded character. *E1215*
2482 Be careful, composing characters are NOT ignored. This
2483 function is similar to |:digraphs| command, but useful to add
2484 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002485
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002486 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002487 this fails an error message is given and v:false is returned.
2488
2489 If you want to define multiple digraphs at once, you can use
2490 |digraph_setlist()|.
2491
2492 Example: >
2493 call digraph_set(' ', 'あ')
2494<
2495 Can be used as a |method|: >
2496 GetString()->digraph_set('あ')
2497<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002498 Return type: |vim9-boolean|
2499
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002500 This function works only when compiled with the |+digraphs|
2501 feature. If this feature is disabled, this function will
2502 display an error message.
2503
2504
2505digraph_setlist({digraphlist}) *digraph_setlist()*
2506 Similar to |digraph_set()| but this function can add multiple
2507 digraphs at once. {digraphlist} is a list composed of lists,
2508 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002509 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002510 Example: >
2511 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2512<
2513 It is similar to the following: >
2514 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2515 call digraph_set(chars, digraph)
2516 endfor
2517< Except that the function returns after the first error,
2518 following digraphs will not be added.
2519
2520 Can be used as a |method|: >
2521 GetList()->digraph_setlist()
2522<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002523 Return type: |vim9-boolean|
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
2530echoraw({string}) *echoraw()*
2531 Output {string} as-is, including unprintable characters.
2532 This can be used to output a terminal code. For example, to
2533 disable modifyOtherKeys: >
2534 call echoraw(&t_TE)
2535< and to enable it again: >
2536 call echoraw(&t_TI)
2537< Use with care, you can mess up the terminal this way.
2538
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002539 Return type: |Number|
2540
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002541
2542empty({expr}) *empty()*
2543 Return the Number 1 if {expr} is empty, zero otherwise.
2544 - A |List| or |Dictionary| is empty when it does not have any
2545 items.
2546 - A |String| is empty when its length is zero.
2547 - A |Number| and |Float| are empty when their value is zero.
2548 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2549 - A |Job| is empty when it failed to start.
2550 - A |Channel| is empty when it is closed.
2551 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002552 - An |Object| is empty, when the empty() method in the object
2553 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002554
2555 For a long |List| this is much faster than comparing the
2556 length with zero.
2557
2558 Can also be used as a |method|: >
2559 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002560<
2561 Return type: |Number|
2562
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002563
2564environ() *environ()*
2565 Return all of environment variables as dictionary. You can
2566 check if an environment variable exists like this: >
2567 :echo has_key(environ(), 'HOME')
2568< Note that the variable name may be CamelCase; to ignore case
2569 use this: >
2570 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002571<
2572 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002573
Bram Moolenaar416bd912023-07-07 23:19:18 +01002574
2575err_teapot([{expr}]) *err_teapot()*
2576 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002577 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002578 If {expr} is present and it is TRUE error 503 is given,
2579 indicating that coffee is temporarily not available.
2580 If {expr} is present it must be a String.
2581
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002582 Return type: |Number|
2583
Bram Moolenaar416bd912023-07-07 23:19:18 +01002584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002585escape({string}, {chars}) *escape()*
2586 Escape the characters in {chars} that occur in {string} with a
2587 backslash. Example: >
2588 :echo escape('c:\program files\vim', ' \')
2589< results in: >
2590 c:\\program\ files\\vim
2591< Also see |shellescape()| and |fnameescape()|.
2592
2593 Can also be used as a |method|: >
2594 GetText()->escape(' \')
2595<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002596 Return type: |String|
2597
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002598 *eval()*
2599eval({string}) Evaluate {string} and return the result. Especially useful to
2600 turn the result of |string()| back into the original value.
2601 This works for Numbers, Floats, Strings, Blobs and composites
2602 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002603 functions. In |Vim9| script, it can be used to obtain |enum|
2604 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002605
2606 Can also be used as a |method|: >
2607 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002608<
2609 Return type: any, depending on {string}
2610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002611
2612eventhandler() *eventhandler()*
2613 Returns 1 when inside an event handler. That is that Vim got
2614 interrupted while waiting for the user to type a character,
2615 e.g., when dropping a file on Vim. This means interactive
2616 commands cannot be used. Otherwise zero is returned.
2617
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002618 Return type: |Number|
2619
2620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621executable({expr}) *executable()*
2622 This function checks if an executable with the name {expr}
2623 exists. {expr} must be the name of the program without any
2624 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002626 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002627 searchpath for programs.
2628 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002629 On MS-Windows the ".exe", ".bat", etc. can optionally be
2630 included. Then the extensions in $PATHEXT are tried. Thus if
2631 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2632 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2633 by itself can be used in $PATHEXT to try using the name
2634 without an extension. When 'shell' looks like a Unix shell,
2635 then the name is also tried without adding an extension.
2636 On MS-Windows it only checks if the file exists and is not a
2637 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002638 On MS-Windows an executable in the same directory as the Vim
2639 executable is always found. Since this directory is added to
2640 $PATH it should also work to execute it |win32-PATH|.
2641 *NoDefaultCurrentDirectoryInExePath*
2642 On MS-Windows an executable in Vim's current working directory
2643 is also normally found, but this can be disabled by setting
2644 the $NoDefaultCurrentDirectoryInExePath environment variable.
2645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002646 The result is a Number:
2647 1 exists
2648 0 does not exist
2649 -1 not implemented on this system
2650 |exepath()| can be used to get the full path of an executable.
2651
2652 Can also be used as a |method|: >
2653 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002654<
2655 Return type: |Number|
2656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002657
2658execute({command} [, {silent}]) *execute()*
2659 Execute an Ex command or commands and return the output as a
2660 string.
2661 {command} can be a string or a List. In case of a List the
2662 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002663 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002664 redir => var
2665 {command}
2666 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002667< Except that line continuation in {command} is not recognized.
2668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002669 The optional {silent} argument can have these values:
2670 "" no `:silent` used
2671 "silent" `:silent` used
2672 "silent!" `:silent!` used
2673 The default is "silent". Note that with "silent!", unlike
2674 `:redir`, error messages are dropped. When using an external
2675 command the screen may be messed up, use `system()` instead.
2676 *E930*
2677 It is not possible to use `:redir` anywhere in {command}.
2678
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002679 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002680 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002681
2682< To execute a command in another window than the current one
2683 use `win_execute()`.
2684
2685 When used recursively the output of the recursive call is not
2686 included in the output of the higher level call.
2687
2688 Can also be used as a |method|: >
2689 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002690<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002691 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002693
2694exepath({expr}) *exepath()*
2695 If {expr} is an executable and is either an absolute path, a
2696 relative path or found in $PATH, return the full path.
2697 Note that the current directory is used when {expr} starts
2698 with "./", which may be a problem for Vim: >
2699 echo exepath(v:progpath)
2700< If {expr} cannot be found in $PATH or is not executable then
2701 an empty string is returned.
2702
2703 Can also be used as a |method|: >
2704 GetCommand()->exepath()
2705<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002706 Return type: |String|
2707
2708
2709exists({expr}) *exists()*
2710 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002711 zero otherwise.
2712
2713 Note: In a compiled |:def| function the evaluation is done at
2714 runtime. Use `exists_compiled()` to evaluate the expression
2715 at compile time.
2716
2717 For checking for a supported feature use |has()|.
2718 For checking if a file exists use |filereadable()|.
2719
2720 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002721 varname internal variable (see
2722 dict.key |internal-variables|). Also works
2723 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002724 import.Func entries, |List| items, class and
2725 class.Func object methods, imported items, etc.
2726 object.Func Does not work for local variables in a
2727 class.varname compiled `:def` function.
2728 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002729 script, since it can be used as a
2730 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002731 Beware that evaluating an index may
2732 cause an error message for an invalid
2733 expression. E.g.: >
2734 :let l = [1, 2, 3]
2735 :echo exists("l[5]")
2736< 0 >
2737 :echo exists("l[xx]")
2738< E121: Undefined variable: xx
2739 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002740 &option-name Vim option (only checks if it exists,
2741 not if it really works)
2742 +option-name Vim option that works.
2743 $ENVNAME environment variable (could also be
2744 done by comparing with an empty
2745 string)
2746 *funcname built-in function (see |functions|)
2747 or user defined function (see
2748 |user-functions|) that is implemented.
2749 Also works for a variable that is a
2750 Funcref.
2751 ?funcname built-in function that could be
2752 implemented; to be used to check if
2753 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002754 :cmdname Ex command: built-in command, user
2755 command or command modifier |:command|.
2756 Returns:
2757 1 for match with start of a command
2758 2 full match with a command
2759 3 matches several user commands
2760 To check for a supported command
2761 always check the return value to be 2.
2762 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002763 :3match The |:3match| command (but you
2764 probably should not use it, it is
2765 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002766 #event autocommand defined for this event
2767 #event#pattern autocommand defined for this event and
2768 pattern (the pattern is taken
2769 literally and compared to the
2770 autocommand patterns character by
2771 character)
2772 #group autocommand group exists
2773 #group#event autocommand defined for this group and
2774 event.
2775 #group#event#pattern
2776 autocommand defined for this group,
2777 event and pattern.
2778 ##event autocommand for this event is
2779 supported.
2780
2781 Examples: >
2782 exists("&shortname")
2783 exists("$HOSTNAME")
2784 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002785 exists("*s:MyFunc") " only for legacy script
2786 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002787 exists("bufcount")
2788 exists(":Make")
2789 exists("#CursorHold")
2790 exists("#BufReadPre#*.gz")
2791 exists("#filetypeindent")
2792 exists("#filetypeindent#FileType")
2793 exists("#filetypeindent#FileType#*")
2794 exists("##ColorScheme")
2795< There must be no space between the symbol (&/$/*/#) and the
2796 name.
2797 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002798 a few cases this is ignored. That may become stricter in the
2799 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002800 Working example: >
2801 exists(":make")
2802< NOT working example: >
2803 exists(":make install")
2804
2805< Note that the argument must be a string, not the name of the
2806 variable itself. For example: >
2807 exists(bufcount)
2808< This doesn't check for existence of the "bufcount" variable,
2809 but gets the value of "bufcount", and checks if that exists.
2810
2811 Can also be used as a |method|: >
2812 Varname()->exists()
2813<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002814 Return type: |String|
2815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002816
2817exists_compiled({expr}) *exists_compiled()*
2818 Like `exists()` but evaluated at compile time. This is useful
2819 to skip a block where a function is used that would otherwise
2820 give an error: >
2821 if exists_compiled('*ThatFunction')
2822 ThatFunction('works')
2823 endif
2824< If `exists()` were used then a compilation error would be
2825 given if ThatFunction() is not defined.
2826
2827 {expr} must be a literal string. *E1232*
2828 Can only be used in a |:def| function. *E1233*
2829 This does not work to check for arguments or local variables.
2830
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002831 Return type: |String|
2832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002833
2834exp({expr}) *exp()*
2835 Return the exponential of {expr} as a |Float| in the range
2836 [0, inf].
2837 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002838 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002839 Examples: >
2840 :echo exp(2)
2841< 7.389056 >
2842 :echo exp(-1)
2843< 0.367879
2844
2845 Can also be used as a |method|: >
2846 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002847<
2848 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002849
2850
2851expand({string} [, {nosuf} [, {list}]]) *expand()*
2852 Expand wildcards and the following special keywords in
2853 {string}. 'wildignorecase' applies.
2854
2855 If {list} is given and it is |TRUE|, a List will be returned.
2856 Otherwise the result is a String and when there are several
2857 matches, they are separated by <NL> characters. [Note: in
2858 version 5.0 a space was used, which caused problems when a
2859 file name contains a space]
2860
2861 If the expansion fails, the result is an empty string. A name
2862 for a non-existing file is not included, unless {string} does
2863 not start with '%', '#' or '<', see below.
2864
Christian Brabandtec9c3262024-02-21 20:40:05 +01002865 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002866 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002868 When {string} starts with '%', '#' or '<', the expansion is
2869 done like for the |cmdline-special| variables with their
2870 associated modifiers. Here is a short overview:
2871
2872 % current file name
2873 # alternate file name
2874 #n alternate file name n
2875 <cfile> file name under the cursor
2876 <afile> autocmd file name
2877 <abuf> autocmd buffer number (as a String!)
2878 <amatch> autocmd matched name
2879 <cexpr> C expression under the cursor
2880 <sfile> sourced script file or function name
2881 <slnum> sourced script line number or function
2882 line number
2883 <sflnum> script file line number, also when in
2884 a function
2885 <SID> "<SNR>123_" where "123" is the
2886 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002887 <script> sourced script file, or script file
2888 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002889 <stack> call stack
2890 <cword> word under the cursor
2891 <cWORD> WORD under the cursor
2892 <client> the {clientid} of the last received
2893 message |server2client()|
2894 Modifiers:
2895 :p expand to full path
2896 :h head (last path component removed)
2897 :t tail (last path component only)
2898 :r root (one extension removed)
2899 :e extension only
2900
2901 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002902 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002903< Note that when expanding a string that starts with '%', '#' or
2904 '<', any following text is ignored. This does NOT work: >
2905 :let doesntwork = expand("%:h.bak")
2906< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002907 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002908< Also note that expanding "<cfile>" and others only returns the
2909 referenced file name without further expansion. If "<cfile>"
2910 is "~/.cshrc", you need to do another expand() to have the
2911 "~/" expanded into the path of the home directory: >
2912 :echo expand(expand("<cfile>"))
2913<
2914 There cannot be white space between the variables and the
2915 following modifier. The |fnamemodify()| function can be used
2916 to modify normal file names.
2917
2918 When using '%' or '#', and the current or alternate file name
2919 is not defined, an empty string is used. Using "%:p" in a
2920 buffer with no name, results in the current directory, with a
2921 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002922 When 'verbose' is set then expanding '%', '#' and <> items
2923 will result in an error message if the argument cannot be
2924 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002925
2926 When {string} does not start with '%', '#' or '<', it is
2927 expanded like a file name is expanded on the command line.
2928 'suffixes' and 'wildignore' are used, unless the optional
2929 {nosuf} argument is given and it is |TRUE|.
2930 Names for non-existing files are included. The "**" item can
2931 be used to search in a directory tree. For example, to find
2932 all "README" files in the current directory and below: >
2933 :echo expand("**/README")
2934<
2935 expand() can also be used to expand variables and environment
2936 variables that are only known in a shell. But this can be
2937 slow, because a shell may be used to do the expansion. See
2938 |expr-env-expand|.
2939 The expanded variable is still handled like a list of file
2940 names. When an environment variable cannot be expanded, it is
2941 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2942 "$FOOBAR".
2943
2944 See |glob()| for finding existing files. See |system()| for
2945 getting the raw output of an external command.
2946
2947 Can also be used as a |method|: >
2948 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002949<
2950 Return type: |String| or list<string> depending on {list}
2951
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002952
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002953expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002954 Expand special items in String {string} like what is done for
2955 an Ex command such as `:edit`. This expands special keywords,
2956 like with |expand()|, and environment variables, anywhere in
2957 {string}. "~user" and "~/path" are only expanded at the
2958 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002959
2960 The following items are supported in the {options} Dict
2961 argument:
2962 errmsg If set to TRUE, error messages are displayed
2963 if an error is encountered during expansion.
2964 By default, error messages are not displayed.
2965
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002966 Returns the expanded string. If an error is encountered
2967 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002968
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002969 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002970 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002971 make /path/runtime/doc/builtin.o
2972 :echo expandcmd('make %<.o', {'errmsg': v:true})
2973<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002974 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002975 GetCommand()->expandcmd()
2976<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002977 Return type: |String| or list<string> depending on {list}
2978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002979extend({expr1}, {expr2} [, {expr3}]) *extend()*
2980 {expr1} and {expr2} must be both |Lists| or both
2981 |Dictionaries|.
2982
2983 If they are |Lists|: Append {expr2} to {expr1}.
2984 If {expr3} is given insert the items of {expr2} before the
2985 item with index {expr3} in {expr1}. When {expr3} is zero
2986 insert before the first item. When {expr3} is equal to
2987 len({expr1}) then {expr2} is appended.
2988 Examples: >
2989 :echo sort(extend(mylist, [7, 5]))
2990 :call extend(mylist, [2, 3], 1)
2991< When {expr1} is the same List as {expr2} then the number of
2992 items copied is equal to the original length of the List.
2993 E.g., when {expr3} is 1 you get N new copies of the first item
2994 (where N is the original length of the List).
2995 Use |add()| to concatenate one item to a list. To concatenate
2996 two lists into a new list use the + operator: >
2997 :let newlist = [1, 2, 3] + [4, 5]
2998<
2999 If they are |Dictionaries|:
3000 Add all entries from {expr2} to {expr1}.
3001 If a key exists in both {expr1} and {expr2} then {expr3} is
3002 used to decide what to do:
3003 {expr3} = "keep": keep the value of {expr1}
3004 {expr3} = "force": use the value of {expr2}
3005 {expr3} = "error": give an error message *E737*
3006 When {expr3} is omitted then "force" is assumed.
3007
3008 {expr1} is changed when {expr2} is not empty. If necessary
Christian Brabandt5647c912025-02-17 21:33:30 +01003009 make a copy of {expr1} first or use |extendnew()| to return a
3010 new List/Dictionary.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003011 {expr2} remains unchanged.
3012 When {expr1} is locked and {expr2} is not empty the operation
3013 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003014 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003015
3016 Can also be used as a |method|: >
3017 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003018<
3019 Return type: list<{type}> or dict<{type}> depending on {expr1}
3020 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003021
3022
3023extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3024 Like |extend()| but instead of adding items to {expr1} a new
3025 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003026 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003027
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003028 Return type: list<{type}> or dict<{type}> depending on {expr1}
3029 and {expr2}, in case of error: |Number|
3030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003031
3032feedkeys({string} [, {mode}]) *feedkeys()*
3033 Characters in {string} are queued for processing as if they
3034 come from a mapping or were typed by the user.
3035
3036 By default the string is added to the end of the typeahead
3037 buffer, thus if a mapping is still being executed the
3038 characters come after them. Use the 'i' flag to insert before
3039 other characters, they will be executed next, before any
3040 characters from a mapping.
3041
3042 The function does not wait for processing of keys contained in
3043 {string}.
3044
3045 To include special keys into {string}, use double-quotes
3046 and "\..." notation |expr-quote|. For example,
3047 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3048 feedkeys('\<CR>') pushes 5 characters.
3049 A special code that might be useful is <Ignore>, it exits the
3050 wait for a character without doing anything. *<Ignore>*
3051
3052 {mode} is a String, which can contain these character flags:
3053 'm' Remap keys. This is default. If {mode} is absent,
3054 keys are remapped.
3055 'n' Do not remap keys.
3056 't' Handle keys as if typed; otherwise they are handled as
3057 if coming from a mapping. This matters for undo,
3058 opening folds, etc.
3059 'L' Lowlevel input. Only works for Unix or when using the
3060 GUI. Keys are used as if they were coming from the
3061 terminal. Other flags are not used. *E980*
3062 When a CTRL-C interrupts and 't' is included it sets
3063 the internal "got_int" flag.
3064 'i' Insert the string instead of appending (see above).
3065 'x' Execute commands until typeahead is empty. This is
3066 similar to using ":normal!". You can call feedkeys()
3067 several times without 'x' and then one time with 'x'
3068 (possibly with an empty {string}) to execute all the
3069 typeahead. Note that when Vim ends in Insert mode it
3070 will behave as if <Esc> is typed, to avoid getting
3071 stuck, waiting for a character to be typed before the
3072 script continues.
3073 Note that if you manage to call feedkeys() while
3074 executing commands, thus calling it recursively, then
3075 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003076 'c' Remove any script context when executing, so that
3077 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003078 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003079 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003080 '!' When used with 'x' will not end Insert mode. Can be
3081 used in a test when a timer is set to exit Insert mode
3082 a little later. Useful for testing CursorHoldI.
3083
3084 Return value is always 0.
3085
3086 Can also be used as a |method|: >
3087 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003088<
3089 Return type: |String| or list<string> depending on {list}
3090
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003091
Shougo Matsushita60c87432024-06-03 22:59:27 +02003092filecopy({from}, {to}) *filecopy()*
3093 Copy the file pointed to by the name {from} to {to}. The
3094 result is a Number, which is |TRUE| if the file was copied
3095 successfully, and |FALSE| when it failed.
3096 If a file with name {to} already exists, it will fail.
3097 Note that it does not handle directories (yet).
3098
3099 This function is not available in the |sandbox|.
3100
3101 Can also be used as a |method|: >
3102 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003103<
3104 Return type: |Number|
3105
Shougo Matsushita60c87432024-06-03 22:59:27 +02003106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003107filereadable({file}) *filereadable()*
3108 The result is a Number, which is |TRUE| when a file with the
3109 name {file} exists, and can be read. If {file} doesn't exist,
3110 or is a directory, the result is |FALSE|. {file} is any
3111 expression, which is used as a String.
3112 If you don't care about the file being readable you can use
3113 |glob()|.
3114 {file} is used as-is, you may want to expand wildcards first: >
3115 echo filereadable('~/.vimrc')
3116 0
3117 echo filereadable(expand('~/.vimrc'))
3118 1
3119
3120< Can also be used as a |method|: >
3121 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003122<
3123 Return type: |Number|
3124
3125 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003126 Obsolete name: file_readable().
3127
3128
3129filewritable({file}) *filewritable()*
3130 The result is a Number, which is 1 when a file with the
3131 name {file} exists, and can be written. If {file} doesn't
3132 exist, or is not writable, the result is 0. If {file} is a
3133 directory, and we can write to it, the result is 2.
3134
3135 Can also be used as a |method|: >
3136 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003137<
3138 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003139
3140
3141filter({expr1}, {expr2}) *filter()*
3142 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3143 For each item in {expr1} evaluate {expr2} and when the result
3144 is zero or false remove the item from the |List| or
3145 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003146 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003147
3148 {expr2} must be a |string| or |Funcref|.
3149
3150 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3151 of the current item. For a |Dictionary| |v:key| has the key
3152 of the current item and for a |List| |v:key| has the index of
3153 the current item. For a |Blob| |v:key| has the index of the
3154 current byte. For a |String| |v:key| has the index of the
3155 current character.
3156 Examples: >
3157 call filter(mylist, 'v:val !~ "OLD"')
3158< Removes the items where "OLD" appears. >
3159 call filter(mydict, 'v:key >= 8')
3160< Removes the items with a key below 8. >
3161 call filter(var, 0)
3162< Removes all the items, thus clears the |List| or |Dictionary|.
3163
3164 Note that {expr2} is the result of expression and is then
3165 used as an expression again. Often it is good to use a
3166 |literal-string| to avoid having to double backslashes.
3167
3168 If {expr2} is a |Funcref| it must take two arguments:
3169 1. the key or the index of the current item.
3170 2. the value of the current item.
3171 The function must return |TRUE| if the item should be kept.
3172 Example that keeps the odd items of a list: >
3173 func Odd(idx, val)
3174 return a:idx % 2 == 1
3175 endfunc
3176 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003177< It is shorter when using a |lambda|. In |Vim9| syntax: >
3178 call filter(myList, (idx, val) => idx * val <= 42)
3179< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003180 call filter(myList, {idx, val -> idx * val <= 42})
3181< If you do not use "val" you can leave it out: >
3182 call filter(myList, {idx -> idx % 2 == 1})
3183<
3184 In |Vim9| script the result must be true, false, zero or one.
3185 Other values will result in a type error.
3186
3187 For a |List| and a |Dictionary| the operation is done
3188 in-place. If you want it to remain unmodified make a copy
3189 first: >
3190 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3191
3192< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003193 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003194 When an error is encountered while evaluating {expr2} no
3195 further items in {expr1} are processed.
3196 When {expr2} is a Funcref errors inside a function are ignored,
3197 unless it was defined with the "abort" flag.
3198
3199 Can also be used as a |method|: >
3200 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003201<
3202 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3203 depending on {expr1}
3204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003205
3206finddir({name} [, {path} [, {count}]]) *finddir()*
3207 Find directory {name} in {path}. Supports both downwards and
3208 upwards recursive directory searches. See |file-searching|
3209 for the syntax of {path}.
3210
3211 Returns the path of the first found match. When the found
3212 directory is below the current directory a relative path is
3213 returned. Otherwise a full path is returned.
3214 If {path} is omitted or empty then 'path' is used.
3215
3216 If the optional {count} is given, find {count}'s occurrence of
3217 {name} in {path} instead of the first one.
3218 When {count} is negative return all the matches in a |List|.
3219
Bram Moolenaar016188f2022-06-06 20:52:59 +01003220 Returns an empty string if the directory is not found.
3221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003223
3224 Can also be used as a |method|: >
3225 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003226<
3227 Return type: |String|
3228
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003229
3230findfile({name} [, {path} [, {count}]]) *findfile()*
3231 Just like |finddir()|, but find a file instead of a directory.
3232 Uses 'suffixesadd'.
3233 Example: >
3234 :echo findfile("tags.vim", ".;")
3235< Searches from the directory of the current file upwards until
3236 it finds the file "tags.vim".
3237
3238 Can also be used as a |method|: >
3239 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003240<
3241 Return type: |String|
3242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003243
3244flatten({list} [, {maxdepth}]) *flatten()*
3245 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3246 the result is a |List| without nesting, as if {maxdepth} is
3247 a very large number.
3248 The {list} is changed in place, use |flattennew()| if you do
3249 not want that.
3250 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003251 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003252 *E900*
3253 {maxdepth} means how deep in nested lists changes are made.
3254 {list} is not modified when {maxdepth} is 0.
3255 {maxdepth} must be positive number.
3256
3257 If there is an error the number zero is returned.
3258
3259 Example: >
3260 :echo flatten([1, [2, [3, 4]], 5])
3261< [1, 2, 3, 4, 5] >
3262 :echo flatten([1, [2, [3, 4]], 5], 1)
3263< [1, 2, [3, 4], 5]
3264
3265 Can also be used as a |method|: >
3266 mylist->flatten()
3267<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003268 Return type: list<{type}>
3269
3270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003271flattennew({list} [, {maxdepth}]) *flattennew()*
3272 Like |flatten()| but first make a copy of {list}.
3273
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003274 Return type: list<{type}>
3275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003276
3277float2nr({expr}) *float2nr()*
3278 Convert {expr} to a Number by omitting the part after the
3279 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003280 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003281 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003282 When the value of {expr} is out of range for a |Number| the
3283 result is truncated to 0x7fffffff or -0x7fffffff (or when
3284 64-bit Number support is enabled, 0x7fffffffffffffff or
3285 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3286 64-bit Number support is enabled, -0x8000000000000000).
3287 Examples: >
3288 echo float2nr(3.95)
3289< 3 >
3290 echo float2nr(-23.45)
3291< -23 >
3292 echo float2nr(1.0e100)
3293< 2147483647 (or 9223372036854775807) >
3294 echo float2nr(-1.0e150)
3295< -2147483647 (or -9223372036854775807) >
3296 echo float2nr(1.0e-100)
3297< 0
3298
3299 Can also be used as a |method|: >
3300 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003301<
3302 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003303
3304
3305floor({expr}) *floor()*
3306 Return the largest integral value less than or equal to
3307 {expr} as a |Float| (round down).
3308 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003309 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003310 Examples: >
3311 echo floor(1.856)
3312< 1.0 >
3313 echo floor(-5.456)
3314< -6.0 >
3315 echo floor(4.0)
3316< 4.0
3317
3318 Can also be used as a |method|: >
3319 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003320<
3321 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003322
3323
3324fmod({expr1}, {expr2}) *fmod()*
3325 Return the remainder of {expr1} / {expr2}, even if the
3326 division is not representable. Returns {expr1} - i * {expr2}
3327 for some integer i such that if {expr2} is non-zero, the
3328 result has the same sign as {expr1} and magnitude less than
3329 the magnitude of {expr2}. If {expr2} is zero, the value
3330 returned is zero. The value returned is a |Float|.
3331 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003332 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3333 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003334 Examples: >
3335 :echo fmod(12.33, 1.22)
3336< 0.13 >
3337 :echo fmod(-12.33, 1.22)
3338< -0.13
3339
3340 Can also be used as a |method|: >
3341 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003342<
3343 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003344
3345
3346fnameescape({string}) *fnameescape()*
3347 Escape {string} for use as file name command argument. All
3348 characters that have a special meaning, such as '%' and '|'
3349 are escaped with a backslash.
3350 For most systems the characters escaped are
3351 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3352 appears in a filename, it depends on the value of 'isfname'.
3353 A leading '+' and '>' is also escaped (special after |:edit|
3354 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003355 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003356 Example: >
3357 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003358 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003359< results in executing: >
3360 edit \+some\ str\%nge\|name
3361<
3362 Can also be used as a |method|: >
3363 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003364<
3365 Return type: |String|
3366
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003367
3368fnamemodify({fname}, {mods}) *fnamemodify()*
3369 Modify file name {fname} according to {mods}. {mods} is a
3370 string of characters like it is used for file names on the
3371 command line. See |filename-modifiers|.
3372 Example: >
3373 :echo fnamemodify("main.c", ":p:h")
3374< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003375 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003376< If {mods} is empty or an unsupported modifier is used then
3377 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003378 When {fname} is empty then with {mods} ":h" returns ".", so
3379 that `:cd` can be used with it. This is different from
3380 expand('%:h') without a buffer name, which returns an empty
3381 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003382 Note: Environment variables don't work in {fname}, use
3383 |expand()| first then.
3384
3385 Can also be used as a |method|: >
3386 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003387<
3388 Return type: |String|
3389
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003390
3391foldclosed({lnum}) *foldclosed()*
3392 The result is a Number. If the line {lnum} is in a closed
3393 fold, the result is the number of the first line in that fold.
3394 If the line {lnum} is not in a closed fold, -1 is returned.
3395 {lnum} is used like with |getline()|. Thus "." is the current
3396 line, "'m" mark m, etc.
3397
3398 Can also be used as a |method|: >
3399 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003400<
3401 Return type: |Number|
3402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003403
3404foldclosedend({lnum}) *foldclosedend()*
3405 The result is a Number. If the line {lnum} is in a closed
3406 fold, the result is the number of the last line in that fold.
3407 If the line {lnum} is not in a closed fold, -1 is returned.
3408 {lnum} is used like with |getline()|. Thus "." is the current
3409 line, "'m" mark m, etc.
3410
3411 Can also be used as a |method|: >
3412 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003413<
3414 Return type: |Number|
3415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003416
3417foldlevel({lnum}) *foldlevel()*
3418 The result is a Number, which is the foldlevel of line {lnum}
3419 in the current buffer. For nested folds the deepest level is
3420 returned. If there is no fold at line {lnum}, zero is
3421 returned. It doesn't matter if the folds are open or closed.
3422 When used while updating folds (from 'foldexpr') -1 is
3423 returned for lines where folds are still to be updated and the
3424 foldlevel is unknown. As a special case the level of the
3425 previous line is usually available.
3426 {lnum} is used like with |getline()|. Thus "." is the current
3427 line, "'m" mark m, etc.
3428
3429 Can also be used as a |method|: >
3430 GetLnum()->foldlevel()
3431<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003432 Return type: |Number|
3433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003434 *foldtext()*
3435foldtext() Returns a String, to be displayed for a closed fold. This is
3436 the default function used for the 'foldtext' option and should
3437 only be called from evaluating 'foldtext'. It uses the
3438 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3439 The returned string looks like this: >
3440 +-- 45 lines: abcdef
3441< The number of leading dashes depends on the foldlevel. The
3442 "45" is the number of lines in the fold. "abcdef" is the text
3443 in the first non-blank line of the fold. Leading white space,
3444 "//" or "/*" and the text from the 'foldmarker' and
3445 'commentstring' options is removed.
3446 When used to draw the actual foldtext, the rest of the line
3447 will be filled with the fold char from the 'fillchars'
3448 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003449 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003450
3451 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003452 {not available when compiled without the |+folding| feature}
3453
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003454
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003455foldtextresult({lnum}) *foldtextresult()*
3456 Returns the text that is displayed for the closed fold at line
3457 {lnum}. Evaluates 'foldtext' in the appropriate context.
3458 When there is no closed fold at {lnum} an empty string is
3459 returned.
3460 {lnum} is used like with |getline()|. Thus "." is the current
3461 line, "'m" mark m, etc.
3462 Useful when exporting folded text, e.g., to HTML.
3463 {not available when compiled without the |+folding| feature}
3464
3465
3466 Can also be used as a |method|: >
3467 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003468<
3469 Return type: |String|
3470
Ernie Raele79e2072024-01-13 11:47:33 +01003471
3472foreach({expr1}, {expr2}) *foreach()*
3473 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3474 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003475 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003476 See |map()| and |filter()| to modify {expr1}.
3477
3478 {expr2} must be a |string| or |Funcref|.
3479
3480 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3481 of the current item. For a |Dictionary| |v:key| has the key
3482 of the current item and for a |List| |v:key| has the index of
3483 the current item. For a |Blob| |v:key| has the index of the
3484 current byte. For a |String| |v:key| has the index of the
3485 current character.
3486 Examples: >
3487 call foreach(mylist, 'used[v:val] = true')
3488< This records the items that are in the {expr1} list.
3489
3490 Note that {expr2} is the result of expression and is then used
3491 as a command. Often it is good to use a |literal-string| to
3492 avoid having to double backslashes.
3493
3494 If {expr2} is a |Funcref| it must take two arguments:
3495 1. the key or the index of the current item.
3496 2. the value of the current item.
3497 With a legacy script lambda you don't get an error if it only
3498 accepts one argument, but with a Vim9 lambda you get "E1106:
3499 One argument too many", the number of arguments must match.
3500 If the function returns a value, it is ignored.
3501
3502 Returns {expr1} in all cases.
3503 When an error is encountered while executing {expr2} no
3504 further items in {expr1} are processed.
3505 When {expr2} is a Funcref errors inside a function are ignored,
3506 unless it was defined with the "abort" flag.
3507
3508 Can also be used as a |method|: >
3509 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003510<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003511 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3512 depending on {expr1}
3513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003514 *foreground()*
3515foreground() Move the Vim window to the foreground. Useful when sent from
3516 a client to a Vim server. |remote_send()|
3517 On Win32 systems this might not work, the OS does not always
3518 allow a window to bring itself to the foreground. Use
3519 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003520
3521 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003522 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003523 Win32 console version}
3524
Bram Moolenaaraa534142022-09-15 21:46:02 +01003525fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003526 Get the full command name from a short abbreviated command
3527 name; see |20.2| for details on command abbreviations.
3528
3529 The string argument {name} may start with a `:` and can
3530 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003531 Returns an empty string if a command doesn't exist, if it's
3532 ambiguous (for user-defined commands) or cannot be shortened
3533 this way. |vim9-no-shorten|
3534
3535 Without the {vim9} argument uses the current script version.
3536 If {vim9} is present and FALSE then legacy script rules are
3537 used. When {vim9} is present and TRUE then Vim9 rules are
3538 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003539
3540 For example `fullcommand('s')`, `fullcommand('sub')`,
3541 `fullcommand(':%substitute')` all return "substitute".
3542
3543 Can also be used as a |method|: >
3544 GetName()->fullcommand()
3545<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003546 Return type: |String|
3547
3548
3549funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003550 Just like |function()|, but the returned Funcref will lookup
3551 the function by reference, not by name. This matters when the
3552 function {name} is redefined later.
3553
3554 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003555 It only works for an autoloaded function if it has already
3556 been loaded (to avoid mistakenly loading the autoload script
3557 when only intending to use the function name, use |function()|
3558 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003559 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003560
3561 Can also be used as a |method|: >
3562 GetFuncname()->funcref([arg])
3563<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003564 Return type: func(...): any or |Number| on error
3565
Dominique Pellee764d1b2023-03-12 21:20:59 +00003566 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003567function({name} [, {arglist}] [, {dict}])
3568 Return a |Funcref| variable that refers to function {name}.
3569 {name} can be the name of a user defined function or an
3570 internal function.
3571
3572 {name} can also be a Funcref or a partial. When it is a
3573 partial the dict stored in it will be used and the {dict}
3574 argument is not allowed. E.g.: >
3575 let FuncWithArg = function(dict.Func, [arg])
3576 let Broken = function(dict.Func, [arg], dict)
3577<
3578 When using the Funcref the function will be found by {name},
3579 also when it was redefined later. Use |funcref()| to keep the
3580 same function.
3581
3582 When {arglist} or {dict} is present this creates a partial.
3583 That means the argument list and/or the dictionary is stored in
3584 the Funcref and will be used when the Funcref is called.
3585
3586 The arguments are passed to the function in front of other
3587 arguments, but after any argument from |method|. Example: >
3588 func Callback(arg1, arg2, name)
3589 ...
3590 let Partial = function('Callback', ['one', 'two'])
3591 ...
3592 call Partial('name')
3593< Invokes the function as with: >
3594 call Callback('one', 'two', 'name')
3595
3596< With a |method|: >
3597 func Callback(one, two, three)
3598 ...
3599 let Partial = function('Callback', ['two'])
3600 ...
3601 eval 'one'->Partial('three')
3602< Invokes the function as with: >
3603 call Callback('one', 'two', 'three')
3604
3605< The function() call can be nested to add more arguments to the
3606 Funcref. The extra arguments are appended to the list of
3607 arguments. Example: >
3608 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003609 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003610 let Func = function('Callback', ['one'])
3611 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003612 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003613 call Func2('name')
3614< Invokes the function as with: >
3615 call Callback('one', 'two', 'name')
3616
3617< The Dictionary is only useful when calling a "dict" function.
3618 In that case the {dict} is passed in as "self". Example: >
3619 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003620 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003621 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003622 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003623 let context = {"name": "example"}
3624 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003625 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003626 call Func() " will echo: called for example
3627< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003628 arguments, these two are equivalent, if Callback() is defined
3629 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003630 let Func = function('Callback', context)
3631 let Func = context.Callback
3632
3633< The argument list and the Dictionary can be combined: >
3634 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003635 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003636 let context = {"name": "example"}
3637 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003638 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003639 call Func(500)
3640< Invokes the function as with: >
3641 call context.Callback('one', 500)
3642<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003643 Returns 0 on error.
3644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003645 Can also be used as a |method|: >
3646 GetFuncname()->function([arg])
3647
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003648<
3649 Return type: func(...): any or |Number| on error
3650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003651
3652garbagecollect([{atexit}]) *garbagecollect()*
3653 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3654 that have circular references.
3655
3656 There is hardly ever a need to invoke this function, as it is
3657 automatically done when Vim runs out of memory or is waiting
3658 for the user to press a key after 'updatetime'. Items without
3659 circular references are always freed when they become unused.
3660 This is useful if you have deleted a very big |List| and/or
3661 |Dictionary| with circular references in a script that runs
3662 for a long time.
3663
3664 When the optional {atexit} argument is one, garbage
3665 collection will also be done when exiting Vim, if it wasn't
3666 done before. This is useful when checking for memory leaks.
3667
3668 The garbage collection is not done immediately but only when
3669 it's safe to perform. This is when waiting for the user to
3670 type a character. To force garbage collection immediately use
3671 |test_garbagecollect_now()|.
3672
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003673 Return type: |String|
3674
3675
LemonBoy48b7d052024-07-09 18:24:59 +02003676get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003677 Get item {idx} from |List| {list}. When this item is not
3678 available return {default}. Return zero when {default} is
3679 omitted.
3680 Preferably used as a |method|: >
3681 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003682<
3683 Return type: any, depending on {list}
3684
LemonBoy48b7d052024-07-09 18:24:59 +02003685get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003686 Get byte {idx} from |Blob| {blob}. When this byte is not
3687 available return {default}. Return -1 when {default} is
3688 omitted.
3689 Preferably used as a |method|: >
3690 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003691<
3692 Return type: |Number|
3693
LemonBoy48b7d052024-07-09 18:24:59 +02003694get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003695 Get item with key {key} from |Dictionary| {dict}. When this
3696 item is not available return {default}. Return zero when
3697 {default} is omitted. Useful example: >
3698 let val = get(g:, 'var_name', 'default')
3699< This gets the value of g:var_name if it exists, and uses
3700 'default' when it does not exist.
3701 Preferably used as a |method|: >
3702 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003703<
h-east84ac2122024-06-17 18:12:30 +02003704 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003705
LemonBoy48b7d052024-07-09 18:24:59 +02003706get({func}, {what}) *get()-func*
3707 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003708 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003709 "name" The function name
3710 "func" The function
3711 "dict" The dictionary
3712 "args" The list with arguments
3713 "arity" A dictionary with information about the number of
3714 arguments accepted by the function (minus the
3715 {arglist}) with the following fields:
3716 required the number of positional arguments
3717 optional the number of optional arguments,
3718 in addition to the required ones
3719 varargs |TRUE| if the function accepts a
3720 variable number of arguments |...|
3721
3722 Note: There is no error, if the {arglist} of
3723 the Funcref contains more arguments than the
3724 Funcref expects, it's not validated.
3725
Bram Moolenaar016188f2022-06-06 20:52:59 +01003726 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003727
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003728 Preferably used as a |method|: >
3729 myfunc->get(what)
3730<
LemonBoy48b7d052024-07-09 18:24:59 +02003731 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003733 *getbufinfo()*
3734getbufinfo([{buf}])
3735getbufinfo([{dict}])
3736 Get information about buffers as a List of Dictionaries.
3737
3738 Without an argument information about all the buffers is
3739 returned.
3740
3741 When the argument is a |Dictionary| only the buffers matching
3742 the specified criteria are returned. The following keys can
3743 be specified in {dict}:
3744 buflisted include only listed buffers.
3745 bufloaded include only loaded buffers.
3746 bufmodified include only modified buffers.
3747
3748 Otherwise, {buf} specifies a particular buffer to return
3749 information for. For the use of {buf}, see |bufname()|
3750 above. If the buffer is found the returned List has one item.
3751 Otherwise the result is an empty list.
3752
3753 Each returned List item is a dictionary with the following
3754 entries:
3755 bufnr Buffer number.
3756 changed TRUE if the buffer is modified.
3757 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003758 command TRUE if the buffer belongs to the
3759 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003760 hidden TRUE if the buffer is hidden.
3761 lastused Timestamp in seconds, like
3762 |localtime()|, when the buffer was
3763 last used.
3764 {only with the |+viminfo| feature}
3765 listed TRUE if the buffer is listed.
3766 lnum Line number used for the buffer when
3767 opened in the current window.
3768 Only valid if the buffer has been
3769 displayed in the window in the past.
3770 If you want the line number of the
3771 last known cursor position in a given
3772 window, use |line()|: >
3773 :echo line('.', {winid})
3774<
3775 linecount Number of lines in the buffer (only
3776 valid when loaded)
3777 loaded TRUE if the buffer is loaded.
3778 name Full path to the file in the buffer.
3779 signs List of signs placed in the buffer.
3780 Each list item is a dictionary with
3781 the following fields:
3782 id sign identifier
3783 lnum line number
3784 name sign name
3785 variables A reference to the dictionary with
3786 buffer-local variables.
3787 windows List of |window-ID|s that display this
3788 buffer
3789 popups List of popup |window-ID|s that
3790 display this buffer
3791
3792 Examples: >
3793 for buf in getbufinfo()
3794 echo buf.name
3795 endfor
3796 for buf in getbufinfo({'buflisted':1})
3797 if buf.changed
3798 ....
3799 endif
3800 endfor
3801<
3802 To get buffer-local options use: >
3803 getbufvar({bufnr}, '&option_name')
3804<
3805 Can also be used as a |method|: >
3806 GetBufnr()->getbufinfo()
3807<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003808 Return type: list<dict<any>>
3809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003810
3811 *getbufline()*
3812getbufline({buf}, {lnum} [, {end}])
3813 Return a |List| with the lines starting from {lnum} to {end}
3814 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003815 |List| with only the line {lnum} is returned. See
3816 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003817
3818 For the use of {buf}, see |bufname()| above.
3819
3820 For {lnum} and {end} "$" can be used for the last line of the
3821 buffer. Otherwise a number must be used.
3822
3823 When {lnum} is smaller than 1 or bigger than the number of
3824 lines in the buffer, an empty |List| is returned.
3825
3826 When {end} is greater than the number of lines in the buffer,
3827 it is treated as {end} is set to the number of lines in the
3828 buffer. When {end} is before {lnum} an empty |List| is
3829 returned.
3830
3831 This function works only for loaded buffers. For unloaded and
3832 non-existing buffers, an empty |List| is returned.
3833
3834 Example: >
3835 :let lines = getbufline(bufnr("myfile"), 1, "$")
3836
3837< Can also be used as a |method|: >
3838 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003839<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003840 Return type: list<string>
3841
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003842 *getbufoneline()*
3843getbufoneline({buf}, {lnum})
3844 Just like `getbufline()` but only get one line and return it
3845 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003846
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003847 Return type: |String|
3848
3849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003850getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3851 The result is the value of option or local buffer variable
3852 {varname} in buffer {buf}. Note that the name without "b:"
3853 must be used.
3854 The {varname} argument is a string.
3855 When {varname} is empty returns a |Dictionary| with all the
3856 buffer-local variables.
3857 When {varname} is equal to "&" returns a |Dictionary| with all
3858 the buffer-local options.
3859 Otherwise, when {varname} starts with "&" returns the value of
3860 a buffer-local option.
3861 This also works for a global or buffer-local option, but it
3862 doesn't work for a global variable, window-local variable or
3863 window-local option.
3864 For the use of {buf}, see |bufname()| above.
3865 When the buffer or variable doesn't exist {def} or an empty
3866 string is returned, there is no error message.
3867 Examples: >
3868 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003869 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003870
3871< Can also be used as a |method|: >
3872 GetBufnr()->getbufvar(varname)
3873<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003874 Return type: any, depending on {varname}
3875
3876
mikoto20001083cae2024-11-11 21:24:14 +01003877getcellpixels() *getcellpixels()*
3878 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003879 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003880
3881 Only works on Unix (terminal and gVim) and Windows (gVim only).
3882 Returns [] on other systems or on failure.
3883 Note that there could be variations across different terminals.
3884 On macOS, system Terminal.app returns sizes in points (before
3885 Retina scaling), whereas third-party terminals return raw pixel
3886 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003887
mikoto2000de094dc2024-11-14 22:13:48 +01003888 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003889
3890
Kota Kato66bb9ae2023-01-17 18:31:56 +00003891getcellwidths() *getcellwidths()*
3892 Returns a |List| of cell widths of character ranges overridden
3893 by |setcellwidths()|. The format is equal to the argument of
3894 |setcellwidths()|. If no character ranges have their cell
3895 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003896
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003897 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003898
3899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003900getchangelist([{buf}]) *getchangelist()*
3901 Returns the |changelist| for the buffer {buf}. For the use
3902 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3903 exist, an empty list is returned.
3904
3905 The returned list contains two entries: a list with the change
3906 locations and the current position in the list. Each
3907 entry in the change list is a dictionary with the following
3908 entries:
3909 col column number
3910 coladd column offset for 'virtualedit'
3911 lnum line number
3912 If buffer {buf} is the current buffer, then the current
3913 position refers to the position in the list. For other
3914 buffers, it is set to the length of the list.
3915
3916 Can also be used as a |method|: >
3917 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003918<
3919 Return type: list<any>
3920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003921
zeertzjqe0a2ab32025-02-02 09:14:35 +01003922getchar([{expr} [, {opts}]]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003923 Get a single character from the user or input stream.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003924 If {expr} is omitted or is -1, wait until a character is
3925 available.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003926 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003927 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003928 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003929 not consumed. Return zero if no character available.
zeertzjqe0a2ab32025-02-02 09:14:35 +01003930 If you prefer always getting a string use |getcharstr()|, or
3931 specify |FALSE| as "number" in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003932
Doug Kearns9cd9e752024-04-07 17:42:17 +02003933 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003934 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003935 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003936 Otherwise a String is returned with the encoded character.
3937 For a special key it's a String with a sequence of bytes
3938 starting with 0x80 (decimal: 128). This is the same value as
3939 the String "\<Key>", e.g., "\<Left>". The returned value is
3940 also a String when a modifier (shift, control, alt) was used
zeertzjqe0a2ab32025-02-02 09:14:35 +01003941 that is not included in the character. |keytrans()| can also
3942 be used to convert a returned String into a readable form.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003943
Doug Kearns9cd9e752024-04-07 17:42:17 +02003944 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003945 while Vim waits to see if this is the start of an escape
3946 sequence.
3947
Doug Kearns9cd9e752024-04-07 17:42:17 +02003948 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003949 one-byte character it is the character itself as a number.
3950 Use nr2char() to convert it to a String.
3951
3952 Use getcharmod() to obtain any additional modifiers.
3953
zeertzjqe0a2ab32025-02-02 09:14:35 +01003954 The optional argument {opts} is a Dict and supports the
3955 following items:
3956
zeertzjqedf0f7d2025-02-02 19:01:01 +01003957 cursor A String specifying cursor behavior
3958 when waiting for a character.
3959 "hide": hide the cursor.
3960 "keep": keep current cursor unchanged.
3961 "msg": move cursor to message area.
3962 (default: "msg")
3963
zeertzjqe0a2ab32025-02-02 09:14:35 +01003964 number If |TRUE|, return a Number when getting
3965 a single character.
3966 If |FALSE|, the return value is always
3967 converted to a String, and an empty
3968 String (instead of 0) is returned when
3969 no character is available.
3970 (default: |TRUE|)
3971
3972 simplify If |TRUE|, include modifiers in the
3973 character if possible. E.g., return
3974 the same value for CTRL-I and <Tab>.
3975 If |FALSE|, don't include modifiers in
3976 the character.
3977 (default: |TRUE|)
3978
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003979 When the user clicks a mouse button, the mouse event will be
3980 returned. The position can then be found in |v:mouse_col|,
3981 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3982 |getmousepos()| can also be used. Mouse move events will be
3983 ignored.
3984 This example positions the mouse as it would normally happen: >
3985 let c = getchar()
3986 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003987 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003988 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003989 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003990 endif
3991<
3992 When using bracketed paste only the first character is
3993 returned, the rest of the pasted text is dropped.
3994 |xterm-bracketed-paste|.
3995
3996 There is no prompt, you will somehow have to make clear to the
3997 user that a character has to be typed. The screen is not
3998 redrawn, e.g. when resizing the window. When using a popup
3999 window it should work better with a |popup-filter|.
4000
4001 There is no mapping for the character.
4002 Key codes are replaced, thus when the user presses the <Del>
4003 key you get the code for the <Del> key, not the raw character
4004 sequence. Examples: >
4005 getchar() == "\<Del>"
4006 getchar() == "\<S-Left>"
4007< This example redefines "f" to ignore case: >
4008 :nmap f :call FindChar()<CR>
4009 :function FindChar()
4010 : let c = nr2char(getchar())
4011 : while col('.') < col('$') - 1
4012 : normal l
4013 : if getline('.')[col('.') - 1] ==? c
4014 : break
4015 : endif
4016 : endwhile
4017 :endfunction
4018<
4019 You may also receive synthetic characters, such as
4020 |<CursorHold>|. Often you will want to ignore this and get
4021 another character: >
4022 :function GetKey()
4023 : let c = getchar()
4024 : while c == "\<CursorHold>"
4025 : let c = getchar()
4026 : endwhile
4027 : return c
4028 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004029<
4030 Return type: |Number| or |String|
4031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004032
4033getcharmod() *getcharmod()*
4034 The result is a Number which is the state of the modifiers for
4035 the last obtained character with getchar() or in another way.
4036 These values are added together:
4037 2 shift
4038 4 control
4039 8 alt (meta)
4040 16 meta (when it's different from ALT)
4041 32 mouse double click
4042 64 mouse triple click
4043 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004044 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004045 Only the modifiers that have not been included in the
4046 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004047 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004048
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004049 Return type: |Number|
4050
4051
4052getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004053 Get the position for String {expr}. Same as |getpos()| but the
4054 column number in the returned List is a character index
4055 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004056 If |getpos()| returns a very large column number, equal to
4057 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004058 of the last character.
4059
4060 Example:
4061 With the cursor on '세' in line 5 with text "여보세요": >
4062 getcharpos('.') returns [0, 5, 3, 0]
4063 getpos('.') returns [0, 5, 7, 0]
4064<
4065 Can also be used as a |method|: >
4066 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004067<
4068 Return type: list<number>
4069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004070
4071getcharsearch() *getcharsearch()*
4072 Return the current character search information as a {dict}
4073 with the following entries:
4074
4075 char character previously used for a character
4076 search (|t|, |f|, |T|, or |F|); empty string
4077 if no character search has been performed
4078 forward direction of character search; 1 for forward,
4079 0 for backward
4080 until type of character search; 1 for a |t| or |T|
4081 character search, 0 for an |f| or |F|
4082 character search
4083
4084 This can be useful to always have |;| and |,| search
4085 forward/backward regardless of the direction of the previous
4086 character search: >
4087 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4088 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4089< Also see |setcharsearch()|.
4090
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004091 Return type: dict<any>
4092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004093
zeertzjqe0a2ab32025-02-02 09:14:35 +01004094getcharstr([{expr} [, {opts}]]) *getcharstr()*
4095 The same as |getchar()|, except that this always returns a
4096 String, and "number" isn't allowed in {opts}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004098 Return type: |String|
4099
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004100getcmdcomplpat() *getcmdcomplpat()*
4101 Return completion pattern of the current command-line.
4102 Only works when the command line is being edited, thus
4103 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4104 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4105 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4106 Returns an empty string when completion is not defined.
4107
4108 Return type: |String|
4109
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004110
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004111getcmdcompltype() *getcmdcompltype()*
4112 Return the type of the current command-line completion.
4113 Only works when the command line is being edited, thus
4114 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004115 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004116 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004117 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004118 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004119
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004120 Return type: |String|
4121
4122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004123getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004124 Return the current command-line input. Only works when the
4125 command line is being edited, thus requires use of
4126 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004127 Example: >
4128 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004129< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4130 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004131 Returns an empty string when entering a password or using
4132 |inputsecret()|.
4133
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004134 Return type: |String|
4135
4136
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004137getcmdpos() *getcmdpos()*
4138 Return the position of the cursor in the command line as a
4139 byte count. The first column is 1.
4140 Only works when editing the command line, thus requires use of
4141 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4142 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004143 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4144 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004145
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004146 Return type: |Number|
4147
4148
Shougo Matsushita69084282024-09-23 20:34:47 +02004149getcmdprompt() *getcmdprompt()*
4150 Return the current command-line prompt when using functions
4151 like |input()| or |confirm()|.
4152 Only works when the command line is being edited, thus
4153 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4154 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4155 |setcmdpos()| and |setcmdline()|.
4156
4157 Return type: |String|
4158
4159
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004160getcmdscreenpos() *getcmdscreenpos()*
4161 Return the screen position of the cursor in the command line
4162 as a byte count. The first column is 1.
4163 Instead of |getcmdpos()|, it adds the prompt position.
4164 Only works when editing the command line, thus requires use of
4165 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4166 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004167 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4168 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004169
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004170 Return type: |Number|
4171
4172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004173getcmdtype() *getcmdtype()*
4174 Return the current command-line type. Possible return values
4175 are:
4176 : normal Ex command
4177 > debug mode command |debug-mode|
4178 / forward search command
4179 ? backward search command
4180 @ |input()| command
4181 - |:insert| or |:append| command
4182 = |i_CTRL-R_=|
4183 Only works when editing the command line, thus requires use of
4184 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4185 Returns an empty string otherwise.
4186 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4187
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004188 Return type: |String|
4189
4190
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004191getcmdwintype() *getcmdwintype()*
4192 Return the current |command-line-window| type. Possible return
4193 values are the same as |getcmdtype()|. Returns an empty string
4194 when not in the command-line window.
4195
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004196 Return type: |String|
4197
4198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004199getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4200 Return a list of command-line completion matches. The String
4201 {type} argument specifies what for. The following completion
4202 types are supported:
4203
4204 arglist file names in argument list
4205 augroup autocmd groups
4206 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004207 behave |:behave| suboptions
4208 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004209 color color schemes
4210 command Ex command
4211 cmdline |cmdline-completion| result
4212 compiler compilers
4213 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004214 custom,{func} custom completion, defined via {func}
4215 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004216 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004217 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004218 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004219 environment environment variable names
4220 event autocommand events
4221 expression Vim expression
4222 file file and directory names
4223 file_in_path file and directory names in |'path'|
4224 filetype filetype names |'filetype'|
4225 function function name
4226 help help subjects
4227 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004228 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004229 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004230 locale locale names (as output of locale -a)
4231 mapclear buffer argument
4232 mapping mapping name
4233 menu menus
4234 messages |:messages| suboptions
4235 option options
4236 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004237 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004238 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004239 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004240 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004241 sign |:sign| suboptions
4242 syntax syntax file names |'syntax'|
4243 syntime |:syntime| suboptions
4244 tag tags
4245 tag_listfiles tags, file names
4246 user user names
4247 var user variables
4248
4249 If {pat} is an empty string, then all the matches are
4250 returned. Otherwise only items matching {pat} are returned.
4251 See |wildcards| for the use of special characters in {pat}.
4252
4253 If the optional {filtered} flag is set to 1, then 'wildignore'
4254 is applied to filter the results. Otherwise all the matches
4255 are returned. The 'wildignorecase' option always applies.
4256
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004257 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4258 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004259 regular expression matching is used. Thus this function
4260 follows the user preference, what happens on the command line.
4261 If you do not want this you can make 'wildoptions' empty
4262 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004264 If {type} is "cmdline", then the |cmdline-completion| result is
4265 returned. For example, to complete the possible values after
4266 a ":call" command: >
4267 echo getcompletion('call ', 'cmdline')
4268<
4269 If there are no matches, an empty list is returned. An
4270 invalid value for {type} produces an error.
4271
4272 Can also be used as a |method|: >
4273 GetPattern()->getcompletion('color')
4274<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004275 Return type: list<string>
4276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004277 *getcurpos()*
4278getcurpos([{winid}])
4279 Get the position of the cursor. This is like getpos('.'), but
4280 includes an extra "curswant" item in the list:
4281 [0, lnum, col, off, curswant] ~
4282 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004283 cursor vertically. After |$| command it will be a very large
4284 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004285 |getpos()|.
4286 The first "bufnum" item is always zero. The byte position of
4287 the cursor is returned in 'col'. To get the character
4288 position, use |getcursorcharpos()|.
4289
4290 The optional {winid} argument can specify the window. It can
4291 be the window number or the |window-ID|. The last known
4292 cursor position is returned, this may be invalid for the
4293 current value of the buffer if it is not the current window.
4294 If {winid} is invalid a list with zeroes is returned.
4295
4296 This can be used to save and restore the cursor position: >
4297 let save_cursor = getcurpos()
4298 MoveTheCursorAround
4299 call setpos('.', save_cursor)
4300< Note that this only works within the window. See
4301 |winrestview()| for restoring more state.
4302
4303 Can also be used as a |method|: >
4304 GetWinid()->getcurpos()
4305<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004306 Return type: list<number>
4307
4308
4309getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004310 Same as |getcurpos()| but the column number in the returned
4311 List is a character index instead of a byte index.
4312
4313 Example:
4314 With the cursor on '보' in line 3 with text "여보세요": >
4315 getcursorcharpos() returns [0, 3, 2, 0, 3]
4316 getcurpos() returns [0, 3, 4, 0, 3]
4317<
4318 Can also be used as a |method|: >
4319 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004320<
4321 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004323
4324getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004325 The result is a String, which is the name of the current
4326 working directory. 'autochdir' is ignored.
4327
4328 With {winnr} return the local current directory of this window
4329 in the current tab page. {winnr} can be the window number or
4330 the |window-ID|.
4331 If {winnr} is -1 return the name of the global working
4332 directory. See also |haslocaldir()|.
4333
4334 With {winnr} and {tabnr} return the local current directory of
4335 the window in the specified tab page. If {winnr} is -1 return
4336 the working directory of the tabpage.
4337 If {winnr} is zero use the current window, if {tabnr} is zero
4338 use the current tabpage.
4339 Without any arguments, return the actual working directory of
4340 the current window.
4341 Return an empty string if the arguments are invalid.
4342
4343 Examples: >
4344 " Get the working directory of the current window
4345 :echo getcwd()
4346 :echo getcwd(0)
4347 :echo getcwd(0, 0)
4348 " Get the working directory of window 3 in tabpage 2
4349 :echo getcwd(3, 2)
4350 " Get the global working directory
4351 :echo getcwd(-1)
4352 " Get the working directory of tabpage 3
4353 :echo getcwd(-1, 3)
4354 " Get the working directory of current tabpage
4355 :echo getcwd(-1, 0)
4356
4357< Can also be used as a |method|: >
4358 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004359<
4360 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004361
4362getenv({name}) *getenv()*
4363 Return the value of environment variable {name}. The {name}
4364 argument is a string, without a leading '$'. Example: >
4365 myHome = getenv('HOME')
4366
4367< When the variable does not exist |v:null| is returned. That
4368 is different from a variable set to an empty string, although
4369 some systems interpret the empty value as the variable being
4370 deleted. See also |expr-env|.
4371
4372 Can also be used as a |method|: >
4373 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004374<
4375 Return type: |String| or |Number|
4376
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004377
4378getfontname([{name}]) *getfontname()*
4379 Without an argument returns the name of the normal font being
4380 used. Like what is used for the Normal highlight group
4381 |hl-Normal|.
4382 With an argument a check is done whether String {name} is a
4383 valid font name. If not then an empty string is returned.
4384 Otherwise the actual font name is returned, or {name} if the
4385 GUI does not support obtaining the real name.
4386 Only works when the GUI is running, thus not in your vimrc or
4387 gvimrc file. Use the |GUIEnter| autocommand to use this
4388 function just after the GUI has started.
4389 Note that the GTK GUI accepts any font name, thus checking for
4390 a valid name does not work.
4391
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004392 Return type: |String|
4393
4394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004395getfperm({fname}) *getfperm()*
4396 The result is a String, which is the read, write, and execute
4397 permissions of the given file {fname}.
4398 If {fname} does not exist or its directory cannot be read, an
4399 empty string is returned.
4400 The result is of the form "rwxrwxrwx", where each group of
4401 "rwx" flags represent, in turn, the permissions of the owner
4402 of the file, the group the file belongs to, and other users.
4403 If a user does not have a given permission the flag for this
4404 is replaced with the string "-". Examples: >
4405 :echo getfperm("/etc/passwd")
4406 :echo getfperm(expand("~/.vimrc"))
4407< This will hopefully (from a security point of view) display
4408 the string "rw-r--r--" or even "rw-------".
4409
4410 Can also be used as a |method|: >
4411 GetFilename()->getfperm()
4412<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004413 Return type: |String|
4414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004415 For setting permissions use |setfperm()|.
4416
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004418getfsize({fname}) *getfsize()*
4419 The result is a Number, which is the size in bytes of the
4420 given file {fname}.
4421 If {fname} is a directory, 0 is returned.
4422 If the file {fname} can't be found, -1 is returned.
4423 If the size of {fname} is too big to fit in a Number then -2
4424 is returned.
4425
4426 Can also be used as a |method|: >
4427 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004428<
4429 Return type: |Number|
4430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004431
4432getftime({fname}) *getftime()*
4433 The result is a Number, which is the last modification time of
4434 the given file {fname}. The value is measured as seconds
4435 since 1st Jan 1970, and may be passed to strftime(). See also
4436 |localtime()| and |strftime()|.
4437 If the file {fname} can't be found -1 is returned.
4438
4439 Can also be used as a |method|: >
4440 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004441<
4442 Return type: |Number|
4443
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004444
4445getftype({fname}) *getftype()*
4446 The result is a String, which is a description of the kind of
4447 file of the given file {fname}.
4448 If {fname} does not exist an empty string is returned.
4449 Here is a table over different kinds of files and their
4450 results:
4451 Normal file "file"
4452 Directory "dir"
4453 Symbolic link "link"
4454 Block device "bdev"
4455 Character device "cdev"
4456 Socket "socket"
4457 FIFO "fifo"
4458 All other "other"
4459 Example: >
4460 getftype("/home")
4461< Note that a type such as "link" will only be returned on
4462 systems that support it. On some systems only "dir" and
4463 "file" are returned. On MS-Windows a symbolic link to a
4464 directory returns "dir" instead of "link".
4465
4466 Can also be used as a |method|: >
4467 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004468<
4469 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004470
4471getimstatus() *getimstatus()*
4472 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004473 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004474 See 'imstatusfunc'.
4475
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004476 Return type: |Number|
4477
4478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004479getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4480 Returns the |jumplist| for the specified window.
4481
4482 Without arguments use the current window.
4483 With {winnr} only use this window in the current tab page.
4484 {winnr} can also be a |window-ID|.
4485 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004486 page. If {winnr} or {tabnr} is invalid, an empty list is
4487 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004488
4489 The returned list contains two entries: a list with the jump
4490 locations and the last used jump position number in the list.
4491 Each entry in the jump location list is a dictionary with
4492 the following entries:
4493 bufnr buffer number
4494 col column number
4495 coladd column offset for 'virtualedit'
4496 filename filename if available
4497 lnum line number
4498
4499 Can also be used as a |method|: >
4500 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004501<
4502 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004503
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004504 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004505getline({lnum} [, {end}])
4506 Without {end} the result is a String, which is line {lnum}
4507 from the current buffer. Example: >
4508 getline(1)
4509< When {lnum} is a String that doesn't start with a
4510 digit, |line()| is called to translate the String into a Number.
4511 To get the line under the cursor: >
4512 getline(".")
4513< When {lnum} is a number smaller than 1 or bigger than the
4514 number of lines in the buffer, an empty string is returned.
4515
4516 When {end} is given the result is a |List| where each item is
4517 a line from the current buffer in the range {lnum} to {end},
4518 including line {end}.
4519 {end} is used in the same way as {lnum}.
4520 Non-existing lines are silently omitted.
4521 When {end} is before {lnum} an empty |List| is returned.
4522 Example: >
4523 :let start = line('.')
4524 :let end = search("^$") - 1
4525 :let lines = getline(start, end)
4526
4527< Can also be used as a |method|: >
4528 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004529<
4530 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004531
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004532 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004533 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004534
4535getloclist({nr} [, {what}]) *getloclist()*
4536 Returns a |List| with all the entries in the location list for
4537 window {nr}. {nr} can be the window number or the |window-ID|.
4538 When {nr} is zero the current window is used.
4539
4540 For a location list window, the displayed location list is
4541 returned. For an invalid window number {nr}, an empty list is
4542 returned. Otherwise, same as |getqflist()|.
4543
4544 If the optional {what} dictionary argument is supplied, then
4545 returns the items listed in {what} as a dictionary. Refer to
4546 |getqflist()| for the supported items in {what}.
4547
4548 In addition to the items supported by |getqflist()| in {what},
4549 the following item is supported by |getloclist()|:
4550
4551 filewinid id of the window used to display files
4552 from the location list. This field is
4553 applicable only when called from a
4554 location list window. See
4555 |location-list-file-window| for more
4556 details.
4557
4558 Returns a |Dictionary| with default values if there is no
4559 location list for the window {nr}.
4560 Returns an empty Dictionary if window {nr} does not exist.
4561
4562 Examples (See also |getqflist-examples|): >
4563 :echo getloclist(3, {'all': 0})
4564 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004565<
4566 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004567
4568
4569getmarklist([{buf}]) *getmarklist()*
4570 Without the {buf} argument returns a |List| with information
4571 about all the global marks. |mark|
4572
4573 If the optional {buf} argument is specified, returns the
4574 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004575 see |bufname()|. If {buf} is invalid, an empty list is
4576 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004577
4578 Each item in the returned List is a |Dict| with the following:
4579 mark name of the mark prefixed by "'"
4580 pos a |List| with the position of the mark:
4581 [bufnum, lnum, col, off]
4582 Refer to |getpos()| for more information.
4583 file file name
4584
4585 Refer to |getpos()| for getting information about a specific
4586 mark.
4587
4588 Can also be used as a |method|: >
4589 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004590<
4591 Return type: list<dict<any>> or list<any>
4592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004593
4594getmatches([{win}]) *getmatches()*
4595 Returns a |List| with all matches previously defined for the
4596 current window by |matchadd()| and the |:match| commands.
4597 |getmatches()| is useful in combination with |setmatches()|,
4598 as |setmatches()| can restore a list of matches saved by
4599 |getmatches()|.
4600 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004601 window ID instead of the current window. If {win} is invalid,
4602 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004603 Example: >
4604 :echo getmatches()
4605< [{'group': 'MyGroup1', 'pattern': 'TODO',
4606 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4607 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4608 :let m = getmatches()
4609 :call clearmatches()
4610 :echo getmatches()
4611< [] >
4612 :call setmatches(m)
4613 :echo getmatches()
4614< [{'group': 'MyGroup1', 'pattern': 'TODO',
4615 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4616 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4617 :unlet m
4618<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004619 Return type: list<dict<any>> or list<any>
4620
4621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004622getmousepos() *getmousepos()*
4623 Returns a |Dictionary| with the last known position of the
4624 mouse. This can be used in a mapping for a mouse click or in
4625 a filter of a popup window. The items are:
4626 screenrow screen row
4627 screencol screen column
4628 winid Window ID of the click
4629 winrow row inside "winid"
4630 wincol column inside "winid"
4631 line text line inside "winid"
4632 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004633 coladd offset (in screen columns) from the
4634 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004635 All numbers are 1-based.
4636
4637 If not over a window, e.g. when in the command line, then only
4638 "screenrow" and "screencol" are valid, the others are zero.
4639
4640 When on the status line below a window or the vertical
4641 separator right of a window, the "line" and "column" values
4642 are zero.
4643
4644 When the position is after the text then "column" is the
4645 length of the text in bytes plus one.
4646
4647 If the mouse is over a popup window then that window is used.
4648
4649 When using |getchar()| the Vim variables |v:mouse_lnum|,
4650 |v:mouse_col| and |v:mouse_winid| also provide these values.
4651
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004652 Return type: dict<number>
4653
4654
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004655getmouseshape() *getmouseshape()*
4656 Returns the name of the currently showing mouse pointer.
4657 When the |+mouseshape| feature is not supported or the shape
4658 is unknown an empty string is returned.
4659 This function is mainly intended for testing.
4660
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004661 Return type: |String|
4662
4663
4664getpid() *getpid()*
4665 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004666 On Unix and MS-Windows this is a unique number, until Vim
4667 exits.
4668
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004669 Return type: |Number|
4670
4671
4672getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004673 Get the position for String {expr}.
4674 The accepted values for {expr} are: *E1209*
4675 . The cursor position.
4676 $ The last line in the current buffer.
4677 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004678 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004679 w0 First line visible in current window (one if the
4680 display isn't updated, e.g. in silent Ex mode).
4681 w$ Last line visible in current window (this is one
4682 less than "w0" if no lines are visible).
4683 v When not in Visual mode, returns the cursor
4684 position. In Visual mode, returns the other end
4685 of the Visual area. A good way to think about
4686 this is that in Visual mode "v" and "." complement
4687 each other. While "." refers to the cursor
4688 position, "v" refers to where |v_o| would move the
4689 cursor. As a result, you can use "v" and "."
4690 together to work on all of a selection in
4691 characterwise Visual mode. If the cursor is at
4692 the end of a characterwise Visual area, "v" refers
4693 to the start of the same Visual area. And if the
4694 cursor is at the start of a characterwise Visual
4695 area, "v" refers to the end of the same Visual
4696 area. "v" differs from |'<| and |'>| in that it's
4697 updated right away.
4698 Note that a mark in another file can be used. The line number
4699 then applies to another buffer.
4700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004701 The result is a |List| with four numbers:
4702 [bufnum, lnum, col, off]
4703 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4704 is the buffer number of the mark.
4705 "lnum" and "col" are the position in the buffer. The first
4706 column is 1.
4707 The "off" number is zero, unless 'virtualedit' is used. Then
4708 it is the offset in screen columns from the start of the
4709 character. E.g., a position within a <Tab> or after the last
4710 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004711
4712 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004713 The column number in the returned List is the byte position
4714 within the line. To get the character position in the line,
4715 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004716
4717 Note that for '< and '> Visual mode matters: when it is "V"
4718 (visual line mode) the column of '< is zero and the column of
4719 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004720 A very large column number equal to |v:maxcol| can be returned,
4721 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004722 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004724 This can be used to save and restore the position of a mark: >
4725 let save_a_mark = getpos("'a")
4726 ...
4727 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004728<
4729 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004730
4731 Can also be used as a |method|: >
4732 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004733<
4734 Return type: list<number>
4735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004736
4737getqflist([{what}]) *getqflist()*
4738 Returns a |List| with all the current quickfix errors. Each
4739 list item is a dictionary with these entries:
4740 bufnr number of buffer that has the file name, use
4741 bufname() to get the name
4742 module module name
4743 lnum line number in the buffer (first line is 1)
4744 end_lnum
4745 end of line number if the item is multiline
4746 col column number (first column is 1)
4747 end_col end of column number if the item has range
4748 vcol |TRUE|: "col" is visual column
4749 |FALSE|: "col" is byte index
4750 nr error number
h-east84ac2122024-06-17 18:12:30 +02004751 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004752 text description of the error
4753 type type of the error, 'E', '1', etc.
4754 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004755 user_data
4756 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004757 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004758
4759 When there is no error list or it's empty, an empty list is
4760 returned. Quickfix list entries with a non-existing buffer
4761 number are returned with "bufnr" set to zero (Note: some
4762 functions accept buffer number zero for the alternate buffer,
4763 you may need to explicitly check for zero).
4764
4765 Useful application: Find pattern matches in multiple files and
4766 do something with them: >
4767 :vimgrep /theword/jg *.c
4768 :for d in getqflist()
4769 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4770 :endfor
4771<
4772 If the optional {what} dictionary argument is supplied, then
4773 returns only the items listed in {what} as a dictionary. The
4774 following string items are supported in {what}:
4775 changedtick get the total number of changes made
4776 to the list |quickfix-changedtick|
4777 context get the |quickfix-context|
4778 efm errorformat to use when parsing "lines". If
4779 not present, then the 'errorformat' option
4780 value is used.
4781 id get information for the quickfix list with
4782 |quickfix-ID|; zero means the id for the
4783 current list or the list specified by "nr"
4784 idx get information for the quickfix entry at this
4785 index in the list specified by 'id' or 'nr'.
4786 If set to zero, then uses the current entry.
4787 See |quickfix-index|
4788 items quickfix list entries
4789 lines parse a list of lines using 'efm' and return
4790 the resulting entries. Only a |List| type is
4791 accepted. The current quickfix list is not
4792 modified. See |quickfix-parse|.
4793 nr get information for this quickfix list; zero
4794 means the current quickfix list and "$" means
4795 the last quickfix list
4796 qfbufnr number of the buffer displayed in the quickfix
4797 window. Returns 0 if the quickfix buffer is
4798 not present. See |quickfix-buffer|.
4799 size number of entries in the quickfix list
4800 title get the list title |quickfix-title|
4801 winid get the quickfix |window-ID|
4802 all all of the above quickfix properties
4803 Non-string items in {what} are ignored. To get the value of a
4804 particular item, set it to zero.
4805 If "nr" is not present then the current quickfix list is used.
4806 If both "nr" and a non-zero "id" are specified, then the list
4807 specified by "id" is used.
4808 To get the number of lists in the quickfix stack, set "nr" to
4809 "$" in {what}. The "nr" value in the returned dictionary
4810 contains the quickfix stack size.
4811 When "lines" is specified, all the other items except "efm"
4812 are ignored. The returned dictionary contains the entry
4813 "items" with the list of entries.
4814
4815 The returned dictionary contains the following entries:
4816 changedtick total number of changes made to the
4817 list |quickfix-changedtick|
4818 context quickfix list context. See |quickfix-context|
4819 If not present, set to "".
4820 id quickfix list ID |quickfix-ID|. If not
4821 present, set to 0.
4822 idx index of the quickfix entry in the list. If not
4823 present, set to 0.
4824 items quickfix list entries. If not present, set to
4825 an empty list.
4826 nr quickfix list number. If not present, set to 0
4827 qfbufnr number of the buffer displayed in the quickfix
4828 window. If not present, set to 0.
4829 size number of entries in the quickfix list. If not
4830 present, set to 0.
4831 title quickfix list title text. If not present, set
4832 to "".
4833 winid quickfix |window-ID|. If not present, set to 0
4834
4835 Examples (See also |getqflist-examples|): >
4836 :echo getqflist({'all': 1})
4837 :echo getqflist({'nr': 2, 'title': 1})
4838 :echo getqflist({'lines' : ["F1:10:L10"]})
4839<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004840 Return type: list<dict<any>> or list<any>
4841
4842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004843getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4844 The result is a String, which is the contents of register
4845 {regname}. Example: >
4846 :let cliptext = getreg('*')
4847< When register {regname} was not set the result is an empty
4848 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004849 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004850
4851 getreg('=') returns the last evaluated value of the expression
4852 register. (For use in maps.)
4853 getreg('=', 1) returns the expression itself, so that it can
4854 be restored with |setreg()|. For other registers the extra
4855 argument is ignored, thus you can always give it.
4856
4857 If {list} is present and |TRUE|, the result type is changed
4858 to |List|. Each list item is one text line. Use it if you care
4859 about zero bytes possibly present inside register: without
4860 third argument both NLs and zero bytes are represented as NLs
4861 (see |NL-used-for-Nul|).
4862 When the register was not set an empty list is returned.
4863
4864 If {regname} is "", the unnamed register '"' is used.
4865 If {regname} is not specified, |v:register| is used.
4866 In |Vim9-script| {regname} must be one character.
4867
4868 Can also be used as a |method|: >
4869 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004870<
4871 Return type: |String|
4872
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004873
4874getreginfo([{regname}]) *getreginfo()*
4875 Returns detailed information about register {regname} as a
4876 Dictionary with the following entries:
4877 regcontents List of lines contained in register
4878 {regname}, like
4879 |getreg|({regname}, 1, 1).
4880 regtype the type of register {regname}, as in
4881 |getregtype()|.
4882 isunnamed Boolean flag, v:true if this register
4883 is currently pointed to by the unnamed
4884 register.
4885 points_to for the unnamed register, gives the
4886 single letter name of the register
4887 currently pointed to (see |quotequote|).
4888 For example, after deleting a line
4889 with `dd`, this field will be "1",
4890 which is the register that got the
4891 deleted text.
4892
4893 The {regname} argument is a string. If {regname} is invalid
4894 or not set, an empty Dictionary will be returned.
4895 If {regname} is "" or "@", the unnamed register '"' is used.
4896 If {regname} is not specified, |v:register| is used.
4897 The returned Dictionary can be passed to |setreg()|.
4898 In |Vim9-script| {regname} must be one character.
4899
4900 Can also be used as a |method|: >
4901 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004902<
4903 Return type: dict<any>
4904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004905
Shougo Matsushita19b71882024-02-28 22:48:12 +01004906getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004907 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004908 buffer.
4909
4910 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004911 See |getpos()| for the format of the list. It's possible
4912 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004913 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004914
4915 The optional argument {opts} is a Dict and supports the
4916 following items:
4917
zeertzjqafc22952024-05-24 19:07:12 +02004918 type Specify the region's selection type.
4919 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004920 except that the width can be omitted
4921 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004922 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004923
zeertzjq87410ab2024-03-02 06:00:23 +08004924 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004925 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004926 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004927
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004928 You can get the last selection type by |visualmode()|.
4929 If Visual mode is active, use |mode()| to get the Visual mode
4930 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004931 This function is useful to get text starting and ending in
4932 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004933
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004934 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004935 Note that:
4936 - Order of {pos1} and {pos2} doesn't matter, it will always
4937 return content from the upper left position to the lower
4938 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004939 - If 'virtualedit' is enabled and the region is past the end
4940 of the lines, resulting lines are padded with spaces.
4941 - If the region is blockwise and it starts or ends in the
4942 middle of a multi-cell character, it is not included but
4943 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004944 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004945 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004946 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004947 - It is evaluated in current window context, which makes a
4948 difference if the buffer is displayed in a window with
4949 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004950
4951 Examples: >
4952 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004953 \ <Cmd>echow getregion(
4954 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004955<
4956 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004957 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004958<
4959 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004960
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004961
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004962getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4963 Same as |getregion()|, but returns a list of positions
4964 describing the buffer text segments bound by {pos1} and
4965 {pos2}.
4966 The segments are a pair of positions for every line: >
4967 [[{start_pos}, {end_pos}], ...]
4968<
4969 The position is a |List| with four numbers:
4970 [bufnum, lnum, col, off]
4971 "bufnum" is the buffer number.
4972 "lnum" and "col" are the position in the buffer. The first
4973 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004974 If the "off" number of a starting position is non-zero, it is
4975 the offset in screen columns from the start of the character.
4976 E.g., a position within a <Tab> or after the last character.
4977 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004978 the offset of the character's first cell not included in the
4979 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004980
zeertzjq2b09de92024-05-24 07:48:51 +02004981 Apart from the options supported by |getregion()|, {opts} also
4982 supports the following:
4983
4984 eol If |TRUE|, indicate positions beyond
4985 the end of a line with "col" values
4986 one more than the length of the line.
4987 If |FALSE|, positions are limited
4988 within their lines, and if a line is
4989 empty or the selection is entirely
4990 beyond the end of a line, a "col"
4991 value of 0 is used for both positions.
4992 (default: |FALSE|)
4993
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004994 Can also be used as a |method|: >
4995 getpos('.')->getregionpos(getpos("'a"))
4996<
zeertzjqd4d12072024-07-16 20:34:16 +02004997 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004998
4999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005000getregtype([{regname}]) *getregtype()*
5001 The result is a String, which is type of register {regname}.
5002 The value will be one of:
5003 "v" for |characterwise| text
5004 "V" for |linewise| text
5005 "<CTRL-V>{width}" for |blockwise-visual| text
5006 "" for an empty or unknown register
5007 <CTRL-V> is one character with value 0x16.
5008 The {regname} argument is a string. If {regname} is "", the
5009 unnamed register '"' is used. If {regname} is not specified,
5010 |v:register| is used.
5011 In |Vim9-script| {regname} must be one character.
5012
5013 Can also be used as a |method|: >
5014 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005015<
5016 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005017
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01005018
Bram Moolenaar71badf92023-04-22 22:40:14 +01005019getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005020 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01005021 scripts in the order they were sourced, like what
5022 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005023
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005024 The optional Dict argument {opts} supports the following
5025 optional items:
5026 name Script name match pattern. If specified,
5027 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005028 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005029 "name" are returned.
5030 sid Script ID |<SID>|. If specified, only
5031 information about the script with ID "sid" is
5032 returned and "name" is ignored.
5033
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005034 Each item in the returned List is a |Dict| with the following
5035 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005036 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005037 `import autoload` but was not actually sourced
5038 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005039 functions List of script-local function names defined in
5040 the script. Present only when a particular
5041 script is specified using the "sid" item in
5042 {opts}.
5043 name Vim script file name.
5044 sid Script ID |<SID>|.
5045 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005046 this script name links to, if any, otherwise
5047 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005048 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005049 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005050 specified using the "sid" item in {opts}.
5051 Note that this is a copy, the value of
5052 script-local variables cannot be changed using
5053 this dictionary.
h_east59858792023-10-25 22:47:05 +09005054 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005055
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005056 Examples: >
5057 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005058 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005059<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005060 Return type: list<dict<any>>
5061
5062
ichizok663d18d2025-01-02 18:06:00 +01005063getstacktrace() *getstacktrace()*
5064 Returns the current stack trace of Vim scripts.
5065 Stack trace is a |List|, of which each item is a |Dictionary|
5066 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005067 funcref The funcref if the stack is at a function,
5068 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005069 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005070 stack is at an autocmd event, otherwise this
5071 item is omitted.
5072 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005073 filepath The file path of the script on the stack.
5074
5075 Return type: list<dict<any>>
5076
5077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005078gettabinfo([{tabnr}]) *gettabinfo()*
5079 If {tabnr} is not specified, then information about all the
5080 tab pages is returned as a |List|. Each List item is a
5081 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5082 number and information about that one is returned. If the tab
5083 page does not exist an empty List is returned.
5084
5085 Each List item is a |Dictionary| with the following entries:
5086 tabnr tab page number.
5087 variables a reference to the dictionary with
5088 tabpage-local variables
5089 windows List of |window-ID|s in the tab page.
5090
5091 Can also be used as a |method|: >
5092 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005093<
5094 Return type: list<dict<any>>
5095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005096
5097gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5098 Get the value of a tab-local variable {varname} in tab page
5099 {tabnr}. |t:var|
5100 Tabs are numbered starting with one.
5101 The {varname} argument is a string. When {varname} is empty a
5102 dictionary with all tab-local variables is returned.
5103 Note that the name without "t:" must be used.
5104 When the tab or variable doesn't exist {def} or an empty
5105 string is returned, there is no error message.
5106
5107 Can also be used as a |method|: >
5108 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005109<
5110 Return type: any, depending on {varname}
5111
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005112
5113gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5114 Get the value of window-local variable {varname} in window
5115 {winnr} in tab page {tabnr}.
5116 The {varname} argument is a string. When {varname} is empty a
5117 dictionary with all window-local variables is returned.
5118 When {varname} is equal to "&" get the values of all
5119 window-local options in a |Dictionary|.
5120 Otherwise, when {varname} starts with "&" get the value of a
5121 window-local option.
5122 Note that {varname} must be the name without "w:".
5123 Tabs are numbered starting with one. For the current tabpage
5124 use |getwinvar()|.
5125 {winnr} can be the window number or the |window-ID|.
5126 When {winnr} is zero the current window is used.
5127 This also works for a global option, buffer-local option and
5128 window-local option, but it doesn't work for a global variable
5129 or buffer-local variable.
5130 When the tab, window or variable doesn't exist {def} or an
5131 empty string is returned, there is no error message.
5132 Examples: >
5133 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005134 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005135<
5136 To obtain all window-local variables use: >
5137 gettabwinvar({tabnr}, {winnr}, '&')
5138
5139< Can also be used as a |method|: >
5140 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005141<
5142 Return type: any, depending on {varname}
5143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005144
5145gettagstack([{winnr}]) *gettagstack()*
5146 The result is a Dict, which is the tag stack of window {winnr}.
5147 {winnr} can be the window number or the |window-ID|.
5148 When {winnr} is not specified, the current window is used.
5149 When window {winnr} doesn't exist, an empty Dict is returned.
5150
5151 The returned dictionary contains the following entries:
5152 curidx Current index in the stack. When at
5153 top of the stack, set to (length + 1).
5154 Index of bottom of the stack is 1.
5155 items List of items in the stack. Each item
5156 is a dictionary containing the
5157 entries described below.
5158 length Number of entries in the stack.
5159
5160 Each item in the stack is a dictionary with the following
5161 entries:
5162 bufnr buffer number of the current jump
5163 from cursor position before the tag jump.
5164 See |getpos()| for the format of the
5165 returned list.
5166 matchnr current matching tag number. Used when
5167 multiple matching tags are found for a
5168 name.
5169 tagname name of the tag
5170
5171 See |tagstack| for more information about the tag stack.
5172
5173 Can also be used as a |method|: >
5174 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005175<
5176 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005177
5178
Christ van Willegence0ef912024-06-20 23:41:59 +02005179gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005180 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005181 This is intended for use in Vim scripts. When generating
5182 message translations the {text} is extracted by `xgettext`,
5183 the translator can add translated messages into the .po file
5184 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005185 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005186 `xgettext` does not support single quoted escaped text.
5187
Christ van Willegence0ef912024-06-20 23:41:59 +02005188 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005189 for that specific package. This is mainly required for
5190 third-party Vim scripts. You need to specify a path to the
5191 translations with the |bindtextdomain()| function before
5192 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005193
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005194 Return type: |String|
5195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005196
5197getwininfo([{winid}]) *getwininfo()*
5198 Returns information about windows as a |List| with Dictionaries.
5199
5200 If {winid} is given Information about the window with that ID
5201 is returned, as a |List| with one item. If the window does not
5202 exist the result is an empty list.
5203
5204 Without {winid} information about all the windows in all the
5205 tab pages is returned.
5206
5207 Each List item is a |Dictionary| with the following entries:
5208 botline last complete displayed buffer line
5209 bufnr number of buffer in the window
5210 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005211 leftcol first column displayed; only used when
5212 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005213 loclist 1 if showing a location list
5214 {only with the +quickfix feature}
5215 quickfix 1 if quickfix or location list window
5216 {only with the +quickfix feature}
5217 terminal 1 if a terminal window
5218 {only with the +terminal feature}
5219 tabnr tab page number
5220 topline first displayed buffer line
5221 variables a reference to the dictionary with
5222 window-local variables
5223 width window width
5224 winbar 1 if the window has a toolbar, 0
5225 otherwise
5226 wincol leftmost screen column of the window;
5227 "col" from |win_screenpos()|
5228 textoff number of columns occupied by any
5229 'foldcolumn', 'signcolumn' and line
5230 number in front of the text
5231 winid |window-ID|
5232 winnr window number
5233 winrow topmost screen line of the window;
5234 "row" from |win_screenpos()|
5235
5236 Can also be used as a |method|: >
5237 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005238<
5239 Return type: list<dict<any>>
5240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005241
5242getwinpos([{timeout}]) *getwinpos()*
5243 The result is a |List| with two numbers, the result of
5244 |getwinposx()| and |getwinposy()| combined:
5245 [x-pos, y-pos]
5246 {timeout} can be used to specify how long to wait in msec for
5247 a response from the terminal. When omitted 100 msec is used.
5248 Use a longer time for a remote terminal.
5249 When using a value less than 10 and no response is received
5250 within that time, a previously reported position is returned,
5251 if available. This can be used to poll for the position and
5252 do some work in the meantime: >
5253 while 1
5254 let res = getwinpos(1)
5255 if res[0] >= 0
5256 break
5257 endif
5258 " Do some work here
5259 endwhile
5260<
5261
5262 Can also be used as a |method|: >
5263 GetTimeout()->getwinpos()
5264<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005265 Return type: list<number>
5266
5267
5268getwinposx() *getwinposx()*
5269 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005270 the left hand side of the GUI Vim window. Also works for an
5271 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005272 The result will be -1 if the information is not available
5273 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005274 The value can be used with `:winpos`.
5275
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005276 Return type: |Number|
5277
5278
5279getwinposy() *getwinposy()*
5280 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005281 the top of the GUI Vim window. Also works for an xterm (uses
5282 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005283 The result will be -1 if the information is not available
5284 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005285 The value can be used with `:winpos`.
5286
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005287 Return type: |Number|
5288
5289
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005290getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5291 Like |gettabwinvar()| for the current tabpage.
5292 Examples: >
5293 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005294 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005295
5296< Can also be used as a |method|: >
5297 GetWinnr()->getwinvar(varname)
5298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005299 Return type: any, depending on {varname}
5300
5301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005302glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5303 Expand the file wildcards in {expr}. See |wildcards| for the
5304 use of special characters.
5305
5306 Unless the optional {nosuf} argument is given and is |TRUE|,
5307 the 'suffixes' and 'wildignore' options apply: Names matching
5308 one of the patterns in 'wildignore' will be skipped and
5309 'suffixes' affect the ordering of matches.
5310 'wildignorecase' always applies.
5311
5312 When {list} is present and it is |TRUE| the result is a |List|
5313 with all matching files. The advantage of using a List is,
5314 you also get filenames containing newlines correctly.
5315 Otherwise the result is a String and when there are several
5316 matches, they are separated by <NL> characters.
5317
5318 If the expansion fails, the result is an empty String or List.
5319
5320 You can also use |readdir()| if you need to do complicated
5321 things, such as limiting the number of matches.
5322
5323 A name for a non-existing file is not included. A symbolic
5324 link is only included if it points to an existing file.
5325 However, when the {alllinks} argument is present and it is
5326 |TRUE| then all symbolic links are included.
5327
5328 For most systems backticks can be used to get files names from
5329 any external command. Example: >
5330 :let tagfiles = glob("`find . -name tags -print`")
5331 :let &tags = substitute(tagfiles, "\n", ",", "g")
5332< The result of the program inside the backticks should be one
5333 item per line. Spaces inside an item are allowed.
5334
5335 See |expand()| for expanding special Vim variables. See
5336 |system()| for getting the raw output of an external command.
5337
5338 Can also be used as a |method|: >
5339 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005340<
5341 Return type: |String| or list<string> or list<any> depending
5342 on {list}
5343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005344
h-east624bb832024-11-09 18:37:32 +01005345glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005346 Convert a file pattern, as used by glob(), into a search
5347 pattern. The result can be used to match with a string that
5348 is a file name. E.g. >
5349 if filename =~ glob2regpat('Make*.mak')
5350< This is equivalent to: >
5351 if filename =~ '^Make.*\.mak$'
5352< When {string} is an empty string the result is "^$", match an
5353 empty string.
5354 Note that the result depends on the system. On MS-Windows
5355 a backslash usually means a path separator.
5356
5357 Can also be used as a |method|: >
5358 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005359<
5360 Return type: |String|
5361
5362 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005363globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5364 Perform glob() for String {expr} on all directories in {path}
5365 and concatenate the results. Example: >
5366 :echo globpath(&rtp, "syntax/c.vim")
5367<
5368 {path} is a comma-separated list of directory names. Each
5369 directory name is prepended to {expr} and expanded like with
5370 |glob()|. A path separator is inserted when needed.
5371 To add a comma inside a directory name escape it with a
5372 backslash. Note that on MS-Windows a directory may have a
5373 trailing backslash, remove it if you put a comma after it.
5374 If the expansion fails for one of the directories, there is no
5375 error message.
5376
5377 Unless the optional {nosuf} argument is given and is |TRUE|,
5378 the 'suffixes' and 'wildignore' options apply: Names matching
5379 one of the patterns in 'wildignore' will be skipped and
5380 'suffixes' affect the ordering of matches.
5381
5382 When {list} is present and it is |TRUE| the result is a |List|
5383 with all matching files. The advantage of using a List is, you
5384 also get filenames containing newlines correctly. Otherwise
5385 the result is a String and when there are several matches,
5386 they are separated by <NL> characters. Example: >
5387 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5388<
5389 {alllinks} is used as with |glob()|.
5390
5391 The "**" item can be used to search in a directory tree.
5392 For example, to find all "README.txt" files in the directories
5393 in 'runtimepath' and below: >
5394 :echo globpath(&rtp, "**/README.txt")
5395< Upwards search and limiting the depth of "**" is not
5396 supported, thus using 'path' will not always work properly.
5397
5398 Can also be used as a |method|, the base is passed as the
5399 second argument: >
5400 GetExpr()->globpath(&rtp)
5401<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005402 Return type: |String| or list<string> or list<any> depending
5403 on {list}
5404
5405
5406has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005407 When {check} is omitted or is zero: The result is a Number,
5408 which is 1 if the feature {feature} is supported, zero
5409 otherwise. The {feature} argument is a string, case is
5410 ignored. See |feature-list| below.
5411
5412 When {check} is present and not zero: The result is a Number,
5413 which is 1 if the feature {feature} could ever be supported,
5414 zero otherwise. This is useful to check for a typo in
5415 {feature} and to detect dead code. Keep in mind that an older
5416 Vim version will not know about a feature added later and
5417 features that have been abandoned will not be known by the
5418 current Vim version.
5419
5420 Also see |exists()| and |exists_compiled()|.
5421
5422 Note that to skip code that has a syntax error when the
5423 feature is not available, Vim may skip the rest of the line
5424 and miss a following `endif`. Therefore put the `endif` on a
5425 separate line: >
5426 if has('feature')
5427 let x = this->breaks->without->the->feature
5428 endif
5429< If the `endif` would be moved to the second line as "| endif" it
5430 would not be found.
5431
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005432 Return type: |Number|
5433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005434
5435has_key({dict}, {key}) *has_key()*
5436 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005437 has an entry with key {key}. FALSE otherwise.
5438 The {key} argument is a string. In |Vim9| script a number is
5439 also accepted (and converted to a string) but no other types.
5440 In legacy script the usual automatic conversion to string is
5441 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005442
5443 Can also be used as a |method|: >
5444 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005445<
5446 Return type: |Number|
5447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005448
5449haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5450 The result is a Number:
5451 1 when the window has set a local directory via |:lcd|
5452 2 when the tab-page has set a local directory via |:tcd|
5453 0 otherwise.
5454
5455 Without arguments use the current window.
5456 With {winnr} use this window in the current tab page.
5457 With {winnr} and {tabnr} use the window in the specified tab
5458 page.
5459 {winnr} can be the window number or the |window-ID|.
5460 If {winnr} is -1 it is ignored and only the tabpage is used.
5461 Return 0 if the arguments are invalid.
5462 Examples: >
5463 if haslocaldir() == 1
5464 " window local directory case
5465 elseif haslocaldir() == 2
5466 " tab-local directory case
5467 else
5468 " global directory case
5469 endif
5470
5471 " current window
5472 :echo haslocaldir()
5473 :echo haslocaldir(0)
5474 :echo haslocaldir(0, 0)
5475 " window n in current tab page
5476 :echo haslocaldir(n)
5477 :echo haslocaldir(n, 0)
5478 " window n in tab page m
5479 :echo haslocaldir(n, m)
5480 " tab page m
5481 :echo haslocaldir(-1, m)
5482<
5483 Can also be used as a |method|: >
5484 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005485<
5486 Return type: |Number|
5487
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005488
5489hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5490 The result is a Number, which is TRUE if there is a mapping
5491 that contains {what} in somewhere in the rhs (what it is
5492 mapped to) and this mapping exists in one of the modes
5493 indicated by {mode}.
5494 The arguments {what} and {mode} are strings.
5495 When {abbr} is there and it is |TRUE| use abbreviations
5496 instead of mappings. Don't forget to specify Insert and/or
5497 Command-line mode.
5498 Both the global mappings and the mappings local to the current
5499 buffer are checked for a match.
5500 If no matching mapping is found FALSE is returned.
5501 The following characters are recognized in {mode}:
5502 n Normal mode
5503 v Visual and Select mode
5504 x Visual mode
5505 s Select mode
5506 o Operator-pending mode
5507 i Insert mode
5508 l Language-Argument ("r", "f", "t", etc.)
5509 c Command-line mode
5510 When {mode} is omitted, "nvo" is used.
5511
5512 This function is useful to check if a mapping already exists
5513 to a function in a Vim script. Example: >
5514 :if !hasmapto('\ABCdoit')
5515 : map <Leader>d \ABCdoit
5516 :endif
5517< This installs the mapping to "\ABCdoit" only if there isn't
5518 already a mapping to "\ABCdoit".
5519
5520 Can also be used as a |method|: >
5521 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005522<
5523 Return type: |Number|
5524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005525
5526histadd({history}, {item}) *histadd()*
5527 Add the String {item} to the history {history} which can be
5528 one of: *hist-names*
5529 "cmd" or ":" command line history
5530 "search" or "/" search pattern history
5531 "expr" or "=" typed expression history
5532 "input" or "@" input line history
5533 "debug" or ">" debug command history
5534 empty the current or last used history
5535 The {history} string does not need to be the whole name, one
5536 character is sufficient.
5537 If {item} does already exist in the history, it will be
5538 shifted to become the newest entry.
5539 The result is a Number: TRUE if the operation was successful,
5540 otherwise FALSE is returned.
5541
5542 Example: >
5543 :call histadd("input", strftime("%Y %b %d"))
5544 :let date=input("Enter date: ")
5545< This function is not available in the |sandbox|.
5546
5547 Can also be used as a |method|, the base is passed as the
5548 second argument: >
5549 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005550<
5551 Return type: |Number|
5552
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005553
5554histdel({history} [, {item}]) *histdel()*
5555 Clear {history}, i.e. delete all its entries. See |hist-names|
5556 for the possible values of {history}.
5557
5558 If the parameter {item} evaluates to a String, it is used as a
5559 regular expression. All entries matching that expression will
5560 be removed from the history (if there are any).
5561 Upper/lowercase must match, unless "\c" is used |/\c|.
5562 If {item} evaluates to a Number, it will be interpreted as
5563 an index, see |:history-indexing|. The respective entry will
5564 be removed if it exists.
5565
5566 The result is TRUE for a successful operation, otherwise FALSE
5567 is returned.
5568
5569 Examples:
5570 Clear expression register history: >
5571 :call histdel("expr")
5572<
5573 Remove all entries starting with "*" from the search history: >
5574 :call histdel("/", '^\*')
5575<
5576 The following three are equivalent: >
5577 :call histdel("search", histnr("search"))
5578 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005579 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005580<
5581 To delete the last search pattern and use the last-but-one for
5582 the "n" command and 'hlsearch': >
5583 :call histdel("search", -1)
5584 :let @/ = histget("search", -1)
5585<
5586 Can also be used as a |method|: >
5587 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005588<
5589 Return type: |Number|
5590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005591
5592histget({history} [, {index}]) *histget()*
5593 The result is a String, the entry with Number {index} from
5594 {history}. See |hist-names| for the possible values of
5595 {history}, and |:history-indexing| for {index}. If there is
5596 no such entry, an empty String is returned. When {index} is
5597 omitted, the most recent item from the history is used.
5598
5599 Examples:
5600 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005601 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005602
5603< Define an Ex command ":H {num}" that supports re-execution of
5604 the {num}th entry from the output of |:history|. >
5605 :command -nargs=1 H execute histget("cmd", 0+<args>)
5606<
5607 Can also be used as a |method|: >
5608 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005609<
5610 Return type: |String|
5611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005612
5613histnr({history}) *histnr()*
5614 The result is the Number of the current entry in {history}.
5615 See |hist-names| for the possible values of {history}.
5616 If an error occurred, -1 is returned.
5617
5618 Example: >
5619 :let inp_index = histnr("expr")
5620
5621< Can also be used as a |method|: >
5622 GetHistory()->histnr()
5623<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005624 Return type: |Number|
5625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005626hlexists({name}) *hlexists()*
5627 The result is a Number, which is TRUE if a highlight group
5628 called {name} exists. This is when the group has been
5629 defined in some way. Not necessarily when highlighting has
5630 been defined for it, it may also have been used for a syntax
5631 item.
5632 *highlight_exists()*
5633 Obsolete name: highlight_exists().
5634
5635 Can also be used as a |method|: >
5636 GetName()->hlexists()
5637<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005638 Return type: |Number|
5639
5640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005641hlget([{name} [, {resolve}]]) *hlget()*
5642 Returns a List of all the highlight group attributes. If the
5643 optional {name} is specified, then returns a List with only
5644 the attributes of the specified highlight group. Returns an
5645 empty List if the highlight group {name} is not present.
5646
5647 If the optional {resolve} argument is set to v:true and the
5648 highlight group {name} is linked to another group, then the
5649 link is resolved recursively and the attributes of the
5650 resolved highlight group are returned.
5651
5652 Each entry in the returned List is a Dictionary with the
5653 following items:
5654 cleared boolean flag, set to v:true if the highlight
5655 group attributes are cleared or not yet
5656 specified. See |highlight-clear|.
5657 cterm cterm attributes. See |highlight-cterm|.
5658 ctermbg cterm background color.
5659 See |highlight-ctermbg|.
5660 ctermfg cterm foreground color.
5661 See |highlight-ctermfg|.
5662 ctermul cterm underline color. See |highlight-ctermul|.
5663 default boolean flag, set to v:true if the highlight
5664 group link is a default link. See
5665 |highlight-default|.
5666 font highlight group font. See |highlight-font|.
5667 gui gui attributes. See |highlight-gui|.
5668 guibg gui background color. See |highlight-guibg|.
5669 guifg gui foreground color. See |highlight-guifg|.
5670 guisp gui special color. See |highlight-guisp|.
5671 id highlight group ID.
5672 linksto linked highlight group name.
5673 See |:highlight-link|.
5674 name highlight group name. See |group-name|.
5675 start start terminal keycode. See |highlight-start|.
5676 stop stop terminal keycode. See |highlight-stop|.
5677 term term attributes. See |highlight-term|.
5678
5679 The 'term', 'cterm' and 'gui' items in the above Dictionary
5680 have a dictionary value with the following optional boolean
5681 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5682 'reverse', 'inverse' and 'strikethrough'.
5683
5684 Example(s): >
5685 :echo hlget()
5686 :echo hlget('ModeMsg')
5687 :echo hlget('Number', v:true)
5688<
5689 Can also be used as a |method|: >
5690 GetName()->hlget()
5691<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005692 Return type: list<dict<any>>
5693
5694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005695hlset({list}) *hlset()*
5696 Creates or modifies the attributes of a List of highlight
5697 groups. Each item in {list} is a dictionary containing the
5698 attributes of a highlight group. See |hlget()| for the list of
5699 supported items in this dictionary.
5700
5701 In addition to the items described in |hlget()|, the following
5702 additional items are supported in the dictionary:
5703
5704 force boolean flag to force the creation of
5705 a link for an existing highlight group
5706 with attributes.
5707
5708 The highlight group is identified using the 'name' item and
5709 the 'id' item (if supplied) is ignored. If a highlight group
5710 with a specified name doesn't exist, then it is created.
5711 Otherwise the attributes of an existing highlight group are
5712 modified.
5713
5714 If an empty dictionary value is used for the 'term' or 'cterm'
5715 or 'gui' entries, then the corresponding attributes are
5716 cleared. If the 'cleared' item is set to v:true, then all the
5717 attributes of the highlight group are cleared.
5718
5719 The 'linksto' item can be used to link a highlight group to
5720 another highlight group. See |:highlight-link|.
5721
5722 Returns zero for success, -1 for failure.
5723
5724 Example(s): >
5725 " add bold attribute to the Visual highlight group
5726 :call hlset([#{name: 'Visual',
5727 \ term: #{reverse: 1 , bold: 1}}])
5728 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5729 :let l = hlget()
5730 :call hlset(l)
5731 " clear the Search highlight group
5732 :call hlset([#{name: 'Search', cleared: v:true}])
5733 " clear the 'term' attributes for a highlight group
5734 :call hlset([#{name: 'Title', term: {}}])
5735 " create the MyHlg group linking it to DiffAdd
5736 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5737 " remove the MyHlg group link
5738 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5739 " clear the attributes and a link
5740 :call hlset([#{name: 'MyHlg', cleared: v:true,
5741 \ linksto: 'NONE'}])
5742<
5743 Can also be used as a |method|: >
5744 GetAttrList()->hlset()
5745<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005746 Return type: |Number|
5747
5748hlID({name}) *hlID()*
5749 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005750 with name {name}. When the highlight group doesn't exist,
5751 zero is returned.
5752 This can be used to retrieve information about the highlight
5753 group. For example, to get the background color of the
5754 "Comment" group: >
5755 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5756< *highlightID()*
5757 Obsolete name: highlightID().
5758
5759 Can also be used as a |method|: >
5760 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005761<
5762 Return type: |Number|
5763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005764
5765hostname() *hostname()*
5766 The result is a String, which is the name of the machine on
5767 which Vim is currently running. Machine names greater than
5768 256 characters long are truncated.
5769
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005770 Return type: |String|
5771
5772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005773iconv({string}, {from}, {to}) *iconv()*
5774 The result is a String, which is the text {string} converted
5775 from encoding {from} to encoding {to}.
5776 When the conversion completely fails an empty string is
5777 returned. When some characters could not be converted they
5778 are replaced with "?".
5779 The encoding names are whatever the iconv() library function
5780 can accept, see ":!man 3 iconv".
5781 Most conversions require Vim to be compiled with the |+iconv|
5782 feature. Otherwise only UTF-8 to latin1 conversion and back
5783 can be done.
5784 This can be used to display messages with special characters,
5785 no matter what 'encoding' is set to. Write the message in
5786 UTF-8 and use: >
5787 echo iconv(utf8_str, "utf-8", &enc)
5788< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5789 from/to UCS-2 is automatically changed to use UTF-8. You
5790 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5791
5792 Can also be used as a |method|: >
5793 GetText()->iconv('latin1', 'utf-8')
5794<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005795 Return type: |String|
5796
5797
h-east624bb832024-11-09 18:37:32 +01005798id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005799 The result is a unique String associated with the {item} and
5800 not with the {item}'s contents. It is only valid while the
5801 {item} exists and is referenced. It is valid only in the
5802 instance of vim that produces the result. The whole idea is
5803 that `id({item})` does not change if the contents of {item}
5804 changes. This is useful as a `key` for creating an identity
5805 dictionary, rather than one based on equals.
5806
5807 This operation does not reference {item} and there is no
5808 function to convert the `id` to the {item}. It may be useful to
5809 have a map of `id` to {item}. The following >
5810 var referenceMap: dict<any>
5811 var id = item->id()
5812 referenceMap[id] = item
5813< prevents {item} from being garbage collected and provides a
5814 way to get the {item} from the `id`.
5815
5816 {item} may be a List, Dictionary, Object, Job, Channel or
5817 Blob. If the item is not a permitted type, or it is a null
5818 value, then an empty String is returned.
5819
5820 Can also be used as a |method|: >
5821 GetItem()->id()
5822<
5823 Return type: |String|
5824
5825
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005826indent({lnum}) *indent()*
5827 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005828 current buffer. The indent is counted in spaces, the value
5829 of 'tabstop' is relevant. {lnum} is used just like in
5830 |getline()|.
5831 When {lnum} is invalid -1 is returned. In |Vim9| script an
5832 error is given.
5833
5834 Can also be used as a |method|: >
5835 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005836<
5837 Return type: |Number|
5838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005839
5840index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005841 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005842 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005844 If {object} is a |List| return the lowest index where the item
5845 has a value equal to {expr}. There is no automatic
5846 conversion, so the String "4" is different from the Number 4.
5847 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005848 of 'ignorecase' is not used here, case matters as indicated by
5849 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005850
5851 If {object} is |Blob| return the lowest index where the byte
5852 value is equal to {expr}.
5853
5854 If {start} is given then start looking at the item with index
5855 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005856
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005857 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5858 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005859
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005860 -1 is returned when {expr} is not found in {object}.
5861 Example: >
5862 :let idx = index(words, "the")
5863 :if index(numbers, 123) >= 0
5864
5865< Can also be used as a |method|: >
5866 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005867<
5868 Return type: |Number|
5869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005870
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005871indexof({object}, {expr} [, {opts}]) *indexof()*
5872 Returns the index of an item in {object} where {expr} is
5873 v:true. {object} must be a |List| or a |Blob|.
5874
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005875 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005876 List until the expression is v:true and return the index of
5877 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005878
5879 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005880 Blob until the expression is v:true and return the index of
5881 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005882
5883 {expr} must be a |string| or |Funcref|.
5884
5885 If {expr} is a |string|: If {object} is a |List|, inside
5886 {expr} |v:key| has the index of the current List item and
5887 |v:val| has the value of the item. If {object} is a |Blob|,
5888 inside {expr} |v:key| has the index of the current byte and
5889 |v:val| has the byte value.
5890
5891 If {expr} is a |Funcref| it must take two arguments:
5892 1. the key or the index of the current item.
5893 2. the value of the current item.
5894 The function must return |TRUE| if the item is found and the
5895 search should stop.
5896
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005897 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005898 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005899 startidx start evaluating {expr} at the item with this
5900 index; may be negative for an item relative to
5901 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005902 Returns -1 when {expr} evaluates to v:false for all the items.
5903 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005904 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5905 :echo indexof(l, "v:val.n == 20")
5906 :echo indexof(l, {i, v -> v.n == 30})
5907 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005908
5909< Can also be used as a |method|: >
5910 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005911<
5912 Return type: |Number|
5913
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005915input({prompt} [, {text} [, {completion}]]) *input()*
5916 The result is a String, which is whatever the user typed on
5917 the command-line. The {prompt} argument is either a prompt
5918 string, or a blank string (for no prompt). A '\n' can be used
5919 in the prompt to start a new line.
5920 The highlighting set with |:echohl| is used for the prompt.
5921 The input is entered just like a command-line, with the same
5922 editing commands and mappings. There is a separate history
5923 for lines typed for input().
5924 Example: >
5925 :if input("Coffee or beer? ") == "beer"
5926 : echo "Cheers!"
5927 :endif
5928<
5929 If the optional {text} argument is present and not empty, this
5930 is used for the default reply, as if the user typed this.
5931 Example: >
5932 :let color = input("Color? ", "white")
5933
5934< The optional {completion} argument specifies the type of
5935 completion supported for the input. Without it completion is
5936 not performed. The supported completion types are the same as
5937 that can be supplied to a user-defined command using the
5938 "-complete=" argument. Refer to |:command-completion| for
5939 more information. Example: >
5940 let fname = input("File: ", "", "file")
5941<
5942 NOTE: This function must not be used in a startup file, for
5943 the versions that only run in GUI mode (e.g., the Win32 GUI).
5944 Note: When input() is called from within a mapping it will
5945 consume remaining characters from that mapping, because a
5946 mapping is handled like the characters were typed.
5947 Use |inputsave()| before input() and |inputrestore()|
5948 after input() to avoid that. Another solution is to avoid
5949 that further characters follow in the mapping, e.g., by using
5950 |:execute| or |:normal|.
5951
5952 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005953 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005954 :function GetFoo()
5955 : call inputsave()
5956 : let g:Foo = input("enter search pattern: ")
5957 : call inputrestore()
5958 :endfunction
5959
5960< Can also be used as a |method|: >
5961 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005962<
5963 Return type: |String|
5964
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005965
5966inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5967 Like |input()|, but when the GUI is running and text dialogs
5968 are supported, a dialog window pops up to input the text.
5969 Example: >
5970 :let n = inputdialog("value for shiftwidth", shiftwidth())
5971 :if n != ""
5972 : let &sw = n
5973 :endif
5974< When the dialog is cancelled {cancelreturn} is returned. When
5975 omitted an empty string is returned.
5976 Hitting <Enter> works like pressing the OK button. Hitting
5977 <Esc> works like pressing the Cancel button.
5978 NOTE: Command-line completion is not supported.
5979
5980 Can also be used as a |method|: >
5981 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005982<
5983 Return type: |String|
5984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005985
5986inputlist({textlist}) *inputlist()*
5987 {textlist} must be a |List| of strings. This |List| is
5988 displayed, one string per line. The user will be prompted to
5989 enter a number, which is returned.
5990 The user can also select an item by clicking on it with the
5991 mouse, if the mouse is enabled in the command line ('mouse' is
5992 "a" or includes "c"). For the first string 0 is returned.
5993 When clicking above the first item a negative number is
5994 returned. When clicking on the prompt one more than the
5995 length of {textlist} is returned.
5996 Make sure {textlist} has less than 'lines' entries, otherwise
5997 it won't work. It's a good idea to put the entry number at
5998 the start of the string. And put a prompt in the first item.
5999 Example: >
6000 let color = inputlist(['Select color:', '1. red',
6001 \ '2. green', '3. blue'])
6002
6003< Can also be used as a |method|: >
6004 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006005<
6006 Return type: |Number|
6007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006008
6009inputrestore() *inputrestore()*
6010 Restore typeahead that was saved with a previous |inputsave()|.
6011 Should be called the same number of times inputsave() is
6012 called. Calling it more often is harmless though.
6013 Returns TRUE when there is nothing to restore, FALSE otherwise.
6014
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006015 Return type: |Number|
6016
6017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006018inputsave() *inputsave()*
6019 Preserve typeahead (also from mappings) and clear it, so that
6020 a following prompt gets input from the user. Should be
6021 followed by a matching inputrestore() after the prompt. Can
6022 be used several times, in which case there must be just as
6023 many inputrestore() calls.
6024 Returns TRUE when out of memory, FALSE otherwise.
6025
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006026 Return type: |Number|
6027
6028
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006029inputsecret({prompt} [, {text}]) *inputsecret()*
6030 This function acts much like the |input()| function with but
6031 two exceptions:
6032 a) the user's response will be displayed as a sequence of
6033 asterisks ("*") thereby keeping the entry secret, and
6034 b) the user's response will not be recorded on the input
6035 |history| stack.
6036 The result is a String, which is whatever the user actually
6037 typed on the command-line in response to the issued prompt.
6038 NOTE: Command-line completion is not supported.
6039
6040 Can also be used as a |method|: >
6041 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006042<
6043 Return type: |String|
6044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006045
6046insert({object}, {item} [, {idx}]) *insert()*
6047 When {object} is a |List| or a |Blob| insert {item} at the start
6048 of it.
6049
6050 If {idx} is specified insert {item} before the item with index
6051 {idx}. If {idx} is zero it goes before the first item, just
6052 like omitting {idx}. A negative {idx} is also possible, see
6053 |list-index|. -1 inserts just before the last item.
6054
6055 Returns the resulting |List| or |Blob|. Examples: >
6056 :let mylist = insert([2, 3, 5], 1)
6057 :call insert(mylist, 4, -1)
6058 :call insert(mylist, 6, len(mylist))
6059< The last example can be done simpler with |add()|.
6060 Note that when {item} is a |List| it is inserted as a single
6061 item. Use |extend()| to concatenate |Lists|.
6062
6063 Can also be used as a |method|: >
6064 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006065<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006066 Return type: |Number|
6067
6068
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006069 *instanceof()* *E614* *E616* *E693*
6070instanceof({object}, {class})
6071 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006072 argument is a direct or indirect instance of a |Class|,
6073 |Interface|, or class |:type| alias specified by {class}.
6074 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006075 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006076 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006077 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006078
6079< Can also be used as a |method|: >
6080 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006081<
6082 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006084interrupt() *interrupt()*
6085 Interrupt script execution. It works more or less like the
6086 user typing CTRL-C, most commands won't execute and control
6087 returns to the user. This is useful to abort execution
6088 from lower down, e.g. in an autocommand. Example: >
6089 :function s:check_typoname(file)
6090 : if fnamemodify(a:file, ':t') == '['
6091 : echomsg 'Maybe typo'
6092 : call interrupt()
6093 : endif
6094 :endfunction
6095 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006096<
6097 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006098
6099invert({expr}) *invert()*
6100 Bitwise invert. The argument is converted to a number. A
6101 List, Dict or Float argument causes an error. Example: >
6102 :let bits = invert(bits)
6103< Can also be used as a |method|: >
6104 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006105<
6106 Return type: |Number|
6107
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006108
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006109isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006110 The result is a Number, which is |TRUE| when {path} is an
6111 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006112 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006113 On MS-Windows, it is considered absolute when it starts with an
6114 optional drive prefix and is followed by a '\' or '/'. UNC paths
6115 are always absolute.
6116 Example: >
6117 echo isabsolutepath('/usr/share/') " 1
6118 echo isabsolutepath('./foobar') " 0
6119 echo isabsolutepath('C:\Windows') " 1
6120 echo isabsolutepath('foobar') " 0
6121 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006122<
LemonBoydca1d402022-04-28 15:26:33 +01006123 Can also be used as a |method|: >
6124 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006125<
6126 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006127
6128
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006129isdirectory({directory}) *isdirectory()*
6130 The result is a Number, which is |TRUE| when a directory
6131 with the name {directory} exists. If {directory} doesn't
6132 exist, or isn't a directory, the result is |FALSE|. {directory}
6133 is any expression, which is used as a String.
6134
6135 Can also be used as a |method|: >
6136 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006137<
6138 Return type: |Number|
6139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006140
6141isinf({expr}) *isinf()*
6142 Return 1 if {expr} is a positive infinity, or -1 a negative
6143 infinity, otherwise 0. >
6144 :echo isinf(1.0 / 0.0)
6145< 1 >
6146 :echo isinf(-1.0 / 0.0)
6147< -1
6148
6149 Can also be used as a |method|: >
6150 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006151<
6152 Return type: |Number|
6153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006154
6155islocked({expr}) *islocked()* *E786*
6156 The result is a Number, which is |TRUE| when {expr} is the
6157 name of a locked variable.
6158 The string argument {expr} must be the name of a variable,
6159 |List| item or |Dictionary| entry, not the variable itself!
6160 Example: >
6161 :let alist = [0, ['a', 'b'], 2, 3]
6162 :lockvar 1 alist
6163 :echo islocked('alist') " 1
6164 :echo islocked('alist[1]') " 0
6165
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006166< When {expr} is a variable that does not exist -1 is returned.
6167 If {expr} uses a range, list or dict index that is out of
6168 range or does not exist you get an error message. Use
6169 |exists()| to check for existence.
6170 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006171
6172 Can also be used as a |method|: >
6173 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006174<
6175 Return type: |Number|
6176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006177
6178isnan({expr}) *isnan()*
6179 Return |TRUE| if {expr} is a float with value NaN. >
6180 echo isnan(0.0 / 0.0)
6181< 1
6182
6183 Can also be used as a |method|: >
6184 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006185<
6186 Return type: |Number|
6187
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006188
6189items({dict}) *items()*
6190 Return a |List| with all the key-value pairs of {dict}. Each
6191 |List| item is a list with two items: the key of a {dict}
6192 entry and the value of this entry. The |List| is in arbitrary
6193 order. Also see |keys()| and |values()|.
6194 Example: >
6195 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006196 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006197 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006198<
6199 A List or a String argument is also supported. In these
6200 cases, items() returns a List with the index and the value at
6201 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006202
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006203 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006204 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006205<
6206 Return type: list<list<any>> or list<any>
6207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006208
6209job_ functions are documented here: |job-functions-details|
6210
6211
6212join({list} [, {sep}]) *join()*
6213 Join the items in {list} together into one String.
6214 When {sep} is specified it is put in between the items. If
6215 {sep} is omitted a single space is used.
6216 Note that {sep} is not added at the end. You might want to
6217 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006218 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006219< String items are used as-is. |Lists| and |Dictionaries| are
6220 converted into a string like with |string()|.
6221 The opposite function is |split()|.
6222
6223 Can also be used as a |method|: >
6224 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006225<
6226 Return type: |String|
6227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006228
6229js_decode({string}) *js_decode()*
6230 This is similar to |json_decode()| with these differences:
6231 - Object key names do not have to be in quotes.
6232 - Strings can be in single quotes.
6233 - Empty items in an array (between two commas) are allowed and
6234 result in v:none items.
6235
6236 Can also be used as a |method|: >
6237 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006238<
6239 Return type: any, depending on {varname}
6240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006241
6242js_encode({expr}) *js_encode()*
6243 This is similar to |json_encode()| with these differences:
6244 - Object key names are not in quotes.
6245 - v:none items in an array result in an empty item between
6246 commas.
6247 For example, the Vim object:
6248 [1,v:none,{"one":1},v:none] ~
6249 Will be encoded as:
6250 [1,,{one:1},,] ~
6251 While json_encode() would produce:
6252 [1,null,{"one":1},null] ~
6253 This encoding is valid for JavaScript. It is more efficient
6254 than JSON, especially when using an array with optional items.
6255
6256 Can also be used as a |method|: >
6257 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006258<
6259 Return type: |String|
6260
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006261
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006262json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006263 This parses a JSON formatted string and returns the equivalent
6264 in Vim values. See |json_encode()| for the relation between
6265 JSON and Vim values.
6266 The decoding is permissive:
6267 - A trailing comma in an array and object is ignored, e.g.
6268 "[1, 2, ]" is the same as "[1, 2]".
6269 - Integer keys are accepted in objects, e.g. {1:2} is the
6270 same as {"1":2}.
6271 - More floating point numbers are recognized, e.g. "1." for
6272 "1.0", or "001.2" for "1.2". Special floating point values
6273 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6274 are accepted.
6275 - Leading zeroes in integer numbers are ignored, e.g. "012"
6276 for "12" or "-012" for "-12".
6277 - Capitalization is ignored in literal names null, true or
6278 false, e.g. "NULL" for "null", "True" for "true".
6279 - Control characters U+0000 through U+001F which are not
6280 escaped in strings are accepted, e.g. " " (tab
6281 character in string) for "\t".
6282 - An empty JSON expression or made of only spaces is accepted
6283 and results in v:none.
6284 - Backslash in an invalid 2-character sequence escape is
6285 ignored, e.g. "\a" is decoded as "a".
6286 - A correct surrogate pair in JSON strings should normally be
6287 a 12 character sequence such as "\uD834\uDD1E", but
6288 json_decode() silently accepts truncated surrogate pairs
6289 such as "\uD834" or "\uD834\u"
6290 *E938*
6291 A duplicate key in an object, valid in rfc7159, is not
6292 accepted by json_decode() as the result must be a valid Vim
6293 type, e.g. this fails: {"a":"b", "a":"c"}
6294
6295 Can also be used as a |method|: >
6296 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006297<
6298 Return type: any, depending on {varname}
6299
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006300
6301json_encode({expr}) *json_encode()*
6302 Encode {expr} as JSON and return this as a string.
6303 The encoding is specified in:
6304 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006305 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006306 |Number| decimal number
6307 |Float| floating point number
6308 Float nan "NaN"
6309 Float inf "Infinity"
6310 Float -inf "-Infinity"
6311 |String| in double quotes (possibly null)
6312 |Funcref| not possible, error
6313 |List| as an array (possibly null); when
6314 used recursively: []
6315 |Dict| as an object (possibly null); when
6316 used recursively: {}
6317 |Blob| as an array of the individual bytes
6318 v:false "false"
6319 v:true "true"
6320 v:none "null"
6321 v:null "null"
6322 Note that NaN and Infinity are passed on as values. This is
6323 missing in the JSON standard, but several implementations do
6324 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006325 If a string contains an illegal character then the replacement
6326 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006327
6328 Can also be used as a |method|: >
6329 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006330<
6331 Return type: |String|
6332
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006333
6334keys({dict}) *keys()*
6335 Return a |List| with all the keys of {dict}. The |List| is in
6336 arbitrary order. Also see |items()| and |values()|.
6337
6338 Can also be used as a |method|: >
6339 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006340<
6341 Return type: list<string>
6342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006343
zeertzjqcdc83932022-09-12 13:38:41 +01006344keytrans({string}) *keytrans()*
6345 Turn the internal byte representation of keys into a form that
6346 can be used for |:map|. E.g. >
6347 :let xx = "\<C-Home>"
6348 :echo keytrans(xx)
6349< <C-Home>
6350
6351 Can also be used as a |method|: >
6352 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006353<
6354 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006355
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006356
6357len({expr}) *len()* *E701*
6358 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006359 When {expr} is a String or a Number the length in bytes is
6360 used, as with |strlen()|.
6361 When {expr} is a |List| the number of items in the |List| is
6362 returned.
6363 When {expr} is a |Blob| the number of bytes is returned.
6364 When {expr} is a |Dictionary| the number of entries in the
6365 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006366 When {expr} is an |Object|, invokes the len() method in the
6367 object (if present) to get the length (|object-len()|).
6368 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006369
6370 Can also be used as a |method|: >
6371 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006372<
6373 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006374
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006375
6376 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006377libcall({libname}, {funcname}, {argument})
6378 Call function {funcname} in the run-time library {libname}
6379 with single argument {argument}.
6380 This is useful to call functions in a library that you
6381 especially made to be used with Vim. Since only one argument
6382 is possible, calling standard library functions is rather
6383 limited.
6384 The result is the String returned by the function. If the
6385 function returns NULL, this will appear as an empty string ""
6386 to Vim.
6387 If the function returns a number, use libcallnr()!
6388 If {argument} is a number, it is passed to the function as an
6389 int; if {argument} is a string, it is passed as a
6390 null-terminated string.
6391 This function will fail in |restricted-mode|.
6392
6393 libcall() allows you to write your own 'plug-in' extensions to
6394 Vim without having to recompile the program. It is NOT a
6395 means to call system functions! If you try to do so Vim will
6396 very probably crash.
6397
6398 For Win32, the functions you write must be placed in a DLL
6399 and use the normal C calling convention (NOT Pascal which is
6400 used in Windows System DLLs). The function must take exactly
6401 one parameter, either a character pointer or a long integer,
6402 and must return a character pointer or NULL. The character
6403 pointer returned must point to memory that will remain valid
6404 after the function has returned (e.g. in static data in the
6405 DLL). If it points to allocated memory, that memory will
6406 leak away. Using a static buffer in the function should work,
6407 it's then freed when the DLL is unloaded.
6408
6409 WARNING: If the function returns a non-valid pointer, Vim may
6410 crash! This also happens if the function returns a number,
6411 because Vim thinks it's a pointer.
6412 For Win32 systems, {libname} should be the filename of the DLL
6413 without the ".DLL" suffix. A full path is only required if
6414 the DLL is not in the usual places.
6415 For Unix: When compiling your own plugins, remember that the
6416 object code must be compiled as position-independent ('PIC').
6417 {only in Win32 and some Unix versions, when the |+libcall|
6418 feature is present}
6419 Examples: >
6420 :echo libcall("libc.so", "getenv", "HOME")
6421
6422< Can also be used as a |method|, the base is passed as the
6423 third argument: >
6424 GetValue()->libcall("libc.so", "getenv")
6425<
6426 *libcallnr()*
6427libcallnr({libname}, {funcname}, {argument})
6428 Just like |libcall()|, but used for a function that returns an
6429 int instead of a string.
6430 {only in Win32 on some Unix versions, when the |+libcall|
6431 feature is present}
6432 Examples: >
6433 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6434 :call libcallnr("libc.so", "printf", "Hello World!\n")
6435 :call libcallnr("libc.so", "sleep", 10)
6436<
6437 Can also be used as a |method|, the base is passed as the
6438 third argument: >
6439 GetValue()->libcallnr("libc.so", "printf")
6440<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006441 Return type: |String|
6442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006443
6444line({expr} [, {winid}]) *line()*
6445 The result is a Number, which is the line number of the file
6446 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006447 See |getpos()| for accepted positions.
6448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006449 To get the column number use |col()|. To get both use
6450 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006452 With the optional {winid} argument the values are obtained for
6453 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006454
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006455 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006457 Examples: >
6458 line(".") line number of the cursor
6459 line(".", winid) idem, in window "winid"
6460 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006461 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006462<
6463 To jump to the last known position when opening a file see
6464 |last-position-jump|.
6465
6466 Can also be used as a |method|: >
6467 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006468<
6469 Return type: |Number|
6470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471
6472line2byte({lnum}) *line2byte()*
6473 Return the byte count from the start of the buffer for line
6474 {lnum}. This includes the end-of-line character, depending on
6475 the 'fileformat' option for the current buffer. The first
6476 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6477 This can also be used to get the byte count for the line just
6478 below the last line: >
6479 line2byte(line("$") + 1)
6480< This is the buffer size plus one. If 'fileencoding' is empty
6481 it is the file size plus one. {lnum} is used like with
6482 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6483 feature has been disabled at compile time, -1 is returned.
6484 Also see |byte2line()|, |go| and |:goto|.
6485
6486 Can also be used as a |method|: >
6487 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006488<
6489 Return type: |Number|
6490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006491
6492lispindent({lnum}) *lispindent()*
6493 Get the amount of indent for line {lnum} according the lisp
6494 indenting rules, as with 'lisp'.
6495 The indent is counted in spaces, the value of 'tabstop' is
6496 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006497 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006498 error is given.
6499
6500 Can also be used as a |method|: >
6501 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006502<
6503 Return type: |Number|
6504
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006505
6506list2blob({list}) *list2blob()*
6507 Return a Blob concatenating all the number values in {list}.
6508 Examples: >
6509 list2blob([1, 2, 3, 4]) returns 0z01020304
6510 list2blob([]) returns 0z
6511< Returns an empty Blob on error. If one of the numbers is
6512 negative or more than 255 error *E1239* is given.
6513
6514 |blob2list()| does the opposite.
6515
6516 Can also be used as a |method|: >
6517 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006518<
6519 Return type: |Blob|
6520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006521
6522list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006523 Convert each number in {list} to a character string and
6524 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006525 list2str([32]) returns " "
6526 list2str([65, 66, 67]) returns "ABC"
6527< The same can be done (slowly) with: >
6528 join(map(list, {nr, val -> nr2char(val)}), '')
6529< |str2list()| does the opposite.
6530
6531 When {utf8} is omitted or zero, the current 'encoding' is used.
6532 When {utf8} is TRUE, always return UTF-8 characters.
6533 With UTF-8 composing characters work as expected: >
6534 list2str([97, 769]) returns "á"
6535<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006536 Returns an empty string on error.
6537
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006538 Can also be used as a |method|: >
6539 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006540<
6541 Return type: |String|
6542
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006543
6544listener_add({callback} [, {buf}]) *listener_add()*
6545 Add a callback function that will be invoked when changes have
6546 been made to buffer {buf}.
6547 {buf} refers to a buffer name or number. For the accepted
6548 values, see |bufname()|. When {buf} is omitted the current
6549 buffer is used.
6550 Returns a unique ID that can be passed to |listener_remove()|.
6551
6552 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006553 bufnr the buffer that was changed
6554 start first changed line number
6555 end first line number below the change
6556 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006557 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006558 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006559
6560 Example: >
6561 func Listener(bufnr, start, end, added, changes)
6562 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6563 endfunc
6564 call listener_add('Listener', bufnr)
6565
Bram Moolenaar944697a2022-02-20 19:48:20 +00006566< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006567 dictionary with these entries:
6568 lnum the first line number of the change
6569 end the first line below the change
6570 added number of lines added; negative if lines were
6571 deleted
6572 col first column in "lnum" that was affected by
6573 the change; one if unknown or the whole line
6574 was affected; this is a byte index, first
6575 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006576 When lines are inserted (not when a line is split, e.g. by
6577 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006578 lnum line above which the new line is added
6579 end equal to "lnum"
6580 added number of lines inserted
6581 col 1
6582 When lines are deleted the values are:
6583 lnum the first deleted line
6584 end the line below the first deleted line, before
6585 the deletion was done
6586 added negative, number of lines deleted
6587 col 1
6588 When lines are changed:
6589 lnum the first changed line
6590 end the line below the last changed line
6591 added 0
6592 col first column with a change or 1
6593
6594 The entries are in the order the changes were made, thus the
6595 most recent change is at the end. The line numbers are valid
6596 when the callback is invoked, but later changes may make them
6597 invalid, thus keeping a copy for later might not work.
6598
6599 The {callback} is invoked just before the screen is updated,
6600 when |listener_flush()| is called or when a change is being
6601 made that changes the line count in a way it causes a line
6602 number in the list of changes to become invalid.
6603
6604 The {callback} is invoked with the text locked, see
6605 |textlock|. If you do need to make changes to the buffer, use
6606 a timer to do this later |timer_start()|.
6607
6608 The {callback} is not invoked when the buffer is first loaded.
6609 Use the |BufReadPost| autocmd event to handle the initial text
6610 of a buffer.
6611 The {callback} is also not invoked when the buffer is
6612 unloaded, use the |BufUnload| autocmd event for that.
6613
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006614 Returns zero if {callback} or {buf} is invalid.
6615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006616 Can also be used as a |method|, the base is passed as the
6617 second argument: >
6618 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006619<
6620 Return type: |Number|
6621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006622
6623listener_flush([{buf}]) *listener_flush()*
6624 Invoke listener callbacks for buffer {buf}. If there are no
6625 pending changes then no callbacks are invoked.
6626
6627 {buf} refers to a buffer name or number. For the accepted
6628 values, see |bufname()|. When {buf} is omitted the current
6629 buffer is used.
6630
6631 Can also be used as a |method|: >
6632 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006633<
6634 Return type: |Number|
6635
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006636
6637listener_remove({id}) *listener_remove()*
6638 Remove a listener previously added with listener_add().
6639 Returns FALSE when {id} could not be found, TRUE when {id} was
6640 removed.
6641
6642 Can also be used as a |method|: >
6643 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006644<
6645 Return type: |Number|
6646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006647
6648localtime() *localtime()*
6649 Return the current time, measured as seconds since 1st Jan
6650 1970. See also |strftime()|, |strptime()| and |getftime()|.
6651
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006652 Return type: |Number|
6653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006654
6655log({expr}) *log()*
6656 Return the natural logarithm (base e) of {expr} as a |Float|.
6657 {expr} must evaluate to a |Float| or a |Number| in the range
6658 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006659 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006660 Examples: >
6661 :echo log(10)
6662< 2.302585 >
6663 :echo log(exp(5))
6664< 5.0
6665
6666 Can also be used as a |method|: >
6667 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006668<
6669 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006670
6671
6672log10({expr}) *log10()*
6673 Return the logarithm of Float {expr} to base 10 as a |Float|.
6674 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006675 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006676 Examples: >
6677 :echo log10(1000)
6678< 3.0 >
6679 :echo log10(0.01)
6680< -2.0
6681
6682 Can also be used as a |method|: >
6683 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006684<
6685 Return type: |Float|
6686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006687
6688luaeval({expr} [, {expr}]) *luaeval()*
6689 Evaluate Lua expression {expr} and return its result converted
6690 to Vim data structures. Second {expr} may hold additional
6691 argument accessible as _A inside first {expr}.
6692 Strings are returned as they are.
6693 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006694 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006695 Dictionaries and lists obtained by vim.eval() are returned
6696 as-is.
6697 Other objects are returned as zero without any errors.
6698 See |lua-luaeval| for more details.
6699 Note that in a `:def` function local variables are not visible
6700 to {expr}.
6701
6702 Can also be used as a |method|: >
6703 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006704<
6705 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006706
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006707 {only available when compiled with the |+lua| feature}
6708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006709
6710map({expr1}, {expr2}) *map()*
6711 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006712 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006713 item in {expr1} with the result of evaluating {expr2}.
6714 For a |Blob| each byte is replaced.
6715 For a |String|, each character, including composing
6716 characters, is replaced.
6717 If the item type changes you may want to use |mapnew()| to
6718 create a new List or Dictionary. This is required when using
6719 Vim9 script.
6720
6721 {expr2} must be a |String| or |Funcref|.
6722
6723 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6724 of the current item. For a |Dictionary| |v:key| has the key
6725 of the current item and for a |List| |v:key| has the index of
6726 the current item. For a |Blob| |v:key| has the index of the
6727 current byte. For a |String| |v:key| has the index of the
6728 current character.
6729 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006730 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006731< This puts "> " before and " <" after each item in "mylist".
6732
6733 Note that {expr2} is the result of an expression and is then
6734 used as an expression again. Often it is good to use a
6735 |literal-string| to avoid having to double backslashes. You
6736 still have to double ' quotes
6737
6738 If {expr2} is a |Funcref| it is called with two arguments:
6739 1. The key or the index of the current item.
6740 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006741 With a legacy script lambda you don't get an error if it only
6742 accepts one argument, but with a Vim9 lambda you get "E1106:
6743 One argument too many", the number of arguments must match.
6744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006745 The function must return the new value of the item. Example
6746 that changes each value by "key-value": >
6747 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006748 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006749 endfunc
6750 call map(myDict, function('KeyValue'))
6751< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006752 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006753< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006754 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006755< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006756 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006757<
6758 The operation is done in-place for a |List| and |Dictionary|.
6759 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006760 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006761
6762< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6763 or a new |Blob| or |String|.
6764 When an error is encountered while evaluating {expr2} no
6765 further items in {expr1} are processed.
6766 When {expr2} is a Funcref errors inside a function are ignored,
6767 unless it was defined with the "abort" flag.
6768
6769 Can also be used as a |method|: >
6770 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006771<
6772 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6773 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006774
6775
6776maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6777 When {dict} is omitted or zero: Return the rhs of mapping
6778 {name} in mode {mode}. The returned String has special
6779 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006780 listing. When {dict} is TRUE a dictionary is returned, see
6781 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006782
6783 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006784 returned if {dict} is FALSE, otherwise returns an empty Dict.
6785 When the mapping for {name} is empty, then "<Nop>" is
6786 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006787
6788 The {name} can have special key names, like in the ":map"
6789 command.
6790
6791 {mode} can be one of these strings:
6792 "n" Normal
6793 "v" Visual (including Select)
6794 "o" Operator-pending
6795 "i" Insert
6796 "c" Cmd-line
6797 "s" Select
6798 "x" Visual
6799 "l" langmap |language-mapping|
6800 "t" Terminal-Job
6801 "" Normal, Visual and Operator-pending
6802 When {mode} is omitted, the modes for "" are used.
6803
6804 When {abbr} is there and it is |TRUE| use abbreviations
6805 instead of mappings.
6806
6807 When {dict} is there and it is |TRUE| return a dictionary
6808 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006809 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006810 "lhs" The {lhs} of the mapping as it would be typed
6811 "lhsraw" The {lhs} of the mapping as raw bytes
6812 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6813 form, only present when it differs from "lhsraw"
6814 "rhs" The {rhs} of the mapping as typed.
6815 "silent" 1 for a |:map-silent| mapping, else 0.
6816 "noremap" 1 if the {rhs} of the mapping is not remappable.
6817 "script" 1 if mapping was defined with <script>.
6818 "expr" 1 for an expression mapping (|:map-<expr>|).
6819 "buffer" 1 for a buffer local mapping (|:map-local|).
6820 "mode" Modes for which the mapping is defined. In
6821 addition to the modes mentioned above, these
6822 characters will be used:
6823 " " Normal, Visual and Operator-pending
6824 "!" Insert and Commandline mode
6825 (|mapmode-ic|)
6826 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006827 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006828 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006829 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006830 "lnum" The line number in "sid", zero if unknown.
6831 "nowait" Do not wait for other, longer mappings.
6832 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006833 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006834 "mode_bits" Vim's internal binary representation of "mode".
6835 |mapset()| ignores this; only "mode" is used.
6836 See |maplist()| for usage examples. The values
6837 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006838
6839 The dictionary can be used to restore a mapping with
6840 |mapset()|.
6841
6842 The mappings local to the current buffer are checked first,
6843 then the global mappings.
6844 This function can be used to map a key even when it's already
6845 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006846 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006847
6848< Can also be used as a |method|: >
6849 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006850<
6851 Return type: |String| or dict<any> depending on {dict}
6852
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006853
6854mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6855 Check if there is a mapping that matches with {name} in mode
6856 {mode}. See |maparg()| for {mode} and special names in
6857 {name}.
6858 When {abbr} is there and it is |TRUE| use abbreviations
6859 instead of mappings.
6860 A match happens with a mapping that starts with {name} and
6861 with a mapping which is equal to the start of {name}.
6862
6863 matches mapping "a" "ab" "abc" ~
6864 mapcheck("a") yes yes yes
6865 mapcheck("abc") yes yes yes
6866 mapcheck("ax") yes no no
6867 mapcheck("b") no no no
6868
6869 The difference with maparg() is that mapcheck() finds a
6870 mapping that matches with {name}, while maparg() only finds a
6871 mapping for {name} exactly.
6872 When there is no mapping that starts with {name}, an empty
6873 String is returned. If there is one, the RHS of that mapping
6874 is returned. If there are several mappings that start with
6875 {name}, the RHS of one of them is returned. This will be
6876 "<Nop>" if the RHS is empty.
6877 The mappings local to the current buffer are checked first,
6878 then the global mappings.
6879 This function can be used to check if a mapping can be added
6880 without being ambiguous. Example: >
6881 :if mapcheck("_vv") == ""
6882 : map _vv :set guifont=7x13<CR>
6883 :endif
6884< This avoids adding the "_vv" mapping when there already is a
6885 mapping for "_v" or for "_vvv".
6886
6887 Can also be used as a |method|: >
6888 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006889<
6890 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006891
6892
Ernie Rael09661202022-04-25 14:40:44 +01006893maplist([{abbr}]) *maplist()*
6894 Returns a |List| of all mappings. Each List item is a |Dict|,
6895 the same as what is returned by |maparg()|, see
6896 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6897 abbreviations instead of mappings.
6898
6899 Example to show all mappings with 'MultiMatch' in rhs: >
6900 vim9script
6901 echo maplist()->filter(
6902 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006903< It can be tricky to find mappings for particular |:map-modes|.
6904 |mapping-dict|'s "mode_bits" can simplify this. For example,
6905 the mode_bits for Normal, Insert or Command-line modes are
6906 0x19. To find all the mappings available in those modes you
6907 can do: >
6908 vim9script
6909 var saved_maps = []
6910 for m in maplist()
6911 if and(m.mode_bits, 0x19) != 0
6912 saved_maps->add(m)
6913 endif
6914 endfor
6915 echo saved_maps->mapnew((_, m) => m.lhs)
6916< The values of the mode_bits are defined in Vim's src/vim.h
6917 file and they can be discovered at runtime using
6918 |:map-commands| and "maplist()". Example: >
6919 vim9script
6920 omap xyzzy <Nop>
6921 var op_bit = maplist()->filter(
6922 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6923 ounmap xyzzy
6924 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006925<
6926 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006927
6928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006929mapnew({expr1}, {expr2}) *mapnew()*
6930 Like |map()| but instead of replacing items in {expr1} a new
6931 List or Dictionary is created and returned. {expr1} remains
6932 unchanged. Items can still be changed by {expr2}, if you
6933 don't want that use |deepcopy()| first.
6934
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006935 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6936 depending on {expr1}
6937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006938
6939mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006940mapset({dict})
6941 Restore a mapping from a dictionary, possibly returned by
6942 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6943 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006944 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006945 feature allows copying mappings from one buffer to another.
6946 The dict.mode value may restore a single mapping that covers
6947 more than one mode, like with mode values of '!', ' ', 'nox',
6948 or 'v'. *E1276*
6949
6950 In the first form, {mode} and {abbr} should be the same as
6951 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006952 {mode} is used to define the mode in which the mapping is set,
6953 not the "mode" entry in {dict}.
6954 Example for saving and restoring a mapping: >
6955 let save_map = maparg('K', 'n', 0, 1)
6956 nnoremap K somethingelse
6957 ...
6958 call mapset('n', 0, save_map)
6959< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006960 e.g. with `:map!`, you need to save/restore the mapping for
6961 all of them, when they might differ.
6962
6963 In the second form, with {dict} as the only argument, mode
6964 and abbr are taken from the dict.
6965 Example: >
6966 vim9script
6967 var save_maps = maplist()->filter(
6968 (_, m) => m.lhs == 'K')
6969 nnoremap K somethingelse
6970 cnoremap K somethingelse2
6971 # ...
6972 unmap K
6973 for d in save_maps
6974 mapset(d)
6975 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006976<
6977 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006978
6979
6980match({expr}, {pat} [, {start} [, {count}]]) *match()*
6981 When {expr} is a |List| then this returns the index of the
6982 first item where {pat} matches. Each item is used as a
6983 String, |Lists| and |Dictionaries| are used as echoed.
6984
6985 Otherwise, {expr} is used as a String. The result is a
6986 Number, which gives the index (byte offset) in {expr} where
6987 {pat} matches.
6988
6989 A match at the first character or |List| item returns zero.
6990 If there is no match -1 is returned.
6991
6992 For getting submatches see |matchlist()|.
6993 Example: >
6994 :echo match("testing", "ing") " results in 4
6995 :echo match([1, 'x'], '\a') " results in 1
6996< See |string-match| for how {pat} is used.
6997 *strpbrk()*
6998 Vim doesn't have a strpbrk() function. But you can do: >
6999 :let sepidx = match(line, '[.,;: \t]')
7000< *strcasestr()*
7001 Vim doesn't have a strcasestr() function. But you can add
7002 "\c" to the pattern to ignore case: >
7003 :let idx = match(haystack, '\cneedle')
7004<
7005 If {start} is given, the search starts from byte index
7006 {start} in a String or item {start} in a |List|.
7007 The result, however, is still the index counted from the
7008 first character/item. Example: >
7009 :echo match("testing", "ing", 2)
7010< result is again "4". >
7011 :echo match("testing", "ing", 4)
7012< result is again "4". >
7013 :echo match("testing", "t", 2)
7014< result is "3".
7015 For a String, if {start} > 0 then it is like the string starts
7016 {start} bytes later, thus "^" will match at {start}. Except
7017 when {count} is given, then it's like matches before the
7018 {start} byte are ignored (this is a bit complicated to keep it
7019 backwards compatible).
7020 For a String, if {start} < 0, it will be set to 0. For a list
7021 the index is counted from the end.
7022 If {start} is out of range ({start} > strlen({expr}) for a
7023 String or {start} > len({expr}) for a |List|) -1 is returned.
7024
7025 When {count} is given use the {count}'th match. When a match
7026 is found in a String the search for the next one starts one
7027 character further. Thus this example results in 1: >
7028 echo match("testing", "..", 0, 2)
7029< In a |List| the search continues in the next item.
7030 Note that when {count} is added the way {start} works changes,
7031 see above.
7032
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007033 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007034 See |pattern| for the patterns that are accepted.
7035 The 'ignorecase' option is used to set the ignore-caseness of
7036 the pattern. 'smartcase' is NOT used. The matching is always
7037 done like 'magic' is set and 'cpoptions' is empty.
7038 Note that a match at the start is preferred, thus when the
7039 pattern is using "*" (any number of matches) it tends to find
7040 zero matches at the start instead of a number of matches
7041 further down in the text.
7042
7043 Can also be used as a |method|: >
7044 GetText()->match('word')
7045 GetList()->match('word')
7046<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007047 Return type: |Number|
7048
7049
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007050 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007051matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7052 Defines a pattern to be highlighted in the current window (a
7053 "match"). It will be highlighted with {group}. Returns an
7054 identification number (ID), which can be used to delete the
7055 match using |matchdelete()|. The ID is bound to the window.
7056 Matching is case sensitive and magic, unless case sensitivity
7057 or magicness are explicitly overridden in {pattern}. The
7058 'magic', 'smartcase' and 'ignorecase' options are not used.
7059 The "Conceal" value is special, it causes the match to be
7060 concealed.
7061
7062 The optional {priority} argument assigns a priority to the
7063 match. A match with a high priority will have its
7064 highlighting overrule that of a match with a lower priority.
7065 A priority is specified as an integer (negative numbers are no
7066 exception). If the {priority} argument is not specified, the
7067 default priority is 10. The priority of 'hlsearch' is zero,
7068 hence all matches with a priority greater than zero will
7069 overrule it. Syntax highlighting (see 'syntax') is a separate
7070 mechanism, and regardless of the chosen priority a match will
7071 always overrule syntax highlighting.
7072
7073 The optional {id} argument allows the request for a specific
7074 match ID. If a specified ID is already taken, an error
7075 message will appear and the match will not be added. An ID
7076 is specified as a positive integer (zero excluded). IDs 1, 2
7077 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007078 respectively. 3 is reserved for use by the |matchparen|
7079 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007080 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007081 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007082
7083 The optional {dict} argument allows for further custom
7084 values. Currently this is used to specify a match specific
7085 conceal character that will be shown for |hl-Conceal|
7086 highlighted matches. The dict can have the following members:
7087
7088 conceal Special character to show instead of the
7089 match (only for |hl-Conceal| highlighted
7090 matches, see |:syn-cchar|)
7091 window Instead of the current window use the
7092 window with this number or window ID.
7093
7094 The number of matches is not limited, as it is the case with
7095 the |:match| commands.
7096
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007097 Returns -1 on error.
7098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007099 Example: >
7100 :highlight MyGroup ctermbg=green guibg=green
7101 :let m = matchadd("MyGroup", "TODO")
7102< Deletion of the pattern: >
7103 :call matchdelete(m)
7104
7105< A list of matches defined by |matchadd()| and |:match| are
7106 available from |getmatches()|. All matches can be deleted in
7107 one operation by |clearmatches()|.
7108
7109 Can also be used as a |method|: >
7110 GetGroup()->matchadd('TODO')
7111<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007112 Return type: |Number|
7113
7114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007115 *matchaddpos()*
7116matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7117 Same as |matchadd()|, but requires a list of positions {pos}
7118 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007119 because it does not handle regular expressions and it sets
7120 buffer line boundaries to redraw screen. It is supposed to be
7121 used when fast match additions and deletions are required, for
7122 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007123
7124 {pos} is a list of positions. Each position can be one of
7125 these:
7126 - A number. This whole line will be highlighted. The first
7127 line has number 1.
7128 - A list with one number, e.g., [23]. The whole line with this
7129 number will be highlighted.
7130 - A list with two numbers, e.g., [23, 11]. The first number is
7131 the line number, the second one is the column number (first
7132 column is 1, the value must correspond to the byte index as
7133 |col()| would return). The character at this position will
7134 be highlighted.
7135 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7136 the third number gives the length of the highlight in bytes.
7137
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007138 Returns -1 on error.
7139
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007140 Example: >
7141 :highlight MyGroup ctermbg=green guibg=green
7142 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7143< Deletion of the pattern: >
7144 :call matchdelete(m)
7145
7146< Matches added by |matchaddpos()| are returned by
7147 |getmatches()|.
7148
7149 Can also be used as a |method|: >
7150 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007151<
7152 Return type: |Number|
7153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007154
7155matcharg({nr}) *matcharg()*
7156 Selects the {nr} match item, as set with a |:match|,
7157 |:2match| or |:3match| command.
7158 Return a |List| with two elements:
7159 The name of the highlight group used
7160 The pattern used.
7161 When {nr} is not 1, 2 or 3 returns an empty |List|.
7162 When there is no match item set returns ['', ''].
7163 This is useful to save and restore a |:match|.
7164 Highlighting matches using the |:match| commands are limited
7165 to three matches. |matchadd()| does not have this limitation.
7166
7167 Can also be used as a |method|: >
7168 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007169<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007170 Return type: list<string>
7171
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007172 *matchbufline()*
7173matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7174 Returns the |List| of matches in lines from {lnum} to {end} in
7175 buffer {buf} where {pat} matches.
7176
7177 {lnum} and {end} can either be a line number or the string "$"
7178 to refer to the last line in {buf}.
7179
7180 The {dict} argument supports following items:
7181 submatches include submatch information (|/\(|)
7182
7183 For each match, a |Dict| with the following items is returned:
7184 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007185 lnum line number where there is a match
7186 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007187 Note that there can be multiple matches in a single line.
7188
7189 This function works only for loaded buffers. First call
7190 |bufload()| if needed.
7191
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007192 See |match-pattern| for information about the effect of some
7193 option settings on the pattern.
7194
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007195 When {buf} is not a valid buffer, the buffer is not loaded or
7196 {lnum} or {end} is not valid then an error is given and an
7197 empty |List| is returned.
7198
7199 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007200 " Assuming line 3 in buffer 5 contains "a"
7201 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7202 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7203 " Assuming line 4 in buffer 10 contains "tik tok"
7204 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7205 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007206<
7207 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007208 "\1", "\2", etc. are also returned. Example: >
7209 " Assuming line 2 in buffer 2 contains "acd"
7210 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007211 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007212 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007213< The "submatches" List always contains 9 items. If a submatch
7214 is not found, then an empty string is returned for that
7215 submatch.
7216
7217 Can also be used as a |method|: >
7218 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007219<
7220 Return type: list<dict<any>> or list<any>
7221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007222
h-east624bb832024-11-09 18:37:32 +01007223matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007224 Deletes a match with ID {id} previously defined by |matchadd()|
7225 or one of the |:match| commands. Returns 0 if successful,
7226 otherwise -1. See example for |matchadd()|. All matches can
7227 be deleted in one operation by |clearmatches()|.
7228 If {win} is specified, use the window with this number or
7229 window ID instead of the current window.
7230
7231 Can also be used as a |method|: >
7232 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007233<
7234 Return type: |Number|
7235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007236
7237matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7238 Same as |match()|, but return the index of first character
7239 after the match. Example: >
7240 :echo matchend("testing", "ing")
7241< results in "7".
7242 *strspn()* *strcspn()*
7243 Vim doesn't have a strspn() or strcspn() function, but you can
7244 do it with matchend(): >
7245 :let span = matchend(line, '[a-zA-Z]')
7246 :let span = matchend(line, '[^a-zA-Z]')
7247< Except that -1 is returned when there are no matches.
7248
7249 The {start}, if given, has the same meaning as for |match()|. >
7250 :echo matchend("testing", "ing", 2)
7251< results in "7". >
7252 :echo matchend("testing", "ing", 5)
7253< result is "-1".
7254 When {expr} is a |List| the result is equal to |match()|.
7255
7256 Can also be used as a |method|: >
7257 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007258<
7259 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007260
7261
7262matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7263 If {list} is a list of strings, then returns a |List| with all
7264 the strings in {list} that fuzzy match {str}. The strings in
7265 the returned list are sorted based on the matching score.
7266
7267 The optional {dict} argument always supports the following
7268 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007269 matchseq When this item is present return only matches
7270 that contain the characters in {str} in the
7271 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007272 limit Maximum number of matches in {list} to be
7273 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007274
7275 If {list} is a list of dictionaries, then the optional {dict}
7276 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007277 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007278 {str}. The value of this item should be a
7279 string.
7280 text_cb |Funcref| that will be called for every item
7281 in {list} to get the text for fuzzy matching.
7282 This should accept a dictionary item as the
7283 argument and return the text for that item to
7284 use for fuzzy matching.
7285
7286 {str} is treated as a literal string and regular expression
7287 matching is NOT supported. The maximum supported {str} length
7288 is 256.
7289
7290 When {str} has multiple words each separated by white space,
7291 then the list of strings that have all the words is returned.
7292
7293 If there are no matching strings or there is an error, then an
7294 empty list is returned. If length of {str} is greater than
7295 256, then returns an empty list.
7296
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007297 When {limit} is given, matchfuzzy() will find up to this
7298 number of matches in {list} and return them in sorted order.
7299
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007300 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007301 matching strings.
7302
7303 Example: >
7304 :echo matchfuzzy(["clay", "crow"], "cay")
7305< results in ["clay"]. >
7306 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7307< results in a list of buffer names fuzzy matching "ndl". >
7308 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7309< results in a list of buffer information dicts with buffer
7310 names fuzzy matching "ndl". >
7311 :echo getbufinfo()->matchfuzzy("spl",
7312 \ {'text_cb' : {v -> v.name}})
7313< results in a list of buffer information dicts with buffer
7314 names fuzzy matching "spl". >
7315 :echo v:oldfiles->matchfuzzy("test")
7316< results in a list of file names fuzzy matching "test". >
7317 :let l = readfile("buffer.c")->matchfuzzy("str")
7318< results in a list of lines in "buffer.c" fuzzy matching "str". >
7319 :echo ['one two', 'two one']->matchfuzzy('two one')
7320< results in ['two one', 'one two']. >
7321 :echo ['one two', 'two one']->matchfuzzy('two one',
7322 \ {'matchseq': 1})
7323< results in ['two one'].
7324
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007325 Return type: list<string> or list<any>
7326
7327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007328matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7329 Same as |matchfuzzy()|, but returns the list of matched
7330 strings, the list of character positions where characters
7331 in {str} matches and a list of matching scores. You can
7332 use |byteidx()| to convert a character position to a byte
7333 position.
7334
7335 If {str} matches multiple times in a string, then only the
7336 positions for the best match is returned.
7337
7338 If there are no matching strings or there is an error, then a
7339 list with three empty list items is returned.
7340
7341 Example: >
7342 :echo matchfuzzypos(['testing'], 'tsg')
7343< results in [['testing'], [[0, 2, 6]], [99]] >
7344 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7345< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7346 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7347< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007349 Return type: list<list<any>>
7350
7351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007352matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7353 Same as |match()|, but return a |List|. The first item in the
7354 list is the matched string, same as what matchstr() would
7355 return. Following items are submatches, like "\1", "\2", etc.
7356 in |:substitute|. When an optional submatch didn't match an
7357 empty string is used. Example: >
7358 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7359< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7360 When there is no match an empty list is returned.
7361
7362 You can pass in a List, but that is not very useful.
7363
7364 Can also be used as a |method|: >
7365 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007366<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007367 Return type: list<string> or list<any>
7368
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007369 *matchstrlist()*
7370matchstrlist({list}, {pat} [, {dict}])
7371 Returns the |List| of matches in {list} where {pat} matches.
7372 {list} is a |List| of strings. {pat} is matched against each
7373 string in {list}.
7374
7375 The {dict} argument supports following items:
7376 submatches include submatch information (|/\(|)
7377
7378 For each match, a |Dict| with the following items is returned:
7379 byteidx starting byte index of the match.
7380 idx index in {list} of the match.
7381 text matched string
7382 submatches a List of submatches. Present only if
7383 "submatches" is set to v:true in {dict}.
7384
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007385 See |match-pattern| for information about the effect of some
7386 option settings on the pattern.
7387
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007388 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007389 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7390 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7391 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7392 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007393<
7394 If "submatches" is present and is v:true, then submatches like
7395 "\1", "\2", etc. are also returned. Example: >
7396 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7397 \ #{submatches: v:true})
7398 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7399< The "submatches" List always contains 9 items. If a submatch
7400 is not found, then an empty string is returned for that
7401 submatch.
7402
7403 Can also be used as a |method|: >
7404 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007405<
7406 Return type: list<dict<any>> or list<any>
7407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007408
7409matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7410 Same as |match()|, but return the matched string. Example: >
7411 :echo matchstr("testing", "ing")
7412< results in "ing".
7413 When there is no match "" is returned.
7414 The {start}, if given, has the same meaning as for |match()|. >
7415 :echo matchstr("testing", "ing", 2)
7416< results in "ing". >
7417 :echo matchstr("testing", "ing", 5)
7418< result is "".
7419 When {expr} is a |List| then the matching item is returned.
7420 The type isn't changed, it's not necessarily a String.
7421
7422 Can also be used as a |method|: >
7423 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007424<
7425 Return type: |String|
7426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007427
7428matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7429 Same as |matchstr()|, but return the matched string, the start
7430 position and the end position of the match. Example: >
7431 :echo matchstrpos("testing", "ing")
7432< results in ["ing", 4, 7].
7433 When there is no match ["", -1, -1] is returned.
7434 The {start}, if given, has the same meaning as for |match()|. >
7435 :echo matchstrpos("testing", "ing", 2)
7436< results in ["ing", 4, 7]. >
7437 :echo matchstrpos("testing", "ing", 5)
7438< result is ["", -1, -1].
7439 When {expr} is a |List| then the matching item, the index
7440 of first item where {pat} matches, the start position and the
7441 end position of the match are returned. >
7442 :echo matchstrpos([1, '__x'], '\a')
7443< result is ["x", 1, 2, 3].
7444 The type isn't changed, it's not necessarily a String.
7445
7446 Can also be used as a |method|: >
7447 GetText()->matchstrpos('word')
7448<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007449 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007450
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007451
7452max({expr}) *max()*
7453 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007454 echo max([apples, pears, oranges])
7455
7456< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7457 it returns the maximum of all values in the Dictionary.
7458 If {expr} is neither a List nor a Dictionary, or one of the
7459 items in {expr} cannot be used as a Number this results in
7460 an error. An empty |List| or |Dictionary| results in zero.
7461
7462 Can also be used as a |method|: >
7463 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007464<
7465 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007466
7467
7468menu_info({name} [, {mode}]) *menu_info()*
7469 Return information about the specified menu {name} in
7470 mode {mode}. The menu name should be specified without the
7471 shortcut character ('&'). If {name} is "", then the top-level
7472 menu names are returned.
7473
7474 {mode} can be one of these strings:
7475 "n" Normal
7476 "v" Visual (including Select)
7477 "o" Operator-pending
7478 "i" Insert
7479 "c" Cmd-line
7480 "s" Select
7481 "x" Visual
7482 "t" Terminal-Job
7483 "" Normal, Visual and Operator-pending
7484 "!" Insert and Cmd-line
7485 When {mode} is omitted, the modes for "" are used.
7486
7487 Returns a |Dictionary| containing the following items:
7488 accel menu item accelerator text |menu-text|
7489 display display name (name without '&')
7490 enabled v:true if this menu item is enabled
7491 Refer to |:menu-enable|
7492 icon name of the icon file (for toolbar)
7493 |toolbar-icon|
7494 iconidx index of a built-in icon
7495 modes modes for which the menu is defined. In
7496 addition to the modes mentioned above, these
7497 characters will be used:
7498 " " Normal, Visual and Operator-pending
7499 name menu item name.
7500 noremenu v:true if the {rhs} of the menu item is not
7501 remappable else v:false.
7502 priority menu order priority |menu-priority|
7503 rhs right-hand-side of the menu item. The returned
7504 string has special characters translated like
7505 in the output of the ":menu" command listing.
7506 When the {rhs} of a menu item is empty, then
7507 "<Nop>" is returned.
7508 script v:true if script-local remapping of {rhs} is
7509 allowed else v:false. See |:menu-script|.
7510 shortcut shortcut key (character after '&' in
7511 the menu name) |menu-shortcut|
7512 silent v:true if the menu item is created
7513 with <silent> argument |:menu-silent|
7514 submenus |List| containing the names of
7515 all the submenus. Present only if the menu
7516 item has submenus.
7517
7518 Returns an empty dictionary if the menu item is not found.
7519
7520 Examples: >
7521 :echo menu_info('Edit.Cut')
7522 :echo menu_info('File.Save', 'n')
7523
7524 " Display the entire menu hierarchy in a buffer
7525 func ShowMenu(name, pfx)
7526 let m = menu_info(a:name)
7527 call append(line('$'), a:pfx .. m.display)
7528 for child in m->get('submenus', [])
7529 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7530 \ a:pfx .. ' ')
7531 endfor
7532 endfunc
7533 new
7534 for topmenu in menu_info('').submenus
7535 call ShowMenu(topmenu, '')
7536 endfor
7537<
7538 Can also be used as a |method|: >
7539 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007540<
7541 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007542
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007543min({expr}) *min()*
7544 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007545 echo min([apples, pears, oranges])
7546
7547< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7548 it returns the minimum of all values in the Dictionary.
7549 If {expr} is neither a List nor a Dictionary, or one of the
7550 items in {expr} cannot be used as a Number this results in
7551 an error. An empty |List| or |Dictionary| results in zero.
7552
7553 Can also be used as a |method|: >
7554 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007555<
7556 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007557
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007558
7559mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007560 Create directory {name}.
7561
Bram Moolenaar938ae282023-02-20 20:44:55 +00007562 When {flags} is present it must be a string. An empty string
7563 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007564
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007565 {flags} can contain these character flags:
7566 "p" intermediate directories will be created as necessary
7567 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007568 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007569 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007570 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007571
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007572 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007573 some directories may already exist. Only the first one that
7574 is created and what it contains is scheduled to be deleted.
7575 E.g. when using: >
7576 call mkdir('subdir/tmp/autoload', 'pR')
7577< and "subdir" already exists then "subdir/tmp" will be
7578 scheduled for deletion, like with: >
7579 defer delete('subdir/tmp', 'rf')
7580< Note that if scheduling the defer fails the directory is not
7581 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007582
7583 If {prot} is given it is used to set the protection bits of
7584 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7585 the user, readable for others). Use 0o700 to make it
7586 unreadable for others. This is only used for the last part of
7587 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7588 created with 0o755.
7589 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007590 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007591
7592< This function is not available in the |sandbox|.
7593
7594 There is no error if the directory already exists and the "p"
7595 flag is passed (since patch 8.0.1708). However, without the
7596 "p" option the call will fail.
7597
7598 The function result is a Number, which is TRUE if the call was
7599 successful or FALSE if the directory creation failed or partly
7600 failed.
7601
7602 Not available on all systems. To check use: >
7603 :if exists("*mkdir")
7604
7605< Can also be used as a |method|: >
7606 GetName()->mkdir()
7607<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007608 Return type: |Number|
7609
7610
7611mode([{expr}]) *mode()*
7612 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007613 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007614 a non-empty String (|non-zero-arg|), then the full mode is
7615 returned, otherwise only the first letter is returned.
7616 Also see |state()|.
7617
7618 n Normal
7619 no Operator-pending
7620 nov Operator-pending (forced characterwise |o_v|)
7621 noV Operator-pending (forced linewise |o_V|)
7622 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7623 CTRL-V is one character
7624 niI Normal using |i_CTRL-O| in |Insert-mode|
7625 niR Normal using |i_CTRL-O| in |Replace-mode|
7626 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7627 nt Terminal-Normal (insert goes to Terminal-Job mode)
7628 v Visual by character
7629 vs Visual by character using |v_CTRL-O| in Select mode
7630 V Visual by line
7631 Vs Visual by line using |v_CTRL-O| in Select mode
7632 CTRL-V Visual blockwise
7633 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7634 s Select by character
7635 S Select by line
7636 CTRL-S Select blockwise
7637 i Insert
7638 ic Insert mode completion |compl-generic|
7639 ix Insert mode |i_CTRL-X| completion
7640 R Replace |R|
7641 Rc Replace mode completion |compl-generic|
7642 Rx Replace mode |i_CTRL-X| completion
7643 Rv Virtual Replace |gR|
7644 Rvc Virtual Replace mode completion |compl-generic|
7645 Rvx Virtual Replace mode |i_CTRL-X| completion
7646 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007647 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007648 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007649 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007650 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007651 ce Normal Ex mode |Q|
7652 r Hit-enter prompt
7653 rm The -- more -- prompt
7654 r? A |:confirm| query of some sort
7655 ! Shell or external command is executing
7656 t Terminal-Job mode: keys go to the job
7657
7658 This is useful in the 'statusline' option or when used
7659 with |remote_expr()| In most other places it always returns
7660 "c" or "n".
7661 Note that in the future more modes and more specific modes may
7662 be added. It's better not to compare the whole string but only
7663 the leading character(s).
7664 Also see |visualmode()|.
7665
7666 Can also be used as a |method|: >
7667 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007668<
7669 Return type: |String|
7670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007671
7672mzeval({expr}) *mzeval()*
7673 Evaluate MzScheme expression {expr} and return its result
7674 converted to Vim data structures.
7675 Numbers and strings are returned as they are.
7676 Pairs (including lists and improper lists) and vectors are
7677 returned as Vim |Lists|.
7678 Hash tables are represented as Vim |Dictionary| type with keys
7679 converted to strings.
7680 All other types are converted to string with display function.
7681 Examples: >
7682 :mz (define l (list 1 2 3))
7683 :mz (define h (make-hash)) (hash-set! h "list" l)
7684 :echo mzeval("l")
7685 :echo mzeval("h")
7686<
7687 Note that in a `:def` function local variables are not visible
7688 to {expr}.
7689
7690 Can also be used as a |method|: >
7691 GetExpr()->mzeval()
7692<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007693 Return type: any, depending on {expr}
7694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007695 {only available when compiled with the |+mzscheme| feature}
7696
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007698nextnonblank({lnum}) *nextnonblank()*
7699 Return the line number of the first line at or below {lnum}
7700 that is not blank. Example: >
7701 if getline(nextnonblank(1)) =~ "Java"
7702< When {lnum} is invalid or there is no non-blank line at or
7703 below it, zero is returned.
7704 {lnum} is used like with |getline()|.
7705 See also |prevnonblank()|.
7706
7707 Can also be used as a |method|: >
7708 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007709<
7710 Return type: |Number|
7711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007712
Christ van Willegenc0786752025-02-01 15:42:16 +01007713ngettext({single}, {plural}, {number}[, {domain}) *ngettext()*
7714 Return a string that contains the correct value for a
7715 message based on the rules for plural form(s) in
7716 a language. Examples: >
7717 ngettext("File", "Files", 2) # returns "Files"
7718<
7719 Can be used as a |method|: >
7720 1->ngettext("File", "Files") # returns "File"
7721<
7722 See |gettext()| for information on the domain parameter.
7723
7724 Return type: |String|
7725
7726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007727nr2char({expr} [, {utf8}]) *nr2char()*
7728 Return a string with a single character, which has the number
7729 value {expr}. Examples: >
7730 nr2char(64) returns "@"
7731 nr2char(32) returns " "
7732< When {utf8} is omitted or zero, the current 'encoding' is used.
7733 Example for "utf-8": >
7734 nr2char(300) returns I with bow character
7735< When {utf8} is TRUE, always return UTF-8 characters.
7736 Note that a NUL character in the file is specified with
7737 nr2char(10), because NULs are represented with newline
7738 characters. nr2char(0) is a real NUL and terminates the
7739 string, thus results in an empty string.
7740 To turn a list of character numbers into a string: >
7741 let list = [65, 66, 67]
7742 let str = join(map(list, {_, val -> nr2char(val)}), '')
7743< Result: "ABC"
7744
7745 Can also be used as a |method|: >
7746 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007747<
7748 Return type: |String|
7749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007750
7751or({expr}, {expr}) *or()*
7752 Bitwise OR on the two arguments. The arguments are converted
7753 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007754 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007755 Example: >
7756 :let bits = or(bits, 0x80)
7757< Can also be used as a |method|: >
7758 :let bits = bits->or(0x80)
7759
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007760< Rationale: The reason this is a function and not using the "|"
7761 character like many languages, is that Vi has always used "|"
7762 to separate commands. In many places it would not be clear if
7763 "|" is an operator or a command separator.
7764
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007765 Return type: |Number|
7766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007767
7768pathshorten({path} [, {len}]) *pathshorten()*
7769 Shorten directory names in the path {path} and return the
7770 result. The tail, the file name, is kept as-is. The other
7771 components in the path are reduced to {len} letters in length.
7772 If {len} is omitted or smaller than 1 then 1 is used (single
7773 letters). Leading '~' and '.' characters are kept. Examples: >
7774 :echo pathshorten('~/.vim/autoload/myfile.vim')
7775< ~/.v/a/myfile.vim ~
7776>
7777 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7778< ~/.vi/au/myfile.vim ~
7779 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007780 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007781
7782 Can also be used as a |method|: >
7783 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007784<
7785 Return type: |String|
7786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007787
7788perleval({expr}) *perleval()*
7789 Evaluate Perl expression {expr} in scalar context and return
7790 its result converted to Vim data structures. If value can't be
7791 converted, it is returned as a string Perl representation.
7792 Note: If you want an array or hash, {expr} must return a
7793 reference to it.
7794 Example: >
7795 :echo perleval('[1 .. 4]')
7796< [1, 2, 3, 4]
7797
7798 Note that in a `:def` function local variables are not visible
7799 to {expr}.
7800
7801 Can also be used as a |method|: >
7802 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007803<
7804 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007805
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007806 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007807
7808
7809popup_ functions are documented here: |popup-functions|
7810
7811
7812pow({x}, {y}) *pow()*
7813 Return the power of {x} to the exponent {y} as a |Float|.
7814 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007815 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007816 Examples: >
7817 :echo pow(3, 3)
7818< 27.0 >
7819 :echo pow(2, 16)
7820< 65536.0 >
7821 :echo pow(32, 0.20)
7822< 2.0
7823
7824 Can also be used as a |method|: >
7825 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007826<
7827 Return type: |Number|
7828
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007829
7830prevnonblank({lnum}) *prevnonblank()*
7831 Return the line number of the first line at or above {lnum}
7832 that is not blank. Example: >
7833 let ind = indent(prevnonblank(v:lnum - 1))
7834< When {lnum} is invalid or there is no non-blank line at or
7835 above it, zero is returned.
7836 {lnum} is used like with |getline()|.
7837 Also see |nextnonblank()|.
7838
7839 Can also be used as a |method|: >
7840 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007841<
7842 Return type: |Number|
7843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007844
7845printf({fmt}, {expr1} ...) *printf()*
7846 Return a String with {fmt}, where "%" items are replaced by
7847 the formatted form of their respective arguments. Example: >
7848 printf("%4d: E%d %.30s", lnum, errno, msg)
7849< May result in:
7850 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7851
7852 When used as a |method| the base is passed as the second
7853 argument: >
7854 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007855<
7856 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007857
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007858 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007859 %s string
7860 %6S string right-aligned in 6 display cells
7861 %6s string right-aligned in 6 bytes
7862 %.9s string truncated to 9 bytes
7863 %c single byte
7864 %d decimal number
7865 %5d decimal number padded with spaces to 5 characters
7866 %x hex number
7867 %04x hex number padded with zeros to at least 4 characters
7868 %X hex number using upper case letters
7869 %o octal number
7870 %08b binary number padded with zeros to at least 8 chars
7871 %f floating point number as 12.23, inf, -inf or nan
7872 %F floating point number as 12.23, INF, -INF or NAN
7873 %e floating point number as 1.23e3, inf, -inf or nan
7874 %E floating point number as 1.23E3, INF, -INF or NAN
7875 %g floating point number, as %f or %e depending on value
7876 %G floating point number, as %F or %E depending on value
7877 %% the % character itself
7878
7879 Conversion specifications start with '%' and end with the
7880 conversion type. All other characters are copied unchanged to
7881 the result.
7882
7883 The "%" starts a conversion specification. The following
7884 arguments appear in sequence:
7885
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007886 % [pos-argument] [flags] [field-width] [.precision] type
7887
7888 pos-argument
7889 At most one positional argument specifier. These
7890 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007891
7892 flags
7893 Zero or more of the following flags:
7894
7895 # The value should be converted to an "alternate
7896 form". For c, d, and s conversions, this option
7897 has no effect. For o conversions, the precision
7898 of the number is increased to force the first
7899 character of the output string to a zero (except
7900 if a zero value is printed with an explicit
7901 precision of zero).
7902 For b and B conversions, a non-zero result has
7903 the string "0b" (or "0B" for B conversions)
7904 prepended to it.
7905 For x and X conversions, a non-zero result has
7906 the string "0x" (or "0X" for X conversions)
7907 prepended to it.
7908
7909 0 (zero) Zero padding. For all conversions the converted
7910 value is padded on the left with zeros rather
7911 than blanks. If a precision is given with a
7912 numeric conversion (d, b, B, o, x, and X), the 0
7913 flag is ignored.
7914
7915 - A negative field width flag; the converted value
7916 is to be left adjusted on the field boundary.
7917 The converted value is padded on the right with
7918 blanks, rather than on the left with blanks or
7919 zeros. A - overrides a 0 if both are given.
7920
7921 ' ' (space) A blank should be left before a positive
7922 number produced by a signed conversion (d).
7923
7924 + A sign must always be placed before a number
7925 produced by a signed conversion. A + overrides
7926 a space if both are used.
7927
7928 field-width
7929 An optional decimal digit string specifying a minimum
7930 field width. If the converted value has fewer bytes
7931 than the field width, it will be padded with spaces on
7932 the left (or right, if the left-adjustment flag has
7933 been given) to fill out the field width. For the S
7934 conversion the count is in cells.
7935
7936 .precision
7937 An optional precision, in the form of a period '.'
7938 followed by an optional digit string. If the digit
7939 string is omitted, the precision is taken as zero.
7940 This gives the minimum number of digits to appear for
7941 d, o, x, and X conversions, the maximum number of
7942 bytes to be printed from a string for s conversions,
7943 or the maximum number of cells to be printed from a
7944 string for S conversions.
7945 For floating point it is the number of digits after
7946 the decimal point.
7947
7948 type
7949 A character that specifies the type of conversion to
7950 be applied, see below.
7951
7952 A field width or precision, or both, may be indicated by an
7953 asterisk '*' instead of a digit string. In this case, a
7954 Number argument supplies the field width or precision. A
7955 negative field width is treated as a left adjustment flag
7956 followed by a positive field width; a negative precision is
7957 treated as though it were missing. Example: >
7958 :echo printf("%d: %.*s", nr, width, line)
7959< This limits the length of the text used from "line" to
7960 "width" bytes.
7961
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007962 If the argument to be formatted is specified using a
7963 positional argument specifier, and a '*' is used to indicate
7964 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007965 precision, the argument(s) to be used must also be specified
7966 using a {n$} positional argument specifier. See |printf-$|.
7967
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007968 The conversion specifiers and their meanings are:
7969
7970 *printf-d* *printf-b* *printf-B* *printf-o*
7971 *printf-x* *printf-X*
7972 dbBoxX The Number argument is converted to signed decimal
7973 (d), unsigned binary (b and B), unsigned octal (o), or
7974 unsigned hexadecimal (x and X) notation. The letters
7975 "abcdef" are used for x conversions; the letters
7976 "ABCDEF" are used for X conversions.
7977 The precision, if any, gives the minimum number of
7978 digits that must appear; if the converted value
7979 requires fewer digits, it is padded on the left with
7980 zeros.
7981 In no case does a non-existent or small field width
7982 cause truncation of a numeric field; if the result of
7983 a conversion is wider than the field width, the field
7984 is expanded to contain the conversion result.
7985 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007986 The 'l' modifier indicates the argument is a long
7987 integer. The size will be 32 bits or 64 bits
7988 depending on your platform.
7989 The "ll" modifier indicates the argument is 64 bits.
7990 The b and B conversion specifiers never take a width
7991 modifier and always assume their argument is a 64 bit
7992 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007993 Generally, these modifiers are not useful. They are
7994 ignored when type is known from the argument.
7995
7996 i alias for d
7997 D alias for ld
7998 U alias for lu
7999 O alias for lo
8000
8001 *printf-c*
8002 c The Number argument is converted to a byte, and the
8003 resulting character is written.
8004
8005 *printf-s*
8006 s The text of the String argument is used. If a
8007 precision is specified, no more bytes than the number
8008 specified are used.
8009 If the argument is not a String type, it is
8010 automatically converted to text with the same format
8011 as ":echo".
8012 *printf-S*
8013 S The text of the String argument is used. If a
8014 precision is specified, no more display cells than the
8015 number specified are used.
8016
8017 *printf-f* *E807*
8018 f F The Float argument is converted into a string of the
8019 form 123.456. The precision specifies the number of
8020 digits after the decimal point. When the precision is
8021 zero the decimal point is omitted. When the precision
8022 is not specified 6 is used. A really big number
8023 (out of range or dividing by zero) results in "inf"
8024 or "-inf" with %f (INF or -INF with %F).
8025 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
8026 Example: >
8027 echo printf("%.2f", 12.115)
8028< 12.12
8029 Note that roundoff depends on the system libraries.
8030 Use |round()| when in doubt.
8031
8032 *printf-e* *printf-E*
8033 e E The Float argument is converted into a string of the
8034 form 1.234e+03 or 1.234E+03 when using 'E'. The
8035 precision specifies the number of digits after the
8036 decimal point, like with 'f'.
8037
8038 *printf-g* *printf-G*
8039 g G The Float argument is converted like with 'f' if the
8040 value is between 0.001 (inclusive) and 10000000.0
8041 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8042 for 'G'. When no precision is specified superfluous
8043 zeroes and '+' signs are removed, except for the zero
8044 immediately after the decimal point. Thus 10000000.0
8045 results in 1.0e7.
8046
8047 *printf-%*
8048 % A '%' is written. No argument is converted. The
8049 complete conversion specification is "%%".
8050
8051 When a Number argument is expected a String argument is also
8052 accepted and automatically converted.
8053 When a Float or String argument is expected a Number argument
8054 is also accepted and automatically converted.
8055 Any other argument type results in an error message.
8056
8057 *E766* *E767*
8058 The number of {exprN} arguments must exactly match the number
8059 of "%" items. If there are not sufficient or too many
8060 arguments an error is given. Up to 18 arguments can be used.
8061
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008062 *printf-$*
8063 In certain languages, error and informative messages are
8064 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008065 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008066 having a different word order, positional arguments may be
8067 used to indicate this. For instance: >
8068
h_east596a9f22023-11-21 21:24:23 +09008069 #, c-format
8070 msgid "%s returning %s"
8071 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008072<
h_east596a9f22023-11-21 21:24:23 +09008073 In this example, the sentence has its 2 string arguments
8074 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008075
h_east596a9f22023-11-21 21:24:23 +09008076 echo printf(
8077 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8078 "Bram", "Moolenaar")
8079< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008080
h_east596a9f22023-11-21 21:24:23 +09008081 echo printf(
8082 "In Belgium, vim's creator's name is: %2$s %1$s",
8083 "Bram", "Moolenaar")
8084< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008085
8086 Width (and precision) can be specified using the '*' specifier.
8087 In this case, you must specify the field width position in the
8088 argument list. >
8089
h_east596a9f22023-11-21 21:24:23 +09008090 echo printf("%1$*2$.*3$d", 1, 2, 3)
8091< 001 >
8092 echo printf("%2$*3$.*1$d", 1, 2, 3)
8093< 2 >
8094 echo printf("%3$*1$.*2$d", 1, 2, 3)
8095< 03 >
8096 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8097< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008098
8099 You can mix specifying the width and/or precision directly
8100 and via positional arguments: >
8101
h_east596a9f22023-11-21 21:24:23 +09008102 echo printf("%1$4.*2$f", 1.4142135, 6)
8103< 1.414214 >
8104 echo printf("%1$*2$.4f", 1.4142135, 6)
8105< 1.4142 >
8106 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8107< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008108
Christ van Willegenc35fc032024-03-14 18:30:41 +01008109 You will get an overflow error |E1510|, when the field-width
8110 or precision will result in a string longer than 6400 chars.
8111
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008112 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008113 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008114 echo printf("%s%1$s", "One", "Two")
8115< E1500: Cannot mix positional and non-positional arguments:
8116 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008117
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008118 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008119 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008120 echo printf("%3$s%1$s", "One", "Two", "Three")
8121< E1501: format argument 2 unused in $-style format:
8122 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008123
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008124 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008125 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008126 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8127< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008128
8129 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008130 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8131< E1502: Positional argument 2 used as field width reused as
8132 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008133
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008134 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008135 When a positional argument is used, but not the correct number
8136 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008137 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8138< E1503: Positional argument 3 out of bounds: %1$d at width
8139 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008140
8141 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008142 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8143< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8144 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008145
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008146 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008147 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008148 echo printf("%1$s %2$s %1$s", "One", "Two")
8149< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008150
8151 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008152 echo printf("%1$s %2$s %1$d", "One", "Two")
8153< E1504: Positional argument 1 type used inconsistently:
8154 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008155
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008156 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008157 Various other errors that lead to a format string being
8158 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008159 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8160< E1505: Invalid format specifier: %1$d at width %2$d is:
8161 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008162
Christ van Willegenea746f92023-10-05 20:48:36 +02008163 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008164 This internal error indicates that the logic to parse a
8165 positional format argument ran into a problem that couldn't be
8166 otherwise reported. Please file a bug against Vim if you run
8167 into this, copying the exact format string and parameters that
8168 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008169
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008170 Return type: |String|
8171
Christ van Willegenea746f92023-10-05 20:48:36 +02008172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008173prompt_getprompt({buf}) *prompt_getprompt()*
8174 Returns the effective prompt text for buffer {buf}. {buf} can
8175 be a buffer name or number. See |prompt-buffer|.
8176
8177 If the buffer doesn't exist or isn't a prompt buffer, an empty
8178 string is returned.
8179
8180 Can also be used as a |method|: >
8181 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008182<
8183 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008184
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008185 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008186
8187
8188prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8189 Set prompt callback for buffer {buf} to {expr}. When {expr}
8190 is an empty string the callback is removed. This has only
8191 effect if {buf} has 'buftype' set to "prompt".
8192
8193 The callback is invoked when pressing Enter. The current
8194 buffer will always be the prompt buffer. A new line for a
8195 prompt is added before invoking the callback, thus the prompt
8196 for which the callback was invoked will be in the last but one
8197 line.
8198 If the callback wants to add text to the buffer, it must
8199 insert it above the last line, since that is where the current
8200 prompt is. This can also be done asynchronously.
8201 The callback is invoked with one argument, which is the text
8202 that was entered at the prompt. This can be an empty string
8203 if the user only typed Enter.
8204 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008205 func s:TextEntered(text)
8206 if a:text == 'exit' || a:text == 'quit'
8207 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008208 " Reset 'modified' to allow the buffer to be closed.
8209 " We assume there is nothing useful to be saved.
8210 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008211 close
8212 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008213 " Do something useful with "a:text". In this example
8214 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008215 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008216 endif
8217 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008218 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008219
8220< Can also be used as a |method|: >
8221 GetBuffer()->prompt_setcallback(callback)
8222
8223< {only available when compiled with the |+channel| feature}
8224
8225prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8226 Set a callback for buffer {buf} to {expr}. When {expr} is an
8227 empty string the callback is removed. This has only effect if
8228 {buf} has 'buftype' set to "prompt".
8229
8230 This callback will be invoked when pressing CTRL-C in Insert
8231 mode. Without setting a callback Vim will exit Insert mode,
8232 as in any buffer.
8233
8234 Can also be used as a |method|: >
8235 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008236<
8237 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008238
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008239 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008240
8241prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8242 Set prompt for buffer {buf} to {text}. You most likely want
8243 {text} to end in a space.
8244 The result is only visible if {buf} has 'buftype' set to
8245 "prompt". Example: >
8246 call prompt_setprompt(bufnr(), 'command: ')
8247<
8248 Can also be used as a |method|: >
8249 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008250<
8251 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008252
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008253 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008254
8255prop_ functions are documented here: |text-prop-functions|
8256
8257pum_getpos() *pum_getpos()*
8258 If the popup menu (see |ins-completion-menu|) is not visible,
8259 returns an empty |Dictionary|, otherwise, returns a
8260 |Dictionary| with the following keys:
8261 height nr of items visible
8262 width screen cells
8263 row top screen row (0 first row)
8264 col leftmost screen column (0 first col)
8265 size total nr of items
8266 scrollbar |TRUE| if scrollbar is visible
8267
8268 The values are the same as in |v:event| during
8269 |CompleteChanged|.
8270
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008271 Return type: dict<any>
8272
8273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008274pumvisible() *pumvisible()*
8275 Returns non-zero when the popup menu is visible, zero
8276 otherwise. See |ins-completion-menu|.
8277 This can be used to avoid some things that would remove the
8278 popup menu.
8279
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008280 Return type: |Number|
8281
8282
zeertzjq7c515282024-11-10 20:26:12 +01008283py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008284 Evaluate Python expression {expr} and return its result
8285 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008286 If a {locals} |Dictionary| is given, it defines set of local
8287 variables available in the expression. The keys are variable
8288 names and the values are the variable values. |Dictionary| and
8289 |List| values are referenced, and may be updated by the
8290 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008291 Numbers and strings are returned as they are (strings are
8292 copied though, Unicode strings are additionally converted to
8293 'encoding').
8294 Lists are represented as Vim |List| type.
8295 Dictionaries are represented as Vim |Dictionary| type with
8296 keys converted to strings.
8297 Note that in a `:def` function local variables are not visible
8298 to {expr}.
8299
8300 Can also be used as a |method|: >
8301 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008302 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008303<
8304 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008305
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008306 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008307
8308 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008309pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310 Evaluate Python expression {expr} and return its result
8311 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008312 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008313 Numbers and strings are returned as they are (strings are
8314 copied though).
8315 Lists are represented as Vim |List| type.
8316 Dictionaries are represented as Vim |Dictionary| type,
8317 non-string keys result in error.
8318 Note that in a `:def` function local variables are not visible
8319 to {expr}.
8320
8321 Can also be used as a |method|: >
8322 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008323<
8324 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008325
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008326 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008327
zeertzjq7c515282024-11-10 20:26:12 +01008328pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008329 Evaluate Python expression {expr} and return its result
8330 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008331 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008332 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8333 See also: |pyeval()|, |py3eval()|
8334
8335 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008336 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008337<
8338 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008339
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008340 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008341 |+python3| feature}
8342
8343rand([{expr}]) *rand()* *random*
8344 Return a pseudo-random Number generated with an xoshiro128**
8345 algorithm using seed {expr}. The returned number is 32 bits,
8346 also on 64 bits systems, for consistency.
8347 {expr} can be initialized by |srand()| and will be updated by
8348 rand(). If {expr} is omitted, an internal seed value is used
8349 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008350 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008351
8352 Examples: >
8353 :echo rand()
8354 :let seed = srand()
8355 :echo rand(seed)
8356 :echo rand(seed) % 16 " random number 0 - 15
8357<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008358 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008359
8360 *E726* *E727*
8361range({expr} [, {max} [, {stride}]]) *range()*
8362 Returns a |List| with Numbers:
8363 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8364 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8365 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8366 {max}] (increasing {expr} with {stride} each time, not
8367 producing a value past {max}).
8368 When the maximum is one before the start the result is an
8369 empty list. When the maximum is more than one before the
8370 start this is an error.
8371 Examples: >
8372 range(4) " [0, 1, 2, 3]
8373 range(2, 4) " [2, 3, 4]
8374 range(2, 9, 3) " [2, 5, 8]
8375 range(2, -2, -1) " [2, 1, 0, -1, -2]
8376 range(0) " []
8377 range(2, 0) " error!
8378<
8379 Can also be used as a |method|: >
8380 GetExpr()->range()
8381<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008382 Return type: list<number>
8383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008384
K.Takata11df3ae2022-10-19 14:02:40 +01008385readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008386 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008387 If {offset} is specified, read the file from the specified
8388 offset. If it is a negative value, it is used as an offset
8389 from the end of the file. E.g., to read the last 12 bytes: >
8390 readblob('file.bin', -12)
8391< If {size} is specified, only the specified size will be read.
8392 E.g. to read the first 100 bytes of a file: >
8393 readblob('file.bin', 0, 100)
8394< If {size} is -1 or omitted, the whole data starting from
8395 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008396 This can be also used to read the data from a character device
8397 on Unix when {size} is explicitly set. Only if the device
8398 supports seeking {offset} can be used. Otherwise it should be
8399 zero. E.g. to read 10 bytes from a serial console: >
8400 readblob('/dev/ttyS0', 0, 10)
8401< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008402 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008403 When the offset is beyond the end of the file the result is an
8404 empty blob.
8405 When trying to read more bytes than are available the result
8406 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008407 Also see |readfile()| and |writefile()|.
8408
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008409 Return type: |Blob|
8410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008411
8412readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8413 Return a list with file and directory names in {directory}.
8414 You can also use |glob()| if you don't need to do complicated
8415 things, such as limiting the number of matches.
8416 The list will be sorted (case sensitive), see the {dict}
8417 argument below for changing the sort order.
8418
8419 When {expr} is omitted all entries are included.
8420 When {expr} is given, it is evaluated to check what to do:
8421 If {expr} results in -1 then no further entries will
8422 be handled.
8423 If {expr} results in 0 then this entry will not be
8424 added to the list.
8425 If {expr} results in 1 then this entry will be added
8426 to the list.
8427 The entries "." and ".." are always excluded.
8428 Each time {expr} is evaluated |v:val| is set to the entry name.
8429 When {expr} is a function the name is passed as the argument.
8430 For example, to get a list of files ending in ".txt": >
8431 readdir(dirname, {n -> n =~ '.txt$'})
8432< To skip hidden and backup files: >
8433 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008434< *E857*
8435 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008436 values. Currently this is used to specify if and how sorting
8437 should be performed. The dict can have the following members:
8438
8439 sort How to sort the result returned from the system.
8440 Valid values are:
8441 "none" do not sort (fastest method)
8442 "case" sort case sensitive (byte value of
8443 each character, technically, using
8444 strcmp()) (default)
8445 "icase" sort case insensitive (technically
8446 using strcasecmp())
8447 "collate" sort using the collation order
8448 of the "POSIX" or "C" |locale|
8449 (technically using strcoll())
8450 Other values are silently ignored.
8451
8452 For example, to get a list of all files in the current
8453 directory without sorting the individual entries: >
8454 readdir('.', '1', #{sort: 'none'})
8455< If you want to get a directory tree: >
8456 function! s:tree(dir)
8457 return {a:dir : map(readdir(a:dir),
8458 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008459 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008460 endfunction
8461 echo s:tree(".")
8462<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008463 Returns an empty List on error.
8464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008465 Can also be used as a |method|: >
8466 GetDirName()->readdir()
8467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008468 Return type: list<string> or list<any>
8469
8470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008471readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8472 Extended version of |readdir()|.
8473 Return a list of Dictionaries with file and directory
8474 information in {directory}.
8475 This is useful if you want to get the attributes of file and
8476 directory at the same time as getting a list of a directory.
8477 This is much faster than calling |readdir()| then calling
8478 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8479 each file and directory especially on MS-Windows.
8480 The list will by default be sorted by name (case sensitive),
8481 the sorting can be changed by using the optional {dict}
8482 argument, see |readdir()|.
8483
8484 The Dictionary for file and directory information has the
8485 following items:
8486 group Group name of the entry. (Only on Unix)
8487 name Name of the entry.
8488 perm Permissions of the entry. See |getfperm()|.
8489 size Size of the entry. See |getfsize()|.
8490 time Timestamp of the entry. See |getftime()|.
8491 type Type of the entry.
8492 On Unix, almost same as |getftype()| except:
8493 Symlink to a dir "linkd"
8494 Other symlink "link"
8495 On MS-Windows:
8496 Normal file "file"
8497 Directory "dir"
8498 Junction "junction"
8499 Symlink to a dir "linkd"
8500 Other symlink "link"
8501 Other reparse point "reparse"
8502 user User name of the entry's owner. (Only on Unix)
8503 On Unix, if the entry is a symlink, the Dictionary includes
8504 the information of the target (except the "type" item).
8505 On MS-Windows, it includes the information of the symlink
8506 itself because of performance reasons.
8507
8508 When {expr} is omitted all entries are included.
8509 When {expr} is given, it is evaluated to check what to do:
8510 If {expr} results in -1 then no further entries will
8511 be handled.
8512 If {expr} results in 0 then this entry will not be
8513 added to the list.
8514 If {expr} results in 1 then this entry will be added
8515 to the list.
8516 The entries "." and ".." are always excluded.
8517 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8518 of the entry.
8519 When {expr} is a function the entry is passed as the argument.
8520 For example, to get a list of files ending in ".txt": >
8521 readdirex(dirname, {e -> e.name =~ '.txt$'})
8522<
8523 For example, to get a list of all files in the current
8524 directory without sorting the individual entries: >
8525 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008526<
8527 Can also be used as a |method|: >
8528 GetDirName()->readdirex()
8529<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008530 Return type: list<dict<any>> or list<any>
8531
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008532
8533 *readfile()*
8534readfile({fname} [, {type} [, {max}]])
8535 Read file {fname} and return a |List|, each line of the file
8536 as an item. Lines are broken at NL characters. Macintosh
8537 files separated with CR will result in a single long line
8538 (unless a NL appears somewhere).
8539 All NUL characters are replaced with a NL character.
8540 When {type} contains "b" binary mode is used:
8541 - When the last line ends in a NL an extra empty list item is
8542 added.
8543 - No CR characters are removed.
8544 Otherwise:
8545 - CR characters that appear before a NL are removed.
8546 - Whether the last line ends in a NL or not does not matter.
8547 - When 'encoding' is Unicode any UTF-8 byte order mark is
8548 removed from the text.
8549 When {max} is given this specifies the maximum number of lines
8550 to be read. Useful if you only want to check the first ten
8551 lines of a file: >
8552 :for line in readfile(fname, '', 10)
8553 : if line =~ 'Date' | echo line | endif
8554 :endfor
8555< When {max} is negative -{max} lines from the end of the file
8556 are returned, or as many as there are.
8557 When {max} is zero the result is an empty list.
8558 Note that without {max} the whole file is read into memory.
8559 Also note that there is no recognition of encoding. Read a
8560 file into a buffer if you need to.
8561 Deprecated (use |readblob()| instead): When {type} contains
8562 "B" a |Blob| is returned with the binary data of the file
8563 unmodified.
8564 When the file can't be opened an error message is given and
8565 the result is an empty list.
8566 Also see |writefile()|.
8567
8568 Can also be used as a |method|: >
8569 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008570<
8571 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008572
8573reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8574 {func} is called for every item in {object}, which can be a
8575 |String|, |List| or a |Blob|. {func} is called with two
8576 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008577 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008578
8579 {initial} is the initial result. When omitted, the first item
8580 in {object} is used and {func} is first called for the second
8581 item. If {initial} is not given and {object} is empty no
8582 result can be computed, an E998 error is given.
8583
8584 Examples: >
8585 echo reduce([1, 3, 5], { acc, val -> acc + val })
8586 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8587 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8588 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8589<
8590 Can also be used as a |method|: >
8591 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008592<
8593 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8594 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008595
8596
8597reg_executing() *reg_executing()*
8598 Returns the single letter name of the register being executed.
8599 Returns an empty string when no register is being executed.
8600 See |@|.
8601
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008602 Return type: |String|
8603
8604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008605reg_recording() *reg_recording()*
8606 Returns the single letter name of the register being recorded.
8607 Returns an empty string when not recording. See |q|.
8608
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008609 Return type: |String|
8610
8611
8612reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008613reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008614reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008615 Return an item that represents a time value. The item is a
8616 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008617 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008618 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008619 string or |reltimefloat()| to convert to a Float. For
8620 example, to see the time spent in function Work(): >
8621 var startTime = reltime()
8622 Work()
8623 echo startTime->reltime()->reltimestr()
8624<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008625 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008626 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008627 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008628 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008629 specified in the argument.
8630 With two arguments it returns the time passed between {start}
8631 and {end}.
8632
8633 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008634 reltime(). If there is an error an empty List is returned in
8635 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008636
8637 Can also be used as a |method|: >
8638 GetStart()->reltime()
8639<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008640 Return type: list<number>
8641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008642 {only available when compiled with the |+reltime| feature}
8643
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008645reltimefloat({time}) *reltimefloat()*
8646 Return a Float that represents the time value of {time}.
8647 Example: >
8648 let start = reltime()
8649 call MyFunction()
8650 let seconds = reltimefloat(reltime(start))
8651< See the note of reltimestr() about overhead.
8652 Also see |profiling|.
8653 If there is an error 0.0 is returned in legacy script, in Vim9
8654 script an error is given.
8655
8656 Can also be used as a |method|: >
8657 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008658<
8659 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008660
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008661 {only available when compiled with the |+reltime| feature}
8662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008663
8664reltimestr({time}) *reltimestr()*
8665 Return a String that represents the time value of {time}.
8666 This is the number of seconds, a dot and the number of
8667 microseconds. Example: >
8668 let start = reltime()
8669 call MyFunction()
8670 echo reltimestr(reltime(start))
8671< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008672 The accuracy depends on the system. Use reltimefloat() for the
8673 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008674 Leading spaces are used to make the string align nicely. You
8675 can use split() to remove it. >
8676 echo split(reltimestr(reltime(start)))[0]
8677< Also see |profiling|.
8678 If there is an error an empty string is returned in legacy
8679 script, in Vim9 script an error is given.
8680
8681 Can also be used as a |method|: >
8682 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008683<
8684 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008685
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008686 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008687
8688 *remote_expr()* *E449*
8689remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008690 Send the {string} to {server}. The {server} argument is a
8691 string, also see |{server}|.
8692
8693 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008694 after evaluation. The result must be a String or a |List|
8695 other types will be converted to String. A |List| is turned
8696 into a String by joining the items with a line break in
8697 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008699 If {idvar} is present and not empty, it is taken as the name
8700 of a variable and a {serverid} for later use with
8701 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008703 If {timeout} is given the read times out after this many
8704 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008706 See also |clientserver| |RemoteReply|.
8707 This function is not available in the |sandbox|.
8708 {only available when compiled with the |+clientserver| feature}
8709 Note: Any errors will cause a local error message to be issued
8710 and the result will be the empty string.
8711
8712 Variables will be evaluated in the global namespace,
8713 independent of a function currently being active. Except
8714 when in debug mode, then local function variables and
8715 arguments can be evaluated.
8716
8717 Examples: >
8718 :echo remote_expr("gvim", "2+2")
8719 :echo remote_expr("gvim1", "b:current_syntax")
8720<
8721 Can also be used as a |method|: >
8722 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008723<
8724 Return type: |String| or list<{type}>
8725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008726
8727remote_foreground({server}) *remote_foreground()*
8728 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008729 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008730 This works like: >
8731 remote_expr({server}, "foreground()")
8732< Except that on Win32 systems the client does the work, to work
8733 around the problem that the OS doesn't always allow the server
8734 to bring itself to the foreground.
8735 Note: This does not restore the window if it was minimized,
8736 like foreground() does.
8737 This function is not available in the |sandbox|.
8738
8739 Can also be used as a |method|: >
8740 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008741<
8742 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008743
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008744 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008745 Win32 console version}
8746
8747
8748remote_peek({serverid} [, {retvar}]) *remote_peek()*
8749 Returns a positive number if there are available strings
8750 from {serverid}. Copies any reply string into the variable
8751 {retvar} if specified. {retvar} must be a string with the
8752 name of a variable.
8753 Returns zero if none are available.
8754 Returns -1 if something is wrong.
8755 See also |clientserver|.
8756 This function is not available in the |sandbox|.
8757 {only available when compiled with the |+clientserver| feature}
8758 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008759 :let repl = ""
8760 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008761
8762< Can also be used as a |method|: >
8763 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008764<
8765 Return type: |Number|
8766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008767
8768remote_read({serverid}, [{timeout}]) *remote_read()*
8769 Return the oldest available reply from {serverid} and consume
8770 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008771 reply is available. Returns an empty string, if a reply is
8772 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008773 See also |clientserver|.
8774 This function is not available in the |sandbox|.
8775 {only available when compiled with the |+clientserver| feature}
8776 Example: >
8777 :echo remote_read(id)
8778
8779< Can also be used as a |method|: >
8780 ServerId()->remote_read()
8781<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008782 Return type: |String|
8783
8784
8785remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008786 Send the {string} to {server}. The {server} argument is a
8787 string, also see |{server}|.
8788
8789 The string is sent as input keys and the function returns
8790 immediately. At the Vim server the keys are not mapped
8791 |:map|.
8792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008793 If {idvar} is present, it is taken as the name of a variable
8794 and a {serverid} for later use with remote_read() is stored
8795 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008796
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008797 See also |clientserver| |RemoteReply|.
8798 This function is not available in the |sandbox|.
8799 {only available when compiled with the |+clientserver| feature}
8800
8801 Note: Any errors will be reported in the server and may mess
8802 up the display.
8803 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008804 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008805 \ remote_read(serverid)
8806
8807 :autocmd NONE RemoteReply *
8808 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008809 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008810 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8811<
8812 Can also be used as a |method|: >
8813 ServerName()->remote_send(keys)
8814<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008815 Return type: |String|
8816
8817
8818remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008819 Become the server {name}. {name} must be a non-empty string.
8820 This fails if already running as a server, when |v:servername|
8821 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008822
8823 Can also be used as a |method|: >
8824 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008825<
8826 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008827
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008828 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008829
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008830
8831remove({list}, {idx}) *remove()*
8832remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008833 Without {end}: Remove the item at {idx} from |List| {list} and
8834 return the item.
8835 With {end}: Remove items from {idx} to {end} (inclusive) and
8836 return a |List| with these items. When {idx} points to the same
8837 item as {end} a list with one item is returned. When {end}
8838 points to an item before {idx} this is an error.
8839 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008840 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008841 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008842 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008843 :call remove(mylist, 0, 9)
8844<
8845 Use |delete()| to remove a file.
8846
8847 Can also be used as a |method|: >
8848 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008849<
8850 Return type: any, depending on {list}
8851
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008852
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008853remove({blob}, {idx})
8854remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008855 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8856 return the byte.
8857 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8858 return a |Blob| with these bytes. When {idx} points to the same
8859 byte as {end} a |Blob| with one byte is returned. When {end}
8860 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008861 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008862 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008863 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008864 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008865<
8866 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008867
8868remove({dict}, {key})
8869 Remove the entry from {dict} with key {key} and return it.
8870 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008871 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008872< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008873 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008874
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008875 Return type: any, depending on {dict}
8876
8877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008878rename({from}, {to}) *rename()*
8879 Rename the file by the name {from} to the name {to}. This
8880 should also work to move files across file systems. The
8881 result is a Number, which is 0 if the file was renamed
8882 successfully, and non-zero when the renaming failed.
8883 NOTE: If {to} exists it is overwritten without warning.
8884 This function is not available in the |sandbox|.
8885
8886 Can also be used as a |method|: >
8887 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008888<
8889 Return type: |Number|
8890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008891
8892repeat({expr}, {count}) *repeat()*
8893 Repeat {expr} {count} times and return the concatenated
8894 result. Example: >
8895 :let separator = repeat('-', 80)
8896< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008897 When {expr} is a |List| or a |Blob| the result is {expr}
8898 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008899 :let longlist = repeat(['a', 'b'], 3)
8900< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8901
8902 Can also be used as a |method|: >
8903 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008904<
8905 Return type: |String|, |Blob| or list<{type}> depending on
8906 {expr}
8907
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008908
8909resolve({filename}) *resolve()* *E655*
8910 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8911 returns the path the shortcut points to in a simplified form.
8912 When {filename} is a symbolic link or junction point, return
8913 the full path to the target. If the target of junction is
8914 removed, return {filename}.
8915 On Unix, repeat resolving symbolic links in all path
8916 components of {filename} and return the simplified result.
8917 To cope with link cycles, resolving of symbolic links is
8918 stopped after 100 iterations.
8919 On other systems, return the simplified {filename}.
8920 The simplification step is done as by |simplify()|.
8921 resolve() keeps a leading path component specifying the
8922 current directory (provided the result is still a relative
8923 path name) and also keeps a trailing path separator.
8924
8925 Can also be used as a |method|: >
8926 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008927<
8928 Return type: |String|
8929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008930
8931reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008932 Reverse the order of items in {object}. {object} can be a
8933 |List|, a |Blob| or a |String|. For a List and a Blob the
8934 items are reversed in-place and {object} is returned.
8935 For a String a new String is returned.
8936 Returns zero if {object} is not a List, Blob or a String.
8937 If you want a List or Blob to remain unmodified make a copy
8938 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008939 :let revlist = reverse(copy(mylist))
8940< Can also be used as a |method|: >
8941 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008942<
8943 Return type: |String|, |Blob| or list<{type}> depending on
8944 {object}
8945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008946
8947round({expr}) *round()*
8948 Round off {expr} to the nearest integral value and return it
8949 as a |Float|. If {expr} lies halfway between two integral
8950 values, then use the larger one (away from zero).
8951 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008952 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008953 Examples: >
8954 echo round(0.456)
8955< 0.0 >
8956 echo round(4.5)
8957< 5.0 >
8958 echo round(-4.5)
8959< -5.0
8960
8961 Can also be used as a |method|: >
8962 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008963<
8964 Return type: |Float|
8965
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008966
8967rubyeval({expr}) *rubyeval()*
8968 Evaluate Ruby expression {expr} and return its result
8969 converted to Vim data structures.
8970 Numbers, floats and strings are returned as they are (strings
8971 are copied though).
8972 Arrays are represented as Vim |List| type.
8973 Hashes are represented as Vim |Dictionary| type.
8974 Other objects are represented as strings resulted from their
8975 "Object#to_s" method.
8976 Note that in a `:def` function local variables are not visible
8977 to {expr}.
8978
8979 Can also be used as a |method|: >
8980 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008981<
8982 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008983
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008984 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008985
8986screenattr({row}, {col}) *screenattr()*
8987 Like |screenchar()|, but return the attribute. This is a rather
8988 arbitrary number that can only be used to compare to the
8989 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008990 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008991
8992 Can also be used as a |method|: >
8993 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008994<
8995 Return type: |Number|
8996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008997
8998screenchar({row}, {col}) *screenchar()*
8999 The result is a Number, which is the character at position
9000 [row, col] on the screen. This works for every possible
9001 screen position, also status lines, window separators and the
9002 command line. The top left position is row one, column one
9003 The character excludes composing characters. For double-byte
9004 encodings it may only be the first byte.
9005 This is mainly to be used for testing.
9006 Returns -1 when row or col is out of range.
9007
9008 Can also be used as a |method|: >
9009 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009010<
9011 Return type: |Number|
9012
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009013
9014screenchars({row}, {col}) *screenchars()*
9015 The result is a |List| of Numbers. The first number is the same
9016 as what |screenchar()| returns. Further numbers are
9017 composing characters on top of the base character.
9018 This is mainly to be used for testing.
9019 Returns an empty List when row or col is out of range.
9020
9021 Can also be used as a |method|: >
9022 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009023<
9024 Return type: list<number> or list<any>
9025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009026
9027screencol() *screencol()*
9028 The result is a Number, which is the current screen column of
9029 the cursor. The leftmost column has number 1.
9030 This function is mainly used for testing.
9031
9032 Note: Always returns the current screen column, thus if used
9033 in a command (e.g. ":echo screencol()") it will return the
9034 column inside the command line, which is 1 when the command is
9035 executed. To get the cursor position in the file use one of
9036 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009037 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009038 nnoremap <silent> GG :echom screencol()<CR>
9039 nnoremap GG <Cmd>echom screencol()<CR>
9040<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009041 Return type: |Number|
9042
9043
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009044screenpos({winid}, {lnum}, {col}) *screenpos()*
9045 The result is a Dict with the screen position of the text
9046 character in window {winid} at buffer line {lnum} and column
9047 {col}. {col} is a one-based byte index.
9048 The Dict has these members:
9049 row screen row
9050 col first screen column
9051 endcol last screen column
9052 curscol cursor screen column
9053 If the specified position is not visible, all values are zero.
9054 The "endcol" value differs from "col" when the character
9055 occupies more than one screen cell. E.g. for a Tab "col" can
9056 be 1 and "endcol" can be 8.
9057 The "curscol" value is where the cursor would be placed. For
9058 a Tab it would be the same as "endcol", while for a double
9059 width character it would be the same as "col".
9060 The |conceal| feature is ignored here, the column numbers are
9061 as if 'conceallevel' is zero. You can set the cursor to the
9062 right position and use |screencol()| to get the value with
9063 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009064 If the position is in a closed fold the screen position of the
9065 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009066 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009067
9068 Can also be used as a |method|: >
9069 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009070<
9071 Return type: dict<number> or dict<any>
9072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009073
9074screenrow() *screenrow()*
9075 The result is a Number, which is the current screen row of the
9076 cursor. The top line has number one.
9077 This function is mainly used for testing.
9078 Alternatively you can use |winline()|.
9079
9080 Note: Same restrictions as with |screencol()|.
9081
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009082 Return type: |Number|
9083
9084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009085screenstring({row}, {col}) *screenstring()*
9086 The result is a String that contains the base character and
9087 any composing characters at position [row, col] on the screen.
9088 This is like |screenchars()| but returning a String with the
9089 characters.
9090 This is mainly to be used for testing.
9091 Returns an empty String when row or col is out of range.
9092
9093 Can also be used as a |method|: >
9094 GetRow()->screenstring(col)
9095<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009096 Return type: |String|
9097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009098 *search()*
9099search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9100 Search for regexp pattern {pattern}. The search starts at the
9101 cursor position (you can use |cursor()| to set it).
9102
9103 When a match has been found its line number is returned.
9104 If there is no match a 0 is returned and the cursor doesn't
9105 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009106 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009107
9108 {flags} is a String, which can contain these character flags:
9109 'b' search Backward instead of forward
9110 'c' accept a match at the Cursor position
9111 'e' move to the End of the match
9112 'n' do Not move the cursor
9113 'p' return number of matching sub-Pattern (see below)
9114 's' Set the ' mark at the previous location of the cursor
9115 'w' Wrap around the end of the file
9116 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009117 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009118 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9119
9120 If the 's' flag is supplied, the ' mark is set, only if the
9121 cursor is moved. The 's' flag cannot be combined with the 'n'
9122 flag.
9123
9124 'ignorecase', 'smartcase' and 'magic' are used.
9125
9126 When the 'z' flag is not given, forward searching always
9127 starts in column zero and then matches before the cursor are
9128 skipped. When the 'c' flag is present in 'cpo' the next
9129 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009130 search starts one column after the start of the match. This
9131 matters for overlapping matches. See |cpo-c|. You can also
9132 insert "\ze" to change where the match ends, see |/\ze|.
9133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009134 When searching backwards and the 'z' flag is given then the
9135 search starts in column zero, thus no match in the current
9136 line will be found (unless wrapping around the end of the
9137 file).
9138
9139 When the {stopline} argument is given then the search stops
9140 after searching this line. This is useful to restrict the
9141 search to a range of lines. Examples: >
9142 let match = search('(', 'b', line("w0"))
9143 let end = search('END', '', line("w$"))
9144< When {stopline} is used and it is not zero this also implies
9145 that the search does not wrap around the end of the file.
9146 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009147 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009148 When the {timeout} argument is given the search stops when
9149 more than this many milliseconds have passed. Thus when
9150 {timeout} is 500 the search stops after half a second.
9151 The value must not be negative. A zero value is like not
9152 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009153
9154 Note: the timeout is only considered when searching, not
9155 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009156 {only available when compiled with the |+reltime| feature}
9157
9158 If the {skip} expression is given it is evaluated with the
9159 cursor positioned on the start of a match. If it evaluates to
9160 non-zero this match is skipped. This can be used, for
9161 example, to skip a match in a comment or a string.
9162 {skip} can be a string, which is evaluated as an expression, a
9163 function reference or a lambda.
9164 When {skip} is omitted or empty, every match is accepted.
9165 When evaluating {skip} causes an error the search is aborted
9166 and -1 returned.
9167 *search()-sub-match*
9168 With the 'p' flag the returned value is one more than the
9169 first sub-match in \(\). One if none of them matched but the
9170 whole pattern did match.
9171 To get the column number too use |searchpos()|.
9172
9173 The cursor will be positioned at the match, unless the 'n'
9174 flag is used.
9175
9176 Example (goes over all files in the argument list): >
9177 :let n = 1
9178 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009179 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009180 : " start at the last char in the file and wrap for the
9181 : " first search to find match at start of file
9182 : normal G$
9183 : let flags = "w"
9184 : while search("foo", flags) > 0
9185 : s/foo/bar/g
9186 : let flags = "W"
9187 : endwhile
9188 : update " write the file if modified
9189 : let n = n + 1
9190 :endwhile
9191<
9192 Example for using some flags: >
9193 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9194< This will search for the keywords "if", "else", and "endif"
9195 under or after the cursor. Because of the 'p' flag, it
9196 returns 1, 2, or 3 depending on which keyword is found, or 0
9197 if the search fails. With the cursor on the first word of the
9198 line:
9199 if (foo == 0) | let foo = foo + 1 | endif ~
9200 the function returns 1. Without the 'c' flag, the function
9201 finds the "endif" and returns 3. The same thing happens
9202 without the 'e' flag if the cursor is on the "f" of "if".
9203 The 'n' flag tells the function not to move the cursor.
9204
9205 Can also be used as a |method|: >
9206 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009207<
9208 Return type: |Number|
9209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009210
9211searchcount([{options}]) *searchcount()*
9212 Get or update the last search count, like what is displayed
9213 without the "S" flag in 'shortmess'. This works even if
9214 'shortmess' does contain the "S" flag.
9215
9216 This returns a |Dictionary|. The dictionary is empty if the
9217 previous pattern was not set and "pattern" was not specified.
9218
9219 key type meaning ~
9220 current |Number| current position of match;
9221 0 if the cursor position is
9222 before the first match
9223 exact_match |Boolean| 1 if "current" is matched on
9224 "pos", otherwise 0
9225 total |Number| total count of matches found
9226 incomplete |Number| 0: search was fully completed
9227 1: recomputing was timed out
9228 2: max count exceeded
9229
9230 For {options} see further down.
9231
9232 To get the last search count when |n| or |N| was pressed, call
9233 this function with `recompute: 0` . This sometimes returns
9234 wrong information because |n| and |N|'s maximum count is 99.
9235 If it exceeded 99 the result must be max count + 1 (100). If
9236 you want to get correct information, specify `recompute: 1`: >
9237
9238 " result == maxcount + 1 (100) when many matches
9239 let result = searchcount(#{recompute: 0})
9240
9241 " Below returns correct result (recompute defaults
9242 " to 1)
9243 let result = searchcount()
9244<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009245 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009246 function! LastSearchCount() abort
9247 let result = searchcount(#{recompute: 0})
9248 if empty(result)
9249 return ''
9250 endif
9251 if result.incomplete ==# 1 " timed out
9252 return printf(' /%s [?/??]', @/)
9253 elseif result.incomplete ==# 2 " max count exceeded
9254 if result.total > result.maxcount &&
9255 \ result.current > result.maxcount
9256 return printf(' /%s [>%d/>%d]', @/,
9257 \ result.current, result.total)
9258 elseif result.total > result.maxcount
9259 return printf(' /%s [%d/>%d]', @/,
9260 \ result.current, result.total)
9261 endif
9262 endif
9263 return printf(' /%s [%d/%d]', @/,
9264 \ result.current, result.total)
9265 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009266 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009267
9268 " Or if you want to show the count only when
9269 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009270 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009271 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9272<
9273 You can also update the search count, which can be useful in a
9274 |CursorMoved| or |CursorMovedI| autocommand: >
9275
9276 autocmd CursorMoved,CursorMovedI *
9277 \ let s:searchcount_timer = timer_start(
9278 \ 200, function('s:update_searchcount'))
9279 function! s:update_searchcount(timer) abort
9280 if a:timer ==# s:searchcount_timer
9281 call searchcount(#{
9282 \ recompute: 1, maxcount: 0, timeout: 100})
9283 redrawstatus
9284 endif
9285 endfunction
9286<
9287 This can also be used to count matched texts with specified
9288 pattern in the current buffer using "pattern": >
9289
9290 " Count '\<foo\>' in this buffer
9291 " (Note that it also updates search count)
9292 let result = searchcount(#{pattern: '\<foo\>'})
9293
9294 " To restore old search count by old pattern,
9295 " search again
9296 call searchcount()
9297<
9298 {options} must be a |Dictionary|. It can contain:
9299 key type meaning ~
9300 recompute |Boolean| if |TRUE|, recompute the count
9301 like |n| or |N| was executed.
9302 otherwise returns the last
9303 computed result (when |n| or
9304 |N| was used when "S" is not
9305 in 'shortmess', or this
9306 function was called).
9307 (default: |TRUE|)
9308 pattern |String| recompute if this was given
9309 and different with |@/|.
9310 this works as same as the
9311 below command is executed
9312 before calling this function >
9313 let @/ = pattern
9314< (default: |@/|)
9315 timeout |Number| 0 or negative number is no
9316 timeout. timeout milliseconds
9317 for recomputing the result
9318 (default: 0)
9319 maxcount |Number| 0 or negative number is no
9320 limit. max count of matched
9321 text while recomputing the
9322 result. if search exceeded
9323 total count, "total" value
9324 becomes `maxcount + 1`
9325 (default: 99)
9326 pos |List| `[lnum, col, off]` value
9327 when recomputing the result.
9328 this changes "current" result
9329 value. see |cursor()|,
9330 |getpos()|
9331 (default: cursor's position)
9332
9333 Can also be used as a |method|: >
9334 GetSearchOpts()->searchcount()
9335<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009336 Return type: dict<number>
9337
9338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009339searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9340 Search for the declaration of {name}.
9341
9342 With a non-zero {global} argument it works like |gD|, find
9343 first match in the file. Otherwise it works like |gd|, find
9344 first match in the function.
9345
9346 With a non-zero {thisblock} argument matches in a {} block
9347 that ends before the cursor position are ignored. Avoids
9348 finding variable declarations only valid in another scope.
9349
9350 Moves the cursor to the found match.
9351 Returns zero for success, non-zero for failure.
9352 Example: >
9353 if searchdecl('myvar') == 0
9354 echo getline('.')
9355 endif
9356<
9357 Can also be used as a |method|: >
9358 GetName()->searchdecl()
9359<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009360 Return type: |Number|
9361
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009362 *searchpair()*
9363searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9364 [, {stopline} [, {timeout}]]]])
9365 Search for the match of a nested start-end pair. This can be
9366 used to find the "endif" that matches an "if", while other
9367 if/endif pairs in between are ignored.
9368 The search starts at the cursor. The default is to search
9369 forward, include 'b' in {flags} to search backward.
9370 If a match is found, the cursor is positioned at it and the
9371 line number is returned. If no match is found 0 or -1 is
9372 returned and the cursor doesn't move. No error message is
9373 given.
9374
9375 {start}, {middle} and {end} are patterns, see |pattern|. They
9376 must not contain \( \) pairs. Use of \%( \) is allowed. When
9377 {middle} is not empty, it is found when searching from either
9378 direction, but only when not in a nested start-end pair. A
9379 typical use is: >
9380 searchpair('\<if\>', '\<else\>', '\<endif\>')
9381< By leaving {middle} empty the "else" is skipped.
9382
9383 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9384 |search()|. Additionally:
9385 'r' Repeat until no more matches found; will find the
9386 outer pair. Implies the 'W' flag.
9387 'm' Return number of matches instead of line number with
9388 the match; will be > 1 when 'r' is used.
9389 Note: it's nearly always a good idea to use the 'W' flag, to
9390 avoid wrapping around the end of the file.
9391
9392 When a match for {start}, {middle} or {end} is found, the
9393 {skip} expression is evaluated with the cursor positioned on
9394 the start of the match. It should return non-zero if this
9395 match is to be skipped. E.g., because it is inside a comment
9396 or a string.
9397 When {skip} is omitted or empty, every match is accepted.
9398 When evaluating {skip} causes an error the search is aborted
9399 and -1 returned.
9400 {skip} can be a string, a lambda, a funcref or a partial.
9401 Anything else makes the function fail.
9402 In a `:def` function when the {skip} argument is a string
9403 constant it is compiled into instructions.
9404
9405 For {stopline} and {timeout} see |search()|.
9406
9407 The value of 'ignorecase' is used. 'magic' is ignored, the
9408 patterns are used like it's on.
9409
9410 The search starts exactly at the cursor. A match with
9411 {start}, {middle} or {end} at the next character, in the
9412 direction of searching, is the first one found. Example: >
9413 if 1
9414 if 2
9415 endif 2
9416 endif 1
9417< When starting at the "if 2", with the cursor on the "i", and
9418 searching forwards, the "endif 2" is found. When starting on
9419 the character just before the "if 2", the "endif 1" will be
9420 found. That's because the "if 2" will be found first, and
9421 then this is considered to be a nested if/endif from "if 2" to
9422 "endif 2".
9423 When searching backwards and {end} is more than one character,
9424 it may be useful to put "\zs" at the end of the pattern, so
9425 that when the cursor is inside a match with the end it finds
9426 the matching start.
9427
9428 Example, to find the "endif" command in a Vim script: >
9429
9430 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9431 \ 'getline(".") =~ "^\\s*\""')
9432
9433< The cursor must be at or after the "if" for which a match is
9434 to be found. Note that single-quote strings are used to avoid
9435 having to double the backslashes. The skip expression only
9436 catches comments at the start of a line, not after a command.
9437 Also, a word "en" or "if" halfway a line is considered a
9438 match.
9439 Another example, to search for the matching "{" of a "}": >
9440
9441 :echo searchpair('{', '', '}', 'bW')
9442
9443< This works when the cursor is at or before the "}" for which a
9444 match is to be found. To reject matches that syntax
9445 highlighting recognized as strings: >
9446
9447 :echo searchpair('{', '', '}', 'bW',
9448 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9449<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009450 Return type: |Number|
9451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009452 *searchpairpos()*
9453searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9454 [, {stopline} [, {timeout}]]]])
9455 Same as |searchpair()|, but returns a |List| with the line and
9456 column position of the match. The first element of the |List|
9457 is the line number and the second element is the byte index of
9458 the column position of the match. If no match is found,
9459 returns [0, 0]. >
9460
9461 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9462<
9463 See |match-parens| for a bigger and more useful example.
9464
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009465 Return type: list<number>
9466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009467 *searchpos()*
9468searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9469 Same as |search()|, but returns a |List| with the line and
9470 column position of the match. The first element of the |List|
9471 is the line number and the second element is the byte index of
9472 the column position of the match. If no match is found,
9473 returns [0, 0].
9474 Example: >
9475 :let [lnum, col] = searchpos('mypattern', 'n')
9476
9477< When the 'p' flag is given then there is an extra item with
9478 the sub-pattern match number |search()-sub-match|. Example: >
9479 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9480< In this example "submatch" is 2 when a lowercase letter is
9481 found |/\l|, 3 when an uppercase letter is found |/\u|.
9482
9483 Can also be used as a |method|: >
9484 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009485<
9486 Return type: list<number>
9487
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009488
9489server2client({clientid}, {string}) *server2client()*
9490 Send a reply string to {clientid}. The most recent {clientid}
9491 that sent a string can be retrieved with expand("<client>").
9492 {only available when compiled with the |+clientserver| feature}
9493 Returns zero for success, -1 for failure.
9494 Note:
9495 This id has to be stored before the next command can be
9496 received. I.e. before returning from the received command and
9497 before calling any commands that waits for input.
9498 See also |clientserver|.
9499 Example: >
9500 :echo server2client(expand("<client>"), "HELLO")
9501
9502< Can also be used as a |method|: >
9503 GetClientId()->server2client(string)
9504<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009505 Return type: |Number|
9506
9507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009508serverlist() *serverlist()*
9509 Return a list of available server names, one per line.
9510 When there are no servers or the information is not available
9511 an empty string is returned. See also |clientserver|.
9512 {only available when compiled with the |+clientserver| feature}
9513 Example: >
9514 :echo serverlist()
9515<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009516 Return type: |String|
9517
9518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009519setbufline({buf}, {lnum}, {text}) *setbufline()*
9520 Set line {lnum} to {text} in buffer {buf}. This works like
9521 |setline()| for the specified buffer.
9522
9523 This function works only for loaded buffers. First call
9524 |bufload()| if needed.
9525
9526 To insert lines use |appendbufline()|.
9527 Any text properties in {lnum} are cleared.
9528
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009529 {text} can be a string to set one line, or a List of strings
9530 to set multiple lines. If the List extends below the last
9531 line then those lines are added. If the List is empty then
9532 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009533
9534 For the use of {buf}, see |bufname()| above.
9535
9536 {lnum} is used like with |setline()|.
9537 Use "$" to refer to the last line in buffer {buf}.
9538 When {lnum} is just below the last line the {text} will be
9539 added below the last line.
9540
9541 When {buf} is not a valid buffer, the buffer is not loaded or
9542 {lnum} is not valid then 1 is returned. In |Vim9| script an
9543 error is given.
9544 On success 0 is returned.
9545
9546 Can also be used as a |method|, the base is passed as the
9547 third argument: >
9548 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009549<
9550 Return type: |Number|
9551
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009552
9553setbufvar({buf}, {varname}, {val}) *setbufvar()*
9554 Set option or local variable {varname} in buffer {buf} to
9555 {val}.
9556 This also works for a global or local window option, but it
9557 doesn't work for a global or local window variable.
9558 For a local window option the global value is unchanged.
9559 For the use of {buf}, see |bufname()| above.
9560 The {varname} argument is a string.
9561 Note that the variable name without "b:" must be used.
9562 Examples: >
9563 :call setbufvar(1, "&mod", 1)
9564 :call setbufvar("todo", "myvar", "foobar")
9565< This function is not available in the |sandbox|.
9566
9567 Can also be used as a |method|, the base is passed as the
9568 third argument: >
9569 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009570<
9571 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009572
9573
9574setcellwidths({list}) *setcellwidths()*
9575 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009576 tells Vim how wide characters are when displayed in the
9577 terminal, counted in screen cells. The values override
9578 'ambiwidth'. Example: >
9579 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009580 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009581 \ [0x2194, 0x2199, 2],
9582 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009583
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009584< The {list} argument is a List of Lists with each three
9585 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9586 {low} and {high} can be the same, in which case this refers to
9587 one character. Otherwise it is the range of characters from
9588 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009589 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009590
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009591 {width} must be either 1 or 2, indicating the character width
9592 in screen cells. *E1112*
9593 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009594 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009596 If the new value causes 'fillchars' or 'listchars' to become
9597 invalid it is rejected and an error is given.
9598
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009599 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009600 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009602< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009603 the effect for known emoji characters. Move the cursor
9604 through the text to check if the cell widths of your terminal
9605 match with what Vim knows about each emoji. If it doesn't
9606 look right you need to adjust the {list} argument.
9607
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009608 Return type: |Number|
9609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009610
9611setcharpos({expr}, {list}) *setcharpos()*
9612 Same as |setpos()| but uses the specified column number as the
9613 character index instead of the byte index in the line.
9614
9615 Example:
9616 With the text "여보세요" in line 8: >
9617 call setcharpos('.', [0, 8, 4, 0])
9618< positions the cursor on the fourth character '요'. >
9619 call setpos('.', [0, 8, 4, 0])
9620< positions the cursor on the second character '보'.
9621
9622 Can also be used as a |method|: >
9623 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009624<
9625 Return type: |Number|
9626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009627
9628setcharsearch({dict}) *setcharsearch()*
9629 Set the current character search information to {dict},
9630 which contains one or more of the following entries:
9631
9632 char character which will be used for a subsequent
9633 |,| or |;| command; an empty string clears the
9634 character search
9635 forward direction of character search; 1 for forward,
9636 0 for backward
9637 until type of character search; 1 for a |t| or |T|
9638 character search, 0 for an |f| or |F|
9639 character search
9640
9641 This can be useful to save/restore a user's character search
9642 from a script: >
9643 :let prevsearch = getcharsearch()
9644 :" Perform a command which clobbers user's search
9645 :call setcharsearch(prevsearch)
9646< Also see |getcharsearch()|.
9647
9648 Can also be used as a |method|: >
9649 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009650<
9651 Return type: dict<any>
9652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009653
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009654setcmdline({str} [, {pos}]) *setcmdline()*
9655 Set the command line to {str} and set the cursor position to
9656 {pos}.
9657 If {pos} is omitted, the cursor is positioned after the text.
9658 Returns 0 when successful, 1 when not editing the command
9659 line.
9660
9661 Can also be used as a |method|: >
9662 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009663<
9664 Return type: |Number|
9665
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009667setcmdpos({pos}) *setcmdpos()*
9668 Set the cursor position in the command line to byte position
9669 {pos}. The first position is 1.
9670 Use |getcmdpos()| to obtain the current position.
9671 Only works while editing the command line, thus you must use
9672 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9673 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9674 set after the command line is set to the expression. For
9675 |c_CTRL-R_=| it is set after evaluating the expression but
9676 before inserting the resulting text.
9677 When the number is too big the cursor is put at the end of the
9678 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009679 Returns 0 when successful, 1 when not editing the command
9680 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009681
9682 Can also be used as a |method|: >
9683 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009684<
9685 Return type: |Number|
9686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009687
9688setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9689setcursorcharpos({list})
9690 Same as |cursor()| but uses the specified column number as the
9691 character index instead of the byte index in the line.
9692
9693 Example:
9694 With the text "여보세요" in line 4: >
9695 call setcursorcharpos(4, 3)
9696< positions the cursor on the third character '세'. >
9697 call cursor(4, 3)
9698< positions the cursor on the first character '여'.
9699
9700 Can also be used as a |method|: >
9701 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009702<
9703 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009704
9705
9706setenv({name}, {val}) *setenv()*
9707 Set environment variable {name} to {val}. Example: >
9708 call setenv('HOME', '/home/myhome')
9709
9710< When {val} is |v:null| the environment variable is deleted.
9711 See also |expr-env|.
9712
9713 Can also be used as a |method|, the base is passed as the
9714 second argument: >
9715 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009716<
9717 Return type: |Number|
9718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009719
9720setfperm({fname}, {mode}) *setfperm()* *chmod*
9721 Set the file permissions for {fname} to {mode}.
9722 {mode} must be a string with 9 characters. It is of the form
9723 "rwxrwxrwx", where each group of "rwx" flags represent, in
9724 turn, the permissions of the owner of the file, the group the
9725 file belongs to, and other users. A '-' character means the
9726 permission is off, any other character means on. Multi-byte
9727 characters are not supported.
9728
9729 For example "rw-r-----" means read-write for the user,
9730 readable by the group, not accessible by others. "xx-x-----"
9731 would do the same thing.
9732
9733 Returns non-zero for success, zero for failure.
9734
9735 Can also be used as a |method|: >
9736 GetFilename()->setfperm(mode)
9737<
9738 To read permissions see |getfperm()|.
9739
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009740 Return type: |Number|
9741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009742
9743setline({lnum}, {text}) *setline()*
9744 Set line {lnum} of the current buffer to {text}. To insert
9745 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009746 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009747 Any text properties in {lnum} are cleared. See
9748 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009749
9750 {lnum} is used like with |getline()|.
9751 When {lnum} is just below the last line the {text} will be
9752 added below the last line.
9753 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009754 converted to a String. When {text} is an empty List then
9755 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009756
9757 If this succeeds, FALSE is returned. If this fails (most likely
9758 because {lnum} is invalid) TRUE is returned.
9759 In |Vim9| script an error is given if {lnum} is invalid.
9760
9761 Example: >
9762 :call setline(5, strftime("%c"))
9763
9764< When {text} is a |List| then line {lnum} and following lines
9765 will be set to the items in the list. Example: >
9766 :call setline(5, ['aaa', 'bbb', 'ccc'])
9767< This is equivalent to: >
9768 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9769 : call setline(n, l)
9770 :endfor
9771
9772< Note: The '[ and '] marks are not set.
9773
9774 Can also be used as a |method|, the base is passed as the
9775 second argument: >
9776 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009777<
9778 Return type: |Number|
9779
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009780
9781setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9782 Create or replace or add to the location list for window {nr}.
9783 {nr} can be the window number or the |window-ID|.
9784 When {nr} is zero the current window is used.
9785
9786 For a location list window, the displayed location list is
9787 modified. For an invalid window number {nr}, -1 is returned.
9788 Otherwise, same as |setqflist()|.
9789 Also see |location-list|.
9790
9791 For {action} see |setqflist-action|.
9792
9793 If the optional {what} dictionary argument is supplied, then
9794 only the items listed in {what} are set. Refer to |setqflist()|
9795 for the list of supported keys in {what}.
9796
9797 Can also be used as a |method|, the base is passed as the
9798 second argument: >
9799 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009800<
9801 Return type: |Number|
9802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009803
9804setmatches({list} [, {win}]) *setmatches()*
9805 Restores a list of matches saved by |getmatches()| for the
9806 current window. Returns 0 if successful, otherwise -1. All
9807 current matches are cleared before the list is restored. See
9808 example for |getmatches()|.
9809 If {win} is specified, use the window with this number or
9810 window ID instead of the current window.
9811
9812 Can also be used as a |method|: >
9813 GetMatches()->setmatches()
9814<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009815 Return type: |Number|
9816
9817
9818setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009819 Set the position for String {expr}. Possible values:
9820 . the cursor
9821 'x mark x
9822
9823 {list} must be a |List| with four or five numbers:
9824 [bufnum, lnum, col, off]
9825 [bufnum, lnum, col, off, curswant]
9826
9827 "bufnum" is the buffer number. Zero can be used for the
9828 current buffer. When setting an uppercase mark "bufnum" is
9829 used for the mark position. For other marks it specifies the
9830 buffer to set the mark in. You can use the |bufnr()| function
9831 to turn a file name into a buffer number.
9832 For setting the cursor and the ' mark "bufnum" is ignored,
9833 since these are associated with a window, not a buffer.
9834 Does not change the jumplist.
9835
9836 "lnum" and "col" are the position in the buffer. The first
9837 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9838 smaller than 1 then 1 is used. To use the character count
9839 instead of the byte count, use |setcharpos()|.
9840
9841 The "off" number is only used when 'virtualedit' is set. Then
9842 it is the offset in screen columns from the start of the
9843 character. E.g., a position within a <Tab> or after the last
9844 character.
9845
9846 The "curswant" number is only used when setting the cursor
9847 position. It sets the preferred column for when moving the
9848 cursor vertically. When the "curswant" number is missing the
9849 preferred column is not set. When it is present and setting a
9850 mark position it is not used.
9851
9852 Note that for '< and '> changing the line number may result in
9853 the marks to be effectively be swapped, so that '< is always
9854 before '>.
9855
9856 Returns 0 when the position could be set, -1 otherwise.
9857 An error message is given if {expr} is invalid.
9858
9859 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9860
9861 This does not restore the preferred column for moving
9862 vertically; if you set the cursor position with this, |j| and
9863 |k| motions will jump to previous columns! Use |cursor()| to
9864 also set the preferred column. Also see the "curswant" key in
9865 |winrestview()|.
9866
9867 Can also be used as a |method|: >
9868 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009869<
9870 Return type: |Number|
9871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009872
9873setqflist({list} [, {action} [, {what}]]) *setqflist()*
9874 Create or replace or add to the quickfix list.
9875
9876 If the optional {what} dictionary argument is supplied, then
9877 only the items listed in {what} are set. The first {list}
9878 argument is ignored. See below for the supported items in
9879 {what}.
9880 *setqflist-what*
9881 When {what} is not present, the items in {list} are used. Each
9882 item must be a dictionary. Non-dictionary items in {list} are
9883 ignored. Each dictionary item can contain the following
9884 entries:
9885
9886 bufnr buffer number; must be the number of a valid
9887 buffer
9888 filename name of a file; only used when "bufnr" is not
9889 present or it is invalid.
9890 module name of a module; if given it will be used in
9891 quickfix error window instead of the filename.
9892 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009893 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009894 pattern search pattern used to locate the error
9895 col column number
9896 vcol when non-zero: "col" is visual column
9897 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009898 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009899 nr error number
9900 text description of the error
9901 type single-character error type, 'E', 'W', etc.
9902 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009903 user_data custom data associated with the item, can be
9904 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009905
9906 The "col", "vcol", "nr", "type" and "text" entries are
9907 optional. Either "lnum" or "pattern" entry can be used to
9908 locate a matching error line.
9909 If the "filename" and "bufnr" entries are not present or
9910 neither the "lnum" or "pattern" entries are present, then the
9911 item will not be handled as an error line.
9912 If both "pattern" and "lnum" are present then "pattern" will
9913 be used.
9914 If the "valid" entry is not supplied, then the valid flag is
9915 set when "bufnr" is a valid buffer or "filename" exists.
9916 If you supply an empty {list}, the quickfix list will be
9917 cleared.
9918 Note that the list is not exactly the same as what
9919 |getqflist()| returns.
9920
9921 {action} values: *setqflist-action* *E927*
9922 'a' The items from {list} are added to the existing
9923 quickfix list. If there is no existing list, then a
9924 new list is created.
9925
9926 'r' The items from the current quickfix list are replaced
9927 with the items from {list}. This can also be used to
9928 clear the list: >
9929 :call setqflist([], 'r')
9930<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009931 'u' Like 'r', but tries to preserve the current selection
9932 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009933 'f' All the quickfix lists in the quickfix stack are
9934 freed.
9935
9936 If {action} is not present or is set to ' ', then a new list
9937 is created. The new quickfix list is added after the current
9938 quickfix list in the stack and all the following lists are
9939 freed. To add a new quickfix list at the end of the stack,
9940 set "nr" in {what} to "$".
9941
9942 The following items can be specified in dictionary {what}:
9943 context quickfix list context. See |quickfix-context|
9944 efm errorformat to use when parsing text from
9945 "lines". If this is not present, then the
9946 'errorformat' option value is used.
9947 See |quickfix-parse|
9948 id quickfix list identifier |quickfix-ID|
9949 idx index of the current entry in the quickfix
9950 list specified by 'id' or 'nr'. If set to '$',
9951 then the last entry in the list is set as the
9952 current entry. See |quickfix-index|
9953 items list of quickfix entries. Same as the {list}
9954 argument.
9955 lines use 'errorformat' to parse a list of lines and
9956 add the resulting entries to the quickfix list
9957 {nr} or {id}. Only a |List| value is supported.
9958 See |quickfix-parse|
9959 nr list number in the quickfix stack; zero
9960 means the current quickfix list and "$" means
9961 the last quickfix list.
9962 quickfixtextfunc
9963 function to get the text to display in the
9964 quickfix window. The value can be the name of
9965 a function or a funcref or a lambda. Refer to
9966 |quickfix-window-function| for an explanation
9967 of how to write the function and an example.
9968 title quickfix list title text. See |quickfix-title|
9969 Unsupported keys in {what} are ignored.
9970 If the "nr" item is not present, then the current quickfix list
9971 is modified. When creating a new quickfix list, "nr" can be
9972 set to a value one greater than the quickfix stack size.
9973 When modifying a quickfix list, to guarantee that the correct
9974 list is modified, "id" should be used instead of "nr" to
9975 specify the list.
9976
9977 Examples (See also |setqflist-examples|): >
9978 :call setqflist([], 'r', {'title': 'My search'})
9979 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9980 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9981<
9982 Returns zero for success, -1 for failure.
9983
9984 This function can be used to create a quickfix list
9985 independent of the 'errorformat' setting. Use a command like
9986 `:cc 1` to jump to the first position.
9987
9988 Can also be used as a |method|, the base is passed as the
9989 second argument: >
9990 GetErrorlist()->setqflist()
9991<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009992 Return type: |Number|
9993
9994
9995setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009996 Set the register {regname} to {value}.
9997 If {regname} is "" or "@", the unnamed register '"' is used.
9998 The {regname} argument is a string. In |Vim9-script|
9999 {regname} must be one character.
10000
10001 {value} may be any value returned by |getreg()| or
10002 |getreginfo()|, including a |List| or |Dict|.
10003 If {options} contains "a" or {regname} is upper case,
10004 then the value is appended.
10005
10006 {options} can also contain a register type specification:
10007 "c" or "v" |characterwise| mode
10008 "l" or "V" |linewise| mode
10009 "b" or "<CTRL-V>" |blockwise-visual| mode
10010 If a number immediately follows "b" or "<CTRL-V>" then this is
10011 used as the width of the selection - if it is not specified
10012 then the width of the block is set to the number of characters
10013 in the longest line (counting a <Tab> as 1 character).
10014
10015 If {options} contains no register settings, then the default
10016 is to use character mode unless {value} ends in a <NL> for
10017 string {value} and linewise mode for list {value}. Blockwise
10018 mode is never selected automatically.
10019 Returns zero for success, non-zero for failure.
10020
10021 *E883*
10022 Note: you may not use |List| containing more than one item to
10023 set search and expression registers. Lists containing no
10024 items act like empty strings.
10025
10026 Examples: >
10027 :call setreg(v:register, @*)
10028 :call setreg('*', @%, 'ac')
10029 :call setreg('a', "1\n2\n3", 'b5')
10030 :call setreg('"', { 'points_to': 'a'})
10031
10032< This example shows using the functions to save and restore a
10033 register: >
10034 :let var_a = getreginfo()
10035 :call setreg('a', var_a)
10036< or: >
10037 :let var_a = getreg('a', 1, 1)
10038 :let var_amode = getregtype('a')
10039 ....
10040 :call setreg('a', var_a, var_amode)
10041< Note: you may not reliably restore register value
10042 without using the third argument to |getreg()| as without it
10043 newlines are represented as newlines AND Nul bytes are
10044 represented as newlines as well, see |NL-used-for-Nul|.
10045
10046 You can also change the type of a register by appending
10047 nothing: >
10048 :call setreg('a', '', 'al')
10049
10050< Can also be used as a |method|, the base is passed as the
10051 second argument: >
10052 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010053<
10054 Return type: |Number|
10055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010056
10057settabvar({tabnr}, {varname}, {val}) *settabvar()*
10058 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10059 |t:var|
10060 The {varname} argument is a string.
10061 Note that autocommands are blocked, side effects may not be
10062 triggered, e.g. when setting 'filetype'.
10063 Note that the variable name without "t:" must be used.
10064 Tabs are numbered starting with one.
10065 This function is not available in the |sandbox|.
10066
10067 Can also be used as a |method|, the base is passed as the
10068 third argument: >
10069 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010070<
10071 Return type: |Number|
10072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010073
10074settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10075 Set option or local variable {varname} in window {winnr} to
10076 {val}.
10077 Tabs are numbered starting with one. For the current tabpage
10078 use |setwinvar()|.
10079 {winnr} can be the window number or the |window-ID|.
10080 When {winnr} is zero the current window is used.
10081 Note that autocommands are blocked, side effects may not be
10082 triggered, e.g. when setting 'filetype' or 'syntax'.
10083 This also works for a global or local buffer option, but it
10084 doesn't work for a global or local buffer variable.
10085 For a local buffer option the global value is unchanged.
10086 Note that the variable name without "w:" must be used.
10087 Examples: >
10088 :call settabwinvar(1, 1, "&list", 0)
10089 :call settabwinvar(3, 2, "myvar", "foobar")
10090< This function is not available in the |sandbox|.
10091
10092 Can also be used as a |method|, the base is passed as the
10093 fourth argument: >
10094 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010095<
10096 Return type: |Number|
10097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010098
10099settagstack({nr}, {dict} [, {action}]) *settagstack()*
10100 Modify the tag stack of the window {nr} using {dict}.
10101 {nr} can be the window number or the |window-ID|.
10102
10103 For a list of supported items in {dict}, refer to
10104 |gettagstack()|. "curidx" takes effect before changing the tag
10105 stack.
10106 *E962*
10107 How the tag stack is modified depends on the {action}
10108 argument:
10109 - If {action} is not present or is set to 'r', then the tag
10110 stack is replaced.
10111 - If {action} is set to 'a', then new entries from {dict} are
10112 pushed (added) onto the tag stack.
10113 - If {action} is set to 't', then all the entries from the
10114 current entry in the tag stack or "curidx" in {dict} are
10115 removed and then new entries are pushed to the stack.
10116
10117 The current index is set to one after the length of the tag
10118 stack after the modification.
10119
10120 Returns zero for success, -1 for failure.
10121
10122 Examples (for more examples see |tagstack-examples|):
10123 Empty the tag stack of window 3: >
10124 call settagstack(3, {'items' : []})
10125
10126< Save and restore the tag stack: >
10127 let stack = gettagstack(1003)
10128 " do something else
10129 call settagstack(1003, stack)
10130 unlet stack
10131<
10132 Can also be used as a |method|, the base is passed as the
10133 second argument: >
10134 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010135<
10136 Return type: |Number|
10137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010138
10139setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10140 Like |settabwinvar()| for the current tab page.
10141 Examples: >
10142 :call setwinvar(1, "&list", 0)
10143 :call setwinvar(2, "myvar", "foobar")
10144
10145< Can also be used as a |method|, the base is passed as the
10146 third argument: >
10147 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010148<
10149 Return type: |Number|
10150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010151
10152sha256({string}) *sha256()*
10153 Returns a String with 64 hex characters, which is the SHA256
10154 checksum of {string}.
10155
10156 Can also be used as a |method|: >
10157 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010158<
10159 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010160
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010161 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010162
10163shellescape({string} [, {special}]) *shellescape()*
10164 Escape {string} for use as a shell command argument.
10165 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010166 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010167 in single quotes and will double up all internal single
10168 quotes.
10169 On MS-Windows, when 'shellslash' is not set, it will enclose
10170 {string} in double quotes and double all double quotes within
10171 {string}.
10172 Otherwise it will enclose {string} in single quotes and
10173 replace all "'" with "'\''".
10174
Enno5faeb602024-05-15 21:54:19 +020010175 The {special} argument adds additional escaping of keywords
10176 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010177 number or a non-empty String (|non-zero-arg|), then special
10178 items such as "!", "%", "#" and "<cword>" (as listed in
10179 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010180 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010181
10182 The "!" character will be escaped (again with a |non-zero-arg|
10183 {special}) when 'shell' contains "csh" in the tail. That is
10184 because for csh and tcsh "!" is used for history replacement
10185 even when inside single quotes.
10186
10187 With a |non-zero-arg| {special} the <NL> character is also
10188 escaped. When 'shell' containing "csh" in the tail it's
10189 escaped a second time.
10190
10191 The "\" character will be escaped when 'shell' contains "fish"
10192 in the tail. That is because for fish "\" is used as an escape
10193 character inside single quotes.
10194
10195 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010196 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010197< This results in a directory listing for the file under the
10198 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010199 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010200< See also |::S|.
10201
10202 Can also be used as a |method|: >
10203 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010204<
10205 Return type: |String|
10206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010207
10208shiftwidth([{col}]) *shiftwidth()*
10209 Returns the effective value of 'shiftwidth'. This is the
10210 'shiftwidth' value unless it is zero, in which case it is the
10211 'tabstop' value. This function was introduced with patch
10212 7.3.694 in 2012, everybody should have it by now (however it
10213 did not allow for the optional {col} argument until 8.1.542).
10214
10215 When there is one argument {col} this is used as column number
10216 for which to return the 'shiftwidth' value. This matters for the
10217 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10218 no {col} argument is given, column 1 will be assumed.
10219
10220 Can also be used as a |method|: >
10221 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010222<
10223 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010224
10225sign_ functions are documented here: |sign-functions-details|
10226
10227
10228simplify({filename}) *simplify()*
10229 Simplify the file name as much as possible without changing
10230 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10231 Unix) are not resolved. If the first path component in
10232 {filename} designates the current directory, this will be
10233 valid for the result as well. A trailing path separator is
10234 not removed either. On Unix "//path" is unchanged, but
10235 "///path" is simplified to "/path" (this follows the Posix
10236 standard).
10237 Example: >
10238 simplify("./dir/.././/file/") == "./file/"
10239< Note: The combination "dir/.." is only removed if "dir" is
10240 a searchable directory or does not exist. On Unix, it is also
10241 removed when "dir" is a symbolic link within the same
10242 directory. In order to resolve all the involved symbolic
10243 links before simplifying the path name, use |resolve()|.
10244
10245 Can also be used as a |method|: >
10246 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010247<
10248 Return type: |String|
10249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010250
10251sin({expr}) *sin()*
10252 Return the sine of {expr}, measured in radians, as a |Float|.
10253 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010254 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010255 Examples: >
10256 :echo sin(100)
10257< -0.506366 >
10258 :echo sin(-4.01)
10259< 0.763301
10260
10261 Can also be used as a |method|: >
10262 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010263<
10264 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010265
10266
10267sinh({expr}) *sinh()*
10268 Return the hyperbolic sine of {expr} as a |Float| in the range
10269 [-inf, inf].
10270 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010271 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010272 Examples: >
10273 :echo sinh(0.5)
10274< 0.521095 >
10275 :echo sinh(-0.9)
10276< -1.026517
10277
10278 Can also be used as a |method|: >
10279 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010280<
10281 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010282
10283
10284slice({expr}, {start} [, {end}]) *slice()*
10285 Similar to using a |slice| "expr[start : end]", but "end" is
10286 used exclusive. And for a string the indexes are used as
10287 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010288 |vim9script|. Also, composing characters are treated as a
10289 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010290 When {end} is omitted the slice continues to the last item.
10291 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010292 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010293
10294 Can also be used as a |method|: >
10295 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010296<
10297 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010298
10299
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010300sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010301 Sort the items in {list} in-place. Returns {list}.
10302
10303 If you want a list to remain unmodified make a copy first: >
10304 :let sortedlist = sort(copy(mylist))
10305
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010306< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010307 string representation of each item to sort on. Numbers sort
10308 after Strings, |Lists| after Numbers. For sorting text in the
10309 current buffer use |:sort|.
10310
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010311 When {how} is given and it is 'i' then case is ignored.
10312 In legacy script, for backwards compatibility, the value one
10313 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010314
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010315 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010316 locale is used for ordering. Implementation details: strcoll()
10317 is used to compare strings. See |:language| check or set the
10318 collation locale. |v:collate| can also be used to check the
10319 current locale. Sorting using the locale typically ignores
10320 case. Example: >
10321 " ö is sorted similarly to o with English locale.
10322 :language collate en_US.UTF8
10323 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10324< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10325>
10326 " ö is sorted after z with Swedish locale.
10327 :language collate sv_SE.UTF8
10328 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10329< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10330 This does not work properly on Mac.
10331
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010332 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010333 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010334 strtod() function to parse numbers. Strings, Lists, Dicts and
10335 Funcrefs will be considered as being 0). Note that this won't
10336 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010337
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010338 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010339 sorted numerical. This is like 'n' but a string containing
10340 digits will be used as the number they represent.
10341
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010342 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010343 sorted numerical. All values must be a Number or a Float.
10344
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010345 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010346 is called to compare items. The function is invoked with two
10347 items as argument and must return zero if they are equal, 1 or
10348 bigger if the first one sorts after the second one, -1 or
10349 smaller if the first one sorts before the second one.
10350
10351 {dict} is for functions with the "dict" attribute. It will be
10352 used to set the local variable "self". |Dictionary-function|
10353
10354 The sort is stable, items which compare equal (as number or as
10355 string) will keep their relative position. E.g., when sorting
10356 on numbers, text strings will sort next to each other, in the
10357 same order as they were originally.
10358
10359 Can also be used as a |method|: >
10360 mylist->sort()
10361
10362< Also see |uniq()|.
10363
10364 Example: >
10365 func MyCompare(i1, i2)
10366 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10367 endfunc
10368 eval mylist->sort("MyCompare")
10369< A shorter compare version for this specific simple case, which
10370 ignores overflow: >
10371 func MyCompare(i1, i2)
10372 return a:i1 - a:i2
10373 endfunc
10374< For a simple expression you can use a lambda: >
10375 eval mylist->sort({i1, i2 -> i1 - i2})
10376<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010377 Return type: list<{type}>
10378
10379
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010380sound_clear() *sound_clear()*
10381 Stop playing all sounds.
10382
10383 On some Linux systems you may need the libcanberra-pulse
10384 package, otherwise sound may not stop.
10385
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010386 Return type: |Number|
10387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010388 {only available when compiled with the |+sound| feature}
10389
10390 *sound_playevent()*
10391sound_playevent({name} [, {callback}])
10392 Play a sound identified by {name}. Which event names are
10393 supported depends on the system. Often the XDG sound names
10394 are used. On Ubuntu they may be found in
10395 /usr/share/sounds/freedesktop/stereo. Example: >
10396 call sound_playevent('bell')
10397< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10398 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10399 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010400 On macOS, {name} refers to files located in
10401 /System/Library/Sounds (e.g. "Tink"). It will also work for
10402 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010403
10404 When {callback} is specified it is invoked when the sound is
10405 finished. The first argument is the sound ID, the second
10406 argument is the status:
10407 0 sound was played to the end
10408 1 sound was interrupted
10409 2 error occurred after sound started
10410 Example: >
10411 func Callback(id, status)
10412 echomsg "sound " .. a:id .. " finished with " .. a:status
10413 endfunc
10414 call sound_playevent('bell', 'Callback')
10415
10416< MS-Windows: {callback} doesn't work for this function.
10417
10418 Returns the sound ID, which can be passed to `sound_stop()`.
10419 Returns zero if the sound could not be played.
10420
10421 Can also be used as a |method|: >
10422 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010423<
10424 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010425
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010426 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010427
10428 *sound_playfile()*
10429sound_playfile({path} [, {callback}])
10430 Like `sound_playevent()` but play sound file {path}. {path}
10431 must be a full path. On Ubuntu you may find files to play
10432 with this command: >
10433 :!find /usr/share/sounds -type f | grep -v index.theme
10434
10435< Can also be used as a |method|: >
10436 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010437<
10438 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010439
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010440 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010441
10442
10443sound_stop({id}) *sound_stop()*
10444 Stop playing sound {id}. {id} must be previously returned by
10445 `sound_playevent()` or `sound_playfile()`.
10446
10447 On some Linux systems you may need the libcanberra-pulse
10448 package, otherwise sound may not stop.
10449
10450 On MS-Windows, this does not work for event sound started by
10451 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10452
10453 Can also be used as a |method|: >
10454 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010455<
10456 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010457
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010458 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010459
10460 *soundfold()*
10461soundfold({word})
10462 Return the sound-folded equivalent of {word}. Uses the first
10463 language in 'spelllang' for the current window that supports
10464 soundfolding. 'spell' must be set. When no sound folding is
10465 possible the {word} is returned unmodified.
10466 This can be used for making spelling suggestions. Note that
10467 the method can be quite slow.
10468
10469 Can also be used as a |method|: >
10470 GetWord()->soundfold()
10471<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010472 Return type: |String|
10473
10474
10475spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010476 Without argument: The result is the badly spelled word under
10477 or after the cursor. The cursor is moved to the start of the
10478 bad word. When no bad word is found in the cursor line the
10479 result is an empty string and the cursor doesn't move.
10480
10481 With argument: The result is the first word in {sentence} that
10482 is badly spelled. If there are no spelling mistakes the
10483 result is an empty string.
10484
10485 The return value is a list with two items:
10486 - The badly spelled word or an empty string.
10487 - The type of the spelling error:
10488 "bad" spelling mistake
10489 "rare" rare word
10490 "local" word only valid in another region
10491 "caps" word should start with Capital
10492 Example: >
10493 echo spellbadword("the quik brown fox")
10494< ['quik', 'bad'] ~
10495
10496 The spelling information for the current window and the value
10497 of 'spelllang' are used.
10498
10499 Can also be used as a |method|: >
10500 GetText()->spellbadword()
10501<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010502 Return type: list<string>
10503
10504
10505spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010506 Return a |List| with spelling suggestions to replace {word}.
10507 When {max} is given up to this number of suggestions are
10508 returned. Otherwise up to 25 suggestions are returned.
10509
10510 When the {capital} argument is given and it's non-zero only
10511 suggestions with a leading capital will be given. Use this
10512 after a match with 'spellcapcheck'.
10513
10514 {word} can be a badly spelled word followed by other text.
10515 This allows for joining two words that were split. The
10516 suggestions also include the following text, thus you can
10517 replace a line.
10518
10519 {word} may also be a good word. Similar words will then be
10520 returned. {word} itself is not included in the suggestions,
10521 although it may appear capitalized.
10522
10523 The spelling information for the current window is used. The
10524 values of 'spelllang' and 'spellsuggest' are used.
10525
10526 Can also be used as a |method|: >
10527 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010528<
10529 Return type: list<string> or list<any>
10530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010531
10532split({string} [, {pattern} [, {keepempty}]]) *split()*
10533 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010534 empty each white space separated sequence of characters
10535 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010536 Otherwise the string is split where {pattern} matches,
10537 removing the matched characters. 'ignorecase' is not used
10538 here, add \c to ignore case. |/\c|
10539 When the first or last item is empty it is omitted, unless the
10540 {keepempty} argument is given and it's non-zero.
10541 Other empty items are kept when {pattern} matches at least one
10542 character or when {keepempty} is non-zero.
10543 Example: >
10544 :let words = split(getline('.'), '\W\+')
10545< To split a string in individual characters: >
10546 :for c in split(mystring, '\zs')
10547< If you want to keep the separator you can also use '\zs' at
10548 the end of the pattern: >
10549 :echo split('abc:def:ghi', ':\zs')
10550< ['abc:', 'def:', 'ghi'] ~
10551 Splitting a table where the first element can be empty: >
10552 :let items = split(line, ':', 1)
10553< The opposite function is |join()|.
10554
10555 Can also be used as a |method|: >
10556 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010557<
10558 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010559
10560sqrt({expr}) *sqrt()*
10561 Return the non-negative square root of Float {expr} as a
10562 |Float|.
10563 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010564 is negative the result is NaN (Not a Number). Returns 0.0 if
10565 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010566 Examples: >
10567 :echo sqrt(100)
10568< 10.0 >
10569 :echo sqrt(-4.01)
10570< nan
10571 "nan" may be different, it depends on system libraries.
10572
10573 Can also be used as a |method|: >
10574 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010575<
10576 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010577
10578
10579srand([{expr}]) *srand()*
10580 Initialize seed used by |rand()|:
10581 - If {expr} is not given, seed values are initialized by
10582 reading from /dev/urandom, if possible, or using time(NULL)
10583 a.k.a. epoch time otherwise; this only has second accuracy.
10584 - If {expr} is given it must be a Number. It is used to
10585 initialize the seed values. This is useful for testing or
10586 when a predictable sequence is intended.
10587
10588 Examples: >
10589 :let seed = srand()
10590 :let seed = srand(userinput)
10591 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010592<
10593 Return type: list<number>
10594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010595
10596state([{what}]) *state()*
10597 Return a string which contains characters indicating the
10598 current state. Mostly useful in callbacks that want to do
10599 work that may not always be safe. Roughly this works like:
10600 - callback uses state() to check if work is safe to do.
10601 Yes: then do it right away.
10602 No: add to work queue and add a |SafeState| and/or
10603 |SafeStateAgain| autocommand (|SafeState| triggers at
10604 toplevel, |SafeStateAgain| triggers after handling
10605 messages and callbacks).
10606 - When SafeState or SafeStateAgain is triggered and executes
10607 your autocommand, check with `state()` if the work can be
10608 done now, and if yes remove it from the queue and execute.
10609 Remove the autocommand if the queue is now empty.
10610 Also see |mode()|.
10611
10612 When {what} is given only characters in this string will be
10613 added. E.g, this checks if the screen has scrolled: >
10614 if state('s') == ''
10615 " screen has not scrolled
10616<
10617 These characters indicate the state, generally indicating that
10618 something is busy:
10619 m halfway a mapping, :normal command, feedkeys() or
10620 stuffed command
10621 o operator pending, e.g. after |d|
10622 a Insert mode autocomplete active
10623 x executing an autocommand
10624 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10625 ch_readraw() when reading json
10626 S not triggering SafeState or SafeStateAgain, e.g. after
10627 |f| or a count
10628 c callback invoked, including timer (repeats for
10629 recursiveness up to "ccc")
10630 s screen has scrolled for messages
10631
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010632 Return type: |String|
10633
10634
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010635str2blob({list} [, {options}]) *str2blob()*
10636 Return a Blob by converting the characters in the List of
10637 strings in {list} into bytes.
10638
10639 A <NL> byte is added to the blob after each list item. A
10640 newline character in the string is translated into a <NUL>
10641 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010642
10643 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010644 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010645
10646 The argument {options} is a |Dict| and supports the following
10647 items:
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010648 encoding Encode the characters using this encoding.
10649 The value is a |String|. See |encoding-names|
10650 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010651
10652 An error is given and an empty blob is returned if the
10653 character encoding fails.
10654
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010655 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010656
10657 See also |blob2str()|
10658
10659 Examples: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010660 str2blob(["ab"]) returns 0z6162
10661 str2blob(["«»"]) returns 0zC2ABC2BB
10662 str2blob(["a\nb"]) returns 0z610A62
10663 str2blob(readfile('myfile.txt'))
10664 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010665<
10666 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010667 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010668<
10669 Return type: |Blob|
10670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010671str2float({string} [, {quoted}]) *str2float()*
10672 Convert String {string} to a Float. This mostly works the
10673 same as when using a floating point number in an expression,
10674 see |floating-point-format|. But it's a bit more permissive.
10675 E.g., "1e40" is accepted, while in an expression you need to
10676 write "1.0e40". The hexadecimal form "0x123" is also
10677 accepted, but not others, like binary or octal.
10678 When {quoted} is present and non-zero then embedded single
10679 quotes before the dot are ignored, thus "1'000.0" is a
10680 thousand.
10681 Text after the number is silently ignored.
10682 The decimal point is always '.', no matter what the locale is
10683 set to. A comma ends the number: "12,345.67" is converted to
10684 12.0. You can strip out thousands separators with
10685 |substitute()|: >
10686 let f = str2float(substitute(text, ',', '', 'g'))
10687<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010688 Returns 0.0 if the conversion fails.
10689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010690 Can also be used as a |method|: >
10691 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010692<
10693 Return type: |Float|
10694
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010695
10696str2list({string} [, {utf8}]) *str2list()*
10697 Return a list containing the number values which represent
10698 each character in String {string}. Examples: >
10699 str2list(" ") returns [32]
10700 str2list("ABC") returns [65, 66, 67]
10701< |list2str()| does the opposite.
10702
10703 When {utf8} is omitted or zero, the current 'encoding' is used.
10704 When {utf8} is TRUE, always treat the String as UTF-8
10705 characters. With UTF-8 composing characters are handled
10706 properly: >
10707 str2list("á") returns [97, 769]
10708
10709< Can also be used as a |method|: >
10710 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010711<
10712 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010713
10714
10715str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10716 Convert string {string} to a number.
10717 {base} is the conversion base, it can be 2, 8, 10 or 16.
10718 When {quoted} is present and non-zero then embedded single
10719 quotes are ignored, thus "1'000'000" is a million.
10720
10721 When {base} is omitted base 10 is used. This also means that
10722 a leading zero doesn't cause octal conversion to be used, as
10723 with the default String to Number conversion. Example: >
10724 let nr = str2nr('0123')
10725<
10726 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10727 different base the result will be zero. Similarly, when
10728 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10729 {base} is 2 a leading "0b" or "0B" is ignored.
10730 Text after the number is silently ignored.
10731
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010732 Returns 0 if {string} is empty or on error.
10733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010734 Can also be used as a |method|: >
10735 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010736<
10737 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010738
10739
10740strcharlen({string}) *strcharlen()*
10741 The result is a Number, which is the number of characters
10742 in String {string}. Composing characters are ignored.
10743 |strchars()| can count the number of characters, counting
10744 composing characters separately.
10745
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010746 Returns 0 if {string} is empty or on error.
10747
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010748 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10749
10750 Can also be used as a |method|: >
10751 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010752<
10753 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010754
10755
10756strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10757 Like |strpart()| but using character index and length instead
10758 of byte index and length.
10759 When {skipcc} is omitted or zero, composing characters are
10760 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010761 When {skipcc} set to 1, composing characters are treated as a
10762 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010763 When a character index is used where a character does not
10764 exist it is omitted and counted as one character. For
10765 example: >
10766 strcharpart('abc', -1, 2)
10767< results in 'a'.
10768
Bram Moolenaard592deb2022-06-17 15:42:40 +010010769 Returns an empty string on error.
10770
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010771 Can also be used as a |method|: >
10772 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010773<
10774 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010775
10776
10777strchars({string} [, {skipcc}]) *strchars()*
10778 The result is a Number, which is the number of characters
10779 in String {string}.
10780 When {skipcc} is omitted or zero, composing characters are
10781 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010782 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010783 |strcharlen()| always does this.
10784
Bram Moolenaard592deb2022-06-17 15:42:40 +010010785 Returns zero on error.
10786
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010787 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10788
10789 {skipcc} is only available after 7.4.755. For backward
10790 compatibility, you can define a wrapper function: >
10791 if has("patch-7.4.755")
10792 function s:strchars(str, skipcc)
10793 return strchars(a:str, a:skipcc)
10794 endfunction
10795 else
10796 function s:strchars(str, skipcc)
10797 if a:skipcc
10798 return strlen(substitute(a:str, ".", "x", "g"))
10799 else
10800 return strchars(a:str)
10801 endif
10802 endfunction
10803 endif
10804<
10805 Can also be used as a |method|: >
10806 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010807<
10808 Return type: |Number|
10809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010810
10811strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10812 The result is a Number, which is the number of display cells
10813 String {string} occupies on the screen when it starts at {col}
10814 (first column is zero). When {col} is omitted zero is used.
10815 Otherwise it is the screen column where to start. This
10816 matters for Tab characters.
10817 The option settings of the current window are used. This
10818 matters for anything that's displayed differently, such as
10819 'tabstop' and 'display'.
10820 When {string} contains characters with East Asian Width Class
10821 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010822 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010823 Also see |strlen()|, |strwidth()| and |strchars()|.
10824
10825 Can also be used as a |method|: >
10826 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010827<
10828 Return type: |Number|
10829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010830
10831strftime({format} [, {time}]) *strftime()*
10832 The result is a String, which is a formatted date and time, as
10833 specified by the {format} string. The given {time} is used,
10834 or the current time if no time is given. The accepted
10835 {format} depends on your system, thus this is not portable!
10836 See the manual page of the C function strftime() for the
10837 format. The maximum length of the result is 80 characters.
10838 See also |localtime()|, |getftime()| and |strptime()|.
10839 The language can be changed with the |:language| command.
10840 Examples: >
10841 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10842 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10843 :echo strftime("%y%m%d %T") 970427 11:53:55
10844 :echo strftime("%H:%M") 11:55
10845 :echo strftime("%c", getftime("file.c"))
10846 Show mod time of file.c.
10847< Not available on all systems. To check use: >
10848 :if exists("*strftime")
10849
10850< Can also be used as a |method|: >
10851 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010852<
10853 Return type: |String|
10854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010855
10856strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010857 Get a Number corresponding to the character at {index} in
10858 {str}. This uses a zero-based character index, not a byte
10859 index. Composing characters are considered separate
10860 characters here. Use |nr2char()| to convert the Number to a
10861 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010862 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010863 Also see |strcharpart()| and |strchars()|.
10864
10865 Can also be used as a |method|: >
10866 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010867<
10868 Return type: |Number|
10869
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010870
10871stridx({haystack}, {needle} [, {start}]) *stridx()*
10872 The result is a Number, which gives the byte index in
10873 {haystack} of the first occurrence of the String {needle}.
10874 If {start} is specified, the search starts at index {start}.
10875 This can be used to find a second match: >
10876 :let colon1 = stridx(line, ":")
10877 :let colon2 = stridx(line, ":", colon1 + 1)
10878< The search is done case-sensitive.
10879 For pattern searches use |match()|.
10880 -1 is returned if the {needle} does not occur in {haystack}.
10881 See also |strridx()|.
10882 Examples: >
10883 :echo stridx("An Example", "Example") 3
10884 :echo stridx("Starting point", "Start") 0
10885 :echo stridx("Starting point", "start") -1
10886< *strstr()* *strchr()*
10887 stridx() works similar to the C function strstr(). When used
10888 with a single character it works similar to strchr().
10889
10890 Can also be used as a |method|: >
10891 GetHaystack()->stridx(needle)
10892<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010893 Return type: |Number|
10894
10895
10896string({expr}) *string()*
10897 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010898 Float, String, Blob or a composition of them, then the result
10899 can be parsed back with |eval()|.
10900 {expr} type result ~
10901 String 'string' (single quotes are doubled)
10902 Number 123
10903 Float 123.123456 or 1.123456e8
10904 Funcref function('name')
10905 Blob 0z00112233.44556677.8899
10906 List [item, item]
10907 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010908 Class class SomeName
10909 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010910 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010911 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010912
10913 When a |List| or |Dictionary| has a recursive reference it is
10914 replaced by "[...]" or "{...}". Using eval() on the result
10915 will then fail.
10916
mityu7f0bba22024-03-29 10:14:41 +010010917 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010918 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010919 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010920
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010921 Can also be used as a |method|: >
10922 mylist->string()
10923
10924< Also see |strtrans()|.
10925
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010926 Return type: |String|
10927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010928
10929strlen({string}) *strlen()*
10930 The result is a Number, which is the length of the String
10931 {string} in bytes.
10932 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010933 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010934 If you want to count the number of multibyte characters use
10935 |strchars()|.
10936 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10937
10938 Can also be used as a |method|: >
10939 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010940<
10941 Return type: |Number|
10942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010943
10944strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10945 The result is a String, which is part of {src}, starting from
10946 byte {start}, with the byte length {len}.
10947 When {chars} is present and TRUE then {len} is the number of
10948 characters positions (composing characters are not counted
10949 separately, thus "1" means one base character and any
10950 following composing characters).
10951 To count {start} as characters instead of bytes use
10952 |strcharpart()|.
10953
10954 When bytes are selected which do not exist, this doesn't
10955 result in an error, the bytes are simply omitted.
10956 If {len} is missing, the copy continues from {start} till the
10957 end of the {src}. >
10958 strpart("abcdefg", 3, 2) == "de"
10959 strpart("abcdefg", -2, 4) == "ab"
10960 strpart("abcdefg", 5, 4) == "fg"
10961 strpart("abcdefg", 3) == "defg"
10962
10963< Note: To get the first character, {start} must be 0. For
10964 example, to get the character under the cursor: >
10965 strpart(getline("."), col(".") - 1, 1, v:true)
10966<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010967 Returns an empty string on error.
10968
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010969 Can also be used as a |method|: >
10970 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010971<
10972 Return type: |String|
10973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010974
10975strptime({format}, {timestring}) *strptime()*
10976 The result is a Number, which is a unix timestamp representing
10977 the date and time in {timestring}, which is expected to match
10978 the format specified in {format}.
10979
10980 The accepted {format} depends on your system, thus this is not
10981 portable! See the manual page of the C function strptime()
10982 for the format. Especially avoid "%c". The value of $TZ also
10983 matters.
10984
10985 If the {timestring} cannot be parsed with {format} zero is
10986 returned. If you do not know the format of {timestring} you
10987 can try different {format} values until you get a non-zero
10988 result.
10989
10990 See also |strftime()|.
10991 Examples: >
10992 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10993< 862156163 >
10994 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10995< Sun Apr 27 11:53:55 1997 >
10996 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10997< Sun Apr 27 12:53:55 1997
10998
10999 Can also be used as a |method|: >
11000 GetFormat()->strptime(timestring)
11001<
11002 Not available on all systems. To check use: >
11003 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011004<
11005 Return type: |Number|
11006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011007
11008strridx({haystack}, {needle} [, {start}]) *strridx()*
11009 The result is a Number, which gives the byte index in
11010 {haystack} of the last occurrence of the String {needle}.
11011 When {start} is specified, matches beyond this index are
11012 ignored. This can be used to find a match before a previous
11013 match: >
11014 :let lastcomma = strridx(line, ",")
11015 :let comma2 = strridx(line, ",", lastcomma - 1)
11016< The search is done case-sensitive.
11017 For pattern searches use |match()|.
11018 -1 is returned if the {needle} does not occur in {haystack}.
11019 If the {needle} is empty the length of {haystack} is returned.
11020 See also |stridx()|. Examples: >
11021 :echo strridx("an angry armadillo", "an") 3
11022< *strrchr()*
11023 When used with a single character it works similar to the C
11024 function strrchr().
11025
11026 Can also be used as a |method|: >
11027 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011028<
11029 Return type: |Number|
11030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011031
11032strtrans({string}) *strtrans()*
11033 The result is a String, which is {string} with all unprintable
11034 characters translated into printable characters |'isprint'|.
11035 Like they are shown in a window. Example: >
11036 echo strtrans(@a)
11037< This displays a newline in register a as "^@" instead of
11038 starting a new line.
11039
Bram Moolenaard592deb2022-06-17 15:42:40 +010011040 Returns an empty string on error.
11041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011042 Can also be used as a |method|: >
11043 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011044<
11045 Return type: |String|
11046
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011047
Christian Brabandt67672ef2023-04-24 21:09:54 +010011048strutf16len({string} [, {countcc}]) *strutf16len()*
11049 The result is a Number, which is the number of UTF-16 code
11050 units in String {string} (after converting it to UTF-16).
11051
11052 When {countcc} is TRUE, composing characters are counted
11053 separately.
11054 When {countcc} is omitted or FALSE, composing characters are
11055 ignored.
11056
11057 Returns zero on error.
11058
11059 Also see |strlen()| and |strcharlen()|.
11060 Examples: >
11061 echo strutf16len('a') returns 1
11062 echo strutf16len('©') returns 1
11063 echo strutf16len('😊') returns 2
11064 echo strutf16len('ą́') returns 1
11065 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011066<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011067 Can also be used as a |method|: >
11068 GetText()->strutf16len()
11069<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011070 Return type: |Number|
11071
11072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011073strwidth({string}) *strwidth()*
11074 The result is a Number, which is the number of display cells
11075 String {string} occupies. A Tab character is counted as one
11076 cell, alternatively use |strdisplaywidth()|.
11077 When {string} contains characters with East Asian Width Class
11078 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011079 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011080 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11081
11082 Can also be used as a |method|: >
11083 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011084<
11085 Return type: |Number|
11086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011087
11088submatch({nr} [, {list}]) *submatch()* *E935*
11089 Only for an expression in a |:substitute| command or
11090 substitute() function.
11091 Returns the {nr}'th submatch of the matched text. When {nr}
11092 is 0 the whole matched text is returned.
11093 Note that a NL in the string can stand for a line break of a
11094 multi-line match or a NUL character in the text.
11095 Also see |sub-replace-expression|.
11096
11097 If {list} is present and non-zero then submatch() returns
11098 a list of strings, similar to |getline()| with two arguments.
11099 NL characters in the text represent NUL characters in the
11100 text.
11101 Only returns more than one item for |:substitute|, inside
11102 |substitute()| this list will always contain one or zero
11103 items, since there are no real line breaks.
11104
11105 When substitute() is used recursively only the submatches in
11106 the current (deepest) call can be obtained.
11107
Bram Moolenaard592deb2022-06-17 15:42:40 +010011108 Returns an empty string or list on error.
11109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011110 Examples: >
11111 :s/\d\+/\=submatch(0) + 1/
11112 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11113< This finds the first number in the line and adds one to it.
11114 A line break is included as a newline character.
11115
11116 Can also be used as a |method|: >
11117 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011118<
11119 Return type: |String| or list<string> depending on {list}
11120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011121
11122substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11123 The result is a String, which is a copy of {string}, in which
11124 the first match of {pat} is replaced with {sub}.
11125 When {flags} is "g", all matches of {pat} in {string} are
11126 replaced. Otherwise {flags} should be "".
11127
11128 This works like the ":substitute" command (without any flags).
11129 But the matching with {pat} is always done like the 'magic'
11130 option is set and 'cpoptions' is empty (to make scripts
11131 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11132 if you want to ignore or match case and ignore 'ignorecase'.
11133 'smartcase' is not used. See |string-match| for how {pat} is
11134 used.
11135
11136 A "~" in {sub} is not replaced with the previous {sub}.
11137 Note that some codes in {sub} have a special meaning
11138 |sub-replace-special|. For example, to replace something with
11139 "\n" (two characters), use "\\\\n" or '\\n'.
11140
11141 When {pat} does not match in {string}, {string} is returned
11142 unmodified.
11143
11144 Example: >
11145 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11146< This removes the last component of the 'path' option. >
11147 :echo substitute("testing", ".*", "\\U\\0", "")
11148< results in "TESTING".
11149
11150 When {sub} starts with "\=", the remainder is interpreted as
11151 an expression. See |sub-replace-expression|. Example: >
11152 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011153 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011154
11155< When {sub} is a Funcref that function is called, with one
11156 optional argument. Example: >
11157 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11158< The optional argument is a list which contains the whole
11159 matched string and up to nine submatches, like what
11160 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011161 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011162
Bram Moolenaard592deb2022-06-17 15:42:40 +010011163< Returns an empty string on error.
11164
11165 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011166 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011167<
11168 Return type: |String|
11169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011170
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011171swapfilelist() *swapfilelist()*
11172 Returns a list of swap file names, like what "vim -r" shows.
11173 See the |-r| command argument. The 'directory' option is used
11174 for the directories to inspect. If you only want to get a
11175 list of swap files in the current directory then temporarily
11176 set 'directory' to a dot: >
11177 let save_dir = &directory
11178 let &directory = '.'
11179 let swapfiles = swapfilelist()
11180 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011181<
11182 Return type: list<string>
11183
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011185swapinfo({fname}) *swapinfo()*
11186 The result is a dictionary, which holds information about the
11187 swapfile {fname}. The available fields are:
11188 version Vim version
11189 user user name
11190 host host name
11191 fname original file name
11192 pid PID of the Vim process that created the swap
11193 file
11194 mtime last modification time in seconds
11195 inode Optional: INODE number of the file
11196 dirty 1 if file was modified, 0 if not
11197 Note that "user" and "host" are truncated to at most 39 bytes.
11198 In case of failure an "error" item is added with the reason:
11199 Cannot open file: file not found or in accessible
11200 Cannot read file: cannot read first block
11201 Not a swap file: does not contain correct block ID
11202 Magic number mismatch: Info in first block is invalid
11203
11204 Can also be used as a |method|: >
11205 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011206<
11207 Return type: dict<any> or dict<string>
11208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011209
11210swapname({buf}) *swapname()*
11211 The result is the swap file path of the buffer {expr}.
11212 For the use of {buf}, see |bufname()| above.
11213 If buffer {buf} is the current buffer, the result is equal to
11214 |:swapname| (unless there is no swap file).
11215 If buffer {buf} has no swap file, returns an empty string.
11216
11217 Can also be used as a |method|: >
11218 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011219<
11220 Return type: |String|
11221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011222
11223synID({lnum}, {col}, {trans}) *synID()*
11224 The result is a Number, which is the syntax ID at the position
11225 {lnum} and {col} in the current window.
11226 The syntax ID can be used with |synIDattr()| and
11227 |synIDtrans()| to obtain syntax information about text.
11228
11229 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11230 line. 'synmaxcol' applies, in a longer line zero is returned.
11231 Note that when the position is after the last character,
11232 that's where the cursor can be in Insert mode, synID() returns
11233 zero. {lnum} is used like with |getline()|.
11234
11235 When {trans} is |TRUE|, transparent items are reduced to the
11236 item that they reveal. This is useful when wanting to know
11237 the effective color. When {trans} is |FALSE|, the transparent
11238 item is returned. This is useful when wanting to know which
11239 syntax item is effective (e.g. inside parens).
11240 Warning: This function can be very slow. Best speed is
11241 obtained by going through the file in forward direction.
11242
Bram Moolenaard592deb2022-06-17 15:42:40 +010011243 Returns zero on error.
11244
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011245 Example (echoes the name of the syntax item under the cursor): >
11246 :echo synIDattr(synID(line("."), col("."), 1), "name")
11247<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011248 Return type: |Number|
11249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011250
11251synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11252 The result is a String, which is the {what} attribute of
11253 syntax ID {synID}. This can be used to obtain information
11254 about a syntax item.
11255 {mode} can be "gui", "cterm" or "term", to get the attributes
11256 for that mode. When {mode} is omitted, or an invalid value is
11257 used, the attributes for the currently active highlighting are
11258 used (GUI, cterm or term).
11259 Use synIDtrans() to follow linked highlight groups.
11260 {what} result
11261 "name" the name of the syntax item
11262 "fg" foreground color (GUI: color name used to set
11263 the color, cterm: color number as a string,
11264 term: empty string)
11265 "bg" background color (as with "fg")
11266 "font" font name (only available in the GUI)
11267 |highlight-font|
11268 "sp" special color for the GUI (as with "fg")
11269 |highlight-guisp|
11270 "ul" underline color for cterm: number as a string
11271 "fg#" like "fg", but for the GUI and the GUI is
11272 running the name in "#RRGGBB" form
11273 "bg#" like "fg#" for "bg"
11274 "sp#" like "fg#" for "sp"
11275 "bold" "1" if bold
11276 "italic" "1" if italic
11277 "reverse" "1" if reverse
11278 "inverse" "1" if inverse (= reverse)
11279 "standout" "1" if standout
11280 "underline" "1" if underlined
11281 "undercurl" "1" if undercurled
11282 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011283 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011284
Bram Moolenaard592deb2022-06-17 15:42:40 +010011285 Returns an empty string on error.
11286
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011287 Example (echoes the color of the syntax item under the
11288 cursor): >
11289 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11290<
11291 Can also be used as a |method|: >
11292 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011293<
11294 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011295
11296
11297synIDtrans({synID}) *synIDtrans()*
11298 The result is a Number, which is the translated syntax ID of
11299 {synID}. This is the syntax group ID of what is being used to
11300 highlight the character. Highlight links given with
11301 ":highlight link" are followed.
11302
Bram Moolenaard592deb2022-06-17 15:42:40 +010011303 Returns zero on error.
11304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011305 Can also be used as a |method|: >
11306 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011307<
11308 Return type: |Number|
11309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011310
11311synconcealed({lnum}, {col}) *synconcealed()*
11312 The result is a |List| with currently three items:
11313 1. The first item in the list is 0 if the character at the
11314 position {lnum} and {col} is not part of a concealable
11315 region, 1 if it is. {lnum} is used like with |getline()|.
11316 2. The second item in the list is a string. If the first item
11317 is 1, the second item contains the text which will be
11318 displayed in place of the concealed text, depending on the
11319 current setting of 'conceallevel' and 'listchars'.
11320 3. The third and final item in the list is a number
11321 representing the specific syntax region matched in the
11322 line. When the character is not concealed the value is
11323 zero. This allows detection of the beginning of a new
11324 concealable region if there are two consecutive regions
11325 with the same replacement character. For an example, if
11326 the text is "123456" and both "23" and "45" are concealed
11327 and replaced by the character "X", then:
11328 call returns ~
11329 synconcealed(lnum, 1) [0, '', 0]
11330 synconcealed(lnum, 2) [1, 'X', 1]
11331 synconcealed(lnum, 3) [1, 'X', 1]
11332 synconcealed(lnum, 4) [1, 'X', 2]
11333 synconcealed(lnum, 5) [1, 'X', 2]
11334 synconcealed(lnum, 6) [0, '', 0]
11335
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011336 Note: Doesn't consider |matchadd()| highlighting items,
11337 since syntax and matching highlighting are two different
11338 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011339
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011340 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011341
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011342
11343synstack({lnum}, {col}) *synstack()*
11344 Return a |List|, which is the stack of syntax items at the
11345 position {lnum} and {col} in the current window. {lnum} is
11346 used like with |getline()|. Each item in the List is an ID
11347 like what |synID()| returns.
11348 The first item in the List is the outer region, following are
11349 items contained in that one. The last one is what |synID()|
11350 returns, unless not the whole item is highlighted or it is a
11351 transparent item.
11352 This function is useful for debugging a syntax file.
11353 Example that shows the syntax stack under the cursor: >
11354 for id in synstack(line("."), col("."))
11355 echo synIDattr(id, "name")
11356 endfor
11357< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011358 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011359 character in a line and the first column in an empty line are
11360 valid positions.
11361
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011362 Return type: list<number> or list<any>
11363
11364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011365system({expr} [, {input}]) *system()* *E677*
11366 Get the output of the shell command {expr} as a |String|. See
11367 |systemlist()| to get the output as a |List|.
11368
11369 When {input} is given and is a |String| this string is written
11370 to a file and passed as stdin to the command. The string is
11371 written as-is, you need to take care of using the correct line
11372 separators yourself.
11373 If {input} is given and is a |List| it is written to the file
11374 in a way |writefile()| does with {binary} set to "b" (i.e.
11375 with a newline between each list item with newlines inside
11376 list items converted to NULs).
11377 When {input} is given and is a number that is a valid id for
11378 an existing buffer then the content of the buffer is written
11379 to the file line by line, each line terminated by a NL and
11380 NULs characters where the text has a NL.
11381
11382 Pipes are not used, the 'shelltemp' option is not used.
11383
11384 When prepended by |:silent| the terminal will not be set to
11385 cooked mode. This is meant to be used for commands that do
11386 not need the user to type. It avoids stray characters showing
11387 up on the screen which require |CTRL-L| to remove. >
11388 :silent let f = system('ls *.vim')
11389<
11390 Note: Use |shellescape()| or |::S| with |expand()| or
11391 |fnamemodify()| to escape special characters in a command
11392 argument. Newlines in {expr} may cause the command to fail.
11393 The characters in 'shellquote' and 'shellxquote' may also
11394 cause trouble.
11395 This is not to be used for interactive commands.
11396
11397 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011398 :let files = system('ls ' .. shellescape(expand('%:h')))
11399 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011400
11401< To make the result more system-independent, the shell output
11402 is filtered to replace <CR> with <NL> for Macintosh, and
11403 <CR><NL> with <NL> for DOS-like systems.
11404 To avoid the string being truncated at a NUL, all NUL
11405 characters are replaced with SOH (0x01).
11406
11407 The command executed is constructed using several options:
11408 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11409 ({tmp} is an automatically generated file name).
11410 For Unix, braces are put around {expr} to allow for
11411 concatenated commands.
11412
11413 The command will be executed in "cooked" mode, so that a
11414 CTRL-C will interrupt the command (on Unix at least).
11415
11416 The resulting error code can be found in |v:shell_error|.
11417 This function will fail in |restricted-mode|.
11418
11419 Note that any wrong value in the options mentioned above may
11420 make the function fail. It has also been reported to fail
11421 when using a security agent application.
11422 Unlike ":!cmd" there is no automatic check for changed files.
11423 Use |:checktime| to force a check.
11424
11425 Can also be used as a |method|: >
11426 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011427<
11428 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011429
11430
11431systemlist({expr} [, {input}]) *systemlist()*
11432 Same as |system()|, but returns a |List| with lines (parts of
11433 output separated by NL) with NULs transformed into NLs. Output
11434 is the same as |readfile()| will output with {binary} argument
11435 set to "b", except that there is no extra empty item when the
11436 result ends in a NL.
11437 Note that on MS-Windows you may get trailing CR characters.
11438
11439 To see the difference between "echo hello" and "echo -n hello"
11440 use |system()| and |split()|: >
11441 echo system('echo hello')->split('\n', 1)
11442<
11443 Returns an empty string on error.
11444
11445 Can also be used as a |method|: >
11446 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011447<
11448 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011449
11450
11451tabpagebuflist([{arg}]) *tabpagebuflist()*
11452 The result is a |List|, where each item is the number of the
11453 buffer associated with each window in the current tab page.
11454 {arg} specifies the number of the tab page to be used. When
11455 omitted the current tab page is used.
11456 When {arg} is invalid the number zero is returned.
11457 To get a list of all buffers in all tabs use this: >
11458 let buflist = []
11459 for i in range(tabpagenr('$'))
11460 call extend(buflist, tabpagebuflist(i + 1))
11461 endfor
11462< Note that a buffer may appear in more than one window.
11463
11464 Can also be used as a |method|: >
11465 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011466<
11467 Return type: list<number>
11468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011469
11470tabpagenr([{arg}]) *tabpagenr()*
11471 The result is a Number, which is the number of the current
11472 tab page. The first tab page has number 1.
11473
11474 The optional argument {arg} supports the following values:
11475 $ the number of the last tab page (the tab page
11476 count).
11477 # the number of the last accessed tab page
11478 (where |g<Tab>| goes to). if there is no
11479 previous tab page 0 is returned.
11480 The number can be used with the |:tab| command.
11481
Bram Moolenaard592deb2022-06-17 15:42:40 +010011482 Returns zero on error.
11483
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011484 Return type: |Number|
11485
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011486
11487tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11488 Like |winnr()| but for tab page {tabarg}.
11489 {tabarg} specifies the number of tab page to be used.
11490 {arg} is used like with |winnr()|:
11491 - When omitted the current window number is returned. This is
11492 the window which will be used when going to this tab page.
11493 - When "$" the number of windows is returned.
11494 - When "#" the previous window nr is returned.
11495 Useful examples: >
11496 tabpagewinnr(1) " current window of tab page 1
11497 tabpagewinnr(4, '$') " number of windows in tab page 4
11498< When {tabarg} is invalid zero is returned.
11499
11500 Can also be used as a |method|: >
11501 GetTabpage()->tabpagewinnr()
11502<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011503 Return type: |Number|
11504
11505
11506tagfiles() *tagfiles()*
11507 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011508 for the current buffer. This is the 'tags' option expanded.
11509
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011510 Return type: list<string> or list<any>
11511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011512
11513taglist({expr} [, {filename}]) *taglist()*
11514 Returns a |List| of tags matching the regular expression {expr}.
11515
11516 If {filename} is passed it is used to prioritize the results
11517 in the same way that |:tselect| does. See |tag-priority|.
11518 {filename} should be the full path of the file.
11519
11520 Each list item is a dictionary with at least the following
11521 entries:
11522 name Name of the tag.
11523 filename Name of the file where the tag is
11524 defined. It is either relative to the
11525 current directory or a full path.
11526 cmd Ex command used to locate the tag in
11527 the file.
11528 kind Type of the tag. The value for this
11529 entry depends on the language specific
11530 kind values. Only available when
11531 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011532 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011533 static A file specific tag. Refer to
11534 |static-tag| for more information.
11535 More entries may be present, depending on the content of the
11536 tags file: access, implementation, inherits and signature.
11537 Refer to the ctags documentation for information about these
11538 fields. For C code the fields "struct", "class" and "enum"
11539 may appear, they give the name of the entity the tag is
11540 contained in.
11541
11542 The ex-command "cmd" can be either an ex search pattern, a
11543 line number or a line number followed by a byte number.
11544
11545 If there are no matching tags, then an empty list is returned.
11546
11547 To get an exact tag match, the anchors '^' and '$' should be
11548 used in {expr}. This also make the function work faster.
11549 Refer to |tag-regexp| for more information about the tag
11550 search regular expression pattern.
11551
11552 Refer to |'tags'| for information about how the tags file is
11553 located by Vim. Refer to |tags-file-format| for the format of
11554 the tags file generated by the different ctags tools.
11555
11556 Can also be used as a |method|: >
11557 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011558<
11559 Return type: list<dict<any>> or list<any>
11560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011561
11562tan({expr}) *tan()*
11563 Return the tangent of {expr}, measured in radians, as a |Float|
11564 in the range [-inf, inf].
11565 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011566 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011567 Examples: >
11568 :echo tan(10)
11569< 0.648361 >
11570 :echo tan(-4.01)
11571< -1.181502
11572
11573 Can also be used as a |method|: >
11574 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011575<
11576 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011577
11578
11579tanh({expr}) *tanh()*
11580 Return the hyperbolic tangent of {expr} as a |Float| in the
11581 range [-1, 1].
11582 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011583 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011584 Examples: >
11585 :echo tanh(0.5)
11586< 0.462117 >
11587 :echo tanh(-1)
11588< -0.761594
11589
11590 Can also be used as a |method|: >
11591 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011592<
11593 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011594
11595
11596tempname() *tempname()* *temp-file-name*
11597 The result is a String, which is the name of a file that
11598 doesn't exist. It can be used for a temporary file. The name
11599 is different for at least 26 consecutive calls. Example: >
11600 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011601 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011602< For Unix, the file will be in a private directory |tempfile|
11603 that is recursively deleted when Vim exits, on other systems
11604 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011605 For MS-Windows forward slashes are used when the 'shellslash'
11606 option is set, or when 'shellcmdflag' starts with '-' and
11607 'shell' does not contain powershell or pwsh.
11608
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011609 Return type: |String|
11610
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011611
11612term_ functions are documented here: |terminal-function-details|
11613
11614
11615terminalprops() *terminalprops()*
11616 Returns a |Dictionary| with properties of the terminal that Vim
11617 detected from the response to |t_RV| request. See
11618 |v:termresponse| for the response itself. If |v:termresponse|
11619 is empty most values here will be 'u' for unknown.
11620 cursor_style whether sending |t_RS| works **
11621 cursor_blink_mode whether sending |t_RC| works **
11622 underline_rgb whether |t_8u| works **
11623 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011624 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011625
11626 ** value 'u' for unknown, 'y' for yes, 'n' for no
11627
11628 If the |+termresponse| feature is missing then the result is
11629 an empty dictionary.
11630
11631 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11632 current cursor style.
11633 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11634 request the cursor blink status.
11635 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11636 is not empty, Vim will detect the working of sending |t_RS|
11637 and |t_RC| on startup.
11638
11639 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11640 This avoids sending it to xterm, which would clear the colors.
11641
11642 For "mouse" the value 'u' is unknown
11643
11644 Also see:
11645 - 'ambiwidth' - detected by using |t_u7|.
11646 - |v:termstyleresp| and |v:termblinkresp| for the response to
11647 |t_RS| and |t_RC|.
11648
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011649 Return type: dict<string>
11650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011651
11652test_ functions are documented here: |test-functions-details|
11653
11654
11655 *timer_info()*
11656timer_info([{id}])
11657 Return a list with information about timers.
11658 When {id} is given only information about this timer is
11659 returned. When timer {id} does not exist an empty list is
11660 returned.
11661 When {id} is omitted information about all timers is returned.
11662
11663 For each timer the information is stored in a |Dictionary| with
11664 these items:
11665 "id" the timer ID
11666 "time" time the timer was started with
11667 "remaining" time until the timer fires
11668 "repeat" number of times the timer will still fire;
11669 -1 means forever
11670 "callback" the callback
11671 "paused" 1 if the timer is paused, 0 otherwise
11672
11673 Can also be used as a |method|: >
11674 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011675<
11676 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011677
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011678 {only available when compiled with the |+timers| feature}
11679
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011680
11681timer_pause({timer}, {paused}) *timer_pause()*
11682 Pause or unpause a timer. A paused timer does not invoke its
11683 callback when its time expires. Unpausing a timer may cause
11684 the callback to be invoked almost immediately if enough time
11685 has passed.
11686
11687 Pausing a timer is useful to avoid the callback to be called
11688 for a short time.
11689
11690 If {paused} evaluates to a non-zero Number or a non-empty
11691 String, then the timer is paused, otherwise it is unpaused.
11692 See |non-zero-arg|.
11693
11694 Can also be used as a |method|: >
11695 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011696<
11697 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011698
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011699 {only available when compiled with the |+timers| feature}
11700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011701
11702 *timer_start()* *timer* *timers*
11703timer_start({time}, {callback} [, {options}])
11704 Create a timer and return the timer ID.
11705
11706 {time} is the waiting time in milliseconds. This is the
11707 minimum time before invoking the callback. When the system is
11708 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011709 Zero can be used to execute the callback when Vim is back in
11710 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011711
11712 {callback} is the function to call. It can be the name of a
11713 function or a |Funcref|. It is called with one argument, which
11714 is the timer ID. The callback is only invoked when Vim is
11715 waiting for input.
11716 If you want to show a message look at |popup_notification()|
11717 to avoid interfering with what the user is doing.
11718
11719 {options} is a dictionary. Supported entries:
11720 "repeat" Number of times to repeat calling the
11721 callback. -1 means forever. When not present
11722 the callback will be called once.
11723 If the timer causes an error three times in a
11724 row the repeat is cancelled. This avoids that
11725 Vim becomes unusable because of all the error
11726 messages.
11727
Bram Moolenaard592deb2022-06-17 15:42:40 +010011728 Returns -1 on error.
11729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011730 Example: >
11731 func MyHandler(timer)
11732 echo 'Handler called'
11733 endfunc
11734 let timer = timer_start(500, 'MyHandler',
11735 \ {'repeat': 3})
11736< This will invoke MyHandler() three times at 500 msec
11737 intervals.
11738
11739 Can also be used as a |method|: >
11740 GetMsec()->timer_start(callback)
11741
11742< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011743
11744 Return type: |Number|
11745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011746 {only available when compiled with the |+timers| feature}
11747
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011748
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011749timer_stop({timer}) *timer_stop()*
11750 Stop a timer. The timer callback will no longer be invoked.
11751 {timer} is an ID returned by timer_start(), thus it must be a
11752 Number. If {timer} does not exist there is no error.
11753
11754 Can also be used as a |method|: >
11755 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011756<
11757 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011758
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011759 {only available when compiled with the |+timers| feature}
11760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011761
11762timer_stopall() *timer_stopall()*
11763 Stop all timers. The timer callbacks will no longer be
11764 invoked. Useful if a timer is misbehaving. If there are no
11765 timers there is no error.
11766
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011767 Return type: |Number|
11768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011769 {only available when compiled with the |+timers| feature}
11770
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011771
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011772tolower({expr}) *tolower()*
11773 The result is a copy of the String given, with all uppercase
11774 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011775 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011776
11777 Can also be used as a |method|: >
11778 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011779<
11780 Return type: |String|
11781
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011782
11783toupper({expr}) *toupper()*
11784 The result is a copy of the String given, with all lowercase
11785 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011786 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011787
11788 Can also be used as a |method|: >
11789 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011790<
11791 Return type: |String|
11792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011793
11794tr({src}, {fromstr}, {tostr}) *tr()*
11795 The result is a copy of the {src} string with all characters
11796 which appear in {fromstr} replaced by the character in that
11797 position in the {tostr} string. Thus the first character in
11798 {fromstr} is translated into the first character in {tostr}
11799 and so on. Exactly like the unix "tr" command.
11800 This code also deals with multibyte characters properly.
11801
Bram Moolenaard592deb2022-06-17 15:42:40 +010011802 Returns an empty string on error.
11803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011804 Examples: >
11805 echo tr("hello there", "ht", "HT")
11806< returns "Hello THere" >
11807 echo tr("<blob>", "<>", "{}")
11808< returns "{blob}"
11809
11810 Can also be used as a |method|: >
11811 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011812<
11813 Return type: |String|
11814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011815
11816trim({text} [, {mask} [, {dir}]]) *trim()*
11817 Return {text} as a String where any character in {mask} is
11818 removed from the beginning and/or end of {text}.
11819
Illia Bobyr80799172023-10-17 18:00:50 +020011820 If {mask} is not given, or is an empty string, {mask} is all
11821 characters up to 0x20, which includes Tab, space, NL and CR,
11822 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011823
11824 The optional {dir} argument specifies where to remove the
11825 characters:
11826 0 remove from the beginning and end of {text}
11827 1 remove only at the beginning of {text}
11828 2 remove only at the end of {text}
11829 When omitted both ends are trimmed.
11830
11831 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011832 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011833
11834 Examples: >
11835 echo trim(" some text ")
11836< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011837 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011838< returns "RESERVE_TAIL" >
11839 echo trim("rm<Xrm<>X>rrm", "rm<>")
11840< returns "Xrm<>X" (characters in the middle are not removed) >
11841 echo trim(" vim ", " ", 2)
11842< returns " vim"
11843
11844 Can also be used as a |method|: >
11845 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011846<
11847 Return type: |String|
11848
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011849
11850trunc({expr}) *trunc()*
11851 Return the largest integral value with magnitude less than or
11852 equal to {expr} as a |Float| (truncate towards zero).
11853 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011854 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011855 Examples: >
11856 echo trunc(1.456)
11857< 1.0 >
11858 echo trunc(-5.456)
11859< -5.0 >
11860 echo trunc(4.0)
11861< 4.0
11862
11863 Can also be used as a |method|: >
11864 Compute()->trunc()
11865<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011866 Return type: |Float|
11867
11868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011869 *type()*
11870type({expr}) The result is a Number representing the type of {expr}.
11871 Instead of using the number directly, it is better to use the
11872 v:t_ variable that has the value:
11873 Number: 0 |v:t_number|
11874 String: 1 |v:t_string|
11875 Funcref: 2 |v:t_func|
11876 List: 3 |v:t_list|
11877 Dictionary: 4 |v:t_dict|
11878 Float: 5 |v:t_float|
11879 Boolean: 6 |v:t_bool| (v:false and v:true)
11880 None: 7 |v:t_none| (v:null and v:none)
11881 Job: 8 |v:t_job|
11882 Channel: 9 |v:t_channel|
11883 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011884 Class: 12 |v:t_class|
11885 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011886 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011887 Enum: 15 |v:t_enum|
11888 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011889 For backward compatibility, this method can be used: >
11890 :if type(myvar) == type(0)
11891 :if type(myvar) == type("")
11892 :if type(myvar) == type(function("tr"))
11893 :if type(myvar) == type([])
11894 :if type(myvar) == type({})
11895 :if type(myvar) == type(0.0)
11896 :if type(myvar) == type(v:false)
11897 :if type(myvar) == type(v:none)
11898< To check if the v:t_ variables exist use this: >
11899 :if exists('v:t_number')
11900
11901< Can also be used as a |method|: >
11902 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011903<
11904 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011905
11906
11907typename({expr}) *typename()*
11908 Return a string representation of the type of {expr}.
11909 Example: >
11910 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011911< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011912
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011913 Return type: |String|
11914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011915
11916undofile({name}) *undofile()*
11917 Return the name of the undo file that would be used for a file
11918 with name {name} when writing. This uses the 'undodir'
11919 option, finding directories that exist. It does not check if
11920 the undo file exists.
11921 {name} is always expanded to the full path, since that is what
11922 is used internally.
11923 If {name} is empty undofile() returns an empty string, since a
11924 buffer without a file name will not write an undo file.
11925 Useful in combination with |:wundo| and |:rundo|.
11926 When compiled without the |+persistent_undo| option this always
11927 returns an empty string.
11928
11929 Can also be used as a |method|: >
11930 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011931<
11932 Return type: |String|
11933
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011934
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011935undotree([{buf}]) *undotree()*
11936 Return the current state of the undo tree for the current
11937 buffer, or for a specific buffer if {buf} is given. The
11938 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011939 "seq_last" The highest undo sequence number used.
11940 "seq_cur" The sequence number of the current position in
11941 the undo tree. This differs from "seq_last"
11942 when some changes were undone.
11943 "time_cur" Time last used for |:earlier| and related
11944 commands. Use |strftime()| to convert to
11945 something readable.
11946 "save_last" Number of the last file write. Zero when no
11947 write yet.
11948 "save_cur" Number of the current position in the undo
11949 tree.
11950 "synced" Non-zero when the last undo block was synced.
11951 This happens when waiting from input from the
11952 user. See |undo-blocks|.
11953 "entries" A list of dictionaries with information about
11954 undo blocks.
11955
11956 The first item in the "entries" list is the oldest undo item.
11957 Each List item is a |Dictionary| with these items:
11958 "seq" Undo sequence number. Same as what appears in
11959 |:undolist|.
11960 "time" Timestamp when the change happened. Use
11961 |strftime()| to convert to something readable.
11962 "newhead" Only appears in the item that is the last one
11963 that was added. This marks the last change
11964 and where further changes will be added.
11965 "curhead" Only appears in the item that is the last one
11966 that was undone. This marks the current
11967 position in the undo tree, the block that will
11968 be used by a redo command. When nothing was
11969 undone after the last change this item will
11970 not appear anywhere.
11971 "save" Only appears on the last block before a file
11972 write. The number is the write count. The
11973 first write has number 1, the last one the
11974 "save_last" mentioned above.
11975 "alt" Alternate entry. This is again a List of undo
11976 blocks. Each item may again have an "alt"
11977 item.
11978
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011979 Return type: dict<any>
11980
11981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011982uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11983 Remove second and succeeding copies of repeated adjacent
11984 {list} items in-place. Returns {list}. If you want a list
11985 to remain unmodified make a copy first: >
11986 :let newlist = uniq(copy(mylist))
11987< The default compare function uses the string representation of
11988 each item. For the use of {func} and {dict} see |sort()|.
11989
Bram Moolenaard592deb2022-06-17 15:42:40 +010011990 Returns zero if {list} is not a |List|.
11991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011992 Can also be used as a |method|: >
11993 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011994<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011995 Return type: list<{type}>
11996
11997
Christian Brabandt67672ef2023-04-24 21:09:54 +010011998 *utf16idx()*
11999utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012000 Same as |charidx()| but returns the UTF-16 code unit index of
12001 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010012002
12003 When {charidx} is present and TRUE, {idx} is used as the
12004 character index in the String {string} instead of as the byte
12005 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010012006 An {idx} in the middle of a UTF-8 sequence is rounded
12007 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010012008
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010012009 Returns -1 if the arguments are invalid or if there are less
12010 than {idx} bytes in {string}. If there are exactly {idx} bytes
12011 the length of the string in UTF-16 code units is returned.
12012
Christian Brabandt67672ef2023-04-24 21:09:54 +010012013 See |byteidx()| and |byteidxcomp()| for getting the byte index
12014 from the UTF-16 index and |charidx()| for getting the
12015 character index from the UTF-16 index.
12016 Refer to |string-offset-encoding| for more information.
12017 Examples: >
12018 echo utf16idx('a😊😊', 3) returns 2
12019 echo utf16idx('a😊😊', 7) returns 4
12020 echo utf16idx('a😊😊', 1, 0, 1) returns 2
12021 echo utf16idx('a😊😊', 2, 0, 1) returns 4
12022 echo utf16idx('aą́c', 6) returns 2
12023 echo utf16idx('aą́c', 6, 1) returns 4
12024 echo utf16idx('a😊😊', 9) returns -1
12025<
12026 Can also be used as a |method|: >
12027 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012028<
12029 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010012030
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012031
12032values({dict}) *values()*
12033 Return a |List| with all the values of {dict}. The |List| is
12034 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012035 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012036
12037 Can also be used as a |method|: >
12038 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012039<
12040 Return type: list<any>
12041
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012042
zeertzjq825cf812023-08-17 22:55:25 +020012043virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012044 The result is a Number, which is the screen column of the file
12045 position given with {expr}. That is, the last screen position
12046 occupied by the character at that position, when the screen
12047 would be of unlimited width. When there is a <Tab> at the
12048 position, the returned Number will be the column at the end of
12049 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12050 set to 8, it returns 8. |conceal| is ignored.
12051 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012052
zeertzjq02f3eba2024-06-12 20:45:24 +020012053 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012054 When {expr} is "$", it means the end of the cursor line, so
12055 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012056
12057 When 'virtualedit' is used {expr} can be [lnum, col, off],
12058 where "off" is the offset in screen columns from the start of
12059 the character. E.g., a position within a <Tab> or after the
12060 last character. When "off" is omitted zero is used. When
12061 Virtual editing is active in the current mode, a position
12062 beyond the end of the line can be returned. Also see
12063 |'virtualedit'|
12064
zeertzjq825cf812023-08-17 22:55:25 +020012065 If {list} is present and non-zero then virtcol() returns a
12066 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012067 character.
12068
zeertzjq825cf812023-08-17 22:55:25 +020012069 With the optional {winid} argument the values are obtained for
12070 that window instead of the current window.
12071
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012072 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012074 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012075 " With text "foo^Lbar" and cursor on the "^L":
12076
12077 virtcol(".") " returns 5
12078 virtcol(".", 1) " returns [4, 5]
12079 virtcol("$") " returns 9
12080
12081 " With text " there", with 't at 'h':
12082
12083 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012084<
12085 The first column is 1. 0 or [0, 0] is returned for an error.
12086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012087 A more advanced example that echoes the maximum length of
12088 all lines: >
12089 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12090
12091< Can also be used as a |method|: >
12092 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012093<
12094 Return type: |Number|
12095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012096
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012097virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12098 The result is a Number, which is the byte index of the
12099 character in window {winid} at buffer line {lnum} and virtual
12100 column {col}.
12101
zeertzjqb583eda2023-10-14 11:32:28 +020012102 If buffer line {lnum} is an empty line, 0 is returned.
12103
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012104 If {col} is greater than the last virtual column in line
12105 {lnum}, then the byte index of the character at the last
12106 virtual column is returned.
12107
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012108 For a multi-byte character, the column number of the first
12109 byte in the character is returned.
12110
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012111 The {winid} argument can be the window number or the
12112 |window-ID|. If this is zero, then the current window is used.
12113
12114 Returns -1 if the window {winid} doesn't exist or the buffer
12115 line {lnum} or virtual column {col} is invalid.
12116
12117 See also |screenpos()|, |virtcol()| and |col()|.
12118
12119 Can also be used as a |method|: >
12120 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012121<
12122 Return type: |Number|
12123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012124
12125visualmode([{expr}]) *visualmode()*
12126 The result is a String, which describes the last Visual mode
12127 used in the current buffer. Initially it returns an empty
12128 string, but once Visual mode has been used, it returns "v",
12129 "V", or "<CTRL-V>" (a single CTRL-V character) for
12130 character-wise, line-wise, or block-wise Visual mode
12131 respectively.
12132 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012133 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012134< This enters the same Visual mode as before. It is also useful
12135 in scripts if you wish to act differently depending on the
12136 Visual mode that was used.
12137 If Visual mode is active, use |mode()| to get the Visual mode
12138 (e.g., in a |:vmap|).
12139 If {expr} is supplied and it evaluates to a non-zero Number or
12140 a non-empty String, then the Visual mode will be cleared and
12141 the old value is returned. See |non-zero-arg|.
12142
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012143 Return type: |String|
12144
12145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012146wildmenumode() *wildmenumode()*
12147 Returns |TRUE| when the wildmenu is active and |FALSE|
12148 otherwise. See 'wildmenu' and 'wildmode'.
12149 This can be used in mappings to handle the 'wildcharm' option
12150 gracefully. (Makes only sense with |mapmode-c| mappings).
12151
12152 For example to make <c-j> work like <down> in wildmode, use: >
12153 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12154<
Milly6c2fc372024-10-16 22:11:17 +020012155 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012156
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012157 Return type: |Number|
12158
12159
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012160win_execute({id}, {command} [, {silent}]) *win_execute()*
12161 Like `execute()` but in the context of window {id}.
12162 The window will temporarily be made the current window,
12163 without triggering autocommands or changing directory. When
12164 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012165 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012166 Example: >
12167 call win_execute(winid, 'set syntax=python')
12168< Doing the same with `setwinvar()` would not trigger
12169 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012170 *E994*
12171 Not all commands are allowed in popup windows.
12172 When window {id} does not exist then no error is given and
12173 an empty string is returned.
12174
12175 Can also be used as a |method|, the base is passed as the
12176 second argument: >
12177 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012178<
12179 Return type: |String|
12180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012181
12182win_findbuf({bufnr}) *win_findbuf()*
12183 Returns a |List| with |window-ID|s for windows that contain
12184 buffer {bufnr}. When there is none the list is empty.
12185
12186 Can also be used as a |method|: >
12187 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012188<
12189 Return type: list<number> or list<any>
12190
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012191
12192win_getid([{win} [, {tab}]]) *win_getid()*
12193 Get the |window-ID| for the specified window.
12194 When {win} is missing use the current window.
12195 With {win} this is the window number. The top window has
12196 number 1.
12197 Without {tab} use the current tab, otherwise the tab with
12198 number {tab}. The first tab has number one.
12199 Return zero if the window cannot be found.
12200
12201 Can also be used as a |method|: >
12202 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012203<
12204 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012205
12206
12207win_gettype([{nr}]) *win_gettype()*
12208 Return the type of the window:
12209 "autocmd" autocommand window. Temporary window
12210 used to execute autocommands.
12211 "command" command-line window |cmdwin|
12212 (empty) normal window
12213 "loclist" |location-list-window|
12214 "popup" popup window |popup|
12215 "preview" preview window |preview-window|
12216 "quickfix" |quickfix-window|
12217 "unknown" window {nr} not found
12218
12219 When {nr} is omitted return the type of the current window.
12220 When {nr} is given return the type of this window by number or
12221 |window-ID|.
12222
12223 Also see the 'buftype' option. When running a terminal in a
12224 popup window then 'buftype' is "terminal" and win_gettype()
12225 returns "popup".
12226
12227 Can also be used as a |method|: >
12228 GetWinid()->win_gettype()
12229<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012230 Return type: |String|
12231
12232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012233win_gotoid({expr}) *win_gotoid()*
12234 Go to window with ID {expr}. This may also change the current
12235 tabpage.
12236 Return TRUE if successful, FALSE if the window cannot be found.
12237
12238 Can also be used as a |method|: >
12239 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012240<
12241 Return type: |Number|
12242
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012243
12244win_id2tabwin({expr}) *win_id2tabwin()*
12245 Return a list with the tab number and window number of window
12246 with ID {expr}: [tabnr, winnr].
12247 Return [0, 0] if the window cannot be found.
12248
12249 Can also be used as a |method|: >
12250 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012251<
12252 Return type: list<number>
12253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012254
12255win_id2win({expr}) *win_id2win()*
12256 Return the window number of window with ID {expr}.
12257 Return 0 if the window cannot be found in the current tabpage.
12258
12259 Can also be used as a |method|: >
12260 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012261<
12262 Return type: |Number|
12263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012264
Daniel Steinbergee630312022-01-10 13:36:34 +000012265win_move_separator({nr}, {offset}) *win_move_separator()*
12266 Move window {nr}'s vertical separator (i.e., the right border)
12267 by {offset} columns, as if being dragged by the mouse. {nr}
12268 can be a window number or |window-ID|. A positive {offset}
12269 moves right and a negative {offset} moves left. Moving a
12270 window's vertical separator will change the width of the
12271 window and the width of other windows adjacent to the vertical
12272 separator. The magnitude of movement may be smaller than
12273 specified (e.g., as a consequence of maintaining
12274 'winminwidth'). Returns TRUE if the window can be found and
12275 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012276 This will fail for the rightmost window and a full-width
12277 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012278 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012279
12280 Can also be used as a |method|: >
12281 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012282<
12283 Return type: |Number|
12284
Daniel Steinbergee630312022-01-10 13:36:34 +000012285
12286win_move_statusline({nr}, {offset}) *win_move_statusline()*
12287 Move window {nr}'s status line (i.e., the bottom border) by
12288 {offset} rows, as if being dragged by the mouse. {nr} can be a
12289 window number or |window-ID|. A positive {offset} moves down
12290 and a negative {offset} moves up. Moving a window's status
12291 line will change the height of the window and the height of
12292 other windows adjacent to the status line. The magnitude of
12293 movement may be smaller than specified (e.g., as a consequence
12294 of maintaining 'winminheight'). Returns TRUE if the window can
12295 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012296 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012297
12298 Can also be used as a |method|: >
12299 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012300<
12301 Return type: |Number|
12302
Daniel Steinbergee630312022-01-10 13:36:34 +000012303
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012304win_screenpos({nr}) *win_screenpos()*
12305 Return the screen position of window {nr} as a list with two
12306 numbers: [row, col]. The first window always has position
12307 [1, 1], unless there is a tabline, then it is [2, 1].
12308 {nr} can be the window number or the |window-ID|. Use zero
12309 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012310 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012311
12312 Can also be used as a |method|: >
12313 GetWinid()->win_screenpos()
12314<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012315 Return type: list<number>
12316
12317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012318win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012319 Temporarily switch to window {target}, then move window {nr}
12320 to a new split adjacent to {target}.
12321 Unlike commands such as |:split|, no new windows are created
12322 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012323
12324 Both {nr} and {target} can be window numbers or |window-ID|s.
12325 Both must be in the current tab page.
12326
12327 Returns zero for success, non-zero for failure.
12328
12329 {options} is a |Dictionary| with the following optional entries:
12330 "vertical" When TRUE, the split is created vertically,
12331 like with |:vsplit|.
12332 "rightbelow" When TRUE, the split is made below or to the
12333 right (if vertical). When FALSE, it is done
12334 above or to the left (if vertical). When not
12335 present, the values of 'splitbelow' and
12336 'splitright' are used.
12337
12338 Can also be used as a |method|: >
12339 GetWinid()->win_splitmove(target)
12340<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012341 Return type: |Number|
12342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012343
12344 *winbufnr()*
12345winbufnr({nr}) The result is a Number, which is the number of the buffer
12346 associated with window {nr}. {nr} can be the window number or
12347 the |window-ID|.
12348 When {nr} is zero, the number of the buffer in the current
12349 window is returned.
12350 When window {nr} doesn't exist, -1 is returned.
12351 Example: >
12352 :echo "The file in the current window is " . bufname(winbufnr(0))
12353<
12354 Can also be used as a |method|: >
12355 FindWindow()->winbufnr()->bufname()
12356<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012357 Return type: |Number|
12358
12359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012360 *wincol()*
12361wincol() The result is a Number, which is the virtual column of the
12362 cursor in the window. This is counting screen cells from the
12363 left side of the window. The leftmost column is one.
12364
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012365 Return type: |Number|
12366
12367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012368 *windowsversion()*
12369windowsversion()
12370 The result is a String. For MS-Windows it indicates the OS
12371 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12372 Windows XP is "5.1". For non-MS-Windows systems the result is
12373 an empty string.
12374
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012375 Return type: |String|
12376
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012377winheight({nr}) *winheight()*
12378 The result is a Number, which is the height of window {nr}.
12379 {nr} can be the window number or the |window-ID|.
12380 When {nr} is zero, the height of the current window is
12381 returned. When window {nr} doesn't exist, -1 is returned.
12382 An existing window always has a height of zero or more.
12383 This excludes any window toolbar line.
12384 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012385 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012386
12387< Can also be used as a |method|: >
12388 GetWinid()->winheight()
12389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012390 Return type: |Number|
12391
12392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012393winlayout([{tabnr}]) *winlayout()*
12394 The result is a nested List containing the layout of windows
12395 in a tabpage.
12396
12397 Without {tabnr} use the current tabpage, otherwise the tabpage
12398 with number {tabnr}. If the tabpage {tabnr} is not found,
12399 returns an empty list.
12400
12401 For a leaf window, it returns:
12402 ['leaf', {winid}]
12403 For horizontally split windows, which form a column, it
12404 returns:
12405 ['col', [{nested list of windows}]]
12406 For vertically split windows, which form a row, it returns:
12407 ['row', [{nested list of windows}]]
12408
12409 Example: >
12410 " Only one window in the tab page
12411 :echo winlayout()
12412 ['leaf', 1000]
12413 " Two horizontally split windows
12414 :echo winlayout()
12415 ['col', [['leaf', 1000], ['leaf', 1001]]]
12416 " The second tab page, with three horizontally split
12417 " windows, with two vertically split windows in the
12418 " middle window
12419 :echo winlayout(2)
12420 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12421 ['leaf', 1001]]], ['leaf', 1000]]]
12422<
12423 Can also be used as a |method|: >
12424 GetTabnr()->winlayout()
12425<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012426 Return type: list<any>
12427
12428
12429winline() *winline()*
12430 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012431 in the window. This is counting screen lines from the top of
12432 the window. The first line is one.
12433 If the cursor was moved the view on the file will be updated
12434 first, this may cause a scroll.
12435
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012436 Return type: |Number|
12437
12438
12439winnr([{arg}]) *winnr()*
12440 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012441 window. The top window has number 1.
12442 Returns zero for a popup window.
12443
12444 The optional argument {arg} supports the following values:
12445 $ the number of the last window (the window
12446 count).
12447 # the number of the last accessed window (where
12448 |CTRL-W_p| goes to). If there is no previous
12449 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012450 returned. May refer to the current window in
12451 some cases (e.g. when evaluating 'statusline'
12452 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012453 {N}j the number of the Nth window below the
12454 current window (where |CTRL-W_j| goes to).
12455 {N}k the number of the Nth window above the current
12456 window (where |CTRL-W_k| goes to).
12457 {N}h the number of the Nth window left of the
12458 current window (where |CTRL-W_h| goes to).
12459 {N}l the number of the Nth window right of the
12460 current window (where |CTRL-W_l| goes to).
12461 The number can be used with |CTRL-W_w| and ":wincmd w"
12462 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012463 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012464 Also see |tabpagewinnr()| and |win_getid()|.
12465 Examples: >
12466 let window_count = winnr('$')
12467 let prev_window = winnr('#')
12468 let wnum = winnr('3k')
12469
12470< Can also be used as a |method|: >
12471 GetWinval()->winnr()
12472<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012473 Return type: |Number|
12474
12475
12476winrestcmd() *winrestcmd()*
12477 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012478 the current window sizes. Only works properly when no windows
12479 are opened or closed and the current window and tab page is
12480 unchanged.
12481 Example: >
12482 :let cmd = winrestcmd()
12483 :call MessWithWindowSizes()
12484 :exe cmd
12485<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012486 Return type: |String|
12487
12488
12489winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012490 Uses the |Dictionary| returned by |winsaveview()| to restore
12491 the view of the current window.
12492 Note: The {dict} does not have to contain all values, that are
12493 returned by |winsaveview()|. If values are missing, those
12494 settings won't be restored. So you can use: >
12495 :call winrestview({'curswant': 4})
12496<
12497 This will only set the curswant value (the column the cursor
12498 wants to move on vertical movements) of the cursor to column 5
12499 (yes, that is 5), while all other settings will remain the
12500 same. This is useful, if you set the cursor position manually.
12501
12502 If you have changed the values the result is unpredictable.
12503 If the window size changed the result won't be the same.
12504
12505 Can also be used as a |method|: >
12506 GetView()->winrestview()
12507<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012508 Return type: |Number|
12509
12510
12511winsaveview() *winsaveview()*
12512 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012513 the view of the current window. Use |winrestview()| to
12514 restore the view.
12515 This is useful if you have a mapping that jumps around in the
12516 buffer and you want to go back to the original view.
12517 This does not save fold information. Use the 'foldenable'
12518 option to temporarily switch off folding, so that folds are
12519 not opened when moving around. This may have side effects.
12520 The return value includes:
12521 lnum cursor line number
12522 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012523 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012524 returns)
12525 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012526 curswant column for vertical movement (Note:
12527 the first column is zero, as opposed
12528 to what |getcurpos()| returns). After
12529 |$| command it will be a very large
12530 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012531 topline first line in the window
12532 topfill filler lines, only in diff mode
12533 leftcol first column displayed; only used when
12534 'wrap' is off
12535 skipcol columns skipped
12536 Note that no option values are saved.
12537
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012538 Return type: dict<number>
12539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012540
12541winwidth({nr}) *winwidth()*
12542 The result is a Number, which is the width of window {nr}.
12543 {nr} can be the window number or the |window-ID|.
12544 When {nr} is zero, the width of the current window is
12545 returned. When window {nr} doesn't exist, -1 is returned.
12546 An existing window always has a width of zero or more.
12547 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012548 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012549 :if winwidth(0) <= 50
12550 : 50 wincmd |
12551 :endif
12552< For getting the terminal or screen size, see the 'columns'
12553 option.
12554
12555 Can also be used as a |method|: >
12556 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012557<
12558 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012559
12560
12561wordcount() *wordcount()*
12562 The result is a dictionary of byte/chars/word statistics for
12563 the current buffer. This is the same info as provided by
12564 |g_CTRL-G|
12565 The return value includes:
12566 bytes Number of bytes in the buffer
12567 chars Number of chars in the buffer
12568 words Number of words in the buffer
12569 cursor_bytes Number of bytes before cursor position
12570 (not in Visual mode)
12571 cursor_chars Number of chars before cursor position
12572 (not in Visual mode)
12573 cursor_words Number of words before cursor position
12574 (not in Visual mode)
12575 visual_bytes Number of bytes visually selected
12576 (only in Visual mode)
12577 visual_chars Number of chars visually selected
12578 (only in Visual mode)
12579 visual_words Number of words visually selected
12580 (only in Visual mode)
12581
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012582 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012583
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012584
12585writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012586 When {object} is a |List| write it to file {fname}. Each list
12587 item is separated with a NL. Each list item must be a String
12588 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012589 All NL characters are replaced with a NUL character.
12590 Inserting CR characters needs to be done before passing {list}
12591 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012592
12593 When {object} is a |Blob| write the bytes to file {fname}
12594 unmodified, also when binary mode is not specified.
12595
12596 {flags} must be a String. These characters are recognized:
12597
12598 'b' Binary mode is used: There will not be a NL after the
12599 last list item. An empty item at the end does cause the
12600 last line in the file to end in a NL.
12601
12602 'a' Append mode is used, lines are appended to the file: >
12603 :call writefile(["foo"], "event.log", "a")
12604 :call writefile(["bar"], "event.log", "a")
12605<
12606 'D' Delete the file when the current function ends. This
12607 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012608 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012609< Fails when not in a function. Also see |:defer|.
12610
12611 's' fsync() is called after writing the file. This flushes
12612 the file to disk, if possible. This takes more time but
12613 avoids losing the file if the system crashes.
12614
12615 'S' fsync() is not called, even when 'fsync' is set.
12616
12617 When {flags} does not contain "S" or "s" then fsync() is
12618 called if the 'fsync' option is set.
12619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012620 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012622 When the write fails -1 is returned, otherwise 0. There is an
12623 error message if the file can't be created or when writing
12624 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012626 Also see |readfile()|.
12627 To copy a file byte for byte: >
12628 :let fl = readfile("foo", "b")
12629 :call writefile(fl, "foocopy", "b")
12630
12631< Can also be used as a |method|: >
12632 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012633<
12634 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012635
12636
12637xor({expr}, {expr}) *xor()*
12638 Bitwise XOR on the two arguments. The arguments are converted
12639 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012640 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012641 Example: >
12642 :let bits = xor(bits, 0x80)
12643<
12644 Can also be used as a |method|: >
12645 :let bits = bits->xor(0x80)
12646<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012647 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012648
12649==============================================================================
126503. Feature list *feature-list*
12651
12652There are three types of features:
126531. Features that are only supported when they have been enabled when Vim
12654 was compiled |+feature-list|. Example: >
12655 :if has("cindent")
12656< *gui_running*
126572. Features that are only supported when certain conditions have been met.
12658 Example: >
12659 :if has("gui_running")
12660< *has-patch*
126613. Beyond a certain version or at a certain version and including a specific
12662 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12663 later, or it is version 7.4 and patch 248 was included. Example: >
12664 :if has("patch-7.4.248")
12665< Note that it's possible for patch 248 to be omitted even though 249 is
12666 included. Only happens when cherry-picking patches.
12667 Note that this form only works for patch 7.4.237 and later, before that
12668 you need to check for the patch and the v:version. Example (checking
12669 version 6.2.148 or later): >
12670 :if v:version > 602 || (v:version == 602 && has("patch148"))
12671
12672Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12673use: `if exists('+shellslash')`
12674
12675
12676acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012677all_builtin_terms Compiled with all builtin terminals enabled. (always
12678 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012679amiga Amiga version of Vim.
12680arabic Compiled with Arabic support |Arabic|.
12681arp Compiled with ARP support (Amiga).
12682autocmd Compiled with autocommand support. (always true)
12683autochdir Compiled with support for 'autochdir'
12684autoservername Automatically enable |clientserver|
12685balloon_eval Compiled with |balloon-eval| support.
12686balloon_multiline GUI supports multiline balloons.
12687beos BeOS version of Vim.
12688browse Compiled with |:browse| support, and browse() will
12689 work.
12690browsefilter Compiled with support for |browsefilter|.
12691bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012692builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012693byte_offset Compiled with support for 'o' in 'statusline'
12694channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012695cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012696clientserver Compiled with remote invocation support |clientserver|.
12697clipboard Compiled with 'clipboard' support.
12698clipboard_working Compiled with 'clipboard' support and it can be used.
12699cmdline_compl Compiled with |cmdline-completion| support.
12700cmdline_hist Compiled with |cmdline-history| support.
12701cmdline_info Compiled with 'showcmd' and 'ruler' support.
12702comments Compiled with |'comments'| support.
12703compatible Compiled to be very Vi compatible.
12704conpty Platform where |ConPTY| can be used.
12705cryptv Compiled with encryption support |encryption|.
12706cscope Compiled with |cscope| support.
12707cursorbind Compiled with |'cursorbind'| (always true)
12708debug Compiled with "DEBUG" defined.
12709dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012710dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012711dialog_gui Compiled with GUI dialog support.
12712diff Compiled with |vimdiff| and 'diff' support.
12713digraphs Compiled with support for digraphs.
12714directx Compiled with support for DirectX and 'renderoptions'.
12715dnd Compiled with support for the "~ register |quote_~|.
12716drop_file Compiled with |drop_file| support.
12717ebcdic Compiled on a machine with ebcdic character set.
12718emacs_tags Compiled with support for Emacs tags.
12719eval Compiled with expression evaluation support. Always
12720 true, of course!
12721ex_extra |+ex_extra| (always true)
12722extra_search Compiled with support for |'incsearch'| and
12723 |'hlsearch'|
12724farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012725file_in_path Compiled with support for |gf| and |<cfile>| (always
12726 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012727filterpipe When 'shelltemp' is off pipes are used for shell
12728 read/write/filter commands
12729find_in_path Compiled with support for include file searches
12730 |+find_in_path|.
12731float Compiled with support for |Float|.
12732fname_case Case in file names matters (for Amiga and MS-Windows
12733 this is not present).
12734folding Compiled with |folding| support.
12735footer Compiled with GUI footer support. |gui-footer|
12736fork Compiled to use fork()/exec() instead of system().
12737gettext Compiled with message translation |multi-lang|
12738gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012739gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012740gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12741gui_gtk Compiled with GTK+ GUI (any version).
12742gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12743gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12744gui_haiku Compiled with Haiku GUI.
12745gui_mac Compiled with Macintosh GUI.
12746gui_motif Compiled with Motif GUI.
12747gui_photon Compiled with Photon GUI.
12748gui_running Vim is running in the GUI, or it will start soon.
12749gui_win32 Compiled with MS-Windows Win32 GUI.
12750gui_win32s idem, and Win32s system being used (Windows 3.1)
12751haiku Haiku version of Vim.
12752hangul_input Compiled with Hangul input support. |hangul|
12753hpux HP-UX version of Vim.
Zhaoming Luoa41dfcd2025-02-06 21:39:35 +010012754hurd GNU/Hurd version of Vim
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012755iconv Can use iconv() for conversion.
12756insert_expand Compiled with support for CTRL-X expansion commands in
12757 Insert mode. (always true)
12758job Compiled with support for |channel| and |job|
12759ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012760jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012761keymap Compiled with 'keymap' support.
12762lambda Compiled with |lambda| support.
12763langmap Compiled with 'langmap' support.
12764libcall Compiled with |libcall()| support.
12765linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12766 'breakindent' support.
12767linux Linux version of Vim.
12768lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012769 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012770listcmds Compiled with commands for the buffer list |:files|
12771 and the argument list |arglist|.
12772localmap Compiled with local mappings and abbr. |:map-local|
12773lua Compiled with Lua interface |Lua|.
12774mac Any Macintosh version of Vim cf. osx
12775macunix Synonym for osxdarwin
12776menu Compiled with support for |:menu|.
12777mksession Compiled with support for |:mksession|.
12778modify_fname Compiled with file name modifiers. |filename-modifiers|
12779 (always true)
12780mouse Compiled with support for mouse.
12781mouse_dec Compiled with support for Dec terminal mouse.
12782mouse_gpm Compiled with support for gpm (Linux console mouse)
12783mouse_gpm_enabled GPM mouse is working
12784mouse_netterm Compiled with support for netterm mouse.
12785mouse_pterm Compiled with support for qnx pterm mouse.
12786mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12787mouse_sgr Compiled with support for sgr mouse.
12788mouse_urxvt Compiled with support for urxvt mouse.
12789mouse_xterm Compiled with support for xterm mouse.
12790mouseshape Compiled with support for 'mouseshape'.
12791multi_byte Compiled with support for 'encoding' (always true)
12792multi_byte_encoding 'encoding' is set to a multibyte encoding.
12793multi_byte_ime Compiled with support for IME input method.
12794multi_lang Compiled with support for multiple languages.
12795mzscheme Compiled with MzScheme interface |mzscheme|.
12796nanotime Compiled with sub-second time stamp checks.
12797netbeans_enabled Compiled with support for |netbeans| and connected.
12798netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012799num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012800ole Compiled with OLE automation support for Win32.
12801osx Compiled for macOS cf. mac
12802osxdarwin Compiled for macOS, with |mac-darwin-feature|
12803packages Compiled with |packages| support.
12804path_extra Compiled with up/downwards search in 'path' and 'tags'
12805perl Compiled with Perl interface.
12806persistent_undo Compiled with support for persistent undo history.
12807postscript Compiled with PostScript file printing.
12808printer Compiled with |:hardcopy| support.
12809profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012810prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012811python Python 2.x interface available. |has-python|
12812python_compiled Compiled with Python 2.x interface. |has-python|
12813python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12814python3 Python 3.x interface available. |has-python|
12815python3_compiled Compiled with Python 3.x interface. |has-python|
12816python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012817python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012818pythonx Python 2.x and/or 3.x interface available. |python_x|
12819qnx QNX version of Vim.
12820quickfix Compiled with |quickfix| support.
12821reltime Compiled with |reltime()| support.
12822rightleft Compiled with 'rightleft' support.
12823ruby Compiled with Ruby interface |ruby|.
12824scrollbind Compiled with 'scrollbind' support. (always true)
12825showcmd Compiled with 'showcmd' support.
12826signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012827smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012828sodium Compiled with libsodium for better crypt support
12829sound Compiled with sound support, e.g. `sound_playevent()`
12830spell Compiled with spell checking support |spell|.
12831startuptime Compiled with |--startuptime| support.
12832statusline Compiled with support for 'statusline', 'rulerformat'
12833 and special formats of 'titlestring' and 'iconstring'.
12834sun SunOS version of Vim.
12835sun_workshop Support for Sun |workshop| has been removed.
12836syntax Compiled with syntax highlighting support |syntax|.
12837syntax_items There are active syntax highlighting items for the
12838 current buffer.
12839system Compiled to use system() instead of fork()/exec().
12840tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012841 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012842tag_old_static Support for old static tags was removed, see
12843 |tag-old-static|.
12844tcl Compiled with Tcl interface.
12845termguicolors Compiled with true color in terminal support.
12846terminal Compiled with |terminal| support.
12847terminfo Compiled with terminfo instead of termcap.
12848termresponse Compiled with support for |t_RV| and |v:termresponse|.
12849textobjects Compiled with support for |text-objects|.
12850textprop Compiled with support for |text-properties|.
12851tgetent Compiled with tgetent support, able to use a termcap
12852 or terminfo file.
12853timers Compiled with |timer_start()| support.
12854title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012855 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012856toolbar Compiled with support for |gui-toolbar|.
12857ttyin input is a terminal (tty)
12858ttyout output is a terminal (tty)
12859unix Unix version of Vim. *+unix*
12860unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12861user_commands User-defined commands. (always true)
12862vartabs Compiled with variable tabstop support |'vartabstop'|.
12863vcon Win32: Virtual console support is working, can use
12864 'termguicolors'. Also see |+vtp|.
12865vertsplit Compiled with vertically split windows |:vsplit|.
12866 (always true)
12867vim_starting True while initial source'ing takes place. |startup|
12868 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012869vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012870viminfo Compiled with viminfo support.
12871vimscript-1 Compiled Vim script version 1 support
12872vimscript-2 Compiled Vim script version 2 support
12873vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012874vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012875virtualedit Compiled with 'virtualedit' option. (always true)
12876visual Compiled with Visual mode. (always true)
12877visualextra Compiled with extra Visual mode commands. (always
12878 true) |blockwise-operators|.
12879vms VMS version of Vim.
12880vreplace Compiled with |gR| and |gr| commands. (always true)
12881vtp Compiled for vcon support |+vtp| (check vcon to find
12882 out if it works in the current console).
12883wildignore Compiled with 'wildignore' option.
12884wildmenu Compiled with 'wildmenu' option.
12885win16 old version for MS-Windows 3.1 (always false)
12886win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12887 64 bits)
12888win32unix Win32 version of Vim, using Unix files (Cygwin)
12889win64 Win64 version of Vim (MS-Windows 64 bit).
12890win95 Win32 version for MS-Windows 95/98/ME (always false)
12891winaltkeys Compiled with 'winaltkeys' option.
12892windows Compiled with support for more than one window.
12893 (always true)
12894writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012895xattr Compiled with extended attributes support |xattr|
12896 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012897xfontset Compiled with X fontset support |xfontset|.
12898xim Compiled with X input method support |xim|.
12899xpm Compiled with pixmap support.
12900xpm_w32 Compiled with pixmap support for Win32. (Only for
12901 backward compatibility. Use "xpm" instead.)
12902xsmp Compiled with X session management support.
12903xsmp_interact Compiled with interactive X session management support.
12904xterm_clipboard Compiled with support for xterm clipboard.
12905xterm_save Compiled with support for saving and restoring the
12906 xterm screen.
12907x11 Compiled with X11 support.
12908
12909
12910==============================================================================
129114. Matching a pattern in a String *string-match*
12912
12913This is common between several functions. A regexp pattern as explained at
12914|pattern| is normally used to find a match in the buffer lines. When a
12915pattern is used to find a match in a String, almost everything works in the
12916same way. The difference is that a String is handled like it is one line.
12917When it contains a "\n" character, this is not seen as a line break for the
12918pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12919>
12920 :let a = "aaaa\nxxxx"
12921 :echo matchstr(a, "..\n..")
12922 aa
12923 xx
12924 :echo matchstr(a, "a.x")
12925 a
12926 x
12927
12928Don't forget that "^" will only match at the first character of the String and
12929"$" at the last character of the string. They don't match after or before a
12930"\n".
12931
12932 vim:tw=78:ts=8:noet:ft=help:norl: