blob: 6f5219cddf329fb37635158837a958aadf583a4a [file] [log] [blame]
Hirohito Higashi195fcc92025-02-01 10:26:58 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Feb 01
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan166b1752025-01-17 11:48:12 +010075blob2str({blob} [, {options}]) List convert {blob} into a list of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000132col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000133complete({startcol}, {matches}) none set Insert mode completion
134complete_add({expr}) Number add completion match
135complete_check() Number check for key typed during completion
136complete_info([{what}]) Dict get current completion information
137confirm({msg} [, {choices} [, {default} [, {type}]]])
138 Number number of choice picked by user
139copy({expr}) any make a shallow copy of {expr}
140cos({expr}) Float cosine of {expr}
141cosh({expr}) Float hyperbolic cosine of {expr}
142count({comp}, {expr} [, {ic} [, {start}]])
143 Number count how many {expr} are in {comp}
144cscope_connection([{num}, {dbpath} [, {prepend}]])
145 Number checks existence of cscope connection
146cursor({lnum}, {col} [, {off}])
147 Number move cursor to {lnum}, {col}, {off}
148cursor({list}) Number move cursor to position in {list}
149debugbreak({pid}) Number interrupt process being debugged
150deepcopy({expr} [, {noref}]) any make a full copy of {expr}
151delete({fname} [, {flags}]) Number delete the file or directory {fname}
152deletebufline({buf}, {first} [, {last}])
153 Number delete lines from buffer {buf}
154did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100155diff({fromlist}, {tolist} [, {options}])
156 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000157diff_filler({lnum}) Number diff filler lines about {lnum}
158diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
159digraph_get({chars}) String get the |digraph| of {chars}
160digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200161digraph_set({chars}, {digraph}) Bool register |digraph|
162digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000163echoraw({expr}) none output {expr} as-is
164empty({expr}) Number |TRUE| if {expr} is empty
165environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100166err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000167escape({string}, {chars}) String escape {chars} in {string} with '\'
168eval({string}) any evaluate {string} into its value
169eventhandler() Number |TRUE| if inside an event handler
170executable({expr}) Number 1 if executable {expr} exists
171execute({command}) String execute {command} and get the output
172exepath({expr}) String full path of the command {expr}
173exists({expr}) Number |TRUE| if {expr} exists
174exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
175exp({expr}) Float exponential of {expr}
176expand({expr} [, {nosuf} [, {list}]])
177 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100178expandcmd({string} [, {options}])
179 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000180extend({expr1}, {expr2} [, {expr3}])
181 List/Dict insert items of {expr2} into {expr1}
182extendnew({expr1}, {expr2} [, {expr3}])
183 List/Dict like |extend()| but creates a new
184 List or Dictionary
185feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200186filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
187 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000188filereadable({file}) Number |TRUE| if {file} is a readable file
189filewritable({file}) Number |TRUE| if {file} is a writable file
190filter({expr1}, {expr2}) List/Dict/Blob/String
191 remove items from {expr1} where
192 {expr2} is 0
193finddir({name} [, {path} [, {count}]])
194 String find directory {name} in {path}
195findfile({name} [, {path} [, {count}]])
196 String find file {name} in {path}
197flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
198flattennew({list} [, {maxdepth}])
199 List flatten a copy of {list}
200float2nr({expr}) Number convert Float {expr} to a Number
201floor({expr}) Float round {expr} down
202fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
203fnameescape({fname}) String escape special characters in {fname}
204fnamemodify({fname}, {mods}) String modify file name
205foldclosed({lnum}) Number first line of fold at {lnum} if closed
206foldclosedend({lnum}) Number last line of fold at {lnum} if closed
207foldlevel({lnum}) Number fold level at {lnum}
208foldtext() String line displayed for closed fold
209foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100210foreach({expr1}, {expr2}) List/Dict/Blob/String
211 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100213fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214funcref({name} [, {arglist}] [, {dict}])
215 Funcref reference to function {name}
216function({name} [, {arglist}] [, {dict}])
217 Funcref named reference to function {name}
218garbagecollect([{atexit}]) none free memory, breaking cyclic references
219get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
220get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
221get({func}, {what}) any get property of funcref/partial {func}
222getbufinfo([{buf}]) List information about buffers
223getbufline({buf}, {lnum} [, {end}])
224 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000225getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getbufvar({buf}, {varname} [, {def}])
227 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100228getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000229getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getchangelist([{buf}]) List list of change list items
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
Hirohito Higashi195fcc92025-02-01 10:26:58 +0100613str2blob({list} [, {options}]) Blob convert list of strings into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000614str2float({expr} [, {quoted}]) Float convert String to Float
615str2list({expr} [, {utf8}]) List convert each character of {expr} to
616 ASCII/UTF-8 value
617str2nr({expr} [, {base} [, {quoted}]])
618 Number convert String to Number
619strcharlen({expr}) Number character length of the String {expr}
620strcharpart({str}, {start} [, {len} [, {skipcc}]])
621 String {len} characters of {str} at
622 character {start}
623strchars({expr} [, {skipcc}]) Number character count of the String {expr}
624strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
625strftime({format} [, {time}]) String format time with a specified format
626strgetchar({str}, {index}) Number get char {index} from {str}
627stridx({haystack}, {needle} [, {start}])
628 Number index of {needle} in {haystack}
629string({expr}) String String representation of {expr} value
630strlen({expr}) Number length of the String {expr}
631strpart({str}, {start} [, {len} [, {chars}]])
632 String {len} bytes/chars of {str} at
633 byte {start}
634strptime({format}, {timestring})
635 Number Convert {timestring} to unix timestamp
636strridx({haystack}, {needle} [, {start}])
637 Number last index of {needle} in {haystack}
638strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100639strutf16len({string} [, {countcc}])
640 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000641strwidth({expr}) Number display cell length of the String {expr}
642submatch({nr} [, {list}]) String or List
643 specific match in ":s" or substitute()
644substitute({expr}, {pat}, {sub}, {flags})
645 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000646swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000647swapinfo({fname}) Dict information about swap file {fname}
648swapname({buf}) String swap file of buffer {buf}
649synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
650synIDattr({synID}, {what} [, {mode}])
651 String attribute {what} of syntax ID {synID}
652synIDtrans({synID}) Number translated syntax ID of {synID}
653synconcealed({lnum}, {col}) List info about concealing
654synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
655system({expr} [, {input}]) String output of shell command/filter {expr}
656systemlist({expr} [, {input}]) List output of shell command/filter {expr}
657tabpagebuflist([{arg}]) List list of buffer numbers in tab page
658tabpagenr([{arg}]) Number number of current or last tab page
659tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
660tagfiles() List tags files used
661taglist({expr} [, {filename}]) List list of tags matching {expr}
662tan({expr}) Float tangent of {expr}
663tanh({expr}) Float hyperbolic tangent of {expr}
664tempname() String name for a temporary file
665term_dumpdiff({filename}, {filename} [, {options}])
666 Number display difference between two dumps
667term_dumpload({filename} [, {options}])
668 Number displaying a screen dump
669term_dumpwrite({buf}, {filename} [, {options}])
670 none dump terminal window contents
671term_getaltscreen({buf}) Number get the alternate screen flag
672term_getansicolors({buf}) List get ANSI palette in GUI color mode
673term_getattr({attr}, {what}) Number get the value of attribute {what}
674term_getcursor({buf}) List get the cursor position of a terminal
675term_getjob({buf}) Job get the job associated with a terminal
676term_getline({buf}, {row}) String get a line of text from a terminal
677term_getscrolled({buf}) Number get the scroll count of a terminal
678term_getsize({buf}) List get the size of a terminal
679term_getstatus({buf}) String get the status of a terminal
680term_gettitle({buf}) String get the title of a terminal
681term_gettty({buf}, [{input}]) String get the tty name of a terminal
682term_list() List get the list of terminal buffers
683term_scrape({buf}, {row}) List get row of a terminal screen
684term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
685term_setansicolors({buf}, {colors})
686 none set ANSI palette in GUI color mode
687term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
688term_setkill({buf}, {how}) none set signal to stop job in terminal
689term_setrestore({buf}, {command}) none set command to restore terminal
690term_setsize({buf}, {rows}, {cols})
691 none set the size of a terminal
692term_start({cmd} [, {options}]) Number open a terminal window and run a job
693term_wait({buf} [, {time}]) Number wait for screen to be updated
694terminalprops() Dict properties of the terminal
695test_alloc_fail({id}, {countdown}, {repeat})
696 none make memory allocation fail
697test_autochdir() none enable 'autochdir' during startup
698test_feedinput({string}) none add key sequence to input buffer
699test_garbagecollect_now() none free memory right now for testing
700test_garbagecollect_soon() none free memory soon for testing
701test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000702test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000703test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000704test_mswin_event({event}, {args})
705 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000706test_null_blob() Blob null value for testing
707test_null_channel() Channel null value for testing
708test_null_dict() Dict null value for testing
709test_null_function() Funcref null value for testing
710test_null_job() Job null value for testing
711test_null_list() List null value for testing
712test_null_partial() Funcref null value for testing
713test_null_string() String null value for testing
714test_option_not_set({name}) none reset flag indicating option was set
715test_override({expr}, {val}) none test with Vim internal overrides
716test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000717test_setmouse({row}, {col}) none set the mouse position for testing
718test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200719test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000720test_unknown() any unknown value for testing
721test_void() any void value for testing
722timer_info([{id}]) List information about timers
723timer_pause({id}, {pause}) none pause or unpause a timer
724timer_start({time}, {callback} [, {options}])
725 Number create a timer
726timer_stop({timer}) none stop a timer
727timer_stopall() none stop all timers
728tolower({expr}) String the String {expr} switched to lowercase
729toupper({expr}) String the String {expr} switched to uppercase
730tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
731 to chars in {tostr}
732trim({text} [, {mask} [, {dir}]])
733 String trim characters in {mask} from {text}
734trunc({expr}) Float truncate Float {expr}
735type({expr}) Number type of value {expr}
736typename({expr}) String representation of the type of {expr}
737undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500738undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000739uniq({list} [, {func} [, {dict}]])
740 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100741utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
742 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000743values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200744virtcol({expr} [, {list} [, {winid}])
745 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100746 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100747virtcol2col({winid}, {lnum}, {col})
748 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200749visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000750wildmenumode() Number whether 'wildmenu' mode is active
751win_execute({id}, {command} [, {silent}])
752 String execute {command} in window {id}
753win_findbuf({bufnr}) List find windows containing {bufnr}
754win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
755win_gettype([{nr}]) String type of window {nr}
756win_gotoid({expr}) Number go to window with ID {expr}
757win_id2tabwin({expr}) List get tab and window nr from window ID
758win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000759win_move_separator({nr}) Number move window vertical separator
760win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000761win_screenpos({nr}) List get screen position of window {nr}
762win_splitmove({nr}, {target} [, {options}])
763 Number move window {nr} to split of {target}
764winbufnr({nr}) Number buffer number of window {nr}
765wincol() Number window column of the cursor
766windowsversion() String MS-Windows OS version
767winheight({nr}) Number height of window {nr}
768winlayout([{tabnr}]) List layout of windows in tab {tabnr}
769winline() Number window line of the cursor
770winnr([{expr}]) Number number of current window
771winrestcmd() String returns command to restore window sizes
772winrestview({dict}) none restore view of current window
773winsaveview() Dict save view of current window
774winwidth({nr}) Number width of window {nr}
775wordcount() Dict get byte/char/word statistics
776writefile({object}, {fname} [, {flags}])
777 Number write |Blob| or |List| of lines to file
778xor({expr}, {expr}) Number bitwise XOR
779
780==============================================================================
7812. Details *builtin-function-details*
782
783Not all functions are here, some have been moved to a help file covering the
784specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200785Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000786
787abs({expr}) *abs()*
788 Return the absolute value of {expr}. When {expr} evaluates to
789 a |Float| abs() returns a |Float|. When {expr} can be
790 converted to a |Number| abs() returns a |Number|. Otherwise
791 abs() gives an error message and returns -1.
792 Examples: >
793 echo abs(1.456)
794< 1.456 >
795 echo abs(-5.456)
796< 5.456 >
797 echo abs(-4)
798< 4
799
800 Can also be used as a |method|: >
801 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200802<
803 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000804
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000805
806acos({expr}) *acos()*
807 Return the arc cosine of {expr} measured in radians, as a
808 |Float| in the range of [0, pi].
809 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100810 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000811 Examples: >
812 :echo acos(0)
813< 1.570796 >
814 :echo acos(-0.5)
815< 2.094395
816
817 Can also be used as a |method|: >
818 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200819<
820 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000822
823add({object}, {expr}) *add()*
824 Append the item {expr} to |List| or |Blob| {object}. Returns
825 the resulting |List| or |Blob|. Examples: >
826 :let alist = add([1, 2, 3], item)
827 :call add(mylist, "woodstock")
828< Note that when {expr} is a |List| it is appended as a single
829 item. Use |extend()| to concatenate |Lists|.
830 When {object} is a |Blob| then {expr} must be a number.
831 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100832 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000833
834 Can also be used as a |method|: >
835 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200836<
837 Return type: list<{type}> (depending on the given |List|) or
838 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000839
840
841and({expr}, {expr}) *and()*
842 Bitwise AND on the two arguments. The arguments are converted
843 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100844 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000845 Example: >
846 :let flag = and(bits, 0x80)
847< Can also be used as a |method|: >
848 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200849<
850 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000851
852
853append({lnum}, {text}) *append()*
854 When {text} is a |List|: Append each item of the |List| as a
855 text line below line {lnum} in the current buffer.
856 Otherwise append {text} as one text line below line {lnum} in
857 the current buffer.
858 Any type of item is accepted and converted to a String.
859 {lnum} can be zero to insert a line before the first one.
860 {lnum} is used like with |getline()|.
861 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000862 0 for success. When {text} is an empty list zero is returned,
863 no matter the value of {lnum}.
864 In |Vim9| script an invalid argument or negative number
865 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000866 :let failed = append(line('$'), "# THE END")
867 :let failed = append(0, ["Chapter 1", "the beginning"])
868
869< Can also be used as a |method| after a List, the base is
870 passed as the second argument: >
871 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200872<
873 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000874
875
876appendbufline({buf}, {lnum}, {text}) *appendbufline()*
877 Like |append()| but append the text in buffer {buf}.
878
879 This function works only for loaded buffers. First call
880 |bufload()| if needed.
881
882 For the use of {buf}, see |bufname()|.
883
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000884 {lnum} is the line number to append below. Note that using
885 |line()| would use the current buffer, not the one appending
886 to. Use "$" to append at the end of the buffer. Other string
887 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000888
889 On success 0 is returned, on failure 1 is returned.
890 In |Vim9| script an error is given for an invalid {lnum}.
891
892 If {buf} is not a valid buffer or {lnum} is not valid, an
893 error message is given. Example: >
894 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000895< However, when {text} is an empty list then no error is given
896 for an invalid {lnum}, since {lnum} isn't actually used.
897
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000898 Can also be used as a |method| after a List, the base is
899 passed as the second argument: >
900 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200901<
902 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000903
904
905argc([{winid}]) *argc()*
906 The result is the number of files in the argument list. See
907 |arglist|.
908 If {winid} is not supplied, the argument list of the current
909 window is used.
910 If {winid} is -1, the global argument list is used.
911 Otherwise {winid} specifies the window of which the argument
912 list is used: either the window number or the window ID.
913 Returns -1 if the {winid} argument is invalid.
914
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200915 Return type: |Number|
916
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000917 *argidx()*
918argidx() The result is the current index in the argument list. 0 is
919 the first file. argc() - 1 is the last one. See |arglist|.
920
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200921 Return type: |Number|
922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000923 *arglistid()*
924arglistid([{winnr} [, {tabnr}]])
925 Return the argument list ID. This is a number which
926 identifies the argument list being used. Zero is used for the
927 global argument list. See |arglist|.
928 Returns -1 if the arguments are invalid.
929
930 Without arguments use the current window.
931 With {winnr} only use this window in the current tab page.
932 With {winnr} and {tabnr} use the window in the specified tab
933 page.
934 {winnr} can be the window number or the |window-ID|.
935
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200936 Return type: |Number|
937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000938 *argv()*
939argv([{nr} [, {winid}]])
940 The result is the {nr}th file in the argument list. See
941 |arglist|. "argv(0)" is the first one. Example: >
942 :let i = 0
943 :while i < argc()
944 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000945 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000946 : let i = i + 1
947 :endwhile
948< Without the {nr} argument, or when {nr} is -1, a |List| with
949 the whole |arglist| is returned.
950
951 The {winid} argument specifies the window ID, see |argc()|.
952 For the Vim command line arguments see |v:argv|.
953
Bram Moolenaar016188f2022-06-06 20:52:59 +0100954 Returns an empty string if {nr}th argument is not present in
955 the argument list. Returns an empty List if the {winid}
956 argument is invalid.
957
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200958 Return type: |String|
959
960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000961asin({expr}) *asin()*
962 Return the arc sine of {expr} measured in radians, as a |Float|
963 in the range of [-pi/2, pi/2].
964 {expr} must evaluate to a |Float| or a |Number| in the range
965 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100966 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
967 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000968 Examples: >
969 :echo asin(0.8)
970< 0.927295 >
971 :echo asin(-0.5)
972< -0.523599
973
974 Can also be used as a |method|: >
975 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200976<
977 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000978
979assert_ functions are documented here: |assert-functions-details|
980
981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000982atan({expr}) *atan()*
983 Return the principal value of the arc tangent of {expr}, in
984 the range [-pi/2, +pi/2] radians, as a |Float|.
985 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100986 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000987 Examples: >
988 :echo atan(100)
989< 1.560797 >
990 :echo atan(-4.01)
991< -1.326405
992
993 Can also be used as a |method|: >
994 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200995<
996 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000997
998
999atan2({expr1}, {expr2}) *atan2()*
1000 Return the arc tangent of {expr1} / {expr2}, measured in
1001 radians, as a |Float| in the range [-pi, pi].
1002 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001003 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1004 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001005 Examples: >
1006 :echo atan2(-1, 1)
1007< -0.785398 >
1008 :echo atan2(1, -1)
1009< 2.356194
1010
1011 Can also be used as a |method|: >
1012 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001013<
1014 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001015
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001016
1017autocmd_add({acmds}) *autocmd_add()*
1018 Adds a List of autocmds and autocmd groups.
1019
1020 The {acmds} argument is a List where each item is a Dict with
1021 the following optional items:
1022 bufnr buffer number to add a buffer-local autocmd.
1023 If this item is specified, then the "pattern"
1024 item is ignored.
1025 cmd Ex command to execute for this autocmd event
1026 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001027 This can be either a String with a single
1028 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001029 group autocmd group name. Refer to |autocmd-groups|.
1030 If this group doesn't exist then it is
1031 created. If not specified or empty, then the
1032 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001033 nested boolean flag, set to v:true to add a nested
1034 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001035 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001036 which executes only once. Refer to
1037 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001038 pattern autocmd pattern string. Refer to
1039 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001040 present, then this item is ignored. This can
1041 be a String with a single pattern or a List of
1042 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001043 replace boolean flag, set to v:true to remove all the
1044 commands associated with the specified autocmd
1045 event and group and add the {cmd}. This is
1046 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001047 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001048
1049 Returns v:true on success and v:false on failure.
1050 Examples: >
1051 " Create a buffer-local autocmd for buffer 5
1052 let acmd = {}
1053 let acmd.group = 'MyGroup'
1054 let acmd.event = 'BufEnter'
1055 let acmd.bufnr = 5
1056 let acmd.cmd = 'call BufEnterFunc()'
1057 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001058<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001059 Can also be used as a |method|: >
1060 GetAutocmdList()->autocmd_add()
1061<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001062 Return type: |vim9-boolean|
1063
1064
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001065autocmd_delete({acmds}) *autocmd_delete()*
1066 Deletes a List of autocmds and autocmd groups.
1067
1068 The {acmds} argument is a List where each item is a Dict with
1069 the following optional items:
1070 bufnr buffer number to delete a buffer-local autocmd.
1071 If this item is specified, then the "pattern"
1072 item is ignored.
1073 cmd Ex command for this autocmd event
1074 event autocmd event name. Refer to |autocmd-events|.
1075 If '*' then all the autocmd events in this
1076 group are deleted.
1077 group autocmd group name. Refer to |autocmd-groups|.
1078 If not specified or empty, then the default
1079 group is used.
1080 nested set to v:true for a nested autocmd.
1081 Refer to |autocmd-nested|.
1082 once set to v:true for an autocmd which executes
1083 only once. Refer to |autocmd-once|.
1084 pattern autocmd pattern string. Refer to
1085 |autocmd-patterns|. If "bufnr" item is
1086 present, then this item is ignored.
1087
1088 If only {group} is specified in a {acmds} entry and {event},
1089 {pattern} and {cmd} are not specified, then that autocmd group
1090 is deleted.
1091
Bram Moolenaar016188f2022-06-06 20:52:59 +01001092 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001093 Examples: >
1094 " :autocmd! BufLeave *.vim
1095 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1096 call autocmd_delete([acmd]})
1097 " :autocmd! MyGroup1 BufLeave
1098 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1099 call autocmd_delete([acmd])
1100 " :autocmd! MyGroup2 BufEnter *.c
1101 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1102 \ pattern: '*.c'}
1103 " :autocmd! MyGroup2 * *.c
1104 let acmd = #{group: 'MyGroup2', event: '*',
1105 \ pattern: '*.c'}
1106 call autocmd_delete([acmd])
1107 " :autocmd! MyGroup3
1108 let acmd = #{group: 'MyGroup3'}
1109 call autocmd_delete([acmd])
1110<
1111 Can also be used as a |method|: >
1112 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001113<
1114 Return type: |vim9-boolean|
1115
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001116
1117autocmd_get([{opts}]) *autocmd_get()*
1118 Returns a |List| of autocmds. If {opts} is not supplied, then
1119 returns the autocmds for all the events in all the groups.
1120
1121 The optional {opts} Dict argument supports the following
1122 items:
1123 group Autocmd group name. If specified, returns only
1124 the autocmds defined in this group. If the
1125 specified group doesn't exist, results in an
1126 error message. If set to an empty string,
1127 then the default autocmd group is used.
1128 event Autocmd event name. If specified, returns only
1129 the autocmds defined for this event. If set
1130 to "*", then returns autocmds for all the
1131 events. If the specified event doesn't exist,
1132 results in an error message.
1133 pattern Autocmd pattern. If specified, returns only
1134 the autocmds defined for this pattern.
1135 A combination of the above three times can be supplied in
1136 {opts}.
1137
1138 Each Dict in the returned List contains the following items:
1139 bufnr For buffer-local autocmds, buffer number where
1140 the autocmd is defined.
1141 cmd Command executed for this autocmd.
1142 event Autocmd event name.
1143 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001144 nested Boolean flag, set to v:true for a nested
1145 autocmd. See |autocmd-nested|.
1146 once Boolean flag, set to v:true, if the autocmd
1147 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001148 pattern Autocmd pattern. For a buffer-local
1149 autocmd, this will be of the form "<buffer=n>".
1150 If there are multiple commands for an autocmd event in a
1151 group, then separate items are returned for each command.
1152
Bram Moolenaar016188f2022-06-06 20:52:59 +01001153 Returns an empty List if an autocmd with the specified group
1154 or event or pattern is not found.
1155
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001156 Examples: >
1157 " :autocmd MyGroup
1158 echo autocmd_get(#{group: 'Mygroup'})
1159 " :autocmd G BufUnload
1160 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1161 " :autocmd G * *.ts
1162 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1163 echo autocmd_get(acmd)
1164 " :autocmd Syntax
1165 echo autocmd_get(#{event: 'Syntax'})
1166 " :autocmd G BufEnter *.ts
1167 let acmd = #{group: 'G', event: 'BufEnter',
1168 \ pattern: '*.ts'}
1169 echo autocmd_get(acmd)
1170<
1171 Can also be used as a |method|: >
1172 Getopts()->autocmd_get()
1173<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001174 Return type: list<dict<any>>
1175
1176
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001177balloon_gettext() *balloon_gettext()*
1178 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001179 not used for the List. Returns an empty string if balloon
1180 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001181
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001182 Return type: |String|
1183
1184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001185balloon_show({expr}) *balloon_show()*
1186 Show {expr} inside the balloon. For the GUI {expr} is used as
1187 a string. For a terminal {expr} can be a list, which contains
1188 the lines of the balloon. If {expr} is not a list it will be
1189 split with |balloon_split()|.
1190 If {expr} is an empty string any existing balloon is removed.
1191
1192 Example: >
1193 func GetBalloonContent()
1194 " ... initiate getting the content
1195 return ''
1196 endfunc
1197 set balloonexpr=GetBalloonContent()
1198
1199 func BalloonCallback(result)
1200 call balloon_show(a:result)
1201 endfunc
1202< Can also be used as a |method|: >
1203 GetText()->balloon_show()
1204<
1205 The intended use is that fetching the content of the balloon
1206 is initiated from 'balloonexpr'. It will invoke an
1207 asynchronous method, in which a callback invokes
1208 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001209 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001210
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001211 When showing a balloon is not possible then nothing happens,
1212 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001213 {only available when compiled with the |+balloon_eval| or
1214 |+balloon_eval_term| feature}
1215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001216 Return type: |Number|
1217
1218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001219balloon_split({msg}) *balloon_split()*
1220 Split String {msg} into lines to be displayed in a balloon.
1221 The splits are made for the current window size and optimize
1222 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001223 Returns a |List| with the split lines. Returns an empty List
1224 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001225 Can also be used as a |method|: >
1226 GetText()->balloon_split()->balloon_show()
1227
1228< {only available when compiled with the |+balloon_eval_term|
1229 feature}
1230
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001231 Return type: list<any> or list<string>
1232
h-easte80f3452025-01-02 10:40:29 +01001233base64_decode({string}) *base64_decode()*
1234 Return a Blob containing the bytes decoded from the base64
1235 encoded characters in {string}.
1236
1237 The {string} argument should contain only base64-encoded
1238 characters and should have a length that is a multiple of 4.
1239
1240 Returns an empty blob on error.
1241
1242 Examples: >
1243 " Write the decoded contents to a binary file
1244 call writefile(base64_decode(s), 'tools.bmp')
1245 " Decode a base64-encoded string
Maxim Kim6472e582025-01-15 18:31:05 +01001246 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001247<
1248 Can also be used as a |method|: >
1249 GetEncodedString()->base64_decode()
1250<
1251 Return type: |Blob|
1252
1253
1254base64_encode({blob}) *base64_encode()*
1255 Return a base64-encoded String representing the bytes in
1256 {blob}. The base64 alphabet defined in RFC 4648 is used.
1257
1258 Examples: >
1259 " Encode the contents of a binary file
1260 echo base64_encode(readblob('somefile.bin'))
1261 " Encode a string
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001262 echo base64_encode(str2blob([somestr]))
h-easte80f3452025-01-02 10:40:29 +01001263<
1264 Can also be used as a |method|: >
1265 GetBinaryData()->base64_encode()
1266<
1267 Return type: |String|
1268
1269
Christ van Willegence0ef912024-06-20 23:41:59 +02001270bindtextdomain({package}, {path}) *bindtextdomain()*
1271 Bind a specific {package} to a {path} so that the
1272 |gettext()| function can be used to get language-specific
1273 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001274 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001275
Christ van Willegen8252ef12024-07-11 21:36:21 +02001276 Returns v:true on success and v:false on failure (out of
1277 memory).
1278
1279 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001281blob2list({blob}) *blob2list()*
1282 Return a List containing the number value of each byte in Blob
1283 {blob}. Examples: >
1284 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1285 blob2list(0z) returns []
1286< Returns an empty List on error. |list2blob()| does the
1287 opposite.
1288
1289 Can also be used as a |method|: >
1290 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001291<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001292 Return type: list<any> or list<number>
1293
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001294
1295blob2str({blob} [, {options}]) *blob2str()*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001296 Return a List of Strings in the current 'encoding' by
1297 converting the bytes in {blob} into characters.
1298
1299 Each <NL> byte in the blob is interpreted as the end of a
1300 string and a new list item is added. Each <NUL> byte in the
1301 blob is converted into a <NL> character.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001302
1303 If {options} is not supplied, the current 'encoding' value is
1304 used to decode the bytes in {blob}.
1305
1306 The argument {options} is a |Dict| and supports the following
1307 items:
1308 encoding Decode the bytes in {blob} using this
1309 encoding. The value is a |String|. See
1310 |encoding-names| for the supported values.
1311 *E1515*
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001312 An error is given and an empty List is returned if
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001313 an invalid byte sequence is encountered in {blob},
1314
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001315 Returns an empty List if blob is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001316
1317 See also |str2blob()|
1318
1319 Examples: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001320 blob2str(0z6162) returns ["ab"]
1321 blob2str(0zC2ABC2BB) returns ["«»"]
1322 blob2str(0zABBB, {'encoding': 'latin1'}) returns ["«»"]
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001323<
1324 Can also be used as a |method|: >
1325 GetBlob()->blob2str()
1326<
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +01001327 Return type: list<string>
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001328
1329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001330 *browse()*
1331browse({save}, {title}, {initdir}, {default})
1332 Put up a file requester. This only works when "has("browse")"
1333 returns |TRUE| (only in some GUI versions).
1334 The input fields are:
1335 {save} when |TRUE|, select file to write
1336 {title} title for the requester
1337 {initdir} directory to start browsing in
1338 {default} default file name
1339 An empty string is returned when the "Cancel" button is hit,
1340 something went wrong, or browsing is not possible.
1341
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001342 Return type: |String|
1343
1344
1345browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001346 Put up a directory requester. This only works when
1347 "has("browse")" returns |TRUE| (only in some GUI versions).
1348 On systems where a directory browser is not supported a file
1349 browser is used. In that case: select a file in the directory
1350 to be used.
1351 The input fields are:
1352 {title} title for the requester
1353 {initdir} directory to start browsing in
1354 When the "Cancel" button is hit, something went wrong, or
1355 browsing is not possible, an empty string is returned.
1356
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001357 Return type: |String|
1358
1359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001360bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001361 Add a buffer to the buffer list with name {name} (must be a
1362 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001363 If a buffer for file {name} already exists, return that buffer
1364 number. Otherwise return the buffer number of the newly
1365 created buffer. When {name} is an empty string then a new
1366 buffer is always created.
1367 The buffer will not have 'buflisted' set and not be loaded
1368 yet. To add some text to the buffer use this: >
1369 let bufnr = bufadd('someName')
1370 call bufload(bufnr)
1371 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001372< Returns 0 on error.
1373 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001374 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001375<
1376 Return type: |Number|
1377
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001378
1379bufexists({buf}) *bufexists()*
1380 The result is a Number, which is |TRUE| if a buffer called
1381 {buf} exists.
1382 If the {buf} argument is a number, buffer numbers are used.
1383 Number zero is the alternate buffer for the current window.
1384
1385 If the {buf} argument is a string it must match a buffer name
1386 exactly. The name can be:
1387 - Relative to the current directory.
1388 - A full path.
1389 - The name of a buffer with 'buftype' set to "nofile".
1390 - A URL name.
1391 Unlisted buffers will be found.
1392 Note that help files are listed by their short name in the
1393 output of |:buffers|, but bufexists() requires using their
1394 long name to be able to find them.
1395 bufexists() may report a buffer exists, but to use the name
1396 with a |:buffer| command you may need to use |expand()|. Esp
1397 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1398 Use "bufexists(0)" to test for the existence of an alternate
1399 file name.
1400
1401 Can also be used as a |method|: >
1402 let exists = 'somename'->bufexists()
1403<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001404 Return type: |Number|
1405
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001406 Obsolete name: buffer_exists(). *buffer_exists()*
1407
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001409buflisted({buf}) *buflisted()*
1410 The result is a Number, which is |TRUE| if a buffer called
1411 {buf} exists and is listed (has the 'buflisted' option set).
1412 The {buf} argument is used like with |bufexists()|.
1413
1414 Can also be used as a |method|: >
1415 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001416<
1417 Return type: |Number|
1418
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001419
1420bufload({buf}) *bufload()*
1421 Ensure the buffer {buf} is loaded. When the buffer name
1422 refers to an existing file then the file is read. Otherwise
1423 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001424 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001425 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001426 If there is an existing swap file for the file of the buffer,
1427 there will be no dialog, the buffer will be loaded anyway.
1428 The {buf} argument is used like with |bufexists()|.
1429
1430 Can also be used as a |method|: >
1431 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001432<
1433 Return type: |Number|
1434
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001435
1436bufloaded({buf}) *bufloaded()*
1437 The result is a Number, which is |TRUE| if a buffer called
1438 {buf} exists and is loaded (shown in a window or hidden).
1439 The {buf} argument is used like with |bufexists()|.
1440
1441 Can also be used as a |method|: >
1442 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001443<
1444 Return type: |Number|
1445
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001446
1447bufname([{buf}]) *bufname()*
1448 The result is the name of a buffer. Mostly as it is displayed
1449 by the `:ls` command, but not using special names such as
1450 "[No Name]".
1451 If {buf} is omitted the current buffer is used.
1452 If {buf} is a Number, that buffer number's name is given.
1453 Number zero is the alternate buffer for the current window.
1454 If {buf} is a String, it is used as a |file-pattern| to match
1455 with the buffer names. This is always done like 'magic' is
1456 set and 'cpoptions' is empty. When there is more than one
1457 match an empty string is returned.
1458 "" or "%" can be used for the current buffer, "#" for the
1459 alternate buffer.
1460 A full match is preferred, otherwise a match at the start, end
1461 or middle of the buffer name is accepted. If you only want a
1462 full match then put "^" at the start and "$" at the end of the
1463 pattern.
1464 Listed buffers are found first. If there is a single match
1465 with a listed buffer, that one is returned. Next unlisted
1466 buffers are searched for.
1467 If the {buf} is a String, but you want to use it as a buffer
1468 number, force it to be a Number by adding zero to it: >
1469 :echo bufname("3" + 0)
1470< Can also be used as a |method|: >
1471 echo bufnr->bufname()
1472
1473< If the buffer doesn't exist, or doesn't have a name, an empty
1474 string is returned. >
1475 bufname("#") alternate buffer name
1476 bufname(3) name of buffer 3
1477 bufname("%") name of current buffer
1478 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001479<
1480 Return type: |String|
1481 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001482 Obsolete name: buffer_name().
1483
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001484
1485bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001486 The result is the number of a buffer, as it is displayed by
1487 the `:ls` command. For the use of {buf}, see |bufname()|
1488 above.
1489
1490 If the buffer doesn't exist, -1 is returned. Or, if the
1491 {create} argument is present and TRUE, a new, unlisted,
1492 buffer is created and its number is returned. Example: >
1493 let newbuf = bufnr('Scratch001', 1)
1494< Using an empty name uses the current buffer. To create a new
1495 buffer with an empty name use |bufadd()|.
1496
1497 bufnr("$") is the last buffer: >
1498 :let last_buffer = bufnr("$")
1499< The result is a Number, which is the highest buffer number
1500 of existing buffers. Note that not all buffers with a smaller
1501 number necessarily exist, because ":bwipeout" may have removed
1502 them. Use bufexists() to test for the existence of a buffer.
1503
1504 Can also be used as a |method|: >
1505 echo bufref->bufnr()
1506<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001507 Return type: |Number|
1508
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001509 Obsolete name: buffer_number(). *buffer_number()*
1510 *last_buffer_nr()*
1511 Obsolete name for bufnr("$"): last_buffer_nr().
1512
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001514bufwinid({buf}) *bufwinid()*
1515 The result is a Number, which is the |window-ID| of the first
1516 window associated with buffer {buf}. For the use of {buf},
1517 see |bufname()| above. If buffer {buf} doesn't exist or
1518 there is no such window, -1 is returned. Example: >
1519
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001520 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001521<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001522 Only deals with the current tab page. See |win_findbuf()| for
1523 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001524
1525 Can also be used as a |method|: >
1526 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001527<
1528 Return type: |Number|
1529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001530
1531bufwinnr({buf}) *bufwinnr()*
1532 Like |bufwinid()| but return the window number instead of the
1533 |window-ID|.
1534 If buffer {buf} doesn't exist or there is no such window, -1
1535 is returned. Example: >
1536
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001537 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001538
1539< The number can be used with |CTRL-W_w| and ":wincmd w"
1540 |:wincmd|.
1541
1542 Can also be used as a |method|: >
1543 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001544<
1545 Return type: |Number|
1546
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001547
1548byte2line({byte}) *byte2line()*
1549 Return the line number that contains the character at byte
1550 count {byte} in the current buffer. This includes the
1551 end-of-line character, depending on the 'fileformat' option
1552 for the current buffer. The first character has byte count
1553 one.
1554 Also see |line2byte()|, |go| and |:goto|.
1555
Bram Moolenaar016188f2022-06-06 20:52:59 +01001556 Returns -1 if the {byte} value is invalid.
1557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001558 Can also be used as a |method|: >
1559 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001560<
1561 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001562
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001563 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001564 feature}
1565
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001566
Christian Brabandt67672ef2023-04-24 21:09:54 +01001567byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001568 Return byte index of the {nr}'th character in the String
1569 {expr}. Use zero for the first character, it then returns
1570 zero.
1571 If there are no multibyte characters the returned value is
1572 equal to {nr}.
1573 Composing characters are not counted separately, their byte
1574 length is added to the preceding base character. See
1575 |byteidxcomp()| below for counting composing characters
1576 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001577 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1578 index in the String {expr} instead of as the character index.
1579 The UTF-16 index is the index in the string when it is encoded
1580 with 16-bit words. If the specified UTF-16 index is in the
1581 middle of a character (e.g. in a 4-byte character), then the
1582 byte index of the first byte in the character is returned.
1583 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001584 Example : >
1585 echo matchstr(str, ".", byteidx(str, 3))
1586< will display the fourth character. Another way to do the
1587 same: >
1588 let s = strpart(str, byteidx(str, 3))
1589 echo strpart(s, 0, byteidx(s, 1))
1590< Also see |strgetchar()| and |strcharpart()|.
1591
1592 If there are less than {nr} characters -1 is returned.
1593 If there are exactly {nr} characters the length of the string
1594 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001595 See |charidx()| and |utf16idx()| for getting the character and
1596 UTF-16 index respectively from the byte index.
1597 Examples: >
1598 echo byteidx('a😊😊', 2) returns 5
1599 echo byteidx('a😊😊', 2, 1) returns 1
1600 echo byteidx('a😊😊', 3, 1) returns 5
1601<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001602 Can also be used as a |method|: >
1603 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001604<
1605 Return type: |Number|
1606
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001607
Christian Brabandt67672ef2023-04-24 21:09:54 +01001608byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001609 Like byteidx(), except that a composing character is counted
1610 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001611 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001612 echo byteidx(s, 1)
1613 echo byteidxcomp(s, 1)
1614 echo byteidxcomp(s, 2)
1615< The first and third echo result in 3 ('e' plus composing
1616 character is 3 bytes), the second echo results in 1 ('e' is
1617 one byte).
1618 Only works differently from byteidx() when 'encoding' is set
1619 to a Unicode encoding.
1620
1621 Can also be used as a |method|: >
1622 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001623<
1624 Return type: |Number|
1625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001626
1627call({func}, {arglist} [, {dict}]) *call()* *E699*
1628 Call function {func} with the items in |List| {arglist} as
1629 arguments.
1630 {func} can either be a |Funcref| or the name of a function.
1631 a:firstline and a:lastline are set to the cursor line.
1632 Returns the return value of the called function.
1633 {dict} is for functions with the "dict" attribute. It will be
1634 used to set the local variable "self". |Dictionary-function|
1635
1636 Can also be used as a |method|: >
1637 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001638<
1639 Return type: any, depending on {func}
1640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001641
1642ceil({expr}) *ceil()*
1643 Return the smallest integral value greater than or equal to
1644 {expr} as a |Float| (round up).
1645 {expr} must evaluate to a |Float| or a |Number|.
1646 Examples: >
1647 echo ceil(1.456)
1648< 2.0 >
1649 echo ceil(-5.456)
1650< -5.0 >
1651 echo ceil(4.0)
1652< 4.0
1653
Bram Moolenaar016188f2022-06-06 20:52:59 +01001654 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1655
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001656 Can also be used as a |method|: >
1657 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001658<
1659 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001660
1661
1662ch_ functions are documented here: |channel-functions-details|
1663
1664
1665changenr() *changenr()*
1666 Return the number of the most recent change. This is the same
1667 number as what is displayed with |:undolist| and can be used
1668 with the |:undo| command.
1669 When a change was made it is the number of that change. After
1670 redo it is the number of the redone change. After undo it is
1671 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001672 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001673
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001674 Return type: |Number|
1675
1676
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001677char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001678 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001679 Examples: >
1680 char2nr(" ") returns 32
1681 char2nr("ABC") returns 65
1682< When {utf8} is omitted or zero, the current 'encoding' is used.
1683 Example for "utf-8": >
1684 char2nr("á") returns 225
1685 char2nr("á"[0]) returns 195
1686< When {utf8} is TRUE, always treat as UTF-8 characters.
1687 A combining character is a separate character.
1688 |nr2char()| does the opposite.
1689 To turn a string into a list of character numbers: >
1690 let str = "ABC"
1691 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1692< Result: [65, 66, 67]
1693
Bram Moolenaar016188f2022-06-06 20:52:59 +01001694 Returns 0 if {string} is not a |String|.
1695
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001696 Can also be used as a |method|: >
1697 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001698<
1699 Return type: |Number|
1700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001702charclass({string}) *charclass()*
1703 Return the character class of the first character in {string}.
1704 The character class is one of:
1705 0 blank
1706 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001707 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001708 3 emoji
1709 other specific Unicode class
1710 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001711 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001712
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001713 Return type: |Number|
1714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001715
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001716charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001717 Same as |col()| but returns the character index of the column
1718 position given with {expr} instead of the byte position.
1719
1720 Example:
1721 With the cursor on '세' in line 5 with text "여보세요": >
1722 charcol('.') returns 3
1723 col('.') returns 7
1724
1725< Can also be used as a |method|: >
1726 GetPos()->col()
1727<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001728 Return type: |Number|
1729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001730 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001731charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001732 Return the character index of the byte at {idx} in {string}.
1733 The index of the first character is zero.
1734 If there are no multibyte characters the returned value is
1735 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001737 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001738 are not counted separately, their byte length is added to the
1739 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001740 When {countcc} is |TRUE|, then composing characters are
1741 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001742
1743 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1744 index in the String {expr} instead of as the byte index.
1745
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001746 Returns -1 if the arguments are invalid or if there are less
1747 than {idx} bytes. If there are exactly {idx} bytes the length
1748 of the string in characters is returned.
1749
1750 An error is given and -1 is returned if the first argument is
1751 not a string, the second argument is not a number or when the
1752 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001753
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001754 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001755 from the character index and |utf16idx()| for getting the
1756 UTF-16 index from the character index.
1757 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001758 Examples: >
1759 echo charidx('áb́ć', 3) returns 1
1760 echo charidx('áb́ć', 6, 1) returns 4
1761 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001762 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001763<
1764 Can also be used as a |method|: >
1765 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001766<
1767 Return type: |Number|
1768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001769
1770chdir({dir}) *chdir()*
1771 Change the current working directory to {dir}. The scope of
1772 the directory change depends on the directory of the current
1773 window:
1774 - If the current window has a window-local directory
1775 (|:lcd|), then changes the window local directory.
1776 - Otherwise, if the current tabpage has a local
1777 directory (|:tcd|) then changes the tabpage local
1778 directory.
1779 - Otherwise, changes the global directory.
1780 {dir} must be a String.
1781 If successful, returns the previous working directory. Pass
1782 this to another chdir() to restore the directory.
1783 On failure, returns an empty string.
1784
1785 Example: >
1786 let save_dir = chdir(newdir)
1787 if save_dir != ""
1788 " ... do some work
1789 call chdir(save_dir)
1790 endif
1791
1792< Can also be used as a |method|: >
1793 GetDir()->chdir()
1794<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001795 Return type: |String|
1796
1797
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001798cindent({lnum}) *cindent()*
1799 Get the amount of indent for line {lnum} according the C
1800 indenting rules, as with 'cindent'.
1801 The indent is counted in spaces, the value of 'tabstop' is
1802 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001803 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001804 See |C-indenting|.
1805
1806 Can also be used as a |method|: >
1807 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001808<
1809 Return type: |Number|
1810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001811
1812clearmatches([{win}]) *clearmatches()*
1813 Clears all matches previously defined for the current window
1814 by |matchadd()| and the |:match| commands.
1815 If {win} is specified, use the window with this number or
1816 window ID instead of the current window.
1817
1818 Can also be used as a |method|: >
1819 GetWin()->clearmatches()
1820<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001821 Return type: |Number|
1822
1823
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001824col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001825 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001826 position given with {expr}.
1827 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001828 When {expr} is "$", it means the end of the cursor line, so
1829 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001830 Additionally {expr} can be [lnum, col]: a |List| with the line
1831 and column number. Most useful when the column is "$", to get
1832 the last column of a specific line. When "lnum" or "col" is
1833 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001834
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001835 With the optional {winid} argument the values are obtained for
1836 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001838 To get the line number use |line()|. To get both use
1839 |getpos()|.
1840 For the screen column position use |virtcol()|. For the
1841 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001843 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001844
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001845 Examples: >
1846 col(".") column of cursor
1847 col("$") length of cursor line plus one
1848 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001849 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001850<
1851 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001852 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001853 For an uppercase mark the column may actually be in another
1854 buffer.
1855 For the cursor position, when 'virtualedit' is active, the
1856 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001857 line. Also, when using a <Cmd> mapping the cursor isn't
1858 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001859 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001860
1861< Can also be used as a |method|: >
1862 GetPos()->col()
1863<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001864 Return type: |Number|
1865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001866
1867complete({startcol}, {matches}) *complete()* *E785*
1868 Set the matches for Insert mode completion.
1869 Can only be used in Insert mode. You need to use a mapping
1870 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1871 or with an expression mapping.
1872 {startcol} is the byte offset in the line where the completed
1873 text start. The text up to the cursor is the original text
1874 that will be replaced by the matches. Use col('.') for an
1875 empty string. "col('.') - 1" will replace one character by a
1876 match.
1877 {matches} must be a |List|. Each |List| item is one match.
1878 See |complete-items| for the kind of items that are possible.
1879 "longest" in 'completeopt' is ignored.
1880 Note that the after calling this function you need to avoid
1881 inserting anything that would cause completion to stop.
1882 The match can be selected with CTRL-N and CTRL-P as usual with
1883 Insert mode completion. The popup menu will appear if
1884 specified, see |ins-completion-menu|.
1885 Example: >
1886 inoremap <F5> <C-R>=ListMonths()<CR>
1887
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001888 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001889 call complete(col('.'), ['January', 'February', 'March',
1890 \ 'April', 'May', 'June', 'July', 'August', 'September',
1891 \ 'October', 'November', 'December'])
1892 return ''
1893 endfunc
1894< This isn't very useful, but it shows how it works. Note that
1895 an empty string is returned to avoid a zero being inserted.
1896
1897 Can also be used as a |method|, the base is passed as the
1898 second argument: >
1899 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001900<
1901 Return type: |Number|
1902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001903
1904complete_add({expr}) *complete_add()*
1905 Add {expr} to the list of matches. Only to be used by the
1906 function specified with the 'completefunc' option.
1907 Returns 0 for failure (empty string or out of memory),
1908 1 when the match was added, 2 when the match was already in
1909 the list.
1910 See |complete-functions| for an explanation of {expr}. It is
1911 the same as one item in the list that 'omnifunc' would return.
1912
1913 Can also be used as a |method|: >
1914 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001915<
1916 Return type: |Number|
1917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001918
1919complete_check() *complete_check()*
1920 Check for a key typed while looking for completion matches.
1921 This is to be used when looking for matches takes some time.
1922 Returns |TRUE| when searching for matches is to be aborted,
1923 zero otherwise.
1924 Only to be used by the function specified with the
1925 'completefunc' option.
1926
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001927 Return type: |Number|
1928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001929
1930complete_info([{what}]) *complete_info()*
1931 Returns a |Dictionary| with information about Insert mode
1932 completion. See |ins-completion|.
1933 The items are:
1934 mode Current completion mode name string.
1935 See |complete_info_mode| for the values.
1936 pum_visible |TRUE| if popup menu is visible.
1937 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001938 items List of all completion candidates. Each item
1939 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001940 "abbr", "menu", "kind", "info" and "user_data".
1941 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001942 matches Same as "items", but only returns items that
1943 are matching current query. If both "matches"
1944 and "items" are in "what", the returned list
1945 will still be named "items", but each item
1946 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001947 selected Selected item index. First index is zero.
1948 Index is -1 if no item is selected (showing
1949 typed text only, or the last completion after
1950 no item is selected when using the <Up> or
1951 <Down> keys)
glepnir037b0282025-01-16 14:37:44 +01001952 completed Return a dictionary containing the entries of
1953 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001954
1955 *complete_info_mode*
1956 mode values are:
1957 "" Not in completion mode
1958 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1959 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1960 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1961 |i_CTRL-X_CTRL-Y|
1962 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1963 "files" File names |i_CTRL-X_CTRL-F|
1964 "tags" Tags |i_CTRL-X_CTRL-]|
1965 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1966 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1967 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1968 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1969 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1970 "function" User defined completion |i_CTRL-X_CTRL-U|
1971 "omni" Omni completion |i_CTRL-X_CTRL-O|
1972 "spell" Spelling suggestions |i_CTRL-X_s|
1973 "eval" |complete()| completion
1974 "unknown" Other internal modes
1975
1976 If the optional {what} list argument is supplied, then only
1977 the items listed in {what} are returned. Unsupported items in
1978 {what} are silently ignored.
1979
1980 To get the position and size of the popup menu, see
1981 |pum_getpos()|. It's also available in |v:event| during the
1982 |CompleteChanged| event.
1983
Bram Moolenaar016188f2022-06-06 20:52:59 +01001984 Returns an empty |Dictionary| on error.
1985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001986 Examples: >
1987 " Get all items
1988 call complete_info()
1989 " Get only 'mode'
1990 call complete_info(['mode'])
1991 " Get only 'mode' and 'pum_visible'
1992 call complete_info(['mode', 'pum_visible'])
1993
1994< Can also be used as a |method|: >
1995 GetItems()->complete_info()
1996<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001997 Return type: dict<any>
1998
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001999 *confirm()*
2000confirm({msg} [, {choices} [, {default} [, {type}]]])
2001 confirm() offers the user a dialog, from which a choice can be
2002 made. It returns the number of the choice. For the first
2003 choice this is 1.
2004 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002005 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002006
2007 {msg} is displayed in a |dialog| with {choices} as the
2008 alternatives. When {choices} is missing or empty, "&OK" is
2009 used (and translated).
2010 {msg} is a String, use '\n' to include a newline. Only on
2011 some systems the string is wrapped when it doesn't fit.
2012
2013 {choices} is a String, with the individual choices separated
2014 by '\n', e.g. >
2015 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2016< The letter after the '&' is the shortcut key for that choice.
2017 Thus you can type 'c' to select "Cancel". The shortcut does
2018 not need to be the first letter: >
2019 confirm("file has been modified", "&Save\nSave &All")
2020< For the console, the first letter of each choice is used as
2021 the default shortcut key. Case is ignored.
2022
2023 The optional {default} argument is the number of the choice
2024 that is made if the user hits <CR>. Use 1 to make the first
2025 choice the default one. Use 0 to not set a default. If
2026 {default} is omitted, 1 is used.
2027
2028 The optional {type} String argument gives the type of dialog.
2029 This is only used for the icon of the GTK, Mac, Motif and
2030 Win32 GUI. It can be one of these values: "Error",
2031 "Question", "Info", "Warning" or "Generic". Only the first
2032 character is relevant. When {type} is omitted, "Generic" is
2033 used.
2034
2035 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2036 or another valid interrupt key, confirm() returns 0.
2037
2038 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002039 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002040 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002041 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002042 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002043 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002044 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002045 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002046 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002047 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002048< In a GUI dialog, buttons are used. The layout of the buttons
2049 depends on the 'v' flag in 'guioptions'. If it is included,
2050 the buttons are always put vertically. Otherwise, confirm()
2051 tries to put the buttons in one horizontal line. If they
2052 don't fit, a vertical layout is used anyway. For some systems
2053 the horizontal layout is always used.
2054
2055 Can also be used as a |method|in: >
2056 BuildMessage()->confirm("&Yes\n&No")
2057<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002058 Return type: |Number|
2059
2060
2061copy({expr}) *copy()*
2062 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002063 different from using {expr} directly.
2064 When {expr} is a |List| a shallow copy is created. This means
2065 that the original |List| can be changed without changing the
2066 copy, and vice versa. But the items are identical, thus
2067 changing an item changes the contents of both |Lists|.
2068 A |Dictionary| is copied in a similar way as a |List|.
2069 Also see |deepcopy()|.
2070 Can also be used as a |method|: >
2071 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002072<
2073 Return type: any, depending on {expr}
2074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002075
2076cos({expr}) *cos()*
2077 Return the cosine of {expr}, measured in radians, as a |Float|.
2078 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002079 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002080 Examples: >
2081 :echo cos(100)
2082< 0.862319 >
2083 :echo cos(-4.01)
2084< -0.646043
2085
2086 Can also be used as a |method|: >
2087 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002088<
2089 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002090
2091
2092cosh({expr}) *cosh()*
2093 Return the hyperbolic cosine of {expr} as a |Float| in the range
2094 [1, inf].
2095 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002096 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002097 Examples: >
2098 :echo cosh(0.5)
2099< 1.127626 >
2100 :echo cosh(-0.5)
2101< -1.127626
2102
2103 Can also be used as a |method|: >
2104 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002105<
2106 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002107
2108
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002109count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002110 Return the number of times an item with value {expr} appears
2111 in |String|, |List| or |Dictionary| {comp}.
2112
2113 If {start} is given then start with the item with this index.
2114 {start} can only be used with a |List|.
2115
2116 When {ic} is given and it's |TRUE| then case is ignored.
2117
2118 When {comp} is a string then the number of not overlapping
2119 occurrences of {expr} is returned. Zero is returned when
2120 {expr} is an empty string.
2121
2122 Can also be used as a |method|: >
2123 mylist->count(val)
2124<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002125 Return type: |Number|
2126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002127 *cscope_connection()*
2128cscope_connection([{num} , {dbpath} [, {prepend}]])
2129 Checks for the existence of a |cscope| connection. If no
2130 parameters are specified, then the function returns:
2131 0, if cscope was not available (not compiled in), or
2132 if there are no cscope connections;
2133 1, if there is at least one cscope connection.
2134
2135 If parameters are specified, then the value of {num}
2136 determines how existence of a cscope connection is checked:
2137
2138 {num} Description of existence check
2139 ----- ------------------------------
2140 0 Same as no parameters (e.g., "cscope_connection()").
2141 1 Ignore {prepend}, and use partial string matches for
2142 {dbpath}.
2143 2 Ignore {prepend}, and use exact string matches for
2144 {dbpath}.
2145 3 Use {prepend}, use partial string matches for both
2146 {dbpath} and {prepend}.
2147 4 Use {prepend}, use exact string matches for both
2148 {dbpath} and {prepend}.
2149
2150 Note: All string comparisons are case sensitive!
2151
2152 Examples. Suppose we had the following (from ":cs show"): >
2153
2154 # pid database name prepend path
2155 0 27664 cscope.out /usr/local
2156<
2157 Invocation Return Val ~
2158 ---------- ---------- >
2159 cscope_connection() 1
2160 cscope_connection(1, "out") 1
2161 cscope_connection(2, "out") 0
2162 cscope_connection(3, "out") 0
2163 cscope_connection(3, "out", "local") 1
2164 cscope_connection(4, "out") 0
2165 cscope_connection(4, "out", "local") 0
2166 cscope_connection(4, "cscope.out", "/usr/local") 1
2167<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002168 Return type: |Number|
2169
2170
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002171cursor({lnum}, {col} [, {off}]) *cursor()*
2172cursor({list})
2173 Positions the cursor at the column (byte count) {col} in the
2174 line {lnum}. The first column is one.
2175
2176 When there is one argument {list} this is used as a |List|
2177 with two, three or four item:
2178 [{lnum}, {col}]
2179 [{lnum}, {col}, {off}]
2180 [{lnum}, {col}, {off}, {curswant}]
2181 This is like the return value of |getpos()| or |getcurpos()|,
2182 but without the first item.
2183
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002184 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002185 |setcursorcharpos()|.
2186
2187 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002188 {lnum} is used like with |getline()|, except that if {lnum} is
2189 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002190 If {lnum} is greater than the number of lines in the buffer,
2191 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002192 If {col} is greater than the number of bytes in the line,
2193 the cursor will be positioned at the last character in the
2194 line.
2195 If {col} is zero, the cursor will stay in the current column.
2196 If {curswant} is given it is used to set the preferred column
2197 for vertical movement. Otherwise {col} is used.
2198
2199 When 'virtualedit' is used {off} specifies the offset in
2200 screen columns from the start of the character. E.g., a
2201 position within a <Tab> or after the last character.
2202 Returns 0 when the position could be set, -1 otherwise.
2203
2204 Can also be used as a |method|: >
2205 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002206<
2207 Return type: |Number|
2208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002209
2210debugbreak({pid}) *debugbreak()*
2211 Specifically used to interrupt a program being debugged. It
2212 will cause process {pid} to get a SIGTRAP. Behavior for other
2213 processes is undefined. See |terminal-debugger|.
2214 {only available on MS-Windows}
2215
Bram Moolenaar016188f2022-06-06 20:52:59 +01002216 Returns |TRUE| if successfully interrupted the program.
2217 Otherwise returns |FALSE|.
2218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002219 Can also be used as a |method|: >
2220 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002221<
2222 Return type: |Number|
2223
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002224
2225deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2226 Make a copy of {expr}. For Numbers and Strings this isn't
2227 different from using {expr} directly.
2228 When {expr} is a |List| a full copy is created. This means
2229 that the original |List| can be changed without changing the
2230 copy, and vice versa. When an item is a |List| or
2231 |Dictionary|, a copy for it is made, recursively. Thus
2232 changing an item in the copy does not change the contents of
2233 the original |List|.
2234 A |Dictionary| is copied in a similar way as a |List|.
2235
2236 When {noref} is omitted or zero a contained |List| or
2237 |Dictionary| is only copied once. All references point to
2238 this single copy. With {noref} set to 1 every occurrence of a
2239 |List| or |Dictionary| results in a new copy. This also means
2240 that a cyclic reference causes deepcopy() to fail.
2241 *E724*
2242 Nesting is possible up to 100 levels. When there is an item
2243 that refers back to a higher level making a deep copy with
2244 {noref} set to 1 will fail.
2245 Also see |copy()|.
2246
2247 Can also be used as a |method|: >
2248 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002249<
2250 Return type: any, depending on {expr}
2251
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002252
2253delete({fname} [, {flags}]) *delete()*
2254 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002255 name {fname}.
2256
2257 This also works when {fname} is a symbolic link. The symbolic
2258 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002259
2260 When {flags} is "d": Deletes the directory by the name
2261 {fname}. This fails when directory {fname} is not empty.
2262
2263 When {flags} is "rf": Deletes the directory by the name
2264 {fname} and everything in it, recursively. BE CAREFUL!
2265 Note: on MS-Windows it is not possible to delete a directory
2266 that is being used.
2267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002268 The result is a Number, which is 0/false if the delete
2269 operation was successful and -1/true when the deletion failed
2270 or partly failed.
2271
2272 Use |remove()| to delete an item from a |List|.
2273 To delete a line from the buffer use |:delete| or
2274 |deletebufline()|.
2275
2276 Can also be used as a |method|: >
2277 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002278<
2279 Return type: |Number|
2280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002281
2282deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2283 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2284 If {last} is omitted then delete line {first} only.
2285 On success 0 is returned, on failure 1 is returned.
2286
2287 This function works only for loaded buffers. First call
2288 |bufload()| if needed.
2289
2290 For the use of {buf}, see |bufname()| above.
2291
2292 {first} and {last} are used like with |getline()|. Note that
2293 when using |line()| this refers to the current buffer. Use "$"
2294 to refer to the last line in buffer {buf}.
2295
2296 Can also be used as a |method|: >
2297 GetBuffer()->deletebufline(1)
2298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002299 Return type: |Number|
2300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002301 *did_filetype()*
2302did_filetype() Returns |TRUE| when autocommands are being executed and the
2303 FileType event has been triggered at least once. Can be used
2304 to avoid triggering the FileType event again in the scripts
2305 that detect the file type. |FileType|
2306 Returns |FALSE| when `:setf FALLBACK` was used.
2307 When editing another file, the counter is reset, thus this
2308 really checks if the FileType event has been triggered for the
2309 current buffer. This allows an autocommand that starts
2310 editing another buffer to set 'filetype' and load a syntax
2311 file.
2312
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002313 Return type: |Number|
2314
2315
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002316diff({fromlist}, {tolist} [, {options}]) *diff()*
2317 Returns a String or a List containing the diff between the
2318 strings in {fromlist} and {tolist}. Uses the Vim internal
2319 diff library to compute the diff.
2320
2321 *E106*
2322 The optional "output" item in {options} specifies the returned
2323 diff format. The following values are supported:
2324 indices Return a List of the starting and ending
2325 indices and a count of the strings in each
2326 diff hunk.
2327 unified Return the unified diff output as a String.
2328 This is the default.
2329
2330 If the "output" item in {options} is "indices", then a List is
2331 returned. Each List item contains a Dict with the following
2332 items for each diff hunk:
2333 from_idx start index in {fromlist} for this diff hunk.
2334 from_count number of strings in {fromlist} that are
2335 added/removed/modified in this diff hunk.
2336 to_idx start index in {tolist} for this diff hunk.
2337 to_count number of strings in {tolist} that are
2338 added/removed/modified in this diff hunk.
2339
2340 The {options} Dict argument also specifies diff options
2341 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002342 algorithm Dict specifying the diff algorithm to
2343 use. Supported boolean items are
2344 "myers", "minimal", "patience" and
2345 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002346 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002347 iblank ignore changes where lines are all
2348 blank.
2349 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002350 indent-heuristic use the indent heuristic for the
2351 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002352 iwhite ignore changes in amount of white
2353 space.
2354 iwhiteall ignore all white space changes.
2355 iwhiteeol ignore white space changes at end of
2356 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002357 For more information about these options, refer to 'diffopt'.
2358
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002359 To compute the unified diff, all the items in {fromlist} are
2360 concatenated into a string using a newline separator and the
2361 same for {tolist}. The unified diff output uses line numbers.
2362
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002363 Returns an empty List or String if {fromlist} and {tolist} are
2364 identical.
2365
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002366 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002367 :echo diff(['abc'], ['xxx'])
2368 @@ -1 +1 @@
2369 -abc
2370 +xxx
2371
2372 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2373 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2374 :echo diff(readfile('oldfile'), readfile('newfile'))
2375 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002376<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002377 For more examples, refer to |diff-func-examples|
2378
2379 Can also be used as a |method|: >
2380 GetFromList->diff(to_list)
2381<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002382 Return type: |String| or list<dict<number>> or list<any>
2383 depending on {options}
2384
2385
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002386diff_filler({lnum}) *diff_filler()*
2387 Returns the number of filler lines above line {lnum}.
2388 These are the lines that were inserted at this point in
2389 another diff'ed window. These filler lines are shown in the
2390 display but don't exist in the buffer.
2391 {lnum} is used like with |getline()|. Thus "." is the current
2392 line, "'m" mark m, etc.
2393 Returns 0 if the current window is not in diff mode.
2394
2395 Can also be used as a |method|: >
2396 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002397<
2398 Return type: |Number|
2399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002400
2401diff_hlID({lnum}, {col}) *diff_hlID()*
2402 Returns the highlight ID for diff mode at line {lnum} column
2403 {col} (byte index). When the current line does not have a
2404 diff change zero is returned.
2405 {lnum} is used like with |getline()|. Thus "." is the current
2406 line, "'m" mark m, etc.
2407 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2408 line.
2409 The highlight ID can be used with |synIDattr()| to obtain
2410 syntax information about the highlighting.
2411
2412 Can also be used as a |method|: >
2413 GetLnum()->diff_hlID(col)
2414<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002415 Return type: |Number|
2416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002417
2418digraph_get({chars}) *digraph_get()* *E1214*
2419 Return the digraph of {chars}. This should be a string with
2420 exactly two characters. If {chars} are not just two
2421 characters, or the digraph of {chars} does not exist, an error
2422 is given and an empty string is returned.
2423
2424 The character will be converted from Unicode to 'encoding'
2425 when needed. This does require the conversion to be
2426 available, it might fail.
2427
2428 Also see |digraph_getlist()|.
2429
2430 Examples: >
2431 " Get a built-in digraph
2432 :echo digraph_get('00') " Returns '∞'
2433
2434 " Get a user-defined digraph
2435 :call digraph_set('aa', 'あ')
2436 :echo digraph_get('aa') " Returns 'あ'
2437<
2438 Can also be used as a |method|: >
2439 GetChars()->digraph_get()
2440<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002441 Return type: |String|
2442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002443 This function works only when compiled with the |+digraphs|
2444 feature. If this feature is disabled, this function will
2445 display an error message.
2446
2447
2448digraph_getlist([{listall}]) *digraph_getlist()*
2449 Return a list of digraphs. If the {listall} argument is given
2450 and it is TRUE, return all digraphs, including the default
2451 digraphs. Otherwise, return only user-defined digraphs.
2452
2453 The characters will be converted from Unicode to 'encoding'
2454 when needed. This does require the conservation to be
2455 available, it might fail.
2456
2457 Also see |digraph_get()|.
2458
2459 Examples: >
2460 " Get user-defined digraphs
2461 :echo digraph_getlist()
2462
2463 " Get all the digraphs, including default digraphs
2464 :echo digraph_getlist(1)
2465<
2466 Can also be used as a |method|: >
2467 GetNumber()->digraph_getlist()
2468<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002469 Return type: list<list<string>>
2470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002471 This function works only when compiled with the |+digraphs|
2472 feature. If this feature is disabled, this function will
2473 display an error message.
2474
2475
Bram Moolenaara2baa732022-02-04 16:09:54 +00002476digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002477 Add digraph {chars} to the list. {chars} must be a string
2478 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002479 encoded character. *E1215*
2480 Be careful, composing characters are NOT ignored. This
2481 function is similar to |:digraphs| command, but useful to add
2482 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002483
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002484 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002485 this fails an error message is given and v:false is returned.
2486
2487 If you want to define multiple digraphs at once, you can use
2488 |digraph_setlist()|.
2489
2490 Example: >
2491 call digraph_set(' ', 'あ')
2492<
2493 Can be used as a |method|: >
2494 GetString()->digraph_set('あ')
2495<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002496 Return type: |vim9-boolean|
2497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002498 This function works only when compiled with the |+digraphs|
2499 feature. If this feature is disabled, this function will
2500 display an error message.
2501
2502
2503digraph_setlist({digraphlist}) *digraph_setlist()*
2504 Similar to |digraph_set()| but this function can add multiple
2505 digraphs at once. {digraphlist} is a list composed of lists,
2506 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002507 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002508 Example: >
2509 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2510<
2511 It is similar to the following: >
2512 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2513 call digraph_set(chars, digraph)
2514 endfor
2515< Except that the function returns after the first error,
2516 following digraphs will not be added.
2517
2518 Can be used as a |method|: >
2519 GetList()->digraph_setlist()
2520<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002521 Return type: |vim9-boolean|
2522
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002523 This function works only when compiled with the |+digraphs|
2524 feature. If this feature is disabled, this function will
2525 display an error message.
2526
2527
2528echoraw({string}) *echoraw()*
2529 Output {string} as-is, including unprintable characters.
2530 This can be used to output a terminal code. For example, to
2531 disable modifyOtherKeys: >
2532 call echoraw(&t_TE)
2533< and to enable it again: >
2534 call echoraw(&t_TI)
2535< Use with care, you can mess up the terminal this way.
2536
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002537 Return type: |Number|
2538
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002539
2540empty({expr}) *empty()*
2541 Return the Number 1 if {expr} is empty, zero otherwise.
2542 - A |List| or |Dictionary| is empty when it does not have any
2543 items.
2544 - A |String| is empty when its length is zero.
2545 - A |Number| and |Float| are empty when their value is zero.
2546 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2547 - A |Job| is empty when it failed to start.
2548 - A |Channel| is empty when it is closed.
2549 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002550 - An |Object| is empty, when the empty() method in the object
2551 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002552
2553 For a long |List| this is much faster than comparing the
2554 length with zero.
2555
2556 Can also be used as a |method|: >
2557 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002558<
2559 Return type: |Number|
2560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002561
2562environ() *environ()*
2563 Return all of environment variables as dictionary. You can
2564 check if an environment variable exists like this: >
2565 :echo has_key(environ(), 'HOME')
2566< Note that the variable name may be CamelCase; to ignore case
2567 use this: >
2568 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002569<
2570 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002571
Bram Moolenaar416bd912023-07-07 23:19:18 +01002572
2573err_teapot([{expr}]) *err_teapot()*
2574 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002575 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002576 If {expr} is present and it is TRUE error 503 is given,
2577 indicating that coffee is temporarily not available.
2578 If {expr} is present it must be a String.
2579
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002580 Return type: |Number|
2581
Bram Moolenaar416bd912023-07-07 23:19:18 +01002582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002583escape({string}, {chars}) *escape()*
2584 Escape the characters in {chars} that occur in {string} with a
2585 backslash. Example: >
2586 :echo escape('c:\program files\vim', ' \')
2587< results in: >
2588 c:\\program\ files\\vim
2589< Also see |shellescape()| and |fnameescape()|.
2590
2591 Can also be used as a |method|: >
2592 GetText()->escape(' \')
2593<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002594 Return type: |String|
2595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002596 *eval()*
2597eval({string}) Evaluate {string} and return the result. Especially useful to
2598 turn the result of |string()| back into the original value.
2599 This works for Numbers, Floats, Strings, Blobs and composites
2600 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002601 functions. In |Vim9| script, it can be used to obtain |enum|
2602 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002603
2604 Can also be used as a |method|: >
2605 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002606<
2607 Return type: any, depending on {string}
2608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002609
2610eventhandler() *eventhandler()*
2611 Returns 1 when inside an event handler. That is that Vim got
2612 interrupted while waiting for the user to type a character,
2613 e.g., when dropping a file on Vim. This means interactive
2614 commands cannot be used. Otherwise zero is returned.
2615
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002616 Return type: |Number|
2617
2618
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002619executable({expr}) *executable()*
2620 This function checks if an executable with the name {expr}
2621 exists. {expr} must be the name of the program without any
2622 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002624 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002625 searchpath for programs.
2626 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002627 On MS-Windows the ".exe", ".bat", etc. can optionally be
2628 included. Then the extensions in $PATHEXT are tried. Thus if
2629 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2630 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2631 by itself can be used in $PATHEXT to try using the name
2632 without an extension. When 'shell' looks like a Unix shell,
2633 then the name is also tried without adding an extension.
2634 On MS-Windows it only checks if the file exists and is not a
2635 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002636 On MS-Windows an executable in the same directory as the Vim
2637 executable is always found. Since this directory is added to
2638 $PATH it should also work to execute it |win32-PATH|.
2639 *NoDefaultCurrentDirectoryInExePath*
2640 On MS-Windows an executable in Vim's current working directory
2641 is also normally found, but this can be disabled by setting
2642 the $NoDefaultCurrentDirectoryInExePath environment variable.
2643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002644 The result is a Number:
2645 1 exists
2646 0 does not exist
2647 -1 not implemented on this system
2648 |exepath()| can be used to get the full path of an executable.
2649
2650 Can also be used as a |method|: >
2651 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002652<
2653 Return type: |Number|
2654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002655
2656execute({command} [, {silent}]) *execute()*
2657 Execute an Ex command or commands and return the output as a
2658 string.
2659 {command} can be a string or a List. In case of a List the
2660 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002661 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002662 redir => var
2663 {command}
2664 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002665< Except that line continuation in {command} is not recognized.
2666
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002667 The optional {silent} argument can have these values:
2668 "" no `:silent` used
2669 "silent" `:silent` used
2670 "silent!" `:silent!` used
2671 The default is "silent". Note that with "silent!", unlike
2672 `:redir`, error messages are dropped. When using an external
2673 command the screen may be messed up, use `system()` instead.
2674 *E930*
2675 It is not possible to use `:redir` anywhere in {command}.
2676
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002677 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002678 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002679
2680< To execute a command in another window than the current one
2681 use `win_execute()`.
2682
2683 When used recursively the output of the recursive call is not
2684 included in the output of the higher level call.
2685
2686 Can also be used as a |method|: >
2687 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002688<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002689 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002690
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002691
2692exepath({expr}) *exepath()*
2693 If {expr} is an executable and is either an absolute path, a
2694 relative path or found in $PATH, return the full path.
2695 Note that the current directory is used when {expr} starts
2696 with "./", which may be a problem for Vim: >
2697 echo exepath(v:progpath)
2698< If {expr} cannot be found in $PATH or is not executable then
2699 an empty string is returned.
2700
2701 Can also be used as a |method|: >
2702 GetCommand()->exepath()
2703<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002704 Return type: |String|
2705
2706
2707exists({expr}) *exists()*
2708 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002709 zero otherwise.
2710
2711 Note: In a compiled |:def| function the evaluation is done at
2712 runtime. Use `exists_compiled()` to evaluate the expression
2713 at compile time.
2714
2715 For checking for a supported feature use |has()|.
2716 For checking if a file exists use |filereadable()|.
2717
2718 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002719 varname internal variable (see
2720 dict.key |internal-variables|). Also works
2721 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002722 import.Func entries, |List| items, class and
2723 class.Func object methods, imported items, etc.
2724 object.Func Does not work for local variables in a
2725 class.varname compiled `:def` function.
2726 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002727 script, since it can be used as a
2728 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002729 Beware that evaluating an index may
2730 cause an error message for an invalid
2731 expression. E.g.: >
2732 :let l = [1, 2, 3]
2733 :echo exists("l[5]")
2734< 0 >
2735 :echo exists("l[xx]")
2736< E121: Undefined variable: xx
2737 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002738 &option-name Vim option (only checks if it exists,
2739 not if it really works)
2740 +option-name Vim option that works.
2741 $ENVNAME environment variable (could also be
2742 done by comparing with an empty
2743 string)
2744 *funcname built-in function (see |functions|)
2745 or user defined function (see
2746 |user-functions|) that is implemented.
2747 Also works for a variable that is a
2748 Funcref.
2749 ?funcname built-in function that could be
2750 implemented; to be used to check if
2751 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002752 :cmdname Ex command: built-in command, user
2753 command or command modifier |:command|.
2754 Returns:
2755 1 for match with start of a command
2756 2 full match with a command
2757 3 matches several user commands
2758 To check for a supported command
2759 always check the return value to be 2.
2760 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002761 :3match The |:3match| command (but you
2762 probably should not use it, it is
2763 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002764 #event autocommand defined for this event
2765 #event#pattern autocommand defined for this event and
2766 pattern (the pattern is taken
2767 literally and compared to the
2768 autocommand patterns character by
2769 character)
2770 #group autocommand group exists
2771 #group#event autocommand defined for this group and
2772 event.
2773 #group#event#pattern
2774 autocommand defined for this group,
2775 event and pattern.
2776 ##event autocommand for this event is
2777 supported.
2778
2779 Examples: >
2780 exists("&shortname")
2781 exists("$HOSTNAME")
2782 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002783 exists("*s:MyFunc") " only for legacy script
2784 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002785 exists("bufcount")
2786 exists(":Make")
2787 exists("#CursorHold")
2788 exists("#BufReadPre#*.gz")
2789 exists("#filetypeindent")
2790 exists("#filetypeindent#FileType")
2791 exists("#filetypeindent#FileType#*")
2792 exists("##ColorScheme")
2793< There must be no space between the symbol (&/$/*/#) and the
2794 name.
2795 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002796 a few cases this is ignored. That may become stricter in the
2797 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002798 Working example: >
2799 exists(":make")
2800< NOT working example: >
2801 exists(":make install")
2802
2803< Note that the argument must be a string, not the name of the
2804 variable itself. For example: >
2805 exists(bufcount)
2806< This doesn't check for existence of the "bufcount" variable,
2807 but gets the value of "bufcount", and checks if that exists.
2808
2809 Can also be used as a |method|: >
2810 Varname()->exists()
2811<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002812 Return type: |String|
2813
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002814
2815exists_compiled({expr}) *exists_compiled()*
2816 Like `exists()` but evaluated at compile time. This is useful
2817 to skip a block where a function is used that would otherwise
2818 give an error: >
2819 if exists_compiled('*ThatFunction')
2820 ThatFunction('works')
2821 endif
2822< If `exists()` were used then a compilation error would be
2823 given if ThatFunction() is not defined.
2824
2825 {expr} must be a literal string. *E1232*
2826 Can only be used in a |:def| function. *E1233*
2827 This does not work to check for arguments or local variables.
2828
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002829 Return type: |String|
2830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002831
2832exp({expr}) *exp()*
2833 Return the exponential of {expr} as a |Float| in the range
2834 [0, inf].
2835 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002836 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002837 Examples: >
2838 :echo exp(2)
2839< 7.389056 >
2840 :echo exp(-1)
2841< 0.367879
2842
2843 Can also be used as a |method|: >
2844 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002845<
2846 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002847
2848
2849expand({string} [, {nosuf} [, {list}]]) *expand()*
2850 Expand wildcards and the following special keywords in
2851 {string}. 'wildignorecase' applies.
2852
2853 If {list} is given and it is |TRUE|, a List will be returned.
2854 Otherwise the result is a String and when there are several
2855 matches, they are separated by <NL> characters. [Note: in
2856 version 5.0 a space was used, which caused problems when a
2857 file name contains a space]
2858
2859 If the expansion fails, the result is an empty string. A name
2860 for a non-existing file is not included, unless {string} does
2861 not start with '%', '#' or '<', see below.
2862
Christian Brabandtec9c3262024-02-21 20:40:05 +01002863 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002864 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002865
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002866 When {string} starts with '%', '#' or '<', the expansion is
2867 done like for the |cmdline-special| variables with their
2868 associated modifiers. Here is a short overview:
2869
2870 % current file name
2871 # alternate file name
2872 #n alternate file name n
2873 <cfile> file name under the cursor
2874 <afile> autocmd file name
2875 <abuf> autocmd buffer number (as a String!)
2876 <amatch> autocmd matched name
2877 <cexpr> C expression under the cursor
2878 <sfile> sourced script file or function name
2879 <slnum> sourced script line number or function
2880 line number
2881 <sflnum> script file line number, also when in
2882 a function
2883 <SID> "<SNR>123_" where "123" is the
2884 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002885 <script> sourced script file, or script file
2886 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002887 <stack> call stack
2888 <cword> word under the cursor
2889 <cWORD> WORD under the cursor
2890 <client> the {clientid} of the last received
2891 message |server2client()|
2892 Modifiers:
2893 :p expand to full path
2894 :h head (last path component removed)
2895 :t tail (last path component only)
2896 :r root (one extension removed)
2897 :e extension only
2898
2899 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002900 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002901< Note that when expanding a string that starts with '%', '#' or
2902 '<', any following text is ignored. This does NOT work: >
2903 :let doesntwork = expand("%:h.bak")
2904< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002905 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002906< Also note that expanding "<cfile>" and others only returns the
2907 referenced file name without further expansion. If "<cfile>"
2908 is "~/.cshrc", you need to do another expand() to have the
2909 "~/" expanded into the path of the home directory: >
2910 :echo expand(expand("<cfile>"))
2911<
2912 There cannot be white space between the variables and the
2913 following modifier. The |fnamemodify()| function can be used
2914 to modify normal file names.
2915
2916 When using '%' or '#', and the current or alternate file name
2917 is not defined, an empty string is used. Using "%:p" in a
2918 buffer with no name, results in the current directory, with a
2919 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002920 When 'verbose' is set then expanding '%', '#' and <> items
2921 will result in an error message if the argument cannot be
2922 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002923
2924 When {string} does not start with '%', '#' or '<', it is
2925 expanded like a file name is expanded on the command line.
2926 'suffixes' and 'wildignore' are used, unless the optional
2927 {nosuf} argument is given and it is |TRUE|.
2928 Names for non-existing files are included. The "**" item can
2929 be used to search in a directory tree. For example, to find
2930 all "README" files in the current directory and below: >
2931 :echo expand("**/README")
2932<
2933 expand() can also be used to expand variables and environment
2934 variables that are only known in a shell. But this can be
2935 slow, because a shell may be used to do the expansion. See
2936 |expr-env-expand|.
2937 The expanded variable is still handled like a list of file
2938 names. When an environment variable cannot be expanded, it is
2939 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2940 "$FOOBAR".
2941
2942 See |glob()| for finding existing files. See |system()| for
2943 getting the raw output of an external command.
2944
2945 Can also be used as a |method|: >
2946 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002947<
2948 Return type: |String| or list<string> depending on {list}
2949
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002950
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002951expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002952 Expand special items in String {string} like what is done for
2953 an Ex command such as `:edit`. This expands special keywords,
2954 like with |expand()|, and environment variables, anywhere in
2955 {string}. "~user" and "~/path" are only expanded at the
2956 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002957
2958 The following items are supported in the {options} Dict
2959 argument:
2960 errmsg If set to TRUE, error messages are displayed
2961 if an error is encountered during expansion.
2962 By default, error messages are not displayed.
2963
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002964 Returns the expanded string. If an error is encountered
2965 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002966
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002967 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002968 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002969 make /path/runtime/doc/builtin.o
2970 :echo expandcmd('make %<.o', {'errmsg': v:true})
2971<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002972 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002973 GetCommand()->expandcmd()
2974<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002975 Return type: |String| or list<string> depending on {list}
2976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002977extend({expr1}, {expr2} [, {expr3}]) *extend()*
2978 {expr1} and {expr2} must be both |Lists| or both
2979 |Dictionaries|.
2980
2981 If they are |Lists|: Append {expr2} to {expr1}.
2982 If {expr3} is given insert the items of {expr2} before the
2983 item with index {expr3} in {expr1}. When {expr3} is zero
2984 insert before the first item. When {expr3} is equal to
2985 len({expr1}) then {expr2} is appended.
2986 Examples: >
2987 :echo sort(extend(mylist, [7, 5]))
2988 :call extend(mylist, [2, 3], 1)
2989< When {expr1} is the same List as {expr2} then the number of
2990 items copied is equal to the original length of the List.
2991 E.g., when {expr3} is 1 you get N new copies of the first item
2992 (where N is the original length of the List).
2993 Use |add()| to concatenate one item to a list. To concatenate
2994 two lists into a new list use the + operator: >
2995 :let newlist = [1, 2, 3] + [4, 5]
2996<
2997 If they are |Dictionaries|:
2998 Add all entries from {expr2} to {expr1}.
2999 If a key exists in both {expr1} and {expr2} then {expr3} is
3000 used to decide what to do:
3001 {expr3} = "keep": keep the value of {expr1}
3002 {expr3} = "force": use the value of {expr2}
3003 {expr3} = "error": give an error message *E737*
3004 When {expr3} is omitted then "force" is assumed.
3005
3006 {expr1} is changed when {expr2} is not empty. If necessary
3007 make a copy of {expr1} first.
3008 {expr2} remains unchanged.
3009 When {expr1} is locked and {expr2} is not empty the operation
3010 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003011 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003012
3013 Can also be used as a |method|: >
3014 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003015<
3016 Return type: list<{type}> or dict<{type}> depending on {expr1}
3017 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003018
3019
3020extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3021 Like |extend()| but instead of adding items to {expr1} a new
3022 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003023 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003024
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003025 Return type: list<{type}> or dict<{type}> depending on {expr1}
3026 and {expr2}, in case of error: |Number|
3027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003028
3029feedkeys({string} [, {mode}]) *feedkeys()*
3030 Characters in {string} are queued for processing as if they
3031 come from a mapping or were typed by the user.
3032
3033 By default the string is added to the end of the typeahead
3034 buffer, thus if a mapping is still being executed the
3035 characters come after them. Use the 'i' flag to insert before
3036 other characters, they will be executed next, before any
3037 characters from a mapping.
3038
3039 The function does not wait for processing of keys contained in
3040 {string}.
3041
3042 To include special keys into {string}, use double-quotes
3043 and "\..." notation |expr-quote|. For example,
3044 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3045 feedkeys('\<CR>') pushes 5 characters.
3046 A special code that might be useful is <Ignore>, it exits the
3047 wait for a character without doing anything. *<Ignore>*
3048
3049 {mode} is a String, which can contain these character flags:
3050 'm' Remap keys. This is default. If {mode} is absent,
3051 keys are remapped.
3052 'n' Do not remap keys.
3053 't' Handle keys as if typed; otherwise they are handled as
3054 if coming from a mapping. This matters for undo,
3055 opening folds, etc.
3056 'L' Lowlevel input. Only works for Unix or when using the
3057 GUI. Keys are used as if they were coming from the
3058 terminal. Other flags are not used. *E980*
3059 When a CTRL-C interrupts and 't' is included it sets
3060 the internal "got_int" flag.
3061 'i' Insert the string instead of appending (see above).
3062 'x' Execute commands until typeahead is empty. This is
3063 similar to using ":normal!". You can call feedkeys()
3064 several times without 'x' and then one time with 'x'
3065 (possibly with an empty {string}) to execute all the
3066 typeahead. Note that when Vim ends in Insert mode it
3067 will behave as if <Esc> is typed, to avoid getting
3068 stuck, waiting for a character to be typed before the
3069 script continues.
3070 Note that if you manage to call feedkeys() while
3071 executing commands, thus calling it recursively, then
3072 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003073 'c' Remove any script context when executing, so that
3074 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003075 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003076 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003077 '!' When used with 'x' will not end Insert mode. Can be
3078 used in a test when a timer is set to exit Insert mode
3079 a little later. Useful for testing CursorHoldI.
3080
3081 Return value is always 0.
3082
3083 Can also be used as a |method|: >
3084 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003085<
3086 Return type: |String| or list<string> depending on {list}
3087
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003088
Shougo Matsushita60c87432024-06-03 22:59:27 +02003089filecopy({from}, {to}) *filecopy()*
3090 Copy the file pointed to by the name {from} to {to}. The
3091 result is a Number, which is |TRUE| if the file was copied
3092 successfully, and |FALSE| when it failed.
3093 If a file with name {to} already exists, it will fail.
3094 Note that it does not handle directories (yet).
3095
3096 This function is not available in the |sandbox|.
3097
3098 Can also be used as a |method|: >
3099 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003100<
3101 Return type: |Number|
3102
Shougo Matsushita60c87432024-06-03 22:59:27 +02003103
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003104filereadable({file}) *filereadable()*
3105 The result is a Number, which is |TRUE| when a file with the
3106 name {file} exists, and can be read. If {file} doesn't exist,
3107 or is a directory, the result is |FALSE|. {file} is any
3108 expression, which is used as a String.
3109 If you don't care about the file being readable you can use
3110 |glob()|.
3111 {file} is used as-is, you may want to expand wildcards first: >
3112 echo filereadable('~/.vimrc')
3113 0
3114 echo filereadable(expand('~/.vimrc'))
3115 1
3116
3117< Can also be used as a |method|: >
3118 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003119<
3120 Return type: |Number|
3121
3122 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003123 Obsolete name: file_readable().
3124
3125
3126filewritable({file}) *filewritable()*
3127 The result is a Number, which is 1 when a file with the
3128 name {file} exists, and can be written. If {file} doesn't
3129 exist, or is not writable, the result is 0. If {file} is a
3130 directory, and we can write to it, the result is 2.
3131
3132 Can also be used as a |method|: >
3133 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003134<
3135 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003136
3137
3138filter({expr1}, {expr2}) *filter()*
3139 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3140 For each item in {expr1} evaluate {expr2} and when the result
3141 is zero or false remove the item from the |List| or
3142 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003143 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003144
3145 {expr2} must be a |string| or |Funcref|.
3146
3147 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3148 of the current item. For a |Dictionary| |v:key| has the key
3149 of the current item and for a |List| |v:key| has the index of
3150 the current item. For a |Blob| |v:key| has the index of the
3151 current byte. For a |String| |v:key| has the index of the
3152 current character.
3153 Examples: >
3154 call filter(mylist, 'v:val !~ "OLD"')
3155< Removes the items where "OLD" appears. >
3156 call filter(mydict, 'v:key >= 8')
3157< Removes the items with a key below 8. >
3158 call filter(var, 0)
3159< Removes all the items, thus clears the |List| or |Dictionary|.
3160
3161 Note that {expr2} is the result of expression and is then
3162 used as an expression again. Often it is good to use a
3163 |literal-string| to avoid having to double backslashes.
3164
3165 If {expr2} is a |Funcref| it must take two arguments:
3166 1. the key or the index of the current item.
3167 2. the value of the current item.
3168 The function must return |TRUE| if the item should be kept.
3169 Example that keeps the odd items of a list: >
3170 func Odd(idx, val)
3171 return a:idx % 2 == 1
3172 endfunc
3173 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003174< It is shorter when using a |lambda|. In |Vim9| syntax: >
3175 call filter(myList, (idx, val) => idx * val <= 42)
3176< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003177 call filter(myList, {idx, val -> idx * val <= 42})
3178< If you do not use "val" you can leave it out: >
3179 call filter(myList, {idx -> idx % 2 == 1})
3180<
3181 In |Vim9| script the result must be true, false, zero or one.
3182 Other values will result in a type error.
3183
3184 For a |List| and a |Dictionary| the operation is done
3185 in-place. If you want it to remain unmodified make a copy
3186 first: >
3187 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3188
3189< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003190 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003191 When an error is encountered while evaluating {expr2} no
3192 further items in {expr1} are processed.
3193 When {expr2} is a Funcref errors inside a function are ignored,
3194 unless it was defined with the "abort" flag.
3195
3196 Can also be used as a |method|: >
3197 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003198<
3199 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3200 depending on {expr1}
3201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003202
3203finddir({name} [, {path} [, {count}]]) *finddir()*
3204 Find directory {name} in {path}. Supports both downwards and
3205 upwards recursive directory searches. See |file-searching|
3206 for the syntax of {path}.
3207
3208 Returns the path of the first found match. When the found
3209 directory is below the current directory a relative path is
3210 returned. Otherwise a full path is returned.
3211 If {path} is omitted or empty then 'path' is used.
3212
3213 If the optional {count} is given, find {count}'s occurrence of
3214 {name} in {path} instead of the first one.
3215 When {count} is negative return all the matches in a |List|.
3216
Bram Moolenaar016188f2022-06-06 20:52:59 +01003217 Returns an empty string if the directory is not found.
3218
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003219 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003220
3221 Can also be used as a |method|: >
3222 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003223<
3224 Return type: |String|
3225
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003226
3227findfile({name} [, {path} [, {count}]]) *findfile()*
3228 Just like |finddir()|, but find a file instead of a directory.
3229 Uses 'suffixesadd'.
3230 Example: >
3231 :echo findfile("tags.vim", ".;")
3232< Searches from the directory of the current file upwards until
3233 it finds the file "tags.vim".
3234
3235 Can also be used as a |method|: >
3236 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003237<
3238 Return type: |String|
3239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003240
3241flatten({list} [, {maxdepth}]) *flatten()*
3242 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3243 the result is a |List| without nesting, as if {maxdepth} is
3244 a very large number.
3245 The {list} is changed in place, use |flattennew()| if you do
3246 not want that.
3247 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003248 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003249 *E900*
3250 {maxdepth} means how deep in nested lists changes are made.
3251 {list} is not modified when {maxdepth} is 0.
3252 {maxdepth} must be positive number.
3253
3254 If there is an error the number zero is returned.
3255
3256 Example: >
3257 :echo flatten([1, [2, [3, 4]], 5])
3258< [1, 2, 3, 4, 5] >
3259 :echo flatten([1, [2, [3, 4]], 5], 1)
3260< [1, 2, [3, 4], 5]
3261
3262 Can also be used as a |method|: >
3263 mylist->flatten()
3264<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003265 Return type: list<{type}>
3266
3267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003268flattennew({list} [, {maxdepth}]) *flattennew()*
3269 Like |flatten()| but first make a copy of {list}.
3270
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003271 Return type: list<{type}>
3272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003273
3274float2nr({expr}) *float2nr()*
3275 Convert {expr} to a Number by omitting the part after the
3276 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003277 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003278 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003279 When the value of {expr} is out of range for a |Number| the
3280 result is truncated to 0x7fffffff or -0x7fffffff (or when
3281 64-bit Number support is enabled, 0x7fffffffffffffff or
3282 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3283 64-bit Number support is enabled, -0x8000000000000000).
3284 Examples: >
3285 echo float2nr(3.95)
3286< 3 >
3287 echo float2nr(-23.45)
3288< -23 >
3289 echo float2nr(1.0e100)
3290< 2147483647 (or 9223372036854775807) >
3291 echo float2nr(-1.0e150)
3292< -2147483647 (or -9223372036854775807) >
3293 echo float2nr(1.0e-100)
3294< 0
3295
3296 Can also be used as a |method|: >
3297 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003298<
3299 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003300
3301
3302floor({expr}) *floor()*
3303 Return the largest integral value less than or equal to
3304 {expr} as a |Float| (round down).
3305 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003306 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003307 Examples: >
3308 echo floor(1.856)
3309< 1.0 >
3310 echo floor(-5.456)
3311< -6.0 >
3312 echo floor(4.0)
3313< 4.0
3314
3315 Can also be used as a |method|: >
3316 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003317<
3318 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003319
3320
3321fmod({expr1}, {expr2}) *fmod()*
3322 Return the remainder of {expr1} / {expr2}, even if the
3323 division is not representable. Returns {expr1} - i * {expr2}
3324 for some integer i such that if {expr2} is non-zero, the
3325 result has the same sign as {expr1} and magnitude less than
3326 the magnitude of {expr2}. If {expr2} is zero, the value
3327 returned is zero. The value returned is a |Float|.
3328 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003329 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3330 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003331 Examples: >
3332 :echo fmod(12.33, 1.22)
3333< 0.13 >
3334 :echo fmod(-12.33, 1.22)
3335< -0.13
3336
3337 Can also be used as a |method|: >
3338 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003339<
3340 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003341
3342
3343fnameescape({string}) *fnameescape()*
3344 Escape {string} for use as file name command argument. All
3345 characters that have a special meaning, such as '%' and '|'
3346 are escaped with a backslash.
3347 For most systems the characters escaped are
3348 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3349 appears in a filename, it depends on the value of 'isfname'.
3350 A leading '+' and '>' is also escaped (special after |:edit|
3351 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003352 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003353 Example: >
3354 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003355 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003356< results in executing: >
3357 edit \+some\ str\%nge\|name
3358<
3359 Can also be used as a |method|: >
3360 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003361<
3362 Return type: |String|
3363
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003364
3365fnamemodify({fname}, {mods}) *fnamemodify()*
3366 Modify file name {fname} according to {mods}. {mods} is a
3367 string of characters like it is used for file names on the
3368 command line. See |filename-modifiers|.
3369 Example: >
3370 :echo fnamemodify("main.c", ":p:h")
3371< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003372 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003373< If {mods} is empty or an unsupported modifier is used then
3374 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003375 When {fname} is empty then with {mods} ":h" returns ".", so
3376 that `:cd` can be used with it. This is different from
3377 expand('%:h') without a buffer name, which returns an empty
3378 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003379 Note: Environment variables don't work in {fname}, use
3380 |expand()| first then.
3381
3382 Can also be used as a |method|: >
3383 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003384<
3385 Return type: |String|
3386
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003387
3388foldclosed({lnum}) *foldclosed()*
3389 The result is a Number. If the line {lnum} is in a closed
3390 fold, the result is the number of the first line in that fold.
3391 If the line {lnum} is not in a closed fold, -1 is returned.
3392 {lnum} is used like with |getline()|. Thus "." is the current
3393 line, "'m" mark m, etc.
3394
3395 Can also be used as a |method|: >
3396 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003397<
3398 Return type: |Number|
3399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003400
3401foldclosedend({lnum}) *foldclosedend()*
3402 The result is a Number. If the line {lnum} is in a closed
3403 fold, the result is the number of the last line in that fold.
3404 If the line {lnum} is not in a closed fold, -1 is returned.
3405 {lnum} is used like with |getline()|. Thus "." is the current
3406 line, "'m" mark m, etc.
3407
3408 Can also be used as a |method|: >
3409 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003410<
3411 Return type: |Number|
3412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003413
3414foldlevel({lnum}) *foldlevel()*
3415 The result is a Number, which is the foldlevel of line {lnum}
3416 in the current buffer. For nested folds the deepest level is
3417 returned. If there is no fold at line {lnum}, zero is
3418 returned. It doesn't matter if the folds are open or closed.
3419 When used while updating folds (from 'foldexpr') -1 is
3420 returned for lines where folds are still to be updated and the
3421 foldlevel is unknown. As a special case the level of the
3422 previous line is usually available.
3423 {lnum} is used like with |getline()|. Thus "." is the current
3424 line, "'m" mark m, etc.
3425
3426 Can also be used as a |method|: >
3427 GetLnum()->foldlevel()
3428<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003429 Return type: |Number|
3430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003431 *foldtext()*
3432foldtext() Returns a String, to be displayed for a closed fold. This is
3433 the default function used for the 'foldtext' option and should
3434 only be called from evaluating 'foldtext'. It uses the
3435 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3436 The returned string looks like this: >
3437 +-- 45 lines: abcdef
3438< The number of leading dashes depends on the foldlevel. The
3439 "45" is the number of lines in the fold. "abcdef" is the text
3440 in the first non-blank line of the fold. Leading white space,
3441 "//" or "/*" and the text from the 'foldmarker' and
3442 'commentstring' options is removed.
3443 When used to draw the actual foldtext, the rest of the line
3444 will be filled with the fold char from the 'fillchars'
3445 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003446 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003447
3448 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003449 {not available when compiled without the |+folding| feature}
3450
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003452foldtextresult({lnum}) *foldtextresult()*
3453 Returns the text that is displayed for the closed fold at line
3454 {lnum}. Evaluates 'foldtext' in the appropriate context.
3455 When there is no closed fold at {lnum} an empty string is
3456 returned.
3457 {lnum} is used like with |getline()|. Thus "." is the current
3458 line, "'m" mark m, etc.
3459 Useful when exporting folded text, e.g., to HTML.
3460 {not available when compiled without the |+folding| feature}
3461
3462
3463 Can also be used as a |method|: >
3464 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003465<
3466 Return type: |String|
3467
Ernie Raele79e2072024-01-13 11:47:33 +01003468
3469foreach({expr1}, {expr2}) *foreach()*
3470 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3471 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003472 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003473 See |map()| and |filter()| to modify {expr1}.
3474
3475 {expr2} must be a |string| or |Funcref|.
3476
3477 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3478 of the current item. For a |Dictionary| |v:key| has the key
3479 of the current item and for a |List| |v:key| has the index of
3480 the current item. For a |Blob| |v:key| has the index of the
3481 current byte. For a |String| |v:key| has the index of the
3482 current character.
3483 Examples: >
3484 call foreach(mylist, 'used[v:val] = true')
3485< This records the items that are in the {expr1} list.
3486
3487 Note that {expr2} is the result of expression and is then used
3488 as a command. Often it is good to use a |literal-string| to
3489 avoid having to double backslashes.
3490
3491 If {expr2} is a |Funcref| it must take two arguments:
3492 1. the key or the index of the current item.
3493 2. the value of the current item.
3494 With a legacy script lambda you don't get an error if it only
3495 accepts one argument, but with a Vim9 lambda you get "E1106:
3496 One argument too many", the number of arguments must match.
3497 If the function returns a value, it is ignored.
3498
3499 Returns {expr1} in all cases.
3500 When an error is encountered while executing {expr2} no
3501 further items in {expr1} are processed.
3502 When {expr2} is a Funcref errors inside a function are ignored,
3503 unless it was defined with the "abort" flag.
3504
3505 Can also be used as a |method|: >
3506 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003507<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003508 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3509 depending on {expr1}
3510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003511 *foreground()*
3512foreground() Move the Vim window to the foreground. Useful when sent from
3513 a client to a Vim server. |remote_send()|
3514 On Win32 systems this might not work, the OS does not always
3515 allow a window to bring itself to the foreground. Use
3516 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003517
3518 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003519 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003520 Win32 console version}
3521
Bram Moolenaaraa534142022-09-15 21:46:02 +01003522fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003523 Get the full command name from a short abbreviated command
3524 name; see |20.2| for details on command abbreviations.
3525
3526 The string argument {name} may start with a `:` and can
3527 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003528 Returns an empty string if a command doesn't exist, if it's
3529 ambiguous (for user-defined commands) or cannot be shortened
3530 this way. |vim9-no-shorten|
3531
3532 Without the {vim9} argument uses the current script version.
3533 If {vim9} is present and FALSE then legacy script rules are
3534 used. When {vim9} is present and TRUE then Vim9 rules are
3535 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003536
3537 For example `fullcommand('s')`, `fullcommand('sub')`,
3538 `fullcommand(':%substitute')` all return "substitute".
3539
3540 Can also be used as a |method|: >
3541 GetName()->fullcommand()
3542<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003543 Return type: |String|
3544
3545
3546funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003547 Just like |function()|, but the returned Funcref will lookup
3548 the function by reference, not by name. This matters when the
3549 function {name} is redefined later.
3550
3551 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003552 It only works for an autoloaded function if it has already
3553 been loaded (to avoid mistakenly loading the autoload script
3554 when only intending to use the function name, use |function()|
3555 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003556 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003557
3558 Can also be used as a |method|: >
3559 GetFuncname()->funcref([arg])
3560<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003561 Return type: func(...): any or |Number| on error
3562
Dominique Pellee764d1b2023-03-12 21:20:59 +00003563 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003564function({name} [, {arglist}] [, {dict}])
3565 Return a |Funcref| variable that refers to function {name}.
3566 {name} can be the name of a user defined function or an
3567 internal function.
3568
3569 {name} can also be a Funcref or a partial. When it is a
3570 partial the dict stored in it will be used and the {dict}
3571 argument is not allowed. E.g.: >
3572 let FuncWithArg = function(dict.Func, [arg])
3573 let Broken = function(dict.Func, [arg], dict)
3574<
3575 When using the Funcref the function will be found by {name},
3576 also when it was redefined later. Use |funcref()| to keep the
3577 same function.
3578
3579 When {arglist} or {dict} is present this creates a partial.
3580 That means the argument list and/or the dictionary is stored in
3581 the Funcref and will be used when the Funcref is called.
3582
3583 The arguments are passed to the function in front of other
3584 arguments, but after any argument from |method|. Example: >
3585 func Callback(arg1, arg2, name)
3586 ...
3587 let Partial = function('Callback', ['one', 'two'])
3588 ...
3589 call Partial('name')
3590< Invokes the function as with: >
3591 call Callback('one', 'two', 'name')
3592
3593< With a |method|: >
3594 func Callback(one, two, three)
3595 ...
3596 let Partial = function('Callback', ['two'])
3597 ...
3598 eval 'one'->Partial('three')
3599< Invokes the function as with: >
3600 call Callback('one', 'two', 'three')
3601
3602< The function() call can be nested to add more arguments to the
3603 Funcref. The extra arguments are appended to the list of
3604 arguments. Example: >
3605 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003606 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 let Func = function('Callback', ['one'])
3608 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003609 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003610 call Func2('name')
3611< Invokes the function as with: >
3612 call Callback('one', 'two', 'name')
3613
3614< The Dictionary is only useful when calling a "dict" function.
3615 In that case the {dict} is passed in as "self". Example: >
3616 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003617 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003618 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003619 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003620 let context = {"name": "example"}
3621 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003622 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003623 call Func() " will echo: called for example
3624< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003625 arguments, these two are equivalent, if Callback() is defined
3626 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003627 let Func = function('Callback', context)
3628 let Func = context.Callback
3629
3630< The argument list and the Dictionary can be combined: >
3631 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003632 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003633 let context = {"name": "example"}
3634 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003635 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003636 call Func(500)
3637< Invokes the function as with: >
3638 call context.Callback('one', 500)
3639<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003640 Returns 0 on error.
3641
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003642 Can also be used as a |method|: >
3643 GetFuncname()->function([arg])
3644
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003645<
3646 Return type: func(...): any or |Number| on error
3647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003648
3649garbagecollect([{atexit}]) *garbagecollect()*
3650 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3651 that have circular references.
3652
3653 There is hardly ever a need to invoke this function, as it is
3654 automatically done when Vim runs out of memory or is waiting
3655 for the user to press a key after 'updatetime'. Items without
3656 circular references are always freed when they become unused.
3657 This is useful if you have deleted a very big |List| and/or
3658 |Dictionary| with circular references in a script that runs
3659 for a long time.
3660
3661 When the optional {atexit} argument is one, garbage
3662 collection will also be done when exiting Vim, if it wasn't
3663 done before. This is useful when checking for memory leaks.
3664
3665 The garbage collection is not done immediately but only when
3666 it's safe to perform. This is when waiting for the user to
3667 type a character. To force garbage collection immediately use
3668 |test_garbagecollect_now()|.
3669
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003670 Return type: |String|
3671
3672
LemonBoy48b7d052024-07-09 18:24:59 +02003673get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003674 Get item {idx} from |List| {list}. When this item is not
3675 available return {default}. Return zero when {default} is
3676 omitted.
3677 Preferably used as a |method|: >
3678 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003679<
3680 Return type: any, depending on {list}
3681
LemonBoy48b7d052024-07-09 18:24:59 +02003682get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003683 Get byte {idx} from |Blob| {blob}. When this byte is not
3684 available return {default}. Return -1 when {default} is
3685 omitted.
3686 Preferably used as a |method|: >
3687 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003688<
3689 Return type: |Number|
3690
LemonBoy48b7d052024-07-09 18:24:59 +02003691get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003692 Get item with key {key} from |Dictionary| {dict}. When this
3693 item is not available return {default}. Return zero when
3694 {default} is omitted. Useful example: >
3695 let val = get(g:, 'var_name', 'default')
3696< This gets the value of g:var_name if it exists, and uses
3697 'default' when it does not exist.
3698 Preferably used as a |method|: >
3699 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003700<
h-east84ac2122024-06-17 18:12:30 +02003701 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003702
LemonBoy48b7d052024-07-09 18:24:59 +02003703get({func}, {what}) *get()-func*
3704 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003705 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003706 "name" The function name
3707 "func" The function
3708 "dict" The dictionary
3709 "args" The list with arguments
3710 "arity" A dictionary with information about the number of
3711 arguments accepted by the function (minus the
3712 {arglist}) with the following fields:
3713 required the number of positional arguments
3714 optional the number of optional arguments,
3715 in addition to the required ones
3716 varargs |TRUE| if the function accepts a
3717 variable number of arguments |...|
3718
3719 Note: There is no error, if the {arglist} of
3720 the Funcref contains more arguments than the
3721 Funcref expects, it's not validated.
3722
Bram Moolenaar016188f2022-06-06 20:52:59 +01003723 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003725 Preferably used as a |method|: >
3726 myfunc->get(what)
3727<
LemonBoy48b7d052024-07-09 18:24:59 +02003728 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003730 *getbufinfo()*
3731getbufinfo([{buf}])
3732getbufinfo([{dict}])
3733 Get information about buffers as a List of Dictionaries.
3734
3735 Without an argument information about all the buffers is
3736 returned.
3737
3738 When the argument is a |Dictionary| only the buffers matching
3739 the specified criteria are returned. The following keys can
3740 be specified in {dict}:
3741 buflisted include only listed buffers.
3742 bufloaded include only loaded buffers.
3743 bufmodified include only modified buffers.
3744
3745 Otherwise, {buf} specifies a particular buffer to return
3746 information for. For the use of {buf}, see |bufname()|
3747 above. If the buffer is found the returned List has one item.
3748 Otherwise the result is an empty list.
3749
3750 Each returned List item is a dictionary with the following
3751 entries:
3752 bufnr Buffer number.
3753 changed TRUE if the buffer is modified.
3754 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003755 command TRUE if the buffer belongs to the
3756 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003757 hidden TRUE if the buffer is hidden.
3758 lastused Timestamp in seconds, like
3759 |localtime()|, when the buffer was
3760 last used.
3761 {only with the |+viminfo| feature}
3762 listed TRUE if the buffer is listed.
3763 lnum Line number used for the buffer when
3764 opened in the current window.
3765 Only valid if the buffer has been
3766 displayed in the window in the past.
3767 If you want the line number of the
3768 last known cursor position in a given
3769 window, use |line()|: >
3770 :echo line('.', {winid})
3771<
3772 linecount Number of lines in the buffer (only
3773 valid when loaded)
3774 loaded TRUE if the buffer is loaded.
3775 name Full path to the file in the buffer.
3776 signs List of signs placed in the buffer.
3777 Each list item is a dictionary with
3778 the following fields:
3779 id sign identifier
3780 lnum line number
3781 name sign name
3782 variables A reference to the dictionary with
3783 buffer-local variables.
3784 windows List of |window-ID|s that display this
3785 buffer
3786 popups List of popup |window-ID|s that
3787 display this buffer
3788
3789 Examples: >
3790 for buf in getbufinfo()
3791 echo buf.name
3792 endfor
3793 for buf in getbufinfo({'buflisted':1})
3794 if buf.changed
3795 ....
3796 endif
3797 endfor
3798<
3799 To get buffer-local options use: >
3800 getbufvar({bufnr}, '&option_name')
3801<
3802 Can also be used as a |method|: >
3803 GetBufnr()->getbufinfo()
3804<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003805 Return type: list<dict<any>>
3806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003807
3808 *getbufline()*
3809getbufline({buf}, {lnum} [, {end}])
3810 Return a |List| with the lines starting from {lnum} to {end}
3811 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003812 |List| with only the line {lnum} is returned. See
3813 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003814
3815 For the use of {buf}, see |bufname()| above.
3816
3817 For {lnum} and {end} "$" can be used for the last line of the
3818 buffer. Otherwise a number must be used.
3819
3820 When {lnum} is smaller than 1 or bigger than the number of
3821 lines in the buffer, an empty |List| is returned.
3822
3823 When {end} is greater than the number of lines in the buffer,
3824 it is treated as {end} is set to the number of lines in the
3825 buffer. When {end} is before {lnum} an empty |List| is
3826 returned.
3827
3828 This function works only for loaded buffers. For unloaded and
3829 non-existing buffers, an empty |List| is returned.
3830
3831 Example: >
3832 :let lines = getbufline(bufnr("myfile"), 1, "$")
3833
3834< Can also be used as a |method|: >
3835 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003836<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003837 Return type: list<string>
3838
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003839 *getbufoneline()*
3840getbufoneline({buf}, {lnum})
3841 Just like `getbufline()` but only get one line and return it
3842 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003843
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003844 Return type: |String|
3845
3846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003847getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3848 The result is the value of option or local buffer variable
3849 {varname} in buffer {buf}. Note that the name without "b:"
3850 must be used.
3851 The {varname} argument is a string.
3852 When {varname} is empty returns a |Dictionary| with all the
3853 buffer-local variables.
3854 When {varname} is equal to "&" returns a |Dictionary| with all
3855 the buffer-local options.
3856 Otherwise, when {varname} starts with "&" returns the value of
3857 a buffer-local option.
3858 This also works for a global or buffer-local option, but it
3859 doesn't work for a global variable, window-local variable or
3860 window-local option.
3861 For the use of {buf}, see |bufname()| above.
3862 When the buffer or variable doesn't exist {def} or an empty
3863 string is returned, there is no error message.
3864 Examples: >
3865 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003866 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003867
3868< Can also be used as a |method|: >
3869 GetBufnr()->getbufvar(varname)
3870<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003871 Return type: any, depending on {varname}
3872
3873
mikoto20001083cae2024-11-11 21:24:14 +01003874getcellpixels() *getcellpixels()*
3875 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003876 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003877
3878 Only works on Unix (terminal and gVim) and Windows (gVim only).
3879 Returns [] on other systems or on failure.
3880 Note that there could be variations across different terminals.
3881 On macOS, system Terminal.app returns sizes in points (before
3882 Retina scaling), whereas third-party terminals return raw pixel
3883 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003884
mikoto2000de094dc2024-11-14 22:13:48 +01003885 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003886
3887
Kota Kato66bb9ae2023-01-17 18:31:56 +00003888getcellwidths() *getcellwidths()*
3889 Returns a |List| of cell widths of character ranges overridden
3890 by |setcellwidths()|. The format is equal to the argument of
3891 |setcellwidths()|. If no character ranges have their cell
3892 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003893
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003894 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003895
3896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003897getchangelist([{buf}]) *getchangelist()*
3898 Returns the |changelist| for the buffer {buf}. For the use
3899 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3900 exist, an empty list is returned.
3901
3902 The returned list contains two entries: a list with the change
3903 locations and the current position in the list. Each
3904 entry in the change list is a dictionary with the following
3905 entries:
3906 col column number
3907 coladd column offset for 'virtualedit'
3908 lnum line number
3909 If buffer {buf} is the current buffer, then the current
3910 position refers to the position in the list. For other
3911 buffers, it is set to the length of the list.
3912
3913 Can also be used as a |method|: >
3914 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003915<
3916 Return type: list<any>
3917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003918
Doug Kearns9cd9e752024-04-07 17:42:17 +02003919getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003920 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003921 If {expr} is omitted, wait until a character is available.
3922 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003923 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003924 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003925 not consumed. Return zero if no character available.
3926 If you prefer always getting a string use |getcharstr()|.
3927
Doug Kearns9cd9e752024-04-07 17:42:17 +02003928 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003929 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003930 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003931 Otherwise a String is returned with the encoded character.
3932 For a special key it's a String with a sequence of bytes
3933 starting with 0x80 (decimal: 128). This is the same value as
3934 the String "\<Key>", e.g., "\<Left>". The returned value is
3935 also a String when a modifier (shift, control, alt) was used
3936 that is not included in the character.
3937
Doug Kearns9cd9e752024-04-07 17:42:17 +02003938 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003939 while Vim waits to see if this is the start of an escape
3940 sequence.
3941
Doug Kearns9cd9e752024-04-07 17:42:17 +02003942 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003943 one-byte character it is the character itself as a number.
3944 Use nr2char() to convert it to a String.
3945
3946 Use getcharmod() to obtain any additional modifiers.
3947
3948 When the user clicks a mouse button, the mouse event will be
3949 returned. The position can then be found in |v:mouse_col|,
3950 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3951 |getmousepos()| can also be used. Mouse move events will be
3952 ignored.
3953 This example positions the mouse as it would normally happen: >
3954 let c = getchar()
3955 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003956 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003957 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003958 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003959 endif
3960<
3961 When using bracketed paste only the first character is
3962 returned, the rest of the pasted text is dropped.
3963 |xterm-bracketed-paste|.
3964
3965 There is no prompt, you will somehow have to make clear to the
3966 user that a character has to be typed. The screen is not
3967 redrawn, e.g. when resizing the window. When using a popup
3968 window it should work better with a |popup-filter|.
3969
3970 There is no mapping for the character.
3971 Key codes are replaced, thus when the user presses the <Del>
3972 key you get the code for the <Del> key, not the raw character
3973 sequence. Examples: >
3974 getchar() == "\<Del>"
3975 getchar() == "\<S-Left>"
3976< This example redefines "f" to ignore case: >
3977 :nmap f :call FindChar()<CR>
3978 :function FindChar()
3979 : let c = nr2char(getchar())
3980 : while col('.') < col('$') - 1
3981 : normal l
3982 : if getline('.')[col('.') - 1] ==? c
3983 : break
3984 : endif
3985 : endwhile
3986 :endfunction
3987<
3988 You may also receive synthetic characters, such as
3989 |<CursorHold>|. Often you will want to ignore this and get
3990 another character: >
3991 :function GetKey()
3992 : let c = getchar()
3993 : while c == "\<CursorHold>"
3994 : let c = getchar()
3995 : endwhile
3996 : return c
3997 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003998<
3999 Return type: |Number| or |String|
4000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004001
4002getcharmod() *getcharmod()*
4003 The result is a Number which is the state of the modifiers for
4004 the last obtained character with getchar() or in another way.
4005 These values are added together:
4006 2 shift
4007 4 control
4008 8 alt (meta)
4009 16 meta (when it's different from ALT)
4010 32 mouse double click
4011 64 mouse triple click
4012 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004013 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004014 Only the modifiers that have not been included in the
4015 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004016 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004017
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004018 Return type: |Number|
4019
4020
4021getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004022 Get the position for String {expr}. Same as |getpos()| but the
4023 column number in the returned List is a character index
4024 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004025 If |getpos()| returns a very large column number, equal to
4026 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004027 of the last character.
4028
4029 Example:
4030 With the cursor on '세' in line 5 with text "여보세요": >
4031 getcharpos('.') returns [0, 5, 3, 0]
4032 getpos('.') returns [0, 5, 7, 0]
4033<
4034 Can also be used as a |method|: >
4035 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004036<
4037 Return type: list<number>
4038
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004039
4040getcharsearch() *getcharsearch()*
4041 Return the current character search information as a {dict}
4042 with the following entries:
4043
4044 char character previously used for a character
4045 search (|t|, |f|, |T|, or |F|); empty string
4046 if no character search has been performed
4047 forward direction of character search; 1 for forward,
4048 0 for backward
4049 until type of character search; 1 for a |t| or |T|
4050 character search, 0 for an |f| or |F|
4051 character search
4052
4053 This can be useful to always have |;| and |,| search
4054 forward/backward regardless of the direction of the previous
4055 character search: >
4056 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4057 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4058< Also see |setcharsearch()|.
4059
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004060 Return type: dict<any>
4061
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004062
Doug Kearns9cd9e752024-04-07 17:42:17 +02004063getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004064 Get a single character from the user or input stream as a
4065 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004066 If {expr} is omitted, wait until a character is available.
4067 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004068 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004069 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004070 available, it is not consumed. Return an empty string
4071 if no character is available.
4072 Otherwise this works like |getchar()|, except that a number
4073 result is converted to a string.
4074
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004075 Return type: |String|
4076
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004077getcmdcomplpat() *getcmdcomplpat()*
4078 Return completion pattern of the current command-line.
4079 Only works when the command line is being edited, thus
4080 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4081 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4082 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4083 Returns an empty string when completion is not defined.
4084
4085 Return type: |String|
4086
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004087
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004088getcmdcompltype() *getcmdcompltype()*
4089 Return the type of the current command-line completion.
4090 Only works when the command line is being edited, thus
4091 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004092 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004093 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004094 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004095 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004096
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004097 Return type: |String|
4098
4099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004100getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004101 Return the current command-line input. Only works when the
4102 command line is being edited, thus requires use of
4103 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004104 Example: >
4105 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004106< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4107 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004108 Returns an empty string when entering a password or using
4109 |inputsecret()|.
4110
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004111 Return type: |String|
4112
4113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004114getcmdpos() *getcmdpos()*
4115 Return the position of the cursor in the command line as a
4116 byte count. The first column is 1.
4117 Only works when editing the command line, thus requires use of
4118 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4119 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004120 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4121 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004122
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004123 Return type: |Number|
4124
4125
Shougo Matsushita69084282024-09-23 20:34:47 +02004126getcmdprompt() *getcmdprompt()*
4127 Return the current command-line prompt when using functions
4128 like |input()| or |confirm()|.
4129 Only works when the command line is being edited, thus
4130 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4131 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4132 |setcmdpos()| and |setcmdline()|.
4133
4134 Return type: |String|
4135
4136
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004137getcmdscreenpos() *getcmdscreenpos()*
4138 Return the screen position of the cursor in the command line
4139 as a byte count. The first column is 1.
4140 Instead of |getcmdpos()|, it adds the prompt position.
4141 Only works when editing the command line, thus requires use of
4142 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4143 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004144 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4145 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004146
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004147 Return type: |Number|
4148
4149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004150getcmdtype() *getcmdtype()*
4151 Return the current command-line type. Possible return values
4152 are:
4153 : normal Ex command
4154 > debug mode command |debug-mode|
4155 / forward search command
4156 ? backward search command
4157 @ |input()| command
4158 - |:insert| or |:append| command
4159 = |i_CTRL-R_=|
4160 Only works when editing the command line, thus requires use of
4161 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4162 Returns an empty string otherwise.
4163 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4164
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004165 Return type: |String|
4166
4167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004168getcmdwintype() *getcmdwintype()*
4169 Return the current |command-line-window| type. Possible return
4170 values are the same as |getcmdtype()|. Returns an empty string
4171 when not in the command-line window.
4172
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004173 Return type: |String|
4174
4175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004176getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4177 Return a list of command-line completion matches. The String
4178 {type} argument specifies what for. The following completion
4179 types are supported:
4180
4181 arglist file names in argument list
4182 augroup autocmd groups
4183 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004184 behave |:behave| suboptions
4185 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004186 color color schemes
4187 command Ex command
4188 cmdline |cmdline-completion| result
4189 compiler compilers
4190 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004191 custom,{func} custom completion, defined via {func}
4192 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004193 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004194 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004195 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004196 environment environment variable names
4197 event autocommand events
4198 expression Vim expression
4199 file file and directory names
4200 file_in_path file and directory names in |'path'|
4201 filetype filetype names |'filetype'|
4202 function function name
4203 help help subjects
4204 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004205 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004206 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004207 locale locale names (as output of locale -a)
4208 mapclear buffer argument
4209 mapping mapping name
4210 menu menus
4211 messages |:messages| suboptions
4212 option options
4213 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004214 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004215 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004216 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004217 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004218 sign |:sign| suboptions
4219 syntax syntax file names |'syntax'|
4220 syntime |:syntime| suboptions
4221 tag tags
4222 tag_listfiles tags, file names
4223 user user names
4224 var user variables
4225
4226 If {pat} is an empty string, then all the matches are
4227 returned. Otherwise only items matching {pat} are returned.
4228 See |wildcards| for the use of special characters in {pat}.
4229
4230 If the optional {filtered} flag is set to 1, then 'wildignore'
4231 is applied to filter the results. Otherwise all the matches
4232 are returned. The 'wildignorecase' option always applies.
4233
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004234 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4235 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004236 regular expression matching is used. Thus this function
4237 follows the user preference, what happens on the command line.
4238 If you do not want this you can make 'wildoptions' empty
4239 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004241 If {type} is "cmdline", then the |cmdline-completion| result is
4242 returned. For example, to complete the possible values after
4243 a ":call" command: >
4244 echo getcompletion('call ', 'cmdline')
4245<
4246 If there are no matches, an empty list is returned. An
4247 invalid value for {type} produces an error.
4248
4249 Can also be used as a |method|: >
4250 GetPattern()->getcompletion('color')
4251<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004252 Return type: list<string>
4253
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004254 *getcurpos()*
4255getcurpos([{winid}])
4256 Get the position of the cursor. This is like getpos('.'), but
4257 includes an extra "curswant" item in the list:
4258 [0, lnum, col, off, curswant] ~
4259 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004260 cursor vertically. After |$| command it will be a very large
4261 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004262 |getpos()|.
4263 The first "bufnum" item is always zero. The byte position of
4264 the cursor is returned in 'col'. To get the character
4265 position, use |getcursorcharpos()|.
4266
4267 The optional {winid} argument can specify the window. It can
4268 be the window number or the |window-ID|. The last known
4269 cursor position is returned, this may be invalid for the
4270 current value of the buffer if it is not the current window.
4271 If {winid} is invalid a list with zeroes is returned.
4272
4273 This can be used to save and restore the cursor position: >
4274 let save_cursor = getcurpos()
4275 MoveTheCursorAround
4276 call setpos('.', save_cursor)
4277< Note that this only works within the window. See
4278 |winrestview()| for restoring more state.
4279
4280 Can also be used as a |method|: >
4281 GetWinid()->getcurpos()
4282<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004283 Return type: list<number>
4284
4285
4286getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004287 Same as |getcurpos()| but the column number in the returned
4288 List is a character index instead of a byte index.
4289
4290 Example:
4291 With the cursor on '보' in line 3 with text "여보세요": >
4292 getcursorcharpos() returns [0, 3, 2, 0, 3]
4293 getcurpos() returns [0, 3, 4, 0, 3]
4294<
4295 Can also be used as a |method|: >
4296 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004297<
4298 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004299
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004300
4301getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004302 The result is a String, which is the name of the current
4303 working directory. 'autochdir' is ignored.
4304
4305 With {winnr} return the local current directory of this window
4306 in the current tab page. {winnr} can be the window number or
4307 the |window-ID|.
4308 If {winnr} is -1 return the name of the global working
4309 directory. See also |haslocaldir()|.
4310
4311 With {winnr} and {tabnr} return the local current directory of
4312 the window in the specified tab page. If {winnr} is -1 return
4313 the working directory of the tabpage.
4314 If {winnr} is zero use the current window, if {tabnr} is zero
4315 use the current tabpage.
4316 Without any arguments, return the actual working directory of
4317 the current window.
4318 Return an empty string if the arguments are invalid.
4319
4320 Examples: >
4321 " Get the working directory of the current window
4322 :echo getcwd()
4323 :echo getcwd(0)
4324 :echo getcwd(0, 0)
4325 " Get the working directory of window 3 in tabpage 2
4326 :echo getcwd(3, 2)
4327 " Get the global working directory
4328 :echo getcwd(-1)
4329 " Get the working directory of tabpage 3
4330 :echo getcwd(-1, 3)
4331 " Get the working directory of current tabpage
4332 :echo getcwd(-1, 0)
4333
4334< Can also be used as a |method|: >
4335 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004336<
4337 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004338
4339getenv({name}) *getenv()*
4340 Return the value of environment variable {name}. The {name}
4341 argument is a string, without a leading '$'. Example: >
4342 myHome = getenv('HOME')
4343
4344< When the variable does not exist |v:null| is returned. That
4345 is different from a variable set to an empty string, although
4346 some systems interpret the empty value as the variable being
4347 deleted. See also |expr-env|.
4348
4349 Can also be used as a |method|: >
4350 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004351<
4352 Return type: |String| or |Number|
4353
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004354
4355getfontname([{name}]) *getfontname()*
4356 Without an argument returns the name of the normal font being
4357 used. Like what is used for the Normal highlight group
4358 |hl-Normal|.
4359 With an argument a check is done whether String {name} is a
4360 valid font name. If not then an empty string is returned.
4361 Otherwise the actual font name is returned, or {name} if the
4362 GUI does not support obtaining the real name.
4363 Only works when the GUI is running, thus not in your vimrc or
4364 gvimrc file. Use the |GUIEnter| autocommand to use this
4365 function just after the GUI has started.
4366 Note that the GTK GUI accepts any font name, thus checking for
4367 a valid name does not work.
4368
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004369 Return type: |String|
4370
4371
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004372getfperm({fname}) *getfperm()*
4373 The result is a String, which is the read, write, and execute
4374 permissions of the given file {fname}.
4375 If {fname} does not exist or its directory cannot be read, an
4376 empty string is returned.
4377 The result is of the form "rwxrwxrwx", where each group of
4378 "rwx" flags represent, in turn, the permissions of the owner
4379 of the file, the group the file belongs to, and other users.
4380 If a user does not have a given permission the flag for this
4381 is replaced with the string "-". Examples: >
4382 :echo getfperm("/etc/passwd")
4383 :echo getfperm(expand("~/.vimrc"))
4384< This will hopefully (from a security point of view) display
4385 the string "rw-r--r--" or even "rw-------".
4386
4387 Can also be used as a |method|: >
4388 GetFilename()->getfperm()
4389<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004390 Return type: |String|
4391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004392 For setting permissions use |setfperm()|.
4393
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004394
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004395getfsize({fname}) *getfsize()*
4396 The result is a Number, which is the size in bytes of the
4397 given file {fname}.
4398 If {fname} is a directory, 0 is returned.
4399 If the file {fname} can't be found, -1 is returned.
4400 If the size of {fname} is too big to fit in a Number then -2
4401 is returned.
4402
4403 Can also be used as a |method|: >
4404 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004405<
4406 Return type: |Number|
4407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004408
4409getftime({fname}) *getftime()*
4410 The result is a Number, which is the last modification time of
4411 the given file {fname}. The value is measured as seconds
4412 since 1st Jan 1970, and may be passed to strftime(). See also
4413 |localtime()| and |strftime()|.
4414 If the file {fname} can't be found -1 is returned.
4415
4416 Can also be used as a |method|: >
4417 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004418<
4419 Return type: |Number|
4420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004421
4422getftype({fname}) *getftype()*
4423 The result is a String, which is a description of the kind of
4424 file of the given file {fname}.
4425 If {fname} does not exist an empty string is returned.
4426 Here is a table over different kinds of files and their
4427 results:
4428 Normal file "file"
4429 Directory "dir"
4430 Symbolic link "link"
4431 Block device "bdev"
4432 Character device "cdev"
4433 Socket "socket"
4434 FIFO "fifo"
4435 All other "other"
4436 Example: >
4437 getftype("/home")
4438< Note that a type such as "link" will only be returned on
4439 systems that support it. On some systems only "dir" and
4440 "file" are returned. On MS-Windows a symbolic link to a
4441 directory returns "dir" instead of "link".
4442
4443 Can also be used as a |method|: >
4444 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004445<
4446 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004447
4448getimstatus() *getimstatus()*
4449 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004450 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004451 See 'imstatusfunc'.
4452
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004453 Return type: |Number|
4454
4455
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004456getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4457 Returns the |jumplist| for the specified window.
4458
4459 Without arguments use the current window.
4460 With {winnr} only use this window in the current tab page.
4461 {winnr} can also be a |window-ID|.
4462 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004463 page. If {winnr} or {tabnr} is invalid, an empty list is
4464 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004465
4466 The returned list contains two entries: a list with the jump
4467 locations and the last used jump position number in the list.
4468 Each entry in the jump location list is a dictionary with
4469 the following entries:
4470 bufnr buffer number
4471 col column number
4472 coladd column offset for 'virtualedit'
4473 filename filename if available
4474 lnum line number
4475
4476 Can also be used as a |method|: >
4477 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004478<
4479 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004481 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004482getline({lnum} [, {end}])
4483 Without {end} the result is a String, which is line {lnum}
4484 from the current buffer. Example: >
4485 getline(1)
4486< When {lnum} is a String that doesn't start with a
4487 digit, |line()| is called to translate the String into a Number.
4488 To get the line under the cursor: >
4489 getline(".")
4490< When {lnum} is a number smaller than 1 or bigger than the
4491 number of lines in the buffer, an empty string is returned.
4492
4493 When {end} is given the result is a |List| where each item is
4494 a line from the current buffer in the range {lnum} to {end},
4495 including line {end}.
4496 {end} is used in the same way as {lnum}.
4497 Non-existing lines are silently omitted.
4498 When {end} is before {lnum} an empty |List| is returned.
4499 Example: >
4500 :let start = line('.')
4501 :let end = search("^$") - 1
4502 :let lines = getline(start, end)
4503
4504< Can also be used as a |method|: >
4505 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004506<
4507 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004508
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004509 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004510 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004511
4512getloclist({nr} [, {what}]) *getloclist()*
4513 Returns a |List| with all the entries in the location list for
4514 window {nr}. {nr} can be the window number or the |window-ID|.
4515 When {nr} is zero the current window is used.
4516
4517 For a location list window, the displayed location list is
4518 returned. For an invalid window number {nr}, an empty list is
4519 returned. Otherwise, same as |getqflist()|.
4520
4521 If the optional {what} dictionary argument is supplied, then
4522 returns the items listed in {what} as a dictionary. Refer to
4523 |getqflist()| for the supported items in {what}.
4524
4525 In addition to the items supported by |getqflist()| in {what},
4526 the following item is supported by |getloclist()|:
4527
4528 filewinid id of the window used to display files
4529 from the location list. This field is
4530 applicable only when called from a
4531 location list window. See
4532 |location-list-file-window| for more
4533 details.
4534
4535 Returns a |Dictionary| with default values if there is no
4536 location list for the window {nr}.
4537 Returns an empty Dictionary if window {nr} does not exist.
4538
4539 Examples (See also |getqflist-examples|): >
4540 :echo getloclist(3, {'all': 0})
4541 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004542<
4543 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004544
4545
4546getmarklist([{buf}]) *getmarklist()*
4547 Without the {buf} argument returns a |List| with information
4548 about all the global marks. |mark|
4549
4550 If the optional {buf} argument is specified, returns the
4551 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004552 see |bufname()|. If {buf} is invalid, an empty list is
4553 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004554
4555 Each item in the returned List is a |Dict| with the following:
4556 mark name of the mark prefixed by "'"
4557 pos a |List| with the position of the mark:
4558 [bufnum, lnum, col, off]
4559 Refer to |getpos()| for more information.
4560 file file name
4561
4562 Refer to |getpos()| for getting information about a specific
4563 mark.
4564
4565 Can also be used as a |method|: >
4566 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004567<
4568 Return type: list<dict<any>> or list<any>
4569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004570
4571getmatches([{win}]) *getmatches()*
4572 Returns a |List| with all matches previously defined for the
4573 current window by |matchadd()| and the |:match| commands.
4574 |getmatches()| is useful in combination with |setmatches()|,
4575 as |setmatches()| can restore a list of matches saved by
4576 |getmatches()|.
4577 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004578 window ID instead of the current window. If {win} is invalid,
4579 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004580 Example: >
4581 :echo getmatches()
4582< [{'group': 'MyGroup1', 'pattern': 'TODO',
4583 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4584 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4585 :let m = getmatches()
4586 :call clearmatches()
4587 :echo getmatches()
4588< [] >
4589 :call setmatches(m)
4590 :echo getmatches()
4591< [{'group': 'MyGroup1', 'pattern': 'TODO',
4592 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4593 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4594 :unlet m
4595<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004596 Return type: list<dict<any>> or list<any>
4597
4598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004599getmousepos() *getmousepos()*
4600 Returns a |Dictionary| with the last known position of the
4601 mouse. This can be used in a mapping for a mouse click or in
4602 a filter of a popup window. The items are:
4603 screenrow screen row
4604 screencol screen column
4605 winid Window ID of the click
4606 winrow row inside "winid"
4607 wincol column inside "winid"
4608 line text line inside "winid"
4609 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004610 coladd offset (in screen columns) from the
4611 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004612 All numbers are 1-based.
4613
4614 If not over a window, e.g. when in the command line, then only
4615 "screenrow" and "screencol" are valid, the others are zero.
4616
4617 When on the status line below a window or the vertical
4618 separator right of a window, the "line" and "column" values
4619 are zero.
4620
4621 When the position is after the text then "column" is the
4622 length of the text in bytes plus one.
4623
4624 If the mouse is over a popup window then that window is used.
4625
4626 When using |getchar()| the Vim variables |v:mouse_lnum|,
4627 |v:mouse_col| and |v:mouse_winid| also provide these values.
4628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004629 Return type: dict<number>
4630
4631
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004632getmouseshape() *getmouseshape()*
4633 Returns the name of the currently showing mouse pointer.
4634 When the |+mouseshape| feature is not supported or the shape
4635 is unknown an empty string is returned.
4636 This function is mainly intended for testing.
4637
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004638 Return type: |String|
4639
4640
4641getpid() *getpid()*
4642 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004643 On Unix and MS-Windows this is a unique number, until Vim
4644 exits.
4645
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004646 Return type: |Number|
4647
4648
4649getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004650 Get the position for String {expr}.
4651 The accepted values for {expr} are: *E1209*
4652 . The cursor position.
4653 $ The last line in the current buffer.
4654 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004655 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004656 w0 First line visible in current window (one if the
4657 display isn't updated, e.g. in silent Ex mode).
4658 w$ Last line visible in current window (this is one
4659 less than "w0" if no lines are visible).
4660 v When not in Visual mode, returns the cursor
4661 position. In Visual mode, returns the other end
4662 of the Visual area. A good way to think about
4663 this is that in Visual mode "v" and "." complement
4664 each other. While "." refers to the cursor
4665 position, "v" refers to where |v_o| would move the
4666 cursor. As a result, you can use "v" and "."
4667 together to work on all of a selection in
4668 characterwise Visual mode. If the cursor is at
4669 the end of a characterwise Visual area, "v" refers
4670 to the start of the same Visual area. And if the
4671 cursor is at the start of a characterwise Visual
4672 area, "v" refers to the end of the same Visual
4673 area. "v" differs from |'<| and |'>| in that it's
4674 updated right away.
4675 Note that a mark in another file can be used. The line number
4676 then applies to another buffer.
4677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004678 The result is a |List| with four numbers:
4679 [bufnum, lnum, col, off]
4680 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4681 is the buffer number of the mark.
4682 "lnum" and "col" are the position in the buffer. The first
4683 column is 1.
4684 The "off" number is zero, unless 'virtualedit' is used. Then
4685 it is the offset in screen columns from the start of the
4686 character. E.g., a position within a <Tab> or after the last
4687 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004688
4689 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004690 The column number in the returned List is the byte position
4691 within the line. To get the character position in the line,
4692 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004693
4694 Note that for '< and '> Visual mode matters: when it is "V"
4695 (visual line mode) the column of '< is zero and the column of
4696 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004697 A very large column number equal to |v:maxcol| can be returned,
4698 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004699 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004701 This can be used to save and restore the position of a mark: >
4702 let save_a_mark = getpos("'a")
4703 ...
4704 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004705<
4706 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004707
4708 Can also be used as a |method|: >
4709 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004710<
4711 Return type: list<number>
4712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004713
4714getqflist([{what}]) *getqflist()*
4715 Returns a |List| with all the current quickfix errors. Each
4716 list item is a dictionary with these entries:
4717 bufnr number of buffer that has the file name, use
4718 bufname() to get the name
4719 module module name
4720 lnum line number in the buffer (first line is 1)
4721 end_lnum
4722 end of line number if the item is multiline
4723 col column number (first column is 1)
4724 end_col end of column number if the item has range
4725 vcol |TRUE|: "col" is visual column
4726 |FALSE|: "col" is byte index
4727 nr error number
h-east84ac2122024-06-17 18:12:30 +02004728 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004729 text description of the error
4730 type type of the error, 'E', '1', etc.
4731 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004732 user_data
4733 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004734 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004735
4736 When there is no error list or it's empty, an empty list is
4737 returned. Quickfix list entries with a non-existing buffer
4738 number are returned with "bufnr" set to zero (Note: some
4739 functions accept buffer number zero for the alternate buffer,
4740 you may need to explicitly check for zero).
4741
4742 Useful application: Find pattern matches in multiple files and
4743 do something with them: >
4744 :vimgrep /theword/jg *.c
4745 :for d in getqflist()
4746 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4747 :endfor
4748<
4749 If the optional {what} dictionary argument is supplied, then
4750 returns only the items listed in {what} as a dictionary. The
4751 following string items are supported in {what}:
4752 changedtick get the total number of changes made
4753 to the list |quickfix-changedtick|
4754 context get the |quickfix-context|
4755 efm errorformat to use when parsing "lines". If
4756 not present, then the 'errorformat' option
4757 value is used.
4758 id get information for the quickfix list with
4759 |quickfix-ID|; zero means the id for the
4760 current list or the list specified by "nr"
4761 idx get information for the quickfix entry at this
4762 index in the list specified by 'id' or 'nr'.
4763 If set to zero, then uses the current entry.
4764 See |quickfix-index|
4765 items quickfix list entries
4766 lines parse a list of lines using 'efm' and return
4767 the resulting entries. Only a |List| type is
4768 accepted. The current quickfix list is not
4769 modified. See |quickfix-parse|.
4770 nr get information for this quickfix list; zero
4771 means the current quickfix list and "$" means
4772 the last quickfix list
4773 qfbufnr number of the buffer displayed in the quickfix
4774 window. Returns 0 if the quickfix buffer is
4775 not present. See |quickfix-buffer|.
4776 size number of entries in the quickfix list
4777 title get the list title |quickfix-title|
4778 winid get the quickfix |window-ID|
4779 all all of the above quickfix properties
4780 Non-string items in {what} are ignored. To get the value of a
4781 particular item, set it to zero.
4782 If "nr" is not present then the current quickfix list is used.
4783 If both "nr" and a non-zero "id" are specified, then the list
4784 specified by "id" is used.
4785 To get the number of lists in the quickfix stack, set "nr" to
4786 "$" in {what}. The "nr" value in the returned dictionary
4787 contains the quickfix stack size.
4788 When "lines" is specified, all the other items except "efm"
4789 are ignored. The returned dictionary contains the entry
4790 "items" with the list of entries.
4791
4792 The returned dictionary contains the following entries:
4793 changedtick total number of changes made to the
4794 list |quickfix-changedtick|
4795 context quickfix list context. See |quickfix-context|
4796 If not present, set to "".
4797 id quickfix list ID |quickfix-ID|. If not
4798 present, set to 0.
4799 idx index of the quickfix entry in the list. If not
4800 present, set to 0.
4801 items quickfix list entries. If not present, set to
4802 an empty list.
4803 nr quickfix list number. If not present, set to 0
4804 qfbufnr number of the buffer displayed in the quickfix
4805 window. If not present, set to 0.
4806 size number of entries in the quickfix list. If not
4807 present, set to 0.
4808 title quickfix list title text. If not present, set
4809 to "".
4810 winid quickfix |window-ID|. If not present, set to 0
4811
4812 Examples (See also |getqflist-examples|): >
4813 :echo getqflist({'all': 1})
4814 :echo getqflist({'nr': 2, 'title': 1})
4815 :echo getqflist({'lines' : ["F1:10:L10"]})
4816<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004817 Return type: list<dict<any>> or list<any>
4818
4819
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004820getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4821 The result is a String, which is the contents of register
4822 {regname}. Example: >
4823 :let cliptext = getreg('*')
4824< When register {regname} was not set the result is an empty
4825 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004826 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004827
4828 getreg('=') returns the last evaluated value of the expression
4829 register. (For use in maps.)
4830 getreg('=', 1) returns the expression itself, so that it can
4831 be restored with |setreg()|. For other registers the extra
4832 argument is ignored, thus you can always give it.
4833
4834 If {list} is present and |TRUE|, the result type is changed
4835 to |List|. Each list item is one text line. Use it if you care
4836 about zero bytes possibly present inside register: without
4837 third argument both NLs and zero bytes are represented as NLs
4838 (see |NL-used-for-Nul|).
4839 When the register was not set an empty list is returned.
4840
4841 If {regname} is "", the unnamed register '"' is used.
4842 If {regname} is not specified, |v:register| is used.
4843 In |Vim9-script| {regname} must be one character.
4844
4845 Can also be used as a |method|: >
4846 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004847<
4848 Return type: |String|
4849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004850
4851getreginfo([{regname}]) *getreginfo()*
4852 Returns detailed information about register {regname} as a
4853 Dictionary with the following entries:
4854 regcontents List of lines contained in register
4855 {regname}, like
4856 |getreg|({regname}, 1, 1).
4857 regtype the type of register {regname}, as in
4858 |getregtype()|.
4859 isunnamed Boolean flag, v:true if this register
4860 is currently pointed to by the unnamed
4861 register.
4862 points_to for the unnamed register, gives the
4863 single letter name of the register
4864 currently pointed to (see |quotequote|).
4865 For example, after deleting a line
4866 with `dd`, this field will be "1",
4867 which is the register that got the
4868 deleted text.
4869
4870 The {regname} argument is a string. If {regname} is invalid
4871 or not set, an empty Dictionary will be returned.
4872 If {regname} is "" or "@", the unnamed register '"' is used.
4873 If {regname} is not specified, |v:register| is used.
4874 The returned Dictionary can be passed to |setreg()|.
4875 In |Vim9-script| {regname} must be one character.
4876
4877 Can also be used as a |method|: >
4878 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004879<
4880 Return type: dict<any>
4881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004882
Shougo Matsushita19b71882024-02-28 22:48:12 +01004883getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004884 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004885 buffer.
4886
4887 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004888 See |getpos()| for the format of the list. It's possible
4889 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004890 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004891
4892 The optional argument {opts} is a Dict and supports the
4893 following items:
4894
zeertzjqafc22952024-05-24 19:07:12 +02004895 type Specify the region's selection type.
4896 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004897 except that the width can be omitted
4898 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004899 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004900
zeertzjq87410ab2024-03-02 06:00:23 +08004901 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004902 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004903 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004904
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004905 You can get the last selection type by |visualmode()|.
4906 If Visual mode is active, use |mode()| to get the Visual mode
4907 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004908 This function is useful to get text starting and ending in
4909 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004910
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004911 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004912 Note that:
4913 - Order of {pos1} and {pos2} doesn't matter, it will always
4914 return content from the upper left position to the lower
4915 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004916 - If 'virtualedit' is enabled and the region is past the end
4917 of the lines, resulting lines are padded with spaces.
4918 - If the region is blockwise and it starts or ends in the
4919 middle of a multi-cell character, it is not included but
4920 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004921 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004922 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004923 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004924 - It is evaluated in current window context, which makes a
4925 difference if the buffer is displayed in a window with
4926 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004927
4928 Examples: >
4929 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004930 \ <Cmd>echow getregion(
4931 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004932<
4933 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004934 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004935<
4936 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004937
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004938
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004939getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4940 Same as |getregion()|, but returns a list of positions
4941 describing the buffer text segments bound by {pos1} and
4942 {pos2}.
4943 The segments are a pair of positions for every line: >
4944 [[{start_pos}, {end_pos}], ...]
4945<
4946 The position is a |List| with four numbers:
4947 [bufnum, lnum, col, off]
4948 "bufnum" is the buffer number.
4949 "lnum" and "col" are the position in the buffer. The first
4950 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004951 If the "off" number of a starting position is non-zero, it is
4952 the offset in screen columns from the start of the character.
4953 E.g., a position within a <Tab> or after the last character.
4954 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004955 the offset of the character's first cell not included in the
4956 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004957
zeertzjq2b09de92024-05-24 07:48:51 +02004958 Apart from the options supported by |getregion()|, {opts} also
4959 supports the following:
4960
4961 eol If |TRUE|, indicate positions beyond
4962 the end of a line with "col" values
4963 one more than the length of the line.
4964 If |FALSE|, positions are limited
4965 within their lines, and if a line is
4966 empty or the selection is entirely
4967 beyond the end of a line, a "col"
4968 value of 0 is used for both positions.
4969 (default: |FALSE|)
4970
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004971 Can also be used as a |method|: >
4972 getpos('.')->getregionpos(getpos("'a"))
4973<
zeertzjqd4d12072024-07-16 20:34:16 +02004974 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004975
4976
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004977getregtype([{regname}]) *getregtype()*
4978 The result is a String, which is type of register {regname}.
4979 The value will be one of:
4980 "v" for |characterwise| text
4981 "V" for |linewise| text
4982 "<CTRL-V>{width}" for |blockwise-visual| text
4983 "" for an empty or unknown register
4984 <CTRL-V> is one character with value 0x16.
4985 The {regname} argument is a string. If {regname} is "", the
4986 unnamed register '"' is used. If {regname} is not specified,
4987 |v:register| is used.
4988 In |Vim9-script| {regname} must be one character.
4989
4990 Can also be used as a |method|: >
4991 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004992<
4993 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004994
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004995
Bram Moolenaar71badf92023-04-22 22:40:14 +01004996getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004997 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004998 scripts in the order they were sourced, like what
4999 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005000
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005001 The optional Dict argument {opts} supports the following
5002 optional items:
5003 name Script name match pattern. If specified,
5004 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005005 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005006 "name" are returned.
5007 sid Script ID |<SID>|. If specified, only
5008 information about the script with ID "sid" is
5009 returned and "name" is ignored.
5010
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005011 Each item in the returned List is a |Dict| with the following
5012 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005013 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005014 `import autoload` but was not actually sourced
5015 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005016 functions List of script-local function names defined in
5017 the script. Present only when a particular
5018 script is specified using the "sid" item in
5019 {opts}.
5020 name Vim script file name.
5021 sid Script ID |<SID>|.
5022 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005023 this script name links to, if any, otherwise
5024 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005025 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005026 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005027 specified using the "sid" item in {opts}.
5028 Note that this is a copy, the value of
5029 script-local variables cannot be changed using
5030 this dictionary.
h_east59858792023-10-25 22:47:05 +09005031 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005032
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005033 Examples: >
5034 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005035 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005036<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005037 Return type: list<dict<any>>
5038
5039
ichizok663d18d2025-01-02 18:06:00 +01005040getstacktrace() *getstacktrace()*
5041 Returns the current stack trace of Vim scripts.
5042 Stack trace is a |List|, of which each item is a |Dictionary|
5043 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005044 funcref The funcref if the stack is at a function,
5045 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005046 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005047 stack is at an autocmd event, otherwise this
5048 item is omitted.
5049 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005050 filepath The file path of the script on the stack.
5051
5052 Return type: list<dict<any>>
5053
5054
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005055gettabinfo([{tabnr}]) *gettabinfo()*
5056 If {tabnr} is not specified, then information about all the
5057 tab pages is returned as a |List|. Each List item is a
5058 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5059 number and information about that one is returned. If the tab
5060 page does not exist an empty List is returned.
5061
5062 Each List item is a |Dictionary| with the following entries:
5063 tabnr tab page number.
5064 variables a reference to the dictionary with
5065 tabpage-local variables
5066 windows List of |window-ID|s in the tab page.
5067
5068 Can also be used as a |method|: >
5069 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005070<
5071 Return type: list<dict<any>>
5072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005073
5074gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5075 Get the value of a tab-local variable {varname} in tab page
5076 {tabnr}. |t:var|
5077 Tabs are numbered starting with one.
5078 The {varname} argument is a string. When {varname} is empty a
5079 dictionary with all tab-local variables is returned.
5080 Note that the name without "t:" must be used.
5081 When the tab or variable doesn't exist {def} or an empty
5082 string is returned, there is no error message.
5083
5084 Can also be used as a |method|: >
5085 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005086<
5087 Return type: any, depending on {varname}
5088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005089
5090gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5091 Get the value of window-local variable {varname} in window
5092 {winnr} in tab page {tabnr}.
5093 The {varname} argument is a string. When {varname} is empty a
5094 dictionary with all window-local variables is returned.
5095 When {varname} is equal to "&" get the values of all
5096 window-local options in a |Dictionary|.
5097 Otherwise, when {varname} starts with "&" get the value of a
5098 window-local option.
5099 Note that {varname} must be the name without "w:".
5100 Tabs are numbered starting with one. For the current tabpage
5101 use |getwinvar()|.
5102 {winnr} can be the window number or the |window-ID|.
5103 When {winnr} is zero the current window is used.
5104 This also works for a global option, buffer-local option and
5105 window-local option, but it doesn't work for a global variable
5106 or buffer-local variable.
5107 When the tab, window or variable doesn't exist {def} or an
5108 empty string is returned, there is no error message.
5109 Examples: >
5110 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005111 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005112<
5113 To obtain all window-local variables use: >
5114 gettabwinvar({tabnr}, {winnr}, '&')
5115
5116< Can also be used as a |method|: >
5117 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005118<
5119 Return type: any, depending on {varname}
5120
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005121
5122gettagstack([{winnr}]) *gettagstack()*
5123 The result is a Dict, which is the tag stack of window {winnr}.
5124 {winnr} can be the window number or the |window-ID|.
5125 When {winnr} is not specified, the current window is used.
5126 When window {winnr} doesn't exist, an empty Dict is returned.
5127
5128 The returned dictionary contains the following entries:
5129 curidx Current index in the stack. When at
5130 top of the stack, set to (length + 1).
5131 Index of bottom of the stack is 1.
5132 items List of items in the stack. Each item
5133 is a dictionary containing the
5134 entries described below.
5135 length Number of entries in the stack.
5136
5137 Each item in the stack is a dictionary with the following
5138 entries:
5139 bufnr buffer number of the current jump
5140 from cursor position before the tag jump.
5141 See |getpos()| for the format of the
5142 returned list.
5143 matchnr current matching tag number. Used when
5144 multiple matching tags are found for a
5145 name.
5146 tagname name of the tag
5147
5148 See |tagstack| for more information about the tag stack.
5149
5150 Can also be used as a |method|: >
5151 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005152<
5153 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005154
5155
Christ van Willegence0ef912024-06-20 23:41:59 +02005156gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005157 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005158 This is intended for use in Vim scripts. When generating
5159 message translations the {text} is extracted by `xgettext`,
5160 the translator can add translated messages into the .po file
5161 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005162 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005163 `xgettext` does not support single quoted escaped text.
5164
Christ van Willegence0ef912024-06-20 23:41:59 +02005165 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005166 for that specific package. This is mainly required for
5167 third-party Vim scripts. You need to specify a path to the
5168 translations with the |bindtextdomain()| function before
5169 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005170
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005171 Return type: |String|
5172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005173
5174getwininfo([{winid}]) *getwininfo()*
5175 Returns information about windows as a |List| with Dictionaries.
5176
5177 If {winid} is given Information about the window with that ID
5178 is returned, as a |List| with one item. If the window does not
5179 exist the result is an empty list.
5180
5181 Without {winid} information about all the windows in all the
5182 tab pages is returned.
5183
5184 Each List item is a |Dictionary| with the following entries:
5185 botline last complete displayed buffer line
5186 bufnr number of buffer in the window
5187 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005188 leftcol first column displayed; only used when
5189 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005190 loclist 1 if showing a location list
5191 {only with the +quickfix feature}
5192 quickfix 1 if quickfix or location list window
5193 {only with the +quickfix feature}
5194 terminal 1 if a terminal window
5195 {only with the +terminal feature}
5196 tabnr tab page number
5197 topline first displayed buffer line
5198 variables a reference to the dictionary with
5199 window-local variables
5200 width window width
5201 winbar 1 if the window has a toolbar, 0
5202 otherwise
5203 wincol leftmost screen column of the window;
5204 "col" from |win_screenpos()|
5205 textoff number of columns occupied by any
5206 'foldcolumn', 'signcolumn' and line
5207 number in front of the text
5208 winid |window-ID|
5209 winnr window number
5210 winrow topmost screen line of the window;
5211 "row" from |win_screenpos()|
5212
5213 Can also be used as a |method|: >
5214 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005215<
5216 Return type: list<dict<any>>
5217
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005218
5219getwinpos([{timeout}]) *getwinpos()*
5220 The result is a |List| with two numbers, the result of
5221 |getwinposx()| and |getwinposy()| combined:
5222 [x-pos, y-pos]
5223 {timeout} can be used to specify how long to wait in msec for
5224 a response from the terminal. When omitted 100 msec is used.
5225 Use a longer time for a remote terminal.
5226 When using a value less than 10 and no response is received
5227 within that time, a previously reported position is returned,
5228 if available. This can be used to poll for the position and
5229 do some work in the meantime: >
5230 while 1
5231 let res = getwinpos(1)
5232 if res[0] >= 0
5233 break
5234 endif
5235 " Do some work here
5236 endwhile
5237<
5238
5239 Can also be used as a |method|: >
5240 GetTimeout()->getwinpos()
5241<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005242 Return type: list<number>
5243
5244
5245getwinposx() *getwinposx()*
5246 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005247 the left hand side of the GUI Vim window. Also works for an
5248 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005249 The result will be -1 if the information is not available
5250 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005251 The value can be used with `:winpos`.
5252
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005253 Return type: |Number|
5254
5255
5256getwinposy() *getwinposy()*
5257 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005258 the top of the GUI Vim window. Also works for an xterm (uses
5259 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005260 The result will be -1 if the information is not available
5261 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005262 The value can be used with `:winpos`.
5263
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005264 Return type: |Number|
5265
5266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005267getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5268 Like |gettabwinvar()| for the current tabpage.
5269 Examples: >
5270 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005271 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005272
5273< Can also be used as a |method|: >
5274 GetWinnr()->getwinvar(varname)
5275<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005276 Return type: any, depending on {varname}
5277
5278
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005279glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5280 Expand the file wildcards in {expr}. See |wildcards| for the
5281 use of special characters.
5282
5283 Unless the optional {nosuf} argument is given and is |TRUE|,
5284 the 'suffixes' and 'wildignore' options apply: Names matching
5285 one of the patterns in 'wildignore' will be skipped and
5286 'suffixes' affect the ordering of matches.
5287 'wildignorecase' always applies.
5288
5289 When {list} is present and it is |TRUE| the result is a |List|
5290 with all matching files. The advantage of using a List is,
5291 you also get filenames containing newlines correctly.
5292 Otherwise the result is a String and when there are several
5293 matches, they are separated by <NL> characters.
5294
5295 If the expansion fails, the result is an empty String or List.
5296
5297 You can also use |readdir()| if you need to do complicated
5298 things, such as limiting the number of matches.
5299
5300 A name for a non-existing file is not included. A symbolic
5301 link is only included if it points to an existing file.
5302 However, when the {alllinks} argument is present and it is
5303 |TRUE| then all symbolic links are included.
5304
5305 For most systems backticks can be used to get files names from
5306 any external command. Example: >
5307 :let tagfiles = glob("`find . -name tags -print`")
5308 :let &tags = substitute(tagfiles, "\n", ",", "g")
5309< The result of the program inside the backticks should be one
5310 item per line. Spaces inside an item are allowed.
5311
5312 See |expand()| for expanding special Vim variables. See
5313 |system()| for getting the raw output of an external command.
5314
5315 Can also be used as a |method|: >
5316 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005317<
5318 Return type: |String| or list<string> or list<any> depending
5319 on {list}
5320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005321
h-east624bb832024-11-09 18:37:32 +01005322glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005323 Convert a file pattern, as used by glob(), into a search
5324 pattern. The result can be used to match with a string that
5325 is a file name. E.g. >
5326 if filename =~ glob2regpat('Make*.mak')
5327< This is equivalent to: >
5328 if filename =~ '^Make.*\.mak$'
5329< When {string} is an empty string the result is "^$", match an
5330 empty string.
5331 Note that the result depends on the system. On MS-Windows
5332 a backslash usually means a path separator.
5333
5334 Can also be used as a |method|: >
5335 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005336<
5337 Return type: |String|
5338
5339 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005340globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5341 Perform glob() for String {expr} on all directories in {path}
5342 and concatenate the results. Example: >
5343 :echo globpath(&rtp, "syntax/c.vim")
5344<
5345 {path} is a comma-separated list of directory names. Each
5346 directory name is prepended to {expr} and expanded like with
5347 |glob()|. A path separator is inserted when needed.
5348 To add a comma inside a directory name escape it with a
5349 backslash. Note that on MS-Windows a directory may have a
5350 trailing backslash, remove it if you put a comma after it.
5351 If the expansion fails for one of the directories, there is no
5352 error message.
5353
5354 Unless the optional {nosuf} argument is given and is |TRUE|,
5355 the 'suffixes' and 'wildignore' options apply: Names matching
5356 one of the patterns in 'wildignore' will be skipped and
5357 'suffixes' affect the ordering of matches.
5358
5359 When {list} is present and it is |TRUE| the result is a |List|
5360 with all matching files. The advantage of using a List is, you
5361 also get filenames containing newlines correctly. Otherwise
5362 the result is a String and when there are several matches,
5363 they are separated by <NL> characters. Example: >
5364 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5365<
5366 {alllinks} is used as with |glob()|.
5367
5368 The "**" item can be used to search in a directory tree.
5369 For example, to find all "README.txt" files in the directories
5370 in 'runtimepath' and below: >
5371 :echo globpath(&rtp, "**/README.txt")
5372< Upwards search and limiting the depth of "**" is not
5373 supported, thus using 'path' will not always work properly.
5374
5375 Can also be used as a |method|, the base is passed as the
5376 second argument: >
5377 GetExpr()->globpath(&rtp)
5378<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005379 Return type: |String| or list<string> or list<any> depending
5380 on {list}
5381
5382
5383has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005384 When {check} is omitted or is zero: The result is a Number,
5385 which is 1 if the feature {feature} is supported, zero
5386 otherwise. The {feature} argument is a string, case is
5387 ignored. See |feature-list| below.
5388
5389 When {check} is present and not zero: The result is a Number,
5390 which is 1 if the feature {feature} could ever be supported,
5391 zero otherwise. This is useful to check for a typo in
5392 {feature} and to detect dead code. Keep in mind that an older
5393 Vim version will not know about a feature added later and
5394 features that have been abandoned will not be known by the
5395 current Vim version.
5396
5397 Also see |exists()| and |exists_compiled()|.
5398
5399 Note that to skip code that has a syntax error when the
5400 feature is not available, Vim may skip the rest of the line
5401 and miss a following `endif`. Therefore put the `endif` on a
5402 separate line: >
5403 if has('feature')
5404 let x = this->breaks->without->the->feature
5405 endif
5406< If the `endif` would be moved to the second line as "| endif" it
5407 would not be found.
5408
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005409 Return type: |Number|
5410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005411
5412has_key({dict}, {key}) *has_key()*
5413 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005414 has an entry with key {key}. FALSE otherwise.
5415 The {key} argument is a string. In |Vim9| script a number is
5416 also accepted (and converted to a string) but no other types.
5417 In legacy script the usual automatic conversion to string is
5418 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005419
5420 Can also be used as a |method|: >
5421 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005422<
5423 Return type: |Number|
5424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005425
5426haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5427 The result is a Number:
5428 1 when the window has set a local directory via |:lcd|
5429 2 when the tab-page has set a local directory via |:tcd|
5430 0 otherwise.
5431
5432 Without arguments use the current window.
5433 With {winnr} use this window in the current tab page.
5434 With {winnr} and {tabnr} use the window in the specified tab
5435 page.
5436 {winnr} can be the window number or the |window-ID|.
5437 If {winnr} is -1 it is ignored and only the tabpage is used.
5438 Return 0 if the arguments are invalid.
5439 Examples: >
5440 if haslocaldir() == 1
5441 " window local directory case
5442 elseif haslocaldir() == 2
5443 " tab-local directory case
5444 else
5445 " global directory case
5446 endif
5447
5448 " current window
5449 :echo haslocaldir()
5450 :echo haslocaldir(0)
5451 :echo haslocaldir(0, 0)
5452 " window n in current tab page
5453 :echo haslocaldir(n)
5454 :echo haslocaldir(n, 0)
5455 " window n in tab page m
5456 :echo haslocaldir(n, m)
5457 " tab page m
5458 :echo haslocaldir(-1, m)
5459<
5460 Can also be used as a |method|: >
5461 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005462<
5463 Return type: |Number|
5464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005465
5466hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5467 The result is a Number, which is TRUE if there is a mapping
5468 that contains {what} in somewhere in the rhs (what it is
5469 mapped to) and this mapping exists in one of the modes
5470 indicated by {mode}.
5471 The arguments {what} and {mode} are strings.
5472 When {abbr} is there and it is |TRUE| use abbreviations
5473 instead of mappings. Don't forget to specify Insert and/or
5474 Command-line mode.
5475 Both the global mappings and the mappings local to the current
5476 buffer are checked for a match.
5477 If no matching mapping is found FALSE is returned.
5478 The following characters are recognized in {mode}:
5479 n Normal mode
5480 v Visual and Select mode
5481 x Visual mode
5482 s Select mode
5483 o Operator-pending mode
5484 i Insert mode
5485 l Language-Argument ("r", "f", "t", etc.)
5486 c Command-line mode
5487 When {mode} is omitted, "nvo" is used.
5488
5489 This function is useful to check if a mapping already exists
5490 to a function in a Vim script. Example: >
5491 :if !hasmapto('\ABCdoit')
5492 : map <Leader>d \ABCdoit
5493 :endif
5494< This installs the mapping to "\ABCdoit" only if there isn't
5495 already a mapping to "\ABCdoit".
5496
5497 Can also be used as a |method|: >
5498 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005499<
5500 Return type: |Number|
5501
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005502
5503histadd({history}, {item}) *histadd()*
5504 Add the String {item} to the history {history} which can be
5505 one of: *hist-names*
5506 "cmd" or ":" command line history
5507 "search" or "/" search pattern history
5508 "expr" or "=" typed expression history
5509 "input" or "@" input line history
5510 "debug" or ">" debug command history
5511 empty the current or last used history
5512 The {history} string does not need to be the whole name, one
5513 character is sufficient.
5514 If {item} does already exist in the history, it will be
5515 shifted to become the newest entry.
5516 The result is a Number: TRUE if the operation was successful,
5517 otherwise FALSE is returned.
5518
5519 Example: >
5520 :call histadd("input", strftime("%Y %b %d"))
5521 :let date=input("Enter date: ")
5522< This function is not available in the |sandbox|.
5523
5524 Can also be used as a |method|, the base is passed as the
5525 second argument: >
5526 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005527<
5528 Return type: |Number|
5529
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005530
5531histdel({history} [, {item}]) *histdel()*
5532 Clear {history}, i.e. delete all its entries. See |hist-names|
5533 for the possible values of {history}.
5534
5535 If the parameter {item} evaluates to a String, it is used as a
5536 regular expression. All entries matching that expression will
5537 be removed from the history (if there are any).
5538 Upper/lowercase must match, unless "\c" is used |/\c|.
5539 If {item} evaluates to a Number, it will be interpreted as
5540 an index, see |:history-indexing|. The respective entry will
5541 be removed if it exists.
5542
5543 The result is TRUE for a successful operation, otherwise FALSE
5544 is returned.
5545
5546 Examples:
5547 Clear expression register history: >
5548 :call histdel("expr")
5549<
5550 Remove all entries starting with "*" from the search history: >
5551 :call histdel("/", '^\*')
5552<
5553 The following three are equivalent: >
5554 :call histdel("search", histnr("search"))
5555 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005556 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005557<
5558 To delete the last search pattern and use the last-but-one for
5559 the "n" command and 'hlsearch': >
5560 :call histdel("search", -1)
5561 :let @/ = histget("search", -1)
5562<
5563 Can also be used as a |method|: >
5564 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005565<
5566 Return type: |Number|
5567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005568
5569histget({history} [, {index}]) *histget()*
5570 The result is a String, the entry with Number {index} from
5571 {history}. See |hist-names| for the possible values of
5572 {history}, and |:history-indexing| for {index}. If there is
5573 no such entry, an empty String is returned. When {index} is
5574 omitted, the most recent item from the history is used.
5575
5576 Examples:
5577 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005578 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005579
5580< Define an Ex command ":H {num}" that supports re-execution of
5581 the {num}th entry from the output of |:history|. >
5582 :command -nargs=1 H execute histget("cmd", 0+<args>)
5583<
5584 Can also be used as a |method|: >
5585 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005586<
5587 Return type: |String|
5588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005589
5590histnr({history}) *histnr()*
5591 The result is the Number of the current entry in {history}.
5592 See |hist-names| for the possible values of {history}.
5593 If an error occurred, -1 is returned.
5594
5595 Example: >
5596 :let inp_index = histnr("expr")
5597
5598< Can also be used as a |method|: >
5599 GetHistory()->histnr()
5600<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005601 Return type: |Number|
5602
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005603hlexists({name}) *hlexists()*
5604 The result is a Number, which is TRUE if a highlight group
5605 called {name} exists. This is when the group has been
5606 defined in some way. Not necessarily when highlighting has
5607 been defined for it, it may also have been used for a syntax
5608 item.
5609 *highlight_exists()*
5610 Obsolete name: highlight_exists().
5611
5612 Can also be used as a |method|: >
5613 GetName()->hlexists()
5614<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005615 Return type: |Number|
5616
5617
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005618hlget([{name} [, {resolve}]]) *hlget()*
5619 Returns a List of all the highlight group attributes. If the
5620 optional {name} is specified, then returns a List with only
5621 the attributes of the specified highlight group. Returns an
5622 empty List if the highlight group {name} is not present.
5623
5624 If the optional {resolve} argument is set to v:true and the
5625 highlight group {name} is linked to another group, then the
5626 link is resolved recursively and the attributes of the
5627 resolved highlight group are returned.
5628
5629 Each entry in the returned List is a Dictionary with the
5630 following items:
5631 cleared boolean flag, set to v:true if the highlight
5632 group attributes are cleared or not yet
5633 specified. See |highlight-clear|.
5634 cterm cterm attributes. See |highlight-cterm|.
5635 ctermbg cterm background color.
5636 See |highlight-ctermbg|.
5637 ctermfg cterm foreground color.
5638 See |highlight-ctermfg|.
5639 ctermul cterm underline color. See |highlight-ctermul|.
5640 default boolean flag, set to v:true if the highlight
5641 group link is a default link. See
5642 |highlight-default|.
5643 font highlight group font. See |highlight-font|.
5644 gui gui attributes. See |highlight-gui|.
5645 guibg gui background color. See |highlight-guibg|.
5646 guifg gui foreground color. See |highlight-guifg|.
5647 guisp gui special color. See |highlight-guisp|.
5648 id highlight group ID.
5649 linksto linked highlight group name.
5650 See |:highlight-link|.
5651 name highlight group name. See |group-name|.
5652 start start terminal keycode. See |highlight-start|.
5653 stop stop terminal keycode. See |highlight-stop|.
5654 term term attributes. See |highlight-term|.
5655
5656 The 'term', 'cterm' and 'gui' items in the above Dictionary
5657 have a dictionary value with the following optional boolean
5658 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5659 'reverse', 'inverse' and 'strikethrough'.
5660
5661 Example(s): >
5662 :echo hlget()
5663 :echo hlget('ModeMsg')
5664 :echo hlget('Number', v:true)
5665<
5666 Can also be used as a |method|: >
5667 GetName()->hlget()
5668<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005669 Return type: list<dict<any>>
5670
5671
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005672hlset({list}) *hlset()*
5673 Creates or modifies the attributes of a List of highlight
5674 groups. Each item in {list} is a dictionary containing the
5675 attributes of a highlight group. See |hlget()| for the list of
5676 supported items in this dictionary.
5677
5678 In addition to the items described in |hlget()|, the following
5679 additional items are supported in the dictionary:
5680
5681 force boolean flag to force the creation of
5682 a link for an existing highlight group
5683 with attributes.
5684
5685 The highlight group is identified using the 'name' item and
5686 the 'id' item (if supplied) is ignored. If a highlight group
5687 with a specified name doesn't exist, then it is created.
5688 Otherwise the attributes of an existing highlight group are
5689 modified.
5690
5691 If an empty dictionary value is used for the 'term' or 'cterm'
5692 or 'gui' entries, then the corresponding attributes are
5693 cleared. If the 'cleared' item is set to v:true, then all the
5694 attributes of the highlight group are cleared.
5695
5696 The 'linksto' item can be used to link a highlight group to
5697 another highlight group. See |:highlight-link|.
5698
5699 Returns zero for success, -1 for failure.
5700
5701 Example(s): >
5702 " add bold attribute to the Visual highlight group
5703 :call hlset([#{name: 'Visual',
5704 \ term: #{reverse: 1 , bold: 1}}])
5705 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5706 :let l = hlget()
5707 :call hlset(l)
5708 " clear the Search highlight group
5709 :call hlset([#{name: 'Search', cleared: v:true}])
5710 " clear the 'term' attributes for a highlight group
5711 :call hlset([#{name: 'Title', term: {}}])
5712 " create the MyHlg group linking it to DiffAdd
5713 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5714 " remove the MyHlg group link
5715 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5716 " clear the attributes and a link
5717 :call hlset([#{name: 'MyHlg', cleared: v:true,
5718 \ linksto: 'NONE'}])
5719<
5720 Can also be used as a |method|: >
5721 GetAttrList()->hlset()
5722<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005723 Return type: |Number|
5724
5725hlID({name}) *hlID()*
5726 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005727 with name {name}. When the highlight group doesn't exist,
5728 zero is returned.
5729 This can be used to retrieve information about the highlight
5730 group. For example, to get the background color of the
5731 "Comment" group: >
5732 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5733< *highlightID()*
5734 Obsolete name: highlightID().
5735
5736 Can also be used as a |method|: >
5737 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005738<
5739 Return type: |Number|
5740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005741
5742hostname() *hostname()*
5743 The result is a String, which is the name of the machine on
5744 which Vim is currently running. Machine names greater than
5745 256 characters long are truncated.
5746
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005747 Return type: |String|
5748
5749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005750iconv({string}, {from}, {to}) *iconv()*
5751 The result is a String, which is the text {string} converted
5752 from encoding {from} to encoding {to}.
5753 When the conversion completely fails an empty string is
5754 returned. When some characters could not be converted they
5755 are replaced with "?".
5756 The encoding names are whatever the iconv() library function
5757 can accept, see ":!man 3 iconv".
5758 Most conversions require Vim to be compiled with the |+iconv|
5759 feature. Otherwise only UTF-8 to latin1 conversion and back
5760 can be done.
5761 This can be used to display messages with special characters,
5762 no matter what 'encoding' is set to. Write the message in
5763 UTF-8 and use: >
5764 echo iconv(utf8_str, "utf-8", &enc)
5765< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5766 from/to UCS-2 is automatically changed to use UTF-8. You
5767 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5768
5769 Can also be used as a |method|: >
5770 GetText()->iconv('latin1', 'utf-8')
5771<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005772 Return type: |String|
5773
5774
h-east624bb832024-11-09 18:37:32 +01005775id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005776 The result is a unique String associated with the {item} and
5777 not with the {item}'s contents. It is only valid while the
5778 {item} exists and is referenced. It is valid only in the
5779 instance of vim that produces the result. The whole idea is
5780 that `id({item})` does not change if the contents of {item}
5781 changes. This is useful as a `key` for creating an identity
5782 dictionary, rather than one based on equals.
5783
5784 This operation does not reference {item} and there is no
5785 function to convert the `id` to the {item}. It may be useful to
5786 have a map of `id` to {item}. The following >
5787 var referenceMap: dict<any>
5788 var id = item->id()
5789 referenceMap[id] = item
5790< prevents {item} from being garbage collected and provides a
5791 way to get the {item} from the `id`.
5792
5793 {item} may be a List, Dictionary, Object, Job, Channel or
5794 Blob. If the item is not a permitted type, or it is a null
5795 value, then an empty String is returned.
5796
5797 Can also be used as a |method|: >
5798 GetItem()->id()
5799<
5800 Return type: |String|
5801
5802
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005803indent({lnum}) *indent()*
5804 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005805 current buffer. The indent is counted in spaces, the value
5806 of 'tabstop' is relevant. {lnum} is used just like in
5807 |getline()|.
5808 When {lnum} is invalid -1 is returned. In |Vim9| script an
5809 error is given.
5810
5811 Can also be used as a |method|: >
5812 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005813<
5814 Return type: |Number|
5815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005816
5817index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005818 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005819 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005820
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005821 If {object} is a |List| return the lowest index where the item
5822 has a value equal to {expr}. There is no automatic
5823 conversion, so the String "4" is different from the Number 4.
5824 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005825 of 'ignorecase' is not used here, case matters as indicated by
5826 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005827
5828 If {object} is |Blob| return the lowest index where the byte
5829 value is equal to {expr}.
5830
5831 If {start} is given then start looking at the item with index
5832 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005834 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5835 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005837 -1 is returned when {expr} is not found in {object}.
5838 Example: >
5839 :let idx = index(words, "the")
5840 :if index(numbers, 123) >= 0
5841
5842< Can also be used as a |method|: >
5843 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005844<
5845 Return type: |Number|
5846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005847
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005848indexof({object}, {expr} [, {opts}]) *indexof()*
5849 Returns the index of an item in {object} where {expr} is
5850 v:true. {object} must be a |List| or a |Blob|.
5851
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005852 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005853 List until the expression is v:true and return the index of
5854 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005855
5856 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005857 Blob until the expression is v:true and return the index of
5858 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005859
5860 {expr} must be a |string| or |Funcref|.
5861
5862 If {expr} is a |string|: If {object} is a |List|, inside
5863 {expr} |v:key| has the index of the current List item and
5864 |v:val| has the value of the item. If {object} is a |Blob|,
5865 inside {expr} |v:key| has the index of the current byte and
5866 |v:val| has the byte value.
5867
5868 If {expr} is a |Funcref| it must take two arguments:
5869 1. the key or the index of the current item.
5870 2. the value of the current item.
5871 The function must return |TRUE| if the item is found and the
5872 search should stop.
5873
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005874 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005875 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005876 startidx start evaluating {expr} at the item with this
5877 index; may be negative for an item relative to
5878 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005879 Returns -1 when {expr} evaluates to v:false for all the items.
5880 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005881 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5882 :echo indexof(l, "v:val.n == 20")
5883 :echo indexof(l, {i, v -> v.n == 30})
5884 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005885
5886< Can also be used as a |method|: >
5887 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005888<
5889 Return type: |Number|
5890
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005891
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005892input({prompt} [, {text} [, {completion}]]) *input()*
5893 The result is a String, which is whatever the user typed on
5894 the command-line. The {prompt} argument is either a prompt
5895 string, or a blank string (for no prompt). A '\n' can be used
5896 in the prompt to start a new line.
5897 The highlighting set with |:echohl| is used for the prompt.
5898 The input is entered just like a command-line, with the same
5899 editing commands and mappings. There is a separate history
5900 for lines typed for input().
5901 Example: >
5902 :if input("Coffee or beer? ") == "beer"
5903 : echo "Cheers!"
5904 :endif
5905<
5906 If the optional {text} argument is present and not empty, this
5907 is used for the default reply, as if the user typed this.
5908 Example: >
5909 :let color = input("Color? ", "white")
5910
5911< The optional {completion} argument specifies the type of
5912 completion supported for the input. Without it completion is
5913 not performed. The supported completion types are the same as
5914 that can be supplied to a user-defined command using the
5915 "-complete=" argument. Refer to |:command-completion| for
5916 more information. Example: >
5917 let fname = input("File: ", "", "file")
5918<
5919 NOTE: This function must not be used in a startup file, for
5920 the versions that only run in GUI mode (e.g., the Win32 GUI).
5921 Note: When input() is called from within a mapping it will
5922 consume remaining characters from that mapping, because a
5923 mapping is handled like the characters were typed.
5924 Use |inputsave()| before input() and |inputrestore()|
5925 after input() to avoid that. Another solution is to avoid
5926 that further characters follow in the mapping, e.g., by using
5927 |:execute| or |:normal|.
5928
5929 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005930 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005931 :function GetFoo()
5932 : call inputsave()
5933 : let g:Foo = input("enter search pattern: ")
5934 : call inputrestore()
5935 :endfunction
5936
5937< Can also be used as a |method|: >
5938 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005939<
5940 Return type: |String|
5941
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005942
5943inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5944 Like |input()|, but when the GUI is running and text dialogs
5945 are supported, a dialog window pops up to input the text.
5946 Example: >
5947 :let n = inputdialog("value for shiftwidth", shiftwidth())
5948 :if n != ""
5949 : let &sw = n
5950 :endif
5951< When the dialog is cancelled {cancelreturn} is returned. When
5952 omitted an empty string is returned.
5953 Hitting <Enter> works like pressing the OK button. Hitting
5954 <Esc> works like pressing the Cancel button.
5955 NOTE: Command-line completion is not supported.
5956
5957 Can also be used as a |method|: >
5958 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005959<
5960 Return type: |String|
5961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005962
5963inputlist({textlist}) *inputlist()*
5964 {textlist} must be a |List| of strings. This |List| is
5965 displayed, one string per line. The user will be prompted to
5966 enter a number, which is returned.
5967 The user can also select an item by clicking on it with the
5968 mouse, if the mouse is enabled in the command line ('mouse' is
5969 "a" or includes "c"). For the first string 0 is returned.
5970 When clicking above the first item a negative number is
5971 returned. When clicking on the prompt one more than the
5972 length of {textlist} is returned.
5973 Make sure {textlist} has less than 'lines' entries, otherwise
5974 it won't work. It's a good idea to put the entry number at
5975 the start of the string. And put a prompt in the first item.
5976 Example: >
5977 let color = inputlist(['Select color:', '1. red',
5978 \ '2. green', '3. blue'])
5979
5980< Can also be used as a |method|: >
5981 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005982<
5983 Return type: |Number|
5984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005985
5986inputrestore() *inputrestore()*
5987 Restore typeahead that was saved with a previous |inputsave()|.
5988 Should be called the same number of times inputsave() is
5989 called. Calling it more often is harmless though.
5990 Returns TRUE when there is nothing to restore, FALSE otherwise.
5991
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005992 Return type: |Number|
5993
5994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005995inputsave() *inputsave()*
5996 Preserve typeahead (also from mappings) and clear it, so that
5997 a following prompt gets input from the user. Should be
5998 followed by a matching inputrestore() after the prompt. Can
5999 be used several times, in which case there must be just as
6000 many inputrestore() calls.
6001 Returns TRUE when out of memory, FALSE otherwise.
6002
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006003 Return type: |Number|
6004
6005
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006006inputsecret({prompt} [, {text}]) *inputsecret()*
6007 This function acts much like the |input()| function with but
6008 two exceptions:
6009 a) the user's response will be displayed as a sequence of
6010 asterisks ("*") thereby keeping the entry secret, and
6011 b) the user's response will not be recorded on the input
6012 |history| stack.
6013 The result is a String, which is whatever the user actually
6014 typed on the command-line in response to the issued prompt.
6015 NOTE: Command-line completion is not supported.
6016
6017 Can also be used as a |method|: >
6018 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006019<
6020 Return type: |String|
6021
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006022
6023insert({object}, {item} [, {idx}]) *insert()*
6024 When {object} is a |List| or a |Blob| insert {item} at the start
6025 of it.
6026
6027 If {idx} is specified insert {item} before the item with index
6028 {idx}. If {idx} is zero it goes before the first item, just
6029 like omitting {idx}. A negative {idx} is also possible, see
6030 |list-index|. -1 inserts just before the last item.
6031
6032 Returns the resulting |List| or |Blob|. Examples: >
6033 :let mylist = insert([2, 3, 5], 1)
6034 :call insert(mylist, 4, -1)
6035 :call insert(mylist, 6, len(mylist))
6036< The last example can be done simpler with |add()|.
6037 Note that when {item} is a |List| it is inserted as a single
6038 item. Use |extend()| to concatenate |Lists|.
6039
6040 Can also be used as a |method|: >
6041 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006042<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006043 Return type: |Number|
6044
6045
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006046 *instanceof()* *E614* *E616* *E693*
6047instanceof({object}, {class})
6048 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006049 argument is a direct or indirect instance of a |Class|,
6050 |Interface|, or class |:type| alias specified by {class}.
6051 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006052 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006053 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006054 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006055
6056< Can also be used as a |method|: >
6057 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006058<
6059 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006061interrupt() *interrupt()*
6062 Interrupt script execution. It works more or less like the
6063 user typing CTRL-C, most commands won't execute and control
6064 returns to the user. This is useful to abort execution
6065 from lower down, e.g. in an autocommand. Example: >
6066 :function s:check_typoname(file)
6067 : if fnamemodify(a:file, ':t') == '['
6068 : echomsg 'Maybe typo'
6069 : call interrupt()
6070 : endif
6071 :endfunction
6072 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006073<
6074 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006075
6076invert({expr}) *invert()*
6077 Bitwise invert. The argument is converted to a number. A
6078 List, Dict or Float argument causes an error. Example: >
6079 :let bits = invert(bits)
6080< Can also be used as a |method|: >
6081 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006082<
6083 Return type: |Number|
6084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006085
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006086isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006087 The result is a Number, which is |TRUE| when {path} is an
6088 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006089 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006090 On MS-Windows, it is considered absolute when it starts with an
6091 optional drive prefix and is followed by a '\' or '/'. UNC paths
6092 are always absolute.
6093 Example: >
6094 echo isabsolutepath('/usr/share/') " 1
6095 echo isabsolutepath('./foobar') " 0
6096 echo isabsolutepath('C:\Windows') " 1
6097 echo isabsolutepath('foobar') " 0
6098 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006099<
LemonBoydca1d402022-04-28 15:26:33 +01006100 Can also be used as a |method|: >
6101 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006102<
6103 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006104
6105
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006106isdirectory({directory}) *isdirectory()*
6107 The result is a Number, which is |TRUE| when a directory
6108 with the name {directory} exists. If {directory} doesn't
6109 exist, or isn't a directory, the result is |FALSE|. {directory}
6110 is any expression, which is used as a String.
6111
6112 Can also be used as a |method|: >
6113 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006114<
6115 Return type: |Number|
6116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006117
6118isinf({expr}) *isinf()*
6119 Return 1 if {expr} is a positive infinity, or -1 a negative
6120 infinity, otherwise 0. >
6121 :echo isinf(1.0 / 0.0)
6122< 1 >
6123 :echo isinf(-1.0 / 0.0)
6124< -1
6125
6126 Can also be used as a |method|: >
6127 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006128<
6129 Return type: |Number|
6130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006131
6132islocked({expr}) *islocked()* *E786*
6133 The result is a Number, which is |TRUE| when {expr} is the
6134 name of a locked variable.
6135 The string argument {expr} must be the name of a variable,
6136 |List| item or |Dictionary| entry, not the variable itself!
6137 Example: >
6138 :let alist = [0, ['a', 'b'], 2, 3]
6139 :lockvar 1 alist
6140 :echo islocked('alist') " 1
6141 :echo islocked('alist[1]') " 0
6142
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006143< When {expr} is a variable that does not exist -1 is returned.
6144 If {expr} uses a range, list or dict index that is out of
6145 range or does not exist you get an error message. Use
6146 |exists()| to check for existence.
6147 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006148
6149 Can also be used as a |method|: >
6150 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006151<
6152 Return type: |Number|
6153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006154
6155isnan({expr}) *isnan()*
6156 Return |TRUE| if {expr} is a float with value NaN. >
6157 echo isnan(0.0 / 0.0)
6158< 1
6159
6160 Can also be used as a |method|: >
6161 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006162<
6163 Return type: |Number|
6164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006165
6166items({dict}) *items()*
6167 Return a |List| with all the key-value pairs of {dict}. Each
6168 |List| item is a list with two items: the key of a {dict}
6169 entry and the value of this entry. The |List| is in arbitrary
6170 order. Also see |keys()| and |values()|.
6171 Example: >
6172 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006173 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006174 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006175<
6176 A List or a String argument is also supported. In these
6177 cases, items() returns a List with the index and the value at
6178 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006179
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006180 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006181 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006182<
6183 Return type: list<list<any>> or list<any>
6184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006185
6186job_ functions are documented here: |job-functions-details|
6187
6188
6189join({list} [, {sep}]) *join()*
6190 Join the items in {list} together into one String.
6191 When {sep} is specified it is put in between the items. If
6192 {sep} is omitted a single space is used.
6193 Note that {sep} is not added at the end. You might want to
6194 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006195 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006196< String items are used as-is. |Lists| and |Dictionaries| are
6197 converted into a string like with |string()|.
6198 The opposite function is |split()|.
6199
6200 Can also be used as a |method|: >
6201 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006202<
6203 Return type: |String|
6204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006205
6206js_decode({string}) *js_decode()*
6207 This is similar to |json_decode()| with these differences:
6208 - Object key names do not have to be in quotes.
6209 - Strings can be in single quotes.
6210 - Empty items in an array (between two commas) are allowed and
6211 result in v:none items.
6212
6213 Can also be used as a |method|: >
6214 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006215<
6216 Return type: any, depending on {varname}
6217
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006218
6219js_encode({expr}) *js_encode()*
6220 This is similar to |json_encode()| with these differences:
6221 - Object key names are not in quotes.
6222 - v:none items in an array result in an empty item between
6223 commas.
6224 For example, the Vim object:
6225 [1,v:none,{"one":1},v:none] ~
6226 Will be encoded as:
6227 [1,,{one:1},,] ~
6228 While json_encode() would produce:
6229 [1,null,{"one":1},null] ~
6230 This encoding is valid for JavaScript. It is more efficient
6231 than JSON, especially when using an array with optional items.
6232
6233 Can also be used as a |method|: >
6234 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006235<
6236 Return type: |String|
6237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006238
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006239json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006240 This parses a JSON formatted string and returns the equivalent
6241 in Vim values. See |json_encode()| for the relation between
6242 JSON and Vim values.
6243 The decoding is permissive:
6244 - A trailing comma in an array and object is ignored, e.g.
6245 "[1, 2, ]" is the same as "[1, 2]".
6246 - Integer keys are accepted in objects, e.g. {1:2} is the
6247 same as {"1":2}.
6248 - More floating point numbers are recognized, e.g. "1." for
6249 "1.0", or "001.2" for "1.2". Special floating point values
6250 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6251 are accepted.
6252 - Leading zeroes in integer numbers are ignored, e.g. "012"
6253 for "12" or "-012" for "-12".
6254 - Capitalization is ignored in literal names null, true or
6255 false, e.g. "NULL" for "null", "True" for "true".
6256 - Control characters U+0000 through U+001F which are not
6257 escaped in strings are accepted, e.g. " " (tab
6258 character in string) for "\t".
6259 - An empty JSON expression or made of only spaces is accepted
6260 and results in v:none.
6261 - Backslash in an invalid 2-character sequence escape is
6262 ignored, e.g. "\a" is decoded as "a".
6263 - A correct surrogate pair in JSON strings should normally be
6264 a 12 character sequence such as "\uD834\uDD1E", but
6265 json_decode() silently accepts truncated surrogate pairs
6266 such as "\uD834" or "\uD834\u"
6267 *E938*
6268 A duplicate key in an object, valid in rfc7159, is not
6269 accepted by json_decode() as the result must be a valid Vim
6270 type, e.g. this fails: {"a":"b", "a":"c"}
6271
6272 Can also be used as a |method|: >
6273 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006274<
6275 Return type: any, depending on {varname}
6276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006277
6278json_encode({expr}) *json_encode()*
6279 Encode {expr} as JSON and return this as a string.
6280 The encoding is specified in:
6281 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006282 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006283 |Number| decimal number
6284 |Float| floating point number
6285 Float nan "NaN"
6286 Float inf "Infinity"
6287 Float -inf "-Infinity"
6288 |String| in double quotes (possibly null)
6289 |Funcref| not possible, error
6290 |List| as an array (possibly null); when
6291 used recursively: []
6292 |Dict| as an object (possibly null); when
6293 used recursively: {}
6294 |Blob| as an array of the individual bytes
6295 v:false "false"
6296 v:true "true"
6297 v:none "null"
6298 v:null "null"
6299 Note that NaN and Infinity are passed on as values. This is
6300 missing in the JSON standard, but several implementations do
6301 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006302 If a string contains an illegal character then the replacement
6303 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006304
6305 Can also be used as a |method|: >
6306 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006307<
6308 Return type: |String|
6309
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006310
6311keys({dict}) *keys()*
6312 Return a |List| with all the keys of {dict}. The |List| is in
6313 arbitrary order. Also see |items()| and |values()|.
6314
6315 Can also be used as a |method|: >
6316 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006317<
6318 Return type: list<string>
6319
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006320
zeertzjqcdc83932022-09-12 13:38:41 +01006321keytrans({string}) *keytrans()*
6322 Turn the internal byte representation of keys into a form that
6323 can be used for |:map|. E.g. >
6324 :let xx = "\<C-Home>"
6325 :echo keytrans(xx)
6326< <C-Home>
6327
6328 Can also be used as a |method|: >
6329 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006330<
6331 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006332
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006333
6334len({expr}) *len()* *E701*
6335 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006336 When {expr} is a String or a Number the length in bytes is
6337 used, as with |strlen()|.
6338 When {expr} is a |List| the number of items in the |List| is
6339 returned.
6340 When {expr} is a |Blob| the number of bytes is returned.
6341 When {expr} is a |Dictionary| the number of entries in the
6342 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006343 When {expr} is an |Object|, invokes the len() method in the
6344 object (if present) to get the length (|object-len()|).
6345 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006346
6347 Can also be used as a |method|: >
6348 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006349<
6350 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006351
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006352
6353 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006354libcall({libname}, {funcname}, {argument})
6355 Call function {funcname} in the run-time library {libname}
6356 with single argument {argument}.
6357 This is useful to call functions in a library that you
6358 especially made to be used with Vim. Since only one argument
6359 is possible, calling standard library functions is rather
6360 limited.
6361 The result is the String returned by the function. If the
6362 function returns NULL, this will appear as an empty string ""
6363 to Vim.
6364 If the function returns a number, use libcallnr()!
6365 If {argument} is a number, it is passed to the function as an
6366 int; if {argument} is a string, it is passed as a
6367 null-terminated string.
6368 This function will fail in |restricted-mode|.
6369
6370 libcall() allows you to write your own 'plug-in' extensions to
6371 Vim without having to recompile the program. It is NOT a
6372 means to call system functions! If you try to do so Vim will
6373 very probably crash.
6374
6375 For Win32, the functions you write must be placed in a DLL
6376 and use the normal C calling convention (NOT Pascal which is
6377 used in Windows System DLLs). The function must take exactly
6378 one parameter, either a character pointer or a long integer,
6379 and must return a character pointer or NULL. The character
6380 pointer returned must point to memory that will remain valid
6381 after the function has returned (e.g. in static data in the
6382 DLL). If it points to allocated memory, that memory will
6383 leak away. Using a static buffer in the function should work,
6384 it's then freed when the DLL is unloaded.
6385
6386 WARNING: If the function returns a non-valid pointer, Vim may
6387 crash! This also happens if the function returns a number,
6388 because Vim thinks it's a pointer.
6389 For Win32 systems, {libname} should be the filename of the DLL
6390 without the ".DLL" suffix. A full path is only required if
6391 the DLL is not in the usual places.
6392 For Unix: When compiling your own plugins, remember that the
6393 object code must be compiled as position-independent ('PIC').
6394 {only in Win32 and some Unix versions, when the |+libcall|
6395 feature is present}
6396 Examples: >
6397 :echo libcall("libc.so", "getenv", "HOME")
6398
6399< Can also be used as a |method|, the base is passed as the
6400 third argument: >
6401 GetValue()->libcall("libc.so", "getenv")
6402<
6403 *libcallnr()*
6404libcallnr({libname}, {funcname}, {argument})
6405 Just like |libcall()|, but used for a function that returns an
6406 int instead of a string.
6407 {only in Win32 on some Unix versions, when the |+libcall|
6408 feature is present}
6409 Examples: >
6410 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6411 :call libcallnr("libc.so", "printf", "Hello World!\n")
6412 :call libcallnr("libc.so", "sleep", 10)
6413<
6414 Can also be used as a |method|, the base is passed as the
6415 third argument: >
6416 GetValue()->libcallnr("libc.so", "printf")
6417<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006418 Return type: |String|
6419
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006420
6421line({expr} [, {winid}]) *line()*
6422 The result is a Number, which is the line number of the file
6423 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006424 See |getpos()| for accepted positions.
6425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006426 To get the column number use |col()|. To get both use
6427 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006428
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006429 With the optional {winid} argument the values are obtained for
6430 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006431
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006432 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006434 Examples: >
6435 line(".") line number of the cursor
6436 line(".", winid) idem, in window "winid"
6437 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006438 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006439<
6440 To jump to the last known position when opening a file see
6441 |last-position-jump|.
6442
6443 Can also be used as a |method|: >
6444 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006445<
6446 Return type: |Number|
6447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006448
6449line2byte({lnum}) *line2byte()*
6450 Return the byte count from the start of the buffer for line
6451 {lnum}. This includes the end-of-line character, depending on
6452 the 'fileformat' option for the current buffer. The first
6453 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6454 This can also be used to get the byte count for the line just
6455 below the last line: >
6456 line2byte(line("$") + 1)
6457< This is the buffer size plus one. If 'fileencoding' is empty
6458 it is the file size plus one. {lnum} is used like with
6459 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6460 feature has been disabled at compile time, -1 is returned.
6461 Also see |byte2line()|, |go| and |:goto|.
6462
6463 Can also be used as a |method|: >
6464 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006465<
6466 Return type: |Number|
6467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006468
6469lispindent({lnum}) *lispindent()*
6470 Get the amount of indent for line {lnum} according the lisp
6471 indenting rules, as with 'lisp'.
6472 The indent is counted in spaces, the value of 'tabstop' is
6473 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006474 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006475 error is given.
6476
6477 Can also be used as a |method|: >
6478 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006479<
6480 Return type: |Number|
6481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006482
6483list2blob({list}) *list2blob()*
6484 Return a Blob concatenating all the number values in {list}.
6485 Examples: >
6486 list2blob([1, 2, 3, 4]) returns 0z01020304
6487 list2blob([]) returns 0z
6488< Returns an empty Blob on error. If one of the numbers is
6489 negative or more than 255 error *E1239* is given.
6490
6491 |blob2list()| does the opposite.
6492
6493 Can also be used as a |method|: >
6494 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006495<
6496 Return type: |Blob|
6497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006498
6499list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006500 Convert each number in {list} to a character string and
6501 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006502 list2str([32]) returns " "
6503 list2str([65, 66, 67]) returns "ABC"
6504< The same can be done (slowly) with: >
6505 join(map(list, {nr, val -> nr2char(val)}), '')
6506< |str2list()| does the opposite.
6507
6508 When {utf8} is omitted or zero, the current 'encoding' is used.
6509 When {utf8} is TRUE, always return UTF-8 characters.
6510 With UTF-8 composing characters work as expected: >
6511 list2str([97, 769]) returns "á"
6512<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006513 Returns an empty string on error.
6514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006515 Can also be used as a |method|: >
6516 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006517<
6518 Return type: |String|
6519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006520
6521listener_add({callback} [, {buf}]) *listener_add()*
6522 Add a callback function that will be invoked when changes have
6523 been made to buffer {buf}.
6524 {buf} refers to a buffer name or number. For the accepted
6525 values, see |bufname()|. When {buf} is omitted the current
6526 buffer is used.
6527 Returns a unique ID that can be passed to |listener_remove()|.
6528
6529 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006530 bufnr the buffer that was changed
6531 start first changed line number
6532 end first line number below the change
6533 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006534 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006535 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006536
6537 Example: >
6538 func Listener(bufnr, start, end, added, changes)
6539 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6540 endfunc
6541 call listener_add('Listener', bufnr)
6542
Bram Moolenaar944697a2022-02-20 19:48:20 +00006543< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006544 dictionary with these entries:
6545 lnum the first line number of the change
6546 end the first line below the change
6547 added number of lines added; negative if lines were
6548 deleted
6549 col first column in "lnum" that was affected by
6550 the change; one if unknown or the whole line
6551 was affected; this is a byte index, first
6552 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006553 When lines are inserted (not when a line is split, e.g. by
6554 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006555 lnum line above which the new line is added
6556 end equal to "lnum"
6557 added number of lines inserted
6558 col 1
6559 When lines are deleted the values are:
6560 lnum the first deleted line
6561 end the line below the first deleted line, before
6562 the deletion was done
6563 added negative, number of lines deleted
6564 col 1
6565 When lines are changed:
6566 lnum the first changed line
6567 end the line below the last changed line
6568 added 0
6569 col first column with a change or 1
6570
6571 The entries are in the order the changes were made, thus the
6572 most recent change is at the end. The line numbers are valid
6573 when the callback is invoked, but later changes may make them
6574 invalid, thus keeping a copy for later might not work.
6575
6576 The {callback} is invoked just before the screen is updated,
6577 when |listener_flush()| is called or when a change is being
6578 made that changes the line count in a way it causes a line
6579 number in the list of changes to become invalid.
6580
6581 The {callback} is invoked with the text locked, see
6582 |textlock|. If you do need to make changes to the buffer, use
6583 a timer to do this later |timer_start()|.
6584
6585 The {callback} is not invoked when the buffer is first loaded.
6586 Use the |BufReadPost| autocmd event to handle the initial text
6587 of a buffer.
6588 The {callback} is also not invoked when the buffer is
6589 unloaded, use the |BufUnload| autocmd event for that.
6590
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006591 Returns zero if {callback} or {buf} is invalid.
6592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006593 Can also be used as a |method|, the base is passed as the
6594 second argument: >
6595 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006596<
6597 Return type: |Number|
6598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006599
6600listener_flush([{buf}]) *listener_flush()*
6601 Invoke listener callbacks for buffer {buf}. If there are no
6602 pending changes then no callbacks are invoked.
6603
6604 {buf} refers to a buffer name or number. For the accepted
6605 values, see |bufname()|. When {buf} is omitted the current
6606 buffer is used.
6607
6608 Can also be used as a |method|: >
6609 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006610<
6611 Return type: |Number|
6612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006613
6614listener_remove({id}) *listener_remove()*
6615 Remove a listener previously added with listener_add().
6616 Returns FALSE when {id} could not be found, TRUE when {id} was
6617 removed.
6618
6619 Can also be used as a |method|: >
6620 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006621<
6622 Return type: |Number|
6623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006624
6625localtime() *localtime()*
6626 Return the current time, measured as seconds since 1st Jan
6627 1970. See also |strftime()|, |strptime()| and |getftime()|.
6628
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006629 Return type: |Number|
6630
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006631
6632log({expr}) *log()*
6633 Return the natural logarithm (base e) of {expr} as a |Float|.
6634 {expr} must evaluate to a |Float| or a |Number| in the range
6635 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006636 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006637 Examples: >
6638 :echo log(10)
6639< 2.302585 >
6640 :echo log(exp(5))
6641< 5.0
6642
6643 Can also be used as a |method|: >
6644 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006645<
6646 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006647
6648
6649log10({expr}) *log10()*
6650 Return the logarithm of Float {expr} to base 10 as a |Float|.
6651 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006652 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006653 Examples: >
6654 :echo log10(1000)
6655< 3.0 >
6656 :echo log10(0.01)
6657< -2.0
6658
6659 Can also be used as a |method|: >
6660 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006661<
6662 Return type: |Float|
6663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006664
6665luaeval({expr} [, {expr}]) *luaeval()*
6666 Evaluate Lua expression {expr} and return its result converted
6667 to Vim data structures. Second {expr} may hold additional
6668 argument accessible as _A inside first {expr}.
6669 Strings are returned as they are.
6670 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006671 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006672 Dictionaries and lists obtained by vim.eval() are returned
6673 as-is.
6674 Other objects are returned as zero without any errors.
6675 See |lua-luaeval| for more details.
6676 Note that in a `:def` function local variables are not visible
6677 to {expr}.
6678
6679 Can also be used as a |method|: >
6680 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006681<
6682 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006684 {only available when compiled with the |+lua| feature}
6685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006686
6687map({expr1}, {expr2}) *map()*
6688 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006689 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006690 item in {expr1} with the result of evaluating {expr2}.
6691 For a |Blob| each byte is replaced.
6692 For a |String|, each character, including composing
6693 characters, is replaced.
6694 If the item type changes you may want to use |mapnew()| to
6695 create a new List or Dictionary. This is required when using
6696 Vim9 script.
6697
6698 {expr2} must be a |String| or |Funcref|.
6699
6700 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6701 of the current item. For a |Dictionary| |v:key| has the key
6702 of the current item and for a |List| |v:key| has the index of
6703 the current item. For a |Blob| |v:key| has the index of the
6704 current byte. For a |String| |v:key| has the index of the
6705 current character.
6706 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006707 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006708< This puts "> " before and " <" after each item in "mylist".
6709
6710 Note that {expr2} is the result of an expression and is then
6711 used as an expression again. Often it is good to use a
6712 |literal-string| to avoid having to double backslashes. You
6713 still have to double ' quotes
6714
6715 If {expr2} is a |Funcref| it is called with two arguments:
6716 1. The key or the index of the current item.
6717 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006718 With a legacy script lambda you don't get an error if it only
6719 accepts one argument, but with a Vim9 lambda you get "E1106:
6720 One argument too many", the number of arguments must match.
6721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006722 The function must return the new value of the item. Example
6723 that changes each value by "key-value": >
6724 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006725 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006726 endfunc
6727 call map(myDict, function('KeyValue'))
6728< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006729 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006730< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006731 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006732< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006733 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006734<
6735 The operation is done in-place for a |List| and |Dictionary|.
6736 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006737 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006738
6739< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6740 or a new |Blob| or |String|.
6741 When an error is encountered while evaluating {expr2} no
6742 further items in {expr1} are processed.
6743 When {expr2} is a Funcref errors inside a function are ignored,
6744 unless it was defined with the "abort" flag.
6745
6746 Can also be used as a |method|: >
6747 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006748<
6749 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6750 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006751
6752
6753maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6754 When {dict} is omitted or zero: Return the rhs of mapping
6755 {name} in mode {mode}. The returned String has special
6756 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006757 listing. When {dict} is TRUE a dictionary is returned, see
6758 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006759
6760 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006761 returned if {dict} is FALSE, otherwise returns an empty Dict.
6762 When the mapping for {name} is empty, then "<Nop>" is
6763 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006764
6765 The {name} can have special key names, like in the ":map"
6766 command.
6767
6768 {mode} can be one of these strings:
6769 "n" Normal
6770 "v" Visual (including Select)
6771 "o" Operator-pending
6772 "i" Insert
6773 "c" Cmd-line
6774 "s" Select
6775 "x" Visual
6776 "l" langmap |language-mapping|
6777 "t" Terminal-Job
6778 "" Normal, Visual and Operator-pending
6779 When {mode} is omitted, the modes for "" are used.
6780
6781 When {abbr} is there and it is |TRUE| use abbreviations
6782 instead of mappings.
6783
6784 When {dict} is there and it is |TRUE| return a dictionary
6785 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006786 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006787 "lhs" The {lhs} of the mapping as it would be typed
6788 "lhsraw" The {lhs} of the mapping as raw bytes
6789 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6790 form, only present when it differs from "lhsraw"
6791 "rhs" The {rhs} of the mapping as typed.
6792 "silent" 1 for a |:map-silent| mapping, else 0.
6793 "noremap" 1 if the {rhs} of the mapping is not remappable.
6794 "script" 1 if mapping was defined with <script>.
6795 "expr" 1 for an expression mapping (|:map-<expr>|).
6796 "buffer" 1 for a buffer local mapping (|:map-local|).
6797 "mode" Modes for which the mapping is defined. In
6798 addition to the modes mentioned above, these
6799 characters will be used:
6800 " " Normal, Visual and Operator-pending
6801 "!" Insert and Commandline mode
6802 (|mapmode-ic|)
6803 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006804 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006805 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006806 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006807 "lnum" The line number in "sid", zero if unknown.
6808 "nowait" Do not wait for other, longer mappings.
6809 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006810 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006811 "mode_bits" Vim's internal binary representation of "mode".
6812 |mapset()| ignores this; only "mode" is used.
6813 See |maplist()| for usage examples. The values
6814 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006815
6816 The dictionary can be used to restore a mapping with
6817 |mapset()|.
6818
6819 The mappings local to the current buffer are checked first,
6820 then the global mappings.
6821 This function can be used to map a key even when it's already
6822 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006823 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006824
6825< Can also be used as a |method|: >
6826 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006827<
6828 Return type: |String| or dict<any> depending on {dict}
6829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006830
6831mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6832 Check if there is a mapping that matches with {name} in mode
6833 {mode}. See |maparg()| for {mode} and special names in
6834 {name}.
6835 When {abbr} is there and it is |TRUE| use abbreviations
6836 instead of mappings.
6837 A match happens with a mapping that starts with {name} and
6838 with a mapping which is equal to the start of {name}.
6839
6840 matches mapping "a" "ab" "abc" ~
6841 mapcheck("a") yes yes yes
6842 mapcheck("abc") yes yes yes
6843 mapcheck("ax") yes no no
6844 mapcheck("b") no no no
6845
6846 The difference with maparg() is that mapcheck() finds a
6847 mapping that matches with {name}, while maparg() only finds a
6848 mapping for {name} exactly.
6849 When there is no mapping that starts with {name}, an empty
6850 String is returned. If there is one, the RHS of that mapping
6851 is returned. If there are several mappings that start with
6852 {name}, the RHS of one of them is returned. This will be
6853 "<Nop>" if the RHS is empty.
6854 The mappings local to the current buffer are checked first,
6855 then the global mappings.
6856 This function can be used to check if a mapping can be added
6857 without being ambiguous. Example: >
6858 :if mapcheck("_vv") == ""
6859 : map _vv :set guifont=7x13<CR>
6860 :endif
6861< This avoids adding the "_vv" mapping when there already is a
6862 mapping for "_v" or for "_vvv".
6863
6864 Can also be used as a |method|: >
6865 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006866<
6867 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006868
6869
Ernie Rael09661202022-04-25 14:40:44 +01006870maplist([{abbr}]) *maplist()*
6871 Returns a |List| of all mappings. Each List item is a |Dict|,
6872 the same as what is returned by |maparg()|, see
6873 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6874 abbreviations instead of mappings.
6875
6876 Example to show all mappings with 'MultiMatch' in rhs: >
6877 vim9script
6878 echo maplist()->filter(
6879 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006880< It can be tricky to find mappings for particular |:map-modes|.
6881 |mapping-dict|'s "mode_bits" can simplify this. For example,
6882 the mode_bits for Normal, Insert or Command-line modes are
6883 0x19. To find all the mappings available in those modes you
6884 can do: >
6885 vim9script
6886 var saved_maps = []
6887 for m in maplist()
6888 if and(m.mode_bits, 0x19) != 0
6889 saved_maps->add(m)
6890 endif
6891 endfor
6892 echo saved_maps->mapnew((_, m) => m.lhs)
6893< The values of the mode_bits are defined in Vim's src/vim.h
6894 file and they can be discovered at runtime using
6895 |:map-commands| and "maplist()". Example: >
6896 vim9script
6897 omap xyzzy <Nop>
6898 var op_bit = maplist()->filter(
6899 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6900 ounmap xyzzy
6901 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006902<
6903 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006904
6905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006906mapnew({expr1}, {expr2}) *mapnew()*
6907 Like |map()| but instead of replacing items in {expr1} a new
6908 List or Dictionary is created and returned. {expr1} remains
6909 unchanged. Items can still be changed by {expr2}, if you
6910 don't want that use |deepcopy()| first.
6911
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006912 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6913 depending on {expr1}
6914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006915
6916mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006917mapset({dict})
6918 Restore a mapping from a dictionary, possibly returned by
6919 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6920 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006921 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006922 feature allows copying mappings from one buffer to another.
6923 The dict.mode value may restore a single mapping that covers
6924 more than one mode, like with mode values of '!', ' ', 'nox',
6925 or 'v'. *E1276*
6926
6927 In the first form, {mode} and {abbr} should be the same as
6928 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006929 {mode} is used to define the mode in which the mapping is set,
6930 not the "mode" entry in {dict}.
6931 Example for saving and restoring a mapping: >
6932 let save_map = maparg('K', 'n', 0, 1)
6933 nnoremap K somethingelse
6934 ...
6935 call mapset('n', 0, save_map)
6936< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006937 e.g. with `:map!`, you need to save/restore the mapping for
6938 all of them, when they might differ.
6939
6940 In the second form, with {dict} as the only argument, mode
6941 and abbr are taken from the dict.
6942 Example: >
6943 vim9script
6944 var save_maps = maplist()->filter(
6945 (_, m) => m.lhs == 'K')
6946 nnoremap K somethingelse
6947 cnoremap K somethingelse2
6948 # ...
6949 unmap K
6950 for d in save_maps
6951 mapset(d)
6952 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006953<
6954 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006955
6956
6957match({expr}, {pat} [, {start} [, {count}]]) *match()*
6958 When {expr} is a |List| then this returns the index of the
6959 first item where {pat} matches. Each item is used as a
6960 String, |Lists| and |Dictionaries| are used as echoed.
6961
6962 Otherwise, {expr} is used as a String. The result is a
6963 Number, which gives the index (byte offset) in {expr} where
6964 {pat} matches.
6965
6966 A match at the first character or |List| item returns zero.
6967 If there is no match -1 is returned.
6968
6969 For getting submatches see |matchlist()|.
6970 Example: >
6971 :echo match("testing", "ing") " results in 4
6972 :echo match([1, 'x'], '\a') " results in 1
6973< See |string-match| for how {pat} is used.
6974 *strpbrk()*
6975 Vim doesn't have a strpbrk() function. But you can do: >
6976 :let sepidx = match(line, '[.,;: \t]')
6977< *strcasestr()*
6978 Vim doesn't have a strcasestr() function. But you can add
6979 "\c" to the pattern to ignore case: >
6980 :let idx = match(haystack, '\cneedle')
6981<
6982 If {start} is given, the search starts from byte index
6983 {start} in a String or item {start} in a |List|.
6984 The result, however, is still the index counted from the
6985 first character/item. Example: >
6986 :echo match("testing", "ing", 2)
6987< result is again "4". >
6988 :echo match("testing", "ing", 4)
6989< result is again "4". >
6990 :echo match("testing", "t", 2)
6991< result is "3".
6992 For a String, if {start} > 0 then it is like the string starts
6993 {start} bytes later, thus "^" will match at {start}. Except
6994 when {count} is given, then it's like matches before the
6995 {start} byte are ignored (this is a bit complicated to keep it
6996 backwards compatible).
6997 For a String, if {start} < 0, it will be set to 0. For a list
6998 the index is counted from the end.
6999 If {start} is out of range ({start} > strlen({expr}) for a
7000 String or {start} > len({expr}) for a |List|) -1 is returned.
7001
7002 When {count} is given use the {count}'th match. When a match
7003 is found in a String the search for the next one starts one
7004 character further. Thus this example results in 1: >
7005 echo match("testing", "..", 0, 2)
7006< In a |List| the search continues in the next item.
7007 Note that when {count} is added the way {start} works changes,
7008 see above.
7009
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007010 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007011 See |pattern| for the patterns that are accepted.
7012 The 'ignorecase' option is used to set the ignore-caseness of
7013 the pattern. 'smartcase' is NOT used. The matching is always
7014 done like 'magic' is set and 'cpoptions' is empty.
7015 Note that a match at the start is preferred, thus when the
7016 pattern is using "*" (any number of matches) it tends to find
7017 zero matches at the start instead of a number of matches
7018 further down in the text.
7019
7020 Can also be used as a |method|: >
7021 GetText()->match('word')
7022 GetList()->match('word')
7023<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007024 Return type: |Number|
7025
7026
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007027 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007028matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7029 Defines a pattern to be highlighted in the current window (a
7030 "match"). It will be highlighted with {group}. Returns an
7031 identification number (ID), which can be used to delete the
7032 match using |matchdelete()|. The ID is bound to the window.
7033 Matching is case sensitive and magic, unless case sensitivity
7034 or magicness are explicitly overridden in {pattern}. The
7035 'magic', 'smartcase' and 'ignorecase' options are not used.
7036 The "Conceal" value is special, it causes the match to be
7037 concealed.
7038
7039 The optional {priority} argument assigns a priority to the
7040 match. A match with a high priority will have its
7041 highlighting overrule that of a match with a lower priority.
7042 A priority is specified as an integer (negative numbers are no
7043 exception). If the {priority} argument is not specified, the
7044 default priority is 10. The priority of 'hlsearch' is zero,
7045 hence all matches with a priority greater than zero will
7046 overrule it. Syntax highlighting (see 'syntax') is a separate
7047 mechanism, and regardless of the chosen priority a match will
7048 always overrule syntax highlighting.
7049
7050 The optional {id} argument allows the request for a specific
7051 match ID. If a specified ID is already taken, an error
7052 message will appear and the match will not be added. An ID
7053 is specified as a positive integer (zero excluded). IDs 1, 2
7054 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007055 respectively. 3 is reserved for use by the |matchparen|
7056 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007057 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007058 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007059
7060 The optional {dict} argument allows for further custom
7061 values. Currently this is used to specify a match specific
7062 conceal character that will be shown for |hl-Conceal|
7063 highlighted matches. The dict can have the following members:
7064
7065 conceal Special character to show instead of the
7066 match (only for |hl-Conceal| highlighted
7067 matches, see |:syn-cchar|)
7068 window Instead of the current window use the
7069 window with this number or window ID.
7070
7071 The number of matches is not limited, as it is the case with
7072 the |:match| commands.
7073
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007074 Returns -1 on error.
7075
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007076 Example: >
7077 :highlight MyGroup ctermbg=green guibg=green
7078 :let m = matchadd("MyGroup", "TODO")
7079< Deletion of the pattern: >
7080 :call matchdelete(m)
7081
7082< A list of matches defined by |matchadd()| and |:match| are
7083 available from |getmatches()|. All matches can be deleted in
7084 one operation by |clearmatches()|.
7085
7086 Can also be used as a |method|: >
7087 GetGroup()->matchadd('TODO')
7088<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007089 Return type: |Number|
7090
7091
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007092 *matchaddpos()*
7093matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7094 Same as |matchadd()|, but requires a list of positions {pos}
7095 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007096 because it does not handle regular expressions and it sets
7097 buffer line boundaries to redraw screen. It is supposed to be
7098 used when fast match additions and deletions are required, for
7099 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007100
7101 {pos} is a list of positions. Each position can be one of
7102 these:
7103 - A number. This whole line will be highlighted. The first
7104 line has number 1.
7105 - A list with one number, e.g., [23]. The whole line with this
7106 number will be highlighted.
7107 - A list with two numbers, e.g., [23, 11]. The first number is
7108 the line number, the second one is the column number (first
7109 column is 1, the value must correspond to the byte index as
7110 |col()| would return). The character at this position will
7111 be highlighted.
7112 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7113 the third number gives the length of the highlight in bytes.
7114
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007115 Returns -1 on error.
7116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007117 Example: >
7118 :highlight MyGroup ctermbg=green guibg=green
7119 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7120< Deletion of the pattern: >
7121 :call matchdelete(m)
7122
7123< Matches added by |matchaddpos()| are returned by
7124 |getmatches()|.
7125
7126 Can also be used as a |method|: >
7127 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007128<
7129 Return type: |Number|
7130
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007131
7132matcharg({nr}) *matcharg()*
7133 Selects the {nr} match item, as set with a |:match|,
7134 |:2match| or |:3match| command.
7135 Return a |List| with two elements:
7136 The name of the highlight group used
7137 The pattern used.
7138 When {nr} is not 1, 2 or 3 returns an empty |List|.
7139 When there is no match item set returns ['', ''].
7140 This is useful to save and restore a |:match|.
7141 Highlighting matches using the |:match| commands are limited
7142 to three matches. |matchadd()| does not have this limitation.
7143
7144 Can also be used as a |method|: >
7145 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007146<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007147 Return type: list<string>
7148
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007149 *matchbufline()*
7150matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7151 Returns the |List| of matches in lines from {lnum} to {end} in
7152 buffer {buf} where {pat} matches.
7153
7154 {lnum} and {end} can either be a line number or the string "$"
7155 to refer to the last line in {buf}.
7156
7157 The {dict} argument supports following items:
7158 submatches include submatch information (|/\(|)
7159
7160 For each match, a |Dict| with the following items is returned:
7161 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007162 lnum line number where there is a match
7163 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007164 Note that there can be multiple matches in a single line.
7165
7166 This function works only for loaded buffers. First call
7167 |bufload()| if needed.
7168
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007169 See |match-pattern| for information about the effect of some
7170 option settings on the pattern.
7171
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007172 When {buf} is not a valid buffer, the buffer is not loaded or
7173 {lnum} or {end} is not valid then an error is given and an
7174 empty |List| is returned.
7175
7176 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007177 " Assuming line 3 in buffer 5 contains "a"
7178 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7179 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7180 " Assuming line 4 in buffer 10 contains "tik tok"
7181 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7182 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007183<
7184 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007185 "\1", "\2", etc. are also returned. Example: >
7186 " Assuming line 2 in buffer 2 contains "acd"
7187 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007188 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007189 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007190< The "submatches" List always contains 9 items. If a submatch
7191 is not found, then an empty string is returned for that
7192 submatch.
7193
7194 Can also be used as a |method|: >
7195 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007196<
7197 Return type: list<dict<any>> or list<any>
7198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007199
h-east624bb832024-11-09 18:37:32 +01007200matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007201 Deletes a match with ID {id} previously defined by |matchadd()|
7202 or one of the |:match| commands. Returns 0 if successful,
7203 otherwise -1. See example for |matchadd()|. All matches can
7204 be deleted in one operation by |clearmatches()|.
7205 If {win} is specified, use the window with this number or
7206 window ID instead of the current window.
7207
7208 Can also be used as a |method|: >
7209 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007210<
7211 Return type: |Number|
7212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007213
7214matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7215 Same as |match()|, but return the index of first character
7216 after the match. Example: >
7217 :echo matchend("testing", "ing")
7218< results in "7".
7219 *strspn()* *strcspn()*
7220 Vim doesn't have a strspn() or strcspn() function, but you can
7221 do it with matchend(): >
7222 :let span = matchend(line, '[a-zA-Z]')
7223 :let span = matchend(line, '[^a-zA-Z]')
7224< Except that -1 is returned when there are no matches.
7225
7226 The {start}, if given, has the same meaning as for |match()|. >
7227 :echo matchend("testing", "ing", 2)
7228< results in "7". >
7229 :echo matchend("testing", "ing", 5)
7230< result is "-1".
7231 When {expr} is a |List| the result is equal to |match()|.
7232
7233 Can also be used as a |method|: >
7234 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007235<
7236 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007237
7238
7239matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7240 If {list} is a list of strings, then returns a |List| with all
7241 the strings in {list} that fuzzy match {str}. The strings in
7242 the returned list are sorted based on the matching score.
7243
7244 The optional {dict} argument always supports the following
7245 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007246 matchseq When this item is present return only matches
7247 that contain the characters in {str} in the
7248 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007249 limit Maximum number of matches in {list} to be
7250 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007251
7252 If {list} is a list of dictionaries, then the optional {dict}
7253 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007254 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007255 {str}. The value of this item should be a
7256 string.
7257 text_cb |Funcref| that will be called for every item
7258 in {list} to get the text for fuzzy matching.
7259 This should accept a dictionary item as the
7260 argument and return the text for that item to
7261 use for fuzzy matching.
7262
7263 {str} is treated as a literal string and regular expression
7264 matching is NOT supported. The maximum supported {str} length
7265 is 256.
7266
7267 When {str} has multiple words each separated by white space,
7268 then the list of strings that have all the words is returned.
7269
7270 If there are no matching strings or there is an error, then an
7271 empty list is returned. If length of {str} is greater than
7272 256, then returns an empty list.
7273
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007274 When {limit} is given, matchfuzzy() will find up to this
7275 number of matches in {list} and return them in sorted order.
7276
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007277 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007278 matching strings.
7279
7280 Example: >
7281 :echo matchfuzzy(["clay", "crow"], "cay")
7282< results in ["clay"]. >
7283 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7284< results in a list of buffer names fuzzy matching "ndl". >
7285 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7286< results in a list of buffer information dicts with buffer
7287 names fuzzy matching "ndl". >
7288 :echo getbufinfo()->matchfuzzy("spl",
7289 \ {'text_cb' : {v -> v.name}})
7290< results in a list of buffer information dicts with buffer
7291 names fuzzy matching "spl". >
7292 :echo v:oldfiles->matchfuzzy("test")
7293< results in a list of file names fuzzy matching "test". >
7294 :let l = readfile("buffer.c")->matchfuzzy("str")
7295< results in a list of lines in "buffer.c" fuzzy matching "str". >
7296 :echo ['one two', 'two one']->matchfuzzy('two one')
7297< results in ['two one', 'one two']. >
7298 :echo ['one two', 'two one']->matchfuzzy('two one',
7299 \ {'matchseq': 1})
7300< results in ['two one'].
7301
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007302 Return type: list<string> or list<any>
7303
7304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007305matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7306 Same as |matchfuzzy()|, but returns the list of matched
7307 strings, the list of character positions where characters
7308 in {str} matches and a list of matching scores. You can
7309 use |byteidx()| to convert a character position to a byte
7310 position.
7311
7312 If {str} matches multiple times in a string, then only the
7313 positions for the best match is returned.
7314
7315 If there are no matching strings or there is an error, then a
7316 list with three empty list items is returned.
7317
7318 Example: >
7319 :echo matchfuzzypos(['testing'], 'tsg')
7320< results in [['testing'], [[0, 2, 6]], [99]] >
7321 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7322< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7323 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7324< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7325
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007326 Return type: list<list<any>>
7327
7328
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007329matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7330 Same as |match()|, but return a |List|. The first item in the
7331 list is the matched string, same as what matchstr() would
7332 return. Following items are submatches, like "\1", "\2", etc.
7333 in |:substitute|. When an optional submatch didn't match an
7334 empty string is used. Example: >
7335 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7336< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7337 When there is no match an empty list is returned.
7338
7339 You can pass in a List, but that is not very useful.
7340
7341 Can also be used as a |method|: >
7342 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007343<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007344 Return type: list<string> or list<any>
7345
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007346 *matchstrlist()*
7347matchstrlist({list}, {pat} [, {dict}])
7348 Returns the |List| of matches in {list} where {pat} matches.
7349 {list} is a |List| of strings. {pat} is matched against each
7350 string in {list}.
7351
7352 The {dict} argument supports following items:
7353 submatches include submatch information (|/\(|)
7354
7355 For each match, a |Dict| with the following items is returned:
7356 byteidx starting byte index of the match.
7357 idx index in {list} of the match.
7358 text matched string
7359 submatches a List of submatches. Present only if
7360 "submatches" is set to v:true in {dict}.
7361
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007362 See |match-pattern| for information about the effect of some
7363 option settings on the pattern.
7364
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007365 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007366 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7367 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7368 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7369 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007370<
7371 If "submatches" is present and is v:true, then submatches like
7372 "\1", "\2", etc. are also returned. Example: >
7373 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7374 \ #{submatches: v:true})
7375 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7376< The "submatches" List always contains 9 items. If a submatch
7377 is not found, then an empty string is returned for that
7378 submatch.
7379
7380 Can also be used as a |method|: >
7381 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007382<
7383 Return type: list<dict<any>> or list<any>
7384
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007385
7386matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7387 Same as |match()|, but return the matched string. Example: >
7388 :echo matchstr("testing", "ing")
7389< results in "ing".
7390 When there is no match "" is returned.
7391 The {start}, if given, has the same meaning as for |match()|. >
7392 :echo matchstr("testing", "ing", 2)
7393< results in "ing". >
7394 :echo matchstr("testing", "ing", 5)
7395< result is "".
7396 When {expr} is a |List| then the matching item is returned.
7397 The type isn't changed, it's not necessarily a String.
7398
7399 Can also be used as a |method|: >
7400 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007401<
7402 Return type: |String|
7403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007404
7405matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7406 Same as |matchstr()|, but return the matched string, the start
7407 position and the end position of the match. Example: >
7408 :echo matchstrpos("testing", "ing")
7409< results in ["ing", 4, 7].
7410 When there is no match ["", -1, -1] is returned.
7411 The {start}, if given, has the same meaning as for |match()|. >
7412 :echo matchstrpos("testing", "ing", 2)
7413< results in ["ing", 4, 7]. >
7414 :echo matchstrpos("testing", "ing", 5)
7415< result is ["", -1, -1].
7416 When {expr} is a |List| then the matching item, the index
7417 of first item where {pat} matches, the start position and the
7418 end position of the match are returned. >
7419 :echo matchstrpos([1, '__x'], '\a')
7420< result is ["x", 1, 2, 3].
7421 The type isn't changed, it's not necessarily a String.
7422
7423 Can also be used as a |method|: >
7424 GetText()->matchstrpos('word')
7425<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007426 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007427
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007428
7429max({expr}) *max()*
7430 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007431 echo max([apples, pears, oranges])
7432
7433< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7434 it returns the maximum of all values in the Dictionary.
7435 If {expr} is neither a List nor a Dictionary, or one of the
7436 items in {expr} cannot be used as a Number this results in
7437 an error. An empty |List| or |Dictionary| results in zero.
7438
7439 Can also be used as a |method|: >
7440 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007441<
7442 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007443
7444
7445menu_info({name} [, {mode}]) *menu_info()*
7446 Return information about the specified menu {name} in
7447 mode {mode}. The menu name should be specified without the
7448 shortcut character ('&'). If {name} is "", then the top-level
7449 menu names are returned.
7450
7451 {mode} can be one of these strings:
7452 "n" Normal
7453 "v" Visual (including Select)
7454 "o" Operator-pending
7455 "i" Insert
7456 "c" Cmd-line
7457 "s" Select
7458 "x" Visual
7459 "t" Terminal-Job
7460 "" Normal, Visual and Operator-pending
7461 "!" Insert and Cmd-line
7462 When {mode} is omitted, the modes for "" are used.
7463
7464 Returns a |Dictionary| containing the following items:
7465 accel menu item accelerator text |menu-text|
7466 display display name (name without '&')
7467 enabled v:true if this menu item is enabled
7468 Refer to |:menu-enable|
7469 icon name of the icon file (for toolbar)
7470 |toolbar-icon|
7471 iconidx index of a built-in icon
7472 modes modes for which the menu is defined. In
7473 addition to the modes mentioned above, these
7474 characters will be used:
7475 " " Normal, Visual and Operator-pending
7476 name menu item name.
7477 noremenu v:true if the {rhs} of the menu item is not
7478 remappable else v:false.
7479 priority menu order priority |menu-priority|
7480 rhs right-hand-side of the menu item. The returned
7481 string has special characters translated like
7482 in the output of the ":menu" command listing.
7483 When the {rhs} of a menu item is empty, then
7484 "<Nop>" is returned.
7485 script v:true if script-local remapping of {rhs} is
7486 allowed else v:false. See |:menu-script|.
7487 shortcut shortcut key (character after '&' in
7488 the menu name) |menu-shortcut|
7489 silent v:true if the menu item is created
7490 with <silent> argument |:menu-silent|
7491 submenus |List| containing the names of
7492 all the submenus. Present only if the menu
7493 item has submenus.
7494
7495 Returns an empty dictionary if the menu item is not found.
7496
7497 Examples: >
7498 :echo menu_info('Edit.Cut')
7499 :echo menu_info('File.Save', 'n')
7500
7501 " Display the entire menu hierarchy in a buffer
7502 func ShowMenu(name, pfx)
7503 let m = menu_info(a:name)
7504 call append(line('$'), a:pfx .. m.display)
7505 for child in m->get('submenus', [])
7506 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7507 \ a:pfx .. ' ')
7508 endfor
7509 endfunc
7510 new
7511 for topmenu in menu_info('').submenus
7512 call ShowMenu(topmenu, '')
7513 endfor
7514<
7515 Can also be used as a |method|: >
7516 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007517<
7518 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007519
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007520min({expr}) *min()*
7521 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007522 echo min([apples, pears, oranges])
7523
7524< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7525 it returns the minimum of all values in the Dictionary.
7526 If {expr} is neither a List nor a Dictionary, or one of the
7527 items in {expr} cannot be used as a Number this results in
7528 an error. An empty |List| or |Dictionary| results in zero.
7529
7530 Can also be used as a |method|: >
7531 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007532<
7533 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007534
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007535
7536mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007537 Create directory {name}.
7538
Bram Moolenaar938ae282023-02-20 20:44:55 +00007539 When {flags} is present it must be a string. An empty string
7540 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007541
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007542 {flags} can contain these character flags:
7543 "p" intermediate directories will be created as necessary
7544 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007545 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007546 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007547 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007548
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007549 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007550 some directories may already exist. Only the first one that
7551 is created and what it contains is scheduled to be deleted.
7552 E.g. when using: >
7553 call mkdir('subdir/tmp/autoload', 'pR')
7554< and "subdir" already exists then "subdir/tmp" will be
7555 scheduled for deletion, like with: >
7556 defer delete('subdir/tmp', 'rf')
7557< Note that if scheduling the defer fails the directory is not
7558 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007559
7560 If {prot} is given it is used to set the protection bits of
7561 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7562 the user, readable for others). Use 0o700 to make it
7563 unreadable for others. This is only used for the last part of
7564 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7565 created with 0o755.
7566 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007567 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007568
7569< This function is not available in the |sandbox|.
7570
7571 There is no error if the directory already exists and the "p"
7572 flag is passed (since patch 8.0.1708). However, without the
7573 "p" option the call will fail.
7574
7575 The function result is a Number, which is TRUE if the call was
7576 successful or FALSE if the directory creation failed or partly
7577 failed.
7578
7579 Not available on all systems. To check use: >
7580 :if exists("*mkdir")
7581
7582< Can also be used as a |method|: >
7583 GetName()->mkdir()
7584<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007585 Return type: |Number|
7586
7587
7588mode([{expr}]) *mode()*
7589 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007590 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007591 a non-empty String (|non-zero-arg|), then the full mode is
7592 returned, otherwise only the first letter is returned.
7593 Also see |state()|.
7594
7595 n Normal
7596 no Operator-pending
7597 nov Operator-pending (forced characterwise |o_v|)
7598 noV Operator-pending (forced linewise |o_V|)
7599 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7600 CTRL-V is one character
7601 niI Normal using |i_CTRL-O| in |Insert-mode|
7602 niR Normal using |i_CTRL-O| in |Replace-mode|
7603 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7604 nt Terminal-Normal (insert goes to Terminal-Job mode)
7605 v Visual by character
7606 vs Visual by character using |v_CTRL-O| in Select mode
7607 V Visual by line
7608 Vs Visual by line using |v_CTRL-O| in Select mode
7609 CTRL-V Visual blockwise
7610 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7611 s Select by character
7612 S Select by line
7613 CTRL-S Select blockwise
7614 i Insert
7615 ic Insert mode completion |compl-generic|
7616 ix Insert mode |i_CTRL-X| completion
7617 R Replace |R|
7618 Rc Replace mode completion |compl-generic|
7619 Rx Replace mode |i_CTRL-X| completion
7620 Rv Virtual Replace |gR|
7621 Rvc Virtual Replace mode completion |compl-generic|
7622 Rvx Virtual Replace mode |i_CTRL-X| completion
7623 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007624 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007625 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007626 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007627 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007628 ce Normal Ex mode |Q|
7629 r Hit-enter prompt
7630 rm The -- more -- prompt
7631 r? A |:confirm| query of some sort
7632 ! Shell or external command is executing
7633 t Terminal-Job mode: keys go to the job
7634
7635 This is useful in the 'statusline' option or when used
7636 with |remote_expr()| In most other places it always returns
7637 "c" or "n".
7638 Note that in the future more modes and more specific modes may
7639 be added. It's better not to compare the whole string but only
7640 the leading character(s).
7641 Also see |visualmode()|.
7642
7643 Can also be used as a |method|: >
7644 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007645<
7646 Return type: |String|
7647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007648
7649mzeval({expr}) *mzeval()*
7650 Evaluate MzScheme expression {expr} and return its result
7651 converted to Vim data structures.
7652 Numbers and strings are returned as they are.
7653 Pairs (including lists and improper lists) and vectors are
7654 returned as Vim |Lists|.
7655 Hash tables are represented as Vim |Dictionary| type with keys
7656 converted to strings.
7657 All other types are converted to string with display function.
7658 Examples: >
7659 :mz (define l (list 1 2 3))
7660 :mz (define h (make-hash)) (hash-set! h "list" l)
7661 :echo mzeval("l")
7662 :echo mzeval("h")
7663<
7664 Note that in a `:def` function local variables are not visible
7665 to {expr}.
7666
7667 Can also be used as a |method|: >
7668 GetExpr()->mzeval()
7669<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007670 Return type: any, depending on {expr}
7671
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007672 {only available when compiled with the |+mzscheme| feature}
7673
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007675nextnonblank({lnum}) *nextnonblank()*
7676 Return the line number of the first line at or below {lnum}
7677 that is not blank. Example: >
7678 if getline(nextnonblank(1)) =~ "Java"
7679< When {lnum} is invalid or there is no non-blank line at or
7680 below it, zero is returned.
7681 {lnum} is used like with |getline()|.
7682 See also |prevnonblank()|.
7683
7684 Can also be used as a |method|: >
7685 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007686<
7687 Return type: |Number|
7688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007689
7690nr2char({expr} [, {utf8}]) *nr2char()*
7691 Return a string with a single character, which has the number
7692 value {expr}. Examples: >
7693 nr2char(64) returns "@"
7694 nr2char(32) returns " "
7695< When {utf8} is omitted or zero, the current 'encoding' is used.
7696 Example for "utf-8": >
7697 nr2char(300) returns I with bow character
7698< When {utf8} is TRUE, always return UTF-8 characters.
7699 Note that a NUL character in the file is specified with
7700 nr2char(10), because NULs are represented with newline
7701 characters. nr2char(0) is a real NUL and terminates the
7702 string, thus results in an empty string.
7703 To turn a list of character numbers into a string: >
7704 let list = [65, 66, 67]
7705 let str = join(map(list, {_, val -> nr2char(val)}), '')
7706< Result: "ABC"
7707
7708 Can also be used as a |method|: >
7709 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007710<
7711 Return type: |String|
7712
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007713
7714or({expr}, {expr}) *or()*
7715 Bitwise OR on the two arguments. The arguments are converted
7716 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007717 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007718 Example: >
7719 :let bits = or(bits, 0x80)
7720< Can also be used as a |method|: >
7721 :let bits = bits->or(0x80)
7722
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007723< Rationale: The reason this is a function and not using the "|"
7724 character like many languages, is that Vi has always used "|"
7725 to separate commands. In many places it would not be clear if
7726 "|" is an operator or a command separator.
7727
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007728 Return type: |Number|
7729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007730
7731pathshorten({path} [, {len}]) *pathshorten()*
7732 Shorten directory names in the path {path} and return the
7733 result. The tail, the file name, is kept as-is. The other
7734 components in the path are reduced to {len} letters in length.
7735 If {len} is omitted or smaller than 1 then 1 is used (single
7736 letters). Leading '~' and '.' characters are kept. Examples: >
7737 :echo pathshorten('~/.vim/autoload/myfile.vim')
7738< ~/.v/a/myfile.vim ~
7739>
7740 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7741< ~/.vi/au/myfile.vim ~
7742 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007743 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007744
7745 Can also be used as a |method|: >
7746 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007747<
7748 Return type: |String|
7749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007750
7751perleval({expr}) *perleval()*
7752 Evaluate Perl expression {expr} in scalar context and return
7753 its result converted to Vim data structures. If value can't be
7754 converted, it is returned as a string Perl representation.
7755 Note: If you want an array or hash, {expr} must return a
7756 reference to it.
7757 Example: >
7758 :echo perleval('[1 .. 4]')
7759< [1, 2, 3, 4]
7760
7761 Note that in a `:def` function local variables are not visible
7762 to {expr}.
7763
7764 Can also be used as a |method|: >
7765 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007766<
7767 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007768
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007769 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007770
7771
7772popup_ functions are documented here: |popup-functions|
7773
7774
7775pow({x}, {y}) *pow()*
7776 Return the power of {x} to the exponent {y} as a |Float|.
7777 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007778 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007779 Examples: >
7780 :echo pow(3, 3)
7781< 27.0 >
7782 :echo pow(2, 16)
7783< 65536.0 >
7784 :echo pow(32, 0.20)
7785< 2.0
7786
7787 Can also be used as a |method|: >
7788 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007789<
7790 Return type: |Number|
7791
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007792
7793prevnonblank({lnum}) *prevnonblank()*
7794 Return the line number of the first line at or above {lnum}
7795 that is not blank. Example: >
7796 let ind = indent(prevnonblank(v:lnum - 1))
7797< When {lnum} is invalid or there is no non-blank line at or
7798 above it, zero is returned.
7799 {lnum} is used like with |getline()|.
7800 Also see |nextnonblank()|.
7801
7802 Can also be used as a |method|: >
7803 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007804<
7805 Return type: |Number|
7806
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007807
7808printf({fmt}, {expr1} ...) *printf()*
7809 Return a String with {fmt}, where "%" items are replaced by
7810 the formatted form of their respective arguments. Example: >
7811 printf("%4d: E%d %.30s", lnum, errno, msg)
7812< May result in:
7813 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7814
7815 When used as a |method| the base is passed as the second
7816 argument: >
7817 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007818<
7819 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007820
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007821 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007822 %s string
7823 %6S string right-aligned in 6 display cells
7824 %6s string right-aligned in 6 bytes
7825 %.9s string truncated to 9 bytes
7826 %c single byte
7827 %d decimal number
7828 %5d decimal number padded with spaces to 5 characters
7829 %x hex number
7830 %04x hex number padded with zeros to at least 4 characters
7831 %X hex number using upper case letters
7832 %o octal number
7833 %08b binary number padded with zeros to at least 8 chars
7834 %f floating point number as 12.23, inf, -inf or nan
7835 %F floating point number as 12.23, INF, -INF or NAN
7836 %e floating point number as 1.23e3, inf, -inf or nan
7837 %E floating point number as 1.23E3, INF, -INF or NAN
7838 %g floating point number, as %f or %e depending on value
7839 %G floating point number, as %F or %E depending on value
7840 %% the % character itself
7841
7842 Conversion specifications start with '%' and end with the
7843 conversion type. All other characters are copied unchanged to
7844 the result.
7845
7846 The "%" starts a conversion specification. The following
7847 arguments appear in sequence:
7848
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007849 % [pos-argument] [flags] [field-width] [.precision] type
7850
7851 pos-argument
7852 At most one positional argument specifier. These
7853 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007854
7855 flags
7856 Zero or more of the following flags:
7857
7858 # The value should be converted to an "alternate
7859 form". For c, d, and s conversions, this option
7860 has no effect. For o conversions, the precision
7861 of the number is increased to force the first
7862 character of the output string to a zero (except
7863 if a zero value is printed with an explicit
7864 precision of zero).
7865 For b and B conversions, a non-zero result has
7866 the string "0b" (or "0B" for B conversions)
7867 prepended to it.
7868 For x and X conversions, a non-zero result has
7869 the string "0x" (or "0X" for X conversions)
7870 prepended to it.
7871
7872 0 (zero) Zero padding. For all conversions the converted
7873 value is padded on the left with zeros rather
7874 than blanks. If a precision is given with a
7875 numeric conversion (d, b, B, o, x, and X), the 0
7876 flag is ignored.
7877
7878 - A negative field width flag; the converted value
7879 is to be left adjusted on the field boundary.
7880 The converted value is padded on the right with
7881 blanks, rather than on the left with blanks or
7882 zeros. A - overrides a 0 if both are given.
7883
7884 ' ' (space) A blank should be left before a positive
7885 number produced by a signed conversion (d).
7886
7887 + A sign must always be placed before a number
7888 produced by a signed conversion. A + overrides
7889 a space if both are used.
7890
7891 field-width
7892 An optional decimal digit string specifying a minimum
7893 field width. If the converted value has fewer bytes
7894 than the field width, it will be padded with spaces on
7895 the left (or right, if the left-adjustment flag has
7896 been given) to fill out the field width. For the S
7897 conversion the count is in cells.
7898
7899 .precision
7900 An optional precision, in the form of a period '.'
7901 followed by an optional digit string. If the digit
7902 string is omitted, the precision is taken as zero.
7903 This gives the minimum number of digits to appear for
7904 d, o, x, and X conversions, the maximum number of
7905 bytes to be printed from a string for s conversions,
7906 or the maximum number of cells to be printed from a
7907 string for S conversions.
7908 For floating point it is the number of digits after
7909 the decimal point.
7910
7911 type
7912 A character that specifies the type of conversion to
7913 be applied, see below.
7914
7915 A field width or precision, or both, may be indicated by an
7916 asterisk '*' instead of a digit string. In this case, a
7917 Number argument supplies the field width or precision. A
7918 negative field width is treated as a left adjustment flag
7919 followed by a positive field width; a negative precision is
7920 treated as though it were missing. Example: >
7921 :echo printf("%d: %.*s", nr, width, line)
7922< This limits the length of the text used from "line" to
7923 "width" bytes.
7924
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007925 If the argument to be formatted is specified using a
7926 positional argument specifier, and a '*' is used to indicate
7927 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007928 precision, the argument(s) to be used must also be specified
7929 using a {n$} positional argument specifier. See |printf-$|.
7930
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007931 The conversion specifiers and their meanings are:
7932
7933 *printf-d* *printf-b* *printf-B* *printf-o*
7934 *printf-x* *printf-X*
7935 dbBoxX The Number argument is converted to signed decimal
7936 (d), unsigned binary (b and B), unsigned octal (o), or
7937 unsigned hexadecimal (x and X) notation. The letters
7938 "abcdef" are used for x conversions; the letters
7939 "ABCDEF" are used for X conversions.
7940 The precision, if any, gives the minimum number of
7941 digits that must appear; if the converted value
7942 requires fewer digits, it is padded on the left with
7943 zeros.
7944 In no case does a non-existent or small field width
7945 cause truncation of a numeric field; if the result of
7946 a conversion is wider than the field width, the field
7947 is expanded to contain the conversion result.
7948 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007949 The 'l' modifier indicates the argument is a long
7950 integer. The size will be 32 bits or 64 bits
7951 depending on your platform.
7952 The "ll" modifier indicates the argument is 64 bits.
7953 The b and B conversion specifiers never take a width
7954 modifier and always assume their argument is a 64 bit
7955 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007956 Generally, these modifiers are not useful. They are
7957 ignored when type is known from the argument.
7958
7959 i alias for d
7960 D alias for ld
7961 U alias for lu
7962 O alias for lo
7963
7964 *printf-c*
7965 c The Number argument is converted to a byte, and the
7966 resulting character is written.
7967
7968 *printf-s*
7969 s The text of the String argument is used. If a
7970 precision is specified, no more bytes than the number
7971 specified are used.
7972 If the argument is not a String type, it is
7973 automatically converted to text with the same format
7974 as ":echo".
7975 *printf-S*
7976 S The text of the String argument is used. If a
7977 precision is specified, no more display cells than the
7978 number specified are used.
7979
7980 *printf-f* *E807*
7981 f F The Float argument is converted into a string of the
7982 form 123.456. The precision specifies the number of
7983 digits after the decimal point. When the precision is
7984 zero the decimal point is omitted. When the precision
7985 is not specified 6 is used. A really big number
7986 (out of range or dividing by zero) results in "inf"
7987 or "-inf" with %f (INF or -INF with %F).
7988 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7989 Example: >
7990 echo printf("%.2f", 12.115)
7991< 12.12
7992 Note that roundoff depends on the system libraries.
7993 Use |round()| when in doubt.
7994
7995 *printf-e* *printf-E*
7996 e E The Float argument is converted into a string of the
7997 form 1.234e+03 or 1.234E+03 when using 'E'. The
7998 precision specifies the number of digits after the
7999 decimal point, like with 'f'.
8000
8001 *printf-g* *printf-G*
8002 g G The Float argument is converted like with 'f' if the
8003 value is between 0.001 (inclusive) and 10000000.0
8004 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8005 for 'G'. When no precision is specified superfluous
8006 zeroes and '+' signs are removed, except for the zero
8007 immediately after the decimal point. Thus 10000000.0
8008 results in 1.0e7.
8009
8010 *printf-%*
8011 % A '%' is written. No argument is converted. The
8012 complete conversion specification is "%%".
8013
8014 When a Number argument is expected a String argument is also
8015 accepted and automatically converted.
8016 When a Float or String argument is expected a Number argument
8017 is also accepted and automatically converted.
8018 Any other argument type results in an error message.
8019
8020 *E766* *E767*
8021 The number of {exprN} arguments must exactly match the number
8022 of "%" items. If there are not sufficient or too many
8023 arguments an error is given. Up to 18 arguments can be used.
8024
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008025 *printf-$*
8026 In certain languages, error and informative messages are
8027 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008028 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008029 having a different word order, positional arguments may be
8030 used to indicate this. For instance: >
8031
h_east596a9f22023-11-21 21:24:23 +09008032 #, c-format
8033 msgid "%s returning %s"
8034 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008035<
h_east596a9f22023-11-21 21:24:23 +09008036 In this example, the sentence has its 2 string arguments
8037 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008038
h_east596a9f22023-11-21 21:24:23 +09008039 echo printf(
8040 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8041 "Bram", "Moolenaar")
8042< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008043
h_east596a9f22023-11-21 21:24:23 +09008044 echo printf(
8045 "In Belgium, vim's creator's name is: %2$s %1$s",
8046 "Bram", "Moolenaar")
8047< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008048
8049 Width (and precision) can be specified using the '*' specifier.
8050 In this case, you must specify the field width position in the
8051 argument list. >
8052
h_east596a9f22023-11-21 21:24:23 +09008053 echo printf("%1$*2$.*3$d", 1, 2, 3)
8054< 001 >
8055 echo printf("%2$*3$.*1$d", 1, 2, 3)
8056< 2 >
8057 echo printf("%3$*1$.*2$d", 1, 2, 3)
8058< 03 >
8059 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8060< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008061
8062 You can mix specifying the width and/or precision directly
8063 and via positional arguments: >
8064
h_east596a9f22023-11-21 21:24:23 +09008065 echo printf("%1$4.*2$f", 1.4142135, 6)
8066< 1.414214 >
8067 echo printf("%1$*2$.4f", 1.4142135, 6)
8068< 1.4142 >
8069 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8070< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008071
Christ van Willegenc35fc032024-03-14 18:30:41 +01008072 You will get an overflow error |E1510|, when the field-width
8073 or precision will result in a string longer than 6400 chars.
8074
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008075 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008076 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008077 echo printf("%s%1$s", "One", "Two")
8078< E1500: Cannot mix positional and non-positional arguments:
8079 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008080
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008081 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008082 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008083 echo printf("%3$s%1$s", "One", "Two", "Three")
8084< E1501: format argument 2 unused in $-style format:
8085 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008086
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008087 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008088 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008089 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8090< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008091
8092 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008093 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8094< E1502: Positional argument 2 used as field width reused as
8095 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008096
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008097 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008098 When a positional argument is used, but not the correct number
8099 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008100 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8101< E1503: Positional argument 3 out of bounds: %1$d at width
8102 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008103
8104 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008105 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8106< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8107 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008108
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008109 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008110 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008111 echo printf("%1$s %2$s %1$s", "One", "Two")
8112< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008113
8114 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008115 echo printf("%1$s %2$s %1$d", "One", "Two")
8116< E1504: Positional argument 1 type used inconsistently:
8117 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008118
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008119 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008120 Various other errors that lead to a format string being
8121 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008122 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8123< E1505: Invalid format specifier: %1$d at width %2$d is:
8124 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008125
Christ van Willegenea746f92023-10-05 20:48:36 +02008126 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008127 This internal error indicates that the logic to parse a
8128 positional format argument ran into a problem that couldn't be
8129 otherwise reported. Please file a bug against Vim if you run
8130 into this, copying the exact format string and parameters that
8131 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008132
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008133 Return type: |String|
8134
Christ van Willegenea746f92023-10-05 20:48:36 +02008135
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008136prompt_getprompt({buf}) *prompt_getprompt()*
8137 Returns the effective prompt text for buffer {buf}. {buf} can
8138 be a buffer name or number. See |prompt-buffer|.
8139
8140 If the buffer doesn't exist or isn't a prompt buffer, an empty
8141 string is returned.
8142
8143 Can also be used as a |method|: >
8144 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008145<
8146 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008147
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008148 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008149
8150
8151prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8152 Set prompt callback for buffer {buf} to {expr}. When {expr}
8153 is an empty string the callback is removed. This has only
8154 effect if {buf} has 'buftype' set to "prompt".
8155
8156 The callback is invoked when pressing Enter. The current
8157 buffer will always be the prompt buffer. A new line for a
8158 prompt is added before invoking the callback, thus the prompt
8159 for which the callback was invoked will be in the last but one
8160 line.
8161 If the callback wants to add text to the buffer, it must
8162 insert it above the last line, since that is where the current
8163 prompt is. This can also be done asynchronously.
8164 The callback is invoked with one argument, which is the text
8165 that was entered at the prompt. This can be an empty string
8166 if the user only typed Enter.
8167 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008168 func s:TextEntered(text)
8169 if a:text == 'exit' || a:text == 'quit'
8170 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008171 " Reset 'modified' to allow the buffer to be closed.
8172 " We assume there is nothing useful to be saved.
8173 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008174 close
8175 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008176 " Do something useful with "a:text". In this example
8177 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008178 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008179 endif
8180 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008181 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008182
8183< Can also be used as a |method|: >
8184 GetBuffer()->prompt_setcallback(callback)
8185
8186< {only available when compiled with the |+channel| feature}
8187
8188prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8189 Set a callback for buffer {buf} to {expr}. When {expr} is an
8190 empty string the callback is removed. This has only effect if
8191 {buf} has 'buftype' set to "prompt".
8192
8193 This callback will be invoked when pressing CTRL-C in Insert
8194 mode. Without setting a callback Vim will exit Insert mode,
8195 as in any buffer.
8196
8197 Can also be used as a |method|: >
8198 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008199<
8200 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008201
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008202 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008203
8204prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8205 Set prompt for buffer {buf} to {text}. You most likely want
8206 {text} to end in a space.
8207 The result is only visible if {buf} has 'buftype' set to
8208 "prompt". Example: >
8209 call prompt_setprompt(bufnr(), 'command: ')
8210<
8211 Can also be used as a |method|: >
8212 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008213<
8214 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008215
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008216 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008217
8218prop_ functions are documented here: |text-prop-functions|
8219
8220pum_getpos() *pum_getpos()*
8221 If the popup menu (see |ins-completion-menu|) is not visible,
8222 returns an empty |Dictionary|, otherwise, returns a
8223 |Dictionary| with the following keys:
8224 height nr of items visible
8225 width screen cells
8226 row top screen row (0 first row)
8227 col leftmost screen column (0 first col)
8228 size total nr of items
8229 scrollbar |TRUE| if scrollbar is visible
8230
8231 The values are the same as in |v:event| during
8232 |CompleteChanged|.
8233
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008234 Return type: dict<any>
8235
8236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008237pumvisible() *pumvisible()*
8238 Returns non-zero when the popup menu is visible, zero
8239 otherwise. See |ins-completion-menu|.
8240 This can be used to avoid some things that would remove the
8241 popup menu.
8242
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008243 Return type: |Number|
8244
8245
zeertzjq7c515282024-11-10 20:26:12 +01008246py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008247 Evaluate Python expression {expr} and return its result
8248 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008249 If a {locals} |Dictionary| is given, it defines set of local
8250 variables available in the expression. The keys are variable
8251 names and the values are the variable values. |Dictionary| and
8252 |List| values are referenced, and may be updated by the
8253 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008254 Numbers and strings are returned as they are (strings are
8255 copied though, Unicode strings are additionally converted to
8256 'encoding').
8257 Lists are represented as Vim |List| type.
8258 Dictionaries are represented as Vim |Dictionary| type with
8259 keys converted to strings.
8260 Note that in a `:def` function local variables are not visible
8261 to {expr}.
8262
8263 Can also be used as a |method|: >
8264 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008265 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008266<
8267 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008268
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008269 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008270
8271 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008272pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008273 Evaluate Python expression {expr} and return its result
8274 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008275 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008276 Numbers and strings are returned as they are (strings are
8277 copied though).
8278 Lists are represented as Vim |List| type.
8279 Dictionaries are represented as Vim |Dictionary| type,
8280 non-string keys result in error.
8281 Note that in a `:def` function local variables are not visible
8282 to {expr}.
8283
8284 Can also be used as a |method|: >
8285 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008286<
8287 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008288
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008289 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008290
zeertzjq7c515282024-11-10 20:26:12 +01008291pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008292 Evaluate Python expression {expr} and return its result
8293 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008294 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008295 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8296 See also: |pyeval()|, |py3eval()|
8297
8298 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008299 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008300<
8301 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008302
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008303 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008304 |+python3| feature}
8305
8306rand([{expr}]) *rand()* *random*
8307 Return a pseudo-random Number generated with an xoshiro128**
8308 algorithm using seed {expr}. The returned number is 32 bits,
8309 also on 64 bits systems, for consistency.
8310 {expr} can be initialized by |srand()| and will be updated by
8311 rand(). If {expr} is omitted, an internal seed value is used
8312 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008313 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008314
8315 Examples: >
8316 :echo rand()
8317 :let seed = srand()
8318 :echo rand(seed)
8319 :echo rand(seed) % 16 " random number 0 - 15
8320<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008321 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008322
8323 *E726* *E727*
8324range({expr} [, {max} [, {stride}]]) *range()*
8325 Returns a |List| with Numbers:
8326 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8327 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8328 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8329 {max}] (increasing {expr} with {stride} each time, not
8330 producing a value past {max}).
8331 When the maximum is one before the start the result is an
8332 empty list. When the maximum is more than one before the
8333 start this is an error.
8334 Examples: >
8335 range(4) " [0, 1, 2, 3]
8336 range(2, 4) " [2, 3, 4]
8337 range(2, 9, 3) " [2, 5, 8]
8338 range(2, -2, -1) " [2, 1, 0, -1, -2]
8339 range(0) " []
8340 range(2, 0) " error!
8341<
8342 Can also be used as a |method|: >
8343 GetExpr()->range()
8344<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008345 Return type: list<number>
8346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008347
K.Takata11df3ae2022-10-19 14:02:40 +01008348readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008349 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008350 If {offset} is specified, read the file from the specified
8351 offset. If it is a negative value, it is used as an offset
8352 from the end of the file. E.g., to read the last 12 bytes: >
8353 readblob('file.bin', -12)
8354< If {size} is specified, only the specified size will be read.
8355 E.g. to read the first 100 bytes of a file: >
8356 readblob('file.bin', 0, 100)
8357< If {size} is -1 or omitted, the whole data starting from
8358 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008359 This can be also used to read the data from a character device
8360 on Unix when {size} is explicitly set. Only if the device
8361 supports seeking {offset} can be used. Otherwise it should be
8362 zero. E.g. to read 10 bytes from a serial console: >
8363 readblob('/dev/ttyS0', 0, 10)
8364< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008365 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008366 When the offset is beyond the end of the file the result is an
8367 empty blob.
8368 When trying to read more bytes than are available the result
8369 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008370 Also see |readfile()| and |writefile()|.
8371
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008372 Return type: |Blob|
8373
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008374
8375readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8376 Return a list with file and directory names in {directory}.
8377 You can also use |glob()| if you don't need to do complicated
8378 things, such as limiting the number of matches.
8379 The list will be sorted (case sensitive), see the {dict}
8380 argument below for changing the sort order.
8381
8382 When {expr} is omitted all entries are included.
8383 When {expr} is given, it is evaluated to check what to do:
8384 If {expr} results in -1 then no further entries will
8385 be handled.
8386 If {expr} results in 0 then this entry will not be
8387 added to the list.
8388 If {expr} results in 1 then this entry will be added
8389 to the list.
8390 The entries "." and ".." are always excluded.
8391 Each time {expr} is evaluated |v:val| is set to the entry name.
8392 When {expr} is a function the name is passed as the argument.
8393 For example, to get a list of files ending in ".txt": >
8394 readdir(dirname, {n -> n =~ '.txt$'})
8395< To skip hidden and backup files: >
8396 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008397< *E857*
8398 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008399 values. Currently this is used to specify if and how sorting
8400 should be performed. The dict can have the following members:
8401
8402 sort How to sort the result returned from the system.
8403 Valid values are:
8404 "none" do not sort (fastest method)
8405 "case" sort case sensitive (byte value of
8406 each character, technically, using
8407 strcmp()) (default)
8408 "icase" sort case insensitive (technically
8409 using strcasecmp())
8410 "collate" sort using the collation order
8411 of the "POSIX" or "C" |locale|
8412 (technically using strcoll())
8413 Other values are silently ignored.
8414
8415 For example, to get a list of all files in the current
8416 directory without sorting the individual entries: >
8417 readdir('.', '1', #{sort: 'none'})
8418< If you want to get a directory tree: >
8419 function! s:tree(dir)
8420 return {a:dir : map(readdir(a:dir),
8421 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008422 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008423 endfunction
8424 echo s:tree(".")
8425<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008426 Returns an empty List on error.
8427
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008428 Can also be used as a |method|: >
8429 GetDirName()->readdir()
8430<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008431 Return type: list<string> or list<any>
8432
8433
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008434readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8435 Extended version of |readdir()|.
8436 Return a list of Dictionaries with file and directory
8437 information in {directory}.
8438 This is useful if you want to get the attributes of file and
8439 directory at the same time as getting a list of a directory.
8440 This is much faster than calling |readdir()| then calling
8441 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8442 each file and directory especially on MS-Windows.
8443 The list will by default be sorted by name (case sensitive),
8444 the sorting can be changed by using the optional {dict}
8445 argument, see |readdir()|.
8446
8447 The Dictionary for file and directory information has the
8448 following items:
8449 group Group name of the entry. (Only on Unix)
8450 name Name of the entry.
8451 perm Permissions of the entry. See |getfperm()|.
8452 size Size of the entry. See |getfsize()|.
8453 time Timestamp of the entry. See |getftime()|.
8454 type Type of the entry.
8455 On Unix, almost same as |getftype()| except:
8456 Symlink to a dir "linkd"
8457 Other symlink "link"
8458 On MS-Windows:
8459 Normal file "file"
8460 Directory "dir"
8461 Junction "junction"
8462 Symlink to a dir "linkd"
8463 Other symlink "link"
8464 Other reparse point "reparse"
8465 user User name of the entry's owner. (Only on Unix)
8466 On Unix, if the entry is a symlink, the Dictionary includes
8467 the information of the target (except the "type" item).
8468 On MS-Windows, it includes the information of the symlink
8469 itself because of performance reasons.
8470
8471 When {expr} is omitted all entries are included.
8472 When {expr} is given, it is evaluated to check what to do:
8473 If {expr} results in -1 then no further entries will
8474 be handled.
8475 If {expr} results in 0 then this entry will not be
8476 added to the list.
8477 If {expr} results in 1 then this entry will be added
8478 to the list.
8479 The entries "." and ".." are always excluded.
8480 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8481 of the entry.
8482 When {expr} is a function the entry is passed as the argument.
8483 For example, to get a list of files ending in ".txt": >
8484 readdirex(dirname, {e -> e.name =~ '.txt$'})
8485<
8486 For example, to get a list of all files in the current
8487 directory without sorting the individual entries: >
8488 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008489<
8490 Can also be used as a |method|: >
8491 GetDirName()->readdirex()
8492<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008493 Return type: list<dict<any>> or list<any>
8494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008495
8496 *readfile()*
8497readfile({fname} [, {type} [, {max}]])
8498 Read file {fname} and return a |List|, each line of the file
8499 as an item. Lines are broken at NL characters. Macintosh
8500 files separated with CR will result in a single long line
8501 (unless a NL appears somewhere).
8502 All NUL characters are replaced with a NL character.
8503 When {type} contains "b" binary mode is used:
8504 - When the last line ends in a NL an extra empty list item is
8505 added.
8506 - No CR characters are removed.
8507 Otherwise:
8508 - CR characters that appear before a NL are removed.
8509 - Whether the last line ends in a NL or not does not matter.
8510 - When 'encoding' is Unicode any UTF-8 byte order mark is
8511 removed from the text.
8512 When {max} is given this specifies the maximum number of lines
8513 to be read. Useful if you only want to check the first ten
8514 lines of a file: >
8515 :for line in readfile(fname, '', 10)
8516 : if line =~ 'Date' | echo line | endif
8517 :endfor
8518< When {max} is negative -{max} lines from the end of the file
8519 are returned, or as many as there are.
8520 When {max} is zero the result is an empty list.
8521 Note that without {max} the whole file is read into memory.
8522 Also note that there is no recognition of encoding. Read a
8523 file into a buffer if you need to.
8524 Deprecated (use |readblob()| instead): When {type} contains
8525 "B" a |Blob| is returned with the binary data of the file
8526 unmodified.
8527 When the file can't be opened an error message is given and
8528 the result is an empty list.
8529 Also see |writefile()|.
8530
8531 Can also be used as a |method|: >
8532 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008533<
8534 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008535
8536reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8537 {func} is called for every item in {object}, which can be a
8538 |String|, |List| or a |Blob|. {func} is called with two
8539 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008540 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008541
8542 {initial} is the initial result. When omitted, the first item
8543 in {object} is used and {func} is first called for the second
8544 item. If {initial} is not given and {object} is empty no
8545 result can be computed, an E998 error is given.
8546
8547 Examples: >
8548 echo reduce([1, 3, 5], { acc, val -> acc + val })
8549 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8550 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8551 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8552<
8553 Can also be used as a |method|: >
8554 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008555<
8556 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8557 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008558
8559
8560reg_executing() *reg_executing()*
8561 Returns the single letter name of the register being executed.
8562 Returns an empty string when no register is being executed.
8563 See |@|.
8564
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008565 Return type: |String|
8566
8567
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008568reg_recording() *reg_recording()*
8569 Returns the single letter name of the register being recorded.
8570 Returns an empty string when not recording. See |q|.
8571
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008572 Return type: |String|
8573
8574
8575reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008576reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008577reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008578 Return an item that represents a time value. The item is a
8579 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008580 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008581 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008582 string or |reltimefloat()| to convert to a Float. For
8583 example, to see the time spent in function Work(): >
8584 var startTime = reltime()
8585 Work()
8586 echo startTime->reltime()->reltimestr()
8587<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008588 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008589 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008590 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008591 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008592 specified in the argument.
8593 With two arguments it returns the time passed between {start}
8594 and {end}.
8595
8596 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008597 reltime(). If there is an error an empty List is returned in
8598 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008599
8600 Can also be used as a |method|: >
8601 GetStart()->reltime()
8602<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008603 Return type: list<number>
8604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008605 {only available when compiled with the |+reltime| feature}
8606
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008607
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008608reltimefloat({time}) *reltimefloat()*
8609 Return a Float that represents the time value of {time}.
8610 Example: >
8611 let start = reltime()
8612 call MyFunction()
8613 let seconds = reltimefloat(reltime(start))
8614< See the note of reltimestr() about overhead.
8615 Also see |profiling|.
8616 If there is an error 0.0 is returned in legacy script, in Vim9
8617 script an error is given.
8618
8619 Can also be used as a |method|: >
8620 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621<
8622 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008623
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008624 {only available when compiled with the |+reltime| feature}
8625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008626
8627reltimestr({time}) *reltimestr()*
8628 Return a String that represents the time value of {time}.
8629 This is the number of seconds, a dot and the number of
8630 microseconds. Example: >
8631 let start = reltime()
8632 call MyFunction()
8633 echo reltimestr(reltime(start))
8634< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008635 The accuracy depends on the system. Use reltimefloat() for the
8636 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008637 Leading spaces are used to make the string align nicely. You
8638 can use split() to remove it. >
8639 echo split(reltimestr(reltime(start)))[0]
8640< Also see |profiling|.
8641 If there is an error an empty string is returned in legacy
8642 script, in Vim9 script an error is given.
8643
8644 Can also be used as a |method|: >
8645 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008646<
8647 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008648
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008649 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008650
8651 *remote_expr()* *E449*
8652remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008653 Send the {string} to {server}. The {server} argument is a
8654 string, also see |{server}|.
8655
8656 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008657 after evaluation. The result must be a String or a |List|
8658 other types will be converted to String. A |List| is turned
8659 into a String by joining the items with a line break in
8660 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008662 If {idvar} is present and not empty, it is taken as the name
8663 of a variable and a {serverid} for later use with
8664 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008666 If {timeout} is given the read times out after this many
8667 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008669 See also |clientserver| |RemoteReply|.
8670 This function is not available in the |sandbox|.
8671 {only available when compiled with the |+clientserver| feature}
8672 Note: Any errors will cause a local error message to be issued
8673 and the result will be the empty string.
8674
8675 Variables will be evaluated in the global namespace,
8676 independent of a function currently being active. Except
8677 when in debug mode, then local function variables and
8678 arguments can be evaluated.
8679
8680 Examples: >
8681 :echo remote_expr("gvim", "2+2")
8682 :echo remote_expr("gvim1", "b:current_syntax")
8683<
8684 Can also be used as a |method|: >
8685 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008686<
8687 Return type: |String| or list<{type}>
8688
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008689
8690remote_foreground({server}) *remote_foreground()*
8691 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008692 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008693 This works like: >
8694 remote_expr({server}, "foreground()")
8695< Except that on Win32 systems the client does the work, to work
8696 around the problem that the OS doesn't always allow the server
8697 to bring itself to the foreground.
8698 Note: This does not restore the window if it was minimized,
8699 like foreground() does.
8700 This function is not available in the |sandbox|.
8701
8702 Can also be used as a |method|: >
8703 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008704<
8705 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008706
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008707 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008708 Win32 console version}
8709
8710
8711remote_peek({serverid} [, {retvar}]) *remote_peek()*
8712 Returns a positive number if there are available strings
8713 from {serverid}. Copies any reply string into the variable
8714 {retvar} if specified. {retvar} must be a string with the
8715 name of a variable.
8716 Returns zero if none are available.
8717 Returns -1 if something is wrong.
8718 See also |clientserver|.
8719 This function is not available in the |sandbox|.
8720 {only available when compiled with the |+clientserver| feature}
8721 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008722 :let repl = ""
8723 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008724
8725< Can also be used as a |method|: >
8726 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008727<
8728 Return type: |Number|
8729
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008730
8731remote_read({serverid}, [{timeout}]) *remote_read()*
8732 Return the oldest available reply from {serverid} and consume
8733 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008734 reply is available. Returns an empty string, if a reply is
8735 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008736 See also |clientserver|.
8737 This function is not available in the |sandbox|.
8738 {only available when compiled with the |+clientserver| feature}
8739 Example: >
8740 :echo remote_read(id)
8741
8742< Can also be used as a |method|: >
8743 ServerId()->remote_read()
8744<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008745 Return type: |String|
8746
8747
8748remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008749 Send the {string} to {server}. The {server} argument is a
8750 string, also see |{server}|.
8751
8752 The string is sent as input keys and the function returns
8753 immediately. At the Vim server the keys are not mapped
8754 |:map|.
8755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756 If {idvar} is present, it is taken as the name of a variable
8757 and a {serverid} for later use with remote_read() is stored
8758 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008759
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008760 See also |clientserver| |RemoteReply|.
8761 This function is not available in the |sandbox|.
8762 {only available when compiled with the |+clientserver| feature}
8763
8764 Note: Any errors will be reported in the server and may mess
8765 up the display.
8766 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008767 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008768 \ remote_read(serverid)
8769
8770 :autocmd NONE RemoteReply *
8771 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008772 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008773 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8774<
8775 Can also be used as a |method|: >
8776 ServerName()->remote_send(keys)
8777<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008778 Return type: |String|
8779
8780
8781remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008782 Become the server {name}. {name} must be a non-empty string.
8783 This fails if already running as a server, when |v:servername|
8784 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008785
8786 Can also be used as a |method|: >
8787 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008788<
8789 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008790
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008791 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008792
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008793
8794remove({list}, {idx}) *remove()*
8795remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008796 Without {end}: Remove the item at {idx} from |List| {list} and
8797 return the item.
8798 With {end}: Remove items from {idx} to {end} (inclusive) and
8799 return a |List| with these items. When {idx} points to the same
8800 item as {end} a list with one item is returned. When {end}
8801 points to an item before {idx} this is an error.
8802 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008803 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008804 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008805 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008806 :call remove(mylist, 0, 9)
8807<
8808 Use |delete()| to remove a file.
8809
8810 Can also be used as a |method|: >
8811 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008812<
8813 Return type: any, depending on {list}
8814
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008815
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008816remove({blob}, {idx})
8817remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008818 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8819 return the byte.
8820 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8821 return a |Blob| with these bytes. When {idx} points to the same
8822 byte as {end} a |Blob| with one byte is returned. When {end}
8823 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008824 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008825 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008826 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008827 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008828<
8829 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008830
8831remove({dict}, {key})
8832 Remove the entry from {dict} with key {key} and return it.
8833 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008834 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008835< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008836 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008837
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008838 Return type: any, depending on {dict}
8839
8840
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008841rename({from}, {to}) *rename()*
8842 Rename the file by the name {from} to the name {to}. This
8843 should also work to move files across file systems. The
8844 result is a Number, which is 0 if the file was renamed
8845 successfully, and non-zero when the renaming failed.
8846 NOTE: If {to} exists it is overwritten without warning.
8847 This function is not available in the |sandbox|.
8848
8849 Can also be used as a |method|: >
8850 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008851<
8852 Return type: |Number|
8853
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008854
8855repeat({expr}, {count}) *repeat()*
8856 Repeat {expr} {count} times and return the concatenated
8857 result. Example: >
8858 :let separator = repeat('-', 80)
8859< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008860 When {expr} is a |List| or a |Blob| the result is {expr}
8861 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008862 :let longlist = repeat(['a', 'b'], 3)
8863< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8864
8865 Can also be used as a |method|: >
8866 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008867<
8868 Return type: |String|, |Blob| or list<{type}> depending on
8869 {expr}
8870
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008871
8872resolve({filename}) *resolve()* *E655*
8873 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8874 returns the path the shortcut points to in a simplified form.
8875 When {filename} is a symbolic link or junction point, return
8876 the full path to the target. If the target of junction is
8877 removed, return {filename}.
8878 On Unix, repeat resolving symbolic links in all path
8879 components of {filename} and return the simplified result.
8880 To cope with link cycles, resolving of symbolic links is
8881 stopped after 100 iterations.
8882 On other systems, return the simplified {filename}.
8883 The simplification step is done as by |simplify()|.
8884 resolve() keeps a leading path component specifying the
8885 current directory (provided the result is still a relative
8886 path name) and also keeps a trailing path separator.
8887
8888 Can also be used as a |method|: >
8889 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008890<
8891 Return type: |String|
8892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008893
8894reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008895 Reverse the order of items in {object}. {object} can be a
8896 |List|, a |Blob| or a |String|. For a List and a Blob the
8897 items are reversed in-place and {object} is returned.
8898 For a String a new String is returned.
8899 Returns zero if {object} is not a List, Blob or a String.
8900 If you want a List or Blob to remain unmodified make a copy
8901 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008902 :let revlist = reverse(copy(mylist))
8903< Can also be used as a |method|: >
8904 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008905<
8906 Return type: |String|, |Blob| or list<{type}> depending on
8907 {object}
8908
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008909
8910round({expr}) *round()*
8911 Round off {expr} to the nearest integral value and return it
8912 as a |Float|. If {expr} lies halfway between two integral
8913 values, then use the larger one (away from zero).
8914 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008915 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008916 Examples: >
8917 echo round(0.456)
8918< 0.0 >
8919 echo round(4.5)
8920< 5.0 >
8921 echo round(-4.5)
8922< -5.0
8923
8924 Can also be used as a |method|: >
8925 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008926<
8927 Return type: |Float|
8928
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008929
8930rubyeval({expr}) *rubyeval()*
8931 Evaluate Ruby expression {expr} and return its result
8932 converted to Vim data structures.
8933 Numbers, floats and strings are returned as they are (strings
8934 are copied though).
8935 Arrays are represented as Vim |List| type.
8936 Hashes are represented as Vim |Dictionary| type.
8937 Other objects are represented as strings resulted from their
8938 "Object#to_s" method.
8939 Note that in a `:def` function local variables are not visible
8940 to {expr}.
8941
8942 Can also be used as a |method|: >
8943 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008944<
8945 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008946
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008947 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008948
8949screenattr({row}, {col}) *screenattr()*
8950 Like |screenchar()|, but return the attribute. This is a rather
8951 arbitrary number that can only be used to compare to the
8952 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008953 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008954
8955 Can also be used as a |method|: >
8956 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008957<
8958 Return type: |Number|
8959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008960
8961screenchar({row}, {col}) *screenchar()*
8962 The result is a Number, which is the character at position
8963 [row, col] on the screen. This works for every possible
8964 screen position, also status lines, window separators and the
8965 command line. The top left position is row one, column one
8966 The character excludes composing characters. For double-byte
8967 encodings it may only be the first byte.
8968 This is mainly to be used for testing.
8969 Returns -1 when row or col is out of range.
8970
8971 Can also be used as a |method|: >
8972 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008973<
8974 Return type: |Number|
8975
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008976
8977screenchars({row}, {col}) *screenchars()*
8978 The result is a |List| of Numbers. The first number is the same
8979 as what |screenchar()| returns. Further numbers are
8980 composing characters on top of the base character.
8981 This is mainly to be used for testing.
8982 Returns an empty List when row or col is out of range.
8983
8984 Can also be used as a |method|: >
8985 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008986<
8987 Return type: list<number> or list<any>
8988
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008989
8990screencol() *screencol()*
8991 The result is a Number, which is the current screen column of
8992 the cursor. The leftmost column has number 1.
8993 This function is mainly used for testing.
8994
8995 Note: Always returns the current screen column, thus if used
8996 in a command (e.g. ":echo screencol()") it will return the
8997 column inside the command line, which is 1 when the command is
8998 executed. To get the cursor position in the file use one of
8999 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009000 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009001 nnoremap <silent> GG :echom screencol()<CR>
9002 nnoremap GG <Cmd>echom screencol()<CR>
9003<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009004 Return type: |Number|
9005
9006
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009007screenpos({winid}, {lnum}, {col}) *screenpos()*
9008 The result is a Dict with the screen position of the text
9009 character in window {winid} at buffer line {lnum} and column
9010 {col}. {col} is a one-based byte index.
9011 The Dict has these members:
9012 row screen row
9013 col first screen column
9014 endcol last screen column
9015 curscol cursor screen column
9016 If the specified position is not visible, all values are zero.
9017 The "endcol" value differs from "col" when the character
9018 occupies more than one screen cell. E.g. for a Tab "col" can
9019 be 1 and "endcol" can be 8.
9020 The "curscol" value is where the cursor would be placed. For
9021 a Tab it would be the same as "endcol", while for a double
9022 width character it would be the same as "col".
9023 The |conceal| feature is ignored here, the column numbers are
9024 as if 'conceallevel' is zero. You can set the cursor to the
9025 right position and use |screencol()| to get the value with
9026 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009027 If the position is in a closed fold the screen position of the
9028 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009029 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009030
9031 Can also be used as a |method|: >
9032 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009033<
9034 Return type: dict<number> or dict<any>
9035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009036
9037screenrow() *screenrow()*
9038 The result is a Number, which is the current screen row of the
9039 cursor. The top line has number one.
9040 This function is mainly used for testing.
9041 Alternatively you can use |winline()|.
9042
9043 Note: Same restrictions as with |screencol()|.
9044
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009045 Return type: |Number|
9046
9047
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009048screenstring({row}, {col}) *screenstring()*
9049 The result is a String that contains the base character and
9050 any composing characters at position [row, col] on the screen.
9051 This is like |screenchars()| but returning a String with the
9052 characters.
9053 This is mainly to be used for testing.
9054 Returns an empty String when row or col is out of range.
9055
9056 Can also be used as a |method|: >
9057 GetRow()->screenstring(col)
9058<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009059 Return type: |String|
9060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009061 *search()*
9062search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9063 Search for regexp pattern {pattern}. The search starts at the
9064 cursor position (you can use |cursor()| to set it).
9065
9066 When a match has been found its line number is returned.
9067 If there is no match a 0 is returned and the cursor doesn't
9068 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009069 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009070
9071 {flags} is a String, which can contain these character flags:
9072 'b' search Backward instead of forward
9073 'c' accept a match at the Cursor position
9074 'e' move to the End of the match
9075 'n' do Not move the cursor
9076 'p' return number of matching sub-Pattern (see below)
9077 's' Set the ' mark at the previous location of the cursor
9078 'w' Wrap around the end of the file
9079 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009080 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009081 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9082
9083 If the 's' flag is supplied, the ' mark is set, only if the
9084 cursor is moved. The 's' flag cannot be combined with the 'n'
9085 flag.
9086
9087 'ignorecase', 'smartcase' and 'magic' are used.
9088
9089 When the 'z' flag is not given, forward searching always
9090 starts in column zero and then matches before the cursor are
9091 skipped. When the 'c' flag is present in 'cpo' the next
9092 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009093 search starts one column after the start of the match. This
9094 matters for overlapping matches. See |cpo-c|. You can also
9095 insert "\ze" to change where the match ends, see |/\ze|.
9096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009097 When searching backwards and the 'z' flag is given then the
9098 search starts in column zero, thus no match in the current
9099 line will be found (unless wrapping around the end of the
9100 file).
9101
9102 When the {stopline} argument is given then the search stops
9103 after searching this line. This is useful to restrict the
9104 search to a range of lines. Examples: >
9105 let match = search('(', 'b', line("w0"))
9106 let end = search('END', '', line("w$"))
9107< When {stopline} is used and it is not zero this also implies
9108 that the search does not wrap around the end of the file.
9109 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009110 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009111 When the {timeout} argument is given the search stops when
9112 more than this many milliseconds have passed. Thus when
9113 {timeout} is 500 the search stops after half a second.
9114 The value must not be negative. A zero value is like not
9115 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009116
9117 Note: the timeout is only considered when searching, not
9118 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009119 {only available when compiled with the |+reltime| feature}
9120
9121 If the {skip} expression is given it is evaluated with the
9122 cursor positioned on the start of a match. If it evaluates to
9123 non-zero this match is skipped. This can be used, for
9124 example, to skip a match in a comment or a string.
9125 {skip} can be a string, which is evaluated as an expression, a
9126 function reference or a lambda.
9127 When {skip} is omitted or empty, every match is accepted.
9128 When evaluating {skip} causes an error the search is aborted
9129 and -1 returned.
9130 *search()-sub-match*
9131 With the 'p' flag the returned value is one more than the
9132 first sub-match in \(\). One if none of them matched but the
9133 whole pattern did match.
9134 To get the column number too use |searchpos()|.
9135
9136 The cursor will be positioned at the match, unless the 'n'
9137 flag is used.
9138
9139 Example (goes over all files in the argument list): >
9140 :let n = 1
9141 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009142 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009143 : " start at the last char in the file and wrap for the
9144 : " first search to find match at start of file
9145 : normal G$
9146 : let flags = "w"
9147 : while search("foo", flags) > 0
9148 : s/foo/bar/g
9149 : let flags = "W"
9150 : endwhile
9151 : update " write the file if modified
9152 : let n = n + 1
9153 :endwhile
9154<
9155 Example for using some flags: >
9156 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9157< This will search for the keywords "if", "else", and "endif"
9158 under or after the cursor. Because of the 'p' flag, it
9159 returns 1, 2, or 3 depending on which keyword is found, or 0
9160 if the search fails. With the cursor on the first word of the
9161 line:
9162 if (foo == 0) | let foo = foo + 1 | endif ~
9163 the function returns 1. Without the 'c' flag, the function
9164 finds the "endif" and returns 3. The same thing happens
9165 without the 'e' flag if the cursor is on the "f" of "if".
9166 The 'n' flag tells the function not to move the cursor.
9167
9168 Can also be used as a |method|: >
9169 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009170<
9171 Return type: |Number|
9172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009173
9174searchcount([{options}]) *searchcount()*
9175 Get or update the last search count, like what is displayed
9176 without the "S" flag in 'shortmess'. This works even if
9177 'shortmess' does contain the "S" flag.
9178
9179 This returns a |Dictionary|. The dictionary is empty if the
9180 previous pattern was not set and "pattern" was not specified.
9181
9182 key type meaning ~
9183 current |Number| current position of match;
9184 0 if the cursor position is
9185 before the first match
9186 exact_match |Boolean| 1 if "current" is matched on
9187 "pos", otherwise 0
9188 total |Number| total count of matches found
9189 incomplete |Number| 0: search was fully completed
9190 1: recomputing was timed out
9191 2: max count exceeded
9192
9193 For {options} see further down.
9194
9195 To get the last search count when |n| or |N| was pressed, call
9196 this function with `recompute: 0` . This sometimes returns
9197 wrong information because |n| and |N|'s maximum count is 99.
9198 If it exceeded 99 the result must be max count + 1 (100). If
9199 you want to get correct information, specify `recompute: 1`: >
9200
9201 " result == maxcount + 1 (100) when many matches
9202 let result = searchcount(#{recompute: 0})
9203
9204 " Below returns correct result (recompute defaults
9205 " to 1)
9206 let result = searchcount()
9207<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009208 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009209 function! LastSearchCount() abort
9210 let result = searchcount(#{recompute: 0})
9211 if empty(result)
9212 return ''
9213 endif
9214 if result.incomplete ==# 1 " timed out
9215 return printf(' /%s [?/??]', @/)
9216 elseif result.incomplete ==# 2 " max count exceeded
9217 if result.total > result.maxcount &&
9218 \ result.current > result.maxcount
9219 return printf(' /%s [>%d/>%d]', @/,
9220 \ result.current, result.total)
9221 elseif result.total > result.maxcount
9222 return printf(' /%s [%d/>%d]', @/,
9223 \ result.current, result.total)
9224 endif
9225 endif
9226 return printf(' /%s [%d/%d]', @/,
9227 \ result.current, result.total)
9228 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009229 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009230
9231 " Or if you want to show the count only when
9232 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009233 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009234 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9235<
9236 You can also update the search count, which can be useful in a
9237 |CursorMoved| or |CursorMovedI| autocommand: >
9238
9239 autocmd CursorMoved,CursorMovedI *
9240 \ let s:searchcount_timer = timer_start(
9241 \ 200, function('s:update_searchcount'))
9242 function! s:update_searchcount(timer) abort
9243 if a:timer ==# s:searchcount_timer
9244 call searchcount(#{
9245 \ recompute: 1, maxcount: 0, timeout: 100})
9246 redrawstatus
9247 endif
9248 endfunction
9249<
9250 This can also be used to count matched texts with specified
9251 pattern in the current buffer using "pattern": >
9252
9253 " Count '\<foo\>' in this buffer
9254 " (Note that it also updates search count)
9255 let result = searchcount(#{pattern: '\<foo\>'})
9256
9257 " To restore old search count by old pattern,
9258 " search again
9259 call searchcount()
9260<
9261 {options} must be a |Dictionary|. It can contain:
9262 key type meaning ~
9263 recompute |Boolean| if |TRUE|, recompute the count
9264 like |n| or |N| was executed.
9265 otherwise returns the last
9266 computed result (when |n| or
9267 |N| was used when "S" is not
9268 in 'shortmess', or this
9269 function was called).
9270 (default: |TRUE|)
9271 pattern |String| recompute if this was given
9272 and different with |@/|.
9273 this works as same as the
9274 below command is executed
9275 before calling this function >
9276 let @/ = pattern
9277< (default: |@/|)
9278 timeout |Number| 0 or negative number is no
9279 timeout. timeout milliseconds
9280 for recomputing the result
9281 (default: 0)
9282 maxcount |Number| 0 or negative number is no
9283 limit. max count of matched
9284 text while recomputing the
9285 result. if search exceeded
9286 total count, "total" value
9287 becomes `maxcount + 1`
9288 (default: 99)
9289 pos |List| `[lnum, col, off]` value
9290 when recomputing the result.
9291 this changes "current" result
9292 value. see |cursor()|,
9293 |getpos()|
9294 (default: cursor's position)
9295
9296 Can also be used as a |method|: >
9297 GetSearchOpts()->searchcount()
9298<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009299 Return type: dict<number>
9300
9301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009302searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9303 Search for the declaration of {name}.
9304
9305 With a non-zero {global} argument it works like |gD|, find
9306 first match in the file. Otherwise it works like |gd|, find
9307 first match in the function.
9308
9309 With a non-zero {thisblock} argument matches in a {} block
9310 that ends before the cursor position are ignored. Avoids
9311 finding variable declarations only valid in another scope.
9312
9313 Moves the cursor to the found match.
9314 Returns zero for success, non-zero for failure.
9315 Example: >
9316 if searchdecl('myvar') == 0
9317 echo getline('.')
9318 endif
9319<
9320 Can also be used as a |method|: >
9321 GetName()->searchdecl()
9322<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009323 Return type: |Number|
9324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009325 *searchpair()*
9326searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9327 [, {stopline} [, {timeout}]]]])
9328 Search for the match of a nested start-end pair. This can be
9329 used to find the "endif" that matches an "if", while other
9330 if/endif pairs in between are ignored.
9331 The search starts at the cursor. The default is to search
9332 forward, include 'b' in {flags} to search backward.
9333 If a match is found, the cursor is positioned at it and the
9334 line number is returned. If no match is found 0 or -1 is
9335 returned and the cursor doesn't move. No error message is
9336 given.
9337
9338 {start}, {middle} and {end} are patterns, see |pattern|. They
9339 must not contain \( \) pairs. Use of \%( \) is allowed. When
9340 {middle} is not empty, it is found when searching from either
9341 direction, but only when not in a nested start-end pair. A
9342 typical use is: >
9343 searchpair('\<if\>', '\<else\>', '\<endif\>')
9344< By leaving {middle} empty the "else" is skipped.
9345
9346 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9347 |search()|. Additionally:
9348 'r' Repeat until no more matches found; will find the
9349 outer pair. Implies the 'W' flag.
9350 'm' Return number of matches instead of line number with
9351 the match; will be > 1 when 'r' is used.
9352 Note: it's nearly always a good idea to use the 'W' flag, to
9353 avoid wrapping around the end of the file.
9354
9355 When a match for {start}, {middle} or {end} is found, the
9356 {skip} expression is evaluated with the cursor positioned on
9357 the start of the match. It should return non-zero if this
9358 match is to be skipped. E.g., because it is inside a comment
9359 or a string.
9360 When {skip} is omitted or empty, every match is accepted.
9361 When evaluating {skip} causes an error the search is aborted
9362 and -1 returned.
9363 {skip} can be a string, a lambda, a funcref or a partial.
9364 Anything else makes the function fail.
9365 In a `:def` function when the {skip} argument is a string
9366 constant it is compiled into instructions.
9367
9368 For {stopline} and {timeout} see |search()|.
9369
9370 The value of 'ignorecase' is used. 'magic' is ignored, the
9371 patterns are used like it's on.
9372
9373 The search starts exactly at the cursor. A match with
9374 {start}, {middle} or {end} at the next character, in the
9375 direction of searching, is the first one found. Example: >
9376 if 1
9377 if 2
9378 endif 2
9379 endif 1
9380< When starting at the "if 2", with the cursor on the "i", and
9381 searching forwards, the "endif 2" is found. When starting on
9382 the character just before the "if 2", the "endif 1" will be
9383 found. That's because the "if 2" will be found first, and
9384 then this is considered to be a nested if/endif from "if 2" to
9385 "endif 2".
9386 When searching backwards and {end} is more than one character,
9387 it may be useful to put "\zs" at the end of the pattern, so
9388 that when the cursor is inside a match with the end it finds
9389 the matching start.
9390
9391 Example, to find the "endif" command in a Vim script: >
9392
9393 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9394 \ 'getline(".") =~ "^\\s*\""')
9395
9396< The cursor must be at or after the "if" for which a match is
9397 to be found. Note that single-quote strings are used to avoid
9398 having to double the backslashes. The skip expression only
9399 catches comments at the start of a line, not after a command.
9400 Also, a word "en" or "if" halfway a line is considered a
9401 match.
9402 Another example, to search for the matching "{" of a "}": >
9403
9404 :echo searchpair('{', '', '}', 'bW')
9405
9406< This works when the cursor is at or before the "}" for which a
9407 match is to be found. To reject matches that syntax
9408 highlighting recognized as strings: >
9409
9410 :echo searchpair('{', '', '}', 'bW',
9411 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9412<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009413 Return type: |Number|
9414
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009415 *searchpairpos()*
9416searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9417 [, {stopline} [, {timeout}]]]])
9418 Same as |searchpair()|, but returns a |List| with the line and
9419 column position of the match. The first element of the |List|
9420 is the line number and the second element is the byte index of
9421 the column position of the match. If no match is found,
9422 returns [0, 0]. >
9423
9424 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9425<
9426 See |match-parens| for a bigger and more useful example.
9427
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009428 Return type: list<number>
9429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009430 *searchpos()*
9431searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9432 Same as |search()|, but returns a |List| with the line and
9433 column position of the match. The first element of the |List|
9434 is the line number and the second element is the byte index of
9435 the column position of the match. If no match is found,
9436 returns [0, 0].
9437 Example: >
9438 :let [lnum, col] = searchpos('mypattern', 'n')
9439
9440< When the 'p' flag is given then there is an extra item with
9441 the sub-pattern match number |search()-sub-match|. Example: >
9442 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9443< In this example "submatch" is 2 when a lowercase letter is
9444 found |/\l|, 3 when an uppercase letter is found |/\u|.
9445
9446 Can also be used as a |method|: >
9447 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009448<
9449 Return type: list<number>
9450
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009451
9452server2client({clientid}, {string}) *server2client()*
9453 Send a reply string to {clientid}. The most recent {clientid}
9454 that sent a string can be retrieved with expand("<client>").
9455 {only available when compiled with the |+clientserver| feature}
9456 Returns zero for success, -1 for failure.
9457 Note:
9458 This id has to be stored before the next command can be
9459 received. I.e. before returning from the received command and
9460 before calling any commands that waits for input.
9461 See also |clientserver|.
9462 Example: >
9463 :echo server2client(expand("<client>"), "HELLO")
9464
9465< Can also be used as a |method|: >
9466 GetClientId()->server2client(string)
9467<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009468 Return type: |Number|
9469
9470
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009471serverlist() *serverlist()*
9472 Return a list of available server names, one per line.
9473 When there are no servers or the information is not available
9474 an empty string is returned. See also |clientserver|.
9475 {only available when compiled with the |+clientserver| feature}
9476 Example: >
9477 :echo serverlist()
9478<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009479 Return type: |String|
9480
9481
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009482setbufline({buf}, {lnum}, {text}) *setbufline()*
9483 Set line {lnum} to {text} in buffer {buf}. This works like
9484 |setline()| for the specified buffer.
9485
9486 This function works only for loaded buffers. First call
9487 |bufload()| if needed.
9488
9489 To insert lines use |appendbufline()|.
9490 Any text properties in {lnum} are cleared.
9491
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009492 {text} can be a string to set one line, or a List of strings
9493 to set multiple lines. If the List extends below the last
9494 line then those lines are added. If the List is empty then
9495 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009496
9497 For the use of {buf}, see |bufname()| above.
9498
9499 {lnum} is used like with |setline()|.
9500 Use "$" to refer to the last line in buffer {buf}.
9501 When {lnum} is just below the last line the {text} will be
9502 added below the last line.
9503
9504 When {buf} is not a valid buffer, the buffer is not loaded or
9505 {lnum} is not valid then 1 is returned. In |Vim9| script an
9506 error is given.
9507 On success 0 is returned.
9508
9509 Can also be used as a |method|, the base is passed as the
9510 third argument: >
9511 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009512<
9513 Return type: |Number|
9514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009515
9516setbufvar({buf}, {varname}, {val}) *setbufvar()*
9517 Set option or local variable {varname} in buffer {buf} to
9518 {val}.
9519 This also works for a global or local window option, but it
9520 doesn't work for a global or local window variable.
9521 For a local window option the global value is unchanged.
9522 For the use of {buf}, see |bufname()| above.
9523 The {varname} argument is a string.
9524 Note that the variable name without "b:" must be used.
9525 Examples: >
9526 :call setbufvar(1, "&mod", 1)
9527 :call setbufvar("todo", "myvar", "foobar")
9528< This function is not available in the |sandbox|.
9529
9530 Can also be used as a |method|, the base is passed as the
9531 third argument: >
9532 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009533<
9534 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009535
9536
9537setcellwidths({list}) *setcellwidths()*
9538 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009539 tells Vim how wide characters are when displayed in the
9540 terminal, counted in screen cells. The values override
9541 'ambiwidth'. Example: >
9542 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009543 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009544 \ [0x2194, 0x2199, 2],
9545 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009546
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009547< The {list} argument is a List of Lists with each three
9548 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9549 {low} and {high} can be the same, in which case this refers to
9550 one character. Otherwise it is the range of characters from
9551 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009552 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009553
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009554 {width} must be either 1 or 2, indicating the character width
9555 in screen cells. *E1112*
9556 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009557 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009558
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009559 If the new value causes 'fillchars' or 'listchars' to become
9560 invalid it is rejected and an error is given.
9561
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009562 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009563 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009565< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009566 the effect for known emoji characters. Move the cursor
9567 through the text to check if the cell widths of your terminal
9568 match with what Vim knows about each emoji. If it doesn't
9569 look right you need to adjust the {list} argument.
9570
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009571 Return type: |Number|
9572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009573
9574setcharpos({expr}, {list}) *setcharpos()*
9575 Same as |setpos()| but uses the specified column number as the
9576 character index instead of the byte index in the line.
9577
9578 Example:
9579 With the text "여보세요" in line 8: >
9580 call setcharpos('.', [0, 8, 4, 0])
9581< positions the cursor on the fourth character '요'. >
9582 call setpos('.', [0, 8, 4, 0])
9583< positions the cursor on the second character '보'.
9584
9585 Can also be used as a |method|: >
9586 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009587<
9588 Return type: |Number|
9589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009590
9591setcharsearch({dict}) *setcharsearch()*
9592 Set the current character search information to {dict},
9593 which contains one or more of the following entries:
9594
9595 char character which will be used for a subsequent
9596 |,| or |;| command; an empty string clears the
9597 character search
9598 forward direction of character search; 1 for forward,
9599 0 for backward
9600 until type of character search; 1 for a |t| or |T|
9601 character search, 0 for an |f| or |F|
9602 character search
9603
9604 This can be useful to save/restore a user's character search
9605 from a script: >
9606 :let prevsearch = getcharsearch()
9607 :" Perform a command which clobbers user's search
9608 :call setcharsearch(prevsearch)
9609< Also see |getcharsearch()|.
9610
9611 Can also be used as a |method|: >
9612 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009613<
9614 Return type: dict<any>
9615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009616
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009617setcmdline({str} [, {pos}]) *setcmdline()*
9618 Set the command line to {str} and set the cursor position to
9619 {pos}.
9620 If {pos} is omitted, the cursor is positioned after the text.
9621 Returns 0 when successful, 1 when not editing the command
9622 line.
9623
9624 Can also be used as a |method|: >
9625 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009626<
9627 Return type: |Number|
9628
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009629
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009630setcmdpos({pos}) *setcmdpos()*
9631 Set the cursor position in the command line to byte position
9632 {pos}. The first position is 1.
9633 Use |getcmdpos()| to obtain the current position.
9634 Only works while editing the command line, thus you must use
9635 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9636 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9637 set after the command line is set to the expression. For
9638 |c_CTRL-R_=| it is set after evaluating the expression but
9639 before inserting the resulting text.
9640 When the number is too big the cursor is put at the end of the
9641 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009642 Returns 0 when successful, 1 when not editing the command
9643 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009644
9645 Can also be used as a |method|: >
9646 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009647<
9648 Return type: |Number|
9649
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009650
9651setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9652setcursorcharpos({list})
9653 Same as |cursor()| but uses the specified column number as the
9654 character index instead of the byte index in the line.
9655
9656 Example:
9657 With the text "여보세요" in line 4: >
9658 call setcursorcharpos(4, 3)
9659< positions the cursor on the third character '세'. >
9660 call cursor(4, 3)
9661< positions the cursor on the first character '여'.
9662
9663 Can also be used as a |method|: >
9664 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009665<
9666 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009667
9668
9669setenv({name}, {val}) *setenv()*
9670 Set environment variable {name} to {val}. Example: >
9671 call setenv('HOME', '/home/myhome')
9672
9673< When {val} is |v:null| the environment variable is deleted.
9674 See also |expr-env|.
9675
9676 Can also be used as a |method|, the base is passed as the
9677 second argument: >
9678 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009679<
9680 Return type: |Number|
9681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009682
9683setfperm({fname}, {mode}) *setfperm()* *chmod*
9684 Set the file permissions for {fname} to {mode}.
9685 {mode} must be a string with 9 characters. It is of the form
9686 "rwxrwxrwx", where each group of "rwx" flags represent, in
9687 turn, the permissions of the owner of the file, the group the
9688 file belongs to, and other users. A '-' character means the
9689 permission is off, any other character means on. Multi-byte
9690 characters are not supported.
9691
9692 For example "rw-r-----" means read-write for the user,
9693 readable by the group, not accessible by others. "xx-x-----"
9694 would do the same thing.
9695
9696 Returns non-zero for success, zero for failure.
9697
9698 Can also be used as a |method|: >
9699 GetFilename()->setfperm(mode)
9700<
9701 To read permissions see |getfperm()|.
9702
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009703 Return type: |Number|
9704
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009705
9706setline({lnum}, {text}) *setline()*
9707 Set line {lnum} of the current buffer to {text}. To insert
9708 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009709 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009710 Any text properties in {lnum} are cleared. See
9711 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009712
9713 {lnum} is used like with |getline()|.
9714 When {lnum} is just below the last line the {text} will be
9715 added below the last line.
9716 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009717 converted to a String. When {text} is an empty List then
9718 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009719
9720 If this succeeds, FALSE is returned. If this fails (most likely
9721 because {lnum} is invalid) TRUE is returned.
9722 In |Vim9| script an error is given if {lnum} is invalid.
9723
9724 Example: >
9725 :call setline(5, strftime("%c"))
9726
9727< When {text} is a |List| then line {lnum} and following lines
9728 will be set to the items in the list. Example: >
9729 :call setline(5, ['aaa', 'bbb', 'ccc'])
9730< This is equivalent to: >
9731 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9732 : call setline(n, l)
9733 :endfor
9734
9735< Note: The '[ and '] marks are not set.
9736
9737 Can also be used as a |method|, the base is passed as the
9738 second argument: >
9739 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009740<
9741 Return type: |Number|
9742
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009743
9744setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9745 Create or replace or add to the location list for window {nr}.
9746 {nr} can be the window number or the |window-ID|.
9747 When {nr} is zero the current window is used.
9748
9749 For a location list window, the displayed location list is
9750 modified. For an invalid window number {nr}, -1 is returned.
9751 Otherwise, same as |setqflist()|.
9752 Also see |location-list|.
9753
9754 For {action} see |setqflist-action|.
9755
9756 If the optional {what} dictionary argument is supplied, then
9757 only the items listed in {what} are set. Refer to |setqflist()|
9758 for the list of supported keys in {what}.
9759
9760 Can also be used as a |method|, the base is passed as the
9761 second argument: >
9762 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009763<
9764 Return type: |Number|
9765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009766
9767setmatches({list} [, {win}]) *setmatches()*
9768 Restores a list of matches saved by |getmatches()| for the
9769 current window. Returns 0 if successful, otherwise -1. All
9770 current matches are cleared before the list is restored. See
9771 example for |getmatches()|.
9772 If {win} is specified, use the window with this number or
9773 window ID instead of the current window.
9774
9775 Can also be used as a |method|: >
9776 GetMatches()->setmatches()
9777<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009778 Return type: |Number|
9779
9780
9781setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009782 Set the position for String {expr}. Possible values:
9783 . the cursor
9784 'x mark x
9785
9786 {list} must be a |List| with four or five numbers:
9787 [bufnum, lnum, col, off]
9788 [bufnum, lnum, col, off, curswant]
9789
9790 "bufnum" is the buffer number. Zero can be used for the
9791 current buffer. When setting an uppercase mark "bufnum" is
9792 used for the mark position. For other marks it specifies the
9793 buffer to set the mark in. You can use the |bufnr()| function
9794 to turn a file name into a buffer number.
9795 For setting the cursor and the ' mark "bufnum" is ignored,
9796 since these are associated with a window, not a buffer.
9797 Does not change the jumplist.
9798
9799 "lnum" and "col" are the position in the buffer. The first
9800 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9801 smaller than 1 then 1 is used. To use the character count
9802 instead of the byte count, use |setcharpos()|.
9803
9804 The "off" number is only used when 'virtualedit' is set. Then
9805 it is the offset in screen columns from the start of the
9806 character. E.g., a position within a <Tab> or after the last
9807 character.
9808
9809 The "curswant" number is only used when setting the cursor
9810 position. It sets the preferred column for when moving the
9811 cursor vertically. When the "curswant" number is missing the
9812 preferred column is not set. When it is present and setting a
9813 mark position it is not used.
9814
9815 Note that for '< and '> changing the line number may result in
9816 the marks to be effectively be swapped, so that '< is always
9817 before '>.
9818
9819 Returns 0 when the position could be set, -1 otherwise.
9820 An error message is given if {expr} is invalid.
9821
9822 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9823
9824 This does not restore the preferred column for moving
9825 vertically; if you set the cursor position with this, |j| and
9826 |k| motions will jump to previous columns! Use |cursor()| to
9827 also set the preferred column. Also see the "curswant" key in
9828 |winrestview()|.
9829
9830 Can also be used as a |method|: >
9831 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009832<
9833 Return type: |Number|
9834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009835
9836setqflist({list} [, {action} [, {what}]]) *setqflist()*
9837 Create or replace or add to the quickfix list.
9838
9839 If the optional {what} dictionary argument is supplied, then
9840 only the items listed in {what} are set. The first {list}
9841 argument is ignored. See below for the supported items in
9842 {what}.
9843 *setqflist-what*
9844 When {what} is not present, the items in {list} are used. Each
9845 item must be a dictionary. Non-dictionary items in {list} are
9846 ignored. Each dictionary item can contain the following
9847 entries:
9848
9849 bufnr buffer number; must be the number of a valid
9850 buffer
9851 filename name of a file; only used when "bufnr" is not
9852 present or it is invalid.
9853 module name of a module; if given it will be used in
9854 quickfix error window instead of the filename.
9855 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009856 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009857 pattern search pattern used to locate the error
9858 col column number
9859 vcol when non-zero: "col" is visual column
9860 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009861 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009862 nr error number
9863 text description of the error
9864 type single-character error type, 'E', 'W', etc.
9865 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009866 user_data custom data associated with the item, can be
9867 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009868
9869 The "col", "vcol", "nr", "type" and "text" entries are
9870 optional. Either "lnum" or "pattern" entry can be used to
9871 locate a matching error line.
9872 If the "filename" and "bufnr" entries are not present or
9873 neither the "lnum" or "pattern" entries are present, then the
9874 item will not be handled as an error line.
9875 If both "pattern" and "lnum" are present then "pattern" will
9876 be used.
9877 If the "valid" entry is not supplied, then the valid flag is
9878 set when "bufnr" is a valid buffer or "filename" exists.
9879 If you supply an empty {list}, the quickfix list will be
9880 cleared.
9881 Note that the list is not exactly the same as what
9882 |getqflist()| returns.
9883
9884 {action} values: *setqflist-action* *E927*
9885 'a' The items from {list} are added to the existing
9886 quickfix list. If there is no existing list, then a
9887 new list is created.
9888
9889 'r' The items from the current quickfix list are replaced
9890 with the items from {list}. This can also be used to
9891 clear the list: >
9892 :call setqflist([], 'r')
9893<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009894 'u' Like 'r', but tries to preserve the current selection
9895 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009896 'f' All the quickfix lists in the quickfix stack are
9897 freed.
9898
9899 If {action} is not present or is set to ' ', then a new list
9900 is created. The new quickfix list is added after the current
9901 quickfix list in the stack and all the following lists are
9902 freed. To add a new quickfix list at the end of the stack,
9903 set "nr" in {what} to "$".
9904
9905 The following items can be specified in dictionary {what}:
9906 context quickfix list context. See |quickfix-context|
9907 efm errorformat to use when parsing text from
9908 "lines". If this is not present, then the
9909 'errorformat' option value is used.
9910 See |quickfix-parse|
9911 id quickfix list identifier |quickfix-ID|
9912 idx index of the current entry in the quickfix
9913 list specified by 'id' or 'nr'. If set to '$',
9914 then the last entry in the list is set as the
9915 current entry. See |quickfix-index|
9916 items list of quickfix entries. Same as the {list}
9917 argument.
9918 lines use 'errorformat' to parse a list of lines and
9919 add the resulting entries to the quickfix list
9920 {nr} or {id}. Only a |List| value is supported.
9921 See |quickfix-parse|
9922 nr list number in the quickfix stack; zero
9923 means the current quickfix list and "$" means
9924 the last quickfix list.
9925 quickfixtextfunc
9926 function to get the text to display in the
9927 quickfix window. The value can be the name of
9928 a function or a funcref or a lambda. Refer to
9929 |quickfix-window-function| for an explanation
9930 of how to write the function and an example.
9931 title quickfix list title text. See |quickfix-title|
9932 Unsupported keys in {what} are ignored.
9933 If the "nr" item is not present, then the current quickfix list
9934 is modified. When creating a new quickfix list, "nr" can be
9935 set to a value one greater than the quickfix stack size.
9936 When modifying a quickfix list, to guarantee that the correct
9937 list is modified, "id" should be used instead of "nr" to
9938 specify the list.
9939
9940 Examples (See also |setqflist-examples|): >
9941 :call setqflist([], 'r', {'title': 'My search'})
9942 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9943 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9944<
9945 Returns zero for success, -1 for failure.
9946
9947 This function can be used to create a quickfix list
9948 independent of the 'errorformat' setting. Use a command like
9949 `:cc 1` to jump to the first position.
9950
9951 Can also be used as a |method|, the base is passed as the
9952 second argument: >
9953 GetErrorlist()->setqflist()
9954<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009955 Return type: |Number|
9956
9957
9958setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009959 Set the register {regname} to {value}.
9960 If {regname} is "" or "@", the unnamed register '"' is used.
9961 The {regname} argument is a string. In |Vim9-script|
9962 {regname} must be one character.
9963
9964 {value} may be any value returned by |getreg()| or
9965 |getreginfo()|, including a |List| or |Dict|.
9966 If {options} contains "a" or {regname} is upper case,
9967 then the value is appended.
9968
9969 {options} can also contain a register type specification:
9970 "c" or "v" |characterwise| mode
9971 "l" or "V" |linewise| mode
9972 "b" or "<CTRL-V>" |blockwise-visual| mode
9973 If a number immediately follows "b" or "<CTRL-V>" then this is
9974 used as the width of the selection - if it is not specified
9975 then the width of the block is set to the number of characters
9976 in the longest line (counting a <Tab> as 1 character).
9977
9978 If {options} contains no register settings, then the default
9979 is to use character mode unless {value} ends in a <NL> for
9980 string {value} and linewise mode for list {value}. Blockwise
9981 mode is never selected automatically.
9982 Returns zero for success, non-zero for failure.
9983
9984 *E883*
9985 Note: you may not use |List| containing more than one item to
9986 set search and expression registers. Lists containing no
9987 items act like empty strings.
9988
9989 Examples: >
9990 :call setreg(v:register, @*)
9991 :call setreg('*', @%, 'ac')
9992 :call setreg('a', "1\n2\n3", 'b5')
9993 :call setreg('"', { 'points_to': 'a'})
9994
9995< This example shows using the functions to save and restore a
9996 register: >
9997 :let var_a = getreginfo()
9998 :call setreg('a', var_a)
9999< or: >
10000 :let var_a = getreg('a', 1, 1)
10001 :let var_amode = getregtype('a')
10002 ....
10003 :call setreg('a', var_a, var_amode)
10004< Note: you may not reliably restore register value
10005 without using the third argument to |getreg()| as without it
10006 newlines are represented as newlines AND Nul bytes are
10007 represented as newlines as well, see |NL-used-for-Nul|.
10008
10009 You can also change the type of a register by appending
10010 nothing: >
10011 :call setreg('a', '', 'al')
10012
10013< Can also be used as a |method|, the base is passed as the
10014 second argument: >
10015 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010016<
10017 Return type: |Number|
10018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010019
10020settabvar({tabnr}, {varname}, {val}) *settabvar()*
10021 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10022 |t:var|
10023 The {varname} argument is a string.
10024 Note that autocommands are blocked, side effects may not be
10025 triggered, e.g. when setting 'filetype'.
10026 Note that the variable name without "t:" must be used.
10027 Tabs are numbered starting with one.
10028 This function is not available in the |sandbox|.
10029
10030 Can also be used as a |method|, the base is passed as the
10031 third argument: >
10032 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010033<
10034 Return type: |Number|
10035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010036
10037settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10038 Set option or local variable {varname} in window {winnr} to
10039 {val}.
10040 Tabs are numbered starting with one. For the current tabpage
10041 use |setwinvar()|.
10042 {winnr} can be the window number or the |window-ID|.
10043 When {winnr} is zero the current window is used.
10044 Note that autocommands are blocked, side effects may not be
10045 triggered, e.g. when setting 'filetype' or 'syntax'.
10046 This also works for a global or local buffer option, but it
10047 doesn't work for a global or local buffer variable.
10048 For a local buffer option the global value is unchanged.
10049 Note that the variable name without "w:" must be used.
10050 Examples: >
10051 :call settabwinvar(1, 1, "&list", 0)
10052 :call settabwinvar(3, 2, "myvar", "foobar")
10053< This function is not available in the |sandbox|.
10054
10055 Can also be used as a |method|, the base is passed as the
10056 fourth argument: >
10057 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010058<
10059 Return type: |Number|
10060
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010061
10062settagstack({nr}, {dict} [, {action}]) *settagstack()*
10063 Modify the tag stack of the window {nr} using {dict}.
10064 {nr} can be the window number or the |window-ID|.
10065
10066 For a list of supported items in {dict}, refer to
10067 |gettagstack()|. "curidx" takes effect before changing the tag
10068 stack.
10069 *E962*
10070 How the tag stack is modified depends on the {action}
10071 argument:
10072 - If {action} is not present or is set to 'r', then the tag
10073 stack is replaced.
10074 - If {action} is set to 'a', then new entries from {dict} are
10075 pushed (added) onto the tag stack.
10076 - If {action} is set to 't', then all the entries from the
10077 current entry in the tag stack or "curidx" in {dict} are
10078 removed and then new entries are pushed to the stack.
10079
10080 The current index is set to one after the length of the tag
10081 stack after the modification.
10082
10083 Returns zero for success, -1 for failure.
10084
10085 Examples (for more examples see |tagstack-examples|):
10086 Empty the tag stack of window 3: >
10087 call settagstack(3, {'items' : []})
10088
10089< Save and restore the tag stack: >
10090 let stack = gettagstack(1003)
10091 " do something else
10092 call settagstack(1003, stack)
10093 unlet stack
10094<
10095 Can also be used as a |method|, the base is passed as the
10096 second argument: >
10097 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010098<
10099 Return type: |Number|
10100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010101
10102setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10103 Like |settabwinvar()| for the current tab page.
10104 Examples: >
10105 :call setwinvar(1, "&list", 0)
10106 :call setwinvar(2, "myvar", "foobar")
10107
10108< Can also be used as a |method|, the base is passed as the
10109 third argument: >
10110 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010111<
10112 Return type: |Number|
10113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010114
10115sha256({string}) *sha256()*
10116 Returns a String with 64 hex characters, which is the SHA256
10117 checksum of {string}.
10118
10119 Can also be used as a |method|: >
10120 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010121<
10122 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010123
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010124 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010125
10126shellescape({string} [, {special}]) *shellescape()*
10127 Escape {string} for use as a shell command argument.
10128 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010129 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010130 in single quotes and will double up all internal single
10131 quotes.
10132 On MS-Windows, when 'shellslash' is not set, it will enclose
10133 {string} in double quotes and double all double quotes within
10134 {string}.
10135 Otherwise it will enclose {string} in single quotes and
10136 replace all "'" with "'\''".
10137
Enno5faeb602024-05-15 21:54:19 +020010138 The {special} argument adds additional escaping of keywords
10139 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010140 number or a non-empty String (|non-zero-arg|), then special
10141 items such as "!", "%", "#" and "<cword>" (as listed in
10142 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010143 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010144
10145 The "!" character will be escaped (again with a |non-zero-arg|
10146 {special}) when 'shell' contains "csh" in the tail. That is
10147 because for csh and tcsh "!" is used for history replacement
10148 even when inside single quotes.
10149
10150 With a |non-zero-arg| {special} the <NL> character is also
10151 escaped. When 'shell' containing "csh" in the tail it's
10152 escaped a second time.
10153
10154 The "\" character will be escaped when 'shell' contains "fish"
10155 in the tail. That is because for fish "\" is used as an escape
10156 character inside single quotes.
10157
10158 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010159 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010160< This results in a directory listing for the file under the
10161 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010162 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010163< See also |::S|.
10164
10165 Can also be used as a |method|: >
10166 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010167<
10168 Return type: |String|
10169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010170
10171shiftwidth([{col}]) *shiftwidth()*
10172 Returns the effective value of 'shiftwidth'. This is the
10173 'shiftwidth' value unless it is zero, in which case it is the
10174 'tabstop' value. This function was introduced with patch
10175 7.3.694 in 2012, everybody should have it by now (however it
10176 did not allow for the optional {col} argument until 8.1.542).
10177
10178 When there is one argument {col} this is used as column number
10179 for which to return the 'shiftwidth' value. This matters for the
10180 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10181 no {col} argument is given, column 1 will be assumed.
10182
10183 Can also be used as a |method|: >
10184 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010185<
10186 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010187
10188sign_ functions are documented here: |sign-functions-details|
10189
10190
10191simplify({filename}) *simplify()*
10192 Simplify the file name as much as possible without changing
10193 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10194 Unix) are not resolved. If the first path component in
10195 {filename} designates the current directory, this will be
10196 valid for the result as well. A trailing path separator is
10197 not removed either. On Unix "//path" is unchanged, but
10198 "///path" is simplified to "/path" (this follows the Posix
10199 standard).
10200 Example: >
10201 simplify("./dir/.././/file/") == "./file/"
10202< Note: The combination "dir/.." is only removed if "dir" is
10203 a searchable directory or does not exist. On Unix, it is also
10204 removed when "dir" is a symbolic link within the same
10205 directory. In order to resolve all the involved symbolic
10206 links before simplifying the path name, use |resolve()|.
10207
10208 Can also be used as a |method|: >
10209 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010210<
10211 Return type: |String|
10212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010213
10214sin({expr}) *sin()*
10215 Return the sine of {expr}, measured in radians, as a |Float|.
10216 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010217 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010218 Examples: >
10219 :echo sin(100)
10220< -0.506366 >
10221 :echo sin(-4.01)
10222< 0.763301
10223
10224 Can also be used as a |method|: >
10225 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010226<
10227 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010228
10229
10230sinh({expr}) *sinh()*
10231 Return the hyperbolic sine of {expr} as a |Float| in the range
10232 [-inf, inf].
10233 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010234 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010235 Examples: >
10236 :echo sinh(0.5)
10237< 0.521095 >
10238 :echo sinh(-0.9)
10239< -1.026517
10240
10241 Can also be used as a |method|: >
10242 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010243<
10244 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010245
10246
10247slice({expr}, {start} [, {end}]) *slice()*
10248 Similar to using a |slice| "expr[start : end]", but "end" is
10249 used exclusive. And for a string the indexes are used as
10250 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010251 |vim9script|. Also, composing characters are treated as a
10252 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010253 When {end} is omitted the slice continues to the last item.
10254 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010255 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010256
10257 Can also be used as a |method|: >
10258 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010259<
10260 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010261
10262
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010263sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010264 Sort the items in {list} in-place. Returns {list}.
10265
10266 If you want a list to remain unmodified make a copy first: >
10267 :let sortedlist = sort(copy(mylist))
10268
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010269< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010270 string representation of each item to sort on. Numbers sort
10271 after Strings, |Lists| after Numbers. For sorting text in the
10272 current buffer use |:sort|.
10273
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010274 When {how} is given and it is 'i' then case is ignored.
10275 In legacy script, for backwards compatibility, the value one
10276 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010277
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010278 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010279 locale is used for ordering. Implementation details: strcoll()
10280 is used to compare strings. See |:language| check or set the
10281 collation locale. |v:collate| can also be used to check the
10282 current locale. Sorting using the locale typically ignores
10283 case. Example: >
10284 " ö is sorted similarly to o with English locale.
10285 :language collate en_US.UTF8
10286 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10287< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10288>
10289 " ö is sorted after z with Swedish locale.
10290 :language collate sv_SE.UTF8
10291 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10292< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10293 This does not work properly on Mac.
10294
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010295 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010296 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010297 strtod() function to parse numbers. Strings, Lists, Dicts and
10298 Funcrefs will be considered as being 0). Note that this won't
10299 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010300
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010301 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010302 sorted numerical. This is like 'n' but a string containing
10303 digits will be used as the number they represent.
10304
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010305 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010306 sorted numerical. All values must be a Number or a Float.
10307
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010308 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010309 is called to compare items. The function is invoked with two
10310 items as argument and must return zero if they are equal, 1 or
10311 bigger if the first one sorts after the second one, -1 or
10312 smaller if the first one sorts before the second one.
10313
10314 {dict} is for functions with the "dict" attribute. It will be
10315 used to set the local variable "self". |Dictionary-function|
10316
10317 The sort is stable, items which compare equal (as number or as
10318 string) will keep their relative position. E.g., when sorting
10319 on numbers, text strings will sort next to each other, in the
10320 same order as they were originally.
10321
10322 Can also be used as a |method|: >
10323 mylist->sort()
10324
10325< Also see |uniq()|.
10326
10327 Example: >
10328 func MyCompare(i1, i2)
10329 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10330 endfunc
10331 eval mylist->sort("MyCompare")
10332< A shorter compare version for this specific simple case, which
10333 ignores overflow: >
10334 func MyCompare(i1, i2)
10335 return a:i1 - a:i2
10336 endfunc
10337< For a simple expression you can use a lambda: >
10338 eval mylist->sort({i1, i2 -> i1 - i2})
10339<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010340 Return type: list<{type}>
10341
10342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010343sound_clear() *sound_clear()*
10344 Stop playing all sounds.
10345
10346 On some Linux systems you may need the libcanberra-pulse
10347 package, otherwise sound may not stop.
10348
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010349 Return type: |Number|
10350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010351 {only available when compiled with the |+sound| feature}
10352
10353 *sound_playevent()*
10354sound_playevent({name} [, {callback}])
10355 Play a sound identified by {name}. Which event names are
10356 supported depends on the system. Often the XDG sound names
10357 are used. On Ubuntu they may be found in
10358 /usr/share/sounds/freedesktop/stereo. Example: >
10359 call sound_playevent('bell')
10360< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10361 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10362 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010363 On macOS, {name} refers to files located in
10364 /System/Library/Sounds (e.g. "Tink"). It will also work for
10365 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010366
10367 When {callback} is specified it is invoked when the sound is
10368 finished. The first argument is the sound ID, the second
10369 argument is the status:
10370 0 sound was played to the end
10371 1 sound was interrupted
10372 2 error occurred after sound started
10373 Example: >
10374 func Callback(id, status)
10375 echomsg "sound " .. a:id .. " finished with " .. a:status
10376 endfunc
10377 call sound_playevent('bell', 'Callback')
10378
10379< MS-Windows: {callback} doesn't work for this function.
10380
10381 Returns the sound ID, which can be passed to `sound_stop()`.
10382 Returns zero if the sound could not be played.
10383
10384 Can also be used as a |method|: >
10385 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010386<
10387 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010388
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010389 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010390
10391 *sound_playfile()*
10392sound_playfile({path} [, {callback}])
10393 Like `sound_playevent()` but play sound file {path}. {path}
10394 must be a full path. On Ubuntu you may find files to play
10395 with this command: >
10396 :!find /usr/share/sounds -type f | grep -v index.theme
10397
10398< Can also be used as a |method|: >
10399 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010400<
10401 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010402
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010403 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010404
10405
10406sound_stop({id}) *sound_stop()*
10407 Stop playing sound {id}. {id} must be previously returned by
10408 `sound_playevent()` or `sound_playfile()`.
10409
10410 On some Linux systems you may need the libcanberra-pulse
10411 package, otherwise sound may not stop.
10412
10413 On MS-Windows, this does not work for event sound started by
10414 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10415
10416 Can also be used as a |method|: >
10417 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010418<
10419 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010420
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010421 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010422
10423 *soundfold()*
10424soundfold({word})
10425 Return the sound-folded equivalent of {word}. Uses the first
10426 language in 'spelllang' for the current window that supports
10427 soundfolding. 'spell' must be set. When no sound folding is
10428 possible the {word} is returned unmodified.
10429 This can be used for making spelling suggestions. Note that
10430 the method can be quite slow.
10431
10432 Can also be used as a |method|: >
10433 GetWord()->soundfold()
10434<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010435 Return type: |String|
10436
10437
10438spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010439 Without argument: The result is the badly spelled word under
10440 or after the cursor. The cursor is moved to the start of the
10441 bad word. When no bad word is found in the cursor line the
10442 result is an empty string and the cursor doesn't move.
10443
10444 With argument: The result is the first word in {sentence} that
10445 is badly spelled. If there are no spelling mistakes the
10446 result is an empty string.
10447
10448 The return value is a list with two items:
10449 - The badly spelled word or an empty string.
10450 - The type of the spelling error:
10451 "bad" spelling mistake
10452 "rare" rare word
10453 "local" word only valid in another region
10454 "caps" word should start with Capital
10455 Example: >
10456 echo spellbadword("the quik brown fox")
10457< ['quik', 'bad'] ~
10458
10459 The spelling information for the current window and the value
10460 of 'spelllang' are used.
10461
10462 Can also be used as a |method|: >
10463 GetText()->spellbadword()
10464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010465 Return type: list<string>
10466
10467
10468spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010469 Return a |List| with spelling suggestions to replace {word}.
10470 When {max} is given up to this number of suggestions are
10471 returned. Otherwise up to 25 suggestions are returned.
10472
10473 When the {capital} argument is given and it's non-zero only
10474 suggestions with a leading capital will be given. Use this
10475 after a match with 'spellcapcheck'.
10476
10477 {word} can be a badly spelled word followed by other text.
10478 This allows for joining two words that were split. The
10479 suggestions also include the following text, thus you can
10480 replace a line.
10481
10482 {word} may also be a good word. Similar words will then be
10483 returned. {word} itself is not included in the suggestions,
10484 although it may appear capitalized.
10485
10486 The spelling information for the current window is used. The
10487 values of 'spelllang' and 'spellsuggest' are used.
10488
10489 Can also be used as a |method|: >
10490 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010491<
10492 Return type: list<string> or list<any>
10493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010494
10495split({string} [, {pattern} [, {keepempty}]]) *split()*
10496 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010497 empty each white space separated sequence of characters
10498 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010499 Otherwise the string is split where {pattern} matches,
10500 removing the matched characters. 'ignorecase' is not used
10501 here, add \c to ignore case. |/\c|
10502 When the first or last item is empty it is omitted, unless the
10503 {keepempty} argument is given and it's non-zero.
10504 Other empty items are kept when {pattern} matches at least one
10505 character or when {keepempty} is non-zero.
10506 Example: >
10507 :let words = split(getline('.'), '\W\+')
10508< To split a string in individual characters: >
10509 :for c in split(mystring, '\zs')
10510< If you want to keep the separator you can also use '\zs' at
10511 the end of the pattern: >
10512 :echo split('abc:def:ghi', ':\zs')
10513< ['abc:', 'def:', 'ghi'] ~
10514 Splitting a table where the first element can be empty: >
10515 :let items = split(line, ':', 1)
10516< The opposite function is |join()|.
10517
10518 Can also be used as a |method|: >
10519 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010520<
10521 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010522
10523sqrt({expr}) *sqrt()*
10524 Return the non-negative square root of Float {expr} as a
10525 |Float|.
10526 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010527 is negative the result is NaN (Not a Number). Returns 0.0 if
10528 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010529 Examples: >
10530 :echo sqrt(100)
10531< 10.0 >
10532 :echo sqrt(-4.01)
10533< nan
10534 "nan" may be different, it depends on system libraries.
10535
10536 Can also be used as a |method|: >
10537 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010538<
10539 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010540
10541
10542srand([{expr}]) *srand()*
10543 Initialize seed used by |rand()|:
10544 - If {expr} is not given, seed values are initialized by
10545 reading from /dev/urandom, if possible, or using time(NULL)
10546 a.k.a. epoch time otherwise; this only has second accuracy.
10547 - If {expr} is given it must be a Number. It is used to
10548 initialize the seed values. This is useful for testing or
10549 when a predictable sequence is intended.
10550
10551 Examples: >
10552 :let seed = srand()
10553 :let seed = srand(userinput)
10554 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010555<
10556 Return type: list<number>
10557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010558
10559state([{what}]) *state()*
10560 Return a string which contains characters indicating the
10561 current state. Mostly useful in callbacks that want to do
10562 work that may not always be safe. Roughly this works like:
10563 - callback uses state() to check if work is safe to do.
10564 Yes: then do it right away.
10565 No: add to work queue and add a |SafeState| and/or
10566 |SafeStateAgain| autocommand (|SafeState| triggers at
10567 toplevel, |SafeStateAgain| triggers after handling
10568 messages and callbacks).
10569 - When SafeState or SafeStateAgain is triggered and executes
10570 your autocommand, check with `state()` if the work can be
10571 done now, and if yes remove it from the queue and execute.
10572 Remove the autocommand if the queue is now empty.
10573 Also see |mode()|.
10574
10575 When {what} is given only characters in this string will be
10576 added. E.g, this checks if the screen has scrolled: >
10577 if state('s') == ''
10578 " screen has not scrolled
10579<
10580 These characters indicate the state, generally indicating that
10581 something is busy:
10582 m halfway a mapping, :normal command, feedkeys() or
10583 stuffed command
10584 o operator pending, e.g. after |d|
10585 a Insert mode autocomplete active
10586 x executing an autocommand
10587 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10588 ch_readraw() when reading json
10589 S not triggering SafeState or SafeStateAgain, e.g. after
10590 |f| or a count
10591 c callback invoked, including timer (repeats for
10592 recursiveness up to "ccc")
10593 s screen has scrolled for messages
10594
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010595 Return type: |String|
10596
10597
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010598str2blob({list} [, {options}]) *str2blob()*
10599 Return a Blob by converting the characters in the List of
10600 strings in {list} into bytes.
10601
10602 A <NL> byte is added to the blob after each list item. A
10603 newline character in the string is translated into a <NUL>
10604 byte in the blob.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010605
10606 If {options} is not supplied, the current 'encoding' value is
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010607 used to convert the characters into bytes.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010608
10609 The argument {options} is a |Dict| and supports the following
10610 items:
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010611 encoding Encode the characters using this encoding.
10612 The value is a |String|. See |encoding-names|
10613 for the supported values.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010614
10615 An error is given and an empty blob is returned if the
10616 character encoding fails.
10617
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010618 Returns an empty Blob if {list} is empty.
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010619
10620 See also |blob2str()|
10621
10622 Examples: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010623 str2blob(["ab"]) returns 0z6162
10624 str2blob(["«»"]) returns 0zC2ABC2BB
10625 str2blob(["a\nb"]) returns 0z610A62
10626 str2blob(readfile('myfile.txt'))
10627 str2blob(["«»"], {'encoding': 'latin1'}) returns 0zABBB
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010628<
10629 Can also be used as a |method|: >
Yegappan Lakshmanana11b23c2025-01-16 19:16:42 +010010630 GetListOfStrings()->str2blob()
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010631<
10632 Return type: |Blob|
10633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010634str2float({string} [, {quoted}]) *str2float()*
10635 Convert String {string} to a Float. This mostly works the
10636 same as when using a floating point number in an expression,
10637 see |floating-point-format|. But it's a bit more permissive.
10638 E.g., "1e40" is accepted, while in an expression you need to
10639 write "1.0e40". The hexadecimal form "0x123" is also
10640 accepted, but not others, like binary or octal.
10641 When {quoted} is present and non-zero then embedded single
10642 quotes before the dot are ignored, thus "1'000.0" is a
10643 thousand.
10644 Text after the number is silently ignored.
10645 The decimal point is always '.', no matter what the locale is
10646 set to. A comma ends the number: "12,345.67" is converted to
10647 12.0. You can strip out thousands separators with
10648 |substitute()|: >
10649 let f = str2float(substitute(text, ',', '', 'g'))
10650<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010651 Returns 0.0 if the conversion fails.
10652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010653 Can also be used as a |method|: >
10654 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010655<
10656 Return type: |Float|
10657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010658
10659str2list({string} [, {utf8}]) *str2list()*
10660 Return a list containing the number values which represent
10661 each character in String {string}. Examples: >
10662 str2list(" ") returns [32]
10663 str2list("ABC") returns [65, 66, 67]
10664< |list2str()| does the opposite.
10665
10666 When {utf8} is omitted or zero, the current 'encoding' is used.
10667 When {utf8} is TRUE, always treat the String as UTF-8
10668 characters. With UTF-8 composing characters are handled
10669 properly: >
10670 str2list("á") returns [97, 769]
10671
10672< Can also be used as a |method|: >
10673 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010674<
10675 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010676
10677
10678str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10679 Convert string {string} to a number.
10680 {base} is the conversion base, it can be 2, 8, 10 or 16.
10681 When {quoted} is present and non-zero then embedded single
10682 quotes are ignored, thus "1'000'000" is a million.
10683
10684 When {base} is omitted base 10 is used. This also means that
10685 a leading zero doesn't cause octal conversion to be used, as
10686 with the default String to Number conversion. Example: >
10687 let nr = str2nr('0123')
10688<
10689 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10690 different base the result will be zero. Similarly, when
10691 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10692 {base} is 2 a leading "0b" or "0B" is ignored.
10693 Text after the number is silently ignored.
10694
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010695 Returns 0 if {string} is empty or on error.
10696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010697 Can also be used as a |method|: >
10698 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010699<
10700 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010701
10702
10703strcharlen({string}) *strcharlen()*
10704 The result is a Number, which is the number of characters
10705 in String {string}. Composing characters are ignored.
10706 |strchars()| can count the number of characters, counting
10707 composing characters separately.
10708
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010709 Returns 0 if {string} is empty or on error.
10710
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010711 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10712
10713 Can also be used as a |method|: >
10714 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010715<
10716 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010717
10718
10719strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10720 Like |strpart()| but using character index and length instead
10721 of byte index and length.
10722 When {skipcc} is omitted or zero, composing characters are
10723 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010724 When {skipcc} set to 1, composing characters are treated as a
10725 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010726 When a character index is used where a character does not
10727 exist it is omitted and counted as one character. For
10728 example: >
10729 strcharpart('abc', -1, 2)
10730< results in 'a'.
10731
Bram Moolenaard592deb2022-06-17 15:42:40 +010010732 Returns an empty string on error.
10733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010734 Can also be used as a |method|: >
10735 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010736<
10737 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010738
10739
10740strchars({string} [, {skipcc}]) *strchars()*
10741 The result is a Number, which is the number of characters
10742 in String {string}.
10743 When {skipcc} is omitted or zero, composing characters are
10744 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010745 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010746 |strcharlen()| always does this.
10747
Bram Moolenaard592deb2022-06-17 15:42:40 +010010748 Returns zero on error.
10749
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010750 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10751
10752 {skipcc} is only available after 7.4.755. For backward
10753 compatibility, you can define a wrapper function: >
10754 if has("patch-7.4.755")
10755 function s:strchars(str, skipcc)
10756 return strchars(a:str, a:skipcc)
10757 endfunction
10758 else
10759 function s:strchars(str, skipcc)
10760 if a:skipcc
10761 return strlen(substitute(a:str, ".", "x", "g"))
10762 else
10763 return strchars(a:str)
10764 endif
10765 endfunction
10766 endif
10767<
10768 Can also be used as a |method|: >
10769 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010770<
10771 Return type: |Number|
10772
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010773
10774strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10775 The result is a Number, which is the number of display cells
10776 String {string} occupies on the screen when it starts at {col}
10777 (first column is zero). When {col} is omitted zero is used.
10778 Otherwise it is the screen column where to start. This
10779 matters for Tab characters.
10780 The option settings of the current window are used. This
10781 matters for anything that's displayed differently, such as
10782 'tabstop' and 'display'.
10783 When {string} contains characters with East Asian Width Class
10784 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010785 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010786 Also see |strlen()|, |strwidth()| and |strchars()|.
10787
10788 Can also be used as a |method|: >
10789 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010790<
10791 Return type: |Number|
10792
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010793
10794strftime({format} [, {time}]) *strftime()*
10795 The result is a String, which is a formatted date and time, as
10796 specified by the {format} string. The given {time} is used,
10797 or the current time if no time is given. The accepted
10798 {format} depends on your system, thus this is not portable!
10799 See the manual page of the C function strftime() for the
10800 format. The maximum length of the result is 80 characters.
10801 See also |localtime()|, |getftime()| and |strptime()|.
10802 The language can be changed with the |:language| command.
10803 Examples: >
10804 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10805 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10806 :echo strftime("%y%m%d %T") 970427 11:53:55
10807 :echo strftime("%H:%M") 11:55
10808 :echo strftime("%c", getftime("file.c"))
10809 Show mod time of file.c.
10810< Not available on all systems. To check use: >
10811 :if exists("*strftime")
10812
10813< Can also be used as a |method|: >
10814 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010815<
10816 Return type: |String|
10817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010818
10819strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010820 Get a Number corresponding to the character at {index} in
10821 {str}. This uses a zero-based character index, not a byte
10822 index. Composing characters are considered separate
10823 characters here. Use |nr2char()| to convert the Number to a
10824 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010825 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010826 Also see |strcharpart()| and |strchars()|.
10827
10828 Can also be used as a |method|: >
10829 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010830<
10831 Return type: |Number|
10832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010833
10834stridx({haystack}, {needle} [, {start}]) *stridx()*
10835 The result is a Number, which gives the byte index in
10836 {haystack} of the first occurrence of the String {needle}.
10837 If {start} is specified, the search starts at index {start}.
10838 This can be used to find a second match: >
10839 :let colon1 = stridx(line, ":")
10840 :let colon2 = stridx(line, ":", colon1 + 1)
10841< The search is done case-sensitive.
10842 For pattern searches use |match()|.
10843 -1 is returned if the {needle} does not occur in {haystack}.
10844 See also |strridx()|.
10845 Examples: >
10846 :echo stridx("An Example", "Example") 3
10847 :echo stridx("Starting point", "Start") 0
10848 :echo stridx("Starting point", "start") -1
10849< *strstr()* *strchr()*
10850 stridx() works similar to the C function strstr(). When used
10851 with a single character it works similar to strchr().
10852
10853 Can also be used as a |method|: >
10854 GetHaystack()->stridx(needle)
10855<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010856 Return type: |Number|
10857
10858
10859string({expr}) *string()*
10860 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010861 Float, String, Blob or a composition of them, then the result
10862 can be parsed back with |eval()|.
10863 {expr} type result ~
10864 String 'string' (single quotes are doubled)
10865 Number 123
10866 Float 123.123456 or 1.123456e8
10867 Funcref function('name')
10868 Blob 0z00112233.44556677.8899
10869 List [item, item]
10870 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010871 Class class SomeName
10872 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010873 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010874 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010875
10876 When a |List| or |Dictionary| has a recursive reference it is
10877 replaced by "[...]" or "{...}". Using eval() on the result
10878 will then fail.
10879
mityu7f0bba22024-03-29 10:14:41 +010010880 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010881 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010882 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010883
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010884 Can also be used as a |method|: >
10885 mylist->string()
10886
10887< Also see |strtrans()|.
10888
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010889 Return type: |String|
10890
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010891
10892strlen({string}) *strlen()*
10893 The result is a Number, which is the length of the String
10894 {string} in bytes.
10895 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010896 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010897 If you want to count the number of multibyte characters use
10898 |strchars()|.
10899 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10900
10901 Can also be used as a |method|: >
10902 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010903<
10904 Return type: |Number|
10905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010906
10907strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10908 The result is a String, which is part of {src}, starting from
10909 byte {start}, with the byte length {len}.
10910 When {chars} is present and TRUE then {len} is the number of
10911 characters positions (composing characters are not counted
10912 separately, thus "1" means one base character and any
10913 following composing characters).
10914 To count {start} as characters instead of bytes use
10915 |strcharpart()|.
10916
10917 When bytes are selected which do not exist, this doesn't
10918 result in an error, the bytes are simply omitted.
10919 If {len} is missing, the copy continues from {start} till the
10920 end of the {src}. >
10921 strpart("abcdefg", 3, 2) == "de"
10922 strpart("abcdefg", -2, 4) == "ab"
10923 strpart("abcdefg", 5, 4) == "fg"
10924 strpart("abcdefg", 3) == "defg"
10925
10926< Note: To get the first character, {start} must be 0. For
10927 example, to get the character under the cursor: >
10928 strpart(getline("."), col(".") - 1, 1, v:true)
10929<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010930 Returns an empty string on error.
10931
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010932 Can also be used as a |method|: >
10933 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010934<
10935 Return type: |String|
10936
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010937
10938strptime({format}, {timestring}) *strptime()*
10939 The result is a Number, which is a unix timestamp representing
10940 the date and time in {timestring}, which is expected to match
10941 the format specified in {format}.
10942
10943 The accepted {format} depends on your system, thus this is not
10944 portable! See the manual page of the C function strptime()
10945 for the format. Especially avoid "%c". The value of $TZ also
10946 matters.
10947
10948 If the {timestring} cannot be parsed with {format} zero is
10949 returned. If you do not know the format of {timestring} you
10950 can try different {format} values until you get a non-zero
10951 result.
10952
10953 See also |strftime()|.
10954 Examples: >
10955 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10956< 862156163 >
10957 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10958< Sun Apr 27 11:53:55 1997 >
10959 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10960< Sun Apr 27 12:53:55 1997
10961
10962 Can also be used as a |method|: >
10963 GetFormat()->strptime(timestring)
10964<
10965 Not available on all systems. To check use: >
10966 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010967<
10968 Return type: |Number|
10969
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010970
10971strridx({haystack}, {needle} [, {start}]) *strridx()*
10972 The result is a Number, which gives the byte index in
10973 {haystack} of the last occurrence of the String {needle}.
10974 When {start} is specified, matches beyond this index are
10975 ignored. This can be used to find a match before a previous
10976 match: >
10977 :let lastcomma = strridx(line, ",")
10978 :let comma2 = strridx(line, ",", lastcomma - 1)
10979< The search is done case-sensitive.
10980 For pattern searches use |match()|.
10981 -1 is returned if the {needle} does not occur in {haystack}.
10982 If the {needle} is empty the length of {haystack} is returned.
10983 See also |stridx()|. Examples: >
10984 :echo strridx("an angry armadillo", "an") 3
10985< *strrchr()*
10986 When used with a single character it works similar to the C
10987 function strrchr().
10988
10989 Can also be used as a |method|: >
10990 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010991<
10992 Return type: |Number|
10993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010994
10995strtrans({string}) *strtrans()*
10996 The result is a String, which is {string} with all unprintable
10997 characters translated into printable characters |'isprint'|.
10998 Like they are shown in a window. Example: >
10999 echo strtrans(@a)
11000< This displays a newline in register a as "^@" instead of
11001 starting a new line.
11002
Bram Moolenaard592deb2022-06-17 15:42:40 +010011003 Returns an empty string on error.
11004
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011005 Can also be used as a |method|: >
11006 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011007<
11008 Return type: |String|
11009
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011010
Christian Brabandt67672ef2023-04-24 21:09:54 +010011011strutf16len({string} [, {countcc}]) *strutf16len()*
11012 The result is a Number, which is the number of UTF-16 code
11013 units in String {string} (after converting it to UTF-16).
11014
11015 When {countcc} is TRUE, composing characters are counted
11016 separately.
11017 When {countcc} is omitted or FALSE, composing characters are
11018 ignored.
11019
11020 Returns zero on error.
11021
11022 Also see |strlen()| and |strcharlen()|.
11023 Examples: >
11024 echo strutf16len('a') returns 1
11025 echo strutf16len('©') returns 1
11026 echo strutf16len('😊') returns 2
11027 echo strutf16len('ą́') returns 1
11028 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011029<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011030 Can also be used as a |method|: >
11031 GetText()->strutf16len()
11032<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011033 Return type: |Number|
11034
11035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011036strwidth({string}) *strwidth()*
11037 The result is a Number, which is the number of display cells
11038 String {string} occupies. A Tab character is counted as one
11039 cell, alternatively use |strdisplaywidth()|.
11040 When {string} contains characters with East Asian Width Class
11041 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011042 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011043 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11044
11045 Can also be used as a |method|: >
11046 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011047<
11048 Return type: |Number|
11049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011050
11051submatch({nr} [, {list}]) *submatch()* *E935*
11052 Only for an expression in a |:substitute| command or
11053 substitute() function.
11054 Returns the {nr}'th submatch of the matched text. When {nr}
11055 is 0 the whole matched text is returned.
11056 Note that a NL in the string can stand for a line break of a
11057 multi-line match or a NUL character in the text.
11058 Also see |sub-replace-expression|.
11059
11060 If {list} is present and non-zero then submatch() returns
11061 a list of strings, similar to |getline()| with two arguments.
11062 NL characters in the text represent NUL characters in the
11063 text.
11064 Only returns more than one item for |:substitute|, inside
11065 |substitute()| this list will always contain one or zero
11066 items, since there are no real line breaks.
11067
11068 When substitute() is used recursively only the submatches in
11069 the current (deepest) call can be obtained.
11070
Bram Moolenaard592deb2022-06-17 15:42:40 +010011071 Returns an empty string or list on error.
11072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011073 Examples: >
11074 :s/\d\+/\=submatch(0) + 1/
11075 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11076< This finds the first number in the line and adds one to it.
11077 A line break is included as a newline character.
11078
11079 Can also be used as a |method|: >
11080 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011081<
11082 Return type: |String| or list<string> depending on {list}
11083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011084
11085substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11086 The result is a String, which is a copy of {string}, in which
11087 the first match of {pat} is replaced with {sub}.
11088 When {flags} is "g", all matches of {pat} in {string} are
11089 replaced. Otherwise {flags} should be "".
11090
11091 This works like the ":substitute" command (without any flags).
11092 But the matching with {pat} is always done like the 'magic'
11093 option is set and 'cpoptions' is empty (to make scripts
11094 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11095 if you want to ignore or match case and ignore 'ignorecase'.
11096 'smartcase' is not used. See |string-match| for how {pat} is
11097 used.
11098
11099 A "~" in {sub} is not replaced with the previous {sub}.
11100 Note that some codes in {sub} have a special meaning
11101 |sub-replace-special|. For example, to replace something with
11102 "\n" (two characters), use "\\\\n" or '\\n'.
11103
11104 When {pat} does not match in {string}, {string} is returned
11105 unmodified.
11106
11107 Example: >
11108 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11109< This removes the last component of the 'path' option. >
11110 :echo substitute("testing", ".*", "\\U\\0", "")
11111< results in "TESTING".
11112
11113 When {sub} starts with "\=", the remainder is interpreted as
11114 an expression. See |sub-replace-expression|. Example: >
11115 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011116 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011117
11118< When {sub} is a Funcref that function is called, with one
11119 optional argument. Example: >
11120 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11121< The optional argument is a list which contains the whole
11122 matched string and up to nine submatches, like what
11123 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011124 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011125
Bram Moolenaard592deb2022-06-17 15:42:40 +010011126< Returns an empty string on error.
11127
11128 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011129 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011130<
11131 Return type: |String|
11132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011133
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011134swapfilelist() *swapfilelist()*
11135 Returns a list of swap file names, like what "vim -r" shows.
11136 See the |-r| command argument. The 'directory' option is used
11137 for the directories to inspect. If you only want to get a
11138 list of swap files in the current directory then temporarily
11139 set 'directory' to a dot: >
11140 let save_dir = &directory
11141 let &directory = '.'
11142 let swapfiles = swapfilelist()
11143 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011144<
11145 Return type: list<string>
11146
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011147
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011148swapinfo({fname}) *swapinfo()*
11149 The result is a dictionary, which holds information about the
11150 swapfile {fname}. The available fields are:
11151 version Vim version
11152 user user name
11153 host host name
11154 fname original file name
11155 pid PID of the Vim process that created the swap
11156 file
11157 mtime last modification time in seconds
11158 inode Optional: INODE number of the file
11159 dirty 1 if file was modified, 0 if not
11160 Note that "user" and "host" are truncated to at most 39 bytes.
11161 In case of failure an "error" item is added with the reason:
11162 Cannot open file: file not found or in accessible
11163 Cannot read file: cannot read first block
11164 Not a swap file: does not contain correct block ID
11165 Magic number mismatch: Info in first block is invalid
11166
11167 Can also be used as a |method|: >
11168 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011169<
11170 Return type: dict<any> or dict<string>
11171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011172
11173swapname({buf}) *swapname()*
11174 The result is the swap file path of the buffer {expr}.
11175 For the use of {buf}, see |bufname()| above.
11176 If buffer {buf} is the current buffer, the result is equal to
11177 |:swapname| (unless there is no swap file).
11178 If buffer {buf} has no swap file, returns an empty string.
11179
11180 Can also be used as a |method|: >
11181 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011182<
11183 Return type: |String|
11184
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011185
11186synID({lnum}, {col}, {trans}) *synID()*
11187 The result is a Number, which is the syntax ID at the position
11188 {lnum} and {col} in the current window.
11189 The syntax ID can be used with |synIDattr()| and
11190 |synIDtrans()| to obtain syntax information about text.
11191
11192 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11193 line. 'synmaxcol' applies, in a longer line zero is returned.
11194 Note that when the position is after the last character,
11195 that's where the cursor can be in Insert mode, synID() returns
11196 zero. {lnum} is used like with |getline()|.
11197
11198 When {trans} is |TRUE|, transparent items are reduced to the
11199 item that they reveal. This is useful when wanting to know
11200 the effective color. When {trans} is |FALSE|, the transparent
11201 item is returned. This is useful when wanting to know which
11202 syntax item is effective (e.g. inside parens).
11203 Warning: This function can be very slow. Best speed is
11204 obtained by going through the file in forward direction.
11205
Bram Moolenaard592deb2022-06-17 15:42:40 +010011206 Returns zero on error.
11207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011208 Example (echoes the name of the syntax item under the cursor): >
11209 :echo synIDattr(synID(line("."), col("."), 1), "name")
11210<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011211 Return type: |Number|
11212
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011213
11214synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11215 The result is a String, which is the {what} attribute of
11216 syntax ID {synID}. This can be used to obtain information
11217 about a syntax item.
11218 {mode} can be "gui", "cterm" or "term", to get the attributes
11219 for that mode. When {mode} is omitted, or an invalid value is
11220 used, the attributes for the currently active highlighting are
11221 used (GUI, cterm or term).
11222 Use synIDtrans() to follow linked highlight groups.
11223 {what} result
11224 "name" the name of the syntax item
11225 "fg" foreground color (GUI: color name used to set
11226 the color, cterm: color number as a string,
11227 term: empty string)
11228 "bg" background color (as with "fg")
11229 "font" font name (only available in the GUI)
11230 |highlight-font|
11231 "sp" special color for the GUI (as with "fg")
11232 |highlight-guisp|
11233 "ul" underline color for cterm: number as a string
11234 "fg#" like "fg", but for the GUI and the GUI is
11235 running the name in "#RRGGBB" form
11236 "bg#" like "fg#" for "bg"
11237 "sp#" like "fg#" for "sp"
11238 "bold" "1" if bold
11239 "italic" "1" if italic
11240 "reverse" "1" if reverse
11241 "inverse" "1" if inverse (= reverse)
11242 "standout" "1" if standout
11243 "underline" "1" if underlined
11244 "undercurl" "1" if undercurled
11245 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011246 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011247
Bram Moolenaard592deb2022-06-17 15:42:40 +010011248 Returns an empty string on error.
11249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011250 Example (echoes the color of the syntax item under the
11251 cursor): >
11252 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11253<
11254 Can also be used as a |method|: >
11255 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011256<
11257 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011258
11259
11260synIDtrans({synID}) *synIDtrans()*
11261 The result is a Number, which is the translated syntax ID of
11262 {synID}. This is the syntax group ID of what is being used to
11263 highlight the character. Highlight links given with
11264 ":highlight link" are followed.
11265
Bram Moolenaard592deb2022-06-17 15:42:40 +010011266 Returns zero on error.
11267
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011268 Can also be used as a |method|: >
11269 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011270<
11271 Return type: |Number|
11272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011273
11274synconcealed({lnum}, {col}) *synconcealed()*
11275 The result is a |List| with currently three items:
11276 1. The first item in the list is 0 if the character at the
11277 position {lnum} and {col} is not part of a concealable
11278 region, 1 if it is. {lnum} is used like with |getline()|.
11279 2. The second item in the list is a string. If the first item
11280 is 1, the second item contains the text which will be
11281 displayed in place of the concealed text, depending on the
11282 current setting of 'conceallevel' and 'listchars'.
11283 3. The third and final item in the list is a number
11284 representing the specific syntax region matched in the
11285 line. When the character is not concealed the value is
11286 zero. This allows detection of the beginning of a new
11287 concealable region if there are two consecutive regions
11288 with the same replacement character. For an example, if
11289 the text is "123456" and both "23" and "45" are concealed
11290 and replaced by the character "X", then:
11291 call returns ~
11292 synconcealed(lnum, 1) [0, '', 0]
11293 synconcealed(lnum, 2) [1, 'X', 1]
11294 synconcealed(lnum, 3) [1, 'X', 1]
11295 synconcealed(lnum, 4) [1, 'X', 2]
11296 synconcealed(lnum, 5) [1, 'X', 2]
11297 synconcealed(lnum, 6) [0, '', 0]
11298
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011299 Note: Doesn't consider |matchadd()| highlighting items,
11300 since syntax and matching highlighting are two different
11301 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011302
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011303 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011304
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011305
11306synstack({lnum}, {col}) *synstack()*
11307 Return a |List|, which is the stack of syntax items at the
11308 position {lnum} and {col} in the current window. {lnum} is
11309 used like with |getline()|. Each item in the List is an ID
11310 like what |synID()| returns.
11311 The first item in the List is the outer region, following are
11312 items contained in that one. The last one is what |synID()|
11313 returns, unless not the whole item is highlighted or it is a
11314 transparent item.
11315 This function is useful for debugging a syntax file.
11316 Example that shows the syntax stack under the cursor: >
11317 for id in synstack(line("."), col("."))
11318 echo synIDattr(id, "name")
11319 endfor
11320< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011321 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011322 character in a line and the first column in an empty line are
11323 valid positions.
11324
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011325 Return type: list<number> or list<any>
11326
11327
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011328system({expr} [, {input}]) *system()* *E677*
11329 Get the output of the shell command {expr} as a |String|. See
11330 |systemlist()| to get the output as a |List|.
11331
11332 When {input} is given and is a |String| this string is written
11333 to a file and passed as stdin to the command. The string is
11334 written as-is, you need to take care of using the correct line
11335 separators yourself.
11336 If {input} is given and is a |List| it is written to the file
11337 in a way |writefile()| does with {binary} set to "b" (i.e.
11338 with a newline between each list item with newlines inside
11339 list items converted to NULs).
11340 When {input} is given and is a number that is a valid id for
11341 an existing buffer then the content of the buffer is written
11342 to the file line by line, each line terminated by a NL and
11343 NULs characters where the text has a NL.
11344
11345 Pipes are not used, the 'shelltemp' option is not used.
11346
11347 When prepended by |:silent| the terminal will not be set to
11348 cooked mode. This is meant to be used for commands that do
11349 not need the user to type. It avoids stray characters showing
11350 up on the screen which require |CTRL-L| to remove. >
11351 :silent let f = system('ls *.vim')
11352<
11353 Note: Use |shellescape()| or |::S| with |expand()| or
11354 |fnamemodify()| to escape special characters in a command
11355 argument. Newlines in {expr} may cause the command to fail.
11356 The characters in 'shellquote' and 'shellxquote' may also
11357 cause trouble.
11358 This is not to be used for interactive commands.
11359
11360 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011361 :let files = system('ls ' .. shellescape(expand('%:h')))
11362 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011363
11364< To make the result more system-independent, the shell output
11365 is filtered to replace <CR> with <NL> for Macintosh, and
11366 <CR><NL> with <NL> for DOS-like systems.
11367 To avoid the string being truncated at a NUL, all NUL
11368 characters are replaced with SOH (0x01).
11369
11370 The command executed is constructed using several options:
11371 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11372 ({tmp} is an automatically generated file name).
11373 For Unix, braces are put around {expr} to allow for
11374 concatenated commands.
11375
11376 The command will be executed in "cooked" mode, so that a
11377 CTRL-C will interrupt the command (on Unix at least).
11378
11379 The resulting error code can be found in |v:shell_error|.
11380 This function will fail in |restricted-mode|.
11381
11382 Note that any wrong value in the options mentioned above may
11383 make the function fail. It has also been reported to fail
11384 when using a security agent application.
11385 Unlike ":!cmd" there is no automatic check for changed files.
11386 Use |:checktime| to force a check.
11387
11388 Can also be used as a |method|: >
11389 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011390<
11391 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011392
11393
11394systemlist({expr} [, {input}]) *systemlist()*
11395 Same as |system()|, but returns a |List| with lines (parts of
11396 output separated by NL) with NULs transformed into NLs. Output
11397 is the same as |readfile()| will output with {binary} argument
11398 set to "b", except that there is no extra empty item when the
11399 result ends in a NL.
11400 Note that on MS-Windows you may get trailing CR characters.
11401
11402 To see the difference between "echo hello" and "echo -n hello"
11403 use |system()| and |split()|: >
11404 echo system('echo hello')->split('\n', 1)
11405<
11406 Returns an empty string on error.
11407
11408 Can also be used as a |method|: >
11409 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011410<
11411 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011412
11413
11414tabpagebuflist([{arg}]) *tabpagebuflist()*
11415 The result is a |List|, where each item is the number of the
11416 buffer associated with each window in the current tab page.
11417 {arg} specifies the number of the tab page to be used. When
11418 omitted the current tab page is used.
11419 When {arg} is invalid the number zero is returned.
11420 To get a list of all buffers in all tabs use this: >
11421 let buflist = []
11422 for i in range(tabpagenr('$'))
11423 call extend(buflist, tabpagebuflist(i + 1))
11424 endfor
11425< Note that a buffer may appear in more than one window.
11426
11427 Can also be used as a |method|: >
11428 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011429<
11430 Return type: list<number>
11431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011432
11433tabpagenr([{arg}]) *tabpagenr()*
11434 The result is a Number, which is the number of the current
11435 tab page. The first tab page has number 1.
11436
11437 The optional argument {arg} supports the following values:
11438 $ the number of the last tab page (the tab page
11439 count).
11440 # the number of the last accessed tab page
11441 (where |g<Tab>| goes to). if there is no
11442 previous tab page 0 is returned.
11443 The number can be used with the |:tab| command.
11444
Bram Moolenaard592deb2022-06-17 15:42:40 +010011445 Returns zero on error.
11446
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011447 Return type: |Number|
11448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011449
11450tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11451 Like |winnr()| but for tab page {tabarg}.
11452 {tabarg} specifies the number of tab page to be used.
11453 {arg} is used like with |winnr()|:
11454 - When omitted the current window number is returned. This is
11455 the window which will be used when going to this tab page.
11456 - When "$" the number of windows is returned.
11457 - When "#" the previous window nr is returned.
11458 Useful examples: >
11459 tabpagewinnr(1) " current window of tab page 1
11460 tabpagewinnr(4, '$') " number of windows in tab page 4
11461< When {tabarg} is invalid zero is returned.
11462
11463 Can also be used as a |method|: >
11464 GetTabpage()->tabpagewinnr()
11465<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011466 Return type: |Number|
11467
11468
11469tagfiles() *tagfiles()*
11470 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011471 for the current buffer. This is the 'tags' option expanded.
11472
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011473 Return type: list<string> or list<any>
11474
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011475
11476taglist({expr} [, {filename}]) *taglist()*
11477 Returns a |List| of tags matching the regular expression {expr}.
11478
11479 If {filename} is passed it is used to prioritize the results
11480 in the same way that |:tselect| does. See |tag-priority|.
11481 {filename} should be the full path of the file.
11482
11483 Each list item is a dictionary with at least the following
11484 entries:
11485 name Name of the tag.
11486 filename Name of the file where the tag is
11487 defined. It is either relative to the
11488 current directory or a full path.
11489 cmd Ex command used to locate the tag in
11490 the file.
11491 kind Type of the tag. The value for this
11492 entry depends on the language specific
11493 kind values. Only available when
11494 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011495 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011496 static A file specific tag. Refer to
11497 |static-tag| for more information.
11498 More entries may be present, depending on the content of the
11499 tags file: access, implementation, inherits and signature.
11500 Refer to the ctags documentation for information about these
11501 fields. For C code the fields "struct", "class" and "enum"
11502 may appear, they give the name of the entity the tag is
11503 contained in.
11504
11505 The ex-command "cmd" can be either an ex search pattern, a
11506 line number or a line number followed by a byte number.
11507
11508 If there are no matching tags, then an empty list is returned.
11509
11510 To get an exact tag match, the anchors '^' and '$' should be
11511 used in {expr}. This also make the function work faster.
11512 Refer to |tag-regexp| for more information about the tag
11513 search regular expression pattern.
11514
11515 Refer to |'tags'| for information about how the tags file is
11516 located by Vim. Refer to |tags-file-format| for the format of
11517 the tags file generated by the different ctags tools.
11518
11519 Can also be used as a |method|: >
11520 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011521<
11522 Return type: list<dict<any>> or list<any>
11523
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011524
11525tan({expr}) *tan()*
11526 Return the tangent of {expr}, measured in radians, as a |Float|
11527 in the range [-inf, inf].
11528 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011529 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011530 Examples: >
11531 :echo tan(10)
11532< 0.648361 >
11533 :echo tan(-4.01)
11534< -1.181502
11535
11536 Can also be used as a |method|: >
11537 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011538<
11539 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011540
11541
11542tanh({expr}) *tanh()*
11543 Return the hyperbolic tangent of {expr} as a |Float| in the
11544 range [-1, 1].
11545 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011546 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011547 Examples: >
11548 :echo tanh(0.5)
11549< 0.462117 >
11550 :echo tanh(-1)
11551< -0.761594
11552
11553 Can also be used as a |method|: >
11554 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011555<
11556 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011557
11558
11559tempname() *tempname()* *temp-file-name*
11560 The result is a String, which is the name of a file that
11561 doesn't exist. It can be used for a temporary file. The name
11562 is different for at least 26 consecutive calls. Example: >
11563 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011564 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011565< For Unix, the file will be in a private directory |tempfile|
11566 that is recursively deleted when Vim exits, on other systems
11567 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011568 For MS-Windows forward slashes are used when the 'shellslash'
11569 option is set, or when 'shellcmdflag' starts with '-' and
11570 'shell' does not contain powershell or pwsh.
11571
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011572 Return type: |String|
11573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011574
11575term_ functions are documented here: |terminal-function-details|
11576
11577
11578terminalprops() *terminalprops()*
11579 Returns a |Dictionary| with properties of the terminal that Vim
11580 detected from the response to |t_RV| request. See
11581 |v:termresponse| for the response itself. If |v:termresponse|
11582 is empty most values here will be 'u' for unknown.
11583 cursor_style whether sending |t_RS| works **
11584 cursor_blink_mode whether sending |t_RC| works **
11585 underline_rgb whether |t_8u| works **
11586 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011587 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011588
11589 ** value 'u' for unknown, 'y' for yes, 'n' for no
11590
11591 If the |+termresponse| feature is missing then the result is
11592 an empty dictionary.
11593
11594 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11595 current cursor style.
11596 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11597 request the cursor blink status.
11598 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11599 is not empty, Vim will detect the working of sending |t_RS|
11600 and |t_RC| on startup.
11601
11602 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11603 This avoids sending it to xterm, which would clear the colors.
11604
11605 For "mouse" the value 'u' is unknown
11606
11607 Also see:
11608 - 'ambiwidth' - detected by using |t_u7|.
11609 - |v:termstyleresp| and |v:termblinkresp| for the response to
11610 |t_RS| and |t_RC|.
11611
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011612 Return type: dict<string>
11613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011614
11615test_ functions are documented here: |test-functions-details|
11616
11617
11618 *timer_info()*
11619timer_info([{id}])
11620 Return a list with information about timers.
11621 When {id} is given only information about this timer is
11622 returned. When timer {id} does not exist an empty list is
11623 returned.
11624 When {id} is omitted information about all timers is returned.
11625
11626 For each timer the information is stored in a |Dictionary| with
11627 these items:
11628 "id" the timer ID
11629 "time" time the timer was started with
11630 "remaining" time until the timer fires
11631 "repeat" number of times the timer will still fire;
11632 -1 means forever
11633 "callback" the callback
11634 "paused" 1 if the timer is paused, 0 otherwise
11635
11636 Can also be used as a |method|: >
11637 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011638<
11639 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011640
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011641 {only available when compiled with the |+timers| feature}
11642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011643
11644timer_pause({timer}, {paused}) *timer_pause()*
11645 Pause or unpause a timer. A paused timer does not invoke its
11646 callback when its time expires. Unpausing a timer may cause
11647 the callback to be invoked almost immediately if enough time
11648 has passed.
11649
11650 Pausing a timer is useful to avoid the callback to be called
11651 for a short time.
11652
11653 If {paused} evaluates to a non-zero Number or a non-empty
11654 String, then the timer is paused, otherwise it is unpaused.
11655 See |non-zero-arg|.
11656
11657 Can also be used as a |method|: >
11658 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011659<
11660 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011661
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011662 {only available when compiled with the |+timers| feature}
11663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011664
11665 *timer_start()* *timer* *timers*
11666timer_start({time}, {callback} [, {options}])
11667 Create a timer and return the timer ID.
11668
11669 {time} is the waiting time in milliseconds. This is the
11670 minimum time before invoking the callback. When the system is
11671 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011672 Zero can be used to execute the callback when Vim is back in
11673 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011674
11675 {callback} is the function to call. It can be the name of a
11676 function or a |Funcref|. It is called with one argument, which
11677 is the timer ID. The callback is only invoked when Vim is
11678 waiting for input.
11679 If you want to show a message look at |popup_notification()|
11680 to avoid interfering with what the user is doing.
11681
11682 {options} is a dictionary. Supported entries:
11683 "repeat" Number of times to repeat calling the
11684 callback. -1 means forever. When not present
11685 the callback will be called once.
11686 If the timer causes an error three times in a
11687 row the repeat is cancelled. This avoids that
11688 Vim becomes unusable because of all the error
11689 messages.
11690
Bram Moolenaard592deb2022-06-17 15:42:40 +010011691 Returns -1 on error.
11692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011693 Example: >
11694 func MyHandler(timer)
11695 echo 'Handler called'
11696 endfunc
11697 let timer = timer_start(500, 'MyHandler',
11698 \ {'repeat': 3})
11699< This will invoke MyHandler() three times at 500 msec
11700 intervals.
11701
11702 Can also be used as a |method|: >
11703 GetMsec()->timer_start(callback)
11704
11705< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011706
11707 Return type: |Number|
11708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011709 {only available when compiled with the |+timers| feature}
11710
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011712timer_stop({timer}) *timer_stop()*
11713 Stop a timer. The timer callback will no longer be invoked.
11714 {timer} is an ID returned by timer_start(), thus it must be a
11715 Number. If {timer} does not exist there is no error.
11716
11717 Can also be used as a |method|: >
11718 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011719<
11720 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011721
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011722 {only available when compiled with the |+timers| feature}
11723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011724
11725timer_stopall() *timer_stopall()*
11726 Stop all timers. The timer callbacks will no longer be
11727 invoked. Useful if a timer is misbehaving. If there are no
11728 timers there is no error.
11729
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011730 Return type: |Number|
11731
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011732 {only available when compiled with the |+timers| feature}
11733
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011735tolower({expr}) *tolower()*
11736 The result is a copy of the String given, with all uppercase
11737 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011738 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011739
11740 Can also be used as a |method|: >
11741 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011742<
11743 Return type: |String|
11744
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011745
11746toupper({expr}) *toupper()*
11747 The result is a copy of the String given, with all lowercase
11748 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011749 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011750
11751 Can also be used as a |method|: >
11752 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011753<
11754 Return type: |String|
11755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011756
11757tr({src}, {fromstr}, {tostr}) *tr()*
11758 The result is a copy of the {src} string with all characters
11759 which appear in {fromstr} replaced by the character in that
11760 position in the {tostr} string. Thus the first character in
11761 {fromstr} is translated into the first character in {tostr}
11762 and so on. Exactly like the unix "tr" command.
11763 This code also deals with multibyte characters properly.
11764
Bram Moolenaard592deb2022-06-17 15:42:40 +010011765 Returns an empty string on error.
11766
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011767 Examples: >
11768 echo tr("hello there", "ht", "HT")
11769< returns "Hello THere" >
11770 echo tr("<blob>", "<>", "{}")
11771< returns "{blob}"
11772
11773 Can also be used as a |method|: >
11774 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011775<
11776 Return type: |String|
11777
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011778
11779trim({text} [, {mask} [, {dir}]]) *trim()*
11780 Return {text} as a String where any character in {mask} is
11781 removed from the beginning and/or end of {text}.
11782
Illia Bobyr80799172023-10-17 18:00:50 +020011783 If {mask} is not given, or is an empty string, {mask} is all
11784 characters up to 0x20, which includes Tab, space, NL and CR,
11785 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011786
11787 The optional {dir} argument specifies where to remove the
11788 characters:
11789 0 remove from the beginning and end of {text}
11790 1 remove only at the beginning of {text}
11791 2 remove only at the end of {text}
11792 When omitted both ends are trimmed.
11793
11794 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011795 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011796
11797 Examples: >
11798 echo trim(" some text ")
11799< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011800 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011801< returns "RESERVE_TAIL" >
11802 echo trim("rm<Xrm<>X>rrm", "rm<>")
11803< returns "Xrm<>X" (characters in the middle are not removed) >
11804 echo trim(" vim ", " ", 2)
11805< returns " vim"
11806
11807 Can also be used as a |method|: >
11808 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011809<
11810 Return type: |String|
11811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011812
11813trunc({expr}) *trunc()*
11814 Return the largest integral value with magnitude less than or
11815 equal to {expr} as a |Float| (truncate towards zero).
11816 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011817 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011818 Examples: >
11819 echo trunc(1.456)
11820< 1.0 >
11821 echo trunc(-5.456)
11822< -5.0 >
11823 echo trunc(4.0)
11824< 4.0
11825
11826 Can also be used as a |method|: >
11827 Compute()->trunc()
11828<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011829 Return type: |Float|
11830
11831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011832 *type()*
11833type({expr}) The result is a Number representing the type of {expr}.
11834 Instead of using the number directly, it is better to use the
11835 v:t_ variable that has the value:
11836 Number: 0 |v:t_number|
11837 String: 1 |v:t_string|
11838 Funcref: 2 |v:t_func|
11839 List: 3 |v:t_list|
11840 Dictionary: 4 |v:t_dict|
11841 Float: 5 |v:t_float|
11842 Boolean: 6 |v:t_bool| (v:false and v:true)
11843 None: 7 |v:t_none| (v:null and v:none)
11844 Job: 8 |v:t_job|
11845 Channel: 9 |v:t_channel|
11846 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011847 Class: 12 |v:t_class|
11848 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011849 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011850 Enum: 15 |v:t_enum|
11851 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011852 For backward compatibility, this method can be used: >
11853 :if type(myvar) == type(0)
11854 :if type(myvar) == type("")
11855 :if type(myvar) == type(function("tr"))
11856 :if type(myvar) == type([])
11857 :if type(myvar) == type({})
11858 :if type(myvar) == type(0.0)
11859 :if type(myvar) == type(v:false)
11860 :if type(myvar) == type(v:none)
11861< To check if the v:t_ variables exist use this: >
11862 :if exists('v:t_number')
11863
11864< Can also be used as a |method|: >
11865 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011866<
11867 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011868
11869
11870typename({expr}) *typename()*
11871 Return a string representation of the type of {expr}.
11872 Example: >
11873 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011874< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011875
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011876 Return type: |String|
11877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011878
11879undofile({name}) *undofile()*
11880 Return the name of the undo file that would be used for a file
11881 with name {name} when writing. This uses the 'undodir'
11882 option, finding directories that exist. It does not check if
11883 the undo file exists.
11884 {name} is always expanded to the full path, since that is what
11885 is used internally.
11886 If {name} is empty undofile() returns an empty string, since a
11887 buffer without a file name will not write an undo file.
11888 Useful in combination with |:wundo| and |:rundo|.
11889 When compiled without the |+persistent_undo| option this always
11890 returns an empty string.
11891
11892 Can also be used as a |method|: >
11893 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011894<
11895 Return type: |String|
11896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011897
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011898undotree([{buf}]) *undotree()*
11899 Return the current state of the undo tree for the current
11900 buffer, or for a specific buffer if {buf} is given. The
11901 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011902 "seq_last" The highest undo sequence number used.
11903 "seq_cur" The sequence number of the current position in
11904 the undo tree. This differs from "seq_last"
11905 when some changes were undone.
11906 "time_cur" Time last used for |:earlier| and related
11907 commands. Use |strftime()| to convert to
11908 something readable.
11909 "save_last" Number of the last file write. Zero when no
11910 write yet.
11911 "save_cur" Number of the current position in the undo
11912 tree.
11913 "synced" Non-zero when the last undo block was synced.
11914 This happens when waiting from input from the
11915 user. See |undo-blocks|.
11916 "entries" A list of dictionaries with information about
11917 undo blocks.
11918
11919 The first item in the "entries" list is the oldest undo item.
11920 Each List item is a |Dictionary| with these items:
11921 "seq" Undo sequence number. Same as what appears in
11922 |:undolist|.
11923 "time" Timestamp when the change happened. Use
11924 |strftime()| to convert to something readable.
11925 "newhead" Only appears in the item that is the last one
11926 that was added. This marks the last change
11927 and where further changes will be added.
11928 "curhead" Only appears in the item that is the last one
11929 that was undone. This marks the current
11930 position in the undo tree, the block that will
11931 be used by a redo command. When nothing was
11932 undone after the last change this item will
11933 not appear anywhere.
11934 "save" Only appears on the last block before a file
11935 write. The number is the write count. The
11936 first write has number 1, the last one the
11937 "save_last" mentioned above.
11938 "alt" Alternate entry. This is again a List of undo
11939 blocks. Each item may again have an "alt"
11940 item.
11941
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011942 Return type: dict<any>
11943
11944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011945uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11946 Remove second and succeeding copies of repeated adjacent
11947 {list} items in-place. Returns {list}. If you want a list
11948 to remain unmodified make a copy first: >
11949 :let newlist = uniq(copy(mylist))
11950< The default compare function uses the string representation of
11951 each item. For the use of {func} and {dict} see |sort()|.
11952
Bram Moolenaard592deb2022-06-17 15:42:40 +010011953 Returns zero if {list} is not a |List|.
11954
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011955 Can also be used as a |method|: >
11956 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011957<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011958 Return type: list<{type}>
11959
11960
Christian Brabandt67672ef2023-04-24 21:09:54 +010011961 *utf16idx()*
11962utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011963 Same as |charidx()| but returns the UTF-16 code unit index of
11964 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011965
11966 When {charidx} is present and TRUE, {idx} is used as the
11967 character index in the String {string} instead of as the byte
11968 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011969 An {idx} in the middle of a UTF-8 sequence is rounded
11970 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011971
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011972 Returns -1 if the arguments are invalid or if there are less
11973 than {idx} bytes in {string}. If there are exactly {idx} bytes
11974 the length of the string in UTF-16 code units is returned.
11975
Christian Brabandt67672ef2023-04-24 21:09:54 +010011976 See |byteidx()| and |byteidxcomp()| for getting the byte index
11977 from the UTF-16 index and |charidx()| for getting the
11978 character index from the UTF-16 index.
11979 Refer to |string-offset-encoding| for more information.
11980 Examples: >
11981 echo utf16idx('a😊😊', 3) returns 2
11982 echo utf16idx('a😊😊', 7) returns 4
11983 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11984 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11985 echo utf16idx('aą́c', 6) returns 2
11986 echo utf16idx('aą́c', 6, 1) returns 4
11987 echo utf16idx('a😊😊', 9) returns -1
11988<
11989 Can also be used as a |method|: >
11990 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011991<
11992 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011993
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011994
11995values({dict}) *values()*
11996 Return a |List| with all the values of {dict}. The |List| is
11997 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011998 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011999
12000 Can also be used as a |method|: >
12001 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012002<
12003 Return type: list<any>
12004
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012005
zeertzjq825cf812023-08-17 22:55:25 +020012006virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012007 The result is a Number, which is the screen column of the file
12008 position given with {expr}. That is, the last screen position
12009 occupied by the character at that position, when the screen
12010 would be of unlimited width. When there is a <Tab> at the
12011 position, the returned Number will be the column at the end of
12012 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12013 set to 8, it returns 8. |conceal| is ignored.
12014 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012015
zeertzjq02f3eba2024-06-12 20:45:24 +020012016 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012017 When {expr} is "$", it means the end of the cursor line, so
12018 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012019
12020 When 'virtualedit' is used {expr} can be [lnum, col, off],
12021 where "off" is the offset in screen columns from the start of
12022 the character. E.g., a position within a <Tab> or after the
12023 last character. When "off" is omitted zero is used. When
12024 Virtual editing is active in the current mode, a position
12025 beyond the end of the line can be returned. Also see
12026 |'virtualedit'|
12027
zeertzjq825cf812023-08-17 22:55:25 +020012028 If {list} is present and non-zero then virtcol() returns a
12029 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012030 character.
12031
zeertzjq825cf812023-08-17 22:55:25 +020012032 With the optional {winid} argument the values are obtained for
12033 that window instead of the current window.
12034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012035 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012036
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012037 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012038 " With text "foo^Lbar" and cursor on the "^L":
12039
12040 virtcol(".") " returns 5
12041 virtcol(".", 1) " returns [4, 5]
12042 virtcol("$") " returns 9
12043
12044 " With text " there", with 't at 'h':
12045
12046 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012047<
12048 The first column is 1. 0 or [0, 0] is returned for an error.
12049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012050 A more advanced example that echoes the maximum length of
12051 all lines: >
12052 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12053
12054< Can also be used as a |method|: >
12055 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012056<
12057 Return type: |Number|
12058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012059
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012060virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12061 The result is a Number, which is the byte index of the
12062 character in window {winid} at buffer line {lnum} and virtual
12063 column {col}.
12064
zeertzjqb583eda2023-10-14 11:32:28 +020012065 If buffer line {lnum} is an empty line, 0 is returned.
12066
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012067 If {col} is greater than the last virtual column in line
12068 {lnum}, then the byte index of the character at the last
12069 virtual column is returned.
12070
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012071 For a multi-byte character, the column number of the first
12072 byte in the character is returned.
12073
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012074 The {winid} argument can be the window number or the
12075 |window-ID|. If this is zero, then the current window is used.
12076
12077 Returns -1 if the window {winid} doesn't exist or the buffer
12078 line {lnum} or virtual column {col} is invalid.
12079
12080 See also |screenpos()|, |virtcol()| and |col()|.
12081
12082 Can also be used as a |method|: >
12083 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012084<
12085 Return type: |Number|
12086
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012087
12088visualmode([{expr}]) *visualmode()*
12089 The result is a String, which describes the last Visual mode
12090 used in the current buffer. Initially it returns an empty
12091 string, but once Visual mode has been used, it returns "v",
12092 "V", or "<CTRL-V>" (a single CTRL-V character) for
12093 character-wise, line-wise, or block-wise Visual mode
12094 respectively.
12095 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012096 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012097< This enters the same Visual mode as before. It is also useful
12098 in scripts if you wish to act differently depending on the
12099 Visual mode that was used.
12100 If Visual mode is active, use |mode()| to get the Visual mode
12101 (e.g., in a |:vmap|).
12102 If {expr} is supplied and it evaluates to a non-zero Number or
12103 a non-empty String, then the Visual mode will be cleared and
12104 the old value is returned. See |non-zero-arg|.
12105
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012106 Return type: |String|
12107
12108
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012109wildmenumode() *wildmenumode()*
12110 Returns |TRUE| when the wildmenu is active and |FALSE|
12111 otherwise. See 'wildmenu' and 'wildmode'.
12112 This can be used in mappings to handle the 'wildcharm' option
12113 gracefully. (Makes only sense with |mapmode-c| mappings).
12114
12115 For example to make <c-j> work like <down> in wildmode, use: >
12116 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12117<
Milly6c2fc372024-10-16 22:11:17 +020012118 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012119
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012120 Return type: |Number|
12121
12122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012123win_execute({id}, {command} [, {silent}]) *win_execute()*
12124 Like `execute()` but in the context of window {id}.
12125 The window will temporarily be made the current window,
12126 without triggering autocommands or changing directory. When
12127 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012128 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012129 Example: >
12130 call win_execute(winid, 'set syntax=python')
12131< Doing the same with `setwinvar()` would not trigger
12132 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012133 *E994*
12134 Not all commands are allowed in popup windows.
12135 When window {id} does not exist then no error is given and
12136 an empty string is returned.
12137
12138 Can also be used as a |method|, the base is passed as the
12139 second argument: >
12140 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012141<
12142 Return type: |String|
12143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012144
12145win_findbuf({bufnr}) *win_findbuf()*
12146 Returns a |List| with |window-ID|s for windows that contain
12147 buffer {bufnr}. When there is none the list is empty.
12148
12149 Can also be used as a |method|: >
12150 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012151<
12152 Return type: list<number> or list<any>
12153
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012154
12155win_getid([{win} [, {tab}]]) *win_getid()*
12156 Get the |window-ID| for the specified window.
12157 When {win} is missing use the current window.
12158 With {win} this is the window number. The top window has
12159 number 1.
12160 Without {tab} use the current tab, otherwise the tab with
12161 number {tab}. The first tab has number one.
12162 Return zero if the window cannot be found.
12163
12164 Can also be used as a |method|: >
12165 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012166<
12167 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012168
12169
12170win_gettype([{nr}]) *win_gettype()*
12171 Return the type of the window:
12172 "autocmd" autocommand window. Temporary window
12173 used to execute autocommands.
12174 "command" command-line window |cmdwin|
12175 (empty) normal window
12176 "loclist" |location-list-window|
12177 "popup" popup window |popup|
12178 "preview" preview window |preview-window|
12179 "quickfix" |quickfix-window|
12180 "unknown" window {nr} not found
12181
12182 When {nr} is omitted return the type of the current window.
12183 When {nr} is given return the type of this window by number or
12184 |window-ID|.
12185
12186 Also see the 'buftype' option. When running a terminal in a
12187 popup window then 'buftype' is "terminal" and win_gettype()
12188 returns "popup".
12189
12190 Can also be used as a |method|: >
12191 GetWinid()->win_gettype()
12192<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012193 Return type: |String|
12194
12195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012196win_gotoid({expr}) *win_gotoid()*
12197 Go to window with ID {expr}. This may also change the current
12198 tabpage.
12199 Return TRUE if successful, FALSE if the window cannot be found.
12200
12201 Can also be used as a |method|: >
12202 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012203<
12204 Return type: |Number|
12205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012206
12207win_id2tabwin({expr}) *win_id2tabwin()*
12208 Return a list with the tab number and window number of window
12209 with ID {expr}: [tabnr, winnr].
12210 Return [0, 0] if the window cannot be found.
12211
12212 Can also be used as a |method|: >
12213 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012214<
12215 Return type: list<number>
12216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012217
12218win_id2win({expr}) *win_id2win()*
12219 Return the window number of window with ID {expr}.
12220 Return 0 if the window cannot be found in the current tabpage.
12221
12222 Can also be used as a |method|: >
12223 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012224<
12225 Return type: |Number|
12226
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012227
Daniel Steinbergee630312022-01-10 13:36:34 +000012228win_move_separator({nr}, {offset}) *win_move_separator()*
12229 Move window {nr}'s vertical separator (i.e., the right border)
12230 by {offset} columns, as if being dragged by the mouse. {nr}
12231 can be a window number or |window-ID|. A positive {offset}
12232 moves right and a negative {offset} moves left. Moving a
12233 window's vertical separator will change the width of the
12234 window and the width of other windows adjacent to the vertical
12235 separator. The magnitude of movement may be smaller than
12236 specified (e.g., as a consequence of maintaining
12237 'winminwidth'). Returns TRUE if the window can be found and
12238 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012239 This will fail for the rightmost window and a full-width
12240 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012241 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012242
12243 Can also be used as a |method|: >
12244 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012245<
12246 Return type: |Number|
12247
Daniel Steinbergee630312022-01-10 13:36:34 +000012248
12249win_move_statusline({nr}, {offset}) *win_move_statusline()*
12250 Move window {nr}'s status line (i.e., the bottom border) by
12251 {offset} rows, as if being dragged by the mouse. {nr} can be a
12252 window number or |window-ID|. A positive {offset} moves down
12253 and a negative {offset} moves up. Moving a window's status
12254 line will change the height of the window and the height of
12255 other windows adjacent to the status line. The magnitude of
12256 movement may be smaller than specified (e.g., as a consequence
12257 of maintaining 'winminheight'). Returns TRUE if the window can
12258 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012259 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012260
12261 Can also be used as a |method|: >
12262 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012263<
12264 Return type: |Number|
12265
Daniel Steinbergee630312022-01-10 13:36:34 +000012266
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012267win_screenpos({nr}) *win_screenpos()*
12268 Return the screen position of window {nr} as a list with two
12269 numbers: [row, col]. The first window always has position
12270 [1, 1], unless there is a tabline, then it is [2, 1].
12271 {nr} can be the window number or the |window-ID|. Use zero
12272 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012273 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012274
12275 Can also be used as a |method|: >
12276 GetWinid()->win_screenpos()
12277<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012278 Return type: list<number>
12279
12280
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012281win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012282 Temporarily switch to window {target}, then move window {nr}
12283 to a new split adjacent to {target}.
12284 Unlike commands such as |:split|, no new windows are created
12285 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012286
12287 Both {nr} and {target} can be window numbers or |window-ID|s.
12288 Both must be in the current tab page.
12289
12290 Returns zero for success, non-zero for failure.
12291
12292 {options} is a |Dictionary| with the following optional entries:
12293 "vertical" When TRUE, the split is created vertically,
12294 like with |:vsplit|.
12295 "rightbelow" When TRUE, the split is made below or to the
12296 right (if vertical). When FALSE, it is done
12297 above or to the left (if vertical). When not
12298 present, the values of 'splitbelow' and
12299 'splitright' are used.
12300
12301 Can also be used as a |method|: >
12302 GetWinid()->win_splitmove(target)
12303<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012304 Return type: |Number|
12305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012306
12307 *winbufnr()*
12308winbufnr({nr}) The result is a Number, which is the number of the buffer
12309 associated with window {nr}. {nr} can be the window number or
12310 the |window-ID|.
12311 When {nr} is zero, the number of the buffer in the current
12312 window is returned.
12313 When window {nr} doesn't exist, -1 is returned.
12314 Example: >
12315 :echo "The file in the current window is " . bufname(winbufnr(0))
12316<
12317 Can also be used as a |method|: >
12318 FindWindow()->winbufnr()->bufname()
12319<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012320 Return type: |Number|
12321
12322
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012323 *wincol()*
12324wincol() The result is a Number, which is the virtual column of the
12325 cursor in the window. This is counting screen cells from the
12326 left side of the window. The leftmost column is one.
12327
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012328 Return type: |Number|
12329
12330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012331 *windowsversion()*
12332windowsversion()
12333 The result is a String. For MS-Windows it indicates the OS
12334 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12335 Windows XP is "5.1". For non-MS-Windows systems the result is
12336 an empty string.
12337
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012338 Return type: |String|
12339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012340winheight({nr}) *winheight()*
12341 The result is a Number, which is the height of window {nr}.
12342 {nr} can be the window number or the |window-ID|.
12343 When {nr} is zero, the height of the current window is
12344 returned. When window {nr} doesn't exist, -1 is returned.
12345 An existing window always has a height of zero or more.
12346 This excludes any window toolbar line.
12347 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012348 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012349
12350< Can also be used as a |method|: >
12351 GetWinid()->winheight()
12352<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012353 Return type: |Number|
12354
12355
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012356winlayout([{tabnr}]) *winlayout()*
12357 The result is a nested List containing the layout of windows
12358 in a tabpage.
12359
12360 Without {tabnr} use the current tabpage, otherwise the tabpage
12361 with number {tabnr}. If the tabpage {tabnr} is not found,
12362 returns an empty list.
12363
12364 For a leaf window, it returns:
12365 ['leaf', {winid}]
12366 For horizontally split windows, which form a column, it
12367 returns:
12368 ['col', [{nested list of windows}]]
12369 For vertically split windows, which form a row, it returns:
12370 ['row', [{nested list of windows}]]
12371
12372 Example: >
12373 " Only one window in the tab page
12374 :echo winlayout()
12375 ['leaf', 1000]
12376 " Two horizontally split windows
12377 :echo winlayout()
12378 ['col', [['leaf', 1000], ['leaf', 1001]]]
12379 " The second tab page, with three horizontally split
12380 " windows, with two vertically split windows in the
12381 " middle window
12382 :echo winlayout(2)
12383 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12384 ['leaf', 1001]]], ['leaf', 1000]]]
12385<
12386 Can also be used as a |method|: >
12387 GetTabnr()->winlayout()
12388<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012389 Return type: list<any>
12390
12391
12392winline() *winline()*
12393 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012394 in the window. This is counting screen lines from the top of
12395 the window. The first line is one.
12396 If the cursor was moved the view on the file will be updated
12397 first, this may cause a scroll.
12398
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012399 Return type: |Number|
12400
12401
12402winnr([{arg}]) *winnr()*
12403 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012404 window. The top window has number 1.
12405 Returns zero for a popup window.
12406
12407 The optional argument {arg} supports the following values:
12408 $ the number of the last window (the window
12409 count).
12410 # the number of the last accessed window (where
12411 |CTRL-W_p| goes to). If there is no previous
12412 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012413 returned. May refer to the current window in
12414 some cases (e.g. when evaluating 'statusline'
12415 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012416 {N}j the number of the Nth window below the
12417 current window (where |CTRL-W_j| goes to).
12418 {N}k the number of the Nth window above the current
12419 window (where |CTRL-W_k| goes to).
12420 {N}h the number of the Nth window left of the
12421 current window (where |CTRL-W_h| goes to).
12422 {N}l the number of the Nth window right of the
12423 current window (where |CTRL-W_l| goes to).
12424 The number can be used with |CTRL-W_w| and ":wincmd w"
12425 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012426 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012427 Also see |tabpagewinnr()| and |win_getid()|.
12428 Examples: >
12429 let window_count = winnr('$')
12430 let prev_window = winnr('#')
12431 let wnum = winnr('3k')
12432
12433< Can also be used as a |method|: >
12434 GetWinval()->winnr()
12435<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012436 Return type: |Number|
12437
12438
12439winrestcmd() *winrestcmd()*
12440 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012441 the current window sizes. Only works properly when no windows
12442 are opened or closed and the current window and tab page is
12443 unchanged.
12444 Example: >
12445 :let cmd = winrestcmd()
12446 :call MessWithWindowSizes()
12447 :exe cmd
12448<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012449 Return type: |String|
12450
12451
12452winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012453 Uses the |Dictionary| returned by |winsaveview()| to restore
12454 the view of the current window.
12455 Note: The {dict} does not have to contain all values, that are
12456 returned by |winsaveview()|. If values are missing, those
12457 settings won't be restored. So you can use: >
12458 :call winrestview({'curswant': 4})
12459<
12460 This will only set the curswant value (the column the cursor
12461 wants to move on vertical movements) of the cursor to column 5
12462 (yes, that is 5), while all other settings will remain the
12463 same. This is useful, if you set the cursor position manually.
12464
12465 If you have changed the values the result is unpredictable.
12466 If the window size changed the result won't be the same.
12467
12468 Can also be used as a |method|: >
12469 GetView()->winrestview()
12470<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012471 Return type: |Number|
12472
12473
12474winsaveview() *winsaveview()*
12475 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012476 the view of the current window. Use |winrestview()| to
12477 restore the view.
12478 This is useful if you have a mapping that jumps around in the
12479 buffer and you want to go back to the original view.
12480 This does not save fold information. Use the 'foldenable'
12481 option to temporarily switch off folding, so that folds are
12482 not opened when moving around. This may have side effects.
12483 The return value includes:
12484 lnum cursor line number
12485 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012486 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012487 returns)
12488 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012489 curswant column for vertical movement (Note:
12490 the first column is zero, as opposed
12491 to what |getcurpos()| returns). After
12492 |$| command it will be a very large
12493 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012494 topline first line in the window
12495 topfill filler lines, only in diff mode
12496 leftcol first column displayed; only used when
12497 'wrap' is off
12498 skipcol columns skipped
12499 Note that no option values are saved.
12500
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012501 Return type: dict<number>
12502
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012503
12504winwidth({nr}) *winwidth()*
12505 The result is a Number, which is the width of window {nr}.
12506 {nr} can be the window number or the |window-ID|.
12507 When {nr} is zero, the width of the current window is
12508 returned. When window {nr} doesn't exist, -1 is returned.
12509 An existing window always has a width of zero or more.
12510 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012511 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012512 :if winwidth(0) <= 50
12513 : 50 wincmd |
12514 :endif
12515< For getting the terminal or screen size, see the 'columns'
12516 option.
12517
12518 Can also be used as a |method|: >
12519 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012520<
12521 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012522
12523
12524wordcount() *wordcount()*
12525 The result is a dictionary of byte/chars/word statistics for
12526 the current buffer. This is the same info as provided by
12527 |g_CTRL-G|
12528 The return value includes:
12529 bytes Number of bytes in the buffer
12530 chars Number of chars in the buffer
12531 words Number of words in the buffer
12532 cursor_bytes Number of bytes before cursor position
12533 (not in Visual mode)
12534 cursor_chars Number of chars before cursor position
12535 (not in Visual mode)
12536 cursor_words Number of words before cursor position
12537 (not in Visual mode)
12538 visual_bytes Number of bytes visually selected
12539 (only in Visual mode)
12540 visual_chars Number of chars visually selected
12541 (only in Visual mode)
12542 visual_words Number of words visually selected
12543 (only in Visual mode)
12544
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012545 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012546
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012547
12548writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012549 When {object} is a |List| write it to file {fname}. Each list
12550 item is separated with a NL. Each list item must be a String
12551 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012552 All NL characters are replaced with a NUL character.
12553 Inserting CR characters needs to be done before passing {list}
12554 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012555
12556 When {object} is a |Blob| write the bytes to file {fname}
12557 unmodified, also when binary mode is not specified.
12558
12559 {flags} must be a String. These characters are recognized:
12560
12561 'b' Binary mode is used: There will not be a NL after the
12562 last list item. An empty item at the end does cause the
12563 last line in the file to end in a NL.
12564
12565 'a' Append mode is used, lines are appended to the file: >
12566 :call writefile(["foo"], "event.log", "a")
12567 :call writefile(["bar"], "event.log", "a")
12568<
12569 'D' Delete the file when the current function ends. This
12570 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012571 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012572< Fails when not in a function. Also see |:defer|.
12573
12574 's' fsync() is called after writing the file. This flushes
12575 the file to disk, if possible. This takes more time but
12576 avoids losing the file if the system crashes.
12577
12578 'S' fsync() is not called, even when 'fsync' is set.
12579
12580 When {flags} does not contain "S" or "s" then fsync() is
12581 called if the 'fsync' option is set.
12582
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012583 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012585 When the write fails -1 is returned, otherwise 0. There is an
12586 error message if the file can't be created or when writing
12587 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012589 Also see |readfile()|.
12590 To copy a file byte for byte: >
12591 :let fl = readfile("foo", "b")
12592 :call writefile(fl, "foocopy", "b")
12593
12594< Can also be used as a |method|: >
12595 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012596<
12597 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012598
12599
12600xor({expr}, {expr}) *xor()*
12601 Bitwise XOR on the two arguments. The arguments are converted
12602 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012603 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012604 Example: >
12605 :let bits = xor(bits, 0x80)
12606<
12607 Can also be used as a |method|: >
12608 :let bits = bits->xor(0x80)
12609<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012610 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012611
12612==============================================================================
126133. Feature list *feature-list*
12614
12615There are three types of features:
126161. Features that are only supported when they have been enabled when Vim
12617 was compiled |+feature-list|. Example: >
12618 :if has("cindent")
12619< *gui_running*
126202. Features that are only supported when certain conditions have been met.
12621 Example: >
12622 :if has("gui_running")
12623< *has-patch*
126243. Beyond a certain version or at a certain version and including a specific
12625 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12626 later, or it is version 7.4 and patch 248 was included. Example: >
12627 :if has("patch-7.4.248")
12628< Note that it's possible for patch 248 to be omitted even though 249 is
12629 included. Only happens when cherry-picking patches.
12630 Note that this form only works for patch 7.4.237 and later, before that
12631 you need to check for the patch and the v:version. Example (checking
12632 version 6.2.148 or later): >
12633 :if v:version > 602 || (v:version == 602 && has("patch148"))
12634
12635Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12636use: `if exists('+shellslash')`
12637
12638
12639acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012640all_builtin_terms Compiled with all builtin terminals enabled. (always
12641 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012642amiga Amiga version of Vim.
12643arabic Compiled with Arabic support |Arabic|.
12644arp Compiled with ARP support (Amiga).
12645autocmd Compiled with autocommand support. (always true)
12646autochdir Compiled with support for 'autochdir'
12647autoservername Automatically enable |clientserver|
12648balloon_eval Compiled with |balloon-eval| support.
12649balloon_multiline GUI supports multiline balloons.
12650beos BeOS version of Vim.
12651browse Compiled with |:browse| support, and browse() will
12652 work.
12653browsefilter Compiled with support for |browsefilter|.
12654bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012655builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012656byte_offset Compiled with support for 'o' in 'statusline'
12657channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012658cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012659clientserver Compiled with remote invocation support |clientserver|.
12660clipboard Compiled with 'clipboard' support.
12661clipboard_working Compiled with 'clipboard' support and it can be used.
12662cmdline_compl Compiled with |cmdline-completion| support.
12663cmdline_hist Compiled with |cmdline-history| support.
12664cmdline_info Compiled with 'showcmd' and 'ruler' support.
12665comments Compiled with |'comments'| support.
12666compatible Compiled to be very Vi compatible.
12667conpty Platform where |ConPTY| can be used.
12668cryptv Compiled with encryption support |encryption|.
12669cscope Compiled with |cscope| support.
12670cursorbind Compiled with |'cursorbind'| (always true)
12671debug Compiled with "DEBUG" defined.
12672dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012673dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012674dialog_gui Compiled with GUI dialog support.
12675diff Compiled with |vimdiff| and 'diff' support.
12676digraphs Compiled with support for digraphs.
12677directx Compiled with support for DirectX and 'renderoptions'.
12678dnd Compiled with support for the "~ register |quote_~|.
12679drop_file Compiled with |drop_file| support.
12680ebcdic Compiled on a machine with ebcdic character set.
12681emacs_tags Compiled with support for Emacs tags.
12682eval Compiled with expression evaluation support. Always
12683 true, of course!
12684ex_extra |+ex_extra| (always true)
12685extra_search Compiled with support for |'incsearch'| and
12686 |'hlsearch'|
12687farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012688file_in_path Compiled with support for |gf| and |<cfile>| (always
12689 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012690filterpipe When 'shelltemp' is off pipes are used for shell
12691 read/write/filter commands
12692find_in_path Compiled with support for include file searches
12693 |+find_in_path|.
12694float Compiled with support for |Float|.
12695fname_case Case in file names matters (for Amiga and MS-Windows
12696 this is not present).
12697folding Compiled with |folding| support.
12698footer Compiled with GUI footer support. |gui-footer|
12699fork Compiled to use fork()/exec() instead of system().
12700gettext Compiled with message translation |multi-lang|
12701gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012702gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012703gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12704gui_gtk Compiled with GTK+ GUI (any version).
12705gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12706gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12707gui_haiku Compiled with Haiku GUI.
12708gui_mac Compiled with Macintosh GUI.
12709gui_motif Compiled with Motif GUI.
12710gui_photon Compiled with Photon GUI.
12711gui_running Vim is running in the GUI, or it will start soon.
12712gui_win32 Compiled with MS-Windows Win32 GUI.
12713gui_win32s idem, and Win32s system being used (Windows 3.1)
12714haiku Haiku version of Vim.
12715hangul_input Compiled with Hangul input support. |hangul|
12716hpux HP-UX version of Vim.
12717iconv Can use iconv() for conversion.
12718insert_expand Compiled with support for CTRL-X expansion commands in
12719 Insert mode. (always true)
12720job Compiled with support for |channel| and |job|
12721ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012722jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012723keymap Compiled with 'keymap' support.
12724lambda Compiled with |lambda| support.
12725langmap Compiled with 'langmap' support.
12726libcall Compiled with |libcall()| support.
12727linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12728 'breakindent' support.
12729linux Linux version of Vim.
12730lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012731 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012732listcmds Compiled with commands for the buffer list |:files|
12733 and the argument list |arglist|.
12734localmap Compiled with local mappings and abbr. |:map-local|
12735lua Compiled with Lua interface |Lua|.
12736mac Any Macintosh version of Vim cf. osx
12737macunix Synonym for osxdarwin
12738menu Compiled with support for |:menu|.
12739mksession Compiled with support for |:mksession|.
12740modify_fname Compiled with file name modifiers. |filename-modifiers|
12741 (always true)
12742mouse Compiled with support for mouse.
12743mouse_dec Compiled with support for Dec terminal mouse.
12744mouse_gpm Compiled with support for gpm (Linux console mouse)
12745mouse_gpm_enabled GPM mouse is working
12746mouse_netterm Compiled with support for netterm mouse.
12747mouse_pterm Compiled with support for qnx pterm mouse.
12748mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12749mouse_sgr Compiled with support for sgr mouse.
12750mouse_urxvt Compiled with support for urxvt mouse.
12751mouse_xterm Compiled with support for xterm mouse.
12752mouseshape Compiled with support for 'mouseshape'.
12753multi_byte Compiled with support for 'encoding' (always true)
12754multi_byte_encoding 'encoding' is set to a multibyte encoding.
12755multi_byte_ime Compiled with support for IME input method.
12756multi_lang Compiled with support for multiple languages.
12757mzscheme Compiled with MzScheme interface |mzscheme|.
12758nanotime Compiled with sub-second time stamp checks.
12759netbeans_enabled Compiled with support for |netbeans| and connected.
12760netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012761num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012762ole Compiled with OLE automation support for Win32.
12763osx Compiled for macOS cf. mac
12764osxdarwin Compiled for macOS, with |mac-darwin-feature|
12765packages Compiled with |packages| support.
12766path_extra Compiled with up/downwards search in 'path' and 'tags'
12767perl Compiled with Perl interface.
12768persistent_undo Compiled with support for persistent undo history.
12769postscript Compiled with PostScript file printing.
12770printer Compiled with |:hardcopy| support.
12771profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012772prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012773python Python 2.x interface available. |has-python|
12774python_compiled Compiled with Python 2.x interface. |has-python|
12775python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12776python3 Python 3.x interface available. |has-python|
12777python3_compiled Compiled with Python 3.x interface. |has-python|
12778python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012779python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012780pythonx Python 2.x and/or 3.x interface available. |python_x|
12781qnx QNX version of Vim.
12782quickfix Compiled with |quickfix| support.
12783reltime Compiled with |reltime()| support.
12784rightleft Compiled with 'rightleft' support.
12785ruby Compiled with Ruby interface |ruby|.
12786scrollbind Compiled with 'scrollbind' support. (always true)
12787showcmd Compiled with 'showcmd' support.
12788signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012789smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012790sodium Compiled with libsodium for better crypt support
12791sound Compiled with sound support, e.g. `sound_playevent()`
12792spell Compiled with spell checking support |spell|.
12793startuptime Compiled with |--startuptime| support.
12794statusline Compiled with support for 'statusline', 'rulerformat'
12795 and special formats of 'titlestring' and 'iconstring'.
12796sun SunOS version of Vim.
12797sun_workshop Support for Sun |workshop| has been removed.
12798syntax Compiled with syntax highlighting support |syntax|.
12799syntax_items There are active syntax highlighting items for the
12800 current buffer.
12801system Compiled to use system() instead of fork()/exec().
12802tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012803 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012804tag_old_static Support for old static tags was removed, see
12805 |tag-old-static|.
12806tcl Compiled with Tcl interface.
12807termguicolors Compiled with true color in terminal support.
12808terminal Compiled with |terminal| support.
12809terminfo Compiled with terminfo instead of termcap.
12810termresponse Compiled with support for |t_RV| and |v:termresponse|.
12811textobjects Compiled with support for |text-objects|.
12812textprop Compiled with support for |text-properties|.
12813tgetent Compiled with tgetent support, able to use a termcap
12814 or terminfo file.
12815timers Compiled with |timer_start()| support.
12816title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012817 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012818toolbar Compiled with support for |gui-toolbar|.
12819ttyin input is a terminal (tty)
12820ttyout output is a terminal (tty)
12821unix Unix version of Vim. *+unix*
12822unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12823user_commands User-defined commands. (always true)
12824vartabs Compiled with variable tabstop support |'vartabstop'|.
12825vcon Win32: Virtual console support is working, can use
12826 'termguicolors'. Also see |+vtp|.
12827vertsplit Compiled with vertically split windows |:vsplit|.
12828 (always true)
12829vim_starting True while initial source'ing takes place. |startup|
12830 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012831vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012832viminfo Compiled with viminfo support.
12833vimscript-1 Compiled Vim script version 1 support
12834vimscript-2 Compiled Vim script version 2 support
12835vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012836vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012837virtualedit Compiled with 'virtualedit' option. (always true)
12838visual Compiled with Visual mode. (always true)
12839visualextra Compiled with extra Visual mode commands. (always
12840 true) |blockwise-operators|.
12841vms VMS version of Vim.
12842vreplace Compiled with |gR| and |gr| commands. (always true)
12843vtp Compiled for vcon support |+vtp| (check vcon to find
12844 out if it works in the current console).
12845wildignore Compiled with 'wildignore' option.
12846wildmenu Compiled with 'wildmenu' option.
12847win16 old version for MS-Windows 3.1 (always false)
12848win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12849 64 bits)
12850win32unix Win32 version of Vim, using Unix files (Cygwin)
12851win64 Win64 version of Vim (MS-Windows 64 bit).
12852win95 Win32 version for MS-Windows 95/98/ME (always false)
12853winaltkeys Compiled with 'winaltkeys' option.
12854windows Compiled with support for more than one window.
12855 (always true)
12856writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012857xattr Compiled with extended attributes support |xattr|
12858 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012859xfontset Compiled with X fontset support |xfontset|.
12860xim Compiled with X input method support |xim|.
12861xpm Compiled with pixmap support.
12862xpm_w32 Compiled with pixmap support for Win32. (Only for
12863 backward compatibility. Use "xpm" instead.)
12864xsmp Compiled with X session management support.
12865xsmp_interact Compiled with interactive X session management support.
12866xterm_clipboard Compiled with support for xterm clipboard.
12867xterm_save Compiled with support for saving and restoring the
12868 xterm screen.
12869x11 Compiled with X11 support.
12870
12871
12872==============================================================================
128734. Matching a pattern in a String *string-match*
12874
12875This is common between several functions. A regexp pattern as explained at
12876|pattern| is normally used to find a match in the buffer lines. When a
12877pattern is used to find a match in a String, almost everything works in the
12878same way. The difference is that a String is handled like it is one line.
12879When it contains a "\n" character, this is not seen as a line break for the
12880pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12881>
12882 :let a = "aaaa\nxxxx"
12883 :echo matchstr(a, "..\n..")
12884 aa
12885 xx
12886 :echo matchstr(a, "a.x")
12887 a
12888 x
12889
12890Don't forget that "^" will only match at the first character of the String and
12891"$" at the last character of the string. They don't match after or before a
12892"\n".
12893
12894 vim:tw=78:ts=8:noet:ft=help:norl: