blob: d60d61f0d08c3be3392c14e89d139c84d86ef9c4 [file] [log] [blame]
glepnir037b0282025-01-16 14:37:44 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Jan 16
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 Lakshmanana11b23c2025-01-16 19:16:42 +010075blob2str({blob} [, {options}]) String 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
Doug Kearns9cd9e752024-04-07 17:42:17 +0200231getchar([{expr}]) 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
Doug Kearns9cd9e752024-04-07 17:42:17 +0200236getcharstr([{expr}]) 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}
419nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
420or({expr}, {expr}) Number bitwise OR
421pathshorten({expr} [, {len}]) String shorten directory names in a path
422perleval({expr}) any evaluate |Perl| expression
423popup_atcursor({what}, {options}) Number create popup window near the cursor
424popup_beval({what}, {options}) Number create popup window for 'ballooneval'
425popup_clear() none close all popup windows
426popup_close({id} [, {result}]) none close popup window {id}
427popup_create({what}, {options}) Number create a popup window
428popup_dialog({what}, {options}) Number create a popup window used as a dialog
429popup_filter_menu({id}, {key}) Number filter for a menu popup window
430popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100431popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000432popup_findinfo() Number get window ID of info popup window
433popup_findpreview() Number get window ID of preview popup window
434popup_getoptions({id}) Dict get options of popup window {id}
435popup_getpos({id}) Dict get position of popup window {id}
436popup_hide({id}) none hide popup menu {id}
437popup_list() List get a list of window IDs of all popups
438popup_locate({row}, {col}) Number get window ID of popup at position
439popup_menu({what}, {options}) Number create a popup window used as a menu
440popup_move({id}, {options}) none set position of popup window {id}
441popup_notification({what}, {options})
442 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200443popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000444popup_setoptions({id}, {options})
445 none set options for popup window {id}
446popup_settext({id}, {text}) none set the text of popup window {id}
447popup_show({id}) none unhide popup window {id}
448pow({x}, {y}) Float {x} to the power of {y}
449prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
450printf({fmt}, {expr1}...) String format text
451prompt_getprompt({buf}) String get prompt text
452prompt_setcallback({buf}, {expr}) none set prompt callback function
453prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
454prompt_setprompt({buf}, {text}) none set prompt text
455prop_add({lnum}, {col}, {props}) none add one text property
456prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
457 none add multiple text properties
458prop_clear({lnum} [, {lnum-end} [, {props}]])
459 none remove all text properties
460prop_find({props} [, {direction}])
461 Dict search for a text property
462prop_list({lnum} [, {props}]) List text properties in {lnum}
463prop_remove({props} [, {lnum} [, {lnum-end}]])
464 Number remove a text property
465prop_type_add({name}, {props}) none define a new property type
466prop_type_change({name}, {props})
467 none change an existing property type
468prop_type_delete({name} [, {props}])
469 none delete a property type
470prop_type_get({name} [, {props}])
471 Dict get property type values
472prop_type_list([{props}]) List get list of property types
473pum_getpos() Dict position and size of pum if visible
474pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100475py3eval({expr} [, {locals}]) any evaluate |python3| expression
476pyeval({expr} [, {locals}]) any evaluate |Python| expression
477pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000478rand([{expr}]) Number get pseudo-random number
479range({expr} [, {max} [, {stride}]])
480 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100481readblob({fname} [, {offset} [, {size}]])
482 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000483readdir({dir} [, {expr} [, {dict}]])
484 List file names in {dir} selected by {expr}
485readdirex({dir} [, {expr} [, {dict}]])
486 List file info in {dir} selected by {expr}
487readfile({fname} [, {type} [, {max}]])
488 List get list of lines from file {fname}
489reduce({object}, {func} [, {initial}])
490 any reduce {object} using {func}
491reg_executing() String get the executing register name
492reg_recording() String get the recording register name
493reltime([{start} [, {end}]]) List get time value
494reltimefloat({time}) Float turn the time value into a Float
495reltimestr({time}) String turn time value into a String
496remote_expr({server}, {string} [, {idvar} [, {timeout}]])
497 String send expression
498remote_foreground({server}) Number bring Vim server to the foreground
499remote_peek({serverid} [, {retvar}])
500 Number check for reply string
501remote_read({serverid} [, {timeout}])
502 String read reply string
503remote_send({server}, {string} [, {idvar}])
504 String send key sequence
505remote_startserver({name}) none become server {name}
506remove({list}, {idx} [, {end}]) any/List
507 remove items {idx}-{end} from {list}
508remove({blob}, {idx} [, {end}]) Number/Blob
509 remove bytes {idx}-{end} from {blob}
510remove({dict}, {key}) any remove entry {key} from {dict}
511rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100512repeat({expr}, {count}) List/Blob/String
513 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000514resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100515reverse({obj}) List/Blob/String
516 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000517round({expr}) Float round off {expr}
518rubyeval({expr}) any evaluate |Ruby| expression
519screenattr({row}, {col}) Number attribute at screen position
520screenchar({row}, {col}) Number character at screen position
521screenchars({row}, {col}) List List of characters at screen position
522screencol() Number current cursor column
523screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
524screenrow() Number current cursor row
525screenstring({row}, {col}) String characters at screen position
526search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
527 Number search for {pattern}
528searchcount([{options}]) Dict get or update search stats
529searchdecl({name} [, {global} [, {thisblock}]])
530 Number search for variable declaration
531searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
532 Number search for other end of start/end pair
533searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
534 List search for other end of start/end pair
535searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
536 List search for {pattern}
537server2client({clientid}, {string})
538 Number send reply string
539serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700540setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000541 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700542 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000543setbufvar({buf}, {varname}, {val})
544 none set {varname} in buffer {buf} to {val}
545setcellwidths({list}) none set character cell width overrides
546setcharpos({expr}, {list}) Number set the {expr} position to {list}
547setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100548setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000549setcmdpos({pos}) Number set cursor position in command-line
550setcursorcharpos({list}) Number move cursor to position in {list}
551setenv({name}, {val}) none set environment variable
552setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
553setline({lnum}, {line}) Number set line {lnum} to {line}
554setloclist({nr}, {list} [, {action}])
555 Number modify location list using {list}
556setloclist({nr}, {list}, {action}, {what})
557 Number modify specific location list props
558setmatches({list} [, {win}]) Number restore a list of matches
559setpos({expr}, {list}) Number set the {expr} position to {list}
560setqflist({list} [, {action}]) Number modify quickfix list using {list}
561setqflist({list}, {action}, {what})
562 Number modify specific quickfix list props
563setreg({n}, {v} [, {opt}]) Number set register to value and type
564settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
565settabwinvar({tabnr}, {winnr}, {varname}, {val})
566 none set {varname} in window {winnr} in tab
567 page {tabnr} to {val}
568settagstack({nr}, {dict} [, {action}])
569 Number modify tag stack using {dict}
570setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
571sha256({string}) String SHA256 checksum of {string}
572shellescape({string} [, {special}])
573 String escape {string} for use as shell
574 command argument
575shiftwidth([{col}]) Number effective value of 'shiftwidth'
576sign_define({name} [, {dict}]) Number define or update a sign
577sign_define({list}) List define or update a list of signs
578sign_getdefined([{name}]) List get a list of defined signs
579sign_getplaced([{buf} [, {dict}]])
580 List get a list of placed signs
581sign_jump({id}, {group}, {buf})
582 Number jump to a sign
583sign_place({id}, {group}, {name}, {buf} [, {dict}])
584 Number place a sign
585sign_placelist({list}) List place a list of signs
586sign_undefine([{name}]) Number undefine a sign
587sign_undefine({list}) List undefine a list of signs
588sign_unplace({group} [, {dict}])
589 Number unplace a sign
590sign_unplacelist({list}) List unplace a list of signs
591simplify({filename}) String simplify filename as much as possible
592sin({expr}) Float sine of {expr}
593sinh({expr}) Float hyperbolic sine of {expr}
594slice({expr}, {start} [, {end}]) String, List or Blob
595 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000596sort({list} [, {how} [, {dict}]])
597 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000598sound_clear() none stop playing all sounds
599sound_playevent({name} [, {callback}])
600 Number play an event sound
601sound_playfile({path} [, {callback}])
602 Number play sound file {path}
603sound_stop({id}) none stop playing sound {id}
604soundfold({word}) String sound-fold {word}
605spellbadword() String badly spelled word at cursor
606spellsuggest({word} [, {max} [, {capital}]])
607 List spelling suggestions
608split({expr} [, {pat} [, {keepempty}]])
609 List make |List| from {pat} separated {expr}
610sqrt({expr}) Float square root of {expr}
611srand([{expr}]) List get seed for |rand()|
612state([{what}]) String current state of Vim
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +0100613str2blob({list} [, {options}])
614 Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000615str2float({expr} [, {quoted}]) Float convert String to Float
616str2list({expr} [, {utf8}]) List convert each character of {expr} to
617 ASCII/UTF-8 value
618str2nr({expr} [, {base} [, {quoted}]])
619 Number convert String to Number
620strcharlen({expr}) Number character length of the String {expr}
621strcharpart({str}, {start} [, {len} [, {skipcc}]])
622 String {len} characters of {str} at
623 character {start}
624strchars({expr} [, {skipcc}]) Number character count of the String {expr}
625strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
626strftime({format} [, {time}]) String format time with a specified format
627strgetchar({str}, {index}) Number get char {index} from {str}
628stridx({haystack}, {needle} [, {start}])
629 Number index of {needle} in {haystack}
630string({expr}) String String representation of {expr} value
631strlen({expr}) Number length of the String {expr}
632strpart({str}, {start} [, {len} [, {chars}]])
633 String {len} bytes/chars of {str} at
634 byte {start}
635strptime({format}, {timestring})
636 Number Convert {timestring} to unix timestamp
637strridx({haystack}, {needle} [, {start}])
638 Number last index of {needle} in {haystack}
639strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100640strutf16len({string} [, {countcc}])
641 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000642strwidth({expr}) Number display cell length of the String {expr}
643submatch({nr} [, {list}]) String or List
644 specific match in ":s" or substitute()
645substitute({expr}, {pat}, {sub}, {flags})
646 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000647swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000648swapinfo({fname}) Dict information about swap file {fname}
649swapname({buf}) String swap file of buffer {buf}
650synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
651synIDattr({synID}, {what} [, {mode}])
652 String attribute {what} of syntax ID {synID}
653synIDtrans({synID}) Number translated syntax ID of {synID}
654synconcealed({lnum}, {col}) List info about concealing
655synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
656system({expr} [, {input}]) String output of shell command/filter {expr}
657systemlist({expr} [, {input}]) List output of shell command/filter {expr}
658tabpagebuflist([{arg}]) List list of buffer numbers in tab page
659tabpagenr([{arg}]) Number number of current or last tab page
660tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
661tagfiles() List tags files used
662taglist({expr} [, {filename}]) List list of tags matching {expr}
663tan({expr}) Float tangent of {expr}
664tanh({expr}) Float hyperbolic tangent of {expr}
665tempname() String name for a temporary file
666term_dumpdiff({filename}, {filename} [, {options}])
667 Number display difference between two dumps
668term_dumpload({filename} [, {options}])
669 Number displaying a screen dump
670term_dumpwrite({buf}, {filename} [, {options}])
671 none dump terminal window contents
672term_getaltscreen({buf}) Number get the alternate screen flag
673term_getansicolors({buf}) List get ANSI palette in GUI color mode
674term_getattr({attr}, {what}) Number get the value of attribute {what}
675term_getcursor({buf}) List get the cursor position of a terminal
676term_getjob({buf}) Job get the job associated with a terminal
677term_getline({buf}, {row}) String get a line of text from a terminal
678term_getscrolled({buf}) Number get the scroll count of a terminal
679term_getsize({buf}) List get the size of a terminal
680term_getstatus({buf}) String get the status of a terminal
681term_gettitle({buf}) String get the title of a terminal
682term_gettty({buf}, [{input}]) String get the tty name of a terminal
683term_list() List get the list of terminal buffers
684term_scrape({buf}, {row}) List get row of a terminal screen
685term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
686term_setansicolors({buf}, {colors})
687 none set ANSI palette in GUI color mode
688term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
689term_setkill({buf}, {how}) none set signal to stop job in terminal
690term_setrestore({buf}, {command}) none set command to restore terminal
691term_setsize({buf}, {rows}, {cols})
692 none set the size of a terminal
693term_start({cmd} [, {options}]) Number open a terminal window and run a job
694term_wait({buf} [, {time}]) Number wait for screen to be updated
695terminalprops() Dict properties of the terminal
696test_alloc_fail({id}, {countdown}, {repeat})
697 none make memory allocation fail
698test_autochdir() none enable 'autochdir' during startup
699test_feedinput({string}) none add key sequence to input buffer
700test_garbagecollect_now() none free memory right now for testing
701test_garbagecollect_soon() none free memory soon for testing
702test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000703test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000704test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000705test_mswin_event({event}, {args})
706 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000707test_null_blob() Blob null value for testing
708test_null_channel() Channel null value for testing
709test_null_dict() Dict null value for testing
710test_null_function() Funcref null value for testing
711test_null_job() Job null value for testing
712test_null_list() List null value for testing
713test_null_partial() Funcref null value for testing
714test_null_string() String null value for testing
715test_option_not_set({name}) none reset flag indicating option was set
716test_override({expr}, {val}) none test with Vim internal overrides
717test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000718test_setmouse({row}, {col}) none set the mouse position for testing
719test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200720test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000721test_unknown() any unknown value for testing
722test_void() any void value for testing
723timer_info([{id}]) List information about timers
724timer_pause({id}, {pause}) none pause or unpause a timer
725timer_start({time}, {callback} [, {options}])
726 Number create a timer
727timer_stop({timer}) none stop a timer
728timer_stopall() none stop all timers
729tolower({expr}) String the String {expr} switched to lowercase
730toupper({expr}) String the String {expr} switched to uppercase
731tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
732 to chars in {tostr}
733trim({text} [, {mask} [, {dir}]])
734 String trim characters in {mask} from {text}
735trunc({expr}) Float truncate Float {expr}
736type({expr}) Number type of value {expr}
737typename({expr}) String representation of the type of {expr}
738undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500739undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000740uniq({list} [, {func} [, {dict}]])
741 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100742utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
743 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000744values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200745virtcol({expr} [, {list} [, {winid}])
746 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100747 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100748virtcol2col({winid}, {lnum}, {col})
749 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200750visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000751wildmenumode() Number whether 'wildmenu' mode is active
752win_execute({id}, {command} [, {silent}])
753 String execute {command} in window {id}
754win_findbuf({bufnr}) List find windows containing {bufnr}
755win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
756win_gettype([{nr}]) String type of window {nr}
757win_gotoid({expr}) Number go to window with ID {expr}
758win_id2tabwin({expr}) List get tab and window nr from window ID
759win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000760win_move_separator({nr}) Number move window vertical separator
761win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000762win_screenpos({nr}) List get screen position of window {nr}
763win_splitmove({nr}, {target} [, {options}])
764 Number move window {nr} to split of {target}
765winbufnr({nr}) Number buffer number of window {nr}
766wincol() Number window column of the cursor
767windowsversion() String MS-Windows OS version
768winheight({nr}) Number height of window {nr}
769winlayout([{tabnr}]) List layout of windows in tab {tabnr}
770winline() Number window line of the cursor
771winnr([{expr}]) Number number of current window
772winrestcmd() String returns command to restore window sizes
773winrestview({dict}) none restore view of current window
774winsaveview() Dict save view of current window
775winwidth({nr}) Number width of window {nr}
776wordcount() Dict get byte/char/word statistics
777writefile({object}, {fname} [, {flags}])
778 Number write |Blob| or |List| of lines to file
779xor({expr}, {expr}) Number bitwise XOR
780
781==============================================================================
7822. Details *builtin-function-details*
783
784Not all functions are here, some have been moved to a help file covering the
785specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200786Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000787
788abs({expr}) *abs()*
789 Return the absolute value of {expr}. When {expr} evaluates to
790 a |Float| abs() returns a |Float|. When {expr} can be
791 converted to a |Number| abs() returns a |Number|. Otherwise
792 abs() gives an error message and returns -1.
793 Examples: >
794 echo abs(1.456)
795< 1.456 >
796 echo abs(-5.456)
797< 5.456 >
798 echo abs(-4)
799< 4
800
801 Can also be used as a |method|: >
802 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200803<
804 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000806
807acos({expr}) *acos()*
808 Return the arc cosine of {expr} measured in radians, as a
809 |Float| in the range of [0, pi].
810 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100811 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812 Examples: >
813 :echo acos(0)
814< 1.570796 >
815 :echo acos(-0.5)
816< 2.094395
817
818 Can also be used as a |method|: >
819 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200820<
821 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000823
824add({object}, {expr}) *add()*
825 Append the item {expr} to |List| or |Blob| {object}. Returns
826 the resulting |List| or |Blob|. Examples: >
827 :let alist = add([1, 2, 3], item)
828 :call add(mylist, "woodstock")
829< Note that when {expr} is a |List| it is appended as a single
830 item. Use |extend()| to concatenate |Lists|.
831 When {object} is a |Blob| then {expr} must be a number.
832 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100833 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000834
835 Can also be used as a |method|: >
836 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200837<
838 Return type: list<{type}> (depending on the given |List|) or
839 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000840
841
842and({expr}, {expr}) *and()*
843 Bitwise AND on the two arguments. The arguments are converted
844 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100845 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846 Example: >
847 :let flag = and(bits, 0x80)
848< Can also be used as a |method|: >
849 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200850<
851 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000852
853
854append({lnum}, {text}) *append()*
855 When {text} is a |List|: Append each item of the |List| as a
856 text line below line {lnum} in the current buffer.
857 Otherwise append {text} as one text line below line {lnum} in
858 the current buffer.
859 Any type of item is accepted and converted to a String.
860 {lnum} can be zero to insert a line before the first one.
861 {lnum} is used like with |getline()|.
862 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000863 0 for success. When {text} is an empty list zero is returned,
864 no matter the value of {lnum}.
865 In |Vim9| script an invalid argument or negative number
866 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000867 :let failed = append(line('$'), "# THE END")
868 :let failed = append(0, ["Chapter 1", "the beginning"])
869
870< Can also be used as a |method| after a List, the base is
871 passed as the second argument: >
872 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200873<
874 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000875
876
877appendbufline({buf}, {lnum}, {text}) *appendbufline()*
878 Like |append()| but append the text in buffer {buf}.
879
880 This function works only for loaded buffers. First call
881 |bufload()| if needed.
882
883 For the use of {buf}, see |bufname()|.
884
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000885 {lnum} is the line number to append below. Note that using
886 |line()| would use the current buffer, not the one appending
887 to. Use "$" to append at the end of the buffer. Other string
888 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000889
890 On success 0 is returned, on failure 1 is returned.
891 In |Vim9| script an error is given for an invalid {lnum}.
892
893 If {buf} is not a valid buffer or {lnum} is not valid, an
894 error message is given. Example: >
895 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000896< However, when {text} is an empty list then no error is given
897 for an invalid {lnum}, since {lnum} isn't actually used.
898
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000899 Can also be used as a |method| after a List, the base is
900 passed as the second argument: >
901 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200902<
903 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000904
905
906argc([{winid}]) *argc()*
907 The result is the number of files in the argument list. See
908 |arglist|.
909 If {winid} is not supplied, the argument list of the current
910 window is used.
911 If {winid} is -1, the global argument list is used.
912 Otherwise {winid} specifies the window of which the argument
913 list is used: either the window number or the window ID.
914 Returns -1 if the {winid} argument is invalid.
915
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200916 Return type: |Number|
917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000918 *argidx()*
919argidx() The result is the current index in the argument list. 0 is
920 the first file. argc() - 1 is the last one. See |arglist|.
921
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200922 Return type: |Number|
923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924 *arglistid()*
925arglistid([{winnr} [, {tabnr}]])
926 Return the argument list ID. This is a number which
927 identifies the argument list being used. Zero is used for the
928 global argument list. See |arglist|.
929 Returns -1 if the arguments are invalid.
930
931 Without arguments use the current window.
932 With {winnr} only use this window in the current tab page.
933 With {winnr} and {tabnr} use the window in the specified tab
934 page.
935 {winnr} can be the window number or the |window-ID|.
936
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200937 Return type: |Number|
938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000939 *argv()*
940argv([{nr} [, {winid}]])
941 The result is the {nr}th file in the argument list. See
942 |arglist|. "argv(0)" is the first one. Example: >
943 :let i = 0
944 :while i < argc()
945 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000946 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000947 : let i = i + 1
948 :endwhile
949< Without the {nr} argument, or when {nr} is -1, a |List| with
950 the whole |arglist| is returned.
951
952 The {winid} argument specifies the window ID, see |argc()|.
953 For the Vim command line arguments see |v:argv|.
954
Bram Moolenaar016188f2022-06-06 20:52:59 +0100955 Returns an empty string if {nr}th argument is not present in
956 the argument list. Returns an empty List if the {winid}
957 argument is invalid.
958
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200959 Return type: |String|
960
961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000962asin({expr}) *asin()*
963 Return the arc sine of {expr} measured in radians, as a |Float|
964 in the range of [-pi/2, pi/2].
965 {expr} must evaluate to a |Float| or a |Number| in the range
966 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100967 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
968 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969 Examples: >
970 :echo asin(0.8)
971< 0.927295 >
972 :echo asin(-0.5)
973< -0.523599
974
975 Can also be used as a |method|: >
976 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200977<
978 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000979
980assert_ functions are documented here: |assert-functions-details|
981
982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000983atan({expr}) *atan()*
984 Return the principal value of the arc tangent of {expr}, in
985 the range [-pi/2, +pi/2] radians, as a |Float|.
986 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100987 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000988 Examples: >
989 :echo atan(100)
990< 1.560797 >
991 :echo atan(-4.01)
992< -1.326405
993
994 Can also be used as a |method|: >
995 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200996<
997 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000998
999
1000atan2({expr1}, {expr2}) *atan2()*
1001 Return the arc tangent of {expr1} / {expr2}, measured in
1002 radians, as a |Float| in the range [-pi, pi].
1003 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001004 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1005 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001006 Examples: >
1007 :echo atan2(-1, 1)
1008< -0.785398 >
1009 :echo atan2(1, -1)
1010< 2.356194
1011
1012 Can also be used as a |method|: >
1013 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001014<
1015 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001016
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001017
1018autocmd_add({acmds}) *autocmd_add()*
1019 Adds a List of autocmds and autocmd groups.
1020
1021 The {acmds} argument is a List where each item is a Dict with
1022 the following optional items:
1023 bufnr buffer number to add a buffer-local autocmd.
1024 If this item is specified, then the "pattern"
1025 item is ignored.
1026 cmd Ex command to execute for this autocmd event
1027 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001028 This can be either a String with a single
1029 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001030 group autocmd group name. Refer to |autocmd-groups|.
1031 If this group doesn't exist then it is
1032 created. If not specified or empty, then the
1033 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001034 nested boolean flag, set to v:true to add a nested
1035 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001036 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001037 which executes only once. Refer to
1038 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001039 pattern autocmd pattern string. Refer to
1040 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001041 present, then this item is ignored. This can
1042 be a String with a single pattern or a List of
1043 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001044 replace boolean flag, set to v:true to remove all the
1045 commands associated with the specified autocmd
1046 event and group and add the {cmd}. This is
1047 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001048 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001049
1050 Returns v:true on success and v:false on failure.
1051 Examples: >
1052 " Create a buffer-local autocmd for buffer 5
1053 let acmd = {}
1054 let acmd.group = 'MyGroup'
1055 let acmd.event = 'BufEnter'
1056 let acmd.bufnr = 5
1057 let acmd.cmd = 'call BufEnterFunc()'
1058 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001059<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001060 Can also be used as a |method|: >
1061 GetAutocmdList()->autocmd_add()
1062<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001063 Return type: |vim9-boolean|
1064
1065
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001066autocmd_delete({acmds}) *autocmd_delete()*
1067 Deletes a List of autocmds and autocmd groups.
1068
1069 The {acmds} argument is a List where each item is a Dict with
1070 the following optional items:
1071 bufnr buffer number to delete a buffer-local autocmd.
1072 If this item is specified, then the "pattern"
1073 item is ignored.
1074 cmd Ex command for this autocmd event
1075 event autocmd event name. Refer to |autocmd-events|.
1076 If '*' then all the autocmd events in this
1077 group are deleted.
1078 group autocmd group name. Refer to |autocmd-groups|.
1079 If not specified or empty, then the default
1080 group is used.
1081 nested set to v:true for a nested autocmd.
1082 Refer to |autocmd-nested|.
1083 once set to v:true for an autocmd which executes
1084 only once. Refer to |autocmd-once|.
1085 pattern autocmd pattern string. Refer to
1086 |autocmd-patterns|. If "bufnr" item is
1087 present, then this item is ignored.
1088
1089 If only {group} is specified in a {acmds} entry and {event},
1090 {pattern} and {cmd} are not specified, then that autocmd group
1091 is deleted.
1092
Bram Moolenaar016188f2022-06-06 20:52:59 +01001093 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001094 Examples: >
1095 " :autocmd! BufLeave *.vim
1096 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1097 call autocmd_delete([acmd]})
1098 " :autocmd! MyGroup1 BufLeave
1099 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1100 call autocmd_delete([acmd])
1101 " :autocmd! MyGroup2 BufEnter *.c
1102 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1103 \ pattern: '*.c'}
1104 " :autocmd! MyGroup2 * *.c
1105 let acmd = #{group: 'MyGroup2', event: '*',
1106 \ pattern: '*.c'}
1107 call autocmd_delete([acmd])
1108 " :autocmd! MyGroup3
1109 let acmd = #{group: 'MyGroup3'}
1110 call autocmd_delete([acmd])
1111<
1112 Can also be used as a |method|: >
1113 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001114<
1115 Return type: |vim9-boolean|
1116
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001117
1118autocmd_get([{opts}]) *autocmd_get()*
1119 Returns a |List| of autocmds. If {opts} is not supplied, then
1120 returns the autocmds for all the events in all the groups.
1121
1122 The optional {opts} Dict argument supports the following
1123 items:
1124 group Autocmd group name. If specified, returns only
1125 the autocmds defined in this group. If the
1126 specified group doesn't exist, results in an
1127 error message. If set to an empty string,
1128 then the default autocmd group is used.
1129 event Autocmd event name. If specified, returns only
1130 the autocmds defined for this event. If set
1131 to "*", then returns autocmds for all the
1132 events. If the specified event doesn't exist,
1133 results in an error message.
1134 pattern Autocmd pattern. If specified, returns only
1135 the autocmds defined for this pattern.
1136 A combination of the above three times can be supplied in
1137 {opts}.
1138
1139 Each Dict in the returned List contains the following items:
1140 bufnr For buffer-local autocmds, buffer number where
1141 the autocmd is defined.
1142 cmd Command executed for this autocmd.
1143 event Autocmd event name.
1144 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001145 nested Boolean flag, set to v:true for a nested
1146 autocmd. See |autocmd-nested|.
1147 once Boolean flag, set to v:true, if the autocmd
1148 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001149 pattern Autocmd pattern. For a buffer-local
1150 autocmd, this will be of the form "<buffer=n>".
1151 If there are multiple commands for an autocmd event in a
1152 group, then separate items are returned for each command.
1153
Bram Moolenaar016188f2022-06-06 20:52:59 +01001154 Returns an empty List if an autocmd with the specified group
1155 or event or pattern is not found.
1156
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001157 Examples: >
1158 " :autocmd MyGroup
1159 echo autocmd_get(#{group: 'Mygroup'})
1160 " :autocmd G BufUnload
1161 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1162 " :autocmd G * *.ts
1163 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1164 echo autocmd_get(acmd)
1165 " :autocmd Syntax
1166 echo autocmd_get(#{event: 'Syntax'})
1167 " :autocmd G BufEnter *.ts
1168 let acmd = #{group: 'G', event: 'BufEnter',
1169 \ pattern: '*.ts'}
1170 echo autocmd_get(acmd)
1171<
1172 Can also be used as a |method|: >
1173 Getopts()->autocmd_get()
1174<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001175 Return type: list<dict<any>>
1176
1177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001178balloon_gettext() *balloon_gettext()*
1179 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001180 not used for the List. Returns an empty string if balloon
1181 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001182
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001183 Return type: |String|
1184
1185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001186balloon_show({expr}) *balloon_show()*
1187 Show {expr} inside the balloon. For the GUI {expr} is used as
1188 a string. For a terminal {expr} can be a list, which contains
1189 the lines of the balloon. If {expr} is not a list it will be
1190 split with |balloon_split()|.
1191 If {expr} is an empty string any existing balloon is removed.
1192
1193 Example: >
1194 func GetBalloonContent()
1195 " ... initiate getting the content
1196 return ''
1197 endfunc
1198 set balloonexpr=GetBalloonContent()
1199
1200 func BalloonCallback(result)
1201 call balloon_show(a:result)
1202 endfunc
1203< Can also be used as a |method|: >
1204 GetText()->balloon_show()
1205<
1206 The intended use is that fetching the content of the balloon
1207 is initiated from 'balloonexpr'. It will invoke an
1208 asynchronous method, in which a callback invokes
1209 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001210 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001211
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001212 When showing a balloon is not possible then nothing happens,
1213 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001214 {only available when compiled with the |+balloon_eval| or
1215 |+balloon_eval_term| feature}
1216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001217 Return type: |Number|
1218
1219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001220balloon_split({msg}) *balloon_split()*
1221 Split String {msg} into lines to be displayed in a balloon.
1222 The splits are made for the current window size and optimize
1223 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001224 Returns a |List| with the split lines. Returns an empty List
1225 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001226 Can also be used as a |method|: >
1227 GetText()->balloon_split()->balloon_show()
1228
1229< {only available when compiled with the |+balloon_eval_term|
1230 feature}
1231
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001232 Return type: list<any> or list<string>
1233
h-easte80f3452025-01-02 10:40:29 +01001234base64_decode({string}) *base64_decode()*
1235 Return a Blob containing the bytes decoded from the base64
1236 encoded characters in {string}.
1237
1238 The {string} argument should contain only base64-encoded
1239 characters and should have a length that is a multiple of 4.
1240
1241 Returns an empty blob on error.
1242
1243 Examples: >
1244 " Write the decoded contents to a binary file
1245 call writefile(base64_decode(s), 'tools.bmp')
1246 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001247 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001248<
1249 Can also be used as a |method|: >
1250 GetEncodedString()->base64_decode()
1251<
1252 Return type: |Blob|
1253
1254
1255base64_encode({blob}) *base64_encode()*
1256 Return a base64-encoded String representing the bytes in
1257 {blob}. The base64 alphabet defined in RFC 4648 is used.
1258
1259 Examples: >
1260 " Encode the contents of a binary file
1261 echo base64_encode(readblob('somefile.bin'))
1262 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001263 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001264<
1265 Can also be used as a |method|: >
1266 GetBinaryData()->base64_encode()
1267<
1268 Return type: |String|
1269
1270
Christ van Willegence0ef912024-06-20 23:41:59 +02001271bindtextdomain({package}, {path}) *bindtextdomain()*
1272 Bind a specific {package} to a {path} so that the
1273 |gettext()| function can be used to get language-specific
1274 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001275 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001276
Christ van Willegen8252ef12024-07-11 21:36:21 +02001277 Returns v:true on success and v:false on failure (out of
1278 memory).
1279
1280 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282blob2list({blob}) *blob2list()*
1283 Return a List containing the number value of each byte in Blob
1284 {blob}. Examples: >
1285 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1286 blob2list(0z) returns []
1287< Returns an empty List on error. |list2blob()| does the
1288 opposite.
1289
1290 Can also be used as a |method|: >
1291 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001292<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001293 Return type: list<any> or list<number>
1294
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001295
1296blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001297 Return a List of Strings in the current 'encoding' by
1298 converting the bytes in {blob} into characters.
1299
1300 Each <NL> byte in the blob is interpreted as the end of a
1301 string and a new list item is added. Each <NUL> byte in the
1302 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001303
1304 If {options} is not supplied, the current 'encoding' value is
1305 used to decode the bytes in {blob}.
1306
1307 The argument {options} is a |Dict| and supports the following
1308 items:
1309 encoding Decode the bytes in {blob} using this
1310 encoding. The value is a |String|. See
1311 |encoding-names| for the supported values.
1312 *E1515*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001313 An error is given and an empty List is returned if
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001314 an invalid byte sequence is encountered in {blob},
1315
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001316 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001317
1318 See also |str2blob()|
1319
1320 Examples: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001321 blob2str(0z6162) returns ["ab"]
1322 blob2str(0zC2ABC2BB) returns ["«»"]
1323 blob2str(0zABBB, {'encoding': 'latin1'}) returns ["«»"]
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001324<
1325 Can also be used as a |method|: >
1326 GetBlob()->blob2str()
1327<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001328 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001329
1330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001331 *browse()*
1332browse({save}, {title}, {initdir}, {default})
1333 Put up a file requester. This only works when "has("browse")"
1334 returns |TRUE| (only in some GUI versions).
1335 The input fields are:
1336 {save} when |TRUE|, select file to write
1337 {title} title for the requester
1338 {initdir} directory to start browsing in
1339 {default} default file name
1340 An empty string is returned when the "Cancel" button is hit,
1341 something went wrong, or browsing is not possible.
1342
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001343 Return type: |String|
1344
1345
1346browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001347 Put up a directory requester. This only works when
1348 "has("browse")" returns |TRUE| (only in some GUI versions).
1349 On systems where a directory browser is not supported a file
1350 browser is used. In that case: select a file in the directory
1351 to be used.
1352 The input fields are:
1353 {title} title for the requester
1354 {initdir} directory to start browsing in
1355 When the "Cancel" button is hit, something went wrong, or
1356 browsing is not possible, an empty string is returned.
1357
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001358 Return type: |String|
1359
1360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001361bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001362 Add a buffer to the buffer list with name {name} (must be a
1363 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001364 If a buffer for file {name} already exists, return that buffer
1365 number. Otherwise return the buffer number of the newly
1366 created buffer. When {name} is an empty string then a new
1367 buffer is always created.
1368 The buffer will not have 'buflisted' set and not be loaded
1369 yet. To add some text to the buffer use this: >
1370 let bufnr = bufadd('someName')
1371 call bufload(bufnr)
1372 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001373< Returns 0 on error.
1374 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001375 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001376<
1377 Return type: |Number|
1378
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001379
1380bufexists({buf}) *bufexists()*
1381 The result is a Number, which is |TRUE| if a buffer called
1382 {buf} exists.
1383 If the {buf} argument is a number, buffer numbers are used.
1384 Number zero is the alternate buffer for the current window.
1385
1386 If the {buf} argument is a string it must match a buffer name
1387 exactly. The name can be:
1388 - Relative to the current directory.
1389 - A full path.
1390 - The name of a buffer with 'buftype' set to "nofile".
1391 - A URL name.
1392 Unlisted buffers will be found.
1393 Note that help files are listed by their short name in the
1394 output of |:buffers|, but bufexists() requires using their
1395 long name to be able to find them.
1396 bufexists() may report a buffer exists, but to use the name
1397 with a |:buffer| command you may need to use |expand()|. Esp
1398 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1399 Use "bufexists(0)" to test for the existence of an alternate
1400 file name.
1401
1402 Can also be used as a |method|: >
1403 let exists = 'somename'->bufexists()
1404<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001405 Return type: |Number|
1406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001407 Obsolete name: buffer_exists(). *buffer_exists()*
1408
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001410buflisted({buf}) *buflisted()*
1411 The result is a Number, which is |TRUE| if a buffer called
1412 {buf} exists and is listed (has the 'buflisted' option set).
1413 The {buf} argument is used like with |bufexists()|.
1414
1415 Can also be used as a |method|: >
1416 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001417<
1418 Return type: |Number|
1419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001420
1421bufload({buf}) *bufload()*
1422 Ensure the buffer {buf} is loaded. When the buffer name
1423 refers to an existing file then the file is read. Otherwise
1424 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001425 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001426 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001427 If there is an existing swap file for the file of the buffer,
1428 there will be no dialog, the buffer will be loaded anyway.
1429 The {buf} argument is used like with |bufexists()|.
1430
1431 Can also be used as a |method|: >
1432 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001433<
1434 Return type: |Number|
1435
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001436
1437bufloaded({buf}) *bufloaded()*
1438 The result is a Number, which is |TRUE| if a buffer called
1439 {buf} exists and is loaded (shown in a window or hidden).
1440 The {buf} argument is used like with |bufexists()|.
1441
1442 Can also be used as a |method|: >
1443 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001444<
1445 Return type: |Number|
1446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001447
1448bufname([{buf}]) *bufname()*
1449 The result is the name of a buffer. Mostly as it is displayed
1450 by the `:ls` command, but not using special names such as
1451 "[No Name]".
1452 If {buf} is omitted the current buffer is used.
1453 If {buf} is a Number, that buffer number's name is given.
1454 Number zero is the alternate buffer for the current window.
1455 If {buf} is a String, it is used as a |file-pattern| to match
1456 with the buffer names. This is always done like 'magic' is
1457 set and 'cpoptions' is empty. When there is more than one
1458 match an empty string is returned.
1459 "" or "%" can be used for the current buffer, "#" for the
1460 alternate buffer.
1461 A full match is preferred, otherwise a match at the start, end
1462 or middle of the buffer name is accepted. If you only want a
1463 full match then put "^" at the start and "$" at the end of the
1464 pattern.
1465 Listed buffers are found first. If there is a single match
1466 with a listed buffer, that one is returned. Next unlisted
1467 buffers are searched for.
1468 If the {buf} is a String, but you want to use it as a buffer
1469 number, force it to be a Number by adding zero to it: >
1470 :echo bufname("3" + 0)
1471< Can also be used as a |method|: >
1472 echo bufnr->bufname()
1473
1474< If the buffer doesn't exist, or doesn't have a name, an empty
1475 string is returned. >
1476 bufname("#") alternate buffer name
1477 bufname(3) name of buffer 3
1478 bufname("%") name of current buffer
1479 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001480<
1481 Return type: |String|
1482 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483 Obsolete name: buffer_name().
1484
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001485
1486bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001487 The result is the number of a buffer, as it is displayed by
1488 the `:ls` command. For the use of {buf}, see |bufname()|
1489 above.
1490
1491 If the buffer doesn't exist, -1 is returned. Or, if the
1492 {create} argument is present and TRUE, a new, unlisted,
1493 buffer is created and its number is returned. Example: >
1494 let newbuf = bufnr('Scratch001', 1)
1495< Using an empty name uses the current buffer. To create a new
1496 buffer with an empty name use |bufadd()|.
1497
1498 bufnr("$") is the last buffer: >
1499 :let last_buffer = bufnr("$")
1500< The result is a Number, which is the highest buffer number
1501 of existing buffers. Note that not all buffers with a smaller
1502 number necessarily exist, because ":bwipeout" may have removed
1503 them. Use bufexists() to test for the existence of a buffer.
1504
1505 Can also be used as a |method|: >
1506 echo bufref->bufnr()
1507<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001508 Return type: |Number|
1509
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001510 Obsolete name: buffer_number(). *buffer_number()*
1511 *last_buffer_nr()*
1512 Obsolete name for bufnr("$"): last_buffer_nr().
1513
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001515bufwinid({buf}) *bufwinid()*
1516 The result is a Number, which is the |window-ID| of the first
1517 window associated with buffer {buf}. For the use of {buf},
1518 see |bufname()| above. If buffer {buf} doesn't exist or
1519 there is no such window, -1 is returned. Example: >
1520
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001521 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001522<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001523 Only deals with the current tab page. See |win_findbuf()| for
1524 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001525
1526 Can also be used as a |method|: >
1527 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001528<
1529 Return type: |Number|
1530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001531
1532bufwinnr({buf}) *bufwinnr()*
1533 Like |bufwinid()| but return the window number instead of the
1534 |window-ID|.
1535 If buffer {buf} doesn't exist or there is no such window, -1
1536 is returned. Example: >
1537
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001538 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001539
1540< The number can be used with |CTRL-W_w| and ":wincmd w"
1541 |:wincmd|.
1542
1543 Can also be used as a |method|: >
1544 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001545<
1546 Return type: |Number|
1547
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001548
1549byte2line({byte}) *byte2line()*
1550 Return the line number that contains the character at byte
1551 count {byte} in the current buffer. This includes the
1552 end-of-line character, depending on the 'fileformat' option
1553 for the current buffer. The first character has byte count
1554 one.
1555 Also see |line2byte()|, |go| and |:goto|.
1556
Bram Moolenaar016188f2022-06-06 20:52:59 +01001557 Returns -1 if the {byte} value is invalid.
1558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001559 Can also be used as a |method|: >
1560 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001561<
1562 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001563
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001564 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001565 feature}
1566
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001567
Christian Brabandt67672ef2023-04-24 21:09:54 +01001568byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001569 Return byte index of the {nr}'th character in the String
1570 {expr}. Use zero for the first character, it then returns
1571 zero.
1572 If there are no multibyte characters the returned value is
1573 equal to {nr}.
1574 Composing characters are not counted separately, their byte
1575 length is added to the preceding base character. See
1576 |byteidxcomp()| below for counting composing characters
1577 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001578 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1579 index in the String {expr} instead of as the character index.
1580 The UTF-16 index is the index in the string when it is encoded
1581 with 16-bit words. If the specified UTF-16 index is in the
1582 middle of a character (e.g. in a 4-byte character), then the
1583 byte index of the first byte in the character is returned.
1584 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001585 Example : >
1586 echo matchstr(str, ".", byteidx(str, 3))
1587< will display the fourth character. Another way to do the
1588 same: >
1589 let s = strpart(str, byteidx(str, 3))
1590 echo strpart(s, 0, byteidx(s, 1))
1591< Also see |strgetchar()| and |strcharpart()|.
1592
1593 If there are less than {nr} characters -1 is returned.
1594 If there are exactly {nr} characters the length of the string
1595 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001596 See |charidx()| and |utf16idx()| for getting the character and
1597 UTF-16 index respectively from the byte index.
1598 Examples: >
1599 echo byteidx('a😊😊', 2) returns 5
1600 echo byteidx('a😊😊', 2, 1) returns 1
1601 echo byteidx('a😊😊', 3, 1) returns 5
1602<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001603 Can also be used as a |method|: >
1604 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001605<
1606 Return type: |Number|
1607
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001608
Christian Brabandt67672ef2023-04-24 21:09:54 +01001609byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001610 Like byteidx(), except that a composing character is counted
1611 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001612 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001613 echo byteidx(s, 1)
1614 echo byteidxcomp(s, 1)
1615 echo byteidxcomp(s, 2)
1616< The first and third echo result in 3 ('e' plus composing
1617 character is 3 bytes), the second echo results in 1 ('e' is
1618 one byte).
1619 Only works differently from byteidx() when 'encoding' is set
1620 to a Unicode encoding.
1621
1622 Can also be used as a |method|: >
1623 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001624<
1625 Return type: |Number|
1626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001627
1628call({func}, {arglist} [, {dict}]) *call()* *E699*
1629 Call function {func} with the items in |List| {arglist} as
1630 arguments.
1631 {func} can either be a |Funcref| or the name of a function.
1632 a:firstline and a:lastline are set to the cursor line.
1633 Returns the return value of the called function.
1634 {dict} is for functions with the "dict" attribute. It will be
1635 used to set the local variable "self". |Dictionary-function|
1636
1637 Can also be used as a |method|: >
1638 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001639<
1640 Return type: any, depending on {func}
1641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001642
1643ceil({expr}) *ceil()*
1644 Return the smallest integral value greater than or equal to
1645 {expr} as a |Float| (round up).
1646 {expr} must evaluate to a |Float| or a |Number|.
1647 Examples: >
1648 echo ceil(1.456)
1649< 2.0 >
1650 echo ceil(-5.456)
1651< -5.0 >
1652 echo ceil(4.0)
1653< 4.0
1654
Bram Moolenaar016188f2022-06-06 20:52:59 +01001655 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1656
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001657 Can also be used as a |method|: >
1658 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001659<
1660 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001661
1662
1663ch_ functions are documented here: |channel-functions-details|
1664
1665
1666changenr() *changenr()*
1667 Return the number of the most recent change. This is the same
1668 number as what is displayed with |:undolist| and can be used
1669 with the |:undo| command.
1670 When a change was made it is the number of that change. After
1671 redo it is the number of the redone change. After undo it is
1672 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001673 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001674
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001675 Return type: |Number|
1676
1677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001678char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001679 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001680 Examples: >
1681 char2nr(" ") returns 32
1682 char2nr("ABC") returns 65
1683< When {utf8} is omitted or zero, the current 'encoding' is used.
1684 Example for "utf-8": >
1685 char2nr("á") returns 225
1686 char2nr("á"[0]) returns 195
1687< When {utf8} is TRUE, always treat as UTF-8 characters.
1688 A combining character is a separate character.
1689 |nr2char()| does the opposite.
1690 To turn a string into a list of character numbers: >
1691 let str = "ABC"
1692 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1693< Result: [65, 66, 67]
1694
Bram Moolenaar016188f2022-06-06 20:52:59 +01001695 Returns 0 if {string} is not a |String|.
1696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001697 Can also be used as a |method|: >
1698 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001699<
1700 Return type: |Number|
1701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001703charclass({string}) *charclass()*
1704 Return the character class of the first character in {string}.
1705 The character class is one of:
1706 0 blank
1707 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001708 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709 3 emoji
1710 other specific Unicode class
1711 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001712 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001713
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001714 Return type: |Number|
1715
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001716
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001717charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001718 Same as |col()| but returns the character index of the column
1719 position given with {expr} instead of the byte position.
1720
1721 Example:
1722 With the cursor on '세' in line 5 with text "여보세요": >
1723 charcol('.') returns 3
1724 col('.') returns 7
1725
1726< Can also be used as a |method|: >
1727 GetPos()->col()
1728<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001729 Return type: |Number|
1730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001731 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001732charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001733 Return the character index of the byte at {idx} in {string}.
1734 The index of the first character is zero.
1735 If there are no multibyte characters the returned value is
1736 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001738 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001739 are not counted separately, their byte length is added to the
1740 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001741 When {countcc} is |TRUE|, then composing characters are
1742 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001743
1744 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1745 index in the String {expr} instead of as the byte index.
1746
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001747 Returns -1 if the arguments are invalid or if there are less
1748 than {idx} bytes. If there are exactly {idx} bytes the length
1749 of the string in characters is returned.
1750
1751 An error is given and -1 is returned if the first argument is
1752 not a string, the second argument is not a number or when the
1753 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001754
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001755 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001756 from the character index and |utf16idx()| for getting the
1757 UTF-16 index from the character index.
1758 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001759 Examples: >
1760 echo charidx('áb́ć', 3) returns 1
1761 echo charidx('áb́ć', 6, 1) returns 4
1762 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001763 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001764<
1765 Can also be used as a |method|: >
1766 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001767<
1768 Return type: |Number|
1769
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001770
1771chdir({dir}) *chdir()*
1772 Change the current working directory to {dir}. The scope of
1773 the directory change depends on the directory of the current
1774 window:
1775 - If the current window has a window-local directory
1776 (|:lcd|), then changes the window local directory.
1777 - Otherwise, if the current tabpage has a local
1778 directory (|:tcd|) then changes the tabpage local
1779 directory.
1780 - Otherwise, changes the global directory.
1781 {dir} must be a String.
1782 If successful, returns the previous working directory. Pass
1783 this to another chdir() to restore the directory.
1784 On failure, returns an empty string.
1785
1786 Example: >
1787 let save_dir = chdir(newdir)
1788 if save_dir != ""
1789 " ... do some work
1790 call chdir(save_dir)
1791 endif
1792
1793< Can also be used as a |method|: >
1794 GetDir()->chdir()
1795<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001796 Return type: |String|
1797
1798
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001799cindent({lnum}) *cindent()*
1800 Get the amount of indent for line {lnum} according the C
1801 indenting rules, as with 'cindent'.
1802 The indent is counted in spaces, the value of 'tabstop' is
1803 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001804 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001805 See |C-indenting|.
1806
1807 Can also be used as a |method|: >
1808 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001809<
1810 Return type: |Number|
1811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001812
1813clearmatches([{win}]) *clearmatches()*
1814 Clears all matches previously defined for the current window
1815 by |matchadd()| and the |:match| commands.
1816 If {win} is specified, use the window with this number or
1817 window ID instead of the current window.
1818
1819 Can also be used as a |method|: >
1820 GetWin()->clearmatches()
1821<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001822 Return type: |Number|
1823
1824
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001825col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001826 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001827 position given with {expr}.
1828 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001829 When {expr} is "$", it means the end of the cursor line, so
1830 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001831 Additionally {expr} can be [lnum, col]: a |List| with the line
1832 and column number. Most useful when the column is "$", to get
1833 the last column of a specific line. When "lnum" or "col" is
1834 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001835
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001836 With the optional {winid} argument the values are obtained for
1837 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001838
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001839 To get the line number use |line()|. To get both use
1840 |getpos()|.
1841 For the screen column position use |virtcol()|. For the
1842 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001844 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001846 Examples: >
1847 col(".") column of cursor
1848 col("$") length of cursor line plus one
1849 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001850 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001851<
1852 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001853 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001854 For an uppercase mark the column may actually be in another
1855 buffer.
1856 For the cursor position, when 'virtualedit' is active, the
1857 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001858 line. Also, when using a <Cmd> mapping the cursor isn't
1859 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001860 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001861
1862< Can also be used as a |method|: >
1863 GetPos()->col()
1864<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001865 Return type: |Number|
1866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001867
1868complete({startcol}, {matches}) *complete()* *E785*
1869 Set the matches for Insert mode completion.
1870 Can only be used in Insert mode. You need to use a mapping
1871 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1872 or with an expression mapping.
1873 {startcol} is the byte offset in the line where the completed
1874 text start. The text up to the cursor is the original text
1875 that will be replaced by the matches. Use col('.') for an
1876 empty string. "col('.') - 1" will replace one character by a
1877 match.
1878 {matches} must be a |List|. Each |List| item is one match.
1879 See |complete-items| for the kind of items that are possible.
1880 "longest" in 'completeopt' is ignored.
1881 Note that the after calling this function you need to avoid
1882 inserting anything that would cause completion to stop.
1883 The match can be selected with CTRL-N and CTRL-P as usual with
1884 Insert mode completion. The popup menu will appear if
1885 specified, see |ins-completion-menu|.
1886 Example: >
1887 inoremap <F5> <C-R>=ListMonths()<CR>
1888
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001889 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001890 call complete(col('.'), ['January', 'February', 'March',
1891 \ 'April', 'May', 'June', 'July', 'August', 'September',
1892 \ 'October', 'November', 'December'])
1893 return ''
1894 endfunc
1895< This isn't very useful, but it shows how it works. Note that
1896 an empty string is returned to avoid a zero being inserted.
1897
1898 Can also be used as a |method|, the base is passed as the
1899 second argument: >
1900 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001901<
1902 Return type: |Number|
1903
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001904
1905complete_add({expr}) *complete_add()*
1906 Add {expr} to the list of matches. Only to be used by the
1907 function specified with the 'completefunc' option.
1908 Returns 0 for failure (empty string or out of memory),
1909 1 when the match was added, 2 when the match was already in
1910 the list.
1911 See |complete-functions| for an explanation of {expr}. It is
1912 the same as one item in the list that 'omnifunc' would return.
1913
1914 Can also be used as a |method|: >
1915 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001916<
1917 Return type: |Number|
1918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001919
1920complete_check() *complete_check()*
1921 Check for a key typed while looking for completion matches.
1922 This is to be used when looking for matches takes some time.
1923 Returns |TRUE| when searching for matches is to be aborted,
1924 zero otherwise.
1925 Only to be used by the function specified with the
1926 'completefunc' option.
1927
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001928 Return type: |Number|
1929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001930
1931complete_info([{what}]) *complete_info()*
1932 Returns a |Dictionary| with information about Insert mode
1933 completion. See |ins-completion|.
1934 The items are:
1935 mode Current completion mode name string.
1936 See |complete_info_mode| for the values.
1937 pum_visible |TRUE| if popup menu is visible.
1938 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001939 items List of all completion candidates. Each item
1940 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001941 "abbr", "menu", "kind", "info" and "user_data".
1942 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001943 matches Same as "items", but only returns items that
1944 are matching current query. If both "matches"
1945 and "items" are in "what", the returned list
1946 will still be named "items", but each item
1947 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001948 selected Selected item index. First index is zero.
1949 Index is -1 if no item is selected (showing
1950 typed text only, or the last completion after
1951 no item is selected when using the <Up> or
1952 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001953 completed Return a dictionary containing the entries of
1954 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001955
1956 *complete_info_mode*
1957 mode values are:
1958 "" Not in completion mode
1959 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1960 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1961 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1962 |i_CTRL-X_CTRL-Y|
1963 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1964 "files" File names |i_CTRL-X_CTRL-F|
1965 "tags" Tags |i_CTRL-X_CTRL-]|
1966 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1967 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1968 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1969 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1970 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1971 "function" User defined completion |i_CTRL-X_CTRL-U|
1972 "omni" Omni completion |i_CTRL-X_CTRL-O|
1973 "spell" Spelling suggestions |i_CTRL-X_s|
1974 "eval" |complete()| completion
1975 "unknown" Other internal modes
1976
1977 If the optional {what} list argument is supplied, then only
1978 the items listed in {what} are returned. Unsupported items in
1979 {what} are silently ignored.
1980
1981 To get the position and size of the popup menu, see
1982 |pum_getpos()|. It's also available in |v:event| during the
1983 |CompleteChanged| event.
1984
Bram Moolenaar016188f2022-06-06 20:52:59 +01001985 Returns an empty |Dictionary| on error.
1986
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001987 Examples: >
1988 " Get all items
1989 call complete_info()
1990 " Get only 'mode'
1991 call complete_info(['mode'])
1992 " Get only 'mode' and 'pum_visible'
1993 call complete_info(['mode', 'pum_visible'])
1994
1995< Can also be used as a |method|: >
1996 GetItems()->complete_info()
1997<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001998 Return type: dict<any>
1999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002000 *confirm()*
2001confirm({msg} [, {choices} [, {default} [, {type}]]])
2002 confirm() offers the user a dialog, from which a choice can be
2003 made. It returns the number of the choice. For the first
2004 choice this is 1.
2005 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002006 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002007
2008 {msg} is displayed in a |dialog| with {choices} as the
2009 alternatives. When {choices} is missing or empty, "&OK" is
2010 used (and translated).
2011 {msg} is a String, use '\n' to include a newline. Only on
2012 some systems the string is wrapped when it doesn't fit.
2013
2014 {choices} is a String, with the individual choices separated
2015 by '\n', e.g. >
2016 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2017< The letter after the '&' is the shortcut key for that choice.
2018 Thus you can type 'c' to select "Cancel". The shortcut does
2019 not need to be the first letter: >
2020 confirm("file has been modified", "&Save\nSave &All")
2021< For the console, the first letter of each choice is used as
2022 the default shortcut key. Case is ignored.
2023
2024 The optional {default} argument is the number of the choice
2025 that is made if the user hits <CR>. Use 1 to make the first
2026 choice the default one. Use 0 to not set a default. If
2027 {default} is omitted, 1 is used.
2028
2029 The optional {type} String argument gives the type of dialog.
2030 This is only used for the icon of the GTK, Mac, Motif and
2031 Win32 GUI. It can be one of these values: "Error",
2032 "Question", "Info", "Warning" or "Generic". Only the first
2033 character is relevant. When {type} is omitted, "Generic" is
2034 used.
2035
2036 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2037 or another valid interrupt key, confirm() returns 0.
2038
2039 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002040 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002041 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002042 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002043 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002044 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002045 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002046 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002047 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002048 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002049< In a GUI dialog, buttons are used. The layout of the buttons
2050 depends on the 'v' flag in 'guioptions'. If it is included,
2051 the buttons are always put vertically. Otherwise, confirm()
2052 tries to put the buttons in one horizontal line. If they
2053 don't fit, a vertical layout is used anyway. For some systems
2054 the horizontal layout is always used.
2055
2056 Can also be used as a |method|in: >
2057 BuildMessage()->confirm("&Yes\n&No")
2058<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002059 Return type: |Number|
2060
2061
2062copy({expr}) *copy()*
2063 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002064 different from using {expr} directly.
2065 When {expr} is a |List| a shallow copy is created. This means
2066 that the original |List| can be changed without changing the
2067 copy, and vice versa. But the items are identical, thus
2068 changing an item changes the contents of both |Lists|.
2069 A |Dictionary| is copied in a similar way as a |List|.
2070 Also see |deepcopy()|.
2071 Can also be used as a |method|: >
2072 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002073<
2074 Return type: any, depending on {expr}
2075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002076
2077cos({expr}) *cos()*
2078 Return the cosine of {expr}, measured in radians, as a |Float|.
2079 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002080 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002081 Examples: >
2082 :echo cos(100)
2083< 0.862319 >
2084 :echo cos(-4.01)
2085< -0.646043
2086
2087 Can also be used as a |method|: >
2088 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002089<
2090 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002091
2092
2093cosh({expr}) *cosh()*
2094 Return the hyperbolic cosine of {expr} as a |Float| in the range
2095 [1, inf].
2096 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002097 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002098 Examples: >
2099 :echo cosh(0.5)
2100< 1.127626 >
2101 :echo cosh(-0.5)
2102< -1.127626
2103
2104 Can also be used as a |method|: >
2105 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002106<
2107 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002108
2109
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002110count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002111 Return the number of times an item with value {expr} appears
2112 in |String|, |List| or |Dictionary| {comp}.
2113
2114 If {start} is given then start with the item with this index.
2115 {start} can only be used with a |List|.
2116
2117 When {ic} is given and it's |TRUE| then case is ignored.
2118
2119 When {comp} is a string then the number of not overlapping
2120 occurrences of {expr} is returned. Zero is returned when
2121 {expr} is an empty string.
2122
2123 Can also be used as a |method|: >
2124 mylist->count(val)
2125<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002126 Return type: |Number|
2127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002128 *cscope_connection()*
2129cscope_connection([{num} , {dbpath} [, {prepend}]])
2130 Checks for the existence of a |cscope| connection. If no
2131 parameters are specified, then the function returns:
2132 0, if cscope was not available (not compiled in), or
2133 if there are no cscope connections;
2134 1, if there is at least one cscope connection.
2135
2136 If parameters are specified, then the value of {num}
2137 determines how existence of a cscope connection is checked:
2138
2139 {num} Description of existence check
2140 ----- ------------------------------
2141 0 Same as no parameters (e.g., "cscope_connection()").
2142 1 Ignore {prepend}, and use partial string matches for
2143 {dbpath}.
2144 2 Ignore {prepend}, and use exact string matches for
2145 {dbpath}.
2146 3 Use {prepend}, use partial string matches for both
2147 {dbpath} and {prepend}.
2148 4 Use {prepend}, use exact string matches for both
2149 {dbpath} and {prepend}.
2150
2151 Note: All string comparisons are case sensitive!
2152
2153 Examples. Suppose we had the following (from ":cs show"): >
2154
2155 # pid database name prepend path
2156 0 27664 cscope.out /usr/local
2157<
2158 Invocation Return Val ~
2159 ---------- ---------- >
2160 cscope_connection() 1
2161 cscope_connection(1, "out") 1
2162 cscope_connection(2, "out") 0
2163 cscope_connection(3, "out") 0
2164 cscope_connection(3, "out", "local") 1
2165 cscope_connection(4, "out") 0
2166 cscope_connection(4, "out", "local") 0
2167 cscope_connection(4, "cscope.out", "/usr/local") 1
2168<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002169 Return type: |Number|
2170
2171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002172cursor({lnum}, {col} [, {off}]) *cursor()*
2173cursor({list})
2174 Positions the cursor at the column (byte count) {col} in the
2175 line {lnum}. The first column is one.
2176
2177 When there is one argument {list} this is used as a |List|
2178 with two, three or four item:
2179 [{lnum}, {col}]
2180 [{lnum}, {col}, {off}]
2181 [{lnum}, {col}, {off}, {curswant}]
2182 This is like the return value of |getpos()| or |getcurpos()|,
2183 but without the first item.
2184
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002185 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002186 |setcursorcharpos()|.
2187
2188 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002189 {lnum} is used like with |getline()|, except that if {lnum} is
2190 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002191 If {lnum} is greater than the number of lines in the buffer,
2192 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002193 If {col} is greater than the number of bytes in the line,
2194 the cursor will be positioned at the last character in the
2195 line.
2196 If {col} is zero, the cursor will stay in the current column.
2197 If {curswant} is given it is used to set the preferred column
2198 for vertical movement. Otherwise {col} is used.
2199
2200 When 'virtualedit' is used {off} specifies the offset in
2201 screen columns from the start of the character. E.g., a
2202 position within a <Tab> or after the last character.
2203 Returns 0 when the position could be set, -1 otherwise.
2204
2205 Can also be used as a |method|: >
2206 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002207<
2208 Return type: |Number|
2209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002210
2211debugbreak({pid}) *debugbreak()*
2212 Specifically used to interrupt a program being debugged. It
2213 will cause process {pid} to get a SIGTRAP. Behavior for other
2214 processes is undefined. See |terminal-debugger|.
2215 {only available on MS-Windows}
2216
Bram Moolenaar016188f2022-06-06 20:52:59 +01002217 Returns |TRUE| if successfully interrupted the program.
2218 Otherwise returns |FALSE|.
2219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002220 Can also be used as a |method|: >
2221 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002222<
2223 Return type: |Number|
2224
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002225
2226deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2227 Make a copy of {expr}. For Numbers and Strings this isn't
2228 different from using {expr} directly.
2229 When {expr} is a |List| a full copy is created. This means
2230 that the original |List| can be changed without changing the
2231 copy, and vice versa. When an item is a |List| or
2232 |Dictionary|, a copy for it is made, recursively. Thus
2233 changing an item in the copy does not change the contents of
2234 the original |List|.
2235 A |Dictionary| is copied in a similar way as a |List|.
2236
2237 When {noref} is omitted or zero a contained |List| or
2238 |Dictionary| is only copied once. All references point to
2239 this single copy. With {noref} set to 1 every occurrence of a
2240 |List| or |Dictionary| results in a new copy. This also means
2241 that a cyclic reference causes deepcopy() to fail.
2242 *E724*
2243 Nesting is possible up to 100 levels. When there is an item
2244 that refers back to a higher level making a deep copy with
2245 {noref} set to 1 will fail.
2246 Also see |copy()|.
2247
2248 Can also be used as a |method|: >
2249 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002250<
2251 Return type: any, depending on {expr}
2252
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002253
2254delete({fname} [, {flags}]) *delete()*
2255 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002256 name {fname}.
2257
2258 This also works when {fname} is a symbolic link. The symbolic
2259 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002260
2261 When {flags} is "d": Deletes the directory by the name
2262 {fname}. This fails when directory {fname} is not empty.
2263
2264 When {flags} is "rf": Deletes the directory by the name
2265 {fname} and everything in it, recursively. BE CAREFUL!
2266 Note: on MS-Windows it is not possible to delete a directory
2267 that is being used.
2268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002269 The result is a Number, which is 0/false if the delete
2270 operation was successful and -1/true when the deletion failed
2271 or partly failed.
2272
2273 Use |remove()| to delete an item from a |List|.
2274 To delete a line from the buffer use |:delete| or
2275 |deletebufline()|.
2276
2277 Can also be used as a |method|: >
2278 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002279<
2280 Return type: |Number|
2281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002282
2283deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2284 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2285 If {last} is omitted then delete line {first} only.
2286 On success 0 is returned, on failure 1 is returned.
2287
2288 This function works only for loaded buffers. First call
2289 |bufload()| if needed.
2290
2291 For the use of {buf}, see |bufname()| above.
2292
2293 {first} and {last} are used like with |getline()|. Note that
2294 when using |line()| this refers to the current buffer. Use "$"
2295 to refer to the last line in buffer {buf}.
2296
2297 Can also be used as a |method|: >
2298 GetBuffer()->deletebufline(1)
2299<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002300 Return type: |Number|
2301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002302 *did_filetype()*
2303did_filetype() Returns |TRUE| when autocommands are being executed and the
2304 FileType event has been triggered at least once. Can be used
2305 to avoid triggering the FileType event again in the scripts
2306 that detect the file type. |FileType|
2307 Returns |FALSE| when `:setf FALLBACK` was used.
2308 When editing another file, the counter is reset, thus this
2309 really checks if the FileType event has been triggered for the
2310 current buffer. This allows an autocommand that starts
2311 editing another buffer to set 'filetype' and load a syntax
2312 file.
2313
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002314 Return type: |Number|
2315
2316
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002317diff({fromlist}, {tolist} [, {options}]) *diff()*
2318 Returns a String or a List containing the diff between the
2319 strings in {fromlist} and {tolist}. Uses the Vim internal
2320 diff library to compute the diff.
2321
2322 *E106*
2323 The optional "output" item in {options} specifies the returned
2324 diff format. The following values are supported:
2325 indices Return a List of the starting and ending
2326 indices and a count of the strings in each
2327 diff hunk.
2328 unified Return the unified diff output as a String.
2329 This is the default.
2330
2331 If the "output" item in {options} is "indices", then a List is
2332 returned. Each List item contains a Dict with the following
2333 items for each diff hunk:
2334 from_idx start index in {fromlist} for this diff hunk.
2335 from_count number of strings in {fromlist} that are
2336 added/removed/modified in this diff hunk.
2337 to_idx start index in {tolist} for this diff hunk.
2338 to_count number of strings in {tolist} that are
2339 added/removed/modified in this diff hunk.
2340
2341 The {options} Dict argument also specifies diff options
2342 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002343 algorithm Dict specifying the diff algorithm to
2344 use. Supported boolean items are
2345 "myers", "minimal", "patience" and
2346 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002347 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002348 iblank ignore changes where lines are all
2349 blank.
2350 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002351 indent-heuristic use the indent heuristic for the
2352 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002353 iwhite ignore changes in amount of white
2354 space.
2355 iwhiteall ignore all white space changes.
2356 iwhiteeol ignore white space changes at end of
2357 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002358 For more information about these options, refer to 'diffopt'.
2359
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002360 To compute the unified diff, all the items in {fromlist} are
2361 concatenated into a string using a newline separator and the
2362 same for {tolist}. The unified diff output uses line numbers.
2363
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002364 Returns an empty List or String if {fromlist} and {tolist} are
2365 identical.
2366
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002367 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002368 :echo diff(['abc'], ['xxx'])
2369 @@ -1 +1 @@
2370 -abc
2371 +xxx
2372
2373 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2374 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2375 :echo diff(readfile('oldfile'), readfile('newfile'))
2376 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002377<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002378 For more examples, refer to |diff-func-examples|
2379
2380 Can also be used as a |method|: >
2381 GetFromList->diff(to_list)
2382<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002383 Return type: |String| or list<dict<number>> or list<any>
2384 depending on {options}
2385
2386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002387diff_filler({lnum}) *diff_filler()*
2388 Returns the number of filler lines above line {lnum}.
2389 These are the lines that were inserted at this point in
2390 another diff'ed window. These filler lines are shown in the
2391 display but don't exist in the buffer.
2392 {lnum} is used like with |getline()|. Thus "." is the current
2393 line, "'m" mark m, etc.
2394 Returns 0 if the current window is not in diff mode.
2395
2396 Can also be used as a |method|: >
2397 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002398<
2399 Return type: |Number|
2400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002401
2402diff_hlID({lnum}, {col}) *diff_hlID()*
2403 Returns the highlight ID for diff mode at line {lnum} column
2404 {col} (byte index). When the current line does not have a
2405 diff change zero is returned.
2406 {lnum} is used like with |getline()|. Thus "." is the current
2407 line, "'m" mark m, etc.
2408 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2409 line.
2410 The highlight ID can be used with |synIDattr()| to obtain
2411 syntax information about the highlighting.
2412
2413 Can also be used as a |method|: >
2414 GetLnum()->diff_hlID(col)
2415<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002416 Return type: |Number|
2417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002418
2419digraph_get({chars}) *digraph_get()* *E1214*
2420 Return the digraph of {chars}. This should be a string with
2421 exactly two characters. If {chars} are not just two
2422 characters, or the digraph of {chars} does not exist, an error
2423 is given and an empty string is returned.
2424
2425 The character will be converted from Unicode to 'encoding'
2426 when needed. This does require the conversion to be
2427 available, it might fail.
2428
2429 Also see |digraph_getlist()|.
2430
2431 Examples: >
2432 " Get a built-in digraph
2433 :echo digraph_get('00') " Returns '∞'
2434
2435 " Get a user-defined digraph
2436 :call digraph_set('aa', 'あ')
2437 :echo digraph_get('aa') " Returns 'あ'
2438<
2439 Can also be used as a |method|: >
2440 GetChars()->digraph_get()
2441<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002442 Return type: |String|
2443
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002444 This function works only when compiled with the |+digraphs|
2445 feature. If this feature is disabled, this function will
2446 display an error message.
2447
2448
2449digraph_getlist([{listall}]) *digraph_getlist()*
2450 Return a list of digraphs. If the {listall} argument is given
2451 and it is TRUE, return all digraphs, including the default
2452 digraphs. Otherwise, return only user-defined digraphs.
2453
2454 The characters will be converted from Unicode to 'encoding'
2455 when needed. This does require the conservation to be
2456 available, it might fail.
2457
2458 Also see |digraph_get()|.
2459
2460 Examples: >
2461 " Get user-defined digraphs
2462 :echo digraph_getlist()
2463
2464 " Get all the digraphs, including default digraphs
2465 :echo digraph_getlist(1)
2466<
2467 Can also be used as a |method|: >
2468 GetNumber()->digraph_getlist()
2469<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002470 Return type: list<list<string>>
2471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002472 This function works only when compiled with the |+digraphs|
2473 feature. If this feature is disabled, this function will
2474 display an error message.
2475
2476
Bram Moolenaara2baa732022-02-04 16:09:54 +00002477digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002478 Add digraph {chars} to the list. {chars} must be a string
2479 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002480 encoded character. *E1215*
2481 Be careful, composing characters are NOT ignored. This
2482 function is similar to |:digraphs| command, but useful to add
2483 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002484
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002485 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002486 this fails an error message is given and v:false is returned.
2487
2488 If you want to define multiple digraphs at once, you can use
2489 |digraph_setlist()|.
2490
2491 Example: >
2492 call digraph_set(' ', 'あ')
2493<
2494 Can be used as a |method|: >
2495 GetString()->digraph_set('あ')
2496<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002497 Return type: |vim9-boolean|
2498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002499 This function works only when compiled with the |+digraphs|
2500 feature. If this feature is disabled, this function will
2501 display an error message.
2502
2503
2504digraph_setlist({digraphlist}) *digraph_setlist()*
2505 Similar to |digraph_set()| but this function can add multiple
2506 digraphs at once. {digraphlist} is a list composed of lists,
2507 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002508 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002509 Example: >
2510 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2511<
2512 It is similar to the following: >
2513 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2514 call digraph_set(chars, digraph)
2515 endfor
2516< Except that the function returns after the first error,
2517 following digraphs will not be added.
2518
2519 Can be used as a |method|: >
2520 GetList()->digraph_setlist()
2521<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002522 Return type: |vim9-boolean|
2523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002524 This function works only when compiled with the |+digraphs|
2525 feature. If this feature is disabled, this function will
2526 display an error message.
2527
2528
2529echoraw({string}) *echoraw()*
2530 Output {string} as-is, including unprintable characters.
2531 This can be used to output a terminal code. For example, to
2532 disable modifyOtherKeys: >
2533 call echoraw(&t_TE)
2534< and to enable it again: >
2535 call echoraw(&t_TI)
2536< Use with care, you can mess up the terminal this way.
2537
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002538 Return type: |Number|
2539
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002540
2541empty({expr}) *empty()*
2542 Return the Number 1 if {expr} is empty, zero otherwise.
2543 - A |List| or |Dictionary| is empty when it does not have any
2544 items.
2545 - A |String| is empty when its length is zero.
2546 - A |Number| and |Float| are empty when their value is zero.
2547 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2548 - A |Job| is empty when it failed to start.
2549 - A |Channel| is empty when it is closed.
2550 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002551 - An |Object| is empty, when the empty() method in the object
2552 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002553
2554 For a long |List| this is much faster than comparing the
2555 length with zero.
2556
2557 Can also be used as a |method|: >
2558 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002559<
2560 Return type: |Number|
2561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002562
2563environ() *environ()*
2564 Return all of environment variables as dictionary. You can
2565 check if an environment variable exists like this: >
2566 :echo has_key(environ(), 'HOME')
2567< Note that the variable name may be CamelCase; to ignore case
2568 use this: >
2569 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002570<
2571 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002572
Bram Moolenaar416bd912023-07-07 23:19:18 +01002573
2574err_teapot([{expr}]) *err_teapot()*
2575 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002576 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002577 If {expr} is present and it is TRUE error 503 is given,
2578 indicating that coffee is temporarily not available.
2579 If {expr} is present it must be a String.
2580
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002581 Return type: |Number|
2582
Bram Moolenaar416bd912023-07-07 23:19:18 +01002583
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002584escape({string}, {chars}) *escape()*
2585 Escape the characters in {chars} that occur in {string} with a
2586 backslash. Example: >
2587 :echo escape('c:\program files\vim', ' \')
2588< results in: >
2589 c:\\program\ files\\vim
2590< Also see |shellescape()| and |fnameescape()|.
2591
2592 Can also be used as a |method|: >
2593 GetText()->escape(' \')
2594<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002595 Return type: |String|
2596
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002597 *eval()*
2598eval({string}) Evaluate {string} and return the result. Especially useful to
2599 turn the result of |string()| back into the original value.
2600 This works for Numbers, Floats, Strings, Blobs and composites
2601 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002602 functions. In |Vim9| script, it can be used to obtain |enum|
2603 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002604
2605 Can also be used as a |method|: >
2606 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002607<
2608 Return type: any, depending on {string}
2609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002610
2611eventhandler() *eventhandler()*
2612 Returns 1 when inside an event handler. That is that Vim got
2613 interrupted while waiting for the user to type a character,
2614 e.g., when dropping a file on Vim. This means interactive
2615 commands cannot be used. Otherwise zero is returned.
2616
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002617 Return type: |Number|
2618
2619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002620executable({expr}) *executable()*
2621 This function checks if an executable with the name {expr}
2622 exists. {expr} must be the name of the program without any
2623 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002625 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002626 searchpath for programs.
2627 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002628 On MS-Windows the ".exe", ".bat", etc. can optionally be
2629 included. Then the extensions in $PATHEXT are tried. Thus if
2630 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2631 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2632 by itself can be used in $PATHEXT to try using the name
2633 without an extension. When 'shell' looks like a Unix shell,
2634 then the name is also tried without adding an extension.
2635 On MS-Windows it only checks if the file exists and is not a
2636 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002637 On MS-Windows an executable in the same directory as the Vim
2638 executable is always found. Since this directory is added to
2639 $PATH it should also work to execute it |win32-PATH|.
2640 *NoDefaultCurrentDirectoryInExePath*
2641 On MS-Windows an executable in Vim's current working directory
2642 is also normally found, but this can be disabled by setting
2643 the $NoDefaultCurrentDirectoryInExePath environment variable.
2644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002645 The result is a Number:
2646 1 exists
2647 0 does not exist
2648 -1 not implemented on this system
2649 |exepath()| can be used to get the full path of an executable.
2650
2651 Can also be used as a |method|: >
2652 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002653<
2654 Return type: |Number|
2655
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002656
2657execute({command} [, {silent}]) *execute()*
2658 Execute an Ex command or commands and return the output as a
2659 string.
2660 {command} can be a string or a List. In case of a List the
2661 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002662 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002663 redir => var
2664 {command}
2665 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002666< Except that line continuation in {command} is not recognized.
2667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002668 The optional {silent} argument can have these values:
2669 "" no `:silent` used
2670 "silent" `:silent` used
2671 "silent!" `:silent!` used
2672 The default is "silent". Note that with "silent!", unlike
2673 `:redir`, error messages are dropped. When using an external
2674 command the screen may be messed up, use `system()` instead.
2675 *E930*
2676 It is not possible to use `:redir` anywhere in {command}.
2677
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002678 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002679 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002680
2681< To execute a command in another window than the current one
2682 use `win_execute()`.
2683
2684 When used recursively the output of the recursive call is not
2685 included in the output of the higher level call.
2686
2687 Can also be used as a |method|: >
2688 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002689<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002690 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002691
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002692
2693exepath({expr}) *exepath()*
2694 If {expr} is an executable and is either an absolute path, a
2695 relative path or found in $PATH, return the full path.
2696 Note that the current directory is used when {expr} starts
2697 with "./", which may be a problem for Vim: >
2698 echo exepath(v:progpath)
2699< If {expr} cannot be found in $PATH or is not executable then
2700 an empty string is returned.
2701
2702 Can also be used as a |method|: >
2703 GetCommand()->exepath()
2704<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002705 Return type: |String|
2706
2707
2708exists({expr}) *exists()*
2709 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002710 zero otherwise.
2711
2712 Note: In a compiled |:def| function the evaluation is done at
2713 runtime. Use `exists_compiled()` to evaluate the expression
2714 at compile time.
2715
2716 For checking for a supported feature use |has()|.
2717 For checking if a file exists use |filereadable()|.
2718
2719 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002720 varname internal variable (see
2721 dict.key |internal-variables|). Also works
2722 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002723 import.Func entries, |List| items, class and
2724 class.Func object methods, imported items, etc.
2725 object.Func Does not work for local variables in a
2726 class.varname compiled `:def` function.
2727 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002728 script, since it can be used as a
2729 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002730 Beware that evaluating an index may
2731 cause an error message for an invalid
2732 expression. E.g.: >
2733 :let l = [1, 2, 3]
2734 :echo exists("l[5]")
2735< 0 >
2736 :echo exists("l[xx]")
2737< E121: Undefined variable: xx
2738 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002739 &option-name Vim option (only checks if it exists,
2740 not if it really works)
2741 +option-name Vim option that works.
2742 $ENVNAME environment variable (could also be
2743 done by comparing with an empty
2744 string)
2745 *funcname built-in function (see |functions|)
2746 or user defined function (see
2747 |user-functions|) that is implemented.
2748 Also works for a variable that is a
2749 Funcref.
2750 ?funcname built-in function that could be
2751 implemented; to be used to check if
2752 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002753 :cmdname Ex command: built-in command, user
2754 command or command modifier |:command|.
2755 Returns:
2756 1 for match with start of a command
2757 2 full match with a command
2758 3 matches several user commands
2759 To check for a supported command
2760 always check the return value to be 2.
2761 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002762 :3match The |:3match| command (but you
2763 probably should not use it, it is
2764 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002765 #event autocommand defined for this event
2766 #event#pattern autocommand defined for this event and
2767 pattern (the pattern is taken
2768 literally and compared to the
2769 autocommand patterns character by
2770 character)
2771 #group autocommand group exists
2772 #group#event autocommand defined for this group and
2773 event.
2774 #group#event#pattern
2775 autocommand defined for this group,
2776 event and pattern.
2777 ##event autocommand for this event is
2778 supported.
2779
2780 Examples: >
2781 exists("&shortname")
2782 exists("$HOSTNAME")
2783 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002784 exists("*s:MyFunc") " only for legacy script
2785 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002786 exists("bufcount")
2787 exists(":Make")
2788 exists("#CursorHold")
2789 exists("#BufReadPre#*.gz")
2790 exists("#filetypeindent")
2791 exists("#filetypeindent#FileType")
2792 exists("#filetypeindent#FileType#*")
2793 exists("##ColorScheme")
2794< There must be no space between the symbol (&/$/*/#) and the
2795 name.
2796 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002797 a few cases this is ignored. That may become stricter in the
2798 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002799 Working example: >
2800 exists(":make")
2801< NOT working example: >
2802 exists(":make install")
2803
2804< Note that the argument must be a string, not the name of the
2805 variable itself. For example: >
2806 exists(bufcount)
2807< This doesn't check for existence of the "bufcount" variable,
2808 but gets the value of "bufcount", and checks if that exists.
2809
2810 Can also be used as a |method|: >
2811 Varname()->exists()
2812<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002813 Return type: |String|
2814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002815
2816exists_compiled({expr}) *exists_compiled()*
2817 Like `exists()` but evaluated at compile time. This is useful
2818 to skip a block where a function is used that would otherwise
2819 give an error: >
2820 if exists_compiled('*ThatFunction')
2821 ThatFunction('works')
2822 endif
2823< If `exists()` were used then a compilation error would be
2824 given if ThatFunction() is not defined.
2825
2826 {expr} must be a literal string. *E1232*
2827 Can only be used in a |:def| function. *E1233*
2828 This does not work to check for arguments or local variables.
2829
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002830 Return type: |String|
2831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002832
2833exp({expr}) *exp()*
2834 Return the exponential of {expr} as a |Float| in the range
2835 [0, inf].
2836 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002837 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002838 Examples: >
2839 :echo exp(2)
2840< 7.389056 >
2841 :echo exp(-1)
2842< 0.367879
2843
2844 Can also be used as a |method|: >
2845 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002846<
2847 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002848
2849
2850expand({string} [, {nosuf} [, {list}]]) *expand()*
2851 Expand wildcards and the following special keywords in
2852 {string}. 'wildignorecase' applies.
2853
2854 If {list} is given and it is |TRUE|, a List will be returned.
2855 Otherwise the result is a String and when there are several
2856 matches, they are separated by <NL> characters. [Note: in
2857 version 5.0 a space was used, which caused problems when a
2858 file name contains a space]
2859
2860 If the expansion fails, the result is an empty string. A name
2861 for a non-existing file is not included, unless {string} does
2862 not start with '%', '#' or '<', see below.
2863
Christian Brabandtec9c3262024-02-21 20:40:05 +01002864 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002865 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002867 When {string} starts with '%', '#' or '<', the expansion is
2868 done like for the |cmdline-special| variables with their
2869 associated modifiers. Here is a short overview:
2870
2871 % current file name
2872 # alternate file name
2873 #n alternate file name n
2874 <cfile> file name under the cursor
2875 <afile> autocmd file name
2876 <abuf> autocmd buffer number (as a String!)
2877 <amatch> autocmd matched name
2878 <cexpr> C expression under the cursor
2879 <sfile> sourced script file or function name
2880 <slnum> sourced script line number or function
2881 line number
2882 <sflnum> script file line number, also when in
2883 a function
2884 <SID> "<SNR>123_" where "123" is the
2885 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002886 <script> sourced script file, or script file
2887 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002888 <stack> call stack
2889 <cword> word under the cursor
2890 <cWORD> WORD under the cursor
2891 <client> the {clientid} of the last received
2892 message |server2client()|
2893 Modifiers:
2894 :p expand to full path
2895 :h head (last path component removed)
2896 :t tail (last path component only)
2897 :r root (one extension removed)
2898 :e extension only
2899
2900 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002901 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002902< Note that when expanding a string that starts with '%', '#' or
2903 '<', any following text is ignored. This does NOT work: >
2904 :let doesntwork = expand("%:h.bak")
2905< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002906 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002907< Also note that expanding "<cfile>" and others only returns the
2908 referenced file name without further expansion. If "<cfile>"
2909 is "~/.cshrc", you need to do another expand() to have the
2910 "~/" expanded into the path of the home directory: >
2911 :echo expand(expand("<cfile>"))
2912<
2913 There cannot be white space between the variables and the
2914 following modifier. The |fnamemodify()| function can be used
2915 to modify normal file names.
2916
2917 When using '%' or '#', and the current or alternate file name
2918 is not defined, an empty string is used. Using "%:p" in a
2919 buffer with no name, results in the current directory, with a
2920 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002921 When 'verbose' is set then expanding '%', '#' and <> items
2922 will result in an error message if the argument cannot be
2923 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002924
2925 When {string} does not start with '%', '#' or '<', it is
2926 expanded like a file name is expanded on the command line.
2927 'suffixes' and 'wildignore' are used, unless the optional
2928 {nosuf} argument is given and it is |TRUE|.
2929 Names for non-existing files are included. The "**" item can
2930 be used to search in a directory tree. For example, to find
2931 all "README" files in the current directory and below: >
2932 :echo expand("**/README")
2933<
2934 expand() can also be used to expand variables and environment
2935 variables that are only known in a shell. But this can be
2936 slow, because a shell may be used to do the expansion. See
2937 |expr-env-expand|.
2938 The expanded variable is still handled like a list of file
2939 names. When an environment variable cannot be expanded, it is
2940 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2941 "$FOOBAR".
2942
2943 See |glob()| for finding existing files. See |system()| for
2944 getting the raw output of an external command.
2945
2946 Can also be used as a |method|: >
2947 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002948<
2949 Return type: |String| or list<string> depending on {list}
2950
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002951
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002952expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002953 Expand special items in String {string} like what is done for
2954 an Ex command such as `:edit`. This expands special keywords,
2955 like with |expand()|, and environment variables, anywhere in
2956 {string}. "~user" and "~/path" are only expanded at the
2957 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002958
2959 The following items are supported in the {options} Dict
2960 argument:
2961 errmsg If set to TRUE, error messages are displayed
2962 if an error is encountered during expansion.
2963 By default, error messages are not displayed.
2964
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002965 Returns the expanded string. If an error is encountered
2966 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002967
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002968 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002969 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002970 make /path/runtime/doc/builtin.o
2971 :echo expandcmd('make %<.o', {'errmsg': v:true})
2972<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002973 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002974 GetCommand()->expandcmd()
2975<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002976 Return type: |String| or list<string> depending on {list}
2977
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002978extend({expr1}, {expr2} [, {expr3}]) *extend()*
2979 {expr1} and {expr2} must be both |Lists| or both
2980 |Dictionaries|.
2981
2982 If they are |Lists|: Append {expr2} to {expr1}.
2983 If {expr3} is given insert the items of {expr2} before the
2984 item with index {expr3} in {expr1}. When {expr3} is zero
2985 insert before the first item. When {expr3} is equal to
2986 len({expr1}) then {expr2} is appended.
2987 Examples: >
2988 :echo sort(extend(mylist, [7, 5]))
2989 :call extend(mylist, [2, 3], 1)
2990< When {expr1} is the same List as {expr2} then the number of
2991 items copied is equal to the original length of the List.
2992 E.g., when {expr3} is 1 you get N new copies of the first item
2993 (where N is the original length of the List).
2994 Use |add()| to concatenate one item to a list. To concatenate
2995 two lists into a new list use the + operator: >
2996 :let newlist = [1, 2, 3] + [4, 5]
2997<
2998 If they are |Dictionaries|:
2999 Add all entries from {expr2} to {expr1}.
3000 If a key exists in both {expr1} and {expr2} then {expr3} is
3001 used to decide what to do:
3002 {expr3} = "keep": keep the value of {expr1}
3003 {expr3} = "force": use the value of {expr2}
3004 {expr3} = "error": give an error message *E737*
3005 When {expr3} is omitted then "force" is assumed.
3006
3007 {expr1} is changed when {expr2} is not empty. If necessary
3008 make a copy of {expr1} first.
3009 {expr2} remains unchanged.
3010 When {expr1} is locked and {expr2} is not empty the operation
3011 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003012 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003013
3014 Can also be used as a |method|: >
3015 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003016<
3017 Return type: list<{type}> or dict<{type}> depending on {expr1}
3018 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003019
3020
3021extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3022 Like |extend()| but instead of adding items to {expr1} a new
3023 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003024 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003025
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003026 Return type: list<{type}> or dict<{type}> depending on {expr1}
3027 and {expr2}, in case of error: |Number|
3028
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003029
3030feedkeys({string} [, {mode}]) *feedkeys()*
3031 Characters in {string} are queued for processing as if they
3032 come from a mapping or were typed by the user.
3033
3034 By default the string is added to the end of the typeahead
3035 buffer, thus if a mapping is still being executed the
3036 characters come after them. Use the 'i' flag to insert before
3037 other characters, they will be executed next, before any
3038 characters from a mapping.
3039
3040 The function does not wait for processing of keys contained in
3041 {string}.
3042
3043 To include special keys into {string}, use double-quotes
3044 and "\..." notation |expr-quote|. For example,
3045 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3046 feedkeys('\<CR>') pushes 5 characters.
3047 A special code that might be useful is <Ignore>, it exits the
3048 wait for a character without doing anything. *<Ignore>*
3049
3050 {mode} is a String, which can contain these character flags:
3051 'm' Remap keys. This is default. If {mode} is absent,
3052 keys are remapped.
3053 'n' Do not remap keys.
3054 't' Handle keys as if typed; otherwise they are handled as
3055 if coming from a mapping. This matters for undo,
3056 opening folds, etc.
3057 'L' Lowlevel input. Only works for Unix or when using the
3058 GUI. Keys are used as if they were coming from the
3059 terminal. Other flags are not used. *E980*
3060 When a CTRL-C interrupts and 't' is included it sets
3061 the internal "got_int" flag.
3062 'i' Insert the string instead of appending (see above).
3063 'x' Execute commands until typeahead is empty. This is
3064 similar to using ":normal!". You can call feedkeys()
3065 several times without 'x' and then one time with 'x'
3066 (possibly with an empty {string}) to execute all the
3067 typeahead. Note that when Vim ends in Insert mode it
3068 will behave as if <Esc> is typed, to avoid getting
3069 stuck, waiting for a character to be typed before the
3070 script continues.
3071 Note that if you manage to call feedkeys() while
3072 executing commands, thus calling it recursively, then
3073 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003074 'c' Remove any script context when executing, so that
3075 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003076 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003077 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003078 '!' When used with 'x' will not end Insert mode. Can be
3079 used in a test when a timer is set to exit Insert mode
3080 a little later. Useful for testing CursorHoldI.
3081
3082 Return value is always 0.
3083
3084 Can also be used as a |method|: >
3085 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003086<
3087 Return type: |String| or list<string> depending on {list}
3088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003089
Shougo Matsushita60c87432024-06-03 22:59:27 +02003090filecopy({from}, {to}) *filecopy()*
3091 Copy the file pointed to by the name {from} to {to}. The
3092 result is a Number, which is |TRUE| if the file was copied
3093 successfully, and |FALSE| when it failed.
3094 If a file with name {to} already exists, it will fail.
3095 Note that it does not handle directories (yet).
3096
3097 This function is not available in the |sandbox|.
3098
3099 Can also be used as a |method|: >
3100 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003101<
3102 Return type: |Number|
3103
Shougo Matsushita60c87432024-06-03 22:59:27 +02003104
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003105filereadable({file}) *filereadable()*
3106 The result is a Number, which is |TRUE| when a file with the
3107 name {file} exists, and can be read. If {file} doesn't exist,
3108 or is a directory, the result is |FALSE|. {file} is any
3109 expression, which is used as a String.
3110 If you don't care about the file being readable you can use
3111 |glob()|.
3112 {file} is used as-is, you may want to expand wildcards first: >
3113 echo filereadable('~/.vimrc')
3114 0
3115 echo filereadable(expand('~/.vimrc'))
3116 1
3117
3118< Can also be used as a |method|: >
3119 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003120<
3121 Return type: |Number|
3122
3123 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003124 Obsolete name: file_readable().
3125
3126
3127filewritable({file}) *filewritable()*
3128 The result is a Number, which is 1 when a file with the
3129 name {file} exists, and can be written. If {file} doesn't
3130 exist, or is not writable, the result is 0. If {file} is a
3131 directory, and we can write to it, the result is 2.
3132
3133 Can also be used as a |method|: >
3134 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003135<
3136 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003137
3138
3139filter({expr1}, {expr2}) *filter()*
3140 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3141 For each item in {expr1} evaluate {expr2} and when the result
3142 is zero or false remove the item from the |List| or
3143 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003144 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003145
3146 {expr2} must be a |string| or |Funcref|.
3147
3148 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3149 of the current item. For a |Dictionary| |v:key| has the key
3150 of the current item and for a |List| |v:key| has the index of
3151 the current item. For a |Blob| |v:key| has the index of the
3152 current byte. For a |String| |v:key| has the index of the
3153 current character.
3154 Examples: >
3155 call filter(mylist, 'v:val !~ "OLD"')
3156< Removes the items where "OLD" appears. >
3157 call filter(mydict, 'v:key >= 8')
3158< Removes the items with a key below 8. >
3159 call filter(var, 0)
3160< Removes all the items, thus clears the |List| or |Dictionary|.
3161
3162 Note that {expr2} is the result of expression and is then
3163 used as an expression again. Often it is good to use a
3164 |literal-string| to avoid having to double backslashes.
3165
3166 If {expr2} is a |Funcref| it must take two arguments:
3167 1. the key or the index of the current item.
3168 2. the value of the current item.
3169 The function must return |TRUE| if the item should be kept.
3170 Example that keeps the odd items of a list: >
3171 func Odd(idx, val)
3172 return a:idx % 2 == 1
3173 endfunc
3174 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003175< It is shorter when using a |lambda|. In |Vim9| syntax: >
3176 call filter(myList, (idx, val) => idx * val <= 42)
3177< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003178 call filter(myList, {idx, val -> idx * val <= 42})
3179< If you do not use "val" you can leave it out: >
3180 call filter(myList, {idx -> idx % 2 == 1})
3181<
3182 In |Vim9| script the result must be true, false, zero or one.
3183 Other values will result in a type error.
3184
3185 For a |List| and a |Dictionary| the operation is done
3186 in-place. If you want it to remain unmodified make a copy
3187 first: >
3188 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3189
3190< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003191 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003192 When an error is encountered while evaluating {expr2} no
3193 further items in {expr1} are processed.
3194 When {expr2} is a Funcref errors inside a function are ignored,
3195 unless it was defined with the "abort" flag.
3196
3197 Can also be used as a |method|: >
3198 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003199<
3200 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3201 depending on {expr1}
3202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003203
3204finddir({name} [, {path} [, {count}]]) *finddir()*
3205 Find directory {name} in {path}. Supports both downwards and
3206 upwards recursive directory searches. See |file-searching|
3207 for the syntax of {path}.
3208
3209 Returns the path of the first found match. When the found
3210 directory is below the current directory a relative path is
3211 returned. Otherwise a full path is returned.
3212 If {path} is omitted or empty then 'path' is used.
3213
3214 If the optional {count} is given, find {count}'s occurrence of
3215 {name} in {path} instead of the first one.
3216 When {count} is negative return all the matches in a |List|.
3217
Bram Moolenaar016188f2022-06-06 20:52:59 +01003218 Returns an empty string if the directory is not found.
3219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003220 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003221
3222 Can also be used as a |method|: >
3223 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003224<
3225 Return type: |String|
3226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003227
3228findfile({name} [, {path} [, {count}]]) *findfile()*
3229 Just like |finddir()|, but find a file instead of a directory.
3230 Uses 'suffixesadd'.
3231 Example: >
3232 :echo findfile("tags.vim", ".;")
3233< Searches from the directory of the current file upwards until
3234 it finds the file "tags.vim".
3235
3236 Can also be used as a |method|: >
3237 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003238<
3239 Return type: |String|
3240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003241
3242flatten({list} [, {maxdepth}]) *flatten()*
3243 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3244 the result is a |List| without nesting, as if {maxdepth} is
3245 a very large number.
3246 The {list} is changed in place, use |flattennew()| if you do
3247 not want that.
3248 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003249 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003250 *E900*
3251 {maxdepth} means how deep in nested lists changes are made.
3252 {list} is not modified when {maxdepth} is 0.
3253 {maxdepth} must be positive number.
3254
3255 If there is an error the number zero is returned.
3256
3257 Example: >
3258 :echo flatten([1, [2, [3, 4]], 5])
3259< [1, 2, 3, 4, 5] >
3260 :echo flatten([1, [2, [3, 4]], 5], 1)
3261< [1, 2, [3, 4], 5]
3262
3263 Can also be used as a |method|: >
3264 mylist->flatten()
3265<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003266 Return type: list<{type}>
3267
3268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003269flattennew({list} [, {maxdepth}]) *flattennew()*
3270 Like |flatten()| but first make a copy of {list}.
3271
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003272 Return type: list<{type}>
3273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003274
3275float2nr({expr}) *float2nr()*
3276 Convert {expr} to a Number by omitting the part after the
3277 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003278 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003279 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003280 When the value of {expr} is out of range for a |Number| the
3281 result is truncated to 0x7fffffff or -0x7fffffff (or when
3282 64-bit Number support is enabled, 0x7fffffffffffffff or
3283 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3284 64-bit Number support is enabled, -0x8000000000000000).
3285 Examples: >
3286 echo float2nr(3.95)
3287< 3 >
3288 echo float2nr(-23.45)
3289< -23 >
3290 echo float2nr(1.0e100)
3291< 2147483647 (or 9223372036854775807) >
3292 echo float2nr(-1.0e150)
3293< -2147483647 (or -9223372036854775807) >
3294 echo float2nr(1.0e-100)
3295< 0
3296
3297 Can also be used as a |method|: >
3298 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003299<
3300 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003301
3302
3303floor({expr}) *floor()*
3304 Return the largest integral value less than or equal to
3305 {expr} as a |Float| (round down).
3306 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003307 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003308 Examples: >
3309 echo floor(1.856)
3310< 1.0 >
3311 echo floor(-5.456)
3312< -6.0 >
3313 echo floor(4.0)
3314< 4.0
3315
3316 Can also be used as a |method|: >
3317 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003318<
3319 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003320
3321
3322fmod({expr1}, {expr2}) *fmod()*
3323 Return the remainder of {expr1} / {expr2}, even if the
3324 division is not representable. Returns {expr1} - i * {expr2}
3325 for some integer i such that if {expr2} is non-zero, the
3326 result has the same sign as {expr1} and magnitude less than
3327 the magnitude of {expr2}. If {expr2} is zero, the value
3328 returned is zero. The value returned is a |Float|.
3329 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003330 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3331 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003332 Examples: >
3333 :echo fmod(12.33, 1.22)
3334< 0.13 >
3335 :echo fmod(-12.33, 1.22)
3336< -0.13
3337
3338 Can also be used as a |method|: >
3339 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003340<
3341 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003342
3343
3344fnameescape({string}) *fnameescape()*
3345 Escape {string} for use as file name command argument. All
3346 characters that have a special meaning, such as '%' and '|'
3347 are escaped with a backslash.
3348 For most systems the characters escaped are
3349 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3350 appears in a filename, it depends on the value of 'isfname'.
3351 A leading '+' and '>' is also escaped (special after |:edit|
3352 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003353 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003354 Example: >
3355 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003356 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003357< results in executing: >
3358 edit \+some\ str\%nge\|name
3359<
3360 Can also be used as a |method|: >
3361 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003362<
3363 Return type: |String|
3364
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003365
3366fnamemodify({fname}, {mods}) *fnamemodify()*
3367 Modify file name {fname} according to {mods}. {mods} is a
3368 string of characters like it is used for file names on the
3369 command line. See |filename-modifiers|.
3370 Example: >
3371 :echo fnamemodify("main.c", ":p:h")
3372< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003373 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003374< If {mods} is empty or an unsupported modifier is used then
3375 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003376 When {fname} is empty then with {mods} ":h" returns ".", so
3377 that `:cd` can be used with it. This is different from
3378 expand('%:h') without a buffer name, which returns an empty
3379 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003380 Note: Environment variables don't work in {fname}, use
3381 |expand()| first then.
3382
3383 Can also be used as a |method|: >
3384 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003385<
3386 Return type: |String|
3387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003388
3389foldclosed({lnum}) *foldclosed()*
3390 The result is a Number. If the line {lnum} is in a closed
3391 fold, the result is the number of the first line in that fold.
3392 If the line {lnum} is not in a closed fold, -1 is returned.
3393 {lnum} is used like with |getline()|. Thus "." is the current
3394 line, "'m" mark m, etc.
3395
3396 Can also be used as a |method|: >
3397 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003398<
3399 Return type: |Number|
3400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003401
3402foldclosedend({lnum}) *foldclosedend()*
3403 The result is a Number. If the line {lnum} is in a closed
3404 fold, the result is the number of the last line in that fold.
3405 If the line {lnum} is not in a closed fold, -1 is returned.
3406 {lnum} is used like with |getline()|. Thus "." is the current
3407 line, "'m" mark m, etc.
3408
3409 Can also be used as a |method|: >
3410 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003411<
3412 Return type: |Number|
3413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003414
3415foldlevel({lnum}) *foldlevel()*
3416 The result is a Number, which is the foldlevel of line {lnum}
3417 in the current buffer. For nested folds the deepest level is
3418 returned. If there is no fold at line {lnum}, zero is
3419 returned. It doesn't matter if the folds are open or closed.
3420 When used while updating folds (from 'foldexpr') -1 is
3421 returned for lines where folds are still to be updated and the
3422 foldlevel is unknown. As a special case the level of the
3423 previous line is usually available.
3424 {lnum} is used like with |getline()|. Thus "." is the current
3425 line, "'m" mark m, etc.
3426
3427 Can also be used as a |method|: >
3428 GetLnum()->foldlevel()
3429<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003430 Return type: |Number|
3431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003432 *foldtext()*
3433foldtext() Returns a String, to be displayed for a closed fold. This is
3434 the default function used for the 'foldtext' option and should
3435 only be called from evaluating 'foldtext'. It uses the
3436 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3437 The returned string looks like this: >
3438 +-- 45 lines: abcdef
3439< The number of leading dashes depends on the foldlevel. The
3440 "45" is the number of lines in the fold. "abcdef" is the text
3441 in the first non-blank line of the fold. Leading white space,
3442 "//" or "/*" and the text from the 'foldmarker' and
3443 'commentstring' options is removed.
3444 When used to draw the actual foldtext, the rest of the line
3445 will be filled with the fold char from the 'fillchars'
3446 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003447 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003448
3449 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003450 {not available when compiled without the |+folding| feature}
3451
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003453foldtextresult({lnum}) *foldtextresult()*
3454 Returns the text that is displayed for the closed fold at line
3455 {lnum}. Evaluates 'foldtext' in the appropriate context.
3456 When there is no closed fold at {lnum} an empty string is
3457 returned.
3458 {lnum} is used like with |getline()|. Thus "." is the current
3459 line, "'m" mark m, etc.
3460 Useful when exporting folded text, e.g., to HTML.
3461 {not available when compiled without the |+folding| feature}
3462
3463
3464 Can also be used as a |method|: >
3465 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003466<
3467 Return type: |String|
3468
Ernie Raele79e2072024-01-13 11:47:33 +01003469
3470foreach({expr1}, {expr2}) *foreach()*
3471 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3472 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003473 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003474 See |map()| and |filter()| to modify {expr1}.
3475
3476 {expr2} must be a |string| or |Funcref|.
3477
3478 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3479 of the current item. For a |Dictionary| |v:key| has the key
3480 of the current item and for a |List| |v:key| has the index of
3481 the current item. For a |Blob| |v:key| has the index of the
3482 current byte. For a |String| |v:key| has the index of the
3483 current character.
3484 Examples: >
3485 call foreach(mylist, 'used[v:val] = true')
3486< This records the items that are in the {expr1} list.
3487
3488 Note that {expr2} is the result of expression and is then used
3489 as a command. Often it is good to use a |literal-string| to
3490 avoid having to double backslashes.
3491
3492 If {expr2} is a |Funcref| it must take two arguments:
3493 1. the key or the index of the current item.
3494 2. the value of the current item.
3495 With a legacy script lambda you don't get an error if it only
3496 accepts one argument, but with a Vim9 lambda you get "E1106:
3497 One argument too many", the number of arguments must match.
3498 If the function returns a value, it is ignored.
3499
3500 Returns {expr1} in all cases.
3501 When an error is encountered while executing {expr2} no
3502 further items in {expr1} are processed.
3503 When {expr2} is a Funcref errors inside a function are ignored,
3504 unless it was defined with the "abort" flag.
3505
3506 Can also be used as a |method|: >
3507 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003508<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003509 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3510 depending on {expr1}
3511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003512 *foreground()*
3513foreground() Move the Vim window to the foreground. Useful when sent from
3514 a client to a Vim server. |remote_send()|
3515 On Win32 systems this might not work, the OS does not always
3516 allow a window to bring itself to the foreground. Use
3517 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003518
3519 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003520 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003521 Win32 console version}
3522
Bram Moolenaaraa534142022-09-15 21:46:02 +01003523fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003524 Get the full command name from a short abbreviated command
3525 name; see |20.2| for details on command abbreviations.
3526
3527 The string argument {name} may start with a `:` and can
3528 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003529 Returns an empty string if a command doesn't exist, if it's
3530 ambiguous (for user-defined commands) or cannot be shortened
3531 this way. |vim9-no-shorten|
3532
3533 Without the {vim9} argument uses the current script version.
3534 If {vim9} is present and FALSE then legacy script rules are
3535 used. When {vim9} is present and TRUE then Vim9 rules are
3536 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003537
3538 For example `fullcommand('s')`, `fullcommand('sub')`,
3539 `fullcommand(':%substitute')` all return "substitute".
3540
3541 Can also be used as a |method|: >
3542 GetName()->fullcommand()
3543<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003544 Return type: |String|
3545
3546
3547funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003548 Just like |function()|, but the returned Funcref will lookup
3549 the function by reference, not by name. This matters when the
3550 function {name} is redefined later.
3551
3552 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003553 It only works for an autoloaded function if it has already
3554 been loaded (to avoid mistakenly loading the autoload script
3555 when only intending to use the function name, use |function()|
3556 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003557 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003558
3559 Can also be used as a |method|: >
3560 GetFuncname()->funcref([arg])
3561<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003562 Return type: func(...): any or |Number| on error
3563
Dominique Pellee764d1b2023-03-12 21:20:59 +00003564 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003565function({name} [, {arglist}] [, {dict}])
3566 Return a |Funcref| variable that refers to function {name}.
3567 {name} can be the name of a user defined function or an
3568 internal function.
3569
3570 {name} can also be a Funcref or a partial. When it is a
3571 partial the dict stored in it will be used and the {dict}
3572 argument is not allowed. E.g.: >
3573 let FuncWithArg = function(dict.Func, [arg])
3574 let Broken = function(dict.Func, [arg], dict)
3575<
3576 When using the Funcref the function will be found by {name},
3577 also when it was redefined later. Use |funcref()| to keep the
3578 same function.
3579
3580 When {arglist} or {dict} is present this creates a partial.
3581 That means the argument list and/or the dictionary is stored in
3582 the Funcref and will be used when the Funcref is called.
3583
3584 The arguments are passed to the function in front of other
3585 arguments, but after any argument from |method|. Example: >
3586 func Callback(arg1, arg2, name)
3587 ...
3588 let Partial = function('Callback', ['one', 'two'])
3589 ...
3590 call Partial('name')
3591< Invokes the function as with: >
3592 call Callback('one', 'two', 'name')
3593
3594< With a |method|: >
3595 func Callback(one, two, three)
3596 ...
3597 let Partial = function('Callback', ['two'])
3598 ...
3599 eval 'one'->Partial('three')
3600< Invokes the function as with: >
3601 call Callback('one', 'two', 'three')
3602
3603< The function() call can be nested to add more arguments to the
3604 Funcref. The extra arguments are appended to the list of
3605 arguments. Example: >
3606 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003607 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003608 let Func = function('Callback', ['one'])
3609 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003610 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003611 call Func2('name')
3612< Invokes the function as with: >
3613 call Callback('one', 'two', 'name')
3614
3615< The Dictionary is only useful when calling a "dict" function.
3616 In that case the {dict} is passed in as "self". Example: >
3617 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003618 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003619 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003620 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003621 let context = {"name": "example"}
3622 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003623 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003624 call Func() " will echo: called for example
3625< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003626 arguments, these two are equivalent, if Callback() is defined
3627 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003628 let Func = function('Callback', context)
3629 let Func = context.Callback
3630
3631< The argument list and the Dictionary can be combined: >
3632 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003633 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003634 let context = {"name": "example"}
3635 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003636 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003637 call Func(500)
3638< Invokes the function as with: >
3639 call context.Callback('one', 500)
3640<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003641 Returns 0 on error.
3642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003643 Can also be used as a |method|: >
3644 GetFuncname()->function([arg])
3645
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003646<
3647 Return type: func(...): any or |Number| on error
3648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003649
3650garbagecollect([{atexit}]) *garbagecollect()*
3651 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3652 that have circular references.
3653
3654 There is hardly ever a need to invoke this function, as it is
3655 automatically done when Vim runs out of memory or is waiting
3656 for the user to press a key after 'updatetime'. Items without
3657 circular references are always freed when they become unused.
3658 This is useful if you have deleted a very big |List| and/or
3659 |Dictionary| with circular references in a script that runs
3660 for a long time.
3661
3662 When the optional {atexit} argument is one, garbage
3663 collection will also be done when exiting Vim, if it wasn't
3664 done before. This is useful when checking for memory leaks.
3665
3666 The garbage collection is not done immediately but only when
3667 it's safe to perform. This is when waiting for the user to
3668 type a character. To force garbage collection immediately use
3669 |test_garbagecollect_now()|.
3670
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003671 Return type: |String|
3672
3673
LemonBoy48b7d052024-07-09 18:24:59 +02003674get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003675 Get item {idx} from |List| {list}. When this item is not
3676 available return {default}. Return zero when {default} is
3677 omitted.
3678 Preferably used as a |method|: >
3679 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003680<
3681 Return type: any, depending on {list}
3682
LemonBoy48b7d052024-07-09 18:24:59 +02003683get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003684 Get byte {idx} from |Blob| {blob}. When this byte is not
3685 available return {default}. Return -1 when {default} is
3686 omitted.
3687 Preferably used as a |method|: >
3688 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003689<
3690 Return type: |Number|
3691
LemonBoy48b7d052024-07-09 18:24:59 +02003692get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003693 Get item with key {key} from |Dictionary| {dict}. When this
3694 item is not available return {default}. Return zero when
3695 {default} is omitted. Useful example: >
3696 let val = get(g:, 'var_name', 'default')
3697< This gets the value of g:var_name if it exists, and uses
3698 'default' when it does not exist.
3699 Preferably used as a |method|: >
3700 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003701<
h-east84ac2122024-06-17 18:12:30 +02003702 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003703
LemonBoy48b7d052024-07-09 18:24:59 +02003704get({func}, {what}) *get()-func*
3705 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003706 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003707 "name" The function name
3708 "func" The function
3709 "dict" The dictionary
3710 "args" The list with arguments
3711 "arity" A dictionary with information about the number of
3712 arguments accepted by the function (minus the
3713 {arglist}) with the following fields:
3714 required the number of positional arguments
3715 optional the number of optional arguments,
3716 in addition to the required ones
3717 varargs |TRUE| if the function accepts a
3718 variable number of arguments |...|
3719
3720 Note: There is no error, if the {arglist} of
3721 the Funcref contains more arguments than the
3722 Funcref expects, it's not validated.
3723
Bram Moolenaar016188f2022-06-06 20:52:59 +01003724 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003726 Preferably used as a |method|: >
3727 myfunc->get(what)
3728<
LemonBoy48b7d052024-07-09 18:24:59 +02003729 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003731 *getbufinfo()*
3732getbufinfo([{buf}])
3733getbufinfo([{dict}])
3734 Get information about buffers as a List of Dictionaries.
3735
3736 Without an argument information about all the buffers is
3737 returned.
3738
3739 When the argument is a |Dictionary| only the buffers matching
3740 the specified criteria are returned. The following keys can
3741 be specified in {dict}:
3742 buflisted include only listed buffers.
3743 bufloaded include only loaded buffers.
3744 bufmodified include only modified buffers.
3745
3746 Otherwise, {buf} specifies a particular buffer to return
3747 information for. For the use of {buf}, see |bufname()|
3748 above. If the buffer is found the returned List has one item.
3749 Otherwise the result is an empty list.
3750
3751 Each returned List item is a dictionary with the following
3752 entries:
3753 bufnr Buffer number.
3754 changed TRUE if the buffer is modified.
3755 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003756 command TRUE if the buffer belongs to the
3757 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003758 hidden TRUE if the buffer is hidden.
3759 lastused Timestamp in seconds, like
3760 |localtime()|, when the buffer was
3761 last used.
3762 {only with the |+viminfo| feature}
3763 listed TRUE if the buffer is listed.
3764 lnum Line number used for the buffer when
3765 opened in the current window.
3766 Only valid if the buffer has been
3767 displayed in the window in the past.
3768 If you want the line number of the
3769 last known cursor position in a given
3770 window, use |line()|: >
3771 :echo line('.', {winid})
3772<
3773 linecount Number of lines in the buffer (only
3774 valid when loaded)
3775 loaded TRUE if the buffer is loaded.
3776 name Full path to the file in the buffer.
3777 signs List of signs placed in the buffer.
3778 Each list item is a dictionary with
3779 the following fields:
3780 id sign identifier
3781 lnum line number
3782 name sign name
3783 variables A reference to the dictionary with
3784 buffer-local variables.
3785 windows List of |window-ID|s that display this
3786 buffer
3787 popups List of popup |window-ID|s that
3788 display this buffer
3789
3790 Examples: >
3791 for buf in getbufinfo()
3792 echo buf.name
3793 endfor
3794 for buf in getbufinfo({'buflisted':1})
3795 if buf.changed
3796 ....
3797 endif
3798 endfor
3799<
3800 To get buffer-local options use: >
3801 getbufvar({bufnr}, '&option_name')
3802<
3803 Can also be used as a |method|: >
3804 GetBufnr()->getbufinfo()
3805<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003806 Return type: list<dict<any>>
3807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003808
3809 *getbufline()*
3810getbufline({buf}, {lnum} [, {end}])
3811 Return a |List| with the lines starting from {lnum} to {end}
3812 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003813 |List| with only the line {lnum} is returned. See
3814 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003815
3816 For the use of {buf}, see |bufname()| above.
3817
3818 For {lnum} and {end} "$" can be used for the last line of the
3819 buffer. Otherwise a number must be used.
3820
3821 When {lnum} is smaller than 1 or bigger than the number of
3822 lines in the buffer, an empty |List| is returned.
3823
3824 When {end} is greater than the number of lines in the buffer,
3825 it is treated as {end} is set to the number of lines in the
3826 buffer. When {end} is before {lnum} an empty |List| is
3827 returned.
3828
3829 This function works only for loaded buffers. For unloaded and
3830 non-existing buffers, an empty |List| is returned.
3831
3832 Example: >
3833 :let lines = getbufline(bufnr("myfile"), 1, "$")
3834
3835< Can also be used as a |method|: >
3836 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003837<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003838 Return type: list<string>
3839
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003840 *getbufoneline()*
3841getbufoneline({buf}, {lnum})
3842 Just like `getbufline()` but only get one line and return it
3843 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003844
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003845 Return type: |String|
3846
3847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003848getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3849 The result is the value of option or local buffer variable
3850 {varname} in buffer {buf}. Note that the name without "b:"
3851 must be used.
3852 The {varname} argument is a string.
3853 When {varname} is empty returns a |Dictionary| with all the
3854 buffer-local variables.
3855 When {varname} is equal to "&" returns a |Dictionary| with all
3856 the buffer-local options.
3857 Otherwise, when {varname} starts with "&" returns the value of
3858 a buffer-local option.
3859 This also works for a global or buffer-local option, but it
3860 doesn't work for a global variable, window-local variable or
3861 window-local option.
3862 For the use of {buf}, see |bufname()| above.
3863 When the buffer or variable doesn't exist {def} or an empty
3864 string is returned, there is no error message.
3865 Examples: >
3866 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003867 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003868
3869< Can also be used as a |method|: >
3870 GetBufnr()->getbufvar(varname)
3871<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003872 Return type: any, depending on {varname}
3873
3874
mikoto20001083cae2024-11-11 21:24:14 +01003875getcellpixels() *getcellpixels()*
3876 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003877 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003878
3879 Only works on Unix (terminal and gVim) and Windows (gVim only).
3880 Returns [] on other systems or on failure.
3881 Note that there could be variations across different terminals.
3882 On macOS, system Terminal.app returns sizes in points (before
3883 Retina scaling), whereas third-party terminals return raw pixel
3884 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003885
mikoto2000de094dc2024-11-14 22:13:48 +01003886 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003887
3888
Kota Kato66bb9ae2023-01-17 18:31:56 +00003889getcellwidths() *getcellwidths()*
3890 Returns a |List| of cell widths of character ranges overridden
3891 by |setcellwidths()|. The format is equal to the argument of
3892 |setcellwidths()|. If no character ranges have their cell
3893 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003894
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003895 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003896
3897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003898getchangelist([{buf}]) *getchangelist()*
3899 Returns the |changelist| for the buffer {buf}. For the use
3900 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3901 exist, an empty list is returned.
3902
3903 The returned list contains two entries: a list with the change
3904 locations and the current position in the list. Each
3905 entry in the change list is a dictionary with the following
3906 entries:
3907 col column number
3908 coladd column offset for 'virtualedit'
3909 lnum line number
3910 If buffer {buf} is the current buffer, then the current
3911 position refers to the position in the list. For other
3912 buffers, it is set to the length of the list.
3913
3914 Can also be used as a |method|: >
3915 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003916<
3917 Return type: list<any>
3918
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003919
Doug Kearns9cd9e752024-04-07 17:42:17 +02003920getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003921 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003922 If {expr} is omitted, wait until a character is available.
3923 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003924 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003925 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003926 not consumed. Return zero if no character available.
3927 If you prefer always getting a string use |getcharstr()|.
3928
Doug Kearns9cd9e752024-04-07 17:42:17 +02003929 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003930 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003931 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003932 Otherwise a String is returned with the encoded character.
3933 For a special key it's a String with a sequence of bytes
3934 starting with 0x80 (decimal: 128). This is the same value as
3935 the String "\<Key>", e.g., "\<Left>". The returned value is
3936 also a String when a modifier (shift, control, alt) was used
3937 that is not included in the character.
3938
Doug Kearns9cd9e752024-04-07 17:42:17 +02003939 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940 while Vim waits to see if this is the start of an escape
3941 sequence.
3942
Doug Kearns9cd9e752024-04-07 17:42:17 +02003943 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003944 one-byte character it is the character itself as a number.
3945 Use nr2char() to convert it to a String.
3946
3947 Use getcharmod() to obtain any additional modifiers.
3948
3949 When the user clicks a mouse button, the mouse event will be
3950 returned. The position can then be found in |v:mouse_col|,
3951 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3952 |getmousepos()| can also be used. Mouse move events will be
3953 ignored.
3954 This example positions the mouse as it would normally happen: >
3955 let c = getchar()
3956 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003957 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003958 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003959 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003960 endif
3961<
3962 When using bracketed paste only the first character is
3963 returned, the rest of the pasted text is dropped.
3964 |xterm-bracketed-paste|.
3965
3966 There is no prompt, you will somehow have to make clear to the
3967 user that a character has to be typed. The screen is not
3968 redrawn, e.g. when resizing the window. When using a popup
3969 window it should work better with a |popup-filter|.
3970
3971 There is no mapping for the character.
3972 Key codes are replaced, thus when the user presses the <Del>
3973 key you get the code for the <Del> key, not the raw character
3974 sequence. Examples: >
3975 getchar() == "\<Del>"
3976 getchar() == "\<S-Left>"
3977< This example redefines "f" to ignore case: >
3978 :nmap f :call FindChar()<CR>
3979 :function FindChar()
3980 : let c = nr2char(getchar())
3981 : while col('.') < col('$') - 1
3982 : normal l
3983 : if getline('.')[col('.') - 1] ==? c
3984 : break
3985 : endif
3986 : endwhile
3987 :endfunction
3988<
3989 You may also receive synthetic characters, such as
3990 |<CursorHold>|. Often you will want to ignore this and get
3991 another character: >
3992 :function GetKey()
3993 : let c = getchar()
3994 : while c == "\<CursorHold>"
3995 : let c = getchar()
3996 : endwhile
3997 : return c
3998 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003999<
4000 Return type: |Number| or |String|
4001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004002
4003getcharmod() *getcharmod()*
4004 The result is a Number which is the state of the modifiers for
4005 the last obtained character with getchar() or in another way.
4006 These values are added together:
4007 2 shift
4008 4 control
4009 8 alt (meta)
4010 16 meta (when it's different from ALT)
4011 32 mouse double click
4012 64 mouse triple click
4013 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004014 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004015 Only the modifiers that have not been included in the
4016 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004017 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004018
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004019 Return type: |Number|
4020
4021
4022getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023 Get the position for String {expr}. Same as |getpos()| but the
4024 column number in the returned List is a character index
4025 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004026 If |getpos()| returns a very large column number, equal to
4027 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004028 of the last character.
4029
4030 Example:
4031 With the cursor on '세' in line 5 with text "여보세요": >
4032 getcharpos('.') returns [0, 5, 3, 0]
4033 getpos('.') returns [0, 5, 7, 0]
4034<
4035 Can also be used as a |method|: >
4036 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004037<
4038 Return type: list<number>
4039
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004040
4041getcharsearch() *getcharsearch()*
4042 Return the current character search information as a {dict}
4043 with the following entries:
4044
4045 char character previously used for a character
4046 search (|t|, |f|, |T|, or |F|); empty string
4047 if no character search has been performed
4048 forward direction of character search; 1 for forward,
4049 0 for backward
4050 until type of character search; 1 for a |t| or |T|
4051 character search, 0 for an |f| or |F|
4052 character search
4053
4054 This can be useful to always have |;| and |,| search
4055 forward/backward regardless of the direction of the previous
4056 character search: >
4057 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4058 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4059< Also see |setcharsearch()|.
4060
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004061 Return type: dict<any>
4062
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004063
Doug Kearns9cd9e752024-04-07 17:42:17 +02004064getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004065 Get a single character from the user or input stream as a
4066 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004067 If {expr} is omitted, wait until a character is available.
4068 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004069 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004070 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004071 available, it is not consumed. Return an empty string
4072 if no character is available.
4073 Otherwise this works like |getchar()|, except that a number
4074 result is converted to a string.
4075
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004076 Return type: |String|
4077
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004078getcmdcomplpat() *getcmdcomplpat()*
4079 Return completion pattern of the current command-line.
4080 Only works when the command line is being edited, thus
4081 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4082 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4083 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4084 Returns an empty string when completion is not defined.
4085
4086 Return type: |String|
4087
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004088
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004089getcmdcompltype() *getcmdcompltype()*
4090 Return the type of the current command-line completion.
4091 Only works when the command line is being edited, thus
4092 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004093 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004094 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004095 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004096 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004098 Return type: |String|
4099
4100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004101getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004102 Return the current command-line input. Only works when the
4103 command line is being edited, thus requires use of
4104 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004105 Example: >
4106 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004107< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4108 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004109 Returns an empty string when entering a password or using
4110 |inputsecret()|.
4111
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004112 Return type: |String|
4113
4114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004115getcmdpos() *getcmdpos()*
4116 Return the position of the cursor in the command line as a
4117 byte count. The first column is 1.
4118 Only works when editing the command line, thus requires use of
4119 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4120 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004121 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4122 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004123
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004124 Return type: |Number|
4125
4126
Shougo Matsushita69084282024-09-23 20:34:47 +02004127getcmdprompt() *getcmdprompt()*
4128 Return the current command-line prompt when using functions
4129 like |input()| or |confirm()|.
4130 Only works when the command line is being edited, thus
4131 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4132 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4133 |setcmdpos()| and |setcmdline()|.
4134
4135 Return type: |String|
4136
4137
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004138getcmdscreenpos() *getcmdscreenpos()*
4139 Return the screen position of the cursor in the command line
4140 as a byte count. The first column is 1.
4141 Instead of |getcmdpos()|, it adds the prompt position.
4142 Only works when editing the command line, thus requires use of
4143 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4144 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004145 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4146 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004147
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004148 Return type: |Number|
4149
4150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004151getcmdtype() *getcmdtype()*
4152 Return the current command-line type. Possible return values
4153 are:
4154 : normal Ex command
4155 > debug mode command |debug-mode|
4156 / forward search command
4157 ? backward search command
4158 @ |input()| command
4159 - |:insert| or |:append| command
4160 = |i_CTRL-R_=|
4161 Only works when editing the command line, thus requires use of
4162 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4163 Returns an empty string otherwise.
4164 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4165
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004166 Return type: |String|
4167
4168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004169getcmdwintype() *getcmdwintype()*
4170 Return the current |command-line-window| type. Possible return
4171 values are the same as |getcmdtype()|. Returns an empty string
4172 when not in the command-line window.
4173
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004174 Return type: |String|
4175
4176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004177getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4178 Return a list of command-line completion matches. The String
4179 {type} argument specifies what for. The following completion
4180 types are supported:
4181
4182 arglist file names in argument list
4183 augroup autocmd groups
4184 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004185 behave |:behave| suboptions
4186 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004187 color color schemes
4188 command Ex command
4189 cmdline |cmdline-completion| result
4190 compiler compilers
4191 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004192 custom,{func} custom completion, defined via {func}
4193 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004194 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004195 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004196 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004197 environment environment variable names
4198 event autocommand events
4199 expression Vim expression
4200 file file and directory names
4201 file_in_path file and directory names in |'path'|
4202 filetype filetype names |'filetype'|
4203 function function name
4204 help help subjects
4205 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004206 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004207 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004208 locale locale names (as output of locale -a)
4209 mapclear buffer argument
4210 mapping mapping name
4211 menu menus
4212 messages |:messages| suboptions
4213 option options
4214 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004215 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004216 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004217 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004218 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004219 sign |:sign| suboptions
4220 syntax syntax file names |'syntax'|
4221 syntime |:syntime| suboptions
4222 tag tags
4223 tag_listfiles tags, file names
4224 user user names
4225 var user variables
4226
4227 If {pat} is an empty string, then all the matches are
4228 returned. Otherwise only items matching {pat} are returned.
4229 See |wildcards| for the use of special characters in {pat}.
4230
4231 If the optional {filtered} flag is set to 1, then 'wildignore'
4232 is applied to filter the results. Otherwise all the matches
4233 are returned. The 'wildignorecase' option always applies.
4234
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004235 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4236 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004237 regular expression matching is used. Thus this function
4238 follows the user preference, what happens on the command line.
4239 If you do not want this you can make 'wildoptions' empty
4240 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004241
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004242 If {type} is "cmdline", then the |cmdline-completion| result is
4243 returned. For example, to complete the possible values after
4244 a ":call" command: >
4245 echo getcompletion('call ', 'cmdline')
4246<
4247 If there are no matches, an empty list is returned. An
4248 invalid value for {type} produces an error.
4249
4250 Can also be used as a |method|: >
4251 GetPattern()->getcompletion('color')
4252<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004253 Return type: list<string>
4254
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004255 *getcurpos()*
4256getcurpos([{winid}])
4257 Get the position of the cursor. This is like getpos('.'), but
4258 includes an extra "curswant" item in the list:
4259 [0, lnum, col, off, curswant] ~
4260 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004261 cursor vertically. After |$| command it will be a very large
4262 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004263 |getpos()|.
4264 The first "bufnum" item is always zero. The byte position of
4265 the cursor is returned in 'col'. To get the character
4266 position, use |getcursorcharpos()|.
4267
4268 The optional {winid} argument can specify the window. It can
4269 be the window number or the |window-ID|. The last known
4270 cursor position is returned, this may be invalid for the
4271 current value of the buffer if it is not the current window.
4272 If {winid} is invalid a list with zeroes is returned.
4273
4274 This can be used to save and restore the cursor position: >
4275 let save_cursor = getcurpos()
4276 MoveTheCursorAround
4277 call setpos('.', save_cursor)
4278< Note that this only works within the window. See
4279 |winrestview()| for restoring more state.
4280
4281 Can also be used as a |method|: >
4282 GetWinid()->getcurpos()
4283<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004284 Return type: list<number>
4285
4286
4287getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004288 Same as |getcurpos()| but the column number in the returned
4289 List is a character index instead of a byte index.
4290
4291 Example:
4292 With the cursor on '보' in line 3 with text "여보세요": >
4293 getcursorcharpos() returns [0, 3, 2, 0, 3]
4294 getcurpos() returns [0, 3, 4, 0, 3]
4295<
4296 Can also be used as a |method|: >
4297 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004298<
4299 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004300
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004301
4302getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004303 The result is a String, which is the name of the current
4304 working directory. 'autochdir' is ignored.
4305
4306 With {winnr} return the local current directory of this window
4307 in the current tab page. {winnr} can be the window number or
4308 the |window-ID|.
4309 If {winnr} is -1 return the name of the global working
4310 directory. See also |haslocaldir()|.
4311
4312 With {winnr} and {tabnr} return the local current directory of
4313 the window in the specified tab page. If {winnr} is -1 return
4314 the working directory of the tabpage.
4315 If {winnr} is zero use the current window, if {tabnr} is zero
4316 use the current tabpage.
4317 Without any arguments, return the actual working directory of
4318 the current window.
4319 Return an empty string if the arguments are invalid.
4320
4321 Examples: >
4322 " Get the working directory of the current window
4323 :echo getcwd()
4324 :echo getcwd(0)
4325 :echo getcwd(0, 0)
4326 " Get the working directory of window 3 in tabpage 2
4327 :echo getcwd(3, 2)
4328 " Get the global working directory
4329 :echo getcwd(-1)
4330 " Get the working directory of tabpage 3
4331 :echo getcwd(-1, 3)
4332 " Get the working directory of current tabpage
4333 :echo getcwd(-1, 0)
4334
4335< Can also be used as a |method|: >
4336 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004337<
4338 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004339
4340getenv({name}) *getenv()*
4341 Return the value of environment variable {name}. The {name}
4342 argument is a string, without a leading '$'. Example: >
4343 myHome = getenv('HOME')
4344
4345< When the variable does not exist |v:null| is returned. That
4346 is different from a variable set to an empty string, although
4347 some systems interpret the empty value as the variable being
4348 deleted. See also |expr-env|.
4349
4350 Can also be used as a |method|: >
4351 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004352<
4353 Return type: |String| or |Number|
4354
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004355
4356getfontname([{name}]) *getfontname()*
4357 Without an argument returns the name of the normal font being
4358 used. Like what is used for the Normal highlight group
4359 |hl-Normal|.
4360 With an argument a check is done whether String {name} is a
4361 valid font name. If not then an empty string is returned.
4362 Otherwise the actual font name is returned, or {name} if the
4363 GUI does not support obtaining the real name.
4364 Only works when the GUI is running, thus not in your vimrc or
4365 gvimrc file. Use the |GUIEnter| autocommand to use this
4366 function just after the GUI has started.
4367 Note that the GTK GUI accepts any font name, thus checking for
4368 a valid name does not work.
4369
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004370 Return type: |String|
4371
4372
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004373getfperm({fname}) *getfperm()*
4374 The result is a String, which is the read, write, and execute
4375 permissions of the given file {fname}.
4376 If {fname} does not exist or its directory cannot be read, an
4377 empty string is returned.
4378 The result is of the form "rwxrwxrwx", where each group of
4379 "rwx" flags represent, in turn, the permissions of the owner
4380 of the file, the group the file belongs to, and other users.
4381 If a user does not have a given permission the flag for this
4382 is replaced with the string "-". Examples: >
4383 :echo getfperm("/etc/passwd")
4384 :echo getfperm(expand("~/.vimrc"))
4385< This will hopefully (from a security point of view) display
4386 the string "rw-r--r--" or even "rw-------".
4387
4388 Can also be used as a |method|: >
4389 GetFilename()->getfperm()
4390<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004391 Return type: |String|
4392
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004393 For setting permissions use |setfperm()|.
4394
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004396getfsize({fname}) *getfsize()*
4397 The result is a Number, which is the size in bytes of the
4398 given file {fname}.
4399 If {fname} is a directory, 0 is returned.
4400 If the file {fname} can't be found, -1 is returned.
4401 If the size of {fname} is too big to fit in a Number then -2
4402 is returned.
4403
4404 Can also be used as a |method|: >
4405 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004406<
4407 Return type: |Number|
4408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004409
4410getftime({fname}) *getftime()*
4411 The result is a Number, which is the last modification time of
4412 the given file {fname}. The value is measured as seconds
4413 since 1st Jan 1970, and may be passed to strftime(). See also
4414 |localtime()| and |strftime()|.
4415 If the file {fname} can't be found -1 is returned.
4416
4417 Can also be used as a |method|: >
4418 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004419<
4420 Return type: |Number|
4421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004422
4423getftype({fname}) *getftype()*
4424 The result is a String, which is a description of the kind of
4425 file of the given file {fname}.
4426 If {fname} does not exist an empty string is returned.
4427 Here is a table over different kinds of files and their
4428 results:
4429 Normal file "file"
4430 Directory "dir"
4431 Symbolic link "link"
4432 Block device "bdev"
4433 Character device "cdev"
4434 Socket "socket"
4435 FIFO "fifo"
4436 All other "other"
4437 Example: >
4438 getftype("/home")
4439< Note that a type such as "link" will only be returned on
4440 systems that support it. On some systems only "dir" and
4441 "file" are returned. On MS-Windows a symbolic link to a
4442 directory returns "dir" instead of "link".
4443
4444 Can also be used as a |method|: >
4445 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004446<
4447 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004448
4449getimstatus() *getimstatus()*
4450 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004451 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004452 See 'imstatusfunc'.
4453
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004454 Return type: |Number|
4455
4456
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004457getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4458 Returns the |jumplist| for the specified window.
4459
4460 Without arguments use the current window.
4461 With {winnr} only use this window in the current tab page.
4462 {winnr} can also be a |window-ID|.
4463 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004464 page. If {winnr} or {tabnr} is invalid, an empty list is
4465 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004466
4467 The returned list contains two entries: a list with the jump
4468 locations and the last used jump position number in the list.
4469 Each entry in the jump location list is a dictionary with
4470 the following entries:
4471 bufnr buffer number
4472 col column number
4473 coladd column offset for 'virtualedit'
4474 filename filename if available
4475 lnum line number
4476
4477 Can also be used as a |method|: >
4478 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004479<
4480 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004481
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004482 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004483getline({lnum} [, {end}])
4484 Without {end} the result is a String, which is line {lnum}
4485 from the current buffer. Example: >
4486 getline(1)
4487< When {lnum} is a String that doesn't start with a
4488 digit, |line()| is called to translate the String into a Number.
4489 To get the line under the cursor: >
4490 getline(".")
4491< When {lnum} is a number smaller than 1 or bigger than the
4492 number of lines in the buffer, an empty string is returned.
4493
4494 When {end} is given the result is a |List| where each item is
4495 a line from the current buffer in the range {lnum} to {end},
4496 including line {end}.
4497 {end} is used in the same way as {lnum}.
4498 Non-existing lines are silently omitted.
4499 When {end} is before {lnum} an empty |List| is returned.
4500 Example: >
4501 :let start = line('.')
4502 :let end = search("^$") - 1
4503 :let lines = getline(start, end)
4504
4505< Can also be used as a |method|: >
4506 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004507<
4508 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004509
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004510 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004511 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004512
4513getloclist({nr} [, {what}]) *getloclist()*
4514 Returns a |List| with all the entries in the location list for
4515 window {nr}. {nr} can be the window number or the |window-ID|.
4516 When {nr} is zero the current window is used.
4517
4518 For a location list window, the displayed location list is
4519 returned. For an invalid window number {nr}, an empty list is
4520 returned. Otherwise, same as |getqflist()|.
4521
4522 If the optional {what} dictionary argument is supplied, then
4523 returns the items listed in {what} as a dictionary. Refer to
4524 |getqflist()| for the supported items in {what}.
4525
4526 In addition to the items supported by |getqflist()| in {what},
4527 the following item is supported by |getloclist()|:
4528
4529 filewinid id of the window used to display files
4530 from the location list. This field is
4531 applicable only when called from a
4532 location list window. See
4533 |location-list-file-window| for more
4534 details.
4535
4536 Returns a |Dictionary| with default values if there is no
4537 location list for the window {nr}.
4538 Returns an empty Dictionary if window {nr} does not exist.
4539
4540 Examples (See also |getqflist-examples|): >
4541 :echo getloclist(3, {'all': 0})
4542 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004543<
4544 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004545
4546
4547getmarklist([{buf}]) *getmarklist()*
4548 Without the {buf} argument returns a |List| with information
4549 about all the global marks. |mark|
4550
4551 If the optional {buf} argument is specified, returns the
4552 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004553 see |bufname()|. If {buf} is invalid, an empty list is
4554 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004555
4556 Each item in the returned List is a |Dict| with the following:
4557 mark name of the mark prefixed by "'"
4558 pos a |List| with the position of the mark:
4559 [bufnum, lnum, col, off]
4560 Refer to |getpos()| for more information.
4561 file file name
4562
4563 Refer to |getpos()| for getting information about a specific
4564 mark.
4565
4566 Can also be used as a |method|: >
4567 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004568<
4569 Return type: list<dict<any>> or list<any>
4570
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004571
4572getmatches([{win}]) *getmatches()*
4573 Returns a |List| with all matches previously defined for the
4574 current window by |matchadd()| and the |:match| commands.
4575 |getmatches()| is useful in combination with |setmatches()|,
4576 as |setmatches()| can restore a list of matches saved by
4577 |getmatches()|.
4578 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004579 window ID instead of the current window. If {win} is invalid,
4580 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004581 Example: >
4582 :echo getmatches()
4583< [{'group': 'MyGroup1', 'pattern': 'TODO',
4584 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4585 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4586 :let m = getmatches()
4587 :call clearmatches()
4588 :echo getmatches()
4589< [] >
4590 :call setmatches(m)
4591 :echo getmatches()
4592< [{'group': 'MyGroup1', 'pattern': 'TODO',
4593 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4594 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4595 :unlet m
4596<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004597 Return type: list<dict<any>> or list<any>
4598
4599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004600getmousepos() *getmousepos()*
4601 Returns a |Dictionary| with the last known position of the
4602 mouse. This can be used in a mapping for a mouse click or in
4603 a filter of a popup window. The items are:
4604 screenrow screen row
4605 screencol screen column
4606 winid Window ID of the click
4607 winrow row inside "winid"
4608 wincol column inside "winid"
4609 line text line inside "winid"
4610 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004611 coladd offset (in screen columns) from the
4612 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004613 All numbers are 1-based.
4614
4615 If not over a window, e.g. when in the command line, then only
4616 "screenrow" and "screencol" are valid, the others are zero.
4617
4618 When on the status line below a window or the vertical
4619 separator right of a window, the "line" and "column" values
4620 are zero.
4621
4622 When the position is after the text then "column" is the
4623 length of the text in bytes plus one.
4624
4625 If the mouse is over a popup window then that window is used.
4626
4627 When using |getchar()| the Vim variables |v:mouse_lnum|,
4628 |v:mouse_col| and |v:mouse_winid| also provide these values.
4629
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004630 Return type: dict<number>
4631
4632
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004633getmouseshape() *getmouseshape()*
4634 Returns the name of the currently showing mouse pointer.
4635 When the |+mouseshape| feature is not supported or the shape
4636 is unknown an empty string is returned.
4637 This function is mainly intended for testing.
4638
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004639 Return type: |String|
4640
4641
4642getpid() *getpid()*
4643 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004644 On Unix and MS-Windows this is a unique number, until Vim
4645 exits.
4646
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004647 Return type: |Number|
4648
4649
4650getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004651 Get the position for String {expr}.
4652 The accepted values for {expr} are: *E1209*
4653 . The cursor position.
4654 $ The last line in the current buffer.
4655 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004656 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004657 w0 First line visible in current window (one if the
4658 display isn't updated, e.g. in silent Ex mode).
4659 w$ Last line visible in current window (this is one
4660 less than "w0" if no lines are visible).
4661 v When not in Visual mode, returns the cursor
4662 position. In Visual mode, returns the other end
4663 of the Visual area. A good way to think about
4664 this is that in Visual mode "v" and "." complement
4665 each other. While "." refers to the cursor
4666 position, "v" refers to where |v_o| would move the
4667 cursor. As a result, you can use "v" and "."
4668 together to work on all of a selection in
4669 characterwise Visual mode. If the cursor is at
4670 the end of a characterwise Visual area, "v" refers
4671 to the start of the same Visual area. And if the
4672 cursor is at the start of a characterwise Visual
4673 area, "v" refers to the end of the same Visual
4674 area. "v" differs from |'<| and |'>| in that it's
4675 updated right away.
4676 Note that a mark in another file can be used. The line number
4677 then applies to another buffer.
4678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004679 The result is a |List| with four numbers:
4680 [bufnum, lnum, col, off]
4681 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4682 is the buffer number of the mark.
4683 "lnum" and "col" are the position in the buffer. The first
4684 column is 1.
4685 The "off" number is zero, unless 'virtualedit' is used. Then
4686 it is the offset in screen columns from the start of the
4687 character. E.g., a position within a <Tab> or after the last
4688 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004689
4690 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004691 The column number in the returned List is the byte position
4692 within the line. To get the character position in the line,
4693 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004694
4695 Note that for '< and '> Visual mode matters: when it is "V"
4696 (visual line mode) the column of '< is zero and the column of
4697 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004698 A very large column number equal to |v:maxcol| can be returned,
4699 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004700 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004702 This can be used to save and restore the position of a mark: >
4703 let save_a_mark = getpos("'a")
4704 ...
4705 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004706<
4707 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004708
4709 Can also be used as a |method|: >
4710 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004711<
4712 Return type: list<number>
4713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004714
4715getqflist([{what}]) *getqflist()*
4716 Returns a |List| with all the current quickfix errors. Each
4717 list item is a dictionary with these entries:
4718 bufnr number of buffer that has the file name, use
4719 bufname() to get the name
4720 module module name
4721 lnum line number in the buffer (first line is 1)
4722 end_lnum
4723 end of line number if the item is multiline
4724 col column number (first column is 1)
4725 end_col end of column number if the item has range
4726 vcol |TRUE|: "col" is visual column
4727 |FALSE|: "col" is byte index
4728 nr error number
h-east84ac2122024-06-17 18:12:30 +02004729 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004730 text description of the error
4731 type type of the error, 'E', '1', etc.
4732 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004733 user_data
4734 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004735 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004736
4737 When there is no error list or it's empty, an empty list is
4738 returned. Quickfix list entries with a non-existing buffer
4739 number are returned with "bufnr" set to zero (Note: some
4740 functions accept buffer number zero for the alternate buffer,
4741 you may need to explicitly check for zero).
4742
4743 Useful application: Find pattern matches in multiple files and
4744 do something with them: >
4745 :vimgrep /theword/jg *.c
4746 :for d in getqflist()
4747 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4748 :endfor
4749<
4750 If the optional {what} dictionary argument is supplied, then
4751 returns only the items listed in {what} as a dictionary. The
4752 following string items are supported in {what}:
4753 changedtick get the total number of changes made
4754 to the list |quickfix-changedtick|
4755 context get the |quickfix-context|
4756 efm errorformat to use when parsing "lines". If
4757 not present, then the 'errorformat' option
4758 value is used.
4759 id get information for the quickfix list with
4760 |quickfix-ID|; zero means the id for the
4761 current list or the list specified by "nr"
4762 idx get information for the quickfix entry at this
4763 index in the list specified by 'id' or 'nr'.
4764 If set to zero, then uses the current entry.
4765 See |quickfix-index|
4766 items quickfix list entries
4767 lines parse a list of lines using 'efm' and return
4768 the resulting entries. Only a |List| type is
4769 accepted. The current quickfix list is not
4770 modified. See |quickfix-parse|.
4771 nr get information for this quickfix list; zero
4772 means the current quickfix list and "$" means
4773 the last quickfix list
4774 qfbufnr number of the buffer displayed in the quickfix
4775 window. Returns 0 if the quickfix buffer is
4776 not present. See |quickfix-buffer|.
4777 size number of entries in the quickfix list
4778 title get the list title |quickfix-title|
4779 winid get the quickfix |window-ID|
4780 all all of the above quickfix properties
4781 Non-string items in {what} are ignored. To get the value of a
4782 particular item, set it to zero.
4783 If "nr" is not present then the current quickfix list is used.
4784 If both "nr" and a non-zero "id" are specified, then the list
4785 specified by "id" is used.
4786 To get the number of lists in the quickfix stack, set "nr" to
4787 "$" in {what}. The "nr" value in the returned dictionary
4788 contains the quickfix stack size.
4789 When "lines" is specified, all the other items except "efm"
4790 are ignored. The returned dictionary contains the entry
4791 "items" with the list of entries.
4792
4793 The returned dictionary contains the following entries:
4794 changedtick total number of changes made to the
4795 list |quickfix-changedtick|
4796 context quickfix list context. See |quickfix-context|
4797 If not present, set to "".
4798 id quickfix list ID |quickfix-ID|. If not
4799 present, set to 0.
4800 idx index of the quickfix entry in the list. If not
4801 present, set to 0.
4802 items quickfix list entries. If not present, set to
4803 an empty list.
4804 nr quickfix list number. If not present, set to 0
4805 qfbufnr number of the buffer displayed in the quickfix
4806 window. If not present, set to 0.
4807 size number of entries in the quickfix list. If not
4808 present, set to 0.
4809 title quickfix list title text. If not present, set
4810 to "".
4811 winid quickfix |window-ID|. If not present, set to 0
4812
4813 Examples (See also |getqflist-examples|): >
4814 :echo getqflist({'all': 1})
4815 :echo getqflist({'nr': 2, 'title': 1})
4816 :echo getqflist({'lines' : ["F1:10:L10"]})
4817<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004818 Return type: list<dict<any>> or list<any>
4819
4820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004821getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4822 The result is a String, which is the contents of register
4823 {regname}. Example: >
4824 :let cliptext = getreg('*')
4825< When register {regname} was not set the result is an empty
4826 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004827 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004828
4829 getreg('=') returns the last evaluated value of the expression
4830 register. (For use in maps.)
4831 getreg('=', 1) returns the expression itself, so that it can
4832 be restored with |setreg()|. For other registers the extra
4833 argument is ignored, thus you can always give it.
4834
4835 If {list} is present and |TRUE|, the result type is changed
4836 to |List|. Each list item is one text line. Use it if you care
4837 about zero bytes possibly present inside register: without
4838 third argument both NLs and zero bytes are represented as NLs
4839 (see |NL-used-for-Nul|).
4840 When the register was not set an empty list is returned.
4841
4842 If {regname} is "", the unnamed register '"' is used.
4843 If {regname} is not specified, |v:register| is used.
4844 In |Vim9-script| {regname} must be one character.
4845
4846 Can also be used as a |method|: >
4847 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004848<
4849 Return type: |String|
4850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004851
4852getreginfo([{regname}]) *getreginfo()*
4853 Returns detailed information about register {regname} as a
4854 Dictionary with the following entries:
4855 regcontents List of lines contained in register
4856 {regname}, like
4857 |getreg|({regname}, 1, 1).
4858 regtype the type of register {regname}, as in
4859 |getregtype()|.
4860 isunnamed Boolean flag, v:true if this register
4861 is currently pointed to by the unnamed
4862 register.
4863 points_to for the unnamed register, gives the
4864 single letter name of the register
4865 currently pointed to (see |quotequote|).
4866 For example, after deleting a line
4867 with `dd`, this field will be "1",
4868 which is the register that got the
4869 deleted text.
4870
4871 The {regname} argument is a string. If {regname} is invalid
4872 or not set, an empty Dictionary will be returned.
4873 If {regname} is "" or "@", the unnamed register '"' is used.
4874 If {regname} is not specified, |v:register| is used.
4875 The returned Dictionary can be passed to |setreg()|.
4876 In |Vim9-script| {regname} must be one character.
4877
4878 Can also be used as a |method|: >
4879 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004880<
4881 Return type: dict<any>
4882
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004883
Shougo Matsushita19b71882024-02-28 22:48:12 +01004884getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004885 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004886 buffer.
4887
4888 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004889 See |getpos()| for the format of the list. It's possible
4890 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004891 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004892
4893 The optional argument {opts} is a Dict and supports the
4894 following items:
4895
zeertzjqafc22952024-05-24 19:07:12 +02004896 type Specify the region's selection type.
4897 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004898 except that the width can be omitted
4899 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004900 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004901
zeertzjq87410ab2024-03-02 06:00:23 +08004902 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004903 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004904 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004905
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004906 You can get the last selection type by |visualmode()|.
4907 If Visual mode is active, use |mode()| to get the Visual mode
4908 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004909 This function is useful to get text starting and ending in
4910 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004911
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004912 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004913 Note that:
4914 - Order of {pos1} and {pos2} doesn't matter, it will always
4915 return content from the upper left position to the lower
4916 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004917 - If 'virtualedit' is enabled and the region is past the end
4918 of the lines, resulting lines are padded with spaces.
4919 - If the region is blockwise and it starts or ends in the
4920 middle of a multi-cell character, it is not included but
4921 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004922 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004923 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004924 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004925 - It is evaluated in current window context, which makes a
4926 difference if the buffer is displayed in a window with
4927 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004928
4929 Examples: >
4930 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004931 \ <Cmd>echow getregion(
4932 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004933<
4934 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004935 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004936<
4937 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004938
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004939
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004940getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4941 Same as |getregion()|, but returns a list of positions
4942 describing the buffer text segments bound by {pos1} and
4943 {pos2}.
4944 The segments are a pair of positions for every line: >
4945 [[{start_pos}, {end_pos}], ...]
4946<
4947 The position is a |List| with four numbers:
4948 [bufnum, lnum, col, off]
4949 "bufnum" is the buffer number.
4950 "lnum" and "col" are the position in the buffer. The first
4951 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004952 If the "off" number of a starting position is non-zero, it is
4953 the offset in screen columns from the start of the character.
4954 E.g., a position within a <Tab> or after the last character.
4955 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004956 the offset of the character's first cell not included in the
4957 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004958
zeertzjq2b09de92024-05-24 07:48:51 +02004959 Apart from the options supported by |getregion()|, {opts} also
4960 supports the following:
4961
4962 eol If |TRUE|, indicate positions beyond
4963 the end of a line with "col" values
4964 one more than the length of the line.
4965 If |FALSE|, positions are limited
4966 within their lines, and if a line is
4967 empty or the selection is entirely
4968 beyond the end of a line, a "col"
4969 value of 0 is used for both positions.
4970 (default: |FALSE|)
4971
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004972 Can also be used as a |method|: >
4973 getpos('.')->getregionpos(getpos("'a"))
4974<
zeertzjqd4d12072024-07-16 20:34:16 +02004975 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004976
4977
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004978getregtype([{regname}]) *getregtype()*
4979 The result is a String, which is type of register {regname}.
4980 The value will be one of:
4981 "v" for |characterwise| text
4982 "V" for |linewise| text
4983 "<CTRL-V>{width}" for |blockwise-visual| text
4984 "" for an empty or unknown register
4985 <CTRL-V> is one character with value 0x16.
4986 The {regname} argument is a string. If {regname} is "", the
4987 unnamed register '"' is used. If {regname} is not specified,
4988 |v:register| is used.
4989 In |Vim9-script| {regname} must be one character.
4990
4991 Can also be used as a |method|: >
4992 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004993<
4994 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004995
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004996
Bram Moolenaar71badf92023-04-22 22:40:14 +01004997getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004998 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004999 scripts in the order they were sourced, like what
5000 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005001
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005002 The optional Dict argument {opts} supports the following
5003 optional items:
5004 name Script name match pattern. If specified,
5005 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005006 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005007 "name" are returned.
5008 sid Script ID |<SID>|. If specified, only
5009 information about the script with ID "sid" is
5010 returned and "name" is ignored.
5011
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005012 Each item in the returned List is a |Dict| with the following
5013 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005014 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005015 `import autoload` but was not actually sourced
5016 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005017 functions List of script-local function names defined in
5018 the script. Present only when a particular
5019 script is specified using the "sid" item in
5020 {opts}.
5021 name Vim script file name.
5022 sid Script ID |<SID>|.
5023 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005024 this script name links to, if any, otherwise
5025 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005026 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005027 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005028 specified using the "sid" item in {opts}.
5029 Note that this is a copy, the value of
5030 script-local variables cannot be changed using
5031 this dictionary.
h_east59858792023-10-25 22:47:05 +09005032 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005033
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005034 Examples: >
5035 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005036 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005037<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005038 Return type: list<dict<any>>
5039
5040
ichizok663d18d2025-01-02 18:06:00 +01005041getstacktrace() *getstacktrace()*
5042 Returns the current stack trace of Vim scripts.
5043 Stack trace is a |List|, of which each item is a |Dictionary|
5044 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005045 funcref The funcref if the stack is at a function,
5046 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005047 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005048 stack is at an autocmd event, otherwise this
5049 item is omitted.
5050 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005051 filepath The file path of the script on the stack.
5052
5053 Return type: list<dict<any>>
5054
5055
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005056gettabinfo([{tabnr}]) *gettabinfo()*
5057 If {tabnr} is not specified, then information about all the
5058 tab pages is returned as a |List|. Each List item is a
5059 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5060 number and information about that one is returned. If the tab
5061 page does not exist an empty List is returned.
5062
5063 Each List item is a |Dictionary| with the following entries:
5064 tabnr tab page number.
5065 variables a reference to the dictionary with
5066 tabpage-local variables
5067 windows List of |window-ID|s in the tab page.
5068
5069 Can also be used as a |method|: >
5070 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005071<
5072 Return type: list<dict<any>>
5073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005074
5075gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5076 Get the value of a tab-local variable {varname} in tab page
5077 {tabnr}. |t:var|
5078 Tabs are numbered starting with one.
5079 The {varname} argument is a string. When {varname} is empty a
5080 dictionary with all tab-local variables is returned.
5081 Note that the name without "t:" must be used.
5082 When the tab or variable doesn't exist {def} or an empty
5083 string is returned, there is no error message.
5084
5085 Can also be used as a |method|: >
5086 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005087<
5088 Return type: any, depending on {varname}
5089
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005090
5091gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5092 Get the value of window-local variable {varname} in window
5093 {winnr} in tab page {tabnr}.
5094 The {varname} argument is a string. When {varname} is empty a
5095 dictionary with all window-local variables is returned.
5096 When {varname} is equal to "&" get the values of all
5097 window-local options in a |Dictionary|.
5098 Otherwise, when {varname} starts with "&" get the value of a
5099 window-local option.
5100 Note that {varname} must be the name without "w:".
5101 Tabs are numbered starting with one. For the current tabpage
5102 use |getwinvar()|.
5103 {winnr} can be the window number or the |window-ID|.
5104 When {winnr} is zero the current window is used.
5105 This also works for a global option, buffer-local option and
5106 window-local option, but it doesn't work for a global variable
5107 or buffer-local variable.
5108 When the tab, window or variable doesn't exist {def} or an
5109 empty string is returned, there is no error message.
5110 Examples: >
5111 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005112 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005113<
5114 To obtain all window-local variables use: >
5115 gettabwinvar({tabnr}, {winnr}, '&')
5116
5117< Can also be used as a |method|: >
5118 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005119<
5120 Return type: any, depending on {varname}
5121
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005122
5123gettagstack([{winnr}]) *gettagstack()*
5124 The result is a Dict, which is the tag stack of window {winnr}.
5125 {winnr} can be the window number or the |window-ID|.
5126 When {winnr} is not specified, the current window is used.
5127 When window {winnr} doesn't exist, an empty Dict is returned.
5128
5129 The returned dictionary contains the following entries:
5130 curidx Current index in the stack. When at
5131 top of the stack, set to (length + 1).
5132 Index of bottom of the stack is 1.
5133 items List of items in the stack. Each item
5134 is a dictionary containing the
5135 entries described below.
5136 length Number of entries in the stack.
5137
5138 Each item in the stack is a dictionary with the following
5139 entries:
5140 bufnr buffer number of the current jump
5141 from cursor position before the tag jump.
5142 See |getpos()| for the format of the
5143 returned list.
5144 matchnr current matching tag number. Used when
5145 multiple matching tags are found for a
5146 name.
5147 tagname name of the tag
5148
5149 See |tagstack| for more information about the tag stack.
5150
5151 Can also be used as a |method|: >
5152 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005153<
5154 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005155
5156
Christ van Willegence0ef912024-06-20 23:41:59 +02005157gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005158 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005159 This is intended for use in Vim scripts. When generating
5160 message translations the {text} is extracted by `xgettext`,
5161 the translator can add translated messages into the .po file
5162 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005163 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005164 `xgettext` does not support single quoted escaped text.
5165
Christ van Willegence0ef912024-06-20 23:41:59 +02005166 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005167 for that specific package. This is mainly required for
5168 third-party Vim scripts. You need to specify a path to the
5169 translations with the |bindtextdomain()| function before
5170 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005171
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005172 Return type: |String|
5173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005174
5175getwininfo([{winid}]) *getwininfo()*
5176 Returns information about windows as a |List| with Dictionaries.
5177
5178 If {winid} is given Information about the window with that ID
5179 is returned, as a |List| with one item. If the window does not
5180 exist the result is an empty list.
5181
5182 Without {winid} information about all the windows in all the
5183 tab pages is returned.
5184
5185 Each List item is a |Dictionary| with the following entries:
5186 botline last complete displayed buffer line
5187 bufnr number of buffer in the window
5188 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005189 leftcol first column displayed; only used when
5190 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005191 loclist 1 if showing a location list
5192 {only with the +quickfix feature}
5193 quickfix 1 if quickfix or location list window
5194 {only with the +quickfix feature}
5195 terminal 1 if a terminal window
5196 {only with the +terminal feature}
5197 tabnr tab page number
5198 topline first displayed buffer line
5199 variables a reference to the dictionary with
5200 window-local variables
5201 width window width
5202 winbar 1 if the window has a toolbar, 0
5203 otherwise
5204 wincol leftmost screen column of the window;
5205 "col" from |win_screenpos()|
5206 textoff number of columns occupied by any
5207 'foldcolumn', 'signcolumn' and line
5208 number in front of the text
5209 winid |window-ID|
5210 winnr window number
5211 winrow topmost screen line of the window;
5212 "row" from |win_screenpos()|
5213
5214 Can also be used as a |method|: >
5215 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005216<
5217 Return type: list<dict<any>>
5218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005219
5220getwinpos([{timeout}]) *getwinpos()*
5221 The result is a |List| with two numbers, the result of
5222 |getwinposx()| and |getwinposy()| combined:
5223 [x-pos, y-pos]
5224 {timeout} can be used to specify how long to wait in msec for
5225 a response from the terminal. When omitted 100 msec is used.
5226 Use a longer time for a remote terminal.
5227 When using a value less than 10 and no response is received
5228 within that time, a previously reported position is returned,
5229 if available. This can be used to poll for the position and
5230 do some work in the meantime: >
5231 while 1
5232 let res = getwinpos(1)
5233 if res[0] >= 0
5234 break
5235 endif
5236 " Do some work here
5237 endwhile
5238<
5239
5240 Can also be used as a |method|: >
5241 GetTimeout()->getwinpos()
5242<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005243 Return type: list<number>
5244
5245
5246getwinposx() *getwinposx()*
5247 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005248 the left hand side of the GUI Vim window. Also works for an
5249 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005250 The result will be -1 if the information is not available
5251 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005252 The value can be used with `:winpos`.
5253
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005254 Return type: |Number|
5255
5256
5257getwinposy() *getwinposy()*
5258 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005259 the top of the GUI Vim window. Also works for an xterm (uses
5260 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005261 The result will be -1 if the information is not available
5262 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005263 The value can be used with `:winpos`.
5264
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005265 Return type: |Number|
5266
5267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005268getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5269 Like |gettabwinvar()| for the current tabpage.
5270 Examples: >
5271 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005272 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005273
5274< Can also be used as a |method|: >
5275 GetWinnr()->getwinvar(varname)
5276<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005277 Return type: any, depending on {varname}
5278
5279
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005280glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5281 Expand the file wildcards in {expr}. See |wildcards| for the
5282 use of special characters.
5283
5284 Unless the optional {nosuf} argument is given and is |TRUE|,
5285 the 'suffixes' and 'wildignore' options apply: Names matching
5286 one of the patterns in 'wildignore' will be skipped and
5287 'suffixes' affect the ordering of matches.
5288 'wildignorecase' always applies.
5289
5290 When {list} is present and it is |TRUE| the result is a |List|
5291 with all matching files. The advantage of using a List is,
5292 you also get filenames containing newlines correctly.
5293 Otherwise the result is a String and when there are several
5294 matches, they are separated by <NL> characters.
5295
5296 If the expansion fails, the result is an empty String or List.
5297
5298 You can also use |readdir()| if you need to do complicated
5299 things, such as limiting the number of matches.
5300
5301 A name for a non-existing file is not included. A symbolic
5302 link is only included if it points to an existing file.
5303 However, when the {alllinks} argument is present and it is
5304 |TRUE| then all symbolic links are included.
5305
5306 For most systems backticks can be used to get files names from
5307 any external command. Example: >
5308 :let tagfiles = glob("`find . -name tags -print`")
5309 :let &tags = substitute(tagfiles, "\n", ",", "g")
5310< The result of the program inside the backticks should be one
5311 item per line. Spaces inside an item are allowed.
5312
5313 See |expand()| for expanding special Vim variables. See
5314 |system()| for getting the raw output of an external command.
5315
5316 Can also be used as a |method|: >
5317 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005318<
5319 Return type: |String| or list<string> or list<any> depending
5320 on {list}
5321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005322
h-east624bb832024-11-09 18:37:32 +01005323glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005324 Convert a file pattern, as used by glob(), into a search
5325 pattern. The result can be used to match with a string that
5326 is a file name. E.g. >
5327 if filename =~ glob2regpat('Make*.mak')
5328< This is equivalent to: >
5329 if filename =~ '^Make.*\.mak$'
5330< When {string} is an empty string the result is "^$", match an
5331 empty string.
5332 Note that the result depends on the system. On MS-Windows
5333 a backslash usually means a path separator.
5334
5335 Can also be used as a |method|: >
5336 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005337<
5338 Return type: |String|
5339
5340 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005341globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5342 Perform glob() for String {expr} on all directories in {path}
5343 and concatenate the results. Example: >
5344 :echo globpath(&rtp, "syntax/c.vim")
5345<
5346 {path} is a comma-separated list of directory names. Each
5347 directory name is prepended to {expr} and expanded like with
5348 |glob()|. A path separator is inserted when needed.
5349 To add a comma inside a directory name escape it with a
5350 backslash. Note that on MS-Windows a directory may have a
5351 trailing backslash, remove it if you put a comma after it.
5352 If the expansion fails for one of the directories, there is no
5353 error message.
5354
5355 Unless the optional {nosuf} argument is given and is |TRUE|,
5356 the 'suffixes' and 'wildignore' options apply: Names matching
5357 one of the patterns in 'wildignore' will be skipped and
5358 'suffixes' affect the ordering of matches.
5359
5360 When {list} is present and it is |TRUE| the result is a |List|
5361 with all matching files. The advantage of using a List is, you
5362 also get filenames containing newlines correctly. Otherwise
5363 the result is a String and when there are several matches,
5364 they are separated by <NL> characters. Example: >
5365 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5366<
5367 {alllinks} is used as with |glob()|.
5368
5369 The "**" item can be used to search in a directory tree.
5370 For example, to find all "README.txt" files in the directories
5371 in 'runtimepath' and below: >
5372 :echo globpath(&rtp, "**/README.txt")
5373< Upwards search and limiting the depth of "**" is not
5374 supported, thus using 'path' will not always work properly.
5375
5376 Can also be used as a |method|, the base is passed as the
5377 second argument: >
5378 GetExpr()->globpath(&rtp)
5379<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005380 Return type: |String| or list<string> or list<any> depending
5381 on {list}
5382
5383
5384has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005385 When {check} is omitted or is zero: The result is a Number,
5386 which is 1 if the feature {feature} is supported, zero
5387 otherwise. The {feature} argument is a string, case is
5388 ignored. See |feature-list| below.
5389
5390 When {check} is present and not zero: The result is a Number,
5391 which is 1 if the feature {feature} could ever be supported,
5392 zero otherwise. This is useful to check for a typo in
5393 {feature} and to detect dead code. Keep in mind that an older
5394 Vim version will not know about a feature added later and
5395 features that have been abandoned will not be known by the
5396 current Vim version.
5397
5398 Also see |exists()| and |exists_compiled()|.
5399
5400 Note that to skip code that has a syntax error when the
5401 feature is not available, Vim may skip the rest of the line
5402 and miss a following `endif`. Therefore put the `endif` on a
5403 separate line: >
5404 if has('feature')
5405 let x = this->breaks->without->the->feature
5406 endif
5407< If the `endif` would be moved to the second line as "| endif" it
5408 would not be found.
5409
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005410 Return type: |Number|
5411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005412
5413has_key({dict}, {key}) *has_key()*
5414 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005415 has an entry with key {key}. FALSE otherwise.
5416 The {key} argument is a string. In |Vim9| script a number is
5417 also accepted (and converted to a string) but no other types.
5418 In legacy script the usual automatic conversion to string is
5419 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005420
5421 Can also be used as a |method|: >
5422 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005423<
5424 Return type: |Number|
5425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005426
5427haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5428 The result is a Number:
5429 1 when the window has set a local directory via |:lcd|
5430 2 when the tab-page has set a local directory via |:tcd|
5431 0 otherwise.
5432
5433 Without arguments use the current window.
5434 With {winnr} use this window in the current tab page.
5435 With {winnr} and {tabnr} use the window in the specified tab
5436 page.
5437 {winnr} can be the window number or the |window-ID|.
5438 If {winnr} is -1 it is ignored and only the tabpage is used.
5439 Return 0 if the arguments are invalid.
5440 Examples: >
5441 if haslocaldir() == 1
5442 " window local directory case
5443 elseif haslocaldir() == 2
5444 " tab-local directory case
5445 else
5446 " global directory case
5447 endif
5448
5449 " current window
5450 :echo haslocaldir()
5451 :echo haslocaldir(0)
5452 :echo haslocaldir(0, 0)
5453 " window n in current tab page
5454 :echo haslocaldir(n)
5455 :echo haslocaldir(n, 0)
5456 " window n in tab page m
5457 :echo haslocaldir(n, m)
5458 " tab page m
5459 :echo haslocaldir(-1, m)
5460<
5461 Can also be used as a |method|: >
5462 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005463<
5464 Return type: |Number|
5465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005466
5467hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5468 The result is a Number, which is TRUE if there is a mapping
5469 that contains {what} in somewhere in the rhs (what it is
5470 mapped to) and this mapping exists in one of the modes
5471 indicated by {mode}.
5472 The arguments {what} and {mode} are strings.
5473 When {abbr} is there and it is |TRUE| use abbreviations
5474 instead of mappings. Don't forget to specify Insert and/or
5475 Command-line mode.
5476 Both the global mappings and the mappings local to the current
5477 buffer are checked for a match.
5478 If no matching mapping is found FALSE is returned.
5479 The following characters are recognized in {mode}:
5480 n Normal mode
5481 v Visual and Select mode
5482 x Visual mode
5483 s Select mode
5484 o Operator-pending mode
5485 i Insert mode
5486 l Language-Argument ("r", "f", "t", etc.)
5487 c Command-line mode
5488 When {mode} is omitted, "nvo" is used.
5489
5490 This function is useful to check if a mapping already exists
5491 to a function in a Vim script. Example: >
5492 :if !hasmapto('\ABCdoit')
5493 : map <Leader>d \ABCdoit
5494 :endif
5495< This installs the mapping to "\ABCdoit" only if there isn't
5496 already a mapping to "\ABCdoit".
5497
5498 Can also be used as a |method|: >
5499 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005500<
5501 Return type: |Number|
5502
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005503
5504histadd({history}, {item}) *histadd()*
5505 Add the String {item} to the history {history} which can be
5506 one of: *hist-names*
5507 "cmd" or ":" command line history
5508 "search" or "/" search pattern history
5509 "expr" or "=" typed expression history
5510 "input" or "@" input line history
5511 "debug" or ">" debug command history
5512 empty the current or last used history
5513 The {history} string does not need to be the whole name, one
5514 character is sufficient.
5515 If {item} does already exist in the history, it will be
5516 shifted to become the newest entry.
5517 The result is a Number: TRUE if the operation was successful,
5518 otherwise FALSE is returned.
5519
5520 Example: >
5521 :call histadd("input", strftime("%Y %b %d"))
5522 :let date=input("Enter date: ")
5523< This function is not available in the |sandbox|.
5524
5525 Can also be used as a |method|, the base is passed as the
5526 second argument: >
5527 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005528<
5529 Return type: |Number|
5530
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005531
5532histdel({history} [, {item}]) *histdel()*
5533 Clear {history}, i.e. delete all its entries. See |hist-names|
5534 for the possible values of {history}.
5535
5536 If the parameter {item} evaluates to a String, it is used as a
5537 regular expression. All entries matching that expression will
5538 be removed from the history (if there are any).
5539 Upper/lowercase must match, unless "\c" is used |/\c|.
5540 If {item} evaluates to a Number, it will be interpreted as
5541 an index, see |:history-indexing|. The respective entry will
5542 be removed if it exists.
5543
5544 The result is TRUE for a successful operation, otherwise FALSE
5545 is returned.
5546
5547 Examples:
5548 Clear expression register history: >
5549 :call histdel("expr")
5550<
5551 Remove all entries starting with "*" from the search history: >
5552 :call histdel("/", '^\*')
5553<
5554 The following three are equivalent: >
5555 :call histdel("search", histnr("search"))
5556 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005557 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005558<
5559 To delete the last search pattern and use the last-but-one for
5560 the "n" command and 'hlsearch': >
5561 :call histdel("search", -1)
5562 :let @/ = histget("search", -1)
5563<
5564 Can also be used as a |method|: >
5565 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005566<
5567 Return type: |Number|
5568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005569
5570histget({history} [, {index}]) *histget()*
5571 The result is a String, the entry with Number {index} from
5572 {history}. See |hist-names| for the possible values of
5573 {history}, and |:history-indexing| for {index}. If there is
5574 no such entry, an empty String is returned. When {index} is
5575 omitted, the most recent item from the history is used.
5576
5577 Examples:
5578 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005579 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005580
5581< Define an Ex command ":H {num}" that supports re-execution of
5582 the {num}th entry from the output of |:history|. >
5583 :command -nargs=1 H execute histget("cmd", 0+<args>)
5584<
5585 Can also be used as a |method|: >
5586 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005587<
5588 Return type: |String|
5589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005590
5591histnr({history}) *histnr()*
5592 The result is the Number of the current entry in {history}.
5593 See |hist-names| for the possible values of {history}.
5594 If an error occurred, -1 is returned.
5595
5596 Example: >
5597 :let inp_index = histnr("expr")
5598
5599< Can also be used as a |method|: >
5600 GetHistory()->histnr()
5601<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005602 Return type: |Number|
5603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005604hlexists({name}) *hlexists()*
5605 The result is a Number, which is TRUE if a highlight group
5606 called {name} exists. This is when the group has been
5607 defined in some way. Not necessarily when highlighting has
5608 been defined for it, it may also have been used for a syntax
5609 item.
5610 *highlight_exists()*
5611 Obsolete name: highlight_exists().
5612
5613 Can also be used as a |method|: >
5614 GetName()->hlexists()
5615<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005616 Return type: |Number|
5617
5618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005619hlget([{name} [, {resolve}]]) *hlget()*
5620 Returns a List of all the highlight group attributes. If the
5621 optional {name} is specified, then returns a List with only
5622 the attributes of the specified highlight group. Returns an
5623 empty List if the highlight group {name} is not present.
5624
5625 If the optional {resolve} argument is set to v:true and the
5626 highlight group {name} is linked to another group, then the
5627 link is resolved recursively and the attributes of the
5628 resolved highlight group are returned.
5629
5630 Each entry in the returned List is a Dictionary with the
5631 following items:
5632 cleared boolean flag, set to v:true if the highlight
5633 group attributes are cleared or not yet
5634 specified. See |highlight-clear|.
5635 cterm cterm attributes. See |highlight-cterm|.
5636 ctermbg cterm background color.
5637 See |highlight-ctermbg|.
5638 ctermfg cterm foreground color.
5639 See |highlight-ctermfg|.
5640 ctermul cterm underline color. See |highlight-ctermul|.
5641 default boolean flag, set to v:true if the highlight
5642 group link is a default link. See
5643 |highlight-default|.
5644 font highlight group font. See |highlight-font|.
5645 gui gui attributes. See |highlight-gui|.
5646 guibg gui background color. See |highlight-guibg|.
5647 guifg gui foreground color. See |highlight-guifg|.
5648 guisp gui special color. See |highlight-guisp|.
5649 id highlight group ID.
5650 linksto linked highlight group name.
5651 See |:highlight-link|.
5652 name highlight group name. See |group-name|.
5653 start start terminal keycode. See |highlight-start|.
5654 stop stop terminal keycode. See |highlight-stop|.
5655 term term attributes. See |highlight-term|.
5656
5657 The 'term', 'cterm' and 'gui' items in the above Dictionary
5658 have a dictionary value with the following optional boolean
5659 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5660 'reverse', 'inverse' and 'strikethrough'.
5661
5662 Example(s): >
5663 :echo hlget()
5664 :echo hlget('ModeMsg')
5665 :echo hlget('Number', v:true)
5666<
5667 Can also be used as a |method|: >
5668 GetName()->hlget()
5669<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005670 Return type: list<dict<any>>
5671
5672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005673hlset({list}) *hlset()*
5674 Creates or modifies the attributes of a List of highlight
5675 groups. Each item in {list} is a dictionary containing the
5676 attributes of a highlight group. See |hlget()| for the list of
5677 supported items in this dictionary.
5678
5679 In addition to the items described in |hlget()|, the following
5680 additional items are supported in the dictionary:
5681
5682 force boolean flag to force the creation of
5683 a link for an existing highlight group
5684 with attributes.
5685
5686 The highlight group is identified using the 'name' item and
5687 the 'id' item (if supplied) is ignored. If a highlight group
5688 with a specified name doesn't exist, then it is created.
5689 Otherwise the attributes of an existing highlight group are
5690 modified.
5691
5692 If an empty dictionary value is used for the 'term' or 'cterm'
5693 or 'gui' entries, then the corresponding attributes are
5694 cleared. If the 'cleared' item is set to v:true, then all the
5695 attributes of the highlight group are cleared.
5696
5697 The 'linksto' item can be used to link a highlight group to
5698 another highlight group. See |:highlight-link|.
5699
5700 Returns zero for success, -1 for failure.
5701
5702 Example(s): >
5703 " add bold attribute to the Visual highlight group
5704 :call hlset([#{name: 'Visual',
5705 \ term: #{reverse: 1 , bold: 1}}])
5706 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5707 :let l = hlget()
5708 :call hlset(l)
5709 " clear the Search highlight group
5710 :call hlset([#{name: 'Search', cleared: v:true}])
5711 " clear the 'term' attributes for a highlight group
5712 :call hlset([#{name: 'Title', term: {}}])
5713 " create the MyHlg group linking it to DiffAdd
5714 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5715 " remove the MyHlg group link
5716 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5717 " clear the attributes and a link
5718 :call hlset([#{name: 'MyHlg', cleared: v:true,
5719 \ linksto: 'NONE'}])
5720<
5721 Can also be used as a |method|: >
5722 GetAttrList()->hlset()
5723<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005724 Return type: |Number|
5725
5726hlID({name}) *hlID()*
5727 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005728 with name {name}. When the highlight group doesn't exist,
5729 zero is returned.
5730 This can be used to retrieve information about the highlight
5731 group. For example, to get the background color of the
5732 "Comment" group: >
5733 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5734< *highlightID()*
5735 Obsolete name: highlightID().
5736
5737 Can also be used as a |method|: >
5738 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005739<
5740 Return type: |Number|
5741
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005742
5743hostname() *hostname()*
5744 The result is a String, which is the name of the machine on
5745 which Vim is currently running. Machine names greater than
5746 256 characters long are truncated.
5747
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005748 Return type: |String|
5749
5750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005751iconv({string}, {from}, {to}) *iconv()*
5752 The result is a String, which is the text {string} converted
5753 from encoding {from} to encoding {to}.
5754 When the conversion completely fails an empty string is
5755 returned. When some characters could not be converted they
5756 are replaced with "?".
5757 The encoding names are whatever the iconv() library function
5758 can accept, see ":!man 3 iconv".
5759 Most conversions require Vim to be compiled with the |+iconv|
5760 feature. Otherwise only UTF-8 to latin1 conversion and back
5761 can be done.
5762 This can be used to display messages with special characters,
5763 no matter what 'encoding' is set to. Write the message in
5764 UTF-8 and use: >
5765 echo iconv(utf8_str, "utf-8", &enc)
5766< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5767 from/to UCS-2 is automatically changed to use UTF-8. You
5768 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5769
5770 Can also be used as a |method|: >
5771 GetText()->iconv('latin1', 'utf-8')
5772<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005773 Return type: |String|
5774
5775
h-east624bb832024-11-09 18:37:32 +01005776id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005777 The result is a unique String associated with the {item} and
5778 not with the {item}'s contents. It is only valid while the
5779 {item} exists and is referenced. It is valid only in the
5780 instance of vim that produces the result. The whole idea is
5781 that `id({item})` does not change if the contents of {item}
5782 changes. This is useful as a `key` for creating an identity
5783 dictionary, rather than one based on equals.
5784
5785 This operation does not reference {item} and there is no
5786 function to convert the `id` to the {item}. It may be useful to
5787 have a map of `id` to {item}. The following >
5788 var referenceMap: dict<any>
5789 var id = item->id()
5790 referenceMap[id] = item
5791< prevents {item} from being garbage collected and provides a
5792 way to get the {item} from the `id`.
5793
5794 {item} may be a List, Dictionary, Object, Job, Channel or
5795 Blob. If the item is not a permitted type, or it is a null
5796 value, then an empty String is returned.
5797
5798 Can also be used as a |method|: >
5799 GetItem()->id()
5800<
5801 Return type: |String|
5802
5803
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005804indent({lnum}) *indent()*
5805 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005806 current buffer. The indent is counted in spaces, the value
5807 of 'tabstop' is relevant. {lnum} is used just like in
5808 |getline()|.
5809 When {lnum} is invalid -1 is returned. In |Vim9| script an
5810 error is given.
5811
5812 Can also be used as a |method|: >
5813 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005814<
5815 Return type: |Number|
5816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005817
5818index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005819 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005820 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005822 If {object} is a |List| return the lowest index where the item
5823 has a value equal to {expr}. There is no automatic
5824 conversion, so the String "4" is different from the Number 4.
5825 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005826 of 'ignorecase' is not used here, case matters as indicated by
5827 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005828
5829 If {object} is |Blob| return the lowest index where the byte
5830 value is equal to {expr}.
5831
5832 If {start} is given then start looking at the item with index
5833 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005835 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5836 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005838 -1 is returned when {expr} is not found in {object}.
5839 Example: >
5840 :let idx = index(words, "the")
5841 :if index(numbers, 123) >= 0
5842
5843< Can also be used as a |method|: >
5844 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005845<
5846 Return type: |Number|
5847
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005848
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005849indexof({object}, {expr} [, {opts}]) *indexof()*
5850 Returns the index of an item in {object} where {expr} is
5851 v:true. {object} must be a |List| or a |Blob|.
5852
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005853 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005854 List until the expression is v:true and return the index of
5855 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005856
5857 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005858 Blob until the expression is v:true and return the index of
5859 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005860
5861 {expr} must be a |string| or |Funcref|.
5862
5863 If {expr} is a |string|: If {object} is a |List|, inside
5864 {expr} |v:key| has the index of the current List item and
5865 |v:val| has the value of the item. If {object} is a |Blob|,
5866 inside {expr} |v:key| has the index of the current byte and
5867 |v:val| has the byte value.
5868
5869 If {expr} is a |Funcref| it must take two arguments:
5870 1. the key or the index of the current item.
5871 2. the value of the current item.
5872 The function must return |TRUE| if the item is found and the
5873 search should stop.
5874
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005875 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005876 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005877 startidx start evaluating {expr} at the item with this
5878 index; may be negative for an item relative to
5879 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005880 Returns -1 when {expr} evaluates to v:false for all the items.
5881 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005882 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5883 :echo indexof(l, "v:val.n == 20")
5884 :echo indexof(l, {i, v -> v.n == 30})
5885 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005886
5887< Can also be used as a |method|: >
5888 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005889<
5890 Return type: |Number|
5891
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005893input({prompt} [, {text} [, {completion}]]) *input()*
5894 The result is a String, which is whatever the user typed on
5895 the command-line. The {prompt} argument is either a prompt
5896 string, or a blank string (for no prompt). A '\n' can be used
5897 in the prompt to start a new line.
5898 The highlighting set with |:echohl| is used for the prompt.
5899 The input is entered just like a command-line, with the same
5900 editing commands and mappings. There is a separate history
5901 for lines typed for input().
5902 Example: >
5903 :if input("Coffee or beer? ") == "beer"
5904 : echo "Cheers!"
5905 :endif
5906<
5907 If the optional {text} argument is present and not empty, this
5908 is used for the default reply, as if the user typed this.
5909 Example: >
5910 :let color = input("Color? ", "white")
5911
5912< The optional {completion} argument specifies the type of
5913 completion supported for the input. Without it completion is
5914 not performed. The supported completion types are the same as
5915 that can be supplied to a user-defined command using the
5916 "-complete=" argument. Refer to |:command-completion| for
5917 more information. Example: >
5918 let fname = input("File: ", "", "file")
5919<
5920 NOTE: This function must not be used in a startup file, for
5921 the versions that only run in GUI mode (e.g., the Win32 GUI).
5922 Note: When input() is called from within a mapping it will
5923 consume remaining characters from that mapping, because a
5924 mapping is handled like the characters were typed.
5925 Use |inputsave()| before input() and |inputrestore()|
5926 after input() to avoid that. Another solution is to avoid
5927 that further characters follow in the mapping, e.g., by using
5928 |:execute| or |:normal|.
5929
5930 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005931 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005932 :function GetFoo()
5933 : call inputsave()
5934 : let g:Foo = input("enter search pattern: ")
5935 : call inputrestore()
5936 :endfunction
5937
5938< Can also be used as a |method|: >
5939 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005940<
5941 Return type: |String|
5942
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005943
5944inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5945 Like |input()|, but when the GUI is running and text dialogs
5946 are supported, a dialog window pops up to input the text.
5947 Example: >
5948 :let n = inputdialog("value for shiftwidth", shiftwidth())
5949 :if n != ""
5950 : let &sw = n
5951 :endif
5952< When the dialog is cancelled {cancelreturn} is returned. When
5953 omitted an empty string is returned.
5954 Hitting <Enter> works like pressing the OK button. Hitting
5955 <Esc> works like pressing the Cancel button.
5956 NOTE: Command-line completion is not supported.
5957
5958 Can also be used as a |method|: >
5959 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005960<
5961 Return type: |String|
5962
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005963
5964inputlist({textlist}) *inputlist()*
5965 {textlist} must be a |List| of strings. This |List| is
5966 displayed, one string per line. The user will be prompted to
5967 enter a number, which is returned.
5968 The user can also select an item by clicking on it with the
5969 mouse, if the mouse is enabled in the command line ('mouse' is
5970 "a" or includes "c"). For the first string 0 is returned.
5971 When clicking above the first item a negative number is
5972 returned. When clicking on the prompt one more than the
5973 length of {textlist} is returned.
5974 Make sure {textlist} has less than 'lines' entries, otherwise
5975 it won't work. It's a good idea to put the entry number at
5976 the start of the string. And put a prompt in the first item.
5977 Example: >
5978 let color = inputlist(['Select color:', '1. red',
5979 \ '2. green', '3. blue'])
5980
5981< Can also be used as a |method|: >
5982 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005983<
5984 Return type: |Number|
5985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005986
5987inputrestore() *inputrestore()*
5988 Restore typeahead that was saved with a previous |inputsave()|.
5989 Should be called the same number of times inputsave() is
5990 called. Calling it more often is harmless though.
5991 Returns TRUE when there is nothing to restore, FALSE otherwise.
5992
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005993 Return type: |Number|
5994
5995
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005996inputsave() *inputsave()*
5997 Preserve typeahead (also from mappings) and clear it, so that
5998 a following prompt gets input from the user. Should be
5999 followed by a matching inputrestore() after the prompt. Can
6000 be used several times, in which case there must be just as
6001 many inputrestore() calls.
6002 Returns TRUE when out of memory, FALSE otherwise.
6003
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006004 Return type: |Number|
6005
6006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006007inputsecret({prompt} [, {text}]) *inputsecret()*
6008 This function acts much like the |input()| function with but
6009 two exceptions:
6010 a) the user's response will be displayed as a sequence of
6011 asterisks ("*") thereby keeping the entry secret, and
6012 b) the user's response will not be recorded on the input
6013 |history| stack.
6014 The result is a String, which is whatever the user actually
6015 typed on the command-line in response to the issued prompt.
6016 NOTE: Command-line completion is not supported.
6017
6018 Can also be used as a |method|: >
6019 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006020<
6021 Return type: |String|
6022
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006023
6024insert({object}, {item} [, {idx}]) *insert()*
6025 When {object} is a |List| or a |Blob| insert {item} at the start
6026 of it.
6027
6028 If {idx} is specified insert {item} before the item with index
6029 {idx}. If {idx} is zero it goes before the first item, just
6030 like omitting {idx}. A negative {idx} is also possible, see
6031 |list-index|. -1 inserts just before the last item.
6032
6033 Returns the resulting |List| or |Blob|. Examples: >
6034 :let mylist = insert([2, 3, 5], 1)
6035 :call insert(mylist, 4, -1)
6036 :call insert(mylist, 6, len(mylist))
6037< The last example can be done simpler with |add()|.
6038 Note that when {item} is a |List| it is inserted as a single
6039 item. Use |extend()| to concatenate |Lists|.
6040
6041 Can also be used as a |method|: >
6042 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006043<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006044 Return type: |Number|
6045
6046
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006047 *instanceof()* *E614* *E616* *E693*
6048instanceof({object}, {class})
6049 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006050 argument is a direct or indirect instance of a |Class|,
6051 |Interface|, or class |:type| alias specified by {class}.
6052 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006053 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006054 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006055 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006056
6057< Can also be used as a |method|: >
6058 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006059<
6060 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006062interrupt() *interrupt()*
6063 Interrupt script execution. It works more or less like the
6064 user typing CTRL-C, most commands won't execute and control
6065 returns to the user. This is useful to abort execution
6066 from lower down, e.g. in an autocommand. Example: >
6067 :function s:check_typoname(file)
6068 : if fnamemodify(a:file, ':t') == '['
6069 : echomsg 'Maybe typo'
6070 : call interrupt()
6071 : endif
6072 :endfunction
6073 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006074<
6075 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006076
6077invert({expr}) *invert()*
6078 Bitwise invert. The argument is converted to a number. A
6079 List, Dict or Float argument causes an error. Example: >
6080 :let bits = invert(bits)
6081< Can also be used as a |method|: >
6082 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006083<
6084 Return type: |Number|
6085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006086
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006087isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006088 The result is a Number, which is |TRUE| when {path} is an
6089 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006090 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006091 On MS-Windows, it is considered absolute when it starts with an
6092 optional drive prefix and is followed by a '\' or '/'. UNC paths
6093 are always absolute.
6094 Example: >
6095 echo isabsolutepath('/usr/share/') " 1
6096 echo isabsolutepath('./foobar') " 0
6097 echo isabsolutepath('C:\Windows') " 1
6098 echo isabsolutepath('foobar') " 0
6099 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006100<
LemonBoydca1d402022-04-28 15:26:33 +01006101 Can also be used as a |method|: >
6102 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006103<
6104 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006105
6106
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006107isdirectory({directory}) *isdirectory()*
6108 The result is a Number, which is |TRUE| when a directory
6109 with the name {directory} exists. If {directory} doesn't
6110 exist, or isn't a directory, the result is |FALSE|. {directory}
6111 is any expression, which is used as a String.
6112
6113 Can also be used as a |method|: >
6114 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006115<
6116 Return type: |Number|
6117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006118
6119isinf({expr}) *isinf()*
6120 Return 1 if {expr} is a positive infinity, or -1 a negative
6121 infinity, otherwise 0. >
6122 :echo isinf(1.0 / 0.0)
6123< 1 >
6124 :echo isinf(-1.0 / 0.0)
6125< -1
6126
6127 Can also be used as a |method|: >
6128 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006129<
6130 Return type: |Number|
6131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006132
6133islocked({expr}) *islocked()* *E786*
6134 The result is a Number, which is |TRUE| when {expr} is the
6135 name of a locked variable.
6136 The string argument {expr} must be the name of a variable,
6137 |List| item or |Dictionary| entry, not the variable itself!
6138 Example: >
6139 :let alist = [0, ['a', 'b'], 2, 3]
6140 :lockvar 1 alist
6141 :echo islocked('alist') " 1
6142 :echo islocked('alist[1]') " 0
6143
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006144< When {expr} is a variable that does not exist -1 is returned.
6145 If {expr} uses a range, list or dict index that is out of
6146 range or does not exist you get an error message. Use
6147 |exists()| to check for existence.
6148 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006149
6150 Can also be used as a |method|: >
6151 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006152<
6153 Return type: |Number|
6154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006155
6156isnan({expr}) *isnan()*
6157 Return |TRUE| if {expr} is a float with value NaN. >
6158 echo isnan(0.0 / 0.0)
6159< 1
6160
6161 Can also be used as a |method|: >
6162 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006163<
6164 Return type: |Number|
6165
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006166
6167items({dict}) *items()*
6168 Return a |List| with all the key-value pairs of {dict}. Each
6169 |List| item is a list with two items: the key of a {dict}
6170 entry and the value of this entry. The |List| is in arbitrary
6171 order. Also see |keys()| and |values()|.
6172 Example: >
6173 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006174 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006175 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006176<
6177 A List or a String argument is also supported. In these
6178 cases, items() returns a List with the index and the value at
6179 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006180
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006181 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006182 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006183<
6184 Return type: list<list<any>> or list<any>
6185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006186
6187job_ functions are documented here: |job-functions-details|
6188
6189
6190join({list} [, {sep}]) *join()*
6191 Join the items in {list} together into one String.
6192 When {sep} is specified it is put in between the items. If
6193 {sep} is omitted a single space is used.
6194 Note that {sep} is not added at the end. You might want to
6195 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006196 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006197< String items are used as-is. |Lists| and |Dictionaries| are
6198 converted into a string like with |string()|.
6199 The opposite function is |split()|.
6200
6201 Can also be used as a |method|: >
6202 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006203<
6204 Return type: |String|
6205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006206
6207js_decode({string}) *js_decode()*
6208 This is similar to |json_decode()| with these differences:
6209 - Object key names do not have to be in quotes.
6210 - Strings can be in single quotes.
6211 - Empty items in an array (between two commas) are allowed and
6212 result in v:none items.
6213
6214 Can also be used as a |method|: >
6215 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006216<
6217 Return type: any, depending on {varname}
6218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006219
6220js_encode({expr}) *js_encode()*
6221 This is similar to |json_encode()| with these differences:
6222 - Object key names are not in quotes.
6223 - v:none items in an array result in an empty item between
6224 commas.
6225 For example, the Vim object:
6226 [1,v:none,{"one":1},v:none] ~
6227 Will be encoded as:
6228 [1,,{one:1},,] ~
6229 While json_encode() would produce:
6230 [1,null,{"one":1},null] ~
6231 This encoding is valid for JavaScript. It is more efficient
6232 than JSON, especially when using an array with optional items.
6233
6234 Can also be used as a |method|: >
6235 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006236<
6237 Return type: |String|
6238
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006239
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006240json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006241 This parses a JSON formatted string and returns the equivalent
6242 in Vim values. See |json_encode()| for the relation between
6243 JSON and Vim values.
6244 The decoding is permissive:
6245 - A trailing comma in an array and object is ignored, e.g.
6246 "[1, 2, ]" is the same as "[1, 2]".
6247 - Integer keys are accepted in objects, e.g. {1:2} is the
6248 same as {"1":2}.
6249 - More floating point numbers are recognized, e.g. "1." for
6250 "1.0", or "001.2" for "1.2". Special floating point values
6251 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6252 are accepted.
6253 - Leading zeroes in integer numbers are ignored, e.g. "012"
6254 for "12" or "-012" for "-12".
6255 - Capitalization is ignored in literal names null, true or
6256 false, e.g. "NULL" for "null", "True" for "true".
6257 - Control characters U+0000 through U+001F which are not
6258 escaped in strings are accepted, e.g. " " (tab
6259 character in string) for "\t".
6260 - An empty JSON expression or made of only spaces is accepted
6261 and results in v:none.
6262 - Backslash in an invalid 2-character sequence escape is
6263 ignored, e.g. "\a" is decoded as "a".
6264 - A correct surrogate pair in JSON strings should normally be
6265 a 12 character sequence such as "\uD834\uDD1E", but
6266 json_decode() silently accepts truncated surrogate pairs
6267 such as "\uD834" or "\uD834\u"
6268 *E938*
6269 A duplicate key in an object, valid in rfc7159, is not
6270 accepted by json_decode() as the result must be a valid Vim
6271 type, e.g. this fails: {"a":"b", "a":"c"}
6272
6273 Can also be used as a |method|: >
6274 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006275<
6276 Return type: any, depending on {varname}
6277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006278
6279json_encode({expr}) *json_encode()*
6280 Encode {expr} as JSON and return this as a string.
6281 The encoding is specified in:
6282 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006283 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006284 |Number| decimal number
6285 |Float| floating point number
6286 Float nan "NaN"
6287 Float inf "Infinity"
6288 Float -inf "-Infinity"
6289 |String| in double quotes (possibly null)
6290 |Funcref| not possible, error
6291 |List| as an array (possibly null); when
6292 used recursively: []
6293 |Dict| as an object (possibly null); when
6294 used recursively: {}
6295 |Blob| as an array of the individual bytes
6296 v:false "false"
6297 v:true "true"
6298 v:none "null"
6299 v:null "null"
6300 Note that NaN and Infinity are passed on as values. This is
6301 missing in the JSON standard, but several implementations do
6302 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006303 If a string contains an illegal character then the replacement
6304 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006305
6306 Can also be used as a |method|: >
6307 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006308<
6309 Return type: |String|
6310
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006311
6312keys({dict}) *keys()*
6313 Return a |List| with all the keys of {dict}. The |List| is in
6314 arbitrary order. Also see |items()| and |values()|.
6315
6316 Can also be used as a |method|: >
6317 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006318<
6319 Return type: list<string>
6320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006321
zeertzjqcdc83932022-09-12 13:38:41 +01006322keytrans({string}) *keytrans()*
6323 Turn the internal byte representation of keys into a form that
6324 can be used for |:map|. E.g. >
6325 :let xx = "\<C-Home>"
6326 :echo keytrans(xx)
6327< <C-Home>
6328
6329 Can also be used as a |method|: >
6330 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006331<
6332 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006333
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006334
6335len({expr}) *len()* *E701*
6336 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006337 When {expr} is a String or a Number the length in bytes is
6338 used, as with |strlen()|.
6339 When {expr} is a |List| the number of items in the |List| is
6340 returned.
6341 When {expr} is a |Blob| the number of bytes is returned.
6342 When {expr} is a |Dictionary| the number of entries in the
6343 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006344 When {expr} is an |Object|, invokes the len() method in the
6345 object (if present) to get the length (|object-len()|).
6346 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006347
6348 Can also be used as a |method|: >
6349 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006350<
6351 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006352
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006353
6354 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006355libcall({libname}, {funcname}, {argument})
6356 Call function {funcname} in the run-time library {libname}
6357 with single argument {argument}.
6358 This is useful to call functions in a library that you
6359 especially made to be used with Vim. Since only one argument
6360 is possible, calling standard library functions is rather
6361 limited.
6362 The result is the String returned by the function. If the
6363 function returns NULL, this will appear as an empty string ""
6364 to Vim.
6365 If the function returns a number, use libcallnr()!
6366 If {argument} is a number, it is passed to the function as an
6367 int; if {argument} is a string, it is passed as a
6368 null-terminated string.
6369 This function will fail in |restricted-mode|.
6370
6371 libcall() allows you to write your own 'plug-in' extensions to
6372 Vim without having to recompile the program. It is NOT a
6373 means to call system functions! If you try to do so Vim will
6374 very probably crash.
6375
6376 For Win32, the functions you write must be placed in a DLL
6377 and use the normal C calling convention (NOT Pascal which is
6378 used in Windows System DLLs). The function must take exactly
6379 one parameter, either a character pointer or a long integer,
6380 and must return a character pointer or NULL. The character
6381 pointer returned must point to memory that will remain valid
6382 after the function has returned (e.g. in static data in the
6383 DLL). If it points to allocated memory, that memory will
6384 leak away. Using a static buffer in the function should work,
6385 it's then freed when the DLL is unloaded.
6386
6387 WARNING: If the function returns a non-valid pointer, Vim may
6388 crash! This also happens if the function returns a number,
6389 because Vim thinks it's a pointer.
6390 For Win32 systems, {libname} should be the filename of the DLL
6391 without the ".DLL" suffix. A full path is only required if
6392 the DLL is not in the usual places.
6393 For Unix: When compiling your own plugins, remember that the
6394 object code must be compiled as position-independent ('PIC').
6395 {only in Win32 and some Unix versions, when the |+libcall|
6396 feature is present}
6397 Examples: >
6398 :echo libcall("libc.so", "getenv", "HOME")
6399
6400< Can also be used as a |method|, the base is passed as the
6401 third argument: >
6402 GetValue()->libcall("libc.so", "getenv")
6403<
6404 *libcallnr()*
6405libcallnr({libname}, {funcname}, {argument})
6406 Just like |libcall()|, but used for a function that returns an
6407 int instead of a string.
6408 {only in Win32 on some Unix versions, when the |+libcall|
6409 feature is present}
6410 Examples: >
6411 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6412 :call libcallnr("libc.so", "printf", "Hello World!\n")
6413 :call libcallnr("libc.so", "sleep", 10)
6414<
6415 Can also be used as a |method|, the base is passed as the
6416 third argument: >
6417 GetValue()->libcallnr("libc.so", "printf")
6418<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006419 Return type: |String|
6420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006421
6422line({expr} [, {winid}]) *line()*
6423 The result is a Number, which is the line number of the file
6424 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006425 See |getpos()| for accepted positions.
6426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006427 To get the column number use |col()|. To get both use
6428 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006430 With the optional {winid} argument the values are obtained for
6431 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006432
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006433 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006435 Examples: >
6436 line(".") line number of the cursor
6437 line(".", winid) idem, in window "winid"
6438 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006439 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006440<
6441 To jump to the last known position when opening a file see
6442 |last-position-jump|.
6443
6444 Can also be used as a |method|: >
6445 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006446<
6447 Return type: |Number|
6448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006449
6450line2byte({lnum}) *line2byte()*
6451 Return the byte count from the start of the buffer for line
6452 {lnum}. This includes the end-of-line character, depending on
6453 the 'fileformat' option for the current buffer. The first
6454 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6455 This can also be used to get the byte count for the line just
6456 below the last line: >
6457 line2byte(line("$") + 1)
6458< This is the buffer size plus one. If 'fileencoding' is empty
6459 it is the file size plus one. {lnum} is used like with
6460 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6461 feature has been disabled at compile time, -1 is returned.
6462 Also see |byte2line()|, |go| and |:goto|.
6463
6464 Can also be used as a |method|: >
6465 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006466<
6467 Return type: |Number|
6468
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006469
6470lispindent({lnum}) *lispindent()*
6471 Get the amount of indent for line {lnum} according the lisp
6472 indenting rules, as with 'lisp'.
6473 The indent is counted in spaces, the value of 'tabstop' is
6474 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006475 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006476 error is given.
6477
6478 Can also be used as a |method|: >
6479 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006480<
6481 Return type: |Number|
6482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006483
6484list2blob({list}) *list2blob()*
6485 Return a Blob concatenating all the number values in {list}.
6486 Examples: >
6487 list2blob([1, 2, 3, 4]) returns 0z01020304
6488 list2blob([]) returns 0z
6489< Returns an empty Blob on error. If one of the numbers is
6490 negative or more than 255 error *E1239* is given.
6491
6492 |blob2list()| does the opposite.
6493
6494 Can also be used as a |method|: >
6495 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006496<
6497 Return type: |Blob|
6498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006499
6500list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006501 Convert each number in {list} to a character string and
6502 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006503 list2str([32]) returns " "
6504 list2str([65, 66, 67]) returns "ABC"
6505< The same can be done (slowly) with: >
6506 join(map(list, {nr, val -> nr2char(val)}), '')
6507< |str2list()| does the opposite.
6508
6509 When {utf8} is omitted or zero, the current 'encoding' is used.
6510 When {utf8} is TRUE, always return UTF-8 characters.
6511 With UTF-8 composing characters work as expected: >
6512 list2str([97, 769]) returns "á"
6513<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006514 Returns an empty string on error.
6515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006516 Can also be used as a |method|: >
6517 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006518<
6519 Return type: |String|
6520
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006521
6522listener_add({callback} [, {buf}]) *listener_add()*
6523 Add a callback function that will be invoked when changes have
6524 been made to buffer {buf}.
6525 {buf} refers to a buffer name or number. For the accepted
6526 values, see |bufname()|. When {buf} is omitted the current
6527 buffer is used.
6528 Returns a unique ID that can be passed to |listener_remove()|.
6529
6530 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006531 bufnr the buffer that was changed
6532 start first changed line number
6533 end first line number below the change
6534 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006535 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006536 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006537
6538 Example: >
6539 func Listener(bufnr, start, end, added, changes)
6540 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6541 endfunc
6542 call listener_add('Listener', bufnr)
6543
Bram Moolenaar944697a2022-02-20 19:48:20 +00006544< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006545 dictionary with these entries:
6546 lnum the first line number of the change
6547 end the first line below the change
6548 added number of lines added; negative if lines were
6549 deleted
6550 col first column in "lnum" that was affected by
6551 the change; one if unknown or the whole line
6552 was affected; this is a byte index, first
6553 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006554 When lines are inserted (not when a line is split, e.g. by
6555 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006556 lnum line above which the new line is added
6557 end equal to "lnum"
6558 added number of lines inserted
6559 col 1
6560 When lines are deleted the values are:
6561 lnum the first deleted line
6562 end the line below the first deleted line, before
6563 the deletion was done
6564 added negative, number of lines deleted
6565 col 1
6566 When lines are changed:
6567 lnum the first changed line
6568 end the line below the last changed line
6569 added 0
6570 col first column with a change or 1
6571
6572 The entries are in the order the changes were made, thus the
6573 most recent change is at the end. The line numbers are valid
6574 when the callback is invoked, but later changes may make them
6575 invalid, thus keeping a copy for later might not work.
6576
6577 The {callback} is invoked just before the screen is updated,
6578 when |listener_flush()| is called or when a change is being
6579 made that changes the line count in a way it causes a line
6580 number in the list of changes to become invalid.
6581
6582 The {callback} is invoked with the text locked, see
6583 |textlock|. If you do need to make changes to the buffer, use
6584 a timer to do this later |timer_start()|.
6585
6586 The {callback} is not invoked when the buffer is first loaded.
6587 Use the |BufReadPost| autocmd event to handle the initial text
6588 of a buffer.
6589 The {callback} is also not invoked when the buffer is
6590 unloaded, use the |BufUnload| autocmd event for that.
6591
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006592 Returns zero if {callback} or {buf} is invalid.
6593
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006594 Can also be used as a |method|, the base is passed as the
6595 second argument: >
6596 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006597<
6598 Return type: |Number|
6599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006600
6601listener_flush([{buf}]) *listener_flush()*
6602 Invoke listener callbacks for buffer {buf}. If there are no
6603 pending changes then no callbacks are invoked.
6604
6605 {buf} refers to a buffer name or number. For the accepted
6606 values, see |bufname()|. When {buf} is omitted the current
6607 buffer is used.
6608
6609 Can also be used as a |method|: >
6610 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006611<
6612 Return type: |Number|
6613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006614
6615listener_remove({id}) *listener_remove()*
6616 Remove a listener previously added with listener_add().
6617 Returns FALSE when {id} could not be found, TRUE when {id} was
6618 removed.
6619
6620 Can also be used as a |method|: >
6621 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006622<
6623 Return type: |Number|
6624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006625
6626localtime() *localtime()*
6627 Return the current time, measured as seconds since 1st Jan
6628 1970. See also |strftime()|, |strptime()| and |getftime()|.
6629
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006630 Return type: |Number|
6631
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006632
6633log({expr}) *log()*
6634 Return the natural logarithm (base e) of {expr} as a |Float|.
6635 {expr} must evaluate to a |Float| or a |Number| in the range
6636 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006637 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006638 Examples: >
6639 :echo log(10)
6640< 2.302585 >
6641 :echo log(exp(5))
6642< 5.0
6643
6644 Can also be used as a |method|: >
6645 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006646<
6647 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006648
6649
6650log10({expr}) *log10()*
6651 Return the logarithm of Float {expr} to base 10 as a |Float|.
6652 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006653 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006654 Examples: >
6655 :echo log10(1000)
6656< 3.0 >
6657 :echo log10(0.01)
6658< -2.0
6659
6660 Can also be used as a |method|: >
6661 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006662<
6663 Return type: |Float|
6664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006665
6666luaeval({expr} [, {expr}]) *luaeval()*
6667 Evaluate Lua expression {expr} and return its result converted
6668 to Vim data structures. Second {expr} may hold additional
6669 argument accessible as _A inside first {expr}.
6670 Strings are returned as they are.
6671 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006672 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006673 Dictionaries and lists obtained by vim.eval() are returned
6674 as-is.
6675 Other objects are returned as zero without any errors.
6676 See |lua-luaeval| for more details.
6677 Note that in a `:def` function local variables are not visible
6678 to {expr}.
6679
6680 Can also be used as a |method|: >
6681 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006682<
6683 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006684
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006685 {only available when compiled with the |+lua| feature}
6686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006687
6688map({expr1}, {expr2}) *map()*
6689 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006690 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006691 item in {expr1} with the result of evaluating {expr2}.
6692 For a |Blob| each byte is replaced.
6693 For a |String|, each character, including composing
6694 characters, is replaced.
6695 If the item type changes you may want to use |mapnew()| to
6696 create a new List or Dictionary. This is required when using
6697 Vim9 script.
6698
6699 {expr2} must be a |String| or |Funcref|.
6700
6701 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6702 of the current item. For a |Dictionary| |v:key| has the key
6703 of the current item and for a |List| |v:key| has the index of
6704 the current item. For a |Blob| |v:key| has the index of the
6705 current byte. For a |String| |v:key| has the index of the
6706 current character.
6707 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006708 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006709< This puts "> " before and " <" after each item in "mylist".
6710
6711 Note that {expr2} is the result of an expression and is then
6712 used as an expression again. Often it is good to use a
6713 |literal-string| to avoid having to double backslashes. You
6714 still have to double ' quotes
6715
6716 If {expr2} is a |Funcref| it is called with two arguments:
6717 1. The key or the index of the current item.
6718 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006719 With a legacy script lambda you don't get an error if it only
6720 accepts one argument, but with a Vim9 lambda you get "E1106:
6721 One argument too many", the number of arguments must match.
6722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006723 The function must return the new value of the item. Example
6724 that changes each value by "key-value": >
6725 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006726 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006727 endfunc
6728 call map(myDict, function('KeyValue'))
6729< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006730 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006731< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006732 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006733< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006734 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006735<
6736 The operation is done in-place for a |List| and |Dictionary|.
6737 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006738 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006739
6740< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6741 or a new |Blob| or |String|.
6742 When an error is encountered while evaluating {expr2} no
6743 further items in {expr1} are processed.
6744 When {expr2} is a Funcref errors inside a function are ignored,
6745 unless it was defined with the "abort" flag.
6746
6747 Can also be used as a |method|: >
6748 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006749<
6750 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6751 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006752
6753
6754maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6755 When {dict} is omitted or zero: Return the rhs of mapping
6756 {name} in mode {mode}. The returned String has special
6757 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006758 listing. When {dict} is TRUE a dictionary is returned, see
6759 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006760
6761 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006762 returned if {dict} is FALSE, otherwise returns an empty Dict.
6763 When the mapping for {name} is empty, then "<Nop>" is
6764 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006765
6766 The {name} can have special key names, like in the ":map"
6767 command.
6768
6769 {mode} can be one of these strings:
6770 "n" Normal
6771 "v" Visual (including Select)
6772 "o" Operator-pending
6773 "i" Insert
6774 "c" Cmd-line
6775 "s" Select
6776 "x" Visual
6777 "l" langmap |language-mapping|
6778 "t" Terminal-Job
6779 "" Normal, Visual and Operator-pending
6780 When {mode} is omitted, the modes for "" are used.
6781
6782 When {abbr} is there and it is |TRUE| use abbreviations
6783 instead of mappings.
6784
6785 When {dict} is there and it is |TRUE| return a dictionary
6786 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006787 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006788 "lhs" The {lhs} of the mapping as it would be typed
6789 "lhsraw" The {lhs} of the mapping as raw bytes
6790 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6791 form, only present when it differs from "lhsraw"
6792 "rhs" The {rhs} of the mapping as typed.
6793 "silent" 1 for a |:map-silent| mapping, else 0.
6794 "noremap" 1 if the {rhs} of the mapping is not remappable.
6795 "script" 1 if mapping was defined with <script>.
6796 "expr" 1 for an expression mapping (|:map-<expr>|).
6797 "buffer" 1 for a buffer local mapping (|:map-local|).
6798 "mode" Modes for which the mapping is defined. In
6799 addition to the modes mentioned above, these
6800 characters will be used:
6801 " " Normal, Visual and Operator-pending
6802 "!" Insert and Commandline mode
6803 (|mapmode-ic|)
6804 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006805 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006806 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006807 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006808 "lnum" The line number in "sid", zero if unknown.
6809 "nowait" Do not wait for other, longer mappings.
6810 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006811 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006812 "mode_bits" Vim's internal binary representation of "mode".
6813 |mapset()| ignores this; only "mode" is used.
6814 See |maplist()| for usage examples. The values
6815 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006816
6817 The dictionary can be used to restore a mapping with
6818 |mapset()|.
6819
6820 The mappings local to the current buffer are checked first,
6821 then the global mappings.
6822 This function can be used to map a key even when it's already
6823 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006824 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006825
6826< Can also be used as a |method|: >
6827 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006828<
6829 Return type: |String| or dict<any> depending on {dict}
6830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006831
6832mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6833 Check if there is a mapping that matches with {name} in mode
6834 {mode}. See |maparg()| for {mode} and special names in
6835 {name}.
6836 When {abbr} is there and it is |TRUE| use abbreviations
6837 instead of mappings.
6838 A match happens with a mapping that starts with {name} and
6839 with a mapping which is equal to the start of {name}.
6840
6841 matches mapping "a" "ab" "abc" ~
6842 mapcheck("a") yes yes yes
6843 mapcheck("abc") yes yes yes
6844 mapcheck("ax") yes no no
6845 mapcheck("b") no no no
6846
6847 The difference with maparg() is that mapcheck() finds a
6848 mapping that matches with {name}, while maparg() only finds a
6849 mapping for {name} exactly.
6850 When there is no mapping that starts with {name}, an empty
6851 String is returned. If there is one, the RHS of that mapping
6852 is returned. If there are several mappings that start with
6853 {name}, the RHS of one of them is returned. This will be
6854 "<Nop>" if the RHS is empty.
6855 The mappings local to the current buffer are checked first,
6856 then the global mappings.
6857 This function can be used to check if a mapping can be added
6858 without being ambiguous. Example: >
6859 :if mapcheck("_vv") == ""
6860 : map _vv :set guifont=7x13<CR>
6861 :endif
6862< This avoids adding the "_vv" mapping when there already is a
6863 mapping for "_v" or for "_vvv".
6864
6865 Can also be used as a |method|: >
6866 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006867<
6868 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006869
6870
Ernie Rael09661202022-04-25 14:40:44 +01006871maplist([{abbr}]) *maplist()*
6872 Returns a |List| of all mappings. Each List item is a |Dict|,
6873 the same as what is returned by |maparg()|, see
6874 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6875 abbreviations instead of mappings.
6876
6877 Example to show all mappings with 'MultiMatch' in rhs: >
6878 vim9script
6879 echo maplist()->filter(
6880 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006881< It can be tricky to find mappings for particular |:map-modes|.
6882 |mapping-dict|'s "mode_bits" can simplify this. For example,
6883 the mode_bits for Normal, Insert or Command-line modes are
6884 0x19. To find all the mappings available in those modes you
6885 can do: >
6886 vim9script
6887 var saved_maps = []
6888 for m in maplist()
6889 if and(m.mode_bits, 0x19) != 0
6890 saved_maps->add(m)
6891 endif
6892 endfor
6893 echo saved_maps->mapnew((_, m) => m.lhs)
6894< The values of the mode_bits are defined in Vim's src/vim.h
6895 file and they can be discovered at runtime using
6896 |:map-commands| and "maplist()". Example: >
6897 vim9script
6898 omap xyzzy <Nop>
6899 var op_bit = maplist()->filter(
6900 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6901 ounmap xyzzy
6902 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006903<
6904 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006905
6906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006907mapnew({expr1}, {expr2}) *mapnew()*
6908 Like |map()| but instead of replacing items in {expr1} a new
6909 List or Dictionary is created and returned. {expr1} remains
6910 unchanged. Items can still be changed by {expr2}, if you
6911 don't want that use |deepcopy()| first.
6912
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006913 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6914 depending on {expr1}
6915
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006916
6917mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006918mapset({dict})
6919 Restore a mapping from a dictionary, possibly returned by
6920 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6921 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006922 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006923 feature allows copying mappings from one buffer to another.
6924 The dict.mode value may restore a single mapping that covers
6925 more than one mode, like with mode values of '!', ' ', 'nox',
6926 or 'v'. *E1276*
6927
6928 In the first form, {mode} and {abbr} should be the same as
6929 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006930 {mode} is used to define the mode in which the mapping is set,
6931 not the "mode" entry in {dict}.
6932 Example for saving and restoring a mapping: >
6933 let save_map = maparg('K', 'n', 0, 1)
6934 nnoremap K somethingelse
6935 ...
6936 call mapset('n', 0, save_map)
6937< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006938 e.g. with `:map!`, you need to save/restore the mapping for
6939 all of them, when they might differ.
6940
6941 In the second form, with {dict} as the only argument, mode
6942 and abbr are taken from the dict.
6943 Example: >
6944 vim9script
6945 var save_maps = maplist()->filter(
6946 (_, m) => m.lhs == 'K')
6947 nnoremap K somethingelse
6948 cnoremap K somethingelse2
6949 # ...
6950 unmap K
6951 for d in save_maps
6952 mapset(d)
6953 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006954<
6955 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006956
6957
6958match({expr}, {pat} [, {start} [, {count}]]) *match()*
6959 When {expr} is a |List| then this returns the index of the
6960 first item where {pat} matches. Each item is used as a
6961 String, |Lists| and |Dictionaries| are used as echoed.
6962
6963 Otherwise, {expr} is used as a String. The result is a
6964 Number, which gives the index (byte offset) in {expr} where
6965 {pat} matches.
6966
6967 A match at the first character or |List| item returns zero.
6968 If there is no match -1 is returned.
6969
6970 For getting submatches see |matchlist()|.
6971 Example: >
6972 :echo match("testing", "ing") " results in 4
6973 :echo match([1, 'x'], '\a') " results in 1
6974< See |string-match| for how {pat} is used.
6975 *strpbrk()*
6976 Vim doesn't have a strpbrk() function. But you can do: >
6977 :let sepidx = match(line, '[.,;: \t]')
6978< *strcasestr()*
6979 Vim doesn't have a strcasestr() function. But you can add
6980 "\c" to the pattern to ignore case: >
6981 :let idx = match(haystack, '\cneedle')
6982<
6983 If {start} is given, the search starts from byte index
6984 {start} in a String or item {start} in a |List|.
6985 The result, however, is still the index counted from the
6986 first character/item. Example: >
6987 :echo match("testing", "ing", 2)
6988< result is again "4". >
6989 :echo match("testing", "ing", 4)
6990< result is again "4". >
6991 :echo match("testing", "t", 2)
6992< result is "3".
6993 For a String, if {start} > 0 then it is like the string starts
6994 {start} bytes later, thus "^" will match at {start}. Except
6995 when {count} is given, then it's like matches before the
6996 {start} byte are ignored (this is a bit complicated to keep it
6997 backwards compatible).
6998 For a String, if {start} < 0, it will be set to 0. For a list
6999 the index is counted from the end.
7000 If {start} is out of range ({start} > strlen({expr}) for a
7001 String or {start} > len({expr}) for a |List|) -1 is returned.
7002
7003 When {count} is given use the {count}'th match. When a match
7004 is found in a String the search for the next one starts one
7005 character further. Thus this example results in 1: >
7006 echo match("testing", "..", 0, 2)
7007< In a |List| the search continues in the next item.
7008 Note that when {count} is added the way {start} works changes,
7009 see above.
7010
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007011 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007012 See |pattern| for the patterns that are accepted.
7013 The 'ignorecase' option is used to set the ignore-caseness of
7014 the pattern. 'smartcase' is NOT used. The matching is always
7015 done like 'magic' is set and 'cpoptions' is empty.
7016 Note that a match at the start is preferred, thus when the
7017 pattern is using "*" (any number of matches) it tends to find
7018 zero matches at the start instead of a number of matches
7019 further down in the text.
7020
7021 Can also be used as a |method|: >
7022 GetText()->match('word')
7023 GetList()->match('word')
7024<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007025 Return type: |Number|
7026
7027
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007028 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007029matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7030 Defines a pattern to be highlighted in the current window (a
7031 "match"). It will be highlighted with {group}. Returns an
7032 identification number (ID), which can be used to delete the
7033 match using |matchdelete()|. The ID is bound to the window.
7034 Matching is case sensitive and magic, unless case sensitivity
7035 or magicness are explicitly overridden in {pattern}. The
7036 'magic', 'smartcase' and 'ignorecase' options are not used.
7037 The "Conceal" value is special, it causes the match to be
7038 concealed.
7039
7040 The optional {priority} argument assigns a priority to the
7041 match. A match with a high priority will have its
7042 highlighting overrule that of a match with a lower priority.
7043 A priority is specified as an integer (negative numbers are no
7044 exception). If the {priority} argument is not specified, the
7045 default priority is 10. The priority of 'hlsearch' is zero,
7046 hence all matches with a priority greater than zero will
7047 overrule it. Syntax highlighting (see 'syntax') is a separate
7048 mechanism, and regardless of the chosen priority a match will
7049 always overrule syntax highlighting.
7050
7051 The optional {id} argument allows the request for a specific
7052 match ID. If a specified ID is already taken, an error
7053 message will appear and the match will not be added. An ID
7054 is specified as a positive integer (zero excluded). IDs 1, 2
7055 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007056 respectively. 3 is reserved for use by the |matchparen|
7057 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007058 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007059 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007060
7061 The optional {dict} argument allows for further custom
7062 values. Currently this is used to specify a match specific
7063 conceal character that will be shown for |hl-Conceal|
7064 highlighted matches. The dict can have the following members:
7065
7066 conceal Special character to show instead of the
7067 match (only for |hl-Conceal| highlighted
7068 matches, see |:syn-cchar|)
7069 window Instead of the current window use the
7070 window with this number or window ID.
7071
7072 The number of matches is not limited, as it is the case with
7073 the |:match| commands.
7074
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007075 Returns -1 on error.
7076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007077 Example: >
7078 :highlight MyGroup ctermbg=green guibg=green
7079 :let m = matchadd("MyGroup", "TODO")
7080< Deletion of the pattern: >
7081 :call matchdelete(m)
7082
7083< A list of matches defined by |matchadd()| and |:match| are
7084 available from |getmatches()|. All matches can be deleted in
7085 one operation by |clearmatches()|.
7086
7087 Can also be used as a |method|: >
7088 GetGroup()->matchadd('TODO')
7089<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007090 Return type: |Number|
7091
7092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007093 *matchaddpos()*
7094matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7095 Same as |matchadd()|, but requires a list of positions {pos}
7096 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007097 because it does not handle regular expressions and it sets
7098 buffer line boundaries to redraw screen. It is supposed to be
7099 used when fast match additions and deletions are required, for
7100 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007101
7102 {pos} is a list of positions. Each position can be one of
7103 these:
7104 - A number. This whole line will be highlighted. The first
7105 line has number 1.
7106 - A list with one number, e.g., [23]. The whole line with this
7107 number will be highlighted.
7108 - A list with two numbers, e.g., [23, 11]. The first number is
7109 the line number, the second one is the column number (first
7110 column is 1, the value must correspond to the byte index as
7111 |col()| would return). The character at this position will
7112 be highlighted.
7113 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7114 the third number gives the length of the highlight in bytes.
7115
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007116 Returns -1 on error.
7117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007118 Example: >
7119 :highlight MyGroup ctermbg=green guibg=green
7120 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7121< Deletion of the pattern: >
7122 :call matchdelete(m)
7123
7124< Matches added by |matchaddpos()| are returned by
7125 |getmatches()|.
7126
7127 Can also be used as a |method|: >
7128 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007129<
7130 Return type: |Number|
7131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007132
7133matcharg({nr}) *matcharg()*
7134 Selects the {nr} match item, as set with a |:match|,
7135 |:2match| or |:3match| command.
7136 Return a |List| with two elements:
7137 The name of the highlight group used
7138 The pattern used.
7139 When {nr} is not 1, 2 or 3 returns an empty |List|.
7140 When there is no match item set returns ['', ''].
7141 This is useful to save and restore a |:match|.
7142 Highlighting matches using the |:match| commands are limited
7143 to three matches. |matchadd()| does not have this limitation.
7144
7145 Can also be used as a |method|: >
7146 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007147<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007148 Return type: list<string>
7149
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007150 *matchbufline()*
7151matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7152 Returns the |List| of matches in lines from {lnum} to {end} in
7153 buffer {buf} where {pat} matches.
7154
7155 {lnum} and {end} can either be a line number or the string "$"
7156 to refer to the last line in {buf}.
7157
7158 The {dict} argument supports following items:
7159 submatches include submatch information (|/\(|)
7160
7161 For each match, a |Dict| with the following items is returned:
7162 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007163 lnum line number where there is a match
7164 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007165 Note that there can be multiple matches in a single line.
7166
7167 This function works only for loaded buffers. First call
7168 |bufload()| if needed.
7169
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007170 See |match-pattern| for information about the effect of some
7171 option settings on the pattern.
7172
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007173 When {buf} is not a valid buffer, the buffer is not loaded or
7174 {lnum} or {end} is not valid then an error is given and an
7175 empty |List| is returned.
7176
7177 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007178 " Assuming line 3 in buffer 5 contains "a"
7179 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7180 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7181 " Assuming line 4 in buffer 10 contains "tik tok"
7182 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7183 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007184<
7185 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007186 "\1", "\2", etc. are also returned. Example: >
7187 " Assuming line 2 in buffer 2 contains "acd"
7188 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007189 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007190 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007191< The "submatches" List always contains 9 items. If a submatch
7192 is not found, then an empty string is returned for that
7193 submatch.
7194
7195 Can also be used as a |method|: >
7196 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007197<
7198 Return type: list<dict<any>> or list<any>
7199
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007200
h-east624bb832024-11-09 18:37:32 +01007201matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007202 Deletes a match with ID {id} previously defined by |matchadd()|
7203 or one of the |:match| commands. Returns 0 if successful,
7204 otherwise -1. See example for |matchadd()|. All matches can
7205 be deleted in one operation by |clearmatches()|.
7206 If {win} is specified, use the window with this number or
7207 window ID instead of the current window.
7208
7209 Can also be used as a |method|: >
7210 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007211<
7212 Return type: |Number|
7213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007214
7215matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7216 Same as |match()|, but return the index of first character
7217 after the match. Example: >
7218 :echo matchend("testing", "ing")
7219< results in "7".
7220 *strspn()* *strcspn()*
7221 Vim doesn't have a strspn() or strcspn() function, but you can
7222 do it with matchend(): >
7223 :let span = matchend(line, '[a-zA-Z]')
7224 :let span = matchend(line, '[^a-zA-Z]')
7225< Except that -1 is returned when there are no matches.
7226
7227 The {start}, if given, has the same meaning as for |match()|. >
7228 :echo matchend("testing", "ing", 2)
7229< results in "7". >
7230 :echo matchend("testing", "ing", 5)
7231< result is "-1".
7232 When {expr} is a |List| the result is equal to |match()|.
7233
7234 Can also be used as a |method|: >
7235 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007236<
7237 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007238
7239
7240matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7241 If {list} is a list of strings, then returns a |List| with all
7242 the strings in {list} that fuzzy match {str}. The strings in
7243 the returned list are sorted based on the matching score.
7244
7245 The optional {dict} argument always supports the following
7246 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007247 matchseq When this item is present return only matches
7248 that contain the characters in {str} in the
7249 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007250 limit Maximum number of matches in {list} to be
7251 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007252
7253 If {list} is a list of dictionaries, then the optional {dict}
7254 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007255 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007256 {str}. The value of this item should be a
7257 string.
7258 text_cb |Funcref| that will be called for every item
7259 in {list} to get the text for fuzzy matching.
7260 This should accept a dictionary item as the
7261 argument and return the text for that item to
7262 use for fuzzy matching.
7263
7264 {str} is treated as a literal string and regular expression
7265 matching is NOT supported. The maximum supported {str} length
7266 is 256.
7267
7268 When {str} has multiple words each separated by white space,
7269 then the list of strings that have all the words is returned.
7270
7271 If there are no matching strings or there is an error, then an
7272 empty list is returned. If length of {str} is greater than
7273 256, then returns an empty list.
7274
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007275 When {limit} is given, matchfuzzy() will find up to this
7276 number of matches in {list} and return them in sorted order.
7277
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007278 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007279 matching strings.
7280
7281 Example: >
7282 :echo matchfuzzy(["clay", "crow"], "cay")
7283< results in ["clay"]. >
7284 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7285< results in a list of buffer names fuzzy matching "ndl". >
7286 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7287< results in a list of buffer information dicts with buffer
7288 names fuzzy matching "ndl". >
7289 :echo getbufinfo()->matchfuzzy("spl",
7290 \ {'text_cb' : {v -> v.name}})
7291< results in a list of buffer information dicts with buffer
7292 names fuzzy matching "spl". >
7293 :echo v:oldfiles->matchfuzzy("test")
7294< results in a list of file names fuzzy matching "test". >
7295 :let l = readfile("buffer.c")->matchfuzzy("str")
7296< results in a list of lines in "buffer.c" fuzzy matching "str". >
7297 :echo ['one two', 'two one']->matchfuzzy('two one')
7298< results in ['two one', 'one two']. >
7299 :echo ['one two', 'two one']->matchfuzzy('two one',
7300 \ {'matchseq': 1})
7301< results in ['two one'].
7302
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007303 Return type: list<string> or list<any>
7304
7305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007306matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7307 Same as |matchfuzzy()|, but returns the list of matched
7308 strings, the list of character positions where characters
7309 in {str} matches and a list of matching scores. You can
7310 use |byteidx()| to convert a character position to a byte
7311 position.
7312
7313 If {str} matches multiple times in a string, then only the
7314 positions for the best match is returned.
7315
7316 If there are no matching strings or there is an error, then a
7317 list with three empty list items is returned.
7318
7319 Example: >
7320 :echo matchfuzzypos(['testing'], 'tsg')
7321< results in [['testing'], [[0, 2, 6]], [99]] >
7322 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7323< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7324 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7325< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7326
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007327 Return type: list<list<any>>
7328
7329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007330matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7331 Same as |match()|, but return a |List|. The first item in the
7332 list is the matched string, same as what matchstr() would
7333 return. Following items are submatches, like "\1", "\2", etc.
7334 in |:substitute|. When an optional submatch didn't match an
7335 empty string is used. Example: >
7336 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7337< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7338 When there is no match an empty list is returned.
7339
7340 You can pass in a List, but that is not very useful.
7341
7342 Can also be used as a |method|: >
7343 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007344<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007345 Return type: list<string> or list<any>
7346
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007347 *matchstrlist()*
7348matchstrlist({list}, {pat} [, {dict}])
7349 Returns the |List| of matches in {list} where {pat} matches.
7350 {list} is a |List| of strings. {pat} is matched against each
7351 string in {list}.
7352
7353 The {dict} argument supports following items:
7354 submatches include submatch information (|/\(|)
7355
7356 For each match, a |Dict| with the following items is returned:
7357 byteidx starting byte index of the match.
7358 idx index in {list} of the match.
7359 text matched string
7360 submatches a List of submatches. Present only if
7361 "submatches" is set to v:true in {dict}.
7362
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007363 See |match-pattern| for information about the effect of some
7364 option settings on the pattern.
7365
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007366 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007367 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7368 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7369 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7370 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007371<
7372 If "submatches" is present and is v:true, then submatches like
7373 "\1", "\2", etc. are also returned. Example: >
7374 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7375 \ #{submatches: v:true})
7376 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7377< The "submatches" List always contains 9 items. If a submatch
7378 is not found, then an empty string is returned for that
7379 submatch.
7380
7381 Can also be used as a |method|: >
7382 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007383<
7384 Return type: list<dict<any>> or list<any>
7385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007386
7387matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7388 Same as |match()|, but return the matched string. Example: >
7389 :echo matchstr("testing", "ing")
7390< results in "ing".
7391 When there is no match "" is returned.
7392 The {start}, if given, has the same meaning as for |match()|. >
7393 :echo matchstr("testing", "ing", 2)
7394< results in "ing". >
7395 :echo matchstr("testing", "ing", 5)
7396< result is "".
7397 When {expr} is a |List| then the matching item is returned.
7398 The type isn't changed, it's not necessarily a String.
7399
7400 Can also be used as a |method|: >
7401 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007402<
7403 Return type: |String|
7404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007405
7406matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7407 Same as |matchstr()|, but return the matched string, the start
7408 position and the end position of the match. Example: >
7409 :echo matchstrpos("testing", "ing")
7410< results in ["ing", 4, 7].
7411 When there is no match ["", -1, -1] is returned.
7412 The {start}, if given, has the same meaning as for |match()|. >
7413 :echo matchstrpos("testing", "ing", 2)
7414< results in ["ing", 4, 7]. >
7415 :echo matchstrpos("testing", "ing", 5)
7416< result is ["", -1, -1].
7417 When {expr} is a |List| then the matching item, the index
7418 of first item where {pat} matches, the start position and the
7419 end position of the match are returned. >
7420 :echo matchstrpos([1, '__x'], '\a')
7421< result is ["x", 1, 2, 3].
7422 The type isn't changed, it's not necessarily a String.
7423
7424 Can also be used as a |method|: >
7425 GetText()->matchstrpos('word')
7426<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007427 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007428
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007429
7430max({expr}) *max()*
7431 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007432 echo max([apples, pears, oranges])
7433
7434< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7435 it returns the maximum of all values in the Dictionary.
7436 If {expr} is neither a List nor a Dictionary, or one of the
7437 items in {expr} cannot be used as a Number this results in
7438 an error. An empty |List| or |Dictionary| results in zero.
7439
7440 Can also be used as a |method|: >
7441 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007442<
7443 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007444
7445
7446menu_info({name} [, {mode}]) *menu_info()*
7447 Return information about the specified menu {name} in
7448 mode {mode}. The menu name should be specified without the
7449 shortcut character ('&'). If {name} is "", then the top-level
7450 menu names are returned.
7451
7452 {mode} can be one of these strings:
7453 "n" Normal
7454 "v" Visual (including Select)
7455 "o" Operator-pending
7456 "i" Insert
7457 "c" Cmd-line
7458 "s" Select
7459 "x" Visual
7460 "t" Terminal-Job
7461 "" Normal, Visual and Operator-pending
7462 "!" Insert and Cmd-line
7463 When {mode} is omitted, the modes for "" are used.
7464
7465 Returns a |Dictionary| containing the following items:
7466 accel menu item accelerator text |menu-text|
7467 display display name (name without '&')
7468 enabled v:true if this menu item is enabled
7469 Refer to |:menu-enable|
7470 icon name of the icon file (for toolbar)
7471 |toolbar-icon|
7472 iconidx index of a built-in icon
7473 modes modes for which the menu is defined. In
7474 addition to the modes mentioned above, these
7475 characters will be used:
7476 " " Normal, Visual and Operator-pending
7477 name menu item name.
7478 noremenu v:true if the {rhs} of the menu item is not
7479 remappable else v:false.
7480 priority menu order priority |menu-priority|
7481 rhs right-hand-side of the menu item. The returned
7482 string has special characters translated like
7483 in the output of the ":menu" command listing.
7484 When the {rhs} of a menu item is empty, then
7485 "<Nop>" is returned.
7486 script v:true if script-local remapping of {rhs} is
7487 allowed else v:false. See |:menu-script|.
7488 shortcut shortcut key (character after '&' in
7489 the menu name) |menu-shortcut|
7490 silent v:true if the menu item is created
7491 with <silent> argument |:menu-silent|
7492 submenus |List| containing the names of
7493 all the submenus. Present only if the menu
7494 item has submenus.
7495
7496 Returns an empty dictionary if the menu item is not found.
7497
7498 Examples: >
7499 :echo menu_info('Edit.Cut')
7500 :echo menu_info('File.Save', 'n')
7501
7502 " Display the entire menu hierarchy in a buffer
7503 func ShowMenu(name, pfx)
7504 let m = menu_info(a:name)
7505 call append(line('$'), a:pfx .. m.display)
7506 for child in m->get('submenus', [])
7507 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7508 \ a:pfx .. ' ')
7509 endfor
7510 endfunc
7511 new
7512 for topmenu in menu_info('').submenus
7513 call ShowMenu(topmenu, '')
7514 endfor
7515<
7516 Can also be used as a |method|: >
7517 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007518<
7519 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007520
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007521min({expr}) *min()*
7522 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007523 echo min([apples, pears, oranges])
7524
7525< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7526 it returns the minimum of all values in the Dictionary.
7527 If {expr} is neither a List nor a Dictionary, or one of the
7528 items in {expr} cannot be used as a Number this results in
7529 an error. An empty |List| or |Dictionary| results in zero.
7530
7531 Can also be used as a |method|: >
7532 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007533<
7534 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007535
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007536
7537mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007538 Create directory {name}.
7539
Bram Moolenaar938ae282023-02-20 20:44:55 +00007540 When {flags} is present it must be a string. An empty string
7541 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007542
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007543 {flags} can contain these character flags:
7544 "p" intermediate directories will be created as necessary
7545 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007546 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007547 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007548 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007549
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007550 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007551 some directories may already exist. Only the first one that
7552 is created and what it contains is scheduled to be deleted.
7553 E.g. when using: >
7554 call mkdir('subdir/tmp/autoload', 'pR')
7555< and "subdir" already exists then "subdir/tmp" will be
7556 scheduled for deletion, like with: >
7557 defer delete('subdir/tmp', 'rf')
7558< Note that if scheduling the defer fails the directory is not
7559 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007560
7561 If {prot} is given it is used to set the protection bits of
7562 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7563 the user, readable for others). Use 0o700 to make it
7564 unreadable for others. This is only used for the last part of
7565 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7566 created with 0o755.
7567 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007568 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007569
7570< This function is not available in the |sandbox|.
7571
7572 There is no error if the directory already exists and the "p"
7573 flag is passed (since patch 8.0.1708). However, without the
7574 "p" option the call will fail.
7575
7576 The function result is a Number, which is TRUE if the call was
7577 successful or FALSE if the directory creation failed or partly
7578 failed.
7579
7580 Not available on all systems. To check use: >
7581 :if exists("*mkdir")
7582
7583< Can also be used as a |method|: >
7584 GetName()->mkdir()
7585<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007586 Return type: |Number|
7587
7588
7589mode([{expr}]) *mode()*
7590 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007591 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007592 a non-empty String (|non-zero-arg|), then the full mode is
7593 returned, otherwise only the first letter is returned.
7594 Also see |state()|.
7595
7596 n Normal
7597 no Operator-pending
7598 nov Operator-pending (forced characterwise |o_v|)
7599 noV Operator-pending (forced linewise |o_V|)
7600 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7601 CTRL-V is one character
7602 niI Normal using |i_CTRL-O| in |Insert-mode|
7603 niR Normal using |i_CTRL-O| in |Replace-mode|
7604 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7605 nt Terminal-Normal (insert goes to Terminal-Job mode)
7606 v Visual by character
7607 vs Visual by character using |v_CTRL-O| in Select mode
7608 V Visual by line
7609 Vs Visual by line using |v_CTRL-O| in Select mode
7610 CTRL-V Visual blockwise
7611 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7612 s Select by character
7613 S Select by line
7614 CTRL-S Select blockwise
7615 i Insert
7616 ic Insert mode completion |compl-generic|
7617 ix Insert mode |i_CTRL-X| completion
7618 R Replace |R|
7619 Rc Replace mode completion |compl-generic|
7620 Rx Replace mode |i_CTRL-X| completion
7621 Rv Virtual Replace |gR|
7622 Rvc Virtual Replace mode completion |compl-generic|
7623 Rvx Virtual Replace mode |i_CTRL-X| completion
7624 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007625 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007626 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007627 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007628 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007629 ce Normal Ex mode |Q|
7630 r Hit-enter prompt
7631 rm The -- more -- prompt
7632 r? A |:confirm| query of some sort
7633 ! Shell or external command is executing
7634 t Terminal-Job mode: keys go to the job
7635
7636 This is useful in the 'statusline' option or when used
7637 with |remote_expr()| In most other places it always returns
7638 "c" or "n".
7639 Note that in the future more modes and more specific modes may
7640 be added. It's better not to compare the whole string but only
7641 the leading character(s).
7642 Also see |visualmode()|.
7643
7644 Can also be used as a |method|: >
7645 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007646<
7647 Return type: |String|
7648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007649
7650mzeval({expr}) *mzeval()*
7651 Evaluate MzScheme expression {expr} and return its result
7652 converted to Vim data structures.
7653 Numbers and strings are returned as they are.
7654 Pairs (including lists and improper lists) and vectors are
7655 returned as Vim |Lists|.
7656 Hash tables are represented as Vim |Dictionary| type with keys
7657 converted to strings.
7658 All other types are converted to string with display function.
7659 Examples: >
7660 :mz (define l (list 1 2 3))
7661 :mz (define h (make-hash)) (hash-set! h "list" l)
7662 :echo mzeval("l")
7663 :echo mzeval("h")
7664<
7665 Note that in a `:def` function local variables are not visible
7666 to {expr}.
7667
7668 Can also be used as a |method|: >
7669 GetExpr()->mzeval()
7670<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007671 Return type: any, depending on {expr}
7672
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007673 {only available when compiled with the |+mzscheme| feature}
7674
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007675
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007676nextnonblank({lnum}) *nextnonblank()*
7677 Return the line number of the first line at or below {lnum}
7678 that is not blank. Example: >
7679 if getline(nextnonblank(1)) =~ "Java"
7680< When {lnum} is invalid or there is no non-blank line at or
7681 below it, zero is returned.
7682 {lnum} is used like with |getline()|.
7683 See also |prevnonblank()|.
7684
7685 Can also be used as a |method|: >
7686 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007687<
7688 Return type: |Number|
7689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007690
7691nr2char({expr} [, {utf8}]) *nr2char()*
7692 Return a string with a single character, which has the number
7693 value {expr}. Examples: >
7694 nr2char(64) returns "@"
7695 nr2char(32) returns " "
7696< When {utf8} is omitted or zero, the current 'encoding' is used.
7697 Example for "utf-8": >
7698 nr2char(300) returns I with bow character
7699< When {utf8} is TRUE, always return UTF-8 characters.
7700 Note that a NUL character in the file is specified with
7701 nr2char(10), because NULs are represented with newline
7702 characters. nr2char(0) is a real NUL and terminates the
7703 string, thus results in an empty string.
7704 To turn a list of character numbers into a string: >
7705 let list = [65, 66, 67]
7706 let str = join(map(list, {_, val -> nr2char(val)}), '')
7707< Result: "ABC"
7708
7709 Can also be used as a |method|: >
7710 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007711<
7712 Return type: |String|
7713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007714
7715or({expr}, {expr}) *or()*
7716 Bitwise OR on the two arguments. The arguments are converted
7717 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007718 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007719 Example: >
7720 :let bits = or(bits, 0x80)
7721< Can also be used as a |method|: >
7722 :let bits = bits->or(0x80)
7723
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007724< Rationale: The reason this is a function and not using the "|"
7725 character like many languages, is that Vi has always used "|"
7726 to separate commands. In many places it would not be clear if
7727 "|" is an operator or a command separator.
7728
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007729 Return type: |Number|
7730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007731
7732pathshorten({path} [, {len}]) *pathshorten()*
7733 Shorten directory names in the path {path} and return the
7734 result. The tail, the file name, is kept as-is. The other
7735 components in the path are reduced to {len} letters in length.
7736 If {len} is omitted or smaller than 1 then 1 is used (single
7737 letters). Leading '~' and '.' characters are kept. Examples: >
7738 :echo pathshorten('~/.vim/autoload/myfile.vim')
7739< ~/.v/a/myfile.vim ~
7740>
7741 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7742< ~/.vi/au/myfile.vim ~
7743 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007744 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007745
7746 Can also be used as a |method|: >
7747 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007748<
7749 Return type: |String|
7750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007751
7752perleval({expr}) *perleval()*
7753 Evaluate Perl expression {expr} in scalar context and return
7754 its result converted to Vim data structures. If value can't be
7755 converted, it is returned as a string Perl representation.
7756 Note: If you want an array or hash, {expr} must return a
7757 reference to it.
7758 Example: >
7759 :echo perleval('[1 .. 4]')
7760< [1, 2, 3, 4]
7761
7762 Note that in a `:def` function local variables are not visible
7763 to {expr}.
7764
7765 Can also be used as a |method|: >
7766 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007767<
7768 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007769
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007770 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007771
7772
7773popup_ functions are documented here: |popup-functions|
7774
7775
7776pow({x}, {y}) *pow()*
7777 Return the power of {x} to the exponent {y} as a |Float|.
7778 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007779 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007780 Examples: >
7781 :echo pow(3, 3)
7782< 27.0 >
7783 :echo pow(2, 16)
7784< 65536.0 >
7785 :echo pow(32, 0.20)
7786< 2.0
7787
7788 Can also be used as a |method|: >
7789 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007790<
7791 Return type: |Number|
7792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007793
7794prevnonblank({lnum}) *prevnonblank()*
7795 Return the line number of the first line at or above {lnum}
7796 that is not blank. Example: >
7797 let ind = indent(prevnonblank(v:lnum - 1))
7798< When {lnum} is invalid or there is no non-blank line at or
7799 above it, zero is returned.
7800 {lnum} is used like with |getline()|.
7801 Also see |nextnonblank()|.
7802
7803 Can also be used as a |method|: >
7804 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007805<
7806 Return type: |Number|
7807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007808
7809printf({fmt}, {expr1} ...) *printf()*
7810 Return a String with {fmt}, where "%" items are replaced by
7811 the formatted form of their respective arguments. Example: >
7812 printf("%4d: E%d %.30s", lnum, errno, msg)
7813< May result in:
7814 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7815
7816 When used as a |method| the base is passed as the second
7817 argument: >
7818 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007819<
7820 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007821
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007822 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007823 %s string
7824 %6S string right-aligned in 6 display cells
7825 %6s string right-aligned in 6 bytes
7826 %.9s string truncated to 9 bytes
7827 %c single byte
7828 %d decimal number
7829 %5d decimal number padded with spaces to 5 characters
7830 %x hex number
7831 %04x hex number padded with zeros to at least 4 characters
7832 %X hex number using upper case letters
7833 %o octal number
7834 %08b binary number padded with zeros to at least 8 chars
7835 %f floating point number as 12.23, inf, -inf or nan
7836 %F floating point number as 12.23, INF, -INF or NAN
7837 %e floating point number as 1.23e3, inf, -inf or nan
7838 %E floating point number as 1.23E3, INF, -INF or NAN
7839 %g floating point number, as %f or %e depending on value
7840 %G floating point number, as %F or %E depending on value
7841 %% the % character itself
7842
7843 Conversion specifications start with '%' and end with the
7844 conversion type. All other characters are copied unchanged to
7845 the result.
7846
7847 The "%" starts a conversion specification. The following
7848 arguments appear in sequence:
7849
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007850 % [pos-argument] [flags] [field-width] [.precision] type
7851
7852 pos-argument
7853 At most one positional argument specifier. These
7854 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007855
7856 flags
7857 Zero or more of the following flags:
7858
7859 # The value should be converted to an "alternate
7860 form". For c, d, and s conversions, this option
7861 has no effect. For o conversions, the precision
7862 of the number is increased to force the first
7863 character of the output string to a zero (except
7864 if a zero value is printed with an explicit
7865 precision of zero).
7866 For b and B conversions, a non-zero result has
7867 the string "0b" (or "0B" for B conversions)
7868 prepended to it.
7869 For x and X conversions, a non-zero result has
7870 the string "0x" (or "0X" for X conversions)
7871 prepended to it.
7872
7873 0 (zero) Zero padding. For all conversions the converted
7874 value is padded on the left with zeros rather
7875 than blanks. If a precision is given with a
7876 numeric conversion (d, b, B, o, x, and X), the 0
7877 flag is ignored.
7878
7879 - A negative field width flag; the converted value
7880 is to be left adjusted on the field boundary.
7881 The converted value is padded on the right with
7882 blanks, rather than on the left with blanks or
7883 zeros. A - overrides a 0 if both are given.
7884
7885 ' ' (space) A blank should be left before a positive
7886 number produced by a signed conversion (d).
7887
7888 + A sign must always be placed before a number
7889 produced by a signed conversion. A + overrides
7890 a space if both are used.
7891
7892 field-width
7893 An optional decimal digit string specifying a minimum
7894 field width. If the converted value has fewer bytes
7895 than the field width, it will be padded with spaces on
7896 the left (or right, if the left-adjustment flag has
7897 been given) to fill out the field width. For the S
7898 conversion the count is in cells.
7899
7900 .precision
7901 An optional precision, in the form of a period '.'
7902 followed by an optional digit string. If the digit
7903 string is omitted, the precision is taken as zero.
7904 This gives the minimum number of digits to appear for
7905 d, o, x, and X conversions, the maximum number of
7906 bytes to be printed from a string for s conversions,
7907 or the maximum number of cells to be printed from a
7908 string for S conversions.
7909 For floating point it is the number of digits after
7910 the decimal point.
7911
7912 type
7913 A character that specifies the type of conversion to
7914 be applied, see below.
7915
7916 A field width or precision, or both, may be indicated by an
7917 asterisk '*' instead of a digit string. In this case, a
7918 Number argument supplies the field width or precision. A
7919 negative field width is treated as a left adjustment flag
7920 followed by a positive field width; a negative precision is
7921 treated as though it were missing. Example: >
7922 :echo printf("%d: %.*s", nr, width, line)
7923< This limits the length of the text used from "line" to
7924 "width" bytes.
7925
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007926 If the argument to be formatted is specified using a
7927 positional argument specifier, and a '*' is used to indicate
7928 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007929 precision, the argument(s) to be used must also be specified
7930 using a {n$} positional argument specifier. See |printf-$|.
7931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007932 The conversion specifiers and their meanings are:
7933
7934 *printf-d* *printf-b* *printf-B* *printf-o*
7935 *printf-x* *printf-X*
7936 dbBoxX The Number argument is converted to signed decimal
7937 (d), unsigned binary (b and B), unsigned octal (o), or
7938 unsigned hexadecimal (x and X) notation. The letters
7939 "abcdef" are used for x conversions; the letters
7940 "ABCDEF" are used for X conversions.
7941 The precision, if any, gives the minimum number of
7942 digits that must appear; if the converted value
7943 requires fewer digits, it is padded on the left with
7944 zeros.
7945 In no case does a non-existent or small field width
7946 cause truncation of a numeric field; if the result of
7947 a conversion is wider than the field width, the field
7948 is expanded to contain the conversion result.
7949 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007950 The 'l' modifier indicates the argument is a long
7951 integer. The size will be 32 bits or 64 bits
7952 depending on your platform.
7953 The "ll" modifier indicates the argument is 64 bits.
7954 The b and B conversion specifiers never take a width
7955 modifier and always assume their argument is a 64 bit
7956 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007957 Generally, these modifiers are not useful. They are
7958 ignored when type is known from the argument.
7959
7960 i alias for d
7961 D alias for ld
7962 U alias for lu
7963 O alias for lo
7964
7965 *printf-c*
7966 c The Number argument is converted to a byte, and the
7967 resulting character is written.
7968
7969 *printf-s*
7970 s The text of the String argument is used. If a
7971 precision is specified, no more bytes than the number
7972 specified are used.
7973 If the argument is not a String type, it is
7974 automatically converted to text with the same format
7975 as ":echo".
7976 *printf-S*
7977 S The text of the String argument is used. If a
7978 precision is specified, no more display cells than the
7979 number specified are used.
7980
7981 *printf-f* *E807*
7982 f F The Float argument is converted into a string of the
7983 form 123.456. The precision specifies the number of
7984 digits after the decimal point. When the precision is
7985 zero the decimal point is omitted. When the precision
7986 is not specified 6 is used. A really big number
7987 (out of range or dividing by zero) results in "inf"
7988 or "-inf" with %f (INF or -INF with %F).
7989 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7990 Example: >
7991 echo printf("%.2f", 12.115)
7992< 12.12
7993 Note that roundoff depends on the system libraries.
7994 Use |round()| when in doubt.
7995
7996 *printf-e* *printf-E*
7997 e E The Float argument is converted into a string of the
7998 form 1.234e+03 or 1.234E+03 when using 'E'. The
7999 precision specifies the number of digits after the
8000 decimal point, like with 'f'.
8001
8002 *printf-g* *printf-G*
8003 g G The Float argument is converted like with 'f' if the
8004 value is between 0.001 (inclusive) and 10000000.0
8005 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8006 for 'G'. When no precision is specified superfluous
8007 zeroes and '+' signs are removed, except for the zero
8008 immediately after the decimal point. Thus 10000000.0
8009 results in 1.0e7.
8010
8011 *printf-%*
8012 % A '%' is written. No argument is converted. The
8013 complete conversion specification is "%%".
8014
8015 When a Number argument is expected a String argument is also
8016 accepted and automatically converted.
8017 When a Float or String argument is expected a Number argument
8018 is also accepted and automatically converted.
8019 Any other argument type results in an error message.
8020
8021 *E766* *E767*
8022 The number of {exprN} arguments must exactly match the number
8023 of "%" items. If there are not sufficient or too many
8024 arguments an error is given. Up to 18 arguments can be used.
8025
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008026 *printf-$*
8027 In certain languages, error and informative messages are
8028 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008029 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008030 having a different word order, positional arguments may be
8031 used to indicate this. For instance: >
8032
h_east596a9f22023-11-21 21:24:23 +09008033 #, c-format
8034 msgid "%s returning %s"
8035 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008036<
h_east596a9f22023-11-21 21:24:23 +09008037 In this example, the sentence has its 2 string arguments
8038 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008039
h_east596a9f22023-11-21 21:24:23 +09008040 echo printf(
8041 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8042 "Bram", "Moolenaar")
8043< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008044
h_east596a9f22023-11-21 21:24:23 +09008045 echo printf(
8046 "In Belgium, vim's creator's name is: %2$s %1$s",
8047 "Bram", "Moolenaar")
8048< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008049
8050 Width (and precision) can be specified using the '*' specifier.
8051 In this case, you must specify the field width position in the
8052 argument list. >
8053
h_east596a9f22023-11-21 21:24:23 +09008054 echo printf("%1$*2$.*3$d", 1, 2, 3)
8055< 001 >
8056 echo printf("%2$*3$.*1$d", 1, 2, 3)
8057< 2 >
8058 echo printf("%3$*1$.*2$d", 1, 2, 3)
8059< 03 >
8060 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8061< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008062
8063 You can mix specifying the width and/or precision directly
8064 and via positional arguments: >
8065
h_east596a9f22023-11-21 21:24:23 +09008066 echo printf("%1$4.*2$f", 1.4142135, 6)
8067< 1.414214 >
8068 echo printf("%1$*2$.4f", 1.4142135, 6)
8069< 1.4142 >
8070 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8071< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008072
Christ van Willegenc35fc032024-03-14 18:30:41 +01008073 You will get an overflow error |E1510|, when the field-width
8074 or precision will result in a string longer than 6400 chars.
8075
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008076 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008077 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008078 echo printf("%s%1$s", "One", "Two")
8079< E1500: Cannot mix positional and non-positional arguments:
8080 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008081
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008082 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008083 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008084 echo printf("%3$s%1$s", "One", "Two", "Three")
8085< E1501: format argument 2 unused in $-style format:
8086 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008087
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008088 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008089 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008090 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8091< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008092
8093 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008094 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8095< E1502: Positional argument 2 used as field width reused as
8096 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008097
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008098 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008099 When a positional argument is used, but not the correct number
8100 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008101 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8102< E1503: Positional argument 3 out of bounds: %1$d at width
8103 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008104
8105 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008106 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8107< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8108 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008109
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008110 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008111 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008112 echo printf("%1$s %2$s %1$s", "One", "Two")
8113< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008114
8115 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008116 echo printf("%1$s %2$s %1$d", "One", "Two")
8117< E1504: Positional argument 1 type used inconsistently:
8118 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008119
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008120 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008121 Various other errors that lead to a format string being
8122 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008123 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8124< E1505: Invalid format specifier: %1$d at width %2$d is:
8125 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008126
Christ van Willegenea746f92023-10-05 20:48:36 +02008127 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008128 This internal error indicates that the logic to parse a
8129 positional format argument ran into a problem that couldn't be
8130 otherwise reported. Please file a bug against Vim if you run
8131 into this, copying the exact format string and parameters that
8132 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008133
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008134 Return type: |String|
8135
Christ van Willegenea746f92023-10-05 20:48:36 +02008136
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008137prompt_getprompt({buf}) *prompt_getprompt()*
8138 Returns the effective prompt text for buffer {buf}. {buf} can
8139 be a buffer name or number. See |prompt-buffer|.
8140
8141 If the buffer doesn't exist or isn't a prompt buffer, an empty
8142 string is returned.
8143
8144 Can also be used as a |method|: >
8145 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008146<
8147 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008148
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008149 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008150
8151
8152prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8153 Set prompt callback for buffer {buf} to {expr}. When {expr}
8154 is an empty string the callback is removed. This has only
8155 effect if {buf} has 'buftype' set to "prompt".
8156
8157 The callback is invoked when pressing Enter. The current
8158 buffer will always be the prompt buffer. A new line for a
8159 prompt is added before invoking the callback, thus the prompt
8160 for which the callback was invoked will be in the last but one
8161 line.
8162 If the callback wants to add text to the buffer, it must
8163 insert it above the last line, since that is where the current
8164 prompt is. This can also be done asynchronously.
8165 The callback is invoked with one argument, which is the text
8166 that was entered at the prompt. This can be an empty string
8167 if the user only typed Enter.
8168 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008169 func s:TextEntered(text)
8170 if a:text == 'exit' || a:text == 'quit'
8171 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008172 " Reset 'modified' to allow the buffer to be closed.
8173 " We assume there is nothing useful to be saved.
8174 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008175 close
8176 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008177 " Do something useful with "a:text". In this example
8178 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008179 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008180 endif
8181 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008182 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008183
8184< Can also be used as a |method|: >
8185 GetBuffer()->prompt_setcallback(callback)
8186
8187< {only available when compiled with the |+channel| feature}
8188
8189prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8190 Set a callback for buffer {buf} to {expr}. When {expr} is an
8191 empty string the callback is removed. This has only effect if
8192 {buf} has 'buftype' set to "prompt".
8193
8194 This callback will be invoked when pressing CTRL-C in Insert
8195 mode. Without setting a callback Vim will exit Insert mode,
8196 as in any buffer.
8197
8198 Can also be used as a |method|: >
8199 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008200<
8201 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008202
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008203 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008204
8205prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8206 Set prompt for buffer {buf} to {text}. You most likely want
8207 {text} to end in a space.
8208 The result is only visible if {buf} has 'buftype' set to
8209 "prompt". Example: >
8210 call prompt_setprompt(bufnr(), 'command: ')
8211<
8212 Can also be used as a |method|: >
8213 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008214<
8215 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008217 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008218
8219prop_ functions are documented here: |text-prop-functions|
8220
8221pum_getpos() *pum_getpos()*
8222 If the popup menu (see |ins-completion-menu|) is not visible,
8223 returns an empty |Dictionary|, otherwise, returns a
8224 |Dictionary| with the following keys:
8225 height nr of items visible
8226 width screen cells
8227 row top screen row (0 first row)
8228 col leftmost screen column (0 first col)
8229 size total nr of items
8230 scrollbar |TRUE| if scrollbar is visible
8231
8232 The values are the same as in |v:event| during
8233 |CompleteChanged|.
8234
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008235 Return type: dict<any>
8236
8237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008238pumvisible() *pumvisible()*
8239 Returns non-zero when the popup menu is visible, zero
8240 otherwise. See |ins-completion-menu|.
8241 This can be used to avoid some things that would remove the
8242 popup menu.
8243
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008244 Return type: |Number|
8245
8246
zeertzjq7c515282024-11-10 20:26:12 +01008247py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008248 Evaluate Python expression {expr} and return its result
8249 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008250 If a {locals} |Dictionary| is given, it defines set of local
8251 variables available in the expression. The keys are variable
8252 names and the values are the variable values. |Dictionary| and
8253 |List| values are referenced, and may be updated by the
8254 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008255 Numbers and strings are returned as they are (strings are
8256 copied though, Unicode strings are additionally converted to
8257 'encoding').
8258 Lists are represented as Vim |List| type.
8259 Dictionaries are represented as Vim |Dictionary| type with
8260 keys converted to strings.
8261 Note that in a `:def` function local variables are not visible
8262 to {expr}.
8263
8264 Can also be used as a |method|: >
8265 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008266 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008267<
8268 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008269
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008270 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008271
8272 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008273pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008274 Evaluate Python expression {expr} and return its result
8275 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008276 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008277 Numbers and strings are returned as they are (strings are
8278 copied though).
8279 Lists are represented as Vim |List| type.
8280 Dictionaries are represented as Vim |Dictionary| type,
8281 non-string keys result in error.
8282 Note that in a `:def` function local variables are not visible
8283 to {expr}.
8284
8285 Can also be used as a |method|: >
8286 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008287<
8288 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008289
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008290 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008291
zeertzjq7c515282024-11-10 20:26:12 +01008292pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008293 Evaluate Python expression {expr} and return its result
8294 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008295 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008296 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8297 See also: |pyeval()|, |py3eval()|
8298
8299 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008300 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008301<
8302 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008303
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008304 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008305 |+python3| feature}
8306
8307rand([{expr}]) *rand()* *random*
8308 Return a pseudo-random Number generated with an xoshiro128**
8309 algorithm using seed {expr}. The returned number is 32 bits,
8310 also on 64 bits systems, for consistency.
8311 {expr} can be initialized by |srand()| and will be updated by
8312 rand(). If {expr} is omitted, an internal seed value is used
8313 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008314 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008315
8316 Examples: >
8317 :echo rand()
8318 :let seed = srand()
8319 :echo rand(seed)
8320 :echo rand(seed) % 16 " random number 0 - 15
8321<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008322 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008323
8324 *E726* *E727*
8325range({expr} [, {max} [, {stride}]]) *range()*
8326 Returns a |List| with Numbers:
8327 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8328 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8329 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8330 {max}] (increasing {expr} with {stride} each time, not
8331 producing a value past {max}).
8332 When the maximum is one before the start the result is an
8333 empty list. When the maximum is more than one before the
8334 start this is an error.
8335 Examples: >
8336 range(4) " [0, 1, 2, 3]
8337 range(2, 4) " [2, 3, 4]
8338 range(2, 9, 3) " [2, 5, 8]
8339 range(2, -2, -1) " [2, 1, 0, -1, -2]
8340 range(0) " []
8341 range(2, 0) " error!
8342<
8343 Can also be used as a |method|: >
8344 GetExpr()->range()
8345<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008346 Return type: list<number>
8347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008348
K.Takata11df3ae2022-10-19 14:02:40 +01008349readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008350 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008351 If {offset} is specified, read the file from the specified
8352 offset. If it is a negative value, it is used as an offset
8353 from the end of the file. E.g., to read the last 12 bytes: >
8354 readblob('file.bin', -12)
8355< If {size} is specified, only the specified size will be read.
8356 E.g. to read the first 100 bytes of a file: >
8357 readblob('file.bin', 0, 100)
8358< If {size} is -1 or omitted, the whole data starting from
8359 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008360 This can be also used to read the data from a character device
8361 on Unix when {size} is explicitly set. Only if the device
8362 supports seeking {offset} can be used. Otherwise it should be
8363 zero. E.g. to read 10 bytes from a serial console: >
8364 readblob('/dev/ttyS0', 0, 10)
8365< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008366 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008367 When the offset is beyond the end of the file the result is an
8368 empty blob.
8369 When trying to read more bytes than are available the result
8370 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008371 Also see |readfile()| and |writefile()|.
8372
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008373 Return type: |Blob|
8374
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008375
8376readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8377 Return a list with file and directory names in {directory}.
8378 You can also use |glob()| if you don't need to do complicated
8379 things, such as limiting the number of matches.
8380 The list will be sorted (case sensitive), see the {dict}
8381 argument below for changing the sort order.
8382
8383 When {expr} is omitted all entries are included.
8384 When {expr} is given, it is evaluated to check what to do:
8385 If {expr} results in -1 then no further entries will
8386 be handled.
8387 If {expr} results in 0 then this entry will not be
8388 added to the list.
8389 If {expr} results in 1 then this entry will be added
8390 to the list.
8391 The entries "." and ".." are always excluded.
8392 Each time {expr} is evaluated |v:val| is set to the entry name.
8393 When {expr} is a function the name is passed as the argument.
8394 For example, to get a list of files ending in ".txt": >
8395 readdir(dirname, {n -> n =~ '.txt$'})
8396< To skip hidden and backup files: >
8397 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008398< *E857*
8399 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008400 values. Currently this is used to specify if and how sorting
8401 should be performed. The dict can have the following members:
8402
8403 sort How to sort the result returned from the system.
8404 Valid values are:
8405 "none" do not sort (fastest method)
8406 "case" sort case sensitive (byte value of
8407 each character, technically, using
8408 strcmp()) (default)
8409 "icase" sort case insensitive (technically
8410 using strcasecmp())
8411 "collate" sort using the collation order
8412 of the "POSIX" or "C" |locale|
8413 (technically using strcoll())
8414 Other values are silently ignored.
8415
8416 For example, to get a list of all files in the current
8417 directory without sorting the individual entries: >
8418 readdir('.', '1', #{sort: 'none'})
8419< If you want to get a directory tree: >
8420 function! s:tree(dir)
8421 return {a:dir : map(readdir(a:dir),
8422 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008423 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008424 endfunction
8425 echo s:tree(".")
8426<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008427 Returns an empty List on error.
8428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008429 Can also be used as a |method|: >
8430 GetDirName()->readdir()
8431<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008432 Return type: list<string> or list<any>
8433
8434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008435readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8436 Extended version of |readdir()|.
8437 Return a list of Dictionaries with file and directory
8438 information in {directory}.
8439 This is useful if you want to get the attributes of file and
8440 directory at the same time as getting a list of a directory.
8441 This is much faster than calling |readdir()| then calling
8442 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8443 each file and directory especially on MS-Windows.
8444 The list will by default be sorted by name (case sensitive),
8445 the sorting can be changed by using the optional {dict}
8446 argument, see |readdir()|.
8447
8448 The Dictionary for file and directory information has the
8449 following items:
8450 group Group name of the entry. (Only on Unix)
8451 name Name of the entry.
8452 perm Permissions of the entry. See |getfperm()|.
8453 size Size of the entry. See |getfsize()|.
8454 time Timestamp of the entry. See |getftime()|.
8455 type Type of the entry.
8456 On Unix, almost same as |getftype()| except:
8457 Symlink to a dir "linkd"
8458 Other symlink "link"
8459 On MS-Windows:
8460 Normal file "file"
8461 Directory "dir"
8462 Junction "junction"
8463 Symlink to a dir "linkd"
8464 Other symlink "link"
8465 Other reparse point "reparse"
8466 user User name of the entry's owner. (Only on Unix)
8467 On Unix, if the entry is a symlink, the Dictionary includes
8468 the information of the target (except the "type" item).
8469 On MS-Windows, it includes the information of the symlink
8470 itself because of performance reasons.
8471
8472 When {expr} is omitted all entries are included.
8473 When {expr} is given, it is evaluated to check what to do:
8474 If {expr} results in -1 then no further entries will
8475 be handled.
8476 If {expr} results in 0 then this entry will not be
8477 added to the list.
8478 If {expr} results in 1 then this entry will be added
8479 to the list.
8480 The entries "." and ".." are always excluded.
8481 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8482 of the entry.
8483 When {expr} is a function the entry is passed as the argument.
8484 For example, to get a list of files ending in ".txt": >
8485 readdirex(dirname, {e -> e.name =~ '.txt$'})
8486<
8487 For example, to get a list of all files in the current
8488 directory without sorting the individual entries: >
8489 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008490<
8491 Can also be used as a |method|: >
8492 GetDirName()->readdirex()
8493<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008494 Return type: list<dict<any>> or list<any>
8495
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008496
8497 *readfile()*
8498readfile({fname} [, {type} [, {max}]])
8499 Read file {fname} and return a |List|, each line of the file
8500 as an item. Lines are broken at NL characters. Macintosh
8501 files separated with CR will result in a single long line
8502 (unless a NL appears somewhere).
8503 All NUL characters are replaced with a NL character.
8504 When {type} contains "b" binary mode is used:
8505 - When the last line ends in a NL an extra empty list item is
8506 added.
8507 - No CR characters are removed.
8508 Otherwise:
8509 - CR characters that appear before a NL are removed.
8510 - Whether the last line ends in a NL or not does not matter.
8511 - When 'encoding' is Unicode any UTF-8 byte order mark is
8512 removed from the text.
8513 When {max} is given this specifies the maximum number of lines
8514 to be read. Useful if you only want to check the first ten
8515 lines of a file: >
8516 :for line in readfile(fname, '', 10)
8517 : if line =~ 'Date' | echo line | endif
8518 :endfor
8519< When {max} is negative -{max} lines from the end of the file
8520 are returned, or as many as there are.
8521 When {max} is zero the result is an empty list.
8522 Note that without {max} the whole file is read into memory.
8523 Also note that there is no recognition of encoding. Read a
8524 file into a buffer if you need to.
8525 Deprecated (use |readblob()| instead): When {type} contains
8526 "B" a |Blob| is returned with the binary data of the file
8527 unmodified.
8528 When the file can't be opened an error message is given and
8529 the result is an empty list.
8530 Also see |writefile()|.
8531
8532 Can also be used as a |method|: >
8533 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008534<
8535 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008536
8537reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8538 {func} is called for every item in {object}, which can be a
8539 |String|, |List| or a |Blob|. {func} is called with two
8540 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008541 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008542
8543 {initial} is the initial result. When omitted, the first item
8544 in {object} is used and {func} is first called for the second
8545 item. If {initial} is not given and {object} is empty no
8546 result can be computed, an E998 error is given.
8547
8548 Examples: >
8549 echo reduce([1, 3, 5], { acc, val -> acc + val })
8550 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8551 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8552 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8553<
8554 Can also be used as a |method|: >
8555 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008556<
8557 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8558 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008559
8560
8561reg_executing() *reg_executing()*
8562 Returns the single letter name of the register being executed.
8563 Returns an empty string when no register is being executed.
8564 See |@|.
8565
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008566 Return type: |String|
8567
8568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008569reg_recording() *reg_recording()*
8570 Returns the single letter name of the register being recorded.
8571 Returns an empty string when not recording. See |q|.
8572
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008573 Return type: |String|
8574
8575
8576reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008577reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008578reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008579 Return an item that represents a time value. The item is a
8580 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008581 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008582 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008583 string or |reltimefloat()| to convert to a Float. For
8584 example, to see the time spent in function Work(): >
8585 var startTime = reltime()
8586 Work()
8587 echo startTime->reltime()->reltimestr()
8588<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008589 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008590 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008591 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008592 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008593 specified in the argument.
8594 With two arguments it returns the time passed between {start}
8595 and {end}.
8596
8597 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008598 reltime(). If there is an error an empty List is returned in
8599 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008600
8601 Can also be used as a |method|: >
8602 GetStart()->reltime()
8603<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008604 Return type: list<number>
8605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008606 {only available when compiled with the |+reltime| feature}
8607
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008609reltimefloat({time}) *reltimefloat()*
8610 Return a Float that represents the time value of {time}.
8611 Example: >
8612 let start = reltime()
8613 call MyFunction()
8614 let seconds = reltimefloat(reltime(start))
8615< See the note of reltimestr() about overhead.
8616 Also see |profiling|.
8617 If there is an error 0.0 is returned in legacy script, in Vim9
8618 script an error is given.
8619
8620 Can also be used as a |method|: >
8621 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008622<
8623 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008624
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008625 {only available when compiled with the |+reltime| feature}
8626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008627
8628reltimestr({time}) *reltimestr()*
8629 Return a String that represents the time value of {time}.
8630 This is the number of seconds, a dot and the number of
8631 microseconds. Example: >
8632 let start = reltime()
8633 call MyFunction()
8634 echo reltimestr(reltime(start))
8635< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008636 The accuracy depends on the system. Use reltimefloat() for the
8637 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008638 Leading spaces are used to make the string align nicely. You
8639 can use split() to remove it. >
8640 echo split(reltimestr(reltime(start)))[0]
8641< Also see |profiling|.
8642 If there is an error an empty string is returned in legacy
8643 script, in Vim9 script an error is given.
8644
8645 Can also be used as a |method|: >
8646 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008647<
8648 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008649
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008650 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008651
8652 *remote_expr()* *E449*
8653remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008654 Send the {string} to {server}. The {server} argument is a
8655 string, also see |{server}|.
8656
8657 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008658 after evaluation. The result must be a String or a |List|
8659 other types will be converted to String. A |List| is turned
8660 into a String by joining the items with a line break in
8661 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008663 If {idvar} is present and not empty, it is taken as the name
8664 of a variable and a {serverid} for later use with
8665 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008667 If {timeout} is given the read times out after this many
8668 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008669
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008670 See also |clientserver| |RemoteReply|.
8671 This function is not available in the |sandbox|.
8672 {only available when compiled with the |+clientserver| feature}
8673 Note: Any errors will cause a local error message to be issued
8674 and the result will be the empty string.
8675
8676 Variables will be evaluated in the global namespace,
8677 independent of a function currently being active. Except
8678 when in debug mode, then local function variables and
8679 arguments can be evaluated.
8680
8681 Examples: >
8682 :echo remote_expr("gvim", "2+2")
8683 :echo remote_expr("gvim1", "b:current_syntax")
8684<
8685 Can also be used as a |method|: >
8686 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008687<
8688 Return type: |String| or list<{type}>
8689
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008690
8691remote_foreground({server}) *remote_foreground()*
8692 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008693 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008694 This works like: >
8695 remote_expr({server}, "foreground()")
8696< Except that on Win32 systems the client does the work, to work
8697 around the problem that the OS doesn't always allow the server
8698 to bring itself to the foreground.
8699 Note: This does not restore the window if it was minimized,
8700 like foreground() does.
8701 This function is not available in the |sandbox|.
8702
8703 Can also be used as a |method|: >
8704 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008705<
8706 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008707
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008708 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008709 Win32 console version}
8710
8711
8712remote_peek({serverid} [, {retvar}]) *remote_peek()*
8713 Returns a positive number if there are available strings
8714 from {serverid}. Copies any reply string into the variable
8715 {retvar} if specified. {retvar} must be a string with the
8716 name of a variable.
8717 Returns zero if none are available.
8718 Returns -1 if something is wrong.
8719 See also |clientserver|.
8720 This function is not available in the |sandbox|.
8721 {only available when compiled with the |+clientserver| feature}
8722 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008723 :let repl = ""
8724 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008725
8726< Can also be used as a |method|: >
8727 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008728<
8729 Return type: |Number|
8730
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008731
8732remote_read({serverid}, [{timeout}]) *remote_read()*
8733 Return the oldest available reply from {serverid} and consume
8734 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008735 reply is available. Returns an empty string, if a reply is
8736 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008737 See also |clientserver|.
8738 This function is not available in the |sandbox|.
8739 {only available when compiled with the |+clientserver| feature}
8740 Example: >
8741 :echo remote_read(id)
8742
8743< Can also be used as a |method|: >
8744 ServerId()->remote_read()
8745<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008746 Return type: |String|
8747
8748
8749remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008750 Send the {string} to {server}. The {server} argument is a
8751 string, also see |{server}|.
8752
8753 The string is sent as input keys and the function returns
8754 immediately. At the Vim server the keys are not mapped
8755 |:map|.
8756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008757 If {idvar} is present, it is taken as the name of a variable
8758 and a {serverid} for later use with remote_read() is stored
8759 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008760
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008761 See also |clientserver| |RemoteReply|.
8762 This function is not available in the |sandbox|.
8763 {only available when compiled with the |+clientserver| feature}
8764
8765 Note: Any errors will be reported in the server and may mess
8766 up the display.
8767 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008768 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008769 \ remote_read(serverid)
8770
8771 :autocmd NONE RemoteReply *
8772 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008773 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008774 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8775<
8776 Can also be used as a |method|: >
8777 ServerName()->remote_send(keys)
8778<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008779 Return type: |String|
8780
8781
8782remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008783 Become the server {name}. {name} must be a non-empty string.
8784 This fails if already running as a server, when |v:servername|
8785 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008786
8787 Can also be used as a |method|: >
8788 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008789<
8790 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008791
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008792 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008793
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008794
8795remove({list}, {idx}) *remove()*
8796remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008797 Without {end}: Remove the item at {idx} from |List| {list} and
8798 return the item.
8799 With {end}: Remove items from {idx} to {end} (inclusive) and
8800 return a |List| with these items. When {idx} points to the same
8801 item as {end} a list with one item is returned. When {end}
8802 points to an item before {idx} this is an error.
8803 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008804 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008805 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008806 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008807 :call remove(mylist, 0, 9)
8808<
8809 Use |delete()| to remove a file.
8810
8811 Can also be used as a |method|: >
8812 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008813<
8814 Return type: any, depending on {list}
8815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008816
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008817remove({blob}, {idx})
8818remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008819 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8820 return the byte.
8821 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8822 return a |Blob| with these bytes. When {idx} points to the same
8823 byte as {end} a |Blob| with one byte is returned. When {end}
8824 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008825 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008826 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008827 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008828 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008829<
8830 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008831
8832remove({dict}, {key})
8833 Remove the entry from {dict} with key {key} and return it.
8834 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008835 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008836< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008837 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008838
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008839 Return type: any, depending on {dict}
8840
8841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008842rename({from}, {to}) *rename()*
8843 Rename the file by the name {from} to the name {to}. This
8844 should also work to move files across file systems. The
8845 result is a Number, which is 0 if the file was renamed
8846 successfully, and non-zero when the renaming failed.
8847 NOTE: If {to} exists it is overwritten without warning.
8848 This function is not available in the |sandbox|.
8849
8850 Can also be used as a |method|: >
8851 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008852<
8853 Return type: |Number|
8854
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008855
8856repeat({expr}, {count}) *repeat()*
8857 Repeat {expr} {count} times and return the concatenated
8858 result. Example: >
8859 :let separator = repeat('-', 80)
8860< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008861 When {expr} is a |List| or a |Blob| the result is {expr}
8862 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008863 :let longlist = repeat(['a', 'b'], 3)
8864< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8865
8866 Can also be used as a |method|: >
8867 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008868<
8869 Return type: |String|, |Blob| or list<{type}> depending on
8870 {expr}
8871
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008872
8873resolve({filename}) *resolve()* *E655*
8874 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8875 returns the path the shortcut points to in a simplified form.
8876 When {filename} is a symbolic link or junction point, return
8877 the full path to the target. If the target of junction is
8878 removed, return {filename}.
8879 On Unix, repeat resolving symbolic links in all path
8880 components of {filename} and return the simplified result.
8881 To cope with link cycles, resolving of symbolic links is
8882 stopped after 100 iterations.
8883 On other systems, return the simplified {filename}.
8884 The simplification step is done as by |simplify()|.
8885 resolve() keeps a leading path component specifying the
8886 current directory (provided the result is still a relative
8887 path name) and also keeps a trailing path separator.
8888
8889 Can also be used as a |method|: >
8890 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008891<
8892 Return type: |String|
8893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008894
8895reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008896 Reverse the order of items in {object}. {object} can be a
8897 |List|, a |Blob| or a |String|. For a List and a Blob the
8898 items are reversed in-place and {object} is returned.
8899 For a String a new String is returned.
8900 Returns zero if {object} is not a List, Blob or a String.
8901 If you want a List or Blob to remain unmodified make a copy
8902 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008903 :let revlist = reverse(copy(mylist))
8904< Can also be used as a |method|: >
8905 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008906<
8907 Return type: |String|, |Blob| or list<{type}> depending on
8908 {object}
8909
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008910
8911round({expr}) *round()*
8912 Round off {expr} to the nearest integral value and return it
8913 as a |Float|. If {expr} lies halfway between two integral
8914 values, then use the larger one (away from zero).
8915 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008916 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008917 Examples: >
8918 echo round(0.456)
8919< 0.0 >
8920 echo round(4.5)
8921< 5.0 >
8922 echo round(-4.5)
8923< -5.0
8924
8925 Can also be used as a |method|: >
8926 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008927<
8928 Return type: |Float|
8929
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008930
8931rubyeval({expr}) *rubyeval()*
8932 Evaluate Ruby expression {expr} and return its result
8933 converted to Vim data structures.
8934 Numbers, floats and strings are returned as they are (strings
8935 are copied though).
8936 Arrays are represented as Vim |List| type.
8937 Hashes are represented as Vim |Dictionary| type.
8938 Other objects are represented as strings resulted from their
8939 "Object#to_s" method.
8940 Note that in a `:def` function local variables are not visible
8941 to {expr}.
8942
8943 Can also be used as a |method|: >
8944 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008945<
8946 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008947
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008948 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008949
8950screenattr({row}, {col}) *screenattr()*
8951 Like |screenchar()|, but return the attribute. This is a rather
8952 arbitrary number that can only be used to compare to the
8953 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008954 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008955
8956 Can also be used as a |method|: >
8957 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008958<
8959 Return type: |Number|
8960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008961
8962screenchar({row}, {col}) *screenchar()*
8963 The result is a Number, which is the character at position
8964 [row, col] on the screen. This works for every possible
8965 screen position, also status lines, window separators and the
8966 command line. The top left position is row one, column one
8967 The character excludes composing characters. For double-byte
8968 encodings it may only be the first byte.
8969 This is mainly to be used for testing.
8970 Returns -1 when row or col is out of range.
8971
8972 Can also be used as a |method|: >
8973 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008974<
8975 Return type: |Number|
8976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008977
8978screenchars({row}, {col}) *screenchars()*
8979 The result is a |List| of Numbers. The first number is the same
8980 as what |screenchar()| returns. Further numbers are
8981 composing characters on top of the base character.
8982 This is mainly to be used for testing.
8983 Returns an empty List when row or col is out of range.
8984
8985 Can also be used as a |method|: >
8986 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008987<
8988 Return type: list<number> or list<any>
8989
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008990
8991screencol() *screencol()*
8992 The result is a Number, which is the current screen column of
8993 the cursor. The leftmost column has number 1.
8994 This function is mainly used for testing.
8995
8996 Note: Always returns the current screen column, thus if used
8997 in a command (e.g. ":echo screencol()") it will return the
8998 column inside the command line, which is 1 when the command is
8999 executed. To get the cursor position in the file use one of
9000 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009001 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009002 nnoremap <silent> GG :echom screencol()<CR>
9003 nnoremap GG <Cmd>echom screencol()<CR>
9004<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009005 Return type: |Number|
9006
9007
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009008screenpos({winid}, {lnum}, {col}) *screenpos()*
9009 The result is a Dict with the screen position of the text
9010 character in window {winid} at buffer line {lnum} and column
9011 {col}. {col} is a one-based byte index.
9012 The Dict has these members:
9013 row screen row
9014 col first screen column
9015 endcol last screen column
9016 curscol cursor screen column
9017 If the specified position is not visible, all values are zero.
9018 The "endcol" value differs from "col" when the character
9019 occupies more than one screen cell. E.g. for a Tab "col" can
9020 be 1 and "endcol" can be 8.
9021 The "curscol" value is where the cursor would be placed. For
9022 a Tab it would be the same as "endcol", while for a double
9023 width character it would be the same as "col".
9024 The |conceal| feature is ignored here, the column numbers are
9025 as if 'conceallevel' is zero. You can set the cursor to the
9026 right position and use |screencol()| to get the value with
9027 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009028 If the position is in a closed fold the screen position of the
9029 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009030 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009031
9032 Can also be used as a |method|: >
9033 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009034<
9035 Return type: dict<number> or dict<any>
9036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009037
9038screenrow() *screenrow()*
9039 The result is a Number, which is the current screen row of the
9040 cursor. The top line has number one.
9041 This function is mainly used for testing.
9042 Alternatively you can use |winline()|.
9043
9044 Note: Same restrictions as with |screencol()|.
9045
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009046 Return type: |Number|
9047
9048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009049screenstring({row}, {col}) *screenstring()*
9050 The result is a String that contains the base character and
9051 any composing characters at position [row, col] on the screen.
9052 This is like |screenchars()| but returning a String with the
9053 characters.
9054 This is mainly to be used for testing.
9055 Returns an empty String when row or col is out of range.
9056
9057 Can also be used as a |method|: >
9058 GetRow()->screenstring(col)
9059<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009060 Return type: |String|
9061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009062 *search()*
9063search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9064 Search for regexp pattern {pattern}. The search starts at the
9065 cursor position (you can use |cursor()| to set it).
9066
9067 When a match has been found its line number is returned.
9068 If there is no match a 0 is returned and the cursor doesn't
9069 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009070 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009071
9072 {flags} is a String, which can contain these character flags:
9073 'b' search Backward instead of forward
9074 'c' accept a match at the Cursor position
9075 'e' move to the End of the match
9076 'n' do Not move the cursor
9077 'p' return number of matching sub-Pattern (see below)
9078 's' Set the ' mark at the previous location of the cursor
9079 'w' Wrap around the end of the file
9080 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009081 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009082 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9083
9084 If the 's' flag is supplied, the ' mark is set, only if the
9085 cursor is moved. The 's' flag cannot be combined with the 'n'
9086 flag.
9087
9088 'ignorecase', 'smartcase' and 'magic' are used.
9089
9090 When the 'z' flag is not given, forward searching always
9091 starts in column zero and then matches before the cursor are
9092 skipped. When the 'c' flag is present in 'cpo' the next
9093 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009094 search starts one column after the start of the match. This
9095 matters for overlapping matches. See |cpo-c|. You can also
9096 insert "\ze" to change where the match ends, see |/\ze|.
9097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009098 When searching backwards and the 'z' flag is given then the
9099 search starts in column zero, thus no match in the current
9100 line will be found (unless wrapping around the end of the
9101 file).
9102
9103 When the {stopline} argument is given then the search stops
9104 after searching this line. This is useful to restrict the
9105 search to a range of lines. Examples: >
9106 let match = search('(', 'b', line("w0"))
9107 let end = search('END', '', line("w$"))
9108< When {stopline} is used and it is not zero this also implies
9109 that the search does not wrap around the end of the file.
9110 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009111 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009112 When the {timeout} argument is given the search stops when
9113 more than this many milliseconds have passed. Thus when
9114 {timeout} is 500 the search stops after half a second.
9115 The value must not be negative. A zero value is like not
9116 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009117
9118 Note: the timeout is only considered when searching, not
9119 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009120 {only available when compiled with the |+reltime| feature}
9121
9122 If the {skip} expression is given it is evaluated with the
9123 cursor positioned on the start of a match. If it evaluates to
9124 non-zero this match is skipped. This can be used, for
9125 example, to skip a match in a comment or a string.
9126 {skip} can be a string, which is evaluated as an expression, a
9127 function reference or a lambda.
9128 When {skip} is omitted or empty, every match is accepted.
9129 When evaluating {skip} causes an error the search is aborted
9130 and -1 returned.
9131 *search()-sub-match*
9132 With the 'p' flag the returned value is one more than the
9133 first sub-match in \(\). One if none of them matched but the
9134 whole pattern did match.
9135 To get the column number too use |searchpos()|.
9136
9137 The cursor will be positioned at the match, unless the 'n'
9138 flag is used.
9139
9140 Example (goes over all files in the argument list): >
9141 :let n = 1
9142 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009143 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009144 : " start at the last char in the file and wrap for the
9145 : " first search to find match at start of file
9146 : normal G$
9147 : let flags = "w"
9148 : while search("foo", flags) > 0
9149 : s/foo/bar/g
9150 : let flags = "W"
9151 : endwhile
9152 : update " write the file if modified
9153 : let n = n + 1
9154 :endwhile
9155<
9156 Example for using some flags: >
9157 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9158< This will search for the keywords "if", "else", and "endif"
9159 under or after the cursor. Because of the 'p' flag, it
9160 returns 1, 2, or 3 depending on which keyword is found, or 0
9161 if the search fails. With the cursor on the first word of the
9162 line:
9163 if (foo == 0) | let foo = foo + 1 | endif ~
9164 the function returns 1. Without the 'c' flag, the function
9165 finds the "endif" and returns 3. The same thing happens
9166 without the 'e' flag if the cursor is on the "f" of "if".
9167 The 'n' flag tells the function not to move the cursor.
9168
9169 Can also be used as a |method|: >
9170 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009171<
9172 Return type: |Number|
9173
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009174
9175searchcount([{options}]) *searchcount()*
9176 Get or update the last search count, like what is displayed
9177 without the "S" flag in 'shortmess'. This works even if
9178 'shortmess' does contain the "S" flag.
9179
9180 This returns a |Dictionary|. The dictionary is empty if the
9181 previous pattern was not set and "pattern" was not specified.
9182
9183 key type meaning ~
9184 current |Number| current position of match;
9185 0 if the cursor position is
9186 before the first match
9187 exact_match |Boolean| 1 if "current" is matched on
9188 "pos", otherwise 0
9189 total |Number| total count of matches found
9190 incomplete |Number| 0: search was fully completed
9191 1: recomputing was timed out
9192 2: max count exceeded
9193
9194 For {options} see further down.
9195
9196 To get the last search count when |n| or |N| was pressed, call
9197 this function with `recompute: 0` . This sometimes returns
9198 wrong information because |n| and |N|'s maximum count is 99.
9199 If it exceeded 99 the result must be max count + 1 (100). If
9200 you want to get correct information, specify `recompute: 1`: >
9201
9202 " result == maxcount + 1 (100) when many matches
9203 let result = searchcount(#{recompute: 0})
9204
9205 " Below returns correct result (recompute defaults
9206 " to 1)
9207 let result = searchcount()
9208<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009209 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009210 function! LastSearchCount() abort
9211 let result = searchcount(#{recompute: 0})
9212 if empty(result)
9213 return ''
9214 endif
9215 if result.incomplete ==# 1 " timed out
9216 return printf(' /%s [?/??]', @/)
9217 elseif result.incomplete ==# 2 " max count exceeded
9218 if result.total > result.maxcount &&
9219 \ result.current > result.maxcount
9220 return printf(' /%s [>%d/>%d]', @/,
9221 \ result.current, result.total)
9222 elseif result.total > result.maxcount
9223 return printf(' /%s [%d/>%d]', @/,
9224 \ result.current, result.total)
9225 endif
9226 endif
9227 return printf(' /%s [%d/%d]', @/,
9228 \ result.current, result.total)
9229 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009230 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009231
9232 " Or if you want to show the count only when
9233 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009234 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009235 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9236<
9237 You can also update the search count, which can be useful in a
9238 |CursorMoved| or |CursorMovedI| autocommand: >
9239
9240 autocmd CursorMoved,CursorMovedI *
9241 \ let s:searchcount_timer = timer_start(
9242 \ 200, function('s:update_searchcount'))
9243 function! s:update_searchcount(timer) abort
9244 if a:timer ==# s:searchcount_timer
9245 call searchcount(#{
9246 \ recompute: 1, maxcount: 0, timeout: 100})
9247 redrawstatus
9248 endif
9249 endfunction
9250<
9251 This can also be used to count matched texts with specified
9252 pattern in the current buffer using "pattern": >
9253
9254 " Count '\<foo\>' in this buffer
9255 " (Note that it also updates search count)
9256 let result = searchcount(#{pattern: '\<foo\>'})
9257
9258 " To restore old search count by old pattern,
9259 " search again
9260 call searchcount()
9261<
9262 {options} must be a |Dictionary|. It can contain:
9263 key type meaning ~
9264 recompute |Boolean| if |TRUE|, recompute the count
9265 like |n| or |N| was executed.
9266 otherwise returns the last
9267 computed result (when |n| or
9268 |N| was used when "S" is not
9269 in 'shortmess', or this
9270 function was called).
9271 (default: |TRUE|)
9272 pattern |String| recompute if this was given
9273 and different with |@/|.
9274 this works as same as the
9275 below command is executed
9276 before calling this function >
9277 let @/ = pattern
9278< (default: |@/|)
9279 timeout |Number| 0 or negative number is no
9280 timeout. timeout milliseconds
9281 for recomputing the result
9282 (default: 0)
9283 maxcount |Number| 0 or negative number is no
9284 limit. max count of matched
9285 text while recomputing the
9286 result. if search exceeded
9287 total count, "total" value
9288 becomes `maxcount + 1`
9289 (default: 99)
9290 pos |List| `[lnum, col, off]` value
9291 when recomputing the result.
9292 this changes "current" result
9293 value. see |cursor()|,
9294 |getpos()|
9295 (default: cursor's position)
9296
9297 Can also be used as a |method|: >
9298 GetSearchOpts()->searchcount()
9299<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009300 Return type: dict<number>
9301
9302
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009303searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9304 Search for the declaration of {name}.
9305
9306 With a non-zero {global} argument it works like |gD|, find
9307 first match in the file. Otherwise it works like |gd|, find
9308 first match in the function.
9309
9310 With a non-zero {thisblock} argument matches in a {} block
9311 that ends before the cursor position are ignored. Avoids
9312 finding variable declarations only valid in another scope.
9313
9314 Moves the cursor to the found match.
9315 Returns zero for success, non-zero for failure.
9316 Example: >
9317 if searchdecl('myvar') == 0
9318 echo getline('.')
9319 endif
9320<
9321 Can also be used as a |method|: >
9322 GetName()->searchdecl()
9323<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009324 Return type: |Number|
9325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009326 *searchpair()*
9327searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9328 [, {stopline} [, {timeout}]]]])
9329 Search for the match of a nested start-end pair. This can be
9330 used to find the "endif" that matches an "if", while other
9331 if/endif pairs in between are ignored.
9332 The search starts at the cursor. The default is to search
9333 forward, include 'b' in {flags} to search backward.
9334 If a match is found, the cursor is positioned at it and the
9335 line number is returned. If no match is found 0 or -1 is
9336 returned and the cursor doesn't move. No error message is
9337 given.
9338
9339 {start}, {middle} and {end} are patterns, see |pattern|. They
9340 must not contain \( \) pairs. Use of \%( \) is allowed. When
9341 {middle} is not empty, it is found when searching from either
9342 direction, but only when not in a nested start-end pair. A
9343 typical use is: >
9344 searchpair('\<if\>', '\<else\>', '\<endif\>')
9345< By leaving {middle} empty the "else" is skipped.
9346
9347 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9348 |search()|. Additionally:
9349 'r' Repeat until no more matches found; will find the
9350 outer pair. Implies the 'W' flag.
9351 'm' Return number of matches instead of line number with
9352 the match; will be > 1 when 'r' is used.
9353 Note: it's nearly always a good idea to use the 'W' flag, to
9354 avoid wrapping around the end of the file.
9355
9356 When a match for {start}, {middle} or {end} is found, the
9357 {skip} expression is evaluated with the cursor positioned on
9358 the start of the match. It should return non-zero if this
9359 match is to be skipped. E.g., because it is inside a comment
9360 or a string.
9361 When {skip} is omitted or empty, every match is accepted.
9362 When evaluating {skip} causes an error the search is aborted
9363 and -1 returned.
9364 {skip} can be a string, a lambda, a funcref or a partial.
9365 Anything else makes the function fail.
9366 In a `:def` function when the {skip} argument is a string
9367 constant it is compiled into instructions.
9368
9369 For {stopline} and {timeout} see |search()|.
9370
9371 The value of 'ignorecase' is used. 'magic' is ignored, the
9372 patterns are used like it's on.
9373
9374 The search starts exactly at the cursor. A match with
9375 {start}, {middle} or {end} at the next character, in the
9376 direction of searching, is the first one found. Example: >
9377 if 1
9378 if 2
9379 endif 2
9380 endif 1
9381< When starting at the "if 2", with the cursor on the "i", and
9382 searching forwards, the "endif 2" is found. When starting on
9383 the character just before the "if 2", the "endif 1" will be
9384 found. That's because the "if 2" will be found first, and
9385 then this is considered to be a nested if/endif from "if 2" to
9386 "endif 2".
9387 When searching backwards and {end} is more than one character,
9388 it may be useful to put "\zs" at the end of the pattern, so
9389 that when the cursor is inside a match with the end it finds
9390 the matching start.
9391
9392 Example, to find the "endif" command in a Vim script: >
9393
9394 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9395 \ 'getline(".") =~ "^\\s*\""')
9396
9397< The cursor must be at or after the "if" for which a match is
9398 to be found. Note that single-quote strings are used to avoid
9399 having to double the backslashes. The skip expression only
9400 catches comments at the start of a line, not after a command.
9401 Also, a word "en" or "if" halfway a line is considered a
9402 match.
9403 Another example, to search for the matching "{" of a "}": >
9404
9405 :echo searchpair('{', '', '}', 'bW')
9406
9407< This works when the cursor is at or before the "}" for which a
9408 match is to be found. To reject matches that syntax
9409 highlighting recognized as strings: >
9410
9411 :echo searchpair('{', '', '}', 'bW',
9412 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9413<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009414 Return type: |Number|
9415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009416 *searchpairpos()*
9417searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9418 [, {stopline} [, {timeout}]]]])
9419 Same as |searchpair()|, but returns a |List| with the line and
9420 column position of the match. The first element of the |List|
9421 is the line number and the second element is the byte index of
9422 the column position of the match. If no match is found,
9423 returns [0, 0]. >
9424
9425 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9426<
9427 See |match-parens| for a bigger and more useful example.
9428
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009429 Return type: list<number>
9430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009431 *searchpos()*
9432searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9433 Same as |search()|, but returns a |List| with the line and
9434 column position of the match. The first element of the |List|
9435 is the line number and the second element is the byte index of
9436 the column position of the match. If no match is found,
9437 returns [0, 0].
9438 Example: >
9439 :let [lnum, col] = searchpos('mypattern', 'n')
9440
9441< When the 'p' flag is given then there is an extra item with
9442 the sub-pattern match number |search()-sub-match|. Example: >
9443 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9444< In this example "submatch" is 2 when a lowercase letter is
9445 found |/\l|, 3 when an uppercase letter is found |/\u|.
9446
9447 Can also be used as a |method|: >
9448 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009449<
9450 Return type: list<number>
9451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009452
9453server2client({clientid}, {string}) *server2client()*
9454 Send a reply string to {clientid}. The most recent {clientid}
9455 that sent a string can be retrieved with expand("<client>").
9456 {only available when compiled with the |+clientserver| feature}
9457 Returns zero for success, -1 for failure.
9458 Note:
9459 This id has to be stored before the next command can be
9460 received. I.e. before returning from the received command and
9461 before calling any commands that waits for input.
9462 See also |clientserver|.
9463 Example: >
9464 :echo server2client(expand("<client>"), "HELLO")
9465
9466< Can also be used as a |method|: >
9467 GetClientId()->server2client(string)
9468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009469 Return type: |Number|
9470
9471
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009472serverlist() *serverlist()*
9473 Return a list of available server names, one per line.
9474 When there are no servers or the information is not available
9475 an empty string is returned. See also |clientserver|.
9476 {only available when compiled with the |+clientserver| feature}
9477 Example: >
9478 :echo serverlist()
9479<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009480 Return type: |String|
9481
9482
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009483setbufline({buf}, {lnum}, {text}) *setbufline()*
9484 Set line {lnum} to {text} in buffer {buf}. This works like
9485 |setline()| for the specified buffer.
9486
9487 This function works only for loaded buffers. First call
9488 |bufload()| if needed.
9489
9490 To insert lines use |appendbufline()|.
9491 Any text properties in {lnum} are cleared.
9492
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009493 {text} can be a string to set one line, or a List of strings
9494 to set multiple lines. If the List extends below the last
9495 line then those lines are added. If the List is empty then
9496 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009497
9498 For the use of {buf}, see |bufname()| above.
9499
9500 {lnum} is used like with |setline()|.
9501 Use "$" to refer to the last line in buffer {buf}.
9502 When {lnum} is just below the last line the {text} will be
9503 added below the last line.
9504
9505 When {buf} is not a valid buffer, the buffer is not loaded or
9506 {lnum} is not valid then 1 is returned. In |Vim9| script an
9507 error is given.
9508 On success 0 is returned.
9509
9510 Can also be used as a |method|, the base is passed as the
9511 third argument: >
9512 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009513<
9514 Return type: |Number|
9515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009516
9517setbufvar({buf}, {varname}, {val}) *setbufvar()*
9518 Set option or local variable {varname} in buffer {buf} to
9519 {val}.
9520 This also works for a global or local window option, but it
9521 doesn't work for a global or local window variable.
9522 For a local window option the global value is unchanged.
9523 For the use of {buf}, see |bufname()| above.
9524 The {varname} argument is a string.
9525 Note that the variable name without "b:" must be used.
9526 Examples: >
9527 :call setbufvar(1, "&mod", 1)
9528 :call setbufvar("todo", "myvar", "foobar")
9529< This function is not available in the |sandbox|.
9530
9531 Can also be used as a |method|, the base is passed as the
9532 third argument: >
9533 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009534<
9535 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009536
9537
9538setcellwidths({list}) *setcellwidths()*
9539 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009540 tells Vim how wide characters are when displayed in the
9541 terminal, counted in screen cells. The values override
9542 'ambiwidth'. Example: >
9543 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009544 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009545 \ [0x2194, 0x2199, 2],
9546 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009547
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009548< The {list} argument is a List of Lists with each three
9549 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9550 {low} and {high} can be the same, in which case this refers to
9551 one character. Otherwise it is the range of characters from
9552 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009553 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009554
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009555 {width} must be either 1 or 2, indicating the character width
9556 in screen cells. *E1112*
9557 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009558 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009559
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009560 If the new value causes 'fillchars' or 'listchars' to become
9561 invalid it is rejected and an error is given.
9562
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009563 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009564 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009566< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009567 the effect for known emoji characters. Move the cursor
9568 through the text to check if the cell widths of your terminal
9569 match with what Vim knows about each emoji. If it doesn't
9570 look right you need to adjust the {list} argument.
9571
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009572 Return type: |Number|
9573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009574
9575setcharpos({expr}, {list}) *setcharpos()*
9576 Same as |setpos()| but uses the specified column number as the
9577 character index instead of the byte index in the line.
9578
9579 Example:
9580 With the text "여보세요" in line 8: >
9581 call setcharpos('.', [0, 8, 4, 0])
9582< positions the cursor on the fourth character '요'. >
9583 call setpos('.', [0, 8, 4, 0])
9584< positions the cursor on the second character '보'.
9585
9586 Can also be used as a |method|: >
9587 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009588<
9589 Return type: |Number|
9590
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009591
9592setcharsearch({dict}) *setcharsearch()*
9593 Set the current character search information to {dict},
9594 which contains one or more of the following entries:
9595
9596 char character which will be used for a subsequent
9597 |,| or |;| command; an empty string clears the
9598 character search
9599 forward direction of character search; 1 for forward,
9600 0 for backward
9601 until type of character search; 1 for a |t| or |T|
9602 character search, 0 for an |f| or |F|
9603 character search
9604
9605 This can be useful to save/restore a user's character search
9606 from a script: >
9607 :let prevsearch = getcharsearch()
9608 :" Perform a command which clobbers user's search
9609 :call setcharsearch(prevsearch)
9610< Also see |getcharsearch()|.
9611
9612 Can also be used as a |method|: >
9613 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009614<
9615 Return type: dict<any>
9616
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009617
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009618setcmdline({str} [, {pos}]) *setcmdline()*
9619 Set the command line to {str} and set the cursor position to
9620 {pos}.
9621 If {pos} is omitted, the cursor is positioned after the text.
9622 Returns 0 when successful, 1 when not editing the command
9623 line.
9624
9625 Can also be used as a |method|: >
9626 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009627<
9628 Return type: |Number|
9629
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009631setcmdpos({pos}) *setcmdpos()*
9632 Set the cursor position in the command line to byte position
9633 {pos}. The first position is 1.
9634 Use |getcmdpos()| to obtain the current position.
9635 Only works while editing the command line, thus you must use
9636 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9637 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9638 set after the command line is set to the expression. For
9639 |c_CTRL-R_=| it is set after evaluating the expression but
9640 before inserting the resulting text.
9641 When the number is too big the cursor is put at the end of the
9642 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009643 Returns 0 when successful, 1 when not editing the command
9644 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009645
9646 Can also be used as a |method|: >
9647 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009648<
9649 Return type: |Number|
9650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009651
9652setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9653setcursorcharpos({list})
9654 Same as |cursor()| but uses the specified column number as the
9655 character index instead of the byte index in the line.
9656
9657 Example:
9658 With the text "여보세요" in line 4: >
9659 call setcursorcharpos(4, 3)
9660< positions the cursor on the third character '세'. >
9661 call cursor(4, 3)
9662< positions the cursor on the first character '여'.
9663
9664 Can also be used as a |method|: >
9665 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009666<
9667 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009668
9669
9670setenv({name}, {val}) *setenv()*
9671 Set environment variable {name} to {val}. Example: >
9672 call setenv('HOME', '/home/myhome')
9673
9674< When {val} is |v:null| the environment variable is deleted.
9675 See also |expr-env|.
9676
9677 Can also be used as a |method|, the base is passed as the
9678 second argument: >
9679 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009680<
9681 Return type: |Number|
9682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009683
9684setfperm({fname}, {mode}) *setfperm()* *chmod*
9685 Set the file permissions for {fname} to {mode}.
9686 {mode} must be a string with 9 characters. It is of the form
9687 "rwxrwxrwx", where each group of "rwx" flags represent, in
9688 turn, the permissions of the owner of the file, the group the
9689 file belongs to, and other users. A '-' character means the
9690 permission is off, any other character means on. Multi-byte
9691 characters are not supported.
9692
9693 For example "rw-r-----" means read-write for the user,
9694 readable by the group, not accessible by others. "xx-x-----"
9695 would do the same thing.
9696
9697 Returns non-zero for success, zero for failure.
9698
9699 Can also be used as a |method|: >
9700 GetFilename()->setfperm(mode)
9701<
9702 To read permissions see |getfperm()|.
9703
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009704 Return type: |Number|
9705
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009706
9707setline({lnum}, {text}) *setline()*
9708 Set line {lnum} of the current buffer to {text}. To insert
9709 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009710 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009711 Any text properties in {lnum} are cleared. See
9712 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009713
9714 {lnum} is used like with |getline()|.
9715 When {lnum} is just below the last line the {text} will be
9716 added below the last line.
9717 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009718 converted to a String. When {text} is an empty List then
9719 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009720
9721 If this succeeds, FALSE is returned. If this fails (most likely
9722 because {lnum} is invalid) TRUE is returned.
9723 In |Vim9| script an error is given if {lnum} is invalid.
9724
9725 Example: >
9726 :call setline(5, strftime("%c"))
9727
9728< When {text} is a |List| then line {lnum} and following lines
9729 will be set to the items in the list. Example: >
9730 :call setline(5, ['aaa', 'bbb', 'ccc'])
9731< This is equivalent to: >
9732 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9733 : call setline(n, l)
9734 :endfor
9735
9736< Note: The '[ and '] marks are not set.
9737
9738 Can also be used as a |method|, the base is passed as the
9739 second argument: >
9740 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009741<
9742 Return type: |Number|
9743
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009744
9745setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9746 Create or replace or add to the location list for window {nr}.
9747 {nr} can be the window number or the |window-ID|.
9748 When {nr} is zero the current window is used.
9749
9750 For a location list window, the displayed location list is
9751 modified. For an invalid window number {nr}, -1 is returned.
9752 Otherwise, same as |setqflist()|.
9753 Also see |location-list|.
9754
9755 For {action} see |setqflist-action|.
9756
9757 If the optional {what} dictionary argument is supplied, then
9758 only the items listed in {what} are set. Refer to |setqflist()|
9759 for the list of supported keys in {what}.
9760
9761 Can also be used as a |method|, the base is passed as the
9762 second argument: >
9763 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009764<
9765 Return type: |Number|
9766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009767
9768setmatches({list} [, {win}]) *setmatches()*
9769 Restores a list of matches saved by |getmatches()| for the
9770 current window. Returns 0 if successful, otherwise -1. All
9771 current matches are cleared before the list is restored. See
9772 example for |getmatches()|.
9773 If {win} is specified, use the window with this number or
9774 window ID instead of the current window.
9775
9776 Can also be used as a |method|: >
9777 GetMatches()->setmatches()
9778<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009779 Return type: |Number|
9780
9781
9782setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009783 Set the position for String {expr}. Possible values:
9784 . the cursor
9785 'x mark x
9786
9787 {list} must be a |List| with four or five numbers:
9788 [bufnum, lnum, col, off]
9789 [bufnum, lnum, col, off, curswant]
9790
9791 "bufnum" is the buffer number. Zero can be used for the
9792 current buffer. When setting an uppercase mark "bufnum" is
9793 used for the mark position. For other marks it specifies the
9794 buffer to set the mark in. You can use the |bufnr()| function
9795 to turn a file name into a buffer number.
9796 For setting the cursor and the ' mark "bufnum" is ignored,
9797 since these are associated with a window, not a buffer.
9798 Does not change the jumplist.
9799
9800 "lnum" and "col" are the position in the buffer. The first
9801 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9802 smaller than 1 then 1 is used. To use the character count
9803 instead of the byte count, use |setcharpos()|.
9804
9805 The "off" number is only used when 'virtualedit' is set. Then
9806 it is the offset in screen columns from the start of the
9807 character. E.g., a position within a <Tab> or after the last
9808 character.
9809
9810 The "curswant" number is only used when setting the cursor
9811 position. It sets the preferred column for when moving the
9812 cursor vertically. When the "curswant" number is missing the
9813 preferred column is not set. When it is present and setting a
9814 mark position it is not used.
9815
9816 Note that for '< and '> changing the line number may result in
9817 the marks to be effectively be swapped, so that '< is always
9818 before '>.
9819
9820 Returns 0 when the position could be set, -1 otherwise.
9821 An error message is given if {expr} is invalid.
9822
9823 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9824
9825 This does not restore the preferred column for moving
9826 vertically; if you set the cursor position with this, |j| and
9827 |k| motions will jump to previous columns! Use |cursor()| to
9828 also set the preferred column. Also see the "curswant" key in
9829 |winrestview()|.
9830
9831 Can also be used as a |method|: >
9832 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009833<
9834 Return type: |Number|
9835
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009836
9837setqflist({list} [, {action} [, {what}]]) *setqflist()*
9838 Create or replace or add to the quickfix list.
9839
9840 If the optional {what} dictionary argument is supplied, then
9841 only the items listed in {what} are set. The first {list}
9842 argument is ignored. See below for the supported items in
9843 {what}.
9844 *setqflist-what*
9845 When {what} is not present, the items in {list} are used. Each
9846 item must be a dictionary. Non-dictionary items in {list} are
9847 ignored. Each dictionary item can contain the following
9848 entries:
9849
9850 bufnr buffer number; must be the number of a valid
9851 buffer
9852 filename name of a file; only used when "bufnr" is not
9853 present or it is invalid.
9854 module name of a module; if given it will be used in
9855 quickfix error window instead of the filename.
9856 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009857 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009858 pattern search pattern used to locate the error
9859 col column number
9860 vcol when non-zero: "col" is visual column
9861 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009862 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009863 nr error number
9864 text description of the error
9865 type single-character error type, 'E', 'W', etc.
9866 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009867 user_data custom data associated with the item, can be
9868 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009869
9870 The "col", "vcol", "nr", "type" and "text" entries are
9871 optional. Either "lnum" or "pattern" entry can be used to
9872 locate a matching error line.
9873 If the "filename" and "bufnr" entries are not present or
9874 neither the "lnum" or "pattern" entries are present, then the
9875 item will not be handled as an error line.
9876 If both "pattern" and "lnum" are present then "pattern" will
9877 be used.
9878 If the "valid" entry is not supplied, then the valid flag is
9879 set when "bufnr" is a valid buffer or "filename" exists.
9880 If you supply an empty {list}, the quickfix list will be
9881 cleared.
9882 Note that the list is not exactly the same as what
9883 |getqflist()| returns.
9884
9885 {action} values: *setqflist-action* *E927*
9886 'a' The items from {list} are added to the existing
9887 quickfix list. If there is no existing list, then a
9888 new list is created.
9889
9890 'r' The items from the current quickfix list are replaced
9891 with the items from {list}. This can also be used to
9892 clear the list: >
9893 :call setqflist([], 'r')
9894<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009895 'u' Like 'r', but tries to preserve the current selection
9896 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009897 'f' All the quickfix lists in the quickfix stack are
9898 freed.
9899
9900 If {action} is not present or is set to ' ', then a new list
9901 is created. The new quickfix list is added after the current
9902 quickfix list in the stack and all the following lists are
9903 freed. To add a new quickfix list at the end of the stack,
9904 set "nr" in {what} to "$".
9905
9906 The following items can be specified in dictionary {what}:
9907 context quickfix list context. See |quickfix-context|
9908 efm errorformat to use when parsing text from
9909 "lines". If this is not present, then the
9910 'errorformat' option value is used.
9911 See |quickfix-parse|
9912 id quickfix list identifier |quickfix-ID|
9913 idx index of the current entry in the quickfix
9914 list specified by 'id' or 'nr'. If set to '$',
9915 then the last entry in the list is set as the
9916 current entry. See |quickfix-index|
9917 items list of quickfix entries. Same as the {list}
9918 argument.
9919 lines use 'errorformat' to parse a list of lines and
9920 add the resulting entries to the quickfix list
9921 {nr} or {id}. Only a |List| value is supported.
9922 See |quickfix-parse|
9923 nr list number in the quickfix stack; zero
9924 means the current quickfix list and "$" means
9925 the last quickfix list.
9926 quickfixtextfunc
9927 function to get the text to display in the
9928 quickfix window. The value can be the name of
9929 a function or a funcref or a lambda. Refer to
9930 |quickfix-window-function| for an explanation
9931 of how to write the function and an example.
9932 title quickfix list title text. See |quickfix-title|
9933 Unsupported keys in {what} are ignored.
9934 If the "nr" item is not present, then the current quickfix list
9935 is modified. When creating a new quickfix list, "nr" can be
9936 set to a value one greater than the quickfix stack size.
9937 When modifying a quickfix list, to guarantee that the correct
9938 list is modified, "id" should be used instead of "nr" to
9939 specify the list.
9940
9941 Examples (See also |setqflist-examples|): >
9942 :call setqflist([], 'r', {'title': 'My search'})
9943 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9944 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9945<
9946 Returns zero for success, -1 for failure.
9947
9948 This function can be used to create a quickfix list
9949 independent of the 'errorformat' setting. Use a command like
9950 `:cc 1` to jump to the first position.
9951
9952 Can also be used as a |method|, the base is passed as the
9953 second argument: >
9954 GetErrorlist()->setqflist()
9955<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009956 Return type: |Number|
9957
9958
9959setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009960 Set the register {regname} to {value}.
9961 If {regname} is "" or "@", the unnamed register '"' is used.
9962 The {regname} argument is a string. In |Vim9-script|
9963 {regname} must be one character.
9964
9965 {value} may be any value returned by |getreg()| or
9966 |getreginfo()|, including a |List| or |Dict|.
9967 If {options} contains "a" or {regname} is upper case,
9968 then the value is appended.
9969
9970 {options} can also contain a register type specification:
9971 "c" or "v" |characterwise| mode
9972 "l" or "V" |linewise| mode
9973 "b" or "<CTRL-V>" |blockwise-visual| mode
9974 If a number immediately follows "b" or "<CTRL-V>" then this is
9975 used as the width of the selection - if it is not specified
9976 then the width of the block is set to the number of characters
9977 in the longest line (counting a <Tab> as 1 character).
9978
9979 If {options} contains no register settings, then the default
9980 is to use character mode unless {value} ends in a <NL> for
9981 string {value} and linewise mode for list {value}. Blockwise
9982 mode is never selected automatically.
9983 Returns zero for success, non-zero for failure.
9984
9985 *E883*
9986 Note: you may not use |List| containing more than one item to
9987 set search and expression registers. Lists containing no
9988 items act like empty strings.
9989
9990 Examples: >
9991 :call setreg(v:register, @*)
9992 :call setreg('*', @%, 'ac')
9993 :call setreg('a', "1\n2\n3", 'b5')
9994 :call setreg('"', { 'points_to': 'a'})
9995
9996< This example shows using the functions to save and restore a
9997 register: >
9998 :let var_a = getreginfo()
9999 :call setreg('a', var_a)
10000< or: >
10001 :let var_a = getreg('a', 1, 1)
10002 :let var_amode = getregtype('a')
10003 ....
10004 :call setreg('a', var_a, var_amode)
10005< Note: you may not reliably restore register value
10006 without using the third argument to |getreg()| as without it
10007 newlines are represented as newlines AND Nul bytes are
10008 represented as newlines as well, see |NL-used-for-Nul|.
10009
10010 You can also change the type of a register by appending
10011 nothing: >
10012 :call setreg('a', '', 'al')
10013
10014< Can also be used as a |method|, the base is passed as the
10015 second argument: >
10016 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010017<
10018 Return type: |Number|
10019
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010020
10021settabvar({tabnr}, {varname}, {val}) *settabvar()*
10022 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10023 |t:var|
10024 The {varname} argument is a string.
10025 Note that autocommands are blocked, side effects may not be
10026 triggered, e.g. when setting 'filetype'.
10027 Note that the variable name without "t:" must be used.
10028 Tabs are numbered starting with one.
10029 This function is not available in the |sandbox|.
10030
10031 Can also be used as a |method|, the base is passed as the
10032 third argument: >
10033 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010034<
10035 Return type: |Number|
10036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010037
10038settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10039 Set option or local variable {varname} in window {winnr} to
10040 {val}.
10041 Tabs are numbered starting with one. For the current tabpage
10042 use |setwinvar()|.
10043 {winnr} can be the window number or the |window-ID|.
10044 When {winnr} is zero the current window is used.
10045 Note that autocommands are blocked, side effects may not be
10046 triggered, e.g. when setting 'filetype' or 'syntax'.
10047 This also works for a global or local buffer option, but it
10048 doesn't work for a global or local buffer variable.
10049 For a local buffer option the global value is unchanged.
10050 Note that the variable name without "w:" must be used.
10051 Examples: >
10052 :call settabwinvar(1, 1, "&list", 0)
10053 :call settabwinvar(3, 2, "myvar", "foobar")
10054< This function is not available in the |sandbox|.
10055
10056 Can also be used as a |method|, the base is passed as the
10057 fourth argument: >
10058 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010059<
10060 Return type: |Number|
10061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010062
10063settagstack({nr}, {dict} [, {action}]) *settagstack()*
10064 Modify the tag stack of the window {nr} using {dict}.
10065 {nr} can be the window number or the |window-ID|.
10066
10067 For a list of supported items in {dict}, refer to
10068 |gettagstack()|. "curidx" takes effect before changing the tag
10069 stack.
10070 *E962*
10071 How the tag stack is modified depends on the {action}
10072 argument:
10073 - If {action} is not present or is set to 'r', then the tag
10074 stack is replaced.
10075 - If {action} is set to 'a', then new entries from {dict} are
10076 pushed (added) onto the tag stack.
10077 - If {action} is set to 't', then all the entries from the
10078 current entry in the tag stack or "curidx" in {dict} are
10079 removed and then new entries are pushed to the stack.
10080
10081 The current index is set to one after the length of the tag
10082 stack after the modification.
10083
10084 Returns zero for success, -1 for failure.
10085
10086 Examples (for more examples see |tagstack-examples|):
10087 Empty the tag stack of window 3: >
10088 call settagstack(3, {'items' : []})
10089
10090< Save and restore the tag stack: >
10091 let stack = gettagstack(1003)
10092 " do something else
10093 call settagstack(1003, stack)
10094 unlet stack
10095<
10096 Can also be used as a |method|, the base is passed as the
10097 second argument: >
10098 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010099<
10100 Return type: |Number|
10101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010102
10103setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10104 Like |settabwinvar()| for the current tab page.
10105 Examples: >
10106 :call setwinvar(1, "&list", 0)
10107 :call setwinvar(2, "myvar", "foobar")
10108
10109< Can also be used as a |method|, the base is passed as the
10110 third argument: >
10111 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010112<
10113 Return type: |Number|
10114
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010115
10116sha256({string}) *sha256()*
10117 Returns a String with 64 hex characters, which is the SHA256
10118 checksum of {string}.
10119
10120 Can also be used as a |method|: >
10121 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010122<
10123 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010124
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010125 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010126
10127shellescape({string} [, {special}]) *shellescape()*
10128 Escape {string} for use as a shell command argument.
10129 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010130 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010131 in single quotes and will double up all internal single
10132 quotes.
10133 On MS-Windows, when 'shellslash' is not set, it will enclose
10134 {string} in double quotes and double all double quotes within
10135 {string}.
10136 Otherwise it will enclose {string} in single quotes and
10137 replace all "'" with "'\''".
10138
Enno5faeb602024-05-15 21:54:19 +020010139 The {special} argument adds additional escaping of keywords
10140 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010141 number or a non-empty String (|non-zero-arg|), then special
10142 items such as "!", "%", "#" and "<cword>" (as listed in
10143 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010144 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010145
10146 The "!" character will be escaped (again with a |non-zero-arg|
10147 {special}) when 'shell' contains "csh" in the tail. That is
10148 because for csh and tcsh "!" is used for history replacement
10149 even when inside single quotes.
10150
10151 With a |non-zero-arg| {special} the <NL> character is also
10152 escaped. When 'shell' containing "csh" in the tail it's
10153 escaped a second time.
10154
10155 The "\" character will be escaped when 'shell' contains "fish"
10156 in the tail. That is because for fish "\" is used as an escape
10157 character inside single quotes.
10158
10159 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010160 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010161< This results in a directory listing for the file under the
10162 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010163 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010164< See also |::S|.
10165
10166 Can also be used as a |method|: >
10167 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010168<
10169 Return type: |String|
10170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010171
10172shiftwidth([{col}]) *shiftwidth()*
10173 Returns the effective value of 'shiftwidth'. This is the
10174 'shiftwidth' value unless it is zero, in which case it is the
10175 'tabstop' value. This function was introduced with patch
10176 7.3.694 in 2012, everybody should have it by now (however it
10177 did not allow for the optional {col} argument until 8.1.542).
10178
10179 When there is one argument {col} this is used as column number
10180 for which to return the 'shiftwidth' value. This matters for the
10181 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10182 no {col} argument is given, column 1 will be assumed.
10183
10184 Can also be used as a |method|: >
10185 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010186<
10187 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010188
10189sign_ functions are documented here: |sign-functions-details|
10190
10191
10192simplify({filename}) *simplify()*
10193 Simplify the file name as much as possible without changing
10194 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10195 Unix) are not resolved. If the first path component in
10196 {filename} designates the current directory, this will be
10197 valid for the result as well. A trailing path separator is
10198 not removed either. On Unix "//path" is unchanged, but
10199 "///path" is simplified to "/path" (this follows the Posix
10200 standard).
10201 Example: >
10202 simplify("./dir/.././/file/") == "./file/"
10203< Note: The combination "dir/.." is only removed if "dir" is
10204 a searchable directory or does not exist. On Unix, it is also
10205 removed when "dir" is a symbolic link within the same
10206 directory. In order to resolve all the involved symbolic
10207 links before simplifying the path name, use |resolve()|.
10208
10209 Can also be used as a |method|: >
10210 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010211<
10212 Return type: |String|
10213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010214
10215sin({expr}) *sin()*
10216 Return the sine of {expr}, measured in radians, as a |Float|.
10217 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010218 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010219 Examples: >
10220 :echo sin(100)
10221< -0.506366 >
10222 :echo sin(-4.01)
10223< 0.763301
10224
10225 Can also be used as a |method|: >
10226 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010227<
10228 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010229
10230
10231sinh({expr}) *sinh()*
10232 Return the hyperbolic sine of {expr} as a |Float| in the range
10233 [-inf, inf].
10234 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010235 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010236 Examples: >
10237 :echo sinh(0.5)
10238< 0.521095 >
10239 :echo sinh(-0.9)
10240< -1.026517
10241
10242 Can also be used as a |method|: >
10243 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010244<
10245 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010246
10247
10248slice({expr}, {start} [, {end}]) *slice()*
10249 Similar to using a |slice| "expr[start : end]", but "end" is
10250 used exclusive. And for a string the indexes are used as
10251 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010252 |vim9script|. Also, composing characters are treated as a
10253 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010254 When {end} is omitted the slice continues to the last item.
10255 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010256 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010257
10258 Can also be used as a |method|: >
10259 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010260<
10261 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010262
10263
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010264sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010265 Sort the items in {list} in-place. Returns {list}.
10266
10267 If you want a list to remain unmodified make a copy first: >
10268 :let sortedlist = sort(copy(mylist))
10269
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010270< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010271 string representation of each item to sort on. Numbers sort
10272 after Strings, |Lists| after Numbers. For sorting text in the
10273 current buffer use |:sort|.
10274
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010275 When {how} is given and it is 'i' then case is ignored.
10276 In legacy script, for backwards compatibility, the value one
10277 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010278
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010279 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010280 locale is used for ordering. Implementation details: strcoll()
10281 is used to compare strings. See |:language| check or set the
10282 collation locale. |v:collate| can also be used to check the
10283 current locale. Sorting using the locale typically ignores
10284 case. Example: >
10285 " ö is sorted similarly to o with English locale.
10286 :language collate en_US.UTF8
10287 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10288< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10289>
10290 " ö is sorted after z with Swedish locale.
10291 :language collate sv_SE.UTF8
10292 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10293< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10294 This does not work properly on Mac.
10295
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010296 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010297 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010298 strtod() function to parse numbers. Strings, Lists, Dicts and
10299 Funcrefs will be considered as being 0). Note that this won't
10300 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010301
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010302 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010303 sorted numerical. This is like 'n' but a string containing
10304 digits will be used as the number they represent.
10305
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010306 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010307 sorted numerical. All values must be a Number or a Float.
10308
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010309 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010310 is called to compare items. The function is invoked with two
10311 items as argument and must return zero if they are equal, 1 or
10312 bigger if the first one sorts after the second one, -1 or
10313 smaller if the first one sorts before the second one.
10314
10315 {dict} is for functions with the "dict" attribute. It will be
10316 used to set the local variable "self". |Dictionary-function|
10317
10318 The sort is stable, items which compare equal (as number or as
10319 string) will keep their relative position. E.g., when sorting
10320 on numbers, text strings will sort next to each other, in the
10321 same order as they were originally.
10322
10323 Can also be used as a |method|: >
10324 mylist->sort()
10325
10326< Also see |uniq()|.
10327
10328 Example: >
10329 func MyCompare(i1, i2)
10330 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10331 endfunc
10332 eval mylist->sort("MyCompare")
10333< A shorter compare version for this specific simple case, which
10334 ignores overflow: >
10335 func MyCompare(i1, i2)
10336 return a:i1 - a:i2
10337 endfunc
10338< For a simple expression you can use a lambda: >
10339 eval mylist->sort({i1, i2 -> i1 - i2})
10340<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010341 Return type: list<{type}>
10342
10343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010344sound_clear() *sound_clear()*
10345 Stop playing all sounds.
10346
10347 On some Linux systems you may need the libcanberra-pulse
10348 package, otherwise sound may not stop.
10349
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010350 Return type: |Number|
10351
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010352 {only available when compiled with the |+sound| feature}
10353
10354 *sound_playevent()*
10355sound_playevent({name} [, {callback}])
10356 Play a sound identified by {name}. Which event names are
10357 supported depends on the system. Often the XDG sound names
10358 are used. On Ubuntu they may be found in
10359 /usr/share/sounds/freedesktop/stereo. Example: >
10360 call sound_playevent('bell')
10361< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10362 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10363 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010364 On macOS, {name} refers to files located in
10365 /System/Library/Sounds (e.g. "Tink"). It will also work for
10366 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010367
10368 When {callback} is specified it is invoked when the sound is
10369 finished. The first argument is the sound ID, the second
10370 argument is the status:
10371 0 sound was played to the end
10372 1 sound was interrupted
10373 2 error occurred after sound started
10374 Example: >
10375 func Callback(id, status)
10376 echomsg "sound " .. a:id .. " finished with " .. a:status
10377 endfunc
10378 call sound_playevent('bell', 'Callback')
10379
10380< MS-Windows: {callback} doesn't work for this function.
10381
10382 Returns the sound ID, which can be passed to `sound_stop()`.
10383 Returns zero if the sound could not be played.
10384
10385 Can also be used as a |method|: >
10386 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010387<
10388 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010389
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010390 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010391
10392 *sound_playfile()*
10393sound_playfile({path} [, {callback}])
10394 Like `sound_playevent()` but play sound file {path}. {path}
10395 must be a full path. On Ubuntu you may find files to play
10396 with this command: >
10397 :!find /usr/share/sounds -type f | grep -v index.theme
10398
10399< Can also be used as a |method|: >
10400 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010401<
10402 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010403
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010404 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010405
10406
10407sound_stop({id}) *sound_stop()*
10408 Stop playing sound {id}. {id} must be previously returned by
10409 `sound_playevent()` or `sound_playfile()`.
10410
10411 On some Linux systems you may need the libcanberra-pulse
10412 package, otherwise sound may not stop.
10413
10414 On MS-Windows, this does not work for event sound started by
10415 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10416
10417 Can also be used as a |method|: >
10418 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010419<
10420 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010421
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010422 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010423
10424 *soundfold()*
10425soundfold({word})
10426 Return the sound-folded equivalent of {word}. Uses the first
10427 language in 'spelllang' for the current window that supports
10428 soundfolding. 'spell' must be set. When no sound folding is
10429 possible the {word} is returned unmodified.
10430 This can be used for making spelling suggestions. Note that
10431 the method can be quite slow.
10432
10433 Can also be used as a |method|: >
10434 GetWord()->soundfold()
10435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010436 Return type: |String|
10437
10438
10439spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010440 Without argument: The result is the badly spelled word under
10441 or after the cursor. The cursor is moved to the start of the
10442 bad word. When no bad word is found in the cursor line the
10443 result is an empty string and the cursor doesn't move.
10444
10445 With argument: The result is the first word in {sentence} that
10446 is badly spelled. If there are no spelling mistakes the
10447 result is an empty string.
10448
10449 The return value is a list with two items:
10450 - The badly spelled word or an empty string.
10451 - The type of the spelling error:
10452 "bad" spelling mistake
10453 "rare" rare word
10454 "local" word only valid in another region
10455 "caps" word should start with Capital
10456 Example: >
10457 echo spellbadword("the quik brown fox")
10458< ['quik', 'bad'] ~
10459
10460 The spelling information for the current window and the value
10461 of 'spelllang' are used.
10462
10463 Can also be used as a |method|: >
10464 GetText()->spellbadword()
10465<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010466 Return type: list<string>
10467
10468
10469spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010470 Return a |List| with spelling suggestions to replace {word}.
10471 When {max} is given up to this number of suggestions are
10472 returned. Otherwise up to 25 suggestions are returned.
10473
10474 When the {capital} argument is given and it's non-zero only
10475 suggestions with a leading capital will be given. Use this
10476 after a match with 'spellcapcheck'.
10477
10478 {word} can be a badly spelled word followed by other text.
10479 This allows for joining two words that were split. The
10480 suggestions also include the following text, thus you can
10481 replace a line.
10482
10483 {word} may also be a good word. Similar words will then be
10484 returned. {word} itself is not included in the suggestions,
10485 although it may appear capitalized.
10486
10487 The spelling information for the current window is used. The
10488 values of 'spelllang' and 'spellsuggest' are used.
10489
10490 Can also be used as a |method|: >
10491 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010492<
10493 Return type: list<string> or list<any>
10494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010495
10496split({string} [, {pattern} [, {keepempty}]]) *split()*
10497 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010498 empty each white space separated sequence of characters
10499 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010500 Otherwise the string is split where {pattern} matches,
10501 removing the matched characters. 'ignorecase' is not used
10502 here, add \c to ignore case. |/\c|
10503 When the first or last item is empty it is omitted, unless the
10504 {keepempty} argument is given and it's non-zero.
10505 Other empty items are kept when {pattern} matches at least one
10506 character or when {keepempty} is non-zero.
10507 Example: >
10508 :let words = split(getline('.'), '\W\+')
10509< To split a string in individual characters: >
10510 :for c in split(mystring, '\zs')
10511< If you want to keep the separator you can also use '\zs' at
10512 the end of the pattern: >
10513 :echo split('abc:def:ghi', ':\zs')
10514< ['abc:', 'def:', 'ghi'] ~
10515 Splitting a table where the first element can be empty: >
10516 :let items = split(line, ':', 1)
10517< The opposite function is |join()|.
10518
10519 Can also be used as a |method|: >
10520 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010521<
10522 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010523
10524sqrt({expr}) *sqrt()*
10525 Return the non-negative square root of Float {expr} as a
10526 |Float|.
10527 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010528 is negative the result is NaN (Not a Number). Returns 0.0 if
10529 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010530 Examples: >
10531 :echo sqrt(100)
10532< 10.0 >
10533 :echo sqrt(-4.01)
10534< nan
10535 "nan" may be different, it depends on system libraries.
10536
10537 Can also be used as a |method|: >
10538 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010539<
10540 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010541
10542
10543srand([{expr}]) *srand()*
10544 Initialize seed used by |rand()|:
10545 - If {expr} is not given, seed values are initialized by
10546 reading from /dev/urandom, if possible, or using time(NULL)
10547 a.k.a. epoch time otherwise; this only has second accuracy.
10548 - If {expr} is given it must be a Number. It is used to
10549 initialize the seed values. This is useful for testing or
10550 when a predictable sequence is intended.
10551
10552 Examples: >
10553 :let seed = srand()
10554 :let seed = srand(userinput)
10555 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010556<
10557 Return type: list<number>
10558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010559
10560state([{what}]) *state()*
10561 Return a string which contains characters indicating the
10562 current state. Mostly useful in callbacks that want to do
10563 work that may not always be safe. Roughly this works like:
10564 - callback uses state() to check if work is safe to do.
10565 Yes: then do it right away.
10566 No: add to work queue and add a |SafeState| and/or
10567 |SafeStateAgain| autocommand (|SafeState| triggers at
10568 toplevel, |SafeStateAgain| triggers after handling
10569 messages and callbacks).
10570 - When SafeState or SafeStateAgain is triggered and executes
10571 your autocommand, check with `state()` if the work can be
10572 done now, and if yes remove it from the queue and execute.
10573 Remove the autocommand if the queue is now empty.
10574 Also see |mode()|.
10575
10576 When {what} is given only characters in this string will be
10577 added. E.g, this checks if the screen has scrolled: >
10578 if state('s') == ''
10579 " screen has not scrolled
10580<
10581 These characters indicate the state, generally indicating that
10582 something is busy:
10583 m halfway a mapping, :normal command, feedkeys() or
10584 stuffed command
10585 o operator pending, e.g. after |d|
10586 a Insert mode autocomplete active
10587 x executing an autocommand
10588 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10589 ch_readraw() when reading json
10590 S not triggering SafeState or SafeStateAgain, e.g. after
10591 |f| or a count
10592 c callback invoked, including timer (repeats for
10593 recursiveness up to "ccc")
10594 s screen has scrolled for messages
10595
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010596 Return type: |String|
10597
10598
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010599str2blob({list} [, {options}]) *str2blob()*
10600 Return a Blob by converting the characters in the List of
10601 strings in {list} into bytes.
10602
10603 A <NL> byte is added to the blob after each list item. A
10604 newline character in the string is translated into a <NUL>
10605 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010606
10607 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010608 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010609
10610 The argument {options} is a |Dict| and supports the following
10611 items:
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010612 encoding Encode the characters using this encoding.
10613 The value is a |String|. See |encoding-names|
10614 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010615
10616 An error is given and an empty blob is returned if the
10617 character encoding fails.
10618
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010619 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010620
10621 See also |blob2str()|
10622
10623 Examples: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010624 str2blob(["ab"]) returns 0z6162
10625 str2blob(["«»"]) returns 0zC2ABC2BB
10626 str2blob(["a\nb"]) returns 0z610A62
10627 str2blob(readfile('myfile.txt'))
10628 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010629<
10630 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010631 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010632<
10633 Return type: |Blob|
10634
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010635str2float({string} [, {quoted}]) *str2float()*
10636 Convert String {string} to a Float. This mostly works the
10637 same as when using a floating point number in an expression,
10638 see |floating-point-format|. But it's a bit more permissive.
10639 E.g., "1e40" is accepted, while in an expression you need to
10640 write "1.0e40". The hexadecimal form "0x123" is also
10641 accepted, but not others, like binary or octal.
10642 When {quoted} is present and non-zero then embedded single
10643 quotes before the dot are ignored, thus "1'000.0" is a
10644 thousand.
10645 Text after the number is silently ignored.
10646 The decimal point is always '.', no matter what the locale is
10647 set to. A comma ends the number: "12,345.67" is converted to
10648 12.0. You can strip out thousands separators with
10649 |substitute()|: >
10650 let f = str2float(substitute(text, ',', '', 'g'))
10651<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010652 Returns 0.0 if the conversion fails.
10653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010654 Can also be used as a |method|: >
10655 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010656<
10657 Return type: |Float|
10658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010659
10660str2list({string} [, {utf8}]) *str2list()*
10661 Return a list containing the number values which represent
10662 each character in String {string}. Examples: >
10663 str2list(" ") returns [32]
10664 str2list("ABC") returns [65, 66, 67]
10665< |list2str()| does the opposite.
10666
10667 When {utf8} is omitted or zero, the current 'encoding' is used.
10668 When {utf8} is TRUE, always treat the String as UTF-8
10669 characters. With UTF-8 composing characters are handled
10670 properly: >
10671 str2list("á") returns [97, 769]
10672
10673< Can also be used as a |method|: >
10674 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010675<
10676 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010677
10678
10679str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10680 Convert string {string} to a number.
10681 {base} is the conversion base, it can be 2, 8, 10 or 16.
10682 When {quoted} is present and non-zero then embedded single
10683 quotes are ignored, thus "1'000'000" is a million.
10684
10685 When {base} is omitted base 10 is used. This also means that
10686 a leading zero doesn't cause octal conversion to be used, as
10687 with the default String to Number conversion. Example: >
10688 let nr = str2nr('0123')
10689<
10690 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10691 different base the result will be zero. Similarly, when
10692 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10693 {base} is 2 a leading "0b" or "0B" is ignored.
10694 Text after the number is silently ignored.
10695
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010696 Returns 0 if {string} is empty or on error.
10697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010698 Can also be used as a |method|: >
10699 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010700<
10701 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010702
10703
10704strcharlen({string}) *strcharlen()*
10705 The result is a Number, which is the number of characters
10706 in String {string}. Composing characters are ignored.
10707 |strchars()| can count the number of characters, counting
10708 composing characters separately.
10709
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010710 Returns 0 if {string} is empty or on error.
10711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010712 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10713
10714 Can also be used as a |method|: >
10715 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010716<
10717 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010718
10719
10720strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10721 Like |strpart()| but using character index and length instead
10722 of byte index and length.
10723 When {skipcc} is omitted or zero, composing characters are
10724 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010725 When {skipcc} set to 1, composing characters are treated as a
10726 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010727 When a character index is used where a character does not
10728 exist it is omitted and counted as one character. For
10729 example: >
10730 strcharpart('abc', -1, 2)
10731< results in 'a'.
10732
Bram Moolenaard592deb2022-06-17 15:42:40 +010010733 Returns an empty string on error.
10734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010735 Can also be used as a |method|: >
10736 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010737<
10738 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010739
10740
10741strchars({string} [, {skipcc}]) *strchars()*
10742 The result is a Number, which is the number of characters
10743 in String {string}.
10744 When {skipcc} is omitted or zero, composing characters are
10745 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010746 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010747 |strcharlen()| always does this.
10748
Bram Moolenaard592deb2022-06-17 15:42:40 +010010749 Returns zero on error.
10750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010751 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10752
10753 {skipcc} is only available after 7.4.755. For backward
10754 compatibility, you can define a wrapper function: >
10755 if has("patch-7.4.755")
10756 function s:strchars(str, skipcc)
10757 return strchars(a:str, a:skipcc)
10758 endfunction
10759 else
10760 function s:strchars(str, skipcc)
10761 if a:skipcc
10762 return strlen(substitute(a:str, ".", "x", "g"))
10763 else
10764 return strchars(a:str)
10765 endif
10766 endfunction
10767 endif
10768<
10769 Can also be used as a |method|: >
10770 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010771<
10772 Return type: |Number|
10773
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010774
10775strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10776 The result is a Number, which is the number of display cells
10777 String {string} occupies on the screen when it starts at {col}
10778 (first column is zero). When {col} is omitted zero is used.
10779 Otherwise it is the screen column where to start. This
10780 matters for Tab characters.
10781 The option settings of the current window are used. This
10782 matters for anything that's displayed differently, such as
10783 'tabstop' and 'display'.
10784 When {string} contains characters with East Asian Width Class
10785 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010786 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010787 Also see |strlen()|, |strwidth()| and |strchars()|.
10788
10789 Can also be used as a |method|: >
10790 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010791<
10792 Return type: |Number|
10793
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010794
10795strftime({format} [, {time}]) *strftime()*
10796 The result is a String, which is a formatted date and time, as
10797 specified by the {format} string. The given {time} is used,
10798 or the current time if no time is given. The accepted
10799 {format} depends on your system, thus this is not portable!
10800 See the manual page of the C function strftime() for the
10801 format. The maximum length of the result is 80 characters.
10802 See also |localtime()|, |getftime()| and |strptime()|.
10803 The language can be changed with the |:language| command.
10804 Examples: >
10805 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10806 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10807 :echo strftime("%y%m%d %T") 970427 11:53:55
10808 :echo strftime("%H:%M") 11:55
10809 :echo strftime("%c", getftime("file.c"))
10810 Show mod time of file.c.
10811< Not available on all systems. To check use: >
10812 :if exists("*strftime")
10813
10814< Can also be used as a |method|: >
10815 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010816<
10817 Return type: |String|
10818
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010819
10820strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010821 Get a Number corresponding to the character at {index} in
10822 {str}. This uses a zero-based character index, not a byte
10823 index. Composing characters are considered separate
10824 characters here. Use |nr2char()| to convert the Number to a
10825 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010826 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010827 Also see |strcharpart()| and |strchars()|.
10828
10829 Can also be used as a |method|: >
10830 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010831<
10832 Return type: |Number|
10833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010834
10835stridx({haystack}, {needle} [, {start}]) *stridx()*
10836 The result is a Number, which gives the byte index in
10837 {haystack} of the first occurrence of the String {needle}.
10838 If {start} is specified, the search starts at index {start}.
10839 This can be used to find a second match: >
10840 :let colon1 = stridx(line, ":")
10841 :let colon2 = stridx(line, ":", colon1 + 1)
10842< The search is done case-sensitive.
10843 For pattern searches use |match()|.
10844 -1 is returned if the {needle} does not occur in {haystack}.
10845 See also |strridx()|.
10846 Examples: >
10847 :echo stridx("An Example", "Example") 3
10848 :echo stridx("Starting point", "Start") 0
10849 :echo stridx("Starting point", "start") -1
10850< *strstr()* *strchr()*
10851 stridx() works similar to the C function strstr(). When used
10852 with a single character it works similar to strchr().
10853
10854 Can also be used as a |method|: >
10855 GetHaystack()->stridx(needle)
10856<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010857 Return type: |Number|
10858
10859
10860string({expr}) *string()*
10861 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010862 Float, String, Blob or a composition of them, then the result
10863 can be parsed back with |eval()|.
10864 {expr} type result ~
10865 String 'string' (single quotes are doubled)
10866 Number 123
10867 Float 123.123456 or 1.123456e8
10868 Funcref function('name')
10869 Blob 0z00112233.44556677.8899
10870 List [item, item]
10871 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010872 Class class SomeName
10873 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010874 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010875 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010876
10877 When a |List| or |Dictionary| has a recursive reference it is
10878 replaced by "[...]" or "{...}". Using eval() on the result
10879 will then fail.
10880
mityu7f0bba22024-03-29 10:14:41 +010010881 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010882 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010883 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010884
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010885 Can also be used as a |method|: >
10886 mylist->string()
10887
10888< Also see |strtrans()|.
10889
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010890 Return type: |String|
10891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010892
10893strlen({string}) *strlen()*
10894 The result is a Number, which is the length of the String
10895 {string} in bytes.
10896 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010897 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010898 If you want to count the number of multibyte characters use
10899 |strchars()|.
10900 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10901
10902 Can also be used as a |method|: >
10903 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010904<
10905 Return type: |Number|
10906
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010907
10908strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10909 The result is a String, which is part of {src}, starting from
10910 byte {start}, with the byte length {len}.
10911 When {chars} is present and TRUE then {len} is the number of
10912 characters positions (composing characters are not counted
10913 separately, thus "1" means one base character and any
10914 following composing characters).
10915 To count {start} as characters instead of bytes use
10916 |strcharpart()|.
10917
10918 When bytes are selected which do not exist, this doesn't
10919 result in an error, the bytes are simply omitted.
10920 If {len} is missing, the copy continues from {start} till the
10921 end of the {src}. >
10922 strpart("abcdefg", 3, 2) == "de"
10923 strpart("abcdefg", -2, 4) == "ab"
10924 strpart("abcdefg", 5, 4) == "fg"
10925 strpart("abcdefg", 3) == "defg"
10926
10927< Note: To get the first character, {start} must be 0. For
10928 example, to get the character under the cursor: >
10929 strpart(getline("."), col(".") - 1, 1, v:true)
10930<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010931 Returns an empty string on error.
10932
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010933 Can also be used as a |method|: >
10934 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010935<
10936 Return type: |String|
10937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010938
10939strptime({format}, {timestring}) *strptime()*
10940 The result is a Number, which is a unix timestamp representing
10941 the date and time in {timestring}, which is expected to match
10942 the format specified in {format}.
10943
10944 The accepted {format} depends on your system, thus this is not
10945 portable! See the manual page of the C function strptime()
10946 for the format. Especially avoid "%c". The value of $TZ also
10947 matters.
10948
10949 If the {timestring} cannot be parsed with {format} zero is
10950 returned. If you do not know the format of {timestring} you
10951 can try different {format} values until you get a non-zero
10952 result.
10953
10954 See also |strftime()|.
10955 Examples: >
10956 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10957< 862156163 >
10958 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10959< Sun Apr 27 11:53:55 1997 >
10960 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10961< Sun Apr 27 12:53:55 1997
10962
10963 Can also be used as a |method|: >
10964 GetFormat()->strptime(timestring)
10965<
10966 Not available on all systems. To check use: >
10967 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010968<
10969 Return type: |Number|
10970
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010971
10972strridx({haystack}, {needle} [, {start}]) *strridx()*
10973 The result is a Number, which gives the byte index in
10974 {haystack} of the last occurrence of the String {needle}.
10975 When {start} is specified, matches beyond this index are
10976 ignored. This can be used to find a match before a previous
10977 match: >
10978 :let lastcomma = strridx(line, ",")
10979 :let comma2 = strridx(line, ",", lastcomma - 1)
10980< The search is done case-sensitive.
10981 For pattern searches use |match()|.
10982 -1 is returned if the {needle} does not occur in {haystack}.
10983 If the {needle} is empty the length of {haystack} is returned.
10984 See also |stridx()|. Examples: >
10985 :echo strridx("an angry armadillo", "an") 3
10986< *strrchr()*
10987 When used with a single character it works similar to the C
10988 function strrchr().
10989
10990 Can also be used as a |method|: >
10991 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010992<
10993 Return type: |Number|
10994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010995
10996strtrans({string}) *strtrans()*
10997 The result is a String, which is {string} with all unprintable
10998 characters translated into printable characters |'isprint'|.
10999 Like they are shown in a window. Example: >
11000 echo strtrans(@a)
11001< This displays a newline in register a as "^@" instead of
11002 starting a new line.
11003
Bram Moolenaard592deb2022-06-17 15:42:40 +010011004 Returns an empty string on error.
11005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011006 Can also be used as a |method|: >
11007 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011008<
11009 Return type: |String|
11010
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011011
Christian Brabandt67672ef2023-04-24 21:09:54 +010011012strutf16len({string} [, {countcc}]) *strutf16len()*
11013 The result is a Number, which is the number of UTF-16 code
11014 units in String {string} (after converting it to UTF-16).
11015
11016 When {countcc} is TRUE, composing characters are counted
11017 separately.
11018 When {countcc} is omitted or FALSE, composing characters are
11019 ignored.
11020
11021 Returns zero on error.
11022
11023 Also see |strlen()| and |strcharlen()|.
11024 Examples: >
11025 echo strutf16len('a') returns 1
11026 echo strutf16len('©') returns 1
11027 echo strutf16len('😊') returns 2
11028 echo strutf16len('ą́') returns 1
11029 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011030<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011031 Can also be used as a |method|: >
11032 GetText()->strutf16len()
11033<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011034 Return type: |Number|
11035
11036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011037strwidth({string}) *strwidth()*
11038 The result is a Number, which is the number of display cells
11039 String {string} occupies. A Tab character is counted as one
11040 cell, alternatively use |strdisplaywidth()|.
11041 When {string} contains characters with East Asian Width Class
11042 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011043 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011044 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11045
11046 Can also be used as a |method|: >
11047 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011048<
11049 Return type: |Number|
11050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011051
11052submatch({nr} [, {list}]) *submatch()* *E935*
11053 Only for an expression in a |:substitute| command or
11054 substitute() function.
11055 Returns the {nr}'th submatch of the matched text. When {nr}
11056 is 0 the whole matched text is returned.
11057 Note that a NL in the string can stand for a line break of a
11058 multi-line match or a NUL character in the text.
11059 Also see |sub-replace-expression|.
11060
11061 If {list} is present and non-zero then submatch() returns
11062 a list of strings, similar to |getline()| with two arguments.
11063 NL characters in the text represent NUL characters in the
11064 text.
11065 Only returns more than one item for |:substitute|, inside
11066 |substitute()| this list will always contain one or zero
11067 items, since there are no real line breaks.
11068
11069 When substitute() is used recursively only the submatches in
11070 the current (deepest) call can be obtained.
11071
Bram Moolenaard592deb2022-06-17 15:42:40 +010011072 Returns an empty string or list on error.
11073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011074 Examples: >
11075 :s/\d\+/\=submatch(0) + 1/
11076 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11077< This finds the first number in the line and adds one to it.
11078 A line break is included as a newline character.
11079
11080 Can also be used as a |method|: >
11081 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011082<
11083 Return type: |String| or list<string> depending on {list}
11084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011085
11086substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11087 The result is a String, which is a copy of {string}, in which
11088 the first match of {pat} is replaced with {sub}.
11089 When {flags} is "g", all matches of {pat} in {string} are
11090 replaced. Otherwise {flags} should be "".
11091
11092 This works like the ":substitute" command (without any flags).
11093 But the matching with {pat} is always done like the 'magic'
11094 option is set and 'cpoptions' is empty (to make scripts
11095 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11096 if you want to ignore or match case and ignore 'ignorecase'.
11097 'smartcase' is not used. See |string-match| for how {pat} is
11098 used.
11099
11100 A "~" in {sub} is not replaced with the previous {sub}.
11101 Note that some codes in {sub} have a special meaning
11102 |sub-replace-special|. For example, to replace something with
11103 "\n" (two characters), use "\\\\n" or '\\n'.
11104
11105 When {pat} does not match in {string}, {string} is returned
11106 unmodified.
11107
11108 Example: >
11109 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11110< This removes the last component of the 'path' option. >
11111 :echo substitute("testing", ".*", "\\U\\0", "")
11112< results in "TESTING".
11113
11114 When {sub} starts with "\=", the remainder is interpreted as
11115 an expression. See |sub-replace-expression|. Example: >
11116 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011117 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011118
11119< When {sub} is a Funcref that function is called, with one
11120 optional argument. Example: >
11121 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11122< The optional argument is a list which contains the whole
11123 matched string and up to nine submatches, like what
11124 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011125 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011126
Bram Moolenaard592deb2022-06-17 15:42:40 +010011127< Returns an empty string on error.
11128
11129 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011130 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011131<
11132 Return type: |String|
11133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011134
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011135swapfilelist() *swapfilelist()*
11136 Returns a list of swap file names, like what "vim -r" shows.
11137 See the |-r| command argument. The 'directory' option is used
11138 for the directories to inspect. If you only want to get a
11139 list of swap files in the current directory then temporarily
11140 set 'directory' to a dot: >
11141 let save_dir = &directory
11142 let &directory = '.'
11143 let swapfiles = swapfilelist()
11144 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011145<
11146 Return type: list<string>
11147
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011148
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011149swapinfo({fname}) *swapinfo()*
11150 The result is a dictionary, which holds information about the
11151 swapfile {fname}. The available fields are:
11152 version Vim version
11153 user user name
11154 host host name
11155 fname original file name
11156 pid PID of the Vim process that created the swap
11157 file
11158 mtime last modification time in seconds
11159 inode Optional: INODE number of the file
11160 dirty 1 if file was modified, 0 if not
11161 Note that "user" and "host" are truncated to at most 39 bytes.
11162 In case of failure an "error" item is added with the reason:
11163 Cannot open file: file not found or in accessible
11164 Cannot read file: cannot read first block
11165 Not a swap file: does not contain correct block ID
11166 Magic number mismatch: Info in first block is invalid
11167
11168 Can also be used as a |method|: >
11169 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011170<
11171 Return type: dict<any> or dict<string>
11172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011173
11174swapname({buf}) *swapname()*
11175 The result is the swap file path of the buffer {expr}.
11176 For the use of {buf}, see |bufname()| above.
11177 If buffer {buf} is the current buffer, the result is equal to
11178 |:swapname| (unless there is no swap file).
11179 If buffer {buf} has no swap file, returns an empty string.
11180
11181 Can also be used as a |method|: >
11182 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011183<
11184 Return type: |String|
11185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011186
11187synID({lnum}, {col}, {trans}) *synID()*
11188 The result is a Number, which is the syntax ID at the position
11189 {lnum} and {col} in the current window.
11190 The syntax ID can be used with |synIDattr()| and
11191 |synIDtrans()| to obtain syntax information about text.
11192
11193 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11194 line. 'synmaxcol' applies, in a longer line zero is returned.
11195 Note that when the position is after the last character,
11196 that's where the cursor can be in Insert mode, synID() returns
11197 zero. {lnum} is used like with |getline()|.
11198
11199 When {trans} is |TRUE|, transparent items are reduced to the
11200 item that they reveal. This is useful when wanting to know
11201 the effective color. When {trans} is |FALSE|, the transparent
11202 item is returned. This is useful when wanting to know which
11203 syntax item is effective (e.g. inside parens).
11204 Warning: This function can be very slow. Best speed is
11205 obtained by going through the file in forward direction.
11206
Bram Moolenaard592deb2022-06-17 15:42:40 +010011207 Returns zero on error.
11208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011209 Example (echoes the name of the syntax item under the cursor): >
11210 :echo synIDattr(synID(line("."), col("."), 1), "name")
11211<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011212 Return type: |Number|
11213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011214
11215synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11216 The result is a String, which is the {what} attribute of
11217 syntax ID {synID}. This can be used to obtain information
11218 about a syntax item.
11219 {mode} can be "gui", "cterm" or "term", to get the attributes
11220 for that mode. When {mode} is omitted, or an invalid value is
11221 used, the attributes for the currently active highlighting are
11222 used (GUI, cterm or term).
11223 Use synIDtrans() to follow linked highlight groups.
11224 {what} result
11225 "name" the name of the syntax item
11226 "fg" foreground color (GUI: color name used to set
11227 the color, cterm: color number as a string,
11228 term: empty string)
11229 "bg" background color (as with "fg")
11230 "font" font name (only available in the GUI)
11231 |highlight-font|
11232 "sp" special color for the GUI (as with "fg")
11233 |highlight-guisp|
11234 "ul" underline color for cterm: number as a string
11235 "fg#" like "fg", but for the GUI and the GUI is
11236 running the name in "#RRGGBB" form
11237 "bg#" like "fg#" for "bg"
11238 "sp#" like "fg#" for "sp"
11239 "bold" "1" if bold
11240 "italic" "1" if italic
11241 "reverse" "1" if reverse
11242 "inverse" "1" if inverse (= reverse)
11243 "standout" "1" if standout
11244 "underline" "1" if underlined
11245 "undercurl" "1" if undercurled
11246 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011247 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011248
Bram Moolenaard592deb2022-06-17 15:42:40 +010011249 Returns an empty string on error.
11250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011251 Example (echoes the color of the syntax item under the
11252 cursor): >
11253 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11254<
11255 Can also be used as a |method|: >
11256 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011257<
11258 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011259
11260
11261synIDtrans({synID}) *synIDtrans()*
11262 The result is a Number, which is the translated syntax ID of
11263 {synID}. This is the syntax group ID of what is being used to
11264 highlight the character. Highlight links given with
11265 ":highlight link" are followed.
11266
Bram Moolenaard592deb2022-06-17 15:42:40 +010011267 Returns zero on error.
11268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011269 Can also be used as a |method|: >
11270 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011271<
11272 Return type: |Number|
11273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011274
11275synconcealed({lnum}, {col}) *synconcealed()*
11276 The result is a |List| with currently three items:
11277 1. The first item in the list is 0 if the character at the
11278 position {lnum} and {col} is not part of a concealable
11279 region, 1 if it is. {lnum} is used like with |getline()|.
11280 2. The second item in the list is a string. If the first item
11281 is 1, the second item contains the text which will be
11282 displayed in place of the concealed text, depending on the
11283 current setting of 'conceallevel' and 'listchars'.
11284 3. The third and final item in the list is a number
11285 representing the specific syntax region matched in the
11286 line. When the character is not concealed the value is
11287 zero. This allows detection of the beginning of a new
11288 concealable region if there are two consecutive regions
11289 with the same replacement character. For an example, if
11290 the text is "123456" and both "23" and "45" are concealed
11291 and replaced by the character "X", then:
11292 call returns ~
11293 synconcealed(lnum, 1) [0, '', 0]
11294 synconcealed(lnum, 2) [1, 'X', 1]
11295 synconcealed(lnum, 3) [1, 'X', 1]
11296 synconcealed(lnum, 4) [1, 'X', 2]
11297 synconcealed(lnum, 5) [1, 'X', 2]
11298 synconcealed(lnum, 6) [0, '', 0]
11299
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011300 Note: Doesn't consider |matchadd()| highlighting items,
11301 since syntax and matching highlighting are two different
11302 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011303
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011304 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011306
11307synstack({lnum}, {col}) *synstack()*
11308 Return a |List|, which is the stack of syntax items at the
11309 position {lnum} and {col} in the current window. {lnum} is
11310 used like with |getline()|. Each item in the List is an ID
11311 like what |synID()| returns.
11312 The first item in the List is the outer region, following are
11313 items contained in that one. The last one is what |synID()|
11314 returns, unless not the whole item is highlighted or it is a
11315 transparent item.
11316 This function is useful for debugging a syntax file.
11317 Example that shows the syntax stack under the cursor: >
11318 for id in synstack(line("."), col("."))
11319 echo synIDattr(id, "name")
11320 endfor
11321< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011322 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011323 character in a line and the first column in an empty line are
11324 valid positions.
11325
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011326 Return type: list<number> or list<any>
11327
11328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011329system({expr} [, {input}]) *system()* *E677*
11330 Get the output of the shell command {expr} as a |String|. See
11331 |systemlist()| to get the output as a |List|.
11332
11333 When {input} is given and is a |String| this string is written
11334 to a file and passed as stdin to the command. The string is
11335 written as-is, you need to take care of using the correct line
11336 separators yourself.
11337 If {input} is given and is a |List| it is written to the file
11338 in a way |writefile()| does with {binary} set to "b" (i.e.
11339 with a newline between each list item with newlines inside
11340 list items converted to NULs).
11341 When {input} is given and is a number that is a valid id for
11342 an existing buffer then the content of the buffer is written
11343 to the file line by line, each line terminated by a NL and
11344 NULs characters where the text has a NL.
11345
11346 Pipes are not used, the 'shelltemp' option is not used.
11347
11348 When prepended by |:silent| the terminal will not be set to
11349 cooked mode. This is meant to be used for commands that do
11350 not need the user to type. It avoids stray characters showing
11351 up on the screen which require |CTRL-L| to remove. >
11352 :silent let f = system('ls *.vim')
11353<
11354 Note: Use |shellescape()| or |::S| with |expand()| or
11355 |fnamemodify()| to escape special characters in a command
11356 argument. Newlines in {expr} may cause the command to fail.
11357 The characters in 'shellquote' and 'shellxquote' may also
11358 cause trouble.
11359 This is not to be used for interactive commands.
11360
11361 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011362 :let files = system('ls ' .. shellescape(expand('%:h')))
11363 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011364
11365< To make the result more system-independent, the shell output
11366 is filtered to replace <CR> with <NL> for Macintosh, and
11367 <CR><NL> with <NL> for DOS-like systems.
11368 To avoid the string being truncated at a NUL, all NUL
11369 characters are replaced with SOH (0x01).
11370
11371 The command executed is constructed using several options:
11372 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11373 ({tmp} is an automatically generated file name).
11374 For Unix, braces are put around {expr} to allow for
11375 concatenated commands.
11376
11377 The command will be executed in "cooked" mode, so that a
11378 CTRL-C will interrupt the command (on Unix at least).
11379
11380 The resulting error code can be found in |v:shell_error|.
11381 This function will fail in |restricted-mode|.
11382
11383 Note that any wrong value in the options mentioned above may
11384 make the function fail. It has also been reported to fail
11385 when using a security agent application.
11386 Unlike ":!cmd" there is no automatic check for changed files.
11387 Use |:checktime| to force a check.
11388
11389 Can also be used as a |method|: >
11390 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011391<
11392 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011393
11394
11395systemlist({expr} [, {input}]) *systemlist()*
11396 Same as |system()|, but returns a |List| with lines (parts of
11397 output separated by NL) with NULs transformed into NLs. Output
11398 is the same as |readfile()| will output with {binary} argument
11399 set to "b", except that there is no extra empty item when the
11400 result ends in a NL.
11401 Note that on MS-Windows you may get trailing CR characters.
11402
11403 To see the difference between "echo hello" and "echo -n hello"
11404 use |system()| and |split()|: >
11405 echo system('echo hello')->split('\n', 1)
11406<
11407 Returns an empty string on error.
11408
11409 Can also be used as a |method|: >
11410 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011411<
11412 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011413
11414
11415tabpagebuflist([{arg}]) *tabpagebuflist()*
11416 The result is a |List|, where each item is the number of the
11417 buffer associated with each window in the current tab page.
11418 {arg} specifies the number of the tab page to be used. When
11419 omitted the current tab page is used.
11420 When {arg} is invalid the number zero is returned.
11421 To get a list of all buffers in all tabs use this: >
11422 let buflist = []
11423 for i in range(tabpagenr('$'))
11424 call extend(buflist, tabpagebuflist(i + 1))
11425 endfor
11426< Note that a buffer may appear in more than one window.
11427
11428 Can also be used as a |method|: >
11429 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011430<
11431 Return type: list<number>
11432
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011433
11434tabpagenr([{arg}]) *tabpagenr()*
11435 The result is a Number, which is the number of the current
11436 tab page. The first tab page has number 1.
11437
11438 The optional argument {arg} supports the following values:
11439 $ the number of the last tab page (the tab page
11440 count).
11441 # the number of the last accessed tab page
11442 (where |g<Tab>| goes to). if there is no
11443 previous tab page 0 is returned.
11444 The number can be used with the |:tab| command.
11445
Bram Moolenaard592deb2022-06-17 15:42:40 +010011446 Returns zero on error.
11447
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011448 Return type: |Number|
11449
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011450
11451tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11452 Like |winnr()| but for tab page {tabarg}.
11453 {tabarg} specifies the number of tab page to be used.
11454 {arg} is used like with |winnr()|:
11455 - When omitted the current window number is returned. This is
11456 the window which will be used when going to this tab page.
11457 - When "$" the number of windows is returned.
11458 - When "#" the previous window nr is returned.
11459 Useful examples: >
11460 tabpagewinnr(1) " current window of tab page 1
11461 tabpagewinnr(4, '$') " number of windows in tab page 4
11462< When {tabarg} is invalid zero is returned.
11463
11464 Can also be used as a |method|: >
11465 GetTabpage()->tabpagewinnr()
11466<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011467 Return type: |Number|
11468
11469
11470tagfiles() *tagfiles()*
11471 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011472 for the current buffer. This is the 'tags' option expanded.
11473
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011474 Return type: list<string> or list<any>
11475
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011476
11477taglist({expr} [, {filename}]) *taglist()*
11478 Returns a |List| of tags matching the regular expression {expr}.
11479
11480 If {filename} is passed it is used to prioritize the results
11481 in the same way that |:tselect| does. See |tag-priority|.
11482 {filename} should be the full path of the file.
11483
11484 Each list item is a dictionary with at least the following
11485 entries:
11486 name Name of the tag.
11487 filename Name of the file where the tag is
11488 defined. It is either relative to the
11489 current directory or a full path.
11490 cmd Ex command used to locate the tag in
11491 the file.
11492 kind Type of the tag. The value for this
11493 entry depends on the language specific
11494 kind values. Only available when
11495 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011496 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011497 static A file specific tag. Refer to
11498 |static-tag| for more information.
11499 More entries may be present, depending on the content of the
11500 tags file: access, implementation, inherits and signature.
11501 Refer to the ctags documentation for information about these
11502 fields. For C code the fields "struct", "class" and "enum"
11503 may appear, they give the name of the entity the tag is
11504 contained in.
11505
11506 The ex-command "cmd" can be either an ex search pattern, a
11507 line number or a line number followed by a byte number.
11508
11509 If there are no matching tags, then an empty list is returned.
11510
11511 To get an exact tag match, the anchors '^' and '$' should be
11512 used in {expr}. This also make the function work faster.
11513 Refer to |tag-regexp| for more information about the tag
11514 search regular expression pattern.
11515
11516 Refer to |'tags'| for information about how the tags file is
11517 located by Vim. Refer to |tags-file-format| for the format of
11518 the tags file generated by the different ctags tools.
11519
11520 Can also be used as a |method|: >
11521 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011522<
11523 Return type: list<dict<any>> or list<any>
11524
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011525
11526tan({expr}) *tan()*
11527 Return the tangent of {expr}, measured in radians, as a |Float|
11528 in the range [-inf, inf].
11529 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011530 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011531 Examples: >
11532 :echo tan(10)
11533< 0.648361 >
11534 :echo tan(-4.01)
11535< -1.181502
11536
11537 Can also be used as a |method|: >
11538 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011539<
11540 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011541
11542
11543tanh({expr}) *tanh()*
11544 Return the hyperbolic tangent of {expr} as a |Float| in the
11545 range [-1, 1].
11546 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011547 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011548 Examples: >
11549 :echo tanh(0.5)
11550< 0.462117 >
11551 :echo tanh(-1)
11552< -0.761594
11553
11554 Can also be used as a |method|: >
11555 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011556<
11557 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011558
11559
11560tempname() *tempname()* *temp-file-name*
11561 The result is a String, which is the name of a file that
11562 doesn't exist. It can be used for a temporary file. The name
11563 is different for at least 26 consecutive calls. Example: >
11564 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011565 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011566< For Unix, the file will be in a private directory |tempfile|
11567 that is recursively deleted when Vim exits, on other systems
11568 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011569 For MS-Windows forward slashes are used when the 'shellslash'
11570 option is set, or when 'shellcmdflag' starts with '-' and
11571 'shell' does not contain powershell or pwsh.
11572
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011573 Return type: |String|
11574
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011575
11576term_ functions are documented here: |terminal-function-details|
11577
11578
11579terminalprops() *terminalprops()*
11580 Returns a |Dictionary| with properties of the terminal that Vim
11581 detected from the response to |t_RV| request. See
11582 |v:termresponse| for the response itself. If |v:termresponse|
11583 is empty most values here will be 'u' for unknown.
11584 cursor_style whether sending |t_RS| works **
11585 cursor_blink_mode whether sending |t_RC| works **
11586 underline_rgb whether |t_8u| works **
11587 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011588 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011589
11590 ** value 'u' for unknown, 'y' for yes, 'n' for no
11591
11592 If the |+termresponse| feature is missing then the result is
11593 an empty dictionary.
11594
11595 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11596 current cursor style.
11597 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11598 request the cursor blink status.
11599 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11600 is not empty, Vim will detect the working of sending |t_RS|
11601 and |t_RC| on startup.
11602
11603 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11604 This avoids sending it to xterm, which would clear the colors.
11605
11606 For "mouse" the value 'u' is unknown
11607
11608 Also see:
11609 - 'ambiwidth' - detected by using |t_u7|.
11610 - |v:termstyleresp| and |v:termblinkresp| for the response to
11611 |t_RS| and |t_RC|.
11612
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011613 Return type: dict<string>
11614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011615
11616test_ functions are documented here: |test-functions-details|
11617
11618
11619 *timer_info()*
11620timer_info([{id}])
11621 Return a list with information about timers.
11622 When {id} is given only information about this timer is
11623 returned. When timer {id} does not exist an empty list is
11624 returned.
11625 When {id} is omitted information about all timers is returned.
11626
11627 For each timer the information is stored in a |Dictionary| with
11628 these items:
11629 "id" the timer ID
11630 "time" time the timer was started with
11631 "remaining" time until the timer fires
11632 "repeat" number of times the timer will still fire;
11633 -1 means forever
11634 "callback" the callback
11635 "paused" 1 if the timer is paused, 0 otherwise
11636
11637 Can also be used as a |method|: >
11638 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011639<
11640 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011641
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011642 {only available when compiled with the |+timers| feature}
11643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011644
11645timer_pause({timer}, {paused}) *timer_pause()*
11646 Pause or unpause a timer. A paused timer does not invoke its
11647 callback when its time expires. Unpausing a timer may cause
11648 the callback to be invoked almost immediately if enough time
11649 has passed.
11650
11651 Pausing a timer is useful to avoid the callback to be called
11652 for a short time.
11653
11654 If {paused} evaluates to a non-zero Number or a non-empty
11655 String, then the timer is paused, otherwise it is unpaused.
11656 See |non-zero-arg|.
11657
11658 Can also be used as a |method|: >
11659 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011660<
11661 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011662
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011663 {only available when compiled with the |+timers| feature}
11664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011665
11666 *timer_start()* *timer* *timers*
11667timer_start({time}, {callback} [, {options}])
11668 Create a timer and return the timer ID.
11669
11670 {time} is the waiting time in milliseconds. This is the
11671 minimum time before invoking the callback. When the system is
11672 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011673 Zero can be used to execute the callback when Vim is back in
11674 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011675
11676 {callback} is the function to call. It can be the name of a
11677 function or a |Funcref|. It is called with one argument, which
11678 is the timer ID. The callback is only invoked when Vim is
11679 waiting for input.
11680 If you want to show a message look at |popup_notification()|
11681 to avoid interfering with what the user is doing.
11682
11683 {options} is a dictionary. Supported entries:
11684 "repeat" Number of times to repeat calling the
11685 callback. -1 means forever. When not present
11686 the callback will be called once.
11687 If the timer causes an error three times in a
11688 row the repeat is cancelled. This avoids that
11689 Vim becomes unusable because of all the error
11690 messages.
11691
Bram Moolenaard592deb2022-06-17 15:42:40 +010011692 Returns -1 on error.
11693
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011694 Example: >
11695 func MyHandler(timer)
11696 echo 'Handler called'
11697 endfunc
11698 let timer = timer_start(500, 'MyHandler',
11699 \ {'repeat': 3})
11700< This will invoke MyHandler() three times at 500 msec
11701 intervals.
11702
11703 Can also be used as a |method|: >
11704 GetMsec()->timer_start(callback)
11705
11706< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011707
11708 Return type: |Number|
11709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011710 {only available when compiled with the |+timers| feature}
11711
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011713timer_stop({timer}) *timer_stop()*
11714 Stop a timer. The timer callback will no longer be invoked.
11715 {timer} is an ID returned by timer_start(), thus it must be a
11716 Number. If {timer} does not exist there is no error.
11717
11718 Can also be used as a |method|: >
11719 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011720<
11721 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011722
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011723 {only available when compiled with the |+timers| feature}
11724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011725
11726timer_stopall() *timer_stopall()*
11727 Stop all timers. The timer callbacks will no longer be
11728 invoked. Useful if a timer is misbehaving. If there are no
11729 timers there is no error.
11730
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011731 Return type: |Number|
11732
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011733 {only available when compiled with the |+timers| feature}
11734
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011736tolower({expr}) *tolower()*
11737 The result is a copy of the String given, with all uppercase
11738 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011739 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011740
11741 Can also be used as a |method|: >
11742 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011743<
11744 Return type: |String|
11745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011746
11747toupper({expr}) *toupper()*
11748 The result is a copy of the String given, with all lowercase
11749 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011750 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011751
11752 Can also be used as a |method|: >
11753 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011754<
11755 Return type: |String|
11756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011757
11758tr({src}, {fromstr}, {tostr}) *tr()*
11759 The result is a copy of the {src} string with all characters
11760 which appear in {fromstr} replaced by the character in that
11761 position in the {tostr} string. Thus the first character in
11762 {fromstr} is translated into the first character in {tostr}
11763 and so on. Exactly like the unix "tr" command.
11764 This code also deals with multibyte characters properly.
11765
Bram Moolenaard592deb2022-06-17 15:42:40 +010011766 Returns an empty string on error.
11767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011768 Examples: >
11769 echo tr("hello there", "ht", "HT")
11770< returns "Hello THere" >
11771 echo tr("<blob>", "<>", "{}")
11772< returns "{blob}"
11773
11774 Can also be used as a |method|: >
11775 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011776<
11777 Return type: |String|
11778
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011779
11780trim({text} [, {mask} [, {dir}]]) *trim()*
11781 Return {text} as a String where any character in {mask} is
11782 removed from the beginning and/or end of {text}.
11783
Illia Bobyr80799172023-10-17 18:00:50 +020011784 If {mask} is not given, or is an empty string, {mask} is all
11785 characters up to 0x20, which includes Tab, space, NL and CR,
11786 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011787
11788 The optional {dir} argument specifies where to remove the
11789 characters:
11790 0 remove from the beginning and end of {text}
11791 1 remove only at the beginning of {text}
11792 2 remove only at the end of {text}
11793 When omitted both ends are trimmed.
11794
11795 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011796 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011797
11798 Examples: >
11799 echo trim(" some text ")
11800< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011801 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011802< returns "RESERVE_TAIL" >
11803 echo trim("rm<Xrm<>X>rrm", "rm<>")
11804< returns "Xrm<>X" (characters in the middle are not removed) >
11805 echo trim(" vim ", " ", 2)
11806< returns " vim"
11807
11808 Can also be used as a |method|: >
11809 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011810<
11811 Return type: |String|
11812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011813
11814trunc({expr}) *trunc()*
11815 Return the largest integral value with magnitude less than or
11816 equal to {expr} as a |Float| (truncate towards zero).
11817 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011818 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011819 Examples: >
11820 echo trunc(1.456)
11821< 1.0 >
11822 echo trunc(-5.456)
11823< -5.0 >
11824 echo trunc(4.0)
11825< 4.0
11826
11827 Can also be used as a |method|: >
11828 Compute()->trunc()
11829<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011830 Return type: |Float|
11831
11832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011833 *type()*
11834type({expr}) The result is a Number representing the type of {expr}.
11835 Instead of using the number directly, it is better to use the
11836 v:t_ variable that has the value:
11837 Number: 0 |v:t_number|
11838 String: 1 |v:t_string|
11839 Funcref: 2 |v:t_func|
11840 List: 3 |v:t_list|
11841 Dictionary: 4 |v:t_dict|
11842 Float: 5 |v:t_float|
11843 Boolean: 6 |v:t_bool| (v:false and v:true)
11844 None: 7 |v:t_none| (v:null and v:none)
11845 Job: 8 |v:t_job|
11846 Channel: 9 |v:t_channel|
11847 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011848 Class: 12 |v:t_class|
11849 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011850 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011851 Enum: 15 |v:t_enum|
11852 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011853 For backward compatibility, this method can be used: >
11854 :if type(myvar) == type(0)
11855 :if type(myvar) == type("")
11856 :if type(myvar) == type(function("tr"))
11857 :if type(myvar) == type([])
11858 :if type(myvar) == type({})
11859 :if type(myvar) == type(0.0)
11860 :if type(myvar) == type(v:false)
11861 :if type(myvar) == type(v:none)
11862< To check if the v:t_ variables exist use this: >
11863 :if exists('v:t_number')
11864
11865< Can also be used as a |method|: >
11866 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011867<
11868 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011869
11870
11871typename({expr}) *typename()*
11872 Return a string representation of the type of {expr}.
11873 Example: >
11874 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011875< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011876
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011877 Return type: |String|
11878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011879
11880undofile({name}) *undofile()*
11881 Return the name of the undo file that would be used for a file
11882 with name {name} when writing. This uses the 'undodir'
11883 option, finding directories that exist. It does not check if
11884 the undo file exists.
11885 {name} is always expanded to the full path, since that is what
11886 is used internally.
11887 If {name} is empty undofile() returns an empty string, since a
11888 buffer without a file name will not write an undo file.
11889 Useful in combination with |:wundo| and |:rundo|.
11890 When compiled without the |+persistent_undo| option this always
11891 returns an empty string.
11892
11893 Can also be used as a |method|: >
11894 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011895<
11896 Return type: |String|
11897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011898
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011899undotree([{buf}]) *undotree()*
11900 Return the current state of the undo tree for the current
11901 buffer, or for a specific buffer if {buf} is given. The
11902 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011903 "seq_last" The highest undo sequence number used.
11904 "seq_cur" The sequence number of the current position in
11905 the undo tree. This differs from "seq_last"
11906 when some changes were undone.
11907 "time_cur" Time last used for |:earlier| and related
11908 commands. Use |strftime()| to convert to
11909 something readable.
11910 "save_last" Number of the last file write. Zero when no
11911 write yet.
11912 "save_cur" Number of the current position in the undo
11913 tree.
11914 "synced" Non-zero when the last undo block was synced.
11915 This happens when waiting from input from the
11916 user. See |undo-blocks|.
11917 "entries" A list of dictionaries with information about
11918 undo blocks.
11919
11920 The first item in the "entries" list is the oldest undo item.
11921 Each List item is a |Dictionary| with these items:
11922 "seq" Undo sequence number. Same as what appears in
11923 |:undolist|.
11924 "time" Timestamp when the change happened. Use
11925 |strftime()| to convert to something readable.
11926 "newhead" Only appears in the item that is the last one
11927 that was added. This marks the last change
11928 and where further changes will be added.
11929 "curhead" Only appears in the item that is the last one
11930 that was undone. This marks the current
11931 position in the undo tree, the block that will
11932 be used by a redo command. When nothing was
11933 undone after the last change this item will
11934 not appear anywhere.
11935 "save" Only appears on the last block before a file
11936 write. The number is the write count. The
11937 first write has number 1, the last one the
11938 "save_last" mentioned above.
11939 "alt" Alternate entry. This is again a List of undo
11940 blocks. Each item may again have an "alt"
11941 item.
11942
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011943 Return type: dict<any>
11944
11945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011946uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11947 Remove second and succeeding copies of repeated adjacent
11948 {list} items in-place. Returns {list}. If you want a list
11949 to remain unmodified make a copy first: >
11950 :let newlist = uniq(copy(mylist))
11951< The default compare function uses the string representation of
11952 each item. For the use of {func} and {dict} see |sort()|.
11953
Bram Moolenaard592deb2022-06-17 15:42:40 +010011954 Returns zero if {list} is not a |List|.
11955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011956 Can also be used as a |method|: >
11957 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011958<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011959 Return type: list<{type}>
11960
11961
Christian Brabandt67672ef2023-04-24 21:09:54 +010011962 *utf16idx()*
11963utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011964 Same as |charidx()| but returns the UTF-16 code unit index of
11965 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011966
11967 When {charidx} is present and TRUE, {idx} is used as the
11968 character index in the String {string} instead of as the byte
11969 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011970 An {idx} in the middle of a UTF-8 sequence is rounded
11971 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011972
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011973 Returns -1 if the arguments are invalid or if there are less
11974 than {idx} bytes in {string}. If there are exactly {idx} bytes
11975 the length of the string in UTF-16 code units is returned.
11976
Christian Brabandt67672ef2023-04-24 21:09:54 +010011977 See |byteidx()| and |byteidxcomp()| for getting the byte index
11978 from the UTF-16 index and |charidx()| for getting the
11979 character index from the UTF-16 index.
11980 Refer to |string-offset-encoding| for more information.
11981 Examples: >
11982 echo utf16idx('a😊😊', 3) returns 2
11983 echo utf16idx('a😊😊', 7) returns 4
11984 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11985 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11986 echo utf16idx('aą́c', 6) returns 2
11987 echo utf16idx('aą́c', 6, 1) returns 4
11988 echo utf16idx('a😊😊', 9) returns -1
11989<
11990 Can also be used as a |method|: >
11991 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011992<
11993 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011995
11996values({dict}) *values()*
11997 Return a |List| with all the values of {dict}. The |List| is
11998 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011999 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012000
12001 Can also be used as a |method|: >
12002 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012003<
12004 Return type: list<any>
12005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012006
zeertzjq825cf812023-08-17 22:55:25 +020012007virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012008 The result is a Number, which is the screen column of the file
12009 position given with {expr}. That is, the last screen position
12010 occupied by the character at that position, when the screen
12011 would be of unlimited width. When there is a <Tab> at the
12012 position, the returned Number will be the column at the end of
12013 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12014 set to 8, it returns 8. |conceal| is ignored.
12015 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012016
zeertzjq02f3eba2024-06-12 20:45:24 +020012017 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012018 When {expr} is "$", it means the end of the cursor line, so
12019 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012020
12021 When 'virtualedit' is used {expr} can be [lnum, col, off],
12022 where "off" is the offset in screen columns from the start of
12023 the character. E.g., a position within a <Tab> or after the
12024 last character. When "off" is omitted zero is used. When
12025 Virtual editing is active in the current mode, a position
12026 beyond the end of the line can be returned. Also see
12027 |'virtualedit'|
12028
zeertzjq825cf812023-08-17 22:55:25 +020012029 If {list} is present and non-zero then virtcol() returns a
12030 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012031 character.
12032
zeertzjq825cf812023-08-17 22:55:25 +020012033 With the optional {winid} argument the values are obtained for
12034 that window instead of the current window.
12035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012036 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012037
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012038 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012039 " With text "foo^Lbar" and cursor on the "^L":
12040
12041 virtcol(".") " returns 5
12042 virtcol(".", 1) " returns [4, 5]
12043 virtcol("$") " returns 9
12044
12045 " With text " there", with 't at 'h':
12046
12047 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012048<
12049 The first column is 1. 0 or [0, 0] is returned for an error.
12050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012051 A more advanced example that echoes the maximum length of
12052 all lines: >
12053 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12054
12055< Can also be used as a |method|: >
12056 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012057<
12058 Return type: |Number|
12059
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012060
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012061virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12062 The result is a Number, which is the byte index of the
12063 character in window {winid} at buffer line {lnum} and virtual
12064 column {col}.
12065
zeertzjqb583eda2023-10-14 11:32:28 +020012066 If buffer line {lnum} is an empty line, 0 is returned.
12067
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012068 If {col} is greater than the last virtual column in line
12069 {lnum}, then the byte index of the character at the last
12070 virtual column is returned.
12071
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012072 For a multi-byte character, the column number of the first
12073 byte in the character is returned.
12074
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012075 The {winid} argument can be the window number or the
12076 |window-ID|. If this is zero, then the current window is used.
12077
12078 Returns -1 if the window {winid} doesn't exist or the buffer
12079 line {lnum} or virtual column {col} is invalid.
12080
12081 See also |screenpos()|, |virtcol()| and |col()|.
12082
12083 Can also be used as a |method|: >
12084 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012085<
12086 Return type: |Number|
12087
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012088
12089visualmode([{expr}]) *visualmode()*
12090 The result is a String, which describes the last Visual mode
12091 used in the current buffer. Initially it returns an empty
12092 string, but once Visual mode has been used, it returns "v",
12093 "V", or "<CTRL-V>" (a single CTRL-V character) for
12094 character-wise, line-wise, or block-wise Visual mode
12095 respectively.
12096 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012097 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012098< This enters the same Visual mode as before. It is also useful
12099 in scripts if you wish to act differently depending on the
12100 Visual mode that was used.
12101 If Visual mode is active, use |mode()| to get the Visual mode
12102 (e.g., in a |:vmap|).
12103 If {expr} is supplied and it evaluates to a non-zero Number or
12104 a non-empty String, then the Visual mode will be cleared and
12105 the old value is returned. See |non-zero-arg|.
12106
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012107 Return type: |String|
12108
12109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012110wildmenumode() *wildmenumode()*
12111 Returns |TRUE| when the wildmenu is active and |FALSE|
12112 otherwise. See 'wildmenu' and 'wildmode'.
12113 This can be used in mappings to handle the 'wildcharm' option
12114 gracefully. (Makes only sense with |mapmode-c| mappings).
12115
12116 For example to make <c-j> work like <down> in wildmode, use: >
12117 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12118<
Milly6c2fc372024-10-16 22:11:17 +020012119 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012120
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012121 Return type: |Number|
12122
12123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012124win_execute({id}, {command} [, {silent}]) *win_execute()*
12125 Like `execute()` but in the context of window {id}.
12126 The window will temporarily be made the current window,
12127 without triggering autocommands or changing directory. When
12128 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012129 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012130 Example: >
12131 call win_execute(winid, 'set syntax=python')
12132< Doing the same with `setwinvar()` would not trigger
12133 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012134 *E994*
12135 Not all commands are allowed in popup windows.
12136 When window {id} does not exist then no error is given and
12137 an empty string is returned.
12138
12139 Can also be used as a |method|, the base is passed as the
12140 second argument: >
12141 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012142<
12143 Return type: |String|
12144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012145
12146win_findbuf({bufnr}) *win_findbuf()*
12147 Returns a |List| with |window-ID|s for windows that contain
12148 buffer {bufnr}. When there is none the list is empty.
12149
12150 Can also be used as a |method|: >
12151 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012152<
12153 Return type: list<number> or list<any>
12154
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012155
12156win_getid([{win} [, {tab}]]) *win_getid()*
12157 Get the |window-ID| for the specified window.
12158 When {win} is missing use the current window.
12159 With {win} this is the window number. The top window has
12160 number 1.
12161 Without {tab} use the current tab, otherwise the tab with
12162 number {tab}. The first tab has number one.
12163 Return zero if the window cannot be found.
12164
12165 Can also be used as a |method|: >
12166 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012167<
12168 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012169
12170
12171win_gettype([{nr}]) *win_gettype()*
12172 Return the type of the window:
12173 "autocmd" autocommand window. Temporary window
12174 used to execute autocommands.
12175 "command" command-line window |cmdwin|
12176 (empty) normal window
12177 "loclist" |location-list-window|
12178 "popup" popup window |popup|
12179 "preview" preview window |preview-window|
12180 "quickfix" |quickfix-window|
12181 "unknown" window {nr} not found
12182
12183 When {nr} is omitted return the type of the current window.
12184 When {nr} is given return the type of this window by number or
12185 |window-ID|.
12186
12187 Also see the 'buftype' option. When running a terminal in a
12188 popup window then 'buftype' is "terminal" and win_gettype()
12189 returns "popup".
12190
12191 Can also be used as a |method|: >
12192 GetWinid()->win_gettype()
12193<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012194 Return type: |String|
12195
12196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012197win_gotoid({expr}) *win_gotoid()*
12198 Go to window with ID {expr}. This may also change the current
12199 tabpage.
12200 Return TRUE if successful, FALSE if the window cannot be found.
12201
12202 Can also be used as a |method|: >
12203 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012204<
12205 Return type: |Number|
12206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012207
12208win_id2tabwin({expr}) *win_id2tabwin()*
12209 Return a list with the tab number and window number of window
12210 with ID {expr}: [tabnr, winnr].
12211 Return [0, 0] if the window cannot be found.
12212
12213 Can also be used as a |method|: >
12214 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012215<
12216 Return type: list<number>
12217
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012218
12219win_id2win({expr}) *win_id2win()*
12220 Return the window number of window with ID {expr}.
12221 Return 0 if the window cannot be found in the current tabpage.
12222
12223 Can also be used as a |method|: >
12224 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012225<
12226 Return type: |Number|
12227
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012228
Daniel Steinbergee630312022-01-10 13:36:34 +000012229win_move_separator({nr}, {offset}) *win_move_separator()*
12230 Move window {nr}'s vertical separator (i.e., the right border)
12231 by {offset} columns, as if being dragged by the mouse. {nr}
12232 can be a window number or |window-ID|. A positive {offset}
12233 moves right and a negative {offset} moves left. Moving a
12234 window's vertical separator will change the width of the
12235 window and the width of other windows adjacent to the vertical
12236 separator. The magnitude of movement may be smaller than
12237 specified (e.g., as a consequence of maintaining
12238 'winminwidth'). Returns TRUE if the window can be found and
12239 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012240 This will fail for the rightmost window and a full-width
12241 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012242 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012243
12244 Can also be used as a |method|: >
12245 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012246<
12247 Return type: |Number|
12248
Daniel Steinbergee630312022-01-10 13:36:34 +000012249
12250win_move_statusline({nr}, {offset}) *win_move_statusline()*
12251 Move window {nr}'s status line (i.e., the bottom border) by
12252 {offset} rows, as if being dragged by the mouse. {nr} can be a
12253 window number or |window-ID|. A positive {offset} moves down
12254 and a negative {offset} moves up. Moving a window's status
12255 line will change the height of the window and the height of
12256 other windows adjacent to the status line. The magnitude of
12257 movement may be smaller than specified (e.g., as a consequence
12258 of maintaining 'winminheight'). Returns TRUE if the window can
12259 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012260 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012261
12262 Can also be used as a |method|: >
12263 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012264<
12265 Return type: |Number|
12266
Daniel Steinbergee630312022-01-10 13:36:34 +000012267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012268win_screenpos({nr}) *win_screenpos()*
12269 Return the screen position of window {nr} as a list with two
12270 numbers: [row, col]. The first window always has position
12271 [1, 1], unless there is a tabline, then it is [2, 1].
12272 {nr} can be the window number or the |window-ID|. Use zero
12273 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012274 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012275
12276 Can also be used as a |method|: >
12277 GetWinid()->win_screenpos()
12278<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012279 Return type: list<number>
12280
12281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012282win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012283 Temporarily switch to window {target}, then move window {nr}
12284 to a new split adjacent to {target}.
12285 Unlike commands such as |:split|, no new windows are created
12286 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012287
12288 Both {nr} and {target} can be window numbers or |window-ID|s.
12289 Both must be in the current tab page.
12290
12291 Returns zero for success, non-zero for failure.
12292
12293 {options} is a |Dictionary| with the following optional entries:
12294 "vertical" When TRUE, the split is created vertically,
12295 like with |:vsplit|.
12296 "rightbelow" When TRUE, the split is made below or to the
12297 right (if vertical). When FALSE, it is done
12298 above or to the left (if vertical). When not
12299 present, the values of 'splitbelow' and
12300 'splitright' are used.
12301
12302 Can also be used as a |method|: >
12303 GetWinid()->win_splitmove(target)
12304<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012305 Return type: |Number|
12306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012307
12308 *winbufnr()*
12309winbufnr({nr}) The result is a Number, which is the number of the buffer
12310 associated with window {nr}. {nr} can be the window number or
12311 the |window-ID|.
12312 When {nr} is zero, the number of the buffer in the current
12313 window is returned.
12314 When window {nr} doesn't exist, -1 is returned.
12315 Example: >
12316 :echo "The file in the current window is " . bufname(winbufnr(0))
12317<
12318 Can also be used as a |method|: >
12319 FindWindow()->winbufnr()->bufname()
12320<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012321 Return type: |Number|
12322
12323
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012324 *wincol()*
12325wincol() The result is a Number, which is the virtual column of the
12326 cursor in the window. This is counting screen cells from the
12327 left side of the window. The leftmost column is one.
12328
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012329 Return type: |Number|
12330
12331
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012332 *windowsversion()*
12333windowsversion()
12334 The result is a String. For MS-Windows it indicates the OS
12335 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12336 Windows XP is "5.1". For non-MS-Windows systems the result is
12337 an empty string.
12338
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012339 Return type: |String|
12340
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012341winheight({nr}) *winheight()*
12342 The result is a Number, which is the height of window {nr}.
12343 {nr} can be the window number or the |window-ID|.
12344 When {nr} is zero, the height of the current window is
12345 returned. When window {nr} doesn't exist, -1 is returned.
12346 An existing window always has a height of zero or more.
12347 This excludes any window toolbar line.
12348 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012349 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012350
12351< Can also be used as a |method|: >
12352 GetWinid()->winheight()
12353<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012354 Return type: |Number|
12355
12356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012357winlayout([{tabnr}]) *winlayout()*
12358 The result is a nested List containing the layout of windows
12359 in a tabpage.
12360
12361 Without {tabnr} use the current tabpage, otherwise the tabpage
12362 with number {tabnr}. If the tabpage {tabnr} is not found,
12363 returns an empty list.
12364
12365 For a leaf window, it returns:
12366 ['leaf', {winid}]
12367 For horizontally split windows, which form a column, it
12368 returns:
12369 ['col', [{nested list of windows}]]
12370 For vertically split windows, which form a row, it returns:
12371 ['row', [{nested list of windows}]]
12372
12373 Example: >
12374 " Only one window in the tab page
12375 :echo winlayout()
12376 ['leaf', 1000]
12377 " Two horizontally split windows
12378 :echo winlayout()
12379 ['col', [['leaf', 1000], ['leaf', 1001]]]
12380 " The second tab page, with three horizontally split
12381 " windows, with two vertically split windows in the
12382 " middle window
12383 :echo winlayout(2)
12384 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12385 ['leaf', 1001]]], ['leaf', 1000]]]
12386<
12387 Can also be used as a |method|: >
12388 GetTabnr()->winlayout()
12389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012390 Return type: list<any>
12391
12392
12393winline() *winline()*
12394 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012395 in the window. This is counting screen lines from the top of
12396 the window. The first line is one.
12397 If the cursor was moved the view on the file will be updated
12398 first, this may cause a scroll.
12399
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012400 Return type: |Number|
12401
12402
12403winnr([{arg}]) *winnr()*
12404 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012405 window. The top window has number 1.
12406 Returns zero for a popup window.
12407
12408 The optional argument {arg} supports the following values:
12409 $ the number of the last window (the window
12410 count).
12411 # the number of the last accessed window (where
12412 |CTRL-W_p| goes to). If there is no previous
12413 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012414 returned. May refer to the current window in
12415 some cases (e.g. when evaluating 'statusline'
12416 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012417 {N}j the number of the Nth window below the
12418 current window (where |CTRL-W_j| goes to).
12419 {N}k the number of the Nth window above the current
12420 window (where |CTRL-W_k| goes to).
12421 {N}h the number of the Nth window left of the
12422 current window (where |CTRL-W_h| goes to).
12423 {N}l the number of the Nth window right of the
12424 current window (where |CTRL-W_l| goes to).
12425 The number can be used with |CTRL-W_w| and ":wincmd w"
12426 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012427 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012428 Also see |tabpagewinnr()| and |win_getid()|.
12429 Examples: >
12430 let window_count = winnr('$')
12431 let prev_window = winnr('#')
12432 let wnum = winnr('3k')
12433
12434< Can also be used as a |method|: >
12435 GetWinval()->winnr()
12436<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012437 Return type: |Number|
12438
12439
12440winrestcmd() *winrestcmd()*
12441 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012442 the current window sizes. Only works properly when no windows
12443 are opened or closed and the current window and tab page is
12444 unchanged.
12445 Example: >
12446 :let cmd = winrestcmd()
12447 :call MessWithWindowSizes()
12448 :exe cmd
12449<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012450 Return type: |String|
12451
12452
12453winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012454 Uses the |Dictionary| returned by |winsaveview()| to restore
12455 the view of the current window.
12456 Note: The {dict} does not have to contain all values, that are
12457 returned by |winsaveview()|. If values are missing, those
12458 settings won't be restored. So you can use: >
12459 :call winrestview({'curswant': 4})
12460<
12461 This will only set the curswant value (the column the cursor
12462 wants to move on vertical movements) of the cursor to column 5
12463 (yes, that is 5), while all other settings will remain the
12464 same. This is useful, if you set the cursor position manually.
12465
12466 If you have changed the values the result is unpredictable.
12467 If the window size changed the result won't be the same.
12468
12469 Can also be used as a |method|: >
12470 GetView()->winrestview()
12471<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012472 Return type: |Number|
12473
12474
12475winsaveview() *winsaveview()*
12476 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012477 the view of the current window. Use |winrestview()| to
12478 restore the view.
12479 This is useful if you have a mapping that jumps around in the
12480 buffer and you want to go back to the original view.
12481 This does not save fold information. Use the 'foldenable'
12482 option to temporarily switch off folding, so that folds are
12483 not opened when moving around. This may have side effects.
12484 The return value includes:
12485 lnum cursor line number
12486 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012487 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012488 returns)
12489 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012490 curswant column for vertical movement (Note:
12491 the first column is zero, as opposed
12492 to what |getcurpos()| returns). After
12493 |$| command it will be a very large
12494 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012495 topline first line in the window
12496 topfill filler lines, only in diff mode
12497 leftcol first column displayed; only used when
12498 'wrap' is off
12499 skipcol columns skipped
12500 Note that no option values are saved.
12501
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012502 Return type: dict<number>
12503
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012504
12505winwidth({nr}) *winwidth()*
12506 The result is a Number, which is the width of window {nr}.
12507 {nr} can be the window number or the |window-ID|.
12508 When {nr} is zero, the width of the current window is
12509 returned. When window {nr} doesn't exist, -1 is returned.
12510 An existing window always has a width of zero or more.
12511 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012512 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012513 :if winwidth(0) <= 50
12514 : 50 wincmd |
12515 :endif
12516< For getting the terminal or screen size, see the 'columns'
12517 option.
12518
12519 Can also be used as a |method|: >
12520 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012521<
12522 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012523
12524
12525wordcount() *wordcount()*
12526 The result is a dictionary of byte/chars/word statistics for
12527 the current buffer. This is the same info as provided by
12528 |g_CTRL-G|
12529 The return value includes:
12530 bytes Number of bytes in the buffer
12531 chars Number of chars in the buffer
12532 words Number of words in the buffer
12533 cursor_bytes Number of bytes before cursor position
12534 (not in Visual mode)
12535 cursor_chars Number of chars before cursor position
12536 (not in Visual mode)
12537 cursor_words Number of words before cursor position
12538 (not in Visual mode)
12539 visual_bytes Number of bytes visually selected
12540 (only in Visual mode)
12541 visual_chars Number of chars visually selected
12542 (only in Visual mode)
12543 visual_words Number of words visually selected
12544 (only in Visual mode)
12545
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012546 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012547
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012548
12549writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012550 When {object} is a |List| write it to file {fname}. Each list
12551 item is separated with a NL. Each list item must be a String
12552 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012553 All NL characters are replaced with a NUL character.
12554 Inserting CR characters needs to be done before passing {list}
12555 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012556
12557 When {object} is a |Blob| write the bytes to file {fname}
12558 unmodified, also when binary mode is not specified.
12559
12560 {flags} must be a String. These characters are recognized:
12561
12562 'b' Binary mode is used: There will not be a NL after the
12563 last list item. An empty item at the end does cause the
12564 last line in the file to end in a NL.
12565
12566 'a' Append mode is used, lines are appended to the file: >
12567 :call writefile(["foo"], "event.log", "a")
12568 :call writefile(["bar"], "event.log", "a")
12569<
12570 'D' Delete the file when the current function ends. This
12571 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012572 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012573< Fails when not in a function. Also see |:defer|.
12574
12575 's' fsync() is called after writing the file. This flushes
12576 the file to disk, if possible. This takes more time but
12577 avoids losing the file if the system crashes.
12578
12579 'S' fsync() is not called, even when 'fsync' is set.
12580
12581 When {flags} does not contain "S" or "s" then fsync() is
12582 called if the 'fsync' option is set.
12583
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012584 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012586 When the write fails -1 is returned, otherwise 0. There is an
12587 error message if the file can't be created or when writing
12588 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012590 Also see |readfile()|.
12591 To copy a file byte for byte: >
12592 :let fl = readfile("foo", "b")
12593 :call writefile(fl, "foocopy", "b")
12594
12595< Can also be used as a |method|: >
12596 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012597<
12598 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012599
12600
12601xor({expr}, {expr}) *xor()*
12602 Bitwise XOR on the two arguments. The arguments are converted
12603 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012604 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012605 Example: >
12606 :let bits = xor(bits, 0x80)
12607<
12608 Can also be used as a |method|: >
12609 :let bits = bits->xor(0x80)
12610<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012611 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012612
12613==============================================================================
126143. Feature list *feature-list*
12615
12616There are three types of features:
126171. Features that are only supported when they have been enabled when Vim
12618 was compiled |+feature-list|. Example: >
12619 :if has("cindent")
12620< *gui_running*
126212. Features that are only supported when certain conditions have been met.
12622 Example: >
12623 :if has("gui_running")
12624< *has-patch*
126253. Beyond a certain version or at a certain version and including a specific
12626 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12627 later, or it is version 7.4 and patch 248 was included. Example: >
12628 :if has("patch-7.4.248")
12629< Note that it's possible for patch 248 to be omitted even though 249 is
12630 included. Only happens when cherry-picking patches.
12631 Note that this form only works for patch 7.4.237 and later, before that
12632 you need to check for the patch and the v:version. Example (checking
12633 version 6.2.148 or later): >
12634 :if v:version > 602 || (v:version == 602 && has("patch148"))
12635
12636Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12637use: `if exists('+shellslash')`
12638
12639
12640acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012641all_builtin_terms Compiled with all builtin terminals enabled. (always
12642 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012643amiga Amiga version of Vim.
12644arabic Compiled with Arabic support |Arabic|.
12645arp Compiled with ARP support (Amiga).
12646autocmd Compiled with autocommand support. (always true)
12647autochdir Compiled with support for 'autochdir'
12648autoservername Automatically enable |clientserver|
12649balloon_eval Compiled with |balloon-eval| support.
12650balloon_multiline GUI supports multiline balloons.
12651beos BeOS version of Vim.
12652browse Compiled with |:browse| support, and browse() will
12653 work.
12654browsefilter Compiled with support for |browsefilter|.
12655bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012656builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012657byte_offset Compiled with support for 'o' in 'statusline'
12658channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012659cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012660clientserver Compiled with remote invocation support |clientserver|.
12661clipboard Compiled with 'clipboard' support.
12662clipboard_working Compiled with 'clipboard' support and it can be used.
12663cmdline_compl Compiled with |cmdline-completion| support.
12664cmdline_hist Compiled with |cmdline-history| support.
12665cmdline_info Compiled with 'showcmd' and 'ruler' support.
12666comments Compiled with |'comments'| support.
12667compatible Compiled to be very Vi compatible.
12668conpty Platform where |ConPTY| can be used.
12669cryptv Compiled with encryption support |encryption|.
12670cscope Compiled with |cscope| support.
12671cursorbind Compiled with |'cursorbind'| (always true)
12672debug Compiled with "DEBUG" defined.
12673dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012674dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012675dialog_gui Compiled with GUI dialog support.
12676diff Compiled with |vimdiff| and 'diff' support.
12677digraphs Compiled with support for digraphs.
12678directx Compiled with support for DirectX and 'renderoptions'.
12679dnd Compiled with support for the "~ register |quote_~|.
12680drop_file Compiled with |drop_file| support.
12681ebcdic Compiled on a machine with ebcdic character set.
12682emacs_tags Compiled with support for Emacs tags.
12683eval Compiled with expression evaluation support. Always
12684 true, of course!
12685ex_extra |+ex_extra| (always true)
12686extra_search Compiled with support for |'incsearch'| and
12687 |'hlsearch'|
12688farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012689file_in_path Compiled with support for |gf| and |<cfile>| (always
12690 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012691filterpipe When 'shelltemp' is off pipes are used for shell
12692 read/write/filter commands
12693find_in_path Compiled with support for include file searches
12694 |+find_in_path|.
12695float Compiled with support for |Float|.
12696fname_case Case in file names matters (for Amiga and MS-Windows
12697 this is not present).
12698folding Compiled with |folding| support.
12699footer Compiled with GUI footer support. |gui-footer|
12700fork Compiled to use fork()/exec() instead of system().
12701gettext Compiled with message translation |multi-lang|
12702gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012703gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012704gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12705gui_gtk Compiled with GTK+ GUI (any version).
12706gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12707gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12708gui_haiku Compiled with Haiku GUI.
12709gui_mac Compiled with Macintosh GUI.
12710gui_motif Compiled with Motif GUI.
12711gui_photon Compiled with Photon GUI.
12712gui_running Vim is running in the GUI, or it will start soon.
12713gui_win32 Compiled with MS-Windows Win32 GUI.
12714gui_win32s idem, and Win32s system being used (Windows 3.1)
12715haiku Haiku version of Vim.
12716hangul_input Compiled with Hangul input support. |hangul|
12717hpux HP-UX version of Vim.
12718iconv Can use iconv() for conversion.
12719insert_expand Compiled with support for CTRL-X expansion commands in
12720 Insert mode. (always true)
12721job Compiled with support for |channel| and |job|
12722ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012723jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012724keymap Compiled with 'keymap' support.
12725lambda Compiled with |lambda| support.
12726langmap Compiled with 'langmap' support.
12727libcall Compiled with |libcall()| support.
12728linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12729 'breakindent' support.
12730linux Linux version of Vim.
12731lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012732 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012733listcmds Compiled with commands for the buffer list |:files|
12734 and the argument list |arglist|.
12735localmap Compiled with local mappings and abbr. |:map-local|
12736lua Compiled with Lua interface |Lua|.
12737mac Any Macintosh version of Vim cf. osx
12738macunix Synonym for osxdarwin
12739menu Compiled with support for |:menu|.
12740mksession Compiled with support for |:mksession|.
12741modify_fname Compiled with file name modifiers. |filename-modifiers|
12742 (always true)
12743mouse Compiled with support for mouse.
12744mouse_dec Compiled with support for Dec terminal mouse.
12745mouse_gpm Compiled with support for gpm (Linux console mouse)
12746mouse_gpm_enabled GPM mouse is working
12747mouse_netterm Compiled with support for netterm mouse.
12748mouse_pterm Compiled with support for qnx pterm mouse.
12749mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12750mouse_sgr Compiled with support for sgr mouse.
12751mouse_urxvt Compiled with support for urxvt mouse.
12752mouse_xterm Compiled with support for xterm mouse.
12753mouseshape Compiled with support for 'mouseshape'.
12754multi_byte Compiled with support for 'encoding' (always true)
12755multi_byte_encoding 'encoding' is set to a multibyte encoding.
12756multi_byte_ime Compiled with support for IME input method.
12757multi_lang Compiled with support for multiple languages.
12758mzscheme Compiled with MzScheme interface |mzscheme|.
12759nanotime Compiled with sub-second time stamp checks.
12760netbeans_enabled Compiled with support for |netbeans| and connected.
12761netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012762num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012763ole Compiled with OLE automation support for Win32.
12764osx Compiled for macOS cf. mac
12765osxdarwin Compiled for macOS, with |mac-darwin-feature|
12766packages Compiled with |packages| support.
12767path_extra Compiled with up/downwards search in 'path' and 'tags'
12768perl Compiled with Perl interface.
12769persistent_undo Compiled with support for persistent undo history.
12770postscript Compiled with PostScript file printing.
12771printer Compiled with |:hardcopy| support.
12772profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012773prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012774python Python 2.x interface available. |has-python|
12775python_compiled Compiled with Python 2.x interface. |has-python|
12776python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12777python3 Python 3.x interface available. |has-python|
12778python3_compiled Compiled with Python 3.x interface. |has-python|
12779python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012780python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012781pythonx Python 2.x and/or 3.x interface available. |python_x|
12782qnx QNX version of Vim.
12783quickfix Compiled with |quickfix| support.
12784reltime Compiled with |reltime()| support.
12785rightleft Compiled with 'rightleft' support.
12786ruby Compiled with Ruby interface |ruby|.
12787scrollbind Compiled with 'scrollbind' support. (always true)
12788showcmd Compiled with 'showcmd' support.
12789signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012790smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012791sodium Compiled with libsodium for better crypt support
12792sound Compiled with sound support, e.g. `sound_playevent()`
12793spell Compiled with spell checking support |spell|.
12794startuptime Compiled with |--startuptime| support.
12795statusline Compiled with support for 'statusline', 'rulerformat'
12796 and special formats of 'titlestring' and 'iconstring'.
12797sun SunOS version of Vim.
12798sun_workshop Support for Sun |workshop| has been removed.
12799syntax Compiled with syntax highlighting support |syntax|.
12800syntax_items There are active syntax highlighting items for the
12801 current buffer.
12802system Compiled to use system() instead of fork()/exec().
12803tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012804 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012805tag_old_static Support for old static tags was removed, see
12806 |tag-old-static|.
12807tcl Compiled with Tcl interface.
12808termguicolors Compiled with true color in terminal support.
12809terminal Compiled with |terminal| support.
12810terminfo Compiled with terminfo instead of termcap.
12811termresponse Compiled with support for |t_RV| and |v:termresponse|.
12812textobjects Compiled with support for |text-objects|.
12813textprop Compiled with support for |text-properties|.
12814tgetent Compiled with tgetent support, able to use a termcap
12815 or terminfo file.
12816timers Compiled with |timer_start()| support.
12817title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012818 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012819toolbar Compiled with support for |gui-toolbar|.
12820ttyin input is a terminal (tty)
12821ttyout output is a terminal (tty)
12822unix Unix version of Vim. *+unix*
12823unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12824user_commands User-defined commands. (always true)
12825vartabs Compiled with variable tabstop support |'vartabstop'|.
12826vcon Win32: Virtual console support is working, can use
12827 'termguicolors'. Also see |+vtp|.
12828vertsplit Compiled with vertically split windows |:vsplit|.
12829 (always true)
12830vim_starting True while initial source'ing takes place. |startup|
12831 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012832vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012833viminfo Compiled with viminfo support.
12834vimscript-1 Compiled Vim script version 1 support
12835vimscript-2 Compiled Vim script version 2 support
12836vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012837vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012838virtualedit Compiled with 'virtualedit' option. (always true)
12839visual Compiled with Visual mode. (always true)
12840visualextra Compiled with extra Visual mode commands. (always
12841 true) |blockwise-operators|.
12842vms VMS version of Vim.
12843vreplace Compiled with |gR| and |gr| commands. (always true)
12844vtp Compiled for vcon support |+vtp| (check vcon to find
12845 out if it works in the current console).
12846wildignore Compiled with 'wildignore' option.
12847wildmenu Compiled with 'wildmenu' option.
12848win16 old version for MS-Windows 3.1 (always false)
12849win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12850 64 bits)
12851win32unix Win32 version of Vim, using Unix files (Cygwin)
12852win64 Win64 version of Vim (MS-Windows 64 bit).
12853win95 Win32 version for MS-Windows 95/98/ME (always false)
12854winaltkeys Compiled with 'winaltkeys' option.
12855windows Compiled with support for more than one window.
12856 (always true)
12857writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012858xattr Compiled with extended attributes support |xattr|
12859 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012860xfontset Compiled with X fontset support |xfontset|.
12861xim Compiled with X input method support |xim|.
12862xpm Compiled with pixmap support.
12863xpm_w32 Compiled with pixmap support for Win32. (Only for
12864 backward compatibility. Use "xpm" instead.)
12865xsmp Compiled with X session management support.
12866xsmp_interact Compiled with interactive X session management support.
12867xterm_clipboard Compiled with support for xterm clipboard.
12868xterm_save Compiled with support for saving and restoring the
12869 xterm screen.
12870x11 Compiled with X11 support.
12871
12872
12873==============================================================================
128744. Matching a pattern in a String *string-match*
12875
12876This is common between several functions. A regexp pattern as explained at
12877|pattern| is normally used to find a match in the buffer lines. When a
12878pattern is used to find a match in a String, almost everything works in the
12879same way. The difference is that a String is handled like it is one line.
12880When it contains a "\n" character, this is not seen as a line break for the
12881pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12882>
12883 :let a = "aaaa\nxxxx"
12884 :echo matchstr(a, "..\n..")
12885 aa
12886 xx
12887 :echo matchstr(a, "a.x")
12888 a
12889 x
12890
12891Don't forget that "^" will only match at the first character of the String and
12892"$" at the last character of the string. They don't match after or before a
12893"\n".
12894
12895 vim:tw=78:ts=8:noet:ft=help:norl: