blob: 10970bc51a18b62cdb93136858c6674f3622779e [file] [log] [blame]
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Jan 14
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010075blob2str({blob} [, {options}]) String convert {blob} into a String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000076browse({save}, {title}, {initdir}, {default})
77 String put up a file requester
78browsedir({title}, {initdir}) String put up a directory requester
79bufadd({name}) Number add a buffer to the buffer list
80bufexists({buf}) Number |TRUE| if buffer {buf} exists
81buflisted({buf}) Number |TRUE| if buffer {buf} is listed
82bufload({buf}) Number load buffer {buf} if not loaded yet
83bufloaded({buf}) Number |TRUE| if buffer {buf} is loaded
84bufname([{buf}]) String Name of the buffer {buf}
85bufnr([{buf} [, {create}]]) Number Number of the buffer {buf}
86bufwinid({buf}) Number window ID of buffer {buf}
87bufwinnr({buf}) Number window number of buffer {buf}
88byte2line({byte}) Number line number at byte count {byte}
Christian Brabandt67672ef2023-04-24 21:09:54 +010089byteidx({expr}, {nr} [, {utf16}])
90 Number byte index of {nr}'th char in {expr}
91byteidxcomp({expr}, {nr} [, {utf16}])
92 Number byte index of {nr}'th char in {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000093call({func}, {arglist} [, {dict}])
94 any call {func} with arguments {arglist}
95ceil({expr}) Float round {expr} up
96ch_canread({handle}) Number check if there is something to read
97ch_close({handle}) none close {handle}
98ch_close_in({handle}) none close in part of {handle}
99ch_evalexpr({handle}, {expr} [, {options}])
100 any evaluate {expr} on JSON {handle}
101ch_evalraw({handle}, {string} [, {options}])
102 any evaluate {string} on raw {handle}
103ch_getbufnr({handle}, {what}) Number get buffer number for {handle}/{what}
104ch_getjob({channel}) Job get the Job of {channel}
105ch_info({handle}) String info about channel {handle}
106ch_log({msg} [, {handle}]) none write {msg} in the channel log file
107ch_logfile({fname} [, {mode}]) none start logging channel activity
108ch_open({address} [, {options}])
109 Channel open a channel to {address}
110ch_read({handle} [, {options}]) String read from {handle}
111ch_readblob({handle} [, {options}])
112 Blob read Blob from {handle}
113ch_readraw({handle} [, {options}])
114 String read raw from {handle}
115ch_sendexpr({handle}, {expr} [, {options}])
116 any send {expr} over JSON {handle}
117ch_sendraw({handle}, {expr} [, {options}])
118 any send {expr} over raw {handle}
119ch_setoptions({handle}, {options})
120 none set options for {handle}
121ch_status({handle} [, {options}])
122 String status of channel {handle}
123changenr() Number current change number
124char2nr({expr} [, {utf8}]) Number ASCII/UTF-8 value of first char in {expr}
125charclass({string}) Number character class of {string}
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000126charcol({expr} [, {winid}]) Number column number of cursor or mark
Christian Brabandt67672ef2023-04-24 21:09:54 +0100127charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000128 Number char index of byte {idx} in {string}
129chdir({dir}) String change current working directory
130cindent({lnum}) Number C indent for line {lnum}
131clearmatches([{win}]) none clear all matches
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +0000132col({expr} [, {winid}]) Number column byte index of cursor or mark
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000133complete({startcol}, {matches}) none set Insert mode completion
134complete_add({expr}) Number add completion match
135complete_check() Number check for key typed during completion
136complete_info([{what}]) Dict get current completion information
137confirm({msg} [, {choices} [, {default} [, {type}]]])
138 Number number of choice picked by user
139copy({expr}) any make a shallow copy of {expr}
140cos({expr}) Float cosine of {expr}
141cosh({expr}) Float hyperbolic cosine of {expr}
142count({comp}, {expr} [, {ic} [, {start}]])
143 Number count how many {expr} are in {comp}
144cscope_connection([{num}, {dbpath} [, {prepend}]])
145 Number checks existence of cscope connection
146cursor({lnum}, {col} [, {off}])
147 Number move cursor to {lnum}, {col}, {off}
148cursor({list}) Number move cursor to position in {list}
149debugbreak({pid}) Number interrupt process being debugged
150deepcopy({expr} [, {noref}]) any make a full copy of {expr}
151delete({fname} [, {flags}]) Number delete the file or directory {fname}
152deletebufline({buf}, {first} [, {last}])
153 Number delete lines from buffer {buf}
154did_filetype() Number |TRUE| if FileType autocmd event used
Yegappan Lakshmananfa378352024-02-01 22:05:27 +0100155diff({fromlist}, {tolist} [, {options}])
156 List diff two Lists of strings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000157diff_filler({lnum}) Number diff filler lines about {lnum}
158diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
159digraph_get({chars}) String get the |digraph| of {chars}
160digraph_getlist([{listall}]) List get all |digraph|s
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200161digraph_set({chars}, {digraph}) Bool register |digraph|
162digraph_setlist({digraphlist}) Bool register multiple |digraph|s
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000163echoraw({expr}) none output {expr} as-is
164empty({expr}) Number |TRUE| if {expr} is empty
165environ() Dict return environment variables
Sean Dewarb0efa492023-07-08 10:35:19 +0100166err_teapot([{expr}]) none give E418, or E503 if {expr} is |TRUE|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000167escape({string}, {chars}) String escape {chars} in {string} with '\'
168eval({string}) any evaluate {string} into its value
169eventhandler() Number |TRUE| if inside an event handler
170executable({expr}) Number 1 if executable {expr} exists
171execute({command}) String execute {command} and get the output
172exepath({expr}) String full path of the command {expr}
173exists({expr}) Number |TRUE| if {expr} exists
174exists_compiled({expr}) Number |TRUE| if {expr} exists at compile time
175exp({expr}) Float exponential of {expr}
176expand({expr} [, {nosuf} [, {list}]])
177 any expand special keywords in {expr}
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +0100178expandcmd({string} [, {options}])
179 String expand {string} like with `:edit`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000180extend({expr1}, {expr2} [, {expr3}])
181 List/Dict insert items of {expr2} into {expr1}
182extendnew({expr1}, {expr2} [, {expr3}])
183 List/Dict like |extend()| but creates a new
184 List or Dictionary
185feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer
Shougo Matsushita60c87432024-06-03 22:59:27 +0200186filecopy({from}, {to}) Number |TRUE| if copying file {from} to {to}
187 worked
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000188filereadable({file}) Number |TRUE| if {file} is a readable file
189filewritable({file}) Number |TRUE| if {file} is a writable file
190filter({expr1}, {expr2}) List/Dict/Blob/String
191 remove items from {expr1} where
192 {expr2} is 0
193finddir({name} [, {path} [, {count}]])
194 String find directory {name} in {path}
195findfile({name} [, {path} [, {count}]])
196 String find file {name} in {path}
197flatten({list} [, {maxdepth}]) List flatten {list} up to {maxdepth} levels
198flattennew({list} [, {maxdepth}])
199 List flatten a copy of {list}
200float2nr({expr}) Number convert Float {expr} to a Number
201floor({expr}) Float round {expr} down
202fmod({expr1}, {expr2}) Float remainder of {expr1} / {expr2}
203fnameescape({fname}) String escape special characters in {fname}
204fnamemodify({fname}, {mods}) String modify file name
205foldclosed({lnum}) Number first line of fold at {lnum} if closed
206foldclosedend({lnum}) Number last line of fold at {lnum} if closed
207foldlevel({lnum}) Number fold level at {lnum}
208foldtext() String line displayed for closed fold
209foldtextresult({lnum}) String text for closed fold at {lnum}
Ernie Raele79e2072024-01-13 11:47:33 +0100210foreach({expr1}, {expr2}) List/Dict/Blob/String
211 for each item in {expr1} call {expr2}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000212foreground() Number bring the Vim window to the foreground
Bram Moolenaaraa534142022-09-15 21:46:02 +0100213fullcommand({name} [, {vim9}]) String get full command from {name}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000214funcref({name} [, {arglist}] [, {dict}])
215 Funcref reference to function {name}
216function({name} [, {arglist}] [, {dict}])
217 Funcref named reference to function {name}
218garbagecollect([{atexit}]) none free memory, breaking cyclic references
219get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
220get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
221get({func}, {what}) any get property of funcref/partial {func}
222getbufinfo([{buf}]) List information about buffers
223getbufline({buf}, {lnum} [, {end}])
224 List lines {lnum} to {end} of buffer {buf}
Bram Moolenaarce30ccc2022-11-21 19:57:04 +0000225getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000226getbufvar({buf}, {varname} [, {def}])
227 any variable {varname} in buffer {buf}
mikoto20001083cae2024-11-11 21:24:14 +0100228getcellpixels() List get character cell pixel size
Kota Kato66bb9ae2023-01-17 18:31:56 +0000229getcellwidths() List get character cell width overrides
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000230getchangelist([{buf}]) List list of change list items
Doug Kearns9cd9e752024-04-07 17:42:17 +0200231getchar([{expr}]) Number or String
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000232 get one character from the user
233getcharmod() Number modifiers for the last typed character
234getcharpos({expr}) List position of cursor, mark, etc.
235getcharsearch() Dict last character search
Doug Kearns9cd9e752024-04-07 17:42:17 +0200236getcharstr([{expr}]) String get one character from the user
Ruslan Russkikh0407d622024-10-08 22:21:05 +0200237getcmdcomplpat() String return the completion pattern of the
238 current command-line completion
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100239getcmdcompltype() String return the type of the current
240 command-line completion
Shougo Matsushita69084282024-09-23 20:34:47 +0200241getcmdline() String return the current command-line input
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000242getcmdpos() Number return cursor position in command-line
Shougo Matsushita69084282024-09-23 20:34:47 +0200243getcmdprompt() String return the current command-line prompt
Shougo Matsushita79d599b2022-05-07 12:48:29 +0100244getcmdscreenpos() Number return cursor screen position in
245 command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000246getcmdtype() String return current command-line type
247getcmdwintype() String return current command-line window type
248getcompletion({pat}, {type} [, {filtered}])
249 List list of cmdline completion matches
250getcurpos([{winnr}]) List position of the cursor
251getcursorcharpos([{winnr}]) List character position of the cursor
252getcwd([{winnr} [, {tabnr}]]) String get the current working directory
253getenv({name}) String return environment variable
254getfontname([{name}]) String name of font being used
255getfperm({fname}) String file permissions of file {fname}
256getfsize({fname}) Number size in bytes of file {fname}
257getftime({fname}) Number last modification time of file
258getftype({fname}) String description of type of file {fname}
259getimstatus() Number |TRUE| if the IME status is active
260getjumplist([{winnr} [, {tabnr}]])
261 List list of jump list items
262getline({lnum}) String line {lnum} of current buffer
263getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
264getloclist({nr}) List list of location list items
265getloclist({nr}, {what}) Dict get specific location list properties
266getmarklist([{buf}]) List list of global/local marks
267getmatches([{win}]) List list of current matches
268getmousepos() Dict last known mouse position
Bram Moolenaar24dc19c2022-11-14 19:49:15 +0000269getmouseshape() String current mouse shape name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000270getpid() Number process ID of Vim
271getpos({expr}) List position of cursor, mark, etc.
272getqflist() List list of quickfix items
273getqflist({what}) Dict get specific quickfix list properties
274getreg([{regname} [, 1 [, {list}]]])
275 String or List contents of a register
276getreginfo([{regname}]) Dict information about a register
Shougo Matsushita19b71882024-02-28 22:48:12 +0100277getregion({pos1}, {pos2} [, {opts}])
Shougo Matsushita3f905ab2024-02-21 00:02:45 +0100278 List get the text from {pos1} to {pos2}
Shougo Matsushitab4757e62024-05-07 20:49:24 +0200279getregionpos({pos1}, {pos2} [, {opts}])
280 List get a list of positions for a region
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000281getregtype([{regname}]) String type of a register
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +0100282getscriptinfo([{opts}]) List list of sourced scripts
ichizok663d18d2025-01-02 18:06:00 +0100283getstacktrace() List get current stack trace of Vim scripts
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000284gettabinfo([{expr}]) List list of tab pages
285gettabvar({nr}, {varname} [, {def}])
286 any variable {varname} in tab {nr} or {def}
287gettabwinvar({tabnr}, {winnr}, {name} [, {def}])
288 any {name} in {winnr} in tab page {tabnr}
289gettagstack([{nr}]) Dict get the tag stack of window {nr}
h-east52e7cc22024-07-28 17:03:29 +0200290gettext({text} [, {package}]) String lookup translation of {text}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000291getwininfo([{winid}]) List list of info about each window
Bram Moolenaar938ae282023-02-20 20:44:55 +0000292getwinpos([{timeout}]) List X and Y coord in pixels of Vim window
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000293getwinposx() Number X coord in pixels of the Vim window
294getwinposy() Number Y coord in pixels of the Vim window
295getwinvar({nr}, {varname} [, {def}])
296 any variable {varname} in window {nr}
297glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
298 any expand file wildcards in {expr}
299glob2regpat({expr}) String convert a glob pat into a search pat
300globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
301 String do glob({expr}) for all dirs in {path}
302has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
303has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
304haslocaldir([{winnr} [, {tabnr}]])
305 Number |TRUE| if the window executed |:lcd|
306 or |:tcd|
307hasmapto({what} [, {mode} [, {abbr}]])
308 Number |TRUE| if mapping to {what} exists
309histadd({history}, {item}) Number add an item to a history
310histdel({history} [, {item}]) Number remove an item from a history
311histget({history} [, {index}]) String get the item {index} from a history
312histnr({history}) Number highest index of a history
313hlID({name}) Number syntax ID of highlight group {name}
314hlexists({name}) Number |TRUE| if highlight group {name} exists
315hlget([{name} [, {resolve}]]) List get highlight group attributes
316hlset({list}) Number set highlight group attributes
317hostname() String name of the machine Vim is running on
318iconv({expr}, {from}, {to}) String convert encoding of {expr}
Ernie Rael05124252024-07-11 22:10:45 +0200319id({item}) String get unique identity string of item
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000320indent({lnum}) Number indent of line {lnum}
321index({object}, {expr} [, {start} [, {ic}]])
322 Number index in {object} where {expr} appears
Yegappan Lakshmananb2186552022-08-13 13:09:20 +0100323indexof({object}, {expr} [, {opts}]])
324 Number index in {object} where {expr} is true
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000325input({prompt} [, {text} [, {completion}]])
326 String get input from the user
Bram Moolenaarb529cfb2022-07-25 15:42:07 +0100327inputdialog({prompt} [, {text} [, {cancelreturn}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000328 String like input() but in a GUI dialog
329inputlist({textlist}) Number let the user pick from a choice list
330inputrestore() Number restore typeahead
331inputsave() Number save and clear typeahead
332inputsecret({prompt} [, {text}]) String like input() but hiding the text
333insert({object}, {item} [, {idx}]) List insert {item} in {object} [before {idx}]
LemonBoyafe04662023-08-23 21:08:11 +0200334instanceof({object}, {class}) Number |TRUE| if {object} is an instance of {class}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000335interrupt() none interrupt script execution
336invert({expr}) Number bitwise invert
LemonBoydca1d402022-04-28 15:26:33 +0100337isabsolutepath({path}) Number |TRUE| if {path} is an absolute path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000338isdirectory({directory}) Number |TRUE| if {directory} is a directory
339isinf({expr}) Number determine if {expr} is infinity value
340 (positive or negative)
341islocked({expr}) Number |TRUE| if {expr} is locked
342isnan({expr}) Number |TRUE| if {expr} is NaN
343items({dict}) List key-value pairs in {dict}
344job_getchannel({job}) Channel get the channel handle for {job}
345job_info([{job}]) Dict get information about {job}
346job_setoptions({job}, {options}) none set options for {job}
347job_start({command} [, {options}])
348 Job start a job
349job_status({job}) String get the status of {job}
350job_stop({job} [, {how}]) Number stop {job}
351join({list} [, {sep}]) String join {list} items into one String
352js_decode({string}) any decode JS style JSON
353js_encode({expr}) String encode JS style JSON
354json_decode({string}) any decode JSON
355json_encode({expr}) String encode JSON
356keys({dict}) List keys in {dict}
zeertzjqcdc83932022-09-12 13:38:41 +0100357keytrans({string}) String translate internal keycodes to a form
358 that can be used by |:map|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000359len({expr}) Number the length of {expr}
360libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
361libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
362line({expr} [, {winid}]) Number line nr of cursor, last line or mark
363line2byte({lnum}) Number byte count of line {lnum}
364lispindent({lnum}) Number Lisp indent for line {lnum}
365list2blob({list}) Blob turn {list} of numbers into a Blob
366list2str({list} [, {utf8}]) String turn {list} of numbers into a String
367listener_add({callback} [, {buf}])
368 Number add a callback to listen to changes
369listener_flush([{buf}]) none invoke listener callbacks
370listener_remove({id}) none remove a listener callback
371localtime() Number current time
372log({expr}) Float natural logarithm (base e) of {expr}
373log10({expr}) Float logarithm of Float {expr} to base 10
374luaeval({expr} [, {expr}]) any evaluate |Lua| expression
375map({expr1}, {expr2}) List/Dict/Blob/String
376 change each item in {expr1} to {expr2}
377maparg({name} [, {mode} [, {abbr} [, {dict}]]])
378 String or Dict
379 rhs of mapping {name} in mode {mode}
380mapcheck({name} [, {mode} [, {abbr}]])
381 String check for mappings matching {name}
Ernie Rael09661202022-04-25 14:40:44 +0100382maplist([{abbr}]) List list of all mappings, a dict for each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000383mapnew({expr1}, {expr2}) List/Dict/Blob/String
384 like |map()| but creates a new List or
385 Dictionary
386mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
387match({expr}, {pat} [, {start} [, {count}]])
388 Number position where {pat} matches in {expr}
389matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
390 Number highlight {pattern} with {group}
391matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
392 Number highlight positions with {group}
393matcharg({nr}) List arguments of |:match|
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100394matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict})
395 List all the {pat} matches in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000396matchdelete({id} [, {win}]) Number delete match identified by {id}
397matchend({expr}, {pat} [, {start} [, {count}]])
398 Number position where {pat} ends in {expr}
399matchfuzzy({list}, {str} [, {dict}])
400 List fuzzy match {str} in {list}
401matchfuzzypos({list}, {str} [, {dict}])
402 List fuzzy match {str} in {list}
403matchlist({expr}, {pat} [, {start} [, {count}]])
404 List match and submatches of {pat} in {expr}
405matchstr({expr}, {pat} [, {start} [, {count}]])
406 String {count}'th match of {pat} in {expr}
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +0100407matchstrlist({list}, {pat} [, {dict})
408 List all the {pat} matches in {list}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000409matchstrpos({expr}, {pat} [, {start} [, {count}]])
410 List {count}'th match of {pat} in {expr}
411max({expr}) Number maximum value of items in {expr}
412menu_info({name} [, {mode}]) Dict get menu item information
413min({expr}) Number minimum value of items in {expr}
Bram Moolenaar938ae282023-02-20 20:44:55 +0000414mkdir({name} [, {flags} [, {prot}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000415 Number create directory {name}
Doug Kearns9cd9e752024-04-07 17:42:17 +0200416mode([{expr}]) String current editing mode
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000417mzeval({expr}) any evaluate |MzScheme| expression
418nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
419nr2char({expr} [, {utf8}]) String single char with ASCII/UTF-8 value {expr}
420or({expr}, {expr}) Number bitwise OR
421pathshorten({expr} [, {len}]) String shorten directory names in a path
422perleval({expr}) any evaluate |Perl| expression
423popup_atcursor({what}, {options}) Number create popup window near the cursor
424popup_beval({what}, {options}) Number create popup window for 'ballooneval'
425popup_clear() none close all popup windows
426popup_close({id} [, {result}]) none close popup window {id}
427popup_create({what}, {options}) Number create a popup window
428popup_dialog({what}, {options}) Number create a popup window used as a dialog
429popup_filter_menu({id}, {key}) Number filter for a menu popup window
430popup_filter_yesno({id}, {key}) Number filter for a dialog popup window
Bram Moolenaarbdc09a12022-10-07 14:31:45 +0100431popup_findecho() Number get window ID of popup for `:echowin`
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000432popup_findinfo() Number get window ID of info popup window
433popup_findpreview() Number get window ID of preview popup window
434popup_getoptions({id}) Dict get options of popup window {id}
435popup_getpos({id}) Dict get position of popup window {id}
436popup_hide({id}) none hide popup menu {id}
437popup_list() List get a list of window IDs of all popups
438popup_locate({row}, {col}) Number get window ID of popup at position
439popup_menu({what}, {options}) Number create a popup window used as a menu
440popup_move({id}, {options}) none set position of popup window {id}
441popup_notification({what}, {options})
442 Number create a notification popup window
Christian Brabandtfbc37f12024-06-18 20:50:58 +0200443popup_setbuf({id}, {buf}) Bool set the buffer for the popup window {id}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000444popup_setoptions({id}, {options})
445 none set options for popup window {id}
446popup_settext({id}, {text}) none set the text of popup window {id}
447popup_show({id}) none unhide popup window {id}
448pow({x}, {y}) Float {x} to the power of {y}
449prevnonblank({lnum}) Number line nr of non-blank line <= {lnum}
450printf({fmt}, {expr1}...) String format text
451prompt_getprompt({buf}) String get prompt text
452prompt_setcallback({buf}, {expr}) none set prompt callback function
453prompt_setinterrupt({buf}, {text}) none set prompt interrupt function
454prompt_setprompt({buf}, {text}) none set prompt text
455prop_add({lnum}, {col}, {props}) none add one text property
456prop_add_list({props}, [[{lnum}, {col}, {end-lnum}, {end-col}], ...])
457 none add multiple text properties
458prop_clear({lnum} [, {lnum-end} [, {props}]])
459 none remove all text properties
460prop_find({props} [, {direction}])
461 Dict search for a text property
462prop_list({lnum} [, {props}]) List text properties in {lnum}
463prop_remove({props} [, {lnum} [, {lnum-end}]])
464 Number remove a text property
465prop_type_add({name}, {props}) none define a new property type
466prop_type_change({name}, {props})
467 none change an existing property type
468prop_type_delete({name} [, {props}])
469 none delete a property type
470prop_type_get({name} [, {props}])
471 Dict get property type values
472prop_type_list([{props}]) List get list of property types
473pum_getpos() Dict position and size of pum if visible
474pumvisible() Number whether popup menu is visible
zeertzjq7c515282024-11-10 20:26:12 +0100475py3eval({expr} [, {locals}]) any evaluate |python3| expression
476pyeval({expr} [, {locals}]) any evaluate |Python| expression
477pyxeval({expr} [, {locals}]) any evaluate |python_x| expression
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000478rand([{expr}]) Number get pseudo-random number
479range({expr} [, {max} [, {stride}]])
480 List items from {expr} to {max}
K.Takata11df3ae2022-10-19 14:02:40 +0100481readblob({fname} [, {offset} [, {size}]])
482 Blob read a |Blob| from {fname}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000483readdir({dir} [, {expr} [, {dict}]])
484 List file names in {dir} selected by {expr}
485readdirex({dir} [, {expr} [, {dict}]])
486 List file info in {dir} selected by {expr}
487readfile({fname} [, {type} [, {max}]])
488 List get list of lines from file {fname}
489reduce({object}, {func} [, {initial}])
490 any reduce {object} using {func}
491reg_executing() String get the executing register name
492reg_recording() String get the recording register name
493reltime([{start} [, {end}]]) List get time value
494reltimefloat({time}) Float turn the time value into a Float
495reltimestr({time}) String turn time value into a String
496remote_expr({server}, {string} [, {idvar} [, {timeout}]])
497 String send expression
498remote_foreground({server}) Number bring Vim server to the foreground
499remote_peek({serverid} [, {retvar}])
500 Number check for reply string
501remote_read({serverid} [, {timeout}])
502 String read reply string
503remote_send({server}, {string} [, {idvar}])
504 String send key sequence
505remote_startserver({name}) none become server {name}
506remove({list}, {idx} [, {end}]) any/List
507 remove items {idx}-{end} from {list}
508remove({blob}, {idx} [, {end}]) Number/Blob
509 remove bytes {idx}-{end} from {blob}
510remove({dict}, {key}) any remove entry {key} from {dict}
511rename({from}, {to}) Number rename (move) file from {from} to {to}
Bakudankun375141e2022-09-09 18:46:47 +0100512repeat({expr}, {count}) List/Blob/String
513 repeat {expr} {count} times
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000514resolve({filename}) String get filename a shortcut points to
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +0100515reverse({obj}) List/Blob/String
516 reverse {obj}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000517round({expr}) Float round off {expr}
518rubyeval({expr}) any evaluate |Ruby| expression
519screenattr({row}, {col}) Number attribute at screen position
520screenchar({row}, {col}) Number character at screen position
521screenchars({row}, {col}) List List of characters at screen position
522screencol() Number current cursor column
523screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
524screenrow() Number current cursor row
525screenstring({row}, {col}) String characters at screen position
526search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
527 Number search for {pattern}
528searchcount([{options}]) Dict get or update search stats
529searchdecl({name} [, {global} [, {thisblock}]])
530 Number search for variable declaration
531searchpair({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
532 Number search for other end of start/end pair
533searchpairpos({start}, {middle}, {end} [, {flags} [, {skip} [...]]])
534 List search for other end of start/end pair
535searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
536 List search for {pattern}
537server2client({clientid}, {string})
538 Number send reply string
539serverlist() String get a list of available servers
erraelf0837ba2024-06-24 12:27:01 -0700540setbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000541 Number set line {lnum} to {text} in buffer
erraelf0837ba2024-06-24 12:27:01 -0700542 {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000543setbufvar({buf}, {varname}, {val})
544 none set {varname} in buffer {buf} to {val}
545setcellwidths({list}) none set character cell width overrides
546setcharpos({expr}, {list}) Number set the {expr} position to {list}
547setcharsearch({dict}) Dict set character search from {dict}
Shougo Matsushita07ea5f12022-08-27 12:22:25 +0100548setcmdline({str} [, {pos}]) Number set command-line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000549setcmdpos({pos}) Number set cursor position in command-line
550setcursorcharpos({list}) Number move cursor to position in {list}
551setenv({name}, {val}) none set environment variable
552setfperm({fname}, {mode}) Number set {fname} file permissions to {mode}
553setline({lnum}, {line}) Number set line {lnum} to {line}
554setloclist({nr}, {list} [, {action}])
555 Number modify location list using {list}
556setloclist({nr}, {list}, {action}, {what})
557 Number modify specific location list props
558setmatches({list} [, {win}]) Number restore a list of matches
559setpos({expr}, {list}) Number set the {expr} position to {list}
560setqflist({list} [, {action}]) Number modify quickfix list using {list}
561setqflist({list}, {action}, {what})
562 Number modify specific quickfix list props
563setreg({n}, {v} [, {opt}]) Number set register to value and type
564settabvar({nr}, {varname}, {val}) none set {varname} in tab page {nr} to {val}
565settabwinvar({tabnr}, {winnr}, {varname}, {val})
566 none set {varname} in window {winnr} in tab
567 page {tabnr} to {val}
568settagstack({nr}, {dict} [, {action}])
569 Number modify tag stack using {dict}
570setwinvar({nr}, {varname}, {val}) none set {varname} in window {nr} to {val}
571sha256({string}) String SHA256 checksum of {string}
572shellescape({string} [, {special}])
573 String escape {string} for use as shell
574 command argument
575shiftwidth([{col}]) Number effective value of 'shiftwidth'
576sign_define({name} [, {dict}]) Number define or update a sign
577sign_define({list}) List define or update a list of signs
578sign_getdefined([{name}]) List get a list of defined signs
579sign_getplaced([{buf} [, {dict}]])
580 List get a list of placed signs
581sign_jump({id}, {group}, {buf})
582 Number jump to a sign
583sign_place({id}, {group}, {name}, {buf} [, {dict}])
584 Number place a sign
585sign_placelist({list}) List place a list of signs
586sign_undefine([{name}]) Number undefine a sign
587sign_undefine({list}) List undefine a list of signs
588sign_unplace({group} [, {dict}])
589 Number unplace a sign
590sign_unplacelist({list}) List unplace a list of signs
591simplify({filename}) String simplify filename as much as possible
592sin({expr}) Float sine of {expr}
593sinh({expr}) Float hyperbolic sine of {expr}
594slice({expr}, {start} [, {end}]) String, List or Blob
595 slice of a String, List or Blob
Bram Moolenaar2007dd42022-02-23 13:17:47 +0000596sort({list} [, {how} [, {dict}]])
597 List sort {list}, compare with {how}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000598sound_clear() none stop playing all sounds
599sound_playevent({name} [, {callback}])
600 Number play an event sound
601sound_playfile({path} [, {callback}])
602 Number play sound file {path}
603sound_stop({id}) none stop playing sound {id}
604soundfold({word}) String sound-fold {word}
605spellbadword() String badly spelled word at cursor
606spellsuggest({word} [, {max} [, {capital}]])
607 List spelling suggestions
608split({expr} [, {pat} [, {keepempty}]])
609 List make |List| from {pat} separated {expr}
610sqrt({expr}) Float square root of {expr}
611srand([{expr}]) List get seed for |rand()|
612state([{what}]) String current state of Vim
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +0100613str2blob({string} [, {options}])
614 Blob convert {string} into a Blob
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000615str2float({expr} [, {quoted}]) Float convert String to Float
616str2list({expr} [, {utf8}]) List convert each character of {expr} to
617 ASCII/UTF-8 value
618str2nr({expr} [, {base} [, {quoted}]])
619 Number convert String to Number
620strcharlen({expr}) Number character length of the String {expr}
621strcharpart({str}, {start} [, {len} [, {skipcc}]])
622 String {len} characters of {str} at
623 character {start}
624strchars({expr} [, {skipcc}]) Number character count of the String {expr}
625strdisplaywidth({expr} [, {col}]) Number display length of the String {expr}
626strftime({format} [, {time}]) String format time with a specified format
627strgetchar({str}, {index}) Number get char {index} from {str}
628stridx({haystack}, {needle} [, {start}])
629 Number index of {needle} in {haystack}
630string({expr}) String String representation of {expr} value
631strlen({expr}) Number length of the String {expr}
632strpart({str}, {start} [, {len} [, {chars}]])
633 String {len} bytes/chars of {str} at
634 byte {start}
635strptime({format}, {timestring})
636 Number Convert {timestring} to unix timestamp
637strridx({haystack}, {needle} [, {start}])
638 Number last index of {needle} in {haystack}
639strtrans({expr}) String translate string to make it printable
Christian Brabandt67672ef2023-04-24 21:09:54 +0100640strutf16len({string} [, {countcc}])
641 Number number of UTF-16 code units in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000642strwidth({expr}) Number display cell length of the String {expr}
643submatch({nr} [, {list}]) String or List
644 specific match in ":s" or substitute()
645substitute({expr}, {pat}, {sub}, {flags})
646 String all {pat} in {expr} replaced with {sub}
Bram Moolenaarc216a7a2022-12-05 13:50:55 +0000647swapfilelist() List swap files found in 'directory'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000648swapinfo({fname}) Dict information about swap file {fname}
649swapname({buf}) String swap file of buffer {buf}
650synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
651synIDattr({synID}, {what} [, {mode}])
652 String attribute {what} of syntax ID {synID}
653synIDtrans({synID}) Number translated syntax ID of {synID}
654synconcealed({lnum}, {col}) List info about concealing
655synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col}
656system({expr} [, {input}]) String output of shell command/filter {expr}
657systemlist({expr} [, {input}]) List output of shell command/filter {expr}
658tabpagebuflist([{arg}]) List list of buffer numbers in tab page
659tabpagenr([{arg}]) Number number of current or last tab page
660tabpagewinnr({tabarg} [, {arg}]) Number number of current window in tab page
661tagfiles() List tags files used
662taglist({expr} [, {filename}]) List list of tags matching {expr}
663tan({expr}) Float tangent of {expr}
664tanh({expr}) Float hyperbolic tangent of {expr}
665tempname() String name for a temporary file
666term_dumpdiff({filename}, {filename} [, {options}])
667 Number display difference between two dumps
668term_dumpload({filename} [, {options}])
669 Number displaying a screen dump
670term_dumpwrite({buf}, {filename} [, {options}])
671 none dump terminal window contents
672term_getaltscreen({buf}) Number get the alternate screen flag
673term_getansicolors({buf}) List get ANSI palette in GUI color mode
674term_getattr({attr}, {what}) Number get the value of attribute {what}
675term_getcursor({buf}) List get the cursor position of a terminal
676term_getjob({buf}) Job get the job associated with a terminal
677term_getline({buf}, {row}) String get a line of text from a terminal
678term_getscrolled({buf}) Number get the scroll count of a terminal
679term_getsize({buf}) List get the size of a terminal
680term_getstatus({buf}) String get the status of a terminal
681term_gettitle({buf}) String get the title of a terminal
682term_gettty({buf}, [{input}]) String get the tty name of a terminal
683term_list() List get the list of terminal buffers
684term_scrape({buf}, {row}) List get row of a terminal screen
685term_sendkeys({buf}, {keys}) none send keystrokes to a terminal
686term_setansicolors({buf}, {colors})
687 none set ANSI palette in GUI color mode
688term_setapi({buf}, {expr}) none set |terminal-api| function name prefix
689term_setkill({buf}, {how}) none set signal to stop job in terminal
690term_setrestore({buf}, {command}) none set command to restore terminal
691term_setsize({buf}, {rows}, {cols})
692 none set the size of a terminal
693term_start({cmd} [, {options}]) Number open a terminal window and run a job
694term_wait({buf} [, {time}]) Number wait for screen to be updated
695terminalprops() Dict properties of the terminal
696test_alloc_fail({id}, {countdown}, {repeat})
697 none make memory allocation fail
698test_autochdir() none enable 'autochdir' during startup
699test_feedinput({string}) none add key sequence to input buffer
700test_garbagecollect_now() none free memory right now for testing
701test_garbagecollect_soon() none free memory soon for testing
702test_getvalue({string}) any get value of an internal variable
Yegappan Lakshmanan06011e12022-01-30 12:37:29 +0000703test_gui_event({event}, {args}) bool generate a GUI event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000704test_ignore_error({expr}) none ignore a specific error
Christopher Plewright20b795e2022-12-20 20:01:58 +0000705test_mswin_event({event}, {args})
706 bool generate MS-Windows event for testing
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000707test_null_blob() Blob null value for testing
708test_null_channel() Channel null value for testing
709test_null_dict() Dict null value for testing
710test_null_function() Funcref null value for testing
711test_null_job() Job null value for testing
712test_null_list() List null value for testing
713test_null_partial() Funcref null value for testing
714test_null_string() String null value for testing
715test_option_not_set({name}) none reset flag indicating option was set
716test_override({expr}, {val}) none test with Vim internal overrides
717test_refcount({expr}) Number get the reference count of {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000718test_setmouse({row}, {col}) none set the mouse position for testing
719test_settime({expr}) none set current time for testing
Doug Kearns9cd9e752024-04-07 17:42:17 +0200720test_srand_seed([{seed}]) none set seed for testing srand()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000721test_unknown() any unknown value for testing
722test_void() any void value for testing
723timer_info([{id}]) List information about timers
724timer_pause({id}, {pause}) none pause or unpause a timer
725timer_start({time}, {callback} [, {options}])
726 Number create a timer
727timer_stop({timer}) none stop a timer
728timer_stopall() none stop all timers
729tolower({expr}) String the String {expr} switched to lowercase
730toupper({expr}) String the String {expr} switched to uppercase
731tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr}
732 to chars in {tostr}
733trim({text} [, {mask} [, {dir}]])
734 String trim characters in {mask} from {text}
735trunc({expr}) Float truncate Float {expr}
736type({expr}) Number type of value {expr}
737typename({expr}) String representation of the type of {expr}
738undofile({name}) String undo file name for {name}
Devin J. Pohly5fee1112023-04-23 20:26:59 -0500739undotree([{buf}]) List undo file tree for buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000740uniq({list} [, {func} [, {dict}]])
741 List remove adjacent duplicates from a list
Christian Brabandt67672ef2023-04-24 21:09:54 +0100742utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
743 Number UTF-16 index of byte {idx} in {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000744values({dict}) List values in {dict}
zeertzjq825cf812023-08-17 22:55:25 +0200745virtcol({expr} [, {list} [, {winid}])
746 Number or List
LemonBoy0f7a3e12022-05-26 12:10:37 +0100747 screen column of cursor or mark
Bram Moolenaar5a6ec102022-05-27 21:58:00 +0100748virtcol2col({winid}, {lnum}, {col})
749 Number byte index of a character on screen
Doug Kearns9cd9e752024-04-07 17:42:17 +0200750visualmode([{expr}]) String last visual mode used
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000751wildmenumode() Number whether 'wildmenu' mode is active
752win_execute({id}, {command} [, {silent}])
753 String execute {command} in window {id}
754win_findbuf({bufnr}) List find windows containing {bufnr}
755win_getid([{win} [, {tab}]]) Number get window ID for {win} in {tab}
756win_gettype([{nr}]) String type of window {nr}
757win_gotoid({expr}) Number go to window with ID {expr}
758win_id2tabwin({expr}) List get tab and window nr from window ID
759win_id2win({expr}) Number get window nr from window ID
Daniel Steinbergee630312022-01-10 13:36:34 +0000760win_move_separator({nr}) Number move window vertical separator
761win_move_statusline({nr}) Number move window status line
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000762win_screenpos({nr}) List get screen position of window {nr}
763win_splitmove({nr}, {target} [, {options}])
764 Number move window {nr} to split of {target}
765winbufnr({nr}) Number buffer number of window {nr}
766wincol() Number window column of the cursor
767windowsversion() String MS-Windows OS version
768winheight({nr}) Number height of window {nr}
769winlayout([{tabnr}]) List layout of windows in tab {tabnr}
770winline() Number window line of the cursor
771winnr([{expr}]) Number number of current window
772winrestcmd() String returns command to restore window sizes
773winrestview({dict}) none restore view of current window
774winsaveview() Dict save view of current window
775winwidth({nr}) Number width of window {nr}
776wordcount() Dict get byte/char/word statistics
777writefile({object}, {fname} [, {flags}])
778 Number write |Blob| or |List| of lines to file
779xor({expr}, {expr}) Number bitwise XOR
780
781==============================================================================
7822. Details *builtin-function-details*
783
784Not all functions are here, some have been moved to a help file covering the
785specific functionality.
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200786Return type specifies the type for |Vim9-script|, see |vim9-types|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000787
788abs({expr}) *abs()*
789 Return the absolute value of {expr}. When {expr} evaluates to
790 a |Float| abs() returns a |Float|. When {expr} can be
791 converted to a |Number| abs() returns a |Number|. Otherwise
792 abs() gives an error message and returns -1.
793 Examples: >
794 echo abs(1.456)
795< 1.456 >
796 echo abs(-5.456)
797< 5.456 >
798 echo abs(-4)
799< 4
800
801 Can also be used as a |method|: >
802 Compute()->abs()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200803<
804 Return type: |Number| or |Float| depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000805
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000806
807acos({expr}) *acos()*
808 Return the arc cosine of {expr} measured in radians, as a
809 |Float| in the range of [0, pi].
810 {expr} must evaluate to a |Float| or a |Number| in the range
Bram Moolenaar016188f2022-06-06 20:52:59 +0100811 [-1, 1]. Otherwise acos() returns "nan".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000812 Examples: >
813 :echo acos(0)
814< 1.570796 >
815 :echo acos(-0.5)
816< 2.094395
817
818 Can also be used as a |method|: >
819 Compute()->acos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200820<
821 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000823
824add({object}, {expr}) *add()*
825 Append the item {expr} to |List| or |Blob| {object}. Returns
826 the resulting |List| or |Blob|. Examples: >
827 :let alist = add([1, 2, 3], item)
828 :call add(mylist, "woodstock")
829< Note that when {expr} is a |List| it is appended as a single
830 item. Use |extend()| to concatenate |Lists|.
831 When {object} is a |Blob| then {expr} must be a number.
832 Use |insert()| to add an item at another position.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100833 Returns 1 if {object} is not a |List| or a |Blob|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000834
835 Can also be used as a |method|: >
836 mylist->add(val1)->add(val2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200837<
838 Return type: list<{type}> (depending on the given |List|) or
839 |Blob|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000840
841
842and({expr}, {expr}) *and()*
843 Bitwise AND on the two arguments. The arguments are converted
844 to a number. A List, Dict or Float argument causes an error.
LemonBoy0f7a3e12022-05-26 12:10:37 +0100845 Also see `or()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000846 Example: >
847 :let flag = and(bits, 0x80)
848< Can also be used as a |method|: >
849 :let flag = bits->and(0x80)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200850<
851 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000852
853
854append({lnum}, {text}) *append()*
855 When {text} is a |List|: Append each item of the |List| as a
856 text line below line {lnum} in the current buffer.
857 Otherwise append {text} as one text line below line {lnum} in
858 the current buffer.
859 Any type of item is accepted and converted to a String.
860 {lnum} can be zero to insert a line before the first one.
861 {lnum} is used like with |getline()|.
862 Returns 1 for failure ({lnum} out of range or out of memory),
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000863 0 for success. When {text} is an empty list zero is returned,
864 no matter the value of {lnum}.
865 In |Vim9| script an invalid argument or negative number
866 results in an error. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000867 :let failed = append(line('$'), "# THE END")
868 :let failed = append(0, ["Chapter 1", "the beginning"])
869
870< Can also be used as a |method| after a List, the base is
871 passed as the second argument: >
872 mylist->append(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200873<
874 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000875
876
877appendbufline({buf}, {lnum}, {text}) *appendbufline()*
878 Like |append()| but append the text in buffer {buf}.
879
880 This function works only for loaded buffers. First call
881 |bufload()| if needed.
882
883 For the use of {buf}, see |bufname()|.
884
Bram Moolenaar8b6256f2021-12-28 11:24:49 +0000885 {lnum} is the line number to append below. Note that using
886 |line()| would use the current buffer, not the one appending
887 to. Use "$" to append at the end of the buffer. Other string
888 values are not supported.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000889
890 On success 0 is returned, on failure 1 is returned.
891 In |Vim9| script an error is given for an invalid {lnum}.
892
893 If {buf} is not a valid buffer or {lnum} is not valid, an
894 error message is given. Example: >
895 :let failed = appendbufline(13, 0, "# THE START")
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +0000896< However, when {text} is an empty list then no error is given
897 for an invalid {lnum}, since {lnum} isn't actually used.
898
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000899 Can also be used as a |method| after a List, the base is
900 passed as the second argument: >
901 mylist->appendbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200902<
903 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000904
905
906argc([{winid}]) *argc()*
907 The result is the number of files in the argument list. See
908 |arglist|.
909 If {winid} is not supplied, the argument list of the current
910 window is used.
911 If {winid} is -1, the global argument list is used.
912 Otherwise {winid} specifies the window of which the argument
913 list is used: either the window number or the window ID.
914 Returns -1 if the {winid} argument is invalid.
915
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200916 Return type: |Number|
917
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000918 *argidx()*
919argidx() The result is the current index in the argument list. 0 is
920 the first file. argc() - 1 is the last one. See |arglist|.
921
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200922 Return type: |Number|
923
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000924 *arglistid()*
925arglistid([{winnr} [, {tabnr}]])
926 Return the argument list ID. This is a number which
927 identifies the argument list being used. Zero is used for the
928 global argument list. See |arglist|.
929 Returns -1 if the arguments are invalid.
930
931 Without arguments use the current window.
932 With {winnr} only use this window in the current tab page.
933 With {winnr} and {tabnr} use the window in the specified tab
934 page.
935 {winnr} can be the window number or the |window-ID|.
936
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200937 Return type: |Number|
938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000939 *argv()*
940argv([{nr} [, {winid}]])
941 The result is the {nr}th file in the argument list. See
942 |arglist|. "argv(0)" is the first one. Example: >
943 :let i = 0
944 :while i < argc()
945 : let f = escape(fnameescape(argv(i)), '.')
Bram Moolenaarc51cf032022-02-26 12:25:45 +0000946 : exe 'amenu Arg.' .. f .. ' :e ' .. f .. '<CR>'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000947 : let i = i + 1
948 :endwhile
949< Without the {nr} argument, or when {nr} is -1, a |List| with
950 the whole |arglist| is returned.
951
952 The {winid} argument specifies the window ID, see |argc()|.
953 For the Vim command line arguments see |v:argv|.
954
Bram Moolenaar016188f2022-06-06 20:52:59 +0100955 Returns an empty string if {nr}th argument is not present in
956 the argument list. Returns an empty List if the {winid}
957 argument is invalid.
958
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200959 Return type: |String|
960
961
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000962asin({expr}) *asin()*
963 Return the arc sine of {expr} measured in radians, as a |Float|
964 in the range of [-pi/2, pi/2].
965 {expr} must evaluate to a |Float| or a |Number| in the range
966 [-1, 1].
Bram Moolenaar016188f2022-06-06 20:52:59 +0100967 Returns "nan" if {expr} is outside the range [-1, 1]. Returns
968 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000969 Examples: >
970 :echo asin(0.8)
971< 0.927295 >
972 :echo asin(-0.5)
973< -0.523599
974
975 Can also be used as a |method|: >
976 Compute()->asin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200977<
978 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000979
980assert_ functions are documented here: |assert-functions-details|
981
982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000983atan({expr}) *atan()*
984 Return the principal value of the arc tangent of {expr}, in
985 the range [-pi/2, +pi/2] radians, as a |Float|.
986 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +0100987 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000988 Examples: >
989 :echo atan(100)
990< 1.560797 >
991 :echo atan(-4.01)
992< -1.326405
993
994 Can also be used as a |method|: >
995 Compute()->atan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +0200996<
997 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +0000998
999
1000atan2({expr1}, {expr2}) *atan2()*
1001 Return the arc tangent of {expr1} / {expr2}, measured in
1002 radians, as a |Float| in the range [-pi, pi].
1003 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001004 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
1005 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001006 Examples: >
1007 :echo atan2(-1, 1)
1008< -0.785398 >
1009 :echo atan2(1, -1)
1010< 2.356194
1011
1012 Can also be used as a |method|: >
1013 Compute()->atan2(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001014<
1015 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001016
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001017
1018autocmd_add({acmds}) *autocmd_add()*
1019 Adds a List of autocmds and autocmd groups.
1020
1021 The {acmds} argument is a List where each item is a Dict with
1022 the following optional items:
1023 bufnr buffer number to add a buffer-local autocmd.
1024 If this item is specified, then the "pattern"
1025 item is ignored.
1026 cmd Ex command to execute for this autocmd event
1027 event autocmd event name. Refer to |autocmd-events|.
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001028 This can be either a String with a single
1029 event name or a List of event names.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001030 group autocmd group name. Refer to |autocmd-groups|.
1031 If this group doesn't exist then it is
1032 created. If not specified or empty, then the
1033 default group is used.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001034 nested boolean flag, set to v:true to add a nested
1035 autocmd. Refer to |autocmd-nested|.
LemonBoy0f7a3e12022-05-26 12:10:37 +01001036 once boolean flag, set to v:true to add an autocmd
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001037 which executes only once. Refer to
1038 |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001039 pattern autocmd pattern string. Refer to
1040 |autocmd-patterns|. If "bufnr" item is
Yegappan Lakshmanane0ff3a72022-05-27 18:05:33 +01001041 present, then this item is ignored. This can
1042 be a String with a single pattern or a List of
1043 patterns.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001044 replace boolean flag, set to v:true to remove all the
1045 commands associated with the specified autocmd
1046 event and group and add the {cmd}. This is
1047 useful to avoid adding the same command
LemonBoy0f7a3e12022-05-26 12:10:37 +01001048 multiple times for an autocmd event in a group.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001049
1050 Returns v:true on success and v:false on failure.
1051 Examples: >
1052 " Create a buffer-local autocmd for buffer 5
1053 let acmd = {}
1054 let acmd.group = 'MyGroup'
1055 let acmd.event = 'BufEnter'
1056 let acmd.bufnr = 5
1057 let acmd.cmd = 'call BufEnterFunc()'
1058 call autocmd_add([acmd])
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00001059<
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001060 Can also be used as a |method|: >
1061 GetAutocmdList()->autocmd_add()
1062<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001063 Return type: |vim9-boolean|
1064
1065
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001066autocmd_delete({acmds}) *autocmd_delete()*
1067 Deletes a List of autocmds and autocmd groups.
1068
1069 The {acmds} argument is a List where each item is a Dict with
1070 the following optional items:
1071 bufnr buffer number to delete a buffer-local autocmd.
1072 If this item is specified, then the "pattern"
1073 item is ignored.
1074 cmd Ex command for this autocmd event
1075 event autocmd event name. Refer to |autocmd-events|.
1076 If '*' then all the autocmd events in this
1077 group are deleted.
1078 group autocmd group name. Refer to |autocmd-groups|.
1079 If not specified or empty, then the default
1080 group is used.
1081 nested set to v:true for a nested autocmd.
1082 Refer to |autocmd-nested|.
1083 once set to v:true for an autocmd which executes
1084 only once. Refer to |autocmd-once|.
1085 pattern autocmd pattern string. Refer to
1086 |autocmd-patterns|. If "bufnr" item is
1087 present, then this item is ignored.
1088
1089 If only {group} is specified in a {acmds} entry and {event},
1090 {pattern} and {cmd} are not specified, then that autocmd group
1091 is deleted.
1092
Bram Moolenaar016188f2022-06-06 20:52:59 +01001093 Returns |v:true| on success and |v:false| on failure.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001094 Examples: >
1095 " :autocmd! BufLeave *.vim
1096 let acmd = #{event: 'BufLeave', pattern: '*.vim'}
1097 call autocmd_delete([acmd]})
1098 " :autocmd! MyGroup1 BufLeave
1099 let acmd = #{group: 'MyGroup1', event: 'BufLeave'}
1100 call autocmd_delete([acmd])
1101 " :autocmd! MyGroup2 BufEnter *.c
1102 let acmd = #{group: 'MyGroup2', event: 'BufEnter',
1103 \ pattern: '*.c'}
1104 " :autocmd! MyGroup2 * *.c
1105 let acmd = #{group: 'MyGroup2', event: '*',
1106 \ pattern: '*.c'}
1107 call autocmd_delete([acmd])
1108 " :autocmd! MyGroup3
1109 let acmd = #{group: 'MyGroup3'}
1110 call autocmd_delete([acmd])
1111<
1112 Can also be used as a |method|: >
1113 GetAutocmdList()->autocmd_delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001114<
1115 Return type: |vim9-boolean|
1116
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001117
1118autocmd_get([{opts}]) *autocmd_get()*
1119 Returns a |List| of autocmds. If {opts} is not supplied, then
1120 returns the autocmds for all the events in all the groups.
1121
1122 The optional {opts} Dict argument supports the following
1123 items:
1124 group Autocmd group name. If specified, returns only
1125 the autocmds defined in this group. If the
1126 specified group doesn't exist, results in an
1127 error message. If set to an empty string,
1128 then the default autocmd group is used.
1129 event Autocmd event name. If specified, returns only
1130 the autocmds defined for this event. If set
1131 to "*", then returns autocmds for all the
1132 events. If the specified event doesn't exist,
1133 results in an error message.
1134 pattern Autocmd pattern. If specified, returns only
1135 the autocmds defined for this pattern.
1136 A combination of the above three times can be supplied in
1137 {opts}.
1138
1139 Each Dict in the returned List contains the following items:
1140 bufnr For buffer-local autocmds, buffer number where
1141 the autocmd is defined.
1142 cmd Command executed for this autocmd.
1143 event Autocmd event name.
1144 group Autocmd group name.
Yegappan Lakshmanan971f6822022-05-24 11:40:11 +01001145 nested Boolean flag, set to v:true for a nested
1146 autocmd. See |autocmd-nested|.
1147 once Boolean flag, set to v:true, if the autocmd
1148 will be executed only once. See |autocmd-once|.
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001149 pattern Autocmd pattern. For a buffer-local
1150 autocmd, this will be of the form "<buffer=n>".
1151 If there are multiple commands for an autocmd event in a
1152 group, then separate items are returned for each command.
1153
Bram Moolenaar016188f2022-06-06 20:52:59 +01001154 Returns an empty List if an autocmd with the specified group
1155 or event or pattern is not found.
1156
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +01001157 Examples: >
1158 " :autocmd MyGroup
1159 echo autocmd_get(#{group: 'Mygroup'})
1160 " :autocmd G BufUnload
1161 echo autocmd_get(#{group: 'G', event: 'BufUnload'})
1162 " :autocmd G * *.ts
1163 let acmd = #{group: 'G', event: '*', pattern: '*.ts'}
1164 echo autocmd_get(acmd)
1165 " :autocmd Syntax
1166 echo autocmd_get(#{event: 'Syntax'})
1167 " :autocmd G BufEnter *.ts
1168 let acmd = #{group: 'G', event: 'BufEnter',
1169 \ pattern: '*.ts'}
1170 echo autocmd_get(acmd)
1171<
1172 Can also be used as a |method|: >
1173 Getopts()->autocmd_get()
1174<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001175 Return type: list<dict<any>>
1176
1177
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001178balloon_gettext() *balloon_gettext()*
1179 Return the current text in the balloon. Only for the string,
Bram Moolenaar016188f2022-06-06 20:52:59 +01001180 not used for the List. Returns an empty string if balloon
1181 is not present.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001182
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001183 Return type: |String|
1184
1185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001186balloon_show({expr}) *balloon_show()*
1187 Show {expr} inside the balloon. For the GUI {expr} is used as
1188 a string. For a terminal {expr} can be a list, which contains
1189 the lines of the balloon. If {expr} is not a list it will be
1190 split with |balloon_split()|.
1191 If {expr} is an empty string any existing balloon is removed.
1192
1193 Example: >
1194 func GetBalloonContent()
1195 " ... initiate getting the content
1196 return ''
1197 endfunc
1198 set balloonexpr=GetBalloonContent()
1199
1200 func BalloonCallback(result)
1201 call balloon_show(a:result)
1202 endfunc
1203< Can also be used as a |method|: >
1204 GetText()->balloon_show()
1205<
1206 The intended use is that fetching the content of the balloon
1207 is initiated from 'balloonexpr'. It will invoke an
1208 asynchronous method, in which a callback invokes
1209 balloon_show(). The 'balloonexpr' itself can return an
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001210 empty string or a placeholder, e.g. "loading...".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001211
Bram Moolenaar069a7d52022-06-27 22:16:08 +01001212 When showing a balloon is not possible then nothing happens,
1213 no error message is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001214 {only available when compiled with the |+balloon_eval| or
1215 |+balloon_eval_term| feature}
1216
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001217 Return type: |Number|
1218
1219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001220balloon_split({msg}) *balloon_split()*
1221 Split String {msg} into lines to be displayed in a balloon.
1222 The splits are made for the current window size and optimize
1223 to show debugger output.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001224 Returns a |List| with the split lines. Returns an empty List
1225 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001226 Can also be used as a |method|: >
1227 GetText()->balloon_split()->balloon_show()
1228
1229< {only available when compiled with the |+balloon_eval_term|
1230 feature}
1231
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001232 Return type: list<any> or list<string>
1233
h-easte80f3452025-01-02 10:40:29 +01001234base64_decode({string}) *base64_decode()*
1235 Return a Blob containing the bytes decoded from the base64
1236 encoded characters in {string}.
1237
1238 The {string} argument should contain only base64-encoded
1239 characters and should have a length that is a multiple of 4.
1240
1241 Returns an empty blob on error.
1242
1243 Examples: >
1244 " Write the decoded contents to a binary file
1245 call writefile(base64_decode(s), 'tools.bmp')
1246 " Decode a base64-encoded string
1247 echo list2str(blob2list(base64_decode(encodedstr)))
1248<
1249 Can also be used as a |method|: >
1250 GetEncodedString()->base64_decode()
1251<
1252 Return type: |Blob|
1253
1254
1255base64_encode({blob}) *base64_encode()*
1256 Return a base64-encoded String representing the bytes in
1257 {blob}. The base64 alphabet defined in RFC 4648 is used.
1258
1259 Examples: >
1260 " Encode the contents of a binary file
1261 echo base64_encode(readblob('somefile.bin'))
1262 " Encode a string
1263 echo base64_encode(list2blob(str2list(somestr)))
1264<
1265 Can also be used as a |method|: >
1266 GetBinaryData()->base64_encode()
1267<
1268 Return type: |String|
1269
1270
Christ van Willegence0ef912024-06-20 23:41:59 +02001271bindtextdomain({package}, {path}) *bindtextdomain()*
1272 Bind a specific {package} to a {path} so that the
1273 |gettext()| function can be used to get language-specific
1274 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001275 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001276
Christ van Willegen8252ef12024-07-11 21:36:21 +02001277 Returns v:true on success and v:false on failure (out of
1278 memory).
1279
1280 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282blob2list({blob}) *blob2list()*
1283 Return a List containing the number value of each byte in Blob
1284 {blob}. Examples: >
1285 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1286 blob2list(0z) returns []
1287< Returns an empty List on error. |list2blob()| does the
1288 opposite.
1289
1290 Can also be used as a |method|: >
1291 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001292<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001293 Return type: list<any> or list<number>
1294
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001295
1296blob2str({blob} [, {options}]) *blob2str()*
1297 Return a String in the current 'encoding' by converting the
1298 bytes in {blob} into characters.
1299
1300 If {options} is not supplied, the current 'encoding' value is
1301 used to decode the bytes in {blob}.
1302
1303 The argument {options} is a |Dict| and supports the following
1304 items:
1305 encoding Decode the bytes in {blob} using this
1306 encoding. The value is a |String|. See
1307 |encoding-names| for the supported values.
1308 *E1515*
1309 An error is given and an empty string is returned if
1310 an invalid byte sequence is encountered in {blob},
1311
1312 Returns an empty String if blob is empty.
1313
1314 See also |str2blob()|
1315
1316 Examples: >
1317 blob2str(0z6162) returns "ab"
1318 blob2str(0zC2ABC2BB) returns "«»"
1319 blob2str(0zABBB, {'encoding': 'latin1'}) returns "«»"
1320<
1321 Can also be used as a |method|: >
1322 GetBlob()->blob2str()
1323<
1324 Return type: |String|
1325
1326
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001327 *browse()*
1328browse({save}, {title}, {initdir}, {default})
1329 Put up a file requester. This only works when "has("browse")"
1330 returns |TRUE| (only in some GUI versions).
1331 The input fields are:
1332 {save} when |TRUE|, select file to write
1333 {title} title for the requester
1334 {initdir} directory to start browsing in
1335 {default} default file name
1336 An empty string is returned when the "Cancel" button is hit,
1337 something went wrong, or browsing is not possible.
1338
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001339 Return type: |String|
1340
1341
1342browsedir({title}, {initdir}) *browsedir()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001343 Put up a directory requester. This only works when
1344 "has("browse")" returns |TRUE| (only in some GUI versions).
1345 On systems where a directory browser is not supported a file
1346 browser is used. In that case: select a file in the directory
1347 to be used.
1348 The input fields are:
1349 {title} title for the requester
1350 {initdir} directory to start browsing in
1351 When the "Cancel" button is hit, something went wrong, or
1352 browsing is not possible, an empty string is returned.
1353
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001354 Return type: |String|
1355
1356
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001357bufadd({name}) *bufadd()*
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001358 Add a buffer to the buffer list with name {name} (must be a
1359 String).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001360 If a buffer for file {name} already exists, return that buffer
1361 number. Otherwise return the buffer number of the newly
1362 created buffer. When {name} is an empty string then a new
1363 buffer is always created.
1364 The buffer will not have 'buflisted' set and not be loaded
1365 yet. To add some text to the buffer use this: >
1366 let bufnr = bufadd('someName')
1367 call bufload(bufnr)
1368 call setbufline(bufnr, 1, ['some', 'text'])
Bram Moolenaar016188f2022-06-06 20:52:59 +01001369< Returns 0 on error.
1370 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001371 let bufnr = 'somename'->bufadd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001372<
1373 Return type: |Number|
1374
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001375
1376bufexists({buf}) *bufexists()*
1377 The result is a Number, which is |TRUE| if a buffer called
1378 {buf} exists.
1379 If the {buf} argument is a number, buffer numbers are used.
1380 Number zero is the alternate buffer for the current window.
1381
1382 If the {buf} argument is a string it must match a buffer name
1383 exactly. The name can be:
1384 - Relative to the current directory.
1385 - A full path.
1386 - The name of a buffer with 'buftype' set to "nofile".
1387 - A URL name.
1388 Unlisted buffers will be found.
1389 Note that help files are listed by their short name in the
1390 output of |:buffers|, but bufexists() requires using their
1391 long name to be able to find them.
1392 bufexists() may report a buffer exists, but to use the name
1393 with a |:buffer| command you may need to use |expand()|. Esp
1394 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
1395 Use "bufexists(0)" to test for the existence of an alternate
1396 file name.
1397
1398 Can also be used as a |method|: >
1399 let exists = 'somename'->bufexists()
1400<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001401 Return type: |Number|
1402
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001403 Obsolete name: buffer_exists(). *buffer_exists()*
1404
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001405
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001406buflisted({buf}) *buflisted()*
1407 The result is a Number, which is |TRUE| if a buffer called
1408 {buf} exists and is listed (has the 'buflisted' option set).
1409 The {buf} argument is used like with |bufexists()|.
1410
1411 Can also be used as a |method|: >
1412 let listed = 'somename'->buflisted()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001413<
1414 Return type: |Number|
1415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001416
1417bufload({buf}) *bufload()*
1418 Ensure the buffer {buf} is loaded. When the buffer name
1419 refers to an existing file then the file is read. Otherwise
1420 the buffer will be empty. If the buffer was already loaded
Bram Moolenaar2eddbac2022-08-25 12:45:21 +01001421 then there is no change. If the buffer is not related to a
Daniel Steinbergc2bd2052023-08-09 12:10:59 -04001422 file then no file is read (e.g., when 'buftype' is "nofile").
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001423 If there is an existing swap file for the file of the buffer,
1424 there will be no dialog, the buffer will be loaded anyway.
1425 The {buf} argument is used like with |bufexists()|.
1426
1427 Can also be used as a |method|: >
1428 eval 'somename'->bufload()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001429<
1430 Return type: |Number|
1431
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001432
1433bufloaded({buf}) *bufloaded()*
1434 The result is a Number, which is |TRUE| if a buffer called
1435 {buf} exists and is loaded (shown in a window or hidden).
1436 The {buf} argument is used like with |bufexists()|.
1437
1438 Can also be used as a |method|: >
1439 let loaded = 'somename'->bufloaded()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001440<
1441 Return type: |Number|
1442
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001443
1444bufname([{buf}]) *bufname()*
1445 The result is the name of a buffer. Mostly as it is displayed
1446 by the `:ls` command, but not using special names such as
1447 "[No Name]".
1448 If {buf} is omitted the current buffer is used.
1449 If {buf} is a Number, that buffer number's name is given.
1450 Number zero is the alternate buffer for the current window.
1451 If {buf} is a String, it is used as a |file-pattern| to match
1452 with the buffer names. This is always done like 'magic' is
1453 set and 'cpoptions' is empty. When there is more than one
1454 match an empty string is returned.
1455 "" or "%" can be used for the current buffer, "#" for the
1456 alternate buffer.
1457 A full match is preferred, otherwise a match at the start, end
1458 or middle of the buffer name is accepted. If you only want a
1459 full match then put "^" at the start and "$" at the end of the
1460 pattern.
1461 Listed buffers are found first. If there is a single match
1462 with a listed buffer, that one is returned. Next unlisted
1463 buffers are searched for.
1464 If the {buf} is a String, but you want to use it as a buffer
1465 number, force it to be a Number by adding zero to it: >
1466 :echo bufname("3" + 0)
1467< Can also be used as a |method|: >
1468 echo bufnr->bufname()
1469
1470< If the buffer doesn't exist, or doesn't have a name, an empty
1471 string is returned. >
1472 bufname("#") alternate buffer name
1473 bufname(3) name of buffer 3
1474 bufname("%") name of current buffer
1475 bufname("file2") name of buffer where "file2" matches.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001476<
1477 Return type: |String|
1478 *buffer_name()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001479 Obsolete name: buffer_name().
1480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001481
1482bufnr([{buf} [, {create}]]) *bufnr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001483 The result is the number of a buffer, as it is displayed by
1484 the `:ls` command. For the use of {buf}, see |bufname()|
1485 above.
1486
1487 If the buffer doesn't exist, -1 is returned. Or, if the
1488 {create} argument is present and TRUE, a new, unlisted,
1489 buffer is created and its number is returned. Example: >
1490 let newbuf = bufnr('Scratch001', 1)
1491< Using an empty name uses the current buffer. To create a new
1492 buffer with an empty name use |bufadd()|.
1493
1494 bufnr("$") is the last buffer: >
1495 :let last_buffer = bufnr("$")
1496< The result is a Number, which is the highest buffer number
1497 of existing buffers. Note that not all buffers with a smaller
1498 number necessarily exist, because ":bwipeout" may have removed
1499 them. Use bufexists() to test for the existence of a buffer.
1500
1501 Can also be used as a |method|: >
1502 echo bufref->bufnr()
1503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001504 Return type: |Number|
1505
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001506 Obsolete name: buffer_number(). *buffer_number()*
1507 *last_buffer_nr()*
1508 Obsolete name for bufnr("$"): last_buffer_nr().
1509
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001511bufwinid({buf}) *bufwinid()*
1512 The result is a Number, which is the |window-ID| of the first
1513 window associated with buffer {buf}. For the use of {buf},
1514 see |bufname()| above. If buffer {buf} doesn't exist or
1515 there is no such window, -1 is returned. Example: >
1516
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001517 echo "A window containing buffer 1 is " .. (bufwinid(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001518<
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001519 Only deals with the current tab page. See |win_findbuf()| for
1520 finding more.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001521
1522 Can also be used as a |method|: >
1523 FindBuffer()->bufwinid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001524<
1525 Return type: |Number|
1526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001527
1528bufwinnr({buf}) *bufwinnr()*
1529 Like |bufwinid()| but return the window number instead of the
1530 |window-ID|.
1531 If buffer {buf} doesn't exist or there is no such window, -1
1532 is returned. Example: >
1533
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001534 echo "A window containing buffer 1 is " .. (bufwinnr(1))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001535
1536< The number can be used with |CTRL-W_w| and ":wincmd w"
1537 |:wincmd|.
1538
1539 Can also be used as a |method|: >
1540 FindBuffer()->bufwinnr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001541<
1542 Return type: |Number|
1543
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001544
1545byte2line({byte}) *byte2line()*
1546 Return the line number that contains the character at byte
1547 count {byte} in the current buffer. This includes the
1548 end-of-line character, depending on the 'fileformat' option
1549 for the current buffer. The first character has byte count
1550 one.
1551 Also see |line2byte()|, |go| and |:goto|.
1552
Bram Moolenaar016188f2022-06-06 20:52:59 +01001553 Returns -1 if the {byte} value is invalid.
1554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001555 Can also be used as a |method|: >
1556 GetOffset()->byte2line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001557<
1558 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001559
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001560 {not available when compiled without the |+byte_offset|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001561 feature}
1562
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001563
Christian Brabandt67672ef2023-04-24 21:09:54 +01001564byteidx({expr}, {nr} [, {utf16}]) *byteidx()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001565 Return byte index of the {nr}'th character in the String
1566 {expr}. Use zero for the first character, it then returns
1567 zero.
1568 If there are no multibyte characters the returned value is
1569 equal to {nr}.
1570 Composing characters are not counted separately, their byte
1571 length is added to the preceding base character. See
1572 |byteidxcomp()| below for counting composing characters
1573 separately.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001574 When {utf16} is present and TRUE, {nr} is used as the UTF-16
1575 index in the String {expr} instead of as the character index.
1576 The UTF-16 index is the index in the string when it is encoded
1577 with 16-bit words. If the specified UTF-16 index is in the
1578 middle of a character (e.g. in a 4-byte character), then the
1579 byte index of the first byte in the character is returned.
1580 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001581 Example : >
1582 echo matchstr(str, ".", byteidx(str, 3))
1583< will display the fourth character. Another way to do the
1584 same: >
1585 let s = strpart(str, byteidx(str, 3))
1586 echo strpart(s, 0, byteidx(s, 1))
1587< Also see |strgetchar()| and |strcharpart()|.
1588
1589 If there are less than {nr} characters -1 is returned.
1590 If there are exactly {nr} characters the length of the string
1591 in bytes is returned.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001592 See |charidx()| and |utf16idx()| for getting the character and
1593 UTF-16 index respectively from the byte index.
1594 Examples: >
1595 echo byteidx('a😊😊', 2) returns 5
1596 echo byteidx('a😊😊', 2, 1) returns 1
1597 echo byteidx('a😊😊', 3, 1) returns 5
1598<
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001599 Can also be used as a |method|: >
1600 GetName()->byteidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001601<
1602 Return type: |Number|
1603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001604
Christian Brabandt67672ef2023-04-24 21:09:54 +01001605byteidxcomp({expr}, {nr} [, {utf16}]) *byteidxcomp()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001606 Like byteidx(), except that a composing character is counted
1607 as a separate character. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001608 let s = 'e' .. nr2char(0x301)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001609 echo byteidx(s, 1)
1610 echo byteidxcomp(s, 1)
1611 echo byteidxcomp(s, 2)
1612< The first and third echo result in 3 ('e' plus composing
1613 character is 3 bytes), the second echo results in 1 ('e' is
1614 one byte).
1615 Only works differently from byteidx() when 'encoding' is set
1616 to a Unicode encoding.
1617
1618 Can also be used as a |method|: >
1619 GetName()->byteidxcomp(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001620<
1621 Return type: |Number|
1622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001623
1624call({func}, {arglist} [, {dict}]) *call()* *E699*
1625 Call function {func} with the items in |List| {arglist} as
1626 arguments.
1627 {func} can either be a |Funcref| or the name of a function.
1628 a:firstline and a:lastline are set to the cursor line.
1629 Returns the return value of the called function.
1630 {dict} is for functions with the "dict" attribute. It will be
1631 used to set the local variable "self". |Dictionary-function|
1632
1633 Can also be used as a |method|: >
1634 GetFunc()->call([arg, arg], dict)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001635<
1636 Return type: any, depending on {func}
1637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001638
1639ceil({expr}) *ceil()*
1640 Return the smallest integral value greater than or equal to
1641 {expr} as a |Float| (round up).
1642 {expr} must evaluate to a |Float| or a |Number|.
1643 Examples: >
1644 echo ceil(1.456)
1645< 2.0 >
1646 echo ceil(-5.456)
1647< -5.0 >
1648 echo ceil(4.0)
1649< 4.0
1650
Bram Moolenaar016188f2022-06-06 20:52:59 +01001651 Returns 0.0 if {expr} is not a |Float| or a |Number|.
1652
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001653 Can also be used as a |method|: >
1654 Compute()->ceil()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001655<
1656 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001657
1658
1659ch_ functions are documented here: |channel-functions-details|
1660
1661
1662changenr() *changenr()*
1663 Return the number of the most recent change. This is the same
1664 number as what is displayed with |:undolist| and can be used
1665 with the |:undo| command.
1666 When a change was made it is the number of that change. After
1667 redo it is the number of the redone change. After undo it is
1668 one less than the number of the undone change.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001669 Returns 0 if the undo list is empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001670
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001671 Return type: |Number|
1672
1673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001674char2nr({string} [, {utf8}]) *char2nr()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01001675 Return Number value of the first char in {string}.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001676 Examples: >
1677 char2nr(" ") returns 32
1678 char2nr("ABC") returns 65
1679< When {utf8} is omitted or zero, the current 'encoding' is used.
1680 Example for "utf-8": >
1681 char2nr("á") returns 225
1682 char2nr("á"[0]) returns 195
1683< When {utf8} is TRUE, always treat as UTF-8 characters.
1684 A combining character is a separate character.
1685 |nr2char()| does the opposite.
1686 To turn a string into a list of character numbers: >
1687 let str = "ABC"
1688 let list = map(split(str, '\zs'), {_, val -> char2nr(val)})
1689< Result: [65, 66, 67]
1690
Bram Moolenaar016188f2022-06-06 20:52:59 +01001691 Returns 0 if {string} is not a |String|.
1692
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001693 Can also be used as a |method|: >
1694 GetChar()->char2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001695<
1696 Return type: |Number|
1697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001699charclass({string}) *charclass()*
1700 Return the character class of the first character in {string}.
1701 The character class is one of:
1702 0 blank
1703 1 punctuation
Christian Brabandtb5e7da12024-11-01 09:33:00 +01001704 2 word character (depends on 'iskeyword')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001705 3 emoji
1706 other specific Unicode class
1707 The class is used in patterns and word motions.
Bram Moolenaar016188f2022-06-06 20:52:59 +01001708 Returns 0 if {string} is not a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001709
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001710 Return type: |Number|
1711
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001712
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001713charcol({expr} [, {winid}]) *charcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001714 Same as |col()| but returns the character index of the column
1715 position given with {expr} instead of the byte position.
1716
1717 Example:
1718 With the cursor on '세' in line 5 with text "여보세요": >
1719 charcol('.') returns 3
1720 col('.') returns 7
1721
1722< Can also be used as a |method|: >
1723 GetPos()->col()
1724<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001725 Return type: |Number|
1726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001727 *charidx()*
Christian Brabandt67672ef2023-04-24 21:09:54 +01001728charidx({string}, {idx} [, {countcc} [, {utf16}]])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001729 Return the character index of the byte at {idx} in {string}.
1730 The index of the first character is zero.
1731 If there are no multibyte characters the returned value is
1732 equal to {idx}.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001733
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001734 When {countcc} is omitted or |FALSE|, then composing characters
Christian Brabandt67672ef2023-04-24 21:09:54 +01001735 are not counted separately, their byte length is added to the
1736 preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001737 When {countcc} is |TRUE|, then composing characters are
1738 counted as separate characters.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001739
1740 When {utf16} is present and TRUE, {idx} is used as the UTF-16
1741 index in the String {expr} instead of as the byte index.
1742
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +01001743 Returns -1 if the arguments are invalid or if there are less
1744 than {idx} bytes. If there are exactly {idx} bytes the length
1745 of the string in characters is returned.
1746
1747 An error is given and -1 is returned if the first argument is
1748 not a string, the second argument is not a number or when the
1749 third argument is present and is not zero or one.
Christian Brabandt67672ef2023-04-24 21:09:54 +01001750
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001751 See |byteidx()| and |byteidxcomp()| for getting the byte index
Christian Brabandt67672ef2023-04-24 21:09:54 +01001752 from the character index and |utf16idx()| for getting the
1753 UTF-16 index from the character index.
1754 Refer to |string-offset-encoding| for more information.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001755 Examples: >
1756 echo charidx('áb́ć', 3) returns 1
1757 echo charidx('áb́ć', 6, 1) returns 4
1758 echo charidx('áb́ć', 16) returns -1
Christian Brabandt67672ef2023-04-24 21:09:54 +01001759 echo charidx('a😊😊', 4, 0, 1) returns 2
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001760<
1761 Can also be used as a |method|: >
1762 GetName()->charidx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001763<
1764 Return type: |Number|
1765
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001766
1767chdir({dir}) *chdir()*
1768 Change the current working directory to {dir}. The scope of
1769 the directory change depends on the directory of the current
1770 window:
1771 - If the current window has a window-local directory
1772 (|:lcd|), then changes the window local directory.
1773 - Otherwise, if the current tabpage has a local
1774 directory (|:tcd|) then changes the tabpage local
1775 directory.
1776 - Otherwise, changes the global directory.
1777 {dir} must be a String.
1778 If successful, returns the previous working directory. Pass
1779 this to another chdir() to restore the directory.
1780 On failure, returns an empty string.
1781
1782 Example: >
1783 let save_dir = chdir(newdir)
1784 if save_dir != ""
1785 " ... do some work
1786 call chdir(save_dir)
1787 endif
1788
1789< Can also be used as a |method|: >
1790 GetDir()->chdir()
1791<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001792 Return type: |String|
1793
1794
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001795cindent({lnum}) *cindent()*
1796 Get the amount of indent for line {lnum} according the C
1797 indenting rules, as with 'cindent'.
1798 The indent is counted in spaces, the value of 'tabstop' is
1799 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01001800 When {lnum} is invalid -1 is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001801 See |C-indenting|.
1802
1803 Can also be used as a |method|: >
1804 GetLnum()->cindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001805<
1806 Return type: |Number|
1807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001808
1809clearmatches([{win}]) *clearmatches()*
1810 Clears all matches previously defined for the current window
1811 by |matchadd()| and the |:match| commands.
1812 If {win} is specified, use the window with this number or
1813 window ID instead of the current window.
1814
1815 Can also be used as a |method|: >
1816 GetWin()->clearmatches()
1817<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001818 Return type: |Number|
1819
1820
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001821col({expr} [, {winid}]) *col()*
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001822 The result is a Number, which is the byte index of the column
zeertzjq02f3eba2024-06-12 20:45:24 +02001823 position given with {expr}.
1824 For accepted positions see |getpos()|.
zeertzjqd353d272024-06-13 23:00:25 +08001825 When {expr} is "$", it means the end of the cursor line, so
1826 the result is the number of bytes in the cursor line plus one.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001827 Additionally {expr} can be [lnum, col]: a |List| with the line
1828 and column number. Most useful when the column is "$", to get
1829 the last column of a specific line. When "lnum" or "col" is
1830 out of range then col() returns zero.
zeertzjq02f3eba2024-06-12 20:45:24 +02001831
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001832 With the optional {winid} argument the values are obtained for
1833 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02001834
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001835 To get the line number use |line()|. To get both use
1836 |getpos()|.
1837 For the screen column position use |virtcol()|. For the
1838 character position use |charcol()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02001839
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001840 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +02001841
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001842 Examples: >
1843 col(".") column of cursor
1844 col("$") length of cursor line plus one
1845 col("'t") column of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00001846 col("'" .. markname) column of mark markname
zeertzjq02f3eba2024-06-12 20:45:24 +02001847<
1848 The first column is 1. Returns 0 if {expr} is invalid or when
Yegappan Lakshmanan4c8d2f02022-11-12 16:07:47 +00001849 the window with ID {winid} is not found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001850 For an uppercase mark the column may actually be in another
1851 buffer.
1852 For the cursor position, when 'virtualedit' is active, the
1853 column is one higher if the cursor is after the end of the
Bram Moolenaar6ebe4f92022-10-28 20:47:54 +01001854 line. Also, when using a <Cmd> mapping the cursor isn't
1855 moved, this can be used to obtain the column in Insert mode: >
Bram Moolenaar76db9e02022-11-09 21:21:04 +00001856 :imap <F2> <Cmd>echowin col(".")<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001857
1858< Can also be used as a |method|: >
1859 GetPos()->col()
1860<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001861 Return type: |Number|
1862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001863
1864complete({startcol}, {matches}) *complete()* *E785*
1865 Set the matches for Insert mode completion.
1866 Can only be used in Insert mode. You need to use a mapping
1867 with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O
1868 or with an expression mapping.
1869 {startcol} is the byte offset in the line where the completed
1870 text start. The text up to the cursor is the original text
1871 that will be replaced by the matches. Use col('.') for an
1872 empty string. "col('.') - 1" will replace one character by a
1873 match.
1874 {matches} must be a |List|. Each |List| item is one match.
1875 See |complete-items| for the kind of items that are possible.
1876 "longest" in 'completeopt' is ignored.
1877 Note that the after calling this function you need to avoid
1878 inserting anything that would cause completion to stop.
1879 The match can be selected with CTRL-N and CTRL-P as usual with
1880 Insert mode completion. The popup menu will appear if
1881 specified, see |ins-completion-menu|.
1882 Example: >
1883 inoremap <F5> <C-R>=ListMonths()<CR>
1884
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01001885 func ListMonths()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001886 call complete(col('.'), ['January', 'February', 'March',
1887 \ 'April', 'May', 'June', 'July', 'August', 'September',
1888 \ 'October', 'November', 'December'])
1889 return ''
1890 endfunc
1891< This isn't very useful, but it shows how it works. Note that
1892 an empty string is returned to avoid a zero being inserted.
1893
1894 Can also be used as a |method|, the base is passed as the
1895 second argument: >
1896 GetMatches()->complete(col('.'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001897<
1898 Return type: |Number|
1899
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001900
1901complete_add({expr}) *complete_add()*
1902 Add {expr} to the list of matches. Only to be used by the
1903 function specified with the 'completefunc' option.
1904 Returns 0 for failure (empty string or out of memory),
1905 1 when the match was added, 2 when the match was already in
1906 the list.
1907 See |complete-functions| for an explanation of {expr}. It is
1908 the same as one item in the list that 'omnifunc' would return.
1909
1910 Can also be used as a |method|: >
1911 GetMoreMatches()->complete_add()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001912<
1913 Return type: |Number|
1914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001915
1916complete_check() *complete_check()*
1917 Check for a key typed while looking for completion matches.
1918 This is to be used when looking for matches takes some time.
1919 Returns |TRUE| when searching for matches is to be aborted,
1920 zero otherwise.
1921 Only to be used by the function specified with the
1922 'completefunc' option.
1923
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001924 Return type: |Number|
1925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001926
1927complete_info([{what}]) *complete_info()*
1928 Returns a |Dictionary| with information about Insert mode
1929 completion. See |ins-completion|.
1930 The items are:
1931 mode Current completion mode name string.
1932 See |complete_info_mode| for the values.
1933 pum_visible |TRUE| if popup menu is visible.
1934 See |pumvisible()|.
glepnird4088ed2024-12-31 10:55:22 +01001935 items List of all completion candidates. Each item
1936 is a dictionary containing the entries "word",
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001937 "abbr", "menu", "kind", "info" and "user_data".
1938 See |complete-items|.
glepnird4088ed2024-12-31 10:55:22 +01001939 matches Same as "items", but only returns items that
1940 are matching current query. If both "matches"
1941 and "items" are in "what", the returned list
1942 will still be named "items", but each item
1943 will have an additional "match" field.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001944 selected Selected item index. First index is zero.
1945 Index is -1 if no item is selected (showing
1946 typed text only, or the last completion after
1947 no item is selected when using the <Up> or
1948 <Down> keys)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01001949 inserted Inserted string. [NOT IMPLEMENTED YET]
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001950
1951 *complete_info_mode*
1952 mode values are:
1953 "" Not in completion mode
1954 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1955 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1956 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1957 |i_CTRL-X_CTRL-Y|
1958 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1959 "files" File names |i_CTRL-X_CTRL-F|
1960 "tags" Tags |i_CTRL-X_CTRL-]|
1961 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1962 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1963 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1964 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1965 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1966 "function" User defined completion |i_CTRL-X_CTRL-U|
1967 "omni" Omni completion |i_CTRL-X_CTRL-O|
1968 "spell" Spelling suggestions |i_CTRL-X_s|
1969 "eval" |complete()| completion
1970 "unknown" Other internal modes
1971
1972 If the optional {what} list argument is supplied, then only
1973 the items listed in {what} are returned. Unsupported items in
1974 {what} are silently ignored.
1975
1976 To get the position and size of the popup menu, see
1977 |pum_getpos()|. It's also available in |v:event| during the
1978 |CompleteChanged| event.
1979
Bram Moolenaar016188f2022-06-06 20:52:59 +01001980 Returns an empty |Dictionary| on error.
1981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001982 Examples: >
1983 " Get all items
1984 call complete_info()
1985 " Get only 'mode'
1986 call complete_info(['mode'])
1987 " Get only 'mode' and 'pum_visible'
1988 call complete_info(['mode', 'pum_visible'])
1989
1990< Can also be used as a |method|: >
1991 GetItems()->complete_info()
1992<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001993 Return type: dict<any>
1994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001995 *confirm()*
1996confirm({msg} [, {choices} [, {default} [, {type}]]])
1997 confirm() offers the user a dialog, from which a choice can be
1998 made. It returns the number of the choice. For the first
1999 choice this is 1.
2000 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002001 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002002
2003 {msg} is displayed in a |dialog| with {choices} as the
2004 alternatives. When {choices} is missing or empty, "&OK" is
2005 used (and translated).
2006 {msg} is a String, use '\n' to include a newline. Only on
2007 some systems the string is wrapped when it doesn't fit.
2008
2009 {choices} is a String, with the individual choices separated
2010 by '\n', e.g. >
2011 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2012< The letter after the '&' is the shortcut key for that choice.
2013 Thus you can type 'c' to select "Cancel". The shortcut does
2014 not need to be the first letter: >
2015 confirm("file has been modified", "&Save\nSave &All")
2016< For the console, the first letter of each choice is used as
2017 the default shortcut key. Case is ignored.
2018
2019 The optional {default} argument is the number of the choice
2020 that is made if the user hits <CR>. Use 1 to make the first
2021 choice the default one. Use 0 to not set a default. If
2022 {default} is omitted, 1 is used.
2023
2024 The optional {type} String argument gives the type of dialog.
2025 This is only used for the icon of the GTK, Mac, Motif and
2026 Win32 GUI. It can be one of these values: "Error",
2027 "Question", "Info", "Warning" or "Generic". Only the first
2028 character is relevant. When {type} is omitted, "Generic" is
2029 used.
2030
2031 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2032 or another valid interrupt key, confirm() returns 0.
2033
2034 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002035 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002036 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002037 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002038 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002039 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002040 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002041 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002042 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002043 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002044< In a GUI dialog, buttons are used. The layout of the buttons
2045 depends on the 'v' flag in 'guioptions'. If it is included,
2046 the buttons are always put vertically. Otherwise, confirm()
2047 tries to put the buttons in one horizontal line. If they
2048 don't fit, a vertical layout is used anyway. For some systems
2049 the horizontal layout is always used.
2050
2051 Can also be used as a |method|in: >
2052 BuildMessage()->confirm("&Yes\n&No")
2053<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002054 Return type: |Number|
2055
2056
2057copy({expr}) *copy()*
2058 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002059 different from using {expr} directly.
2060 When {expr} is a |List| a shallow copy is created. This means
2061 that the original |List| can be changed without changing the
2062 copy, and vice versa. But the items are identical, thus
2063 changing an item changes the contents of both |Lists|.
2064 A |Dictionary| is copied in a similar way as a |List|.
2065 Also see |deepcopy()|.
2066 Can also be used as a |method|: >
2067 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002068<
2069 Return type: any, depending on {expr}
2070
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002071
2072cos({expr}) *cos()*
2073 Return the cosine of {expr}, measured in radians, as a |Float|.
2074 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002075 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002076 Examples: >
2077 :echo cos(100)
2078< 0.862319 >
2079 :echo cos(-4.01)
2080< -0.646043
2081
2082 Can also be used as a |method|: >
2083 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002084<
2085 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002086
2087
2088cosh({expr}) *cosh()*
2089 Return the hyperbolic cosine of {expr} as a |Float| in the range
2090 [1, inf].
2091 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002092 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002093 Examples: >
2094 :echo cosh(0.5)
2095< 1.127626 >
2096 :echo cosh(-0.5)
2097< -1.127626
2098
2099 Can also be used as a |method|: >
2100 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002101<
2102 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002103
2104
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002105count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002106 Return the number of times an item with value {expr} appears
2107 in |String|, |List| or |Dictionary| {comp}.
2108
2109 If {start} is given then start with the item with this index.
2110 {start} can only be used with a |List|.
2111
2112 When {ic} is given and it's |TRUE| then case is ignored.
2113
2114 When {comp} is a string then the number of not overlapping
2115 occurrences of {expr} is returned. Zero is returned when
2116 {expr} is an empty string.
2117
2118 Can also be used as a |method|: >
2119 mylist->count(val)
2120<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002121 Return type: |Number|
2122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002123 *cscope_connection()*
2124cscope_connection([{num} , {dbpath} [, {prepend}]])
2125 Checks for the existence of a |cscope| connection. If no
2126 parameters are specified, then the function returns:
2127 0, if cscope was not available (not compiled in), or
2128 if there are no cscope connections;
2129 1, if there is at least one cscope connection.
2130
2131 If parameters are specified, then the value of {num}
2132 determines how existence of a cscope connection is checked:
2133
2134 {num} Description of existence check
2135 ----- ------------------------------
2136 0 Same as no parameters (e.g., "cscope_connection()").
2137 1 Ignore {prepend}, and use partial string matches for
2138 {dbpath}.
2139 2 Ignore {prepend}, and use exact string matches for
2140 {dbpath}.
2141 3 Use {prepend}, use partial string matches for both
2142 {dbpath} and {prepend}.
2143 4 Use {prepend}, use exact string matches for both
2144 {dbpath} and {prepend}.
2145
2146 Note: All string comparisons are case sensitive!
2147
2148 Examples. Suppose we had the following (from ":cs show"): >
2149
2150 # pid database name prepend path
2151 0 27664 cscope.out /usr/local
2152<
2153 Invocation Return Val ~
2154 ---------- ---------- >
2155 cscope_connection() 1
2156 cscope_connection(1, "out") 1
2157 cscope_connection(2, "out") 0
2158 cscope_connection(3, "out") 0
2159 cscope_connection(3, "out", "local") 1
2160 cscope_connection(4, "out") 0
2161 cscope_connection(4, "out", "local") 0
2162 cscope_connection(4, "cscope.out", "/usr/local") 1
2163<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002164 Return type: |Number|
2165
2166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002167cursor({lnum}, {col} [, {off}]) *cursor()*
2168cursor({list})
2169 Positions the cursor at the column (byte count) {col} in the
2170 line {lnum}. The first column is one.
2171
2172 When there is one argument {list} this is used as a |List|
2173 with two, three or four item:
2174 [{lnum}, {col}]
2175 [{lnum}, {col}, {off}]
2176 [{lnum}, {col}, {off}, {curswant}]
2177 This is like the return value of |getpos()| or |getcurpos()|,
2178 but without the first item.
2179
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002180 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002181 |setcursorcharpos()|.
2182
2183 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002184 {lnum} is used like with |getline()|, except that if {lnum} is
2185 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002186 If {lnum} is greater than the number of lines in the buffer,
2187 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002188 If {col} is greater than the number of bytes in the line,
2189 the cursor will be positioned at the last character in the
2190 line.
2191 If {col} is zero, the cursor will stay in the current column.
2192 If {curswant} is given it is used to set the preferred column
2193 for vertical movement. Otherwise {col} is used.
2194
2195 When 'virtualedit' is used {off} specifies the offset in
2196 screen columns from the start of the character. E.g., a
2197 position within a <Tab> or after the last character.
2198 Returns 0 when the position could be set, -1 otherwise.
2199
2200 Can also be used as a |method|: >
2201 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002202<
2203 Return type: |Number|
2204
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002205
2206debugbreak({pid}) *debugbreak()*
2207 Specifically used to interrupt a program being debugged. It
2208 will cause process {pid} to get a SIGTRAP. Behavior for other
2209 processes is undefined. See |terminal-debugger|.
2210 {only available on MS-Windows}
2211
Bram Moolenaar016188f2022-06-06 20:52:59 +01002212 Returns |TRUE| if successfully interrupted the program.
2213 Otherwise returns |FALSE|.
2214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002215 Can also be used as a |method|: >
2216 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002217<
2218 Return type: |Number|
2219
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002220
2221deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2222 Make a copy of {expr}. For Numbers and Strings this isn't
2223 different from using {expr} directly.
2224 When {expr} is a |List| a full copy is created. This means
2225 that the original |List| can be changed without changing the
2226 copy, and vice versa. When an item is a |List| or
2227 |Dictionary|, a copy for it is made, recursively. Thus
2228 changing an item in the copy does not change the contents of
2229 the original |List|.
2230 A |Dictionary| is copied in a similar way as a |List|.
2231
2232 When {noref} is omitted or zero a contained |List| or
2233 |Dictionary| is only copied once. All references point to
2234 this single copy. With {noref} set to 1 every occurrence of a
2235 |List| or |Dictionary| results in a new copy. This also means
2236 that a cyclic reference causes deepcopy() to fail.
2237 *E724*
2238 Nesting is possible up to 100 levels. When there is an item
2239 that refers back to a higher level making a deep copy with
2240 {noref} set to 1 will fail.
2241 Also see |copy()|.
2242
2243 Can also be used as a |method|: >
2244 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002245<
2246 Return type: any, depending on {expr}
2247
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002248
2249delete({fname} [, {flags}]) *delete()*
2250 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002251 name {fname}.
2252
2253 This also works when {fname} is a symbolic link. The symbolic
2254 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002255
2256 When {flags} is "d": Deletes the directory by the name
2257 {fname}. This fails when directory {fname} is not empty.
2258
2259 When {flags} is "rf": Deletes the directory by the name
2260 {fname} and everything in it, recursively. BE CAREFUL!
2261 Note: on MS-Windows it is not possible to delete a directory
2262 that is being used.
2263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002264 The result is a Number, which is 0/false if the delete
2265 operation was successful and -1/true when the deletion failed
2266 or partly failed.
2267
2268 Use |remove()| to delete an item from a |List|.
2269 To delete a line from the buffer use |:delete| or
2270 |deletebufline()|.
2271
2272 Can also be used as a |method|: >
2273 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002274<
2275 Return type: |Number|
2276
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002277
2278deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2279 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2280 If {last} is omitted then delete line {first} only.
2281 On success 0 is returned, on failure 1 is returned.
2282
2283 This function works only for loaded buffers. First call
2284 |bufload()| if needed.
2285
2286 For the use of {buf}, see |bufname()| above.
2287
2288 {first} and {last} are used like with |getline()|. Note that
2289 when using |line()| this refers to the current buffer. Use "$"
2290 to refer to the last line in buffer {buf}.
2291
2292 Can also be used as a |method|: >
2293 GetBuffer()->deletebufline(1)
2294<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002295 Return type: |Number|
2296
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002297 *did_filetype()*
2298did_filetype() Returns |TRUE| when autocommands are being executed and the
2299 FileType event has been triggered at least once. Can be used
2300 to avoid triggering the FileType event again in the scripts
2301 that detect the file type. |FileType|
2302 Returns |FALSE| when `:setf FALLBACK` was used.
2303 When editing another file, the counter is reset, thus this
2304 really checks if the FileType event has been triggered for the
2305 current buffer. This allows an autocommand that starts
2306 editing another buffer to set 'filetype' and load a syntax
2307 file.
2308
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002309 Return type: |Number|
2310
2311
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002312diff({fromlist}, {tolist} [, {options}]) *diff()*
2313 Returns a String or a List containing the diff between the
2314 strings in {fromlist} and {tolist}. Uses the Vim internal
2315 diff library to compute the diff.
2316
2317 *E106*
2318 The optional "output" item in {options} specifies the returned
2319 diff format. The following values are supported:
2320 indices Return a List of the starting and ending
2321 indices and a count of the strings in each
2322 diff hunk.
2323 unified Return the unified diff output as a String.
2324 This is the default.
2325
2326 If the "output" item in {options} is "indices", then a List is
2327 returned. Each List item contains a Dict with the following
2328 items for each diff hunk:
2329 from_idx start index in {fromlist} for this diff hunk.
2330 from_count number of strings in {fromlist} that are
2331 added/removed/modified in this diff hunk.
2332 to_idx start index in {tolist} for this diff hunk.
2333 to_count number of strings in {tolist} that are
2334 added/removed/modified in this diff hunk.
2335
2336 The {options} Dict argument also specifies diff options
2337 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002338 algorithm Dict specifying the diff algorithm to
2339 use. Supported boolean items are
2340 "myers", "minimal", "patience" and
2341 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002342 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002343 iblank ignore changes where lines are all
2344 blank.
2345 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002346 indent-heuristic use the indent heuristic for the
2347 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002348 iwhite ignore changes in amount of white
2349 space.
2350 iwhiteall ignore all white space changes.
2351 iwhiteeol ignore white space changes at end of
2352 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002353 For more information about these options, refer to 'diffopt'.
2354
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002355 To compute the unified diff, all the items in {fromlist} are
2356 concatenated into a string using a newline separator and the
2357 same for {tolist}. The unified diff output uses line numbers.
2358
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002359 Returns an empty List or String if {fromlist} and {tolist} are
2360 identical.
2361
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002362 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002363 :echo diff(['abc'], ['xxx'])
2364 @@ -1 +1 @@
2365 -abc
2366 +xxx
2367
2368 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2369 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2370 :echo diff(readfile('oldfile'), readfile('newfile'))
2371 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002372<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002373 For more examples, refer to |diff-func-examples|
2374
2375 Can also be used as a |method|: >
2376 GetFromList->diff(to_list)
2377<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002378 Return type: |String| or list<dict<number>> or list<any>
2379 depending on {options}
2380
2381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002382diff_filler({lnum}) *diff_filler()*
2383 Returns the number of filler lines above line {lnum}.
2384 These are the lines that were inserted at this point in
2385 another diff'ed window. These filler lines are shown in the
2386 display but don't exist in the buffer.
2387 {lnum} is used like with |getline()|. Thus "." is the current
2388 line, "'m" mark m, etc.
2389 Returns 0 if the current window is not in diff mode.
2390
2391 Can also be used as a |method|: >
2392 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002393<
2394 Return type: |Number|
2395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002396
2397diff_hlID({lnum}, {col}) *diff_hlID()*
2398 Returns the highlight ID for diff mode at line {lnum} column
2399 {col} (byte index). When the current line does not have a
2400 diff change zero is returned.
2401 {lnum} is used like with |getline()|. Thus "." is the current
2402 line, "'m" mark m, etc.
2403 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2404 line.
2405 The highlight ID can be used with |synIDattr()| to obtain
2406 syntax information about the highlighting.
2407
2408 Can also be used as a |method|: >
2409 GetLnum()->diff_hlID(col)
2410<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002411 Return type: |Number|
2412
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002413
2414digraph_get({chars}) *digraph_get()* *E1214*
2415 Return the digraph of {chars}. This should be a string with
2416 exactly two characters. If {chars} are not just two
2417 characters, or the digraph of {chars} does not exist, an error
2418 is given and an empty string is returned.
2419
2420 The character will be converted from Unicode to 'encoding'
2421 when needed. This does require the conversion to be
2422 available, it might fail.
2423
2424 Also see |digraph_getlist()|.
2425
2426 Examples: >
2427 " Get a built-in digraph
2428 :echo digraph_get('00') " Returns '∞'
2429
2430 " Get a user-defined digraph
2431 :call digraph_set('aa', 'あ')
2432 :echo digraph_get('aa') " Returns 'あ'
2433<
2434 Can also be used as a |method|: >
2435 GetChars()->digraph_get()
2436<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002437 Return type: |String|
2438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002439 This function works only when compiled with the |+digraphs|
2440 feature. If this feature is disabled, this function will
2441 display an error message.
2442
2443
2444digraph_getlist([{listall}]) *digraph_getlist()*
2445 Return a list of digraphs. If the {listall} argument is given
2446 and it is TRUE, return all digraphs, including the default
2447 digraphs. Otherwise, return only user-defined digraphs.
2448
2449 The characters will be converted from Unicode to 'encoding'
2450 when needed. This does require the conservation to be
2451 available, it might fail.
2452
2453 Also see |digraph_get()|.
2454
2455 Examples: >
2456 " Get user-defined digraphs
2457 :echo digraph_getlist()
2458
2459 " Get all the digraphs, including default digraphs
2460 :echo digraph_getlist(1)
2461<
2462 Can also be used as a |method|: >
2463 GetNumber()->digraph_getlist()
2464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002465 Return type: list<list<string>>
2466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002467 This function works only when compiled with the |+digraphs|
2468 feature. If this feature is disabled, this function will
2469 display an error message.
2470
2471
Bram Moolenaara2baa732022-02-04 16:09:54 +00002472digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002473 Add digraph {chars} to the list. {chars} must be a string
2474 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002475 encoded character. *E1215*
2476 Be careful, composing characters are NOT ignored. This
2477 function is similar to |:digraphs| command, but useful to add
2478 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002479
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002480 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002481 this fails an error message is given and v:false is returned.
2482
2483 If you want to define multiple digraphs at once, you can use
2484 |digraph_setlist()|.
2485
2486 Example: >
2487 call digraph_set(' ', 'あ')
2488<
2489 Can be used as a |method|: >
2490 GetString()->digraph_set('あ')
2491<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002492 Return type: |vim9-boolean|
2493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002494 This function works only when compiled with the |+digraphs|
2495 feature. If this feature is disabled, this function will
2496 display an error message.
2497
2498
2499digraph_setlist({digraphlist}) *digraph_setlist()*
2500 Similar to |digraph_set()| but this function can add multiple
2501 digraphs at once. {digraphlist} is a list composed of lists,
2502 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002503 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002504 Example: >
2505 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2506<
2507 It is similar to the following: >
2508 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2509 call digraph_set(chars, digraph)
2510 endfor
2511< Except that the function returns after the first error,
2512 following digraphs will not be added.
2513
2514 Can be used as a |method|: >
2515 GetList()->digraph_setlist()
2516<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002517 Return type: |vim9-boolean|
2518
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002519 This function works only when compiled with the |+digraphs|
2520 feature. If this feature is disabled, this function will
2521 display an error message.
2522
2523
2524echoraw({string}) *echoraw()*
2525 Output {string} as-is, including unprintable characters.
2526 This can be used to output a terminal code. For example, to
2527 disable modifyOtherKeys: >
2528 call echoraw(&t_TE)
2529< and to enable it again: >
2530 call echoraw(&t_TI)
2531< Use with care, you can mess up the terminal this way.
2532
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002533 Return type: |Number|
2534
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002535
2536empty({expr}) *empty()*
2537 Return the Number 1 if {expr} is empty, zero otherwise.
2538 - A |List| or |Dictionary| is empty when it does not have any
2539 items.
2540 - A |String| is empty when its length is zero.
2541 - A |Number| and |Float| are empty when their value is zero.
2542 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2543 - A |Job| is empty when it failed to start.
2544 - A |Channel| is empty when it is closed.
2545 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002546 - An |Object| is empty, when the empty() method in the object
2547 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002548
2549 For a long |List| this is much faster than comparing the
2550 length with zero.
2551
2552 Can also be used as a |method|: >
2553 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002554<
2555 Return type: |Number|
2556
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002557
2558environ() *environ()*
2559 Return all of environment variables as dictionary. You can
2560 check if an environment variable exists like this: >
2561 :echo has_key(environ(), 'HOME')
2562< Note that the variable name may be CamelCase; to ignore case
2563 use this: >
2564 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002565<
2566 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002567
Bram Moolenaar416bd912023-07-07 23:19:18 +01002568
2569err_teapot([{expr}]) *err_teapot()*
2570 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002571 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002572 If {expr} is present and it is TRUE error 503 is given,
2573 indicating that coffee is temporarily not available.
2574 If {expr} is present it must be a String.
2575
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002576 Return type: |Number|
2577
Bram Moolenaar416bd912023-07-07 23:19:18 +01002578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002579escape({string}, {chars}) *escape()*
2580 Escape the characters in {chars} that occur in {string} with a
2581 backslash. Example: >
2582 :echo escape('c:\program files\vim', ' \')
2583< results in: >
2584 c:\\program\ files\\vim
2585< Also see |shellescape()| and |fnameescape()|.
2586
2587 Can also be used as a |method|: >
2588 GetText()->escape(' \')
2589<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002590 Return type: |String|
2591
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002592 *eval()*
2593eval({string}) Evaluate {string} and return the result. Especially useful to
2594 turn the result of |string()| back into the original value.
2595 This works for Numbers, Floats, Strings, Blobs and composites
2596 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002597 functions. In |Vim9| script, it can be used to obtain |enum|
2598 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002599
2600 Can also be used as a |method|: >
2601 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002602<
2603 Return type: any, depending on {string}
2604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002605
2606eventhandler() *eventhandler()*
2607 Returns 1 when inside an event handler. That is that Vim got
2608 interrupted while waiting for the user to type a character,
2609 e.g., when dropping a file on Vim. This means interactive
2610 commands cannot be used. Otherwise zero is returned.
2611
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002612 Return type: |Number|
2613
2614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002615executable({expr}) *executable()*
2616 This function checks if an executable with the name {expr}
2617 exists. {expr} must be the name of the program without any
2618 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002620 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002621 searchpath for programs.
2622 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002623 On MS-Windows the ".exe", ".bat", etc. can optionally be
2624 included. Then the extensions in $PATHEXT are tried. Thus if
2625 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2626 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2627 by itself can be used in $PATHEXT to try using the name
2628 without an extension. When 'shell' looks like a Unix shell,
2629 then the name is also tried without adding an extension.
2630 On MS-Windows it only checks if the file exists and is not a
2631 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002632 On MS-Windows an executable in the same directory as the Vim
2633 executable is always found. Since this directory is added to
2634 $PATH it should also work to execute it |win32-PATH|.
2635 *NoDefaultCurrentDirectoryInExePath*
2636 On MS-Windows an executable in Vim's current working directory
2637 is also normally found, but this can be disabled by setting
2638 the $NoDefaultCurrentDirectoryInExePath environment variable.
2639
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002640 The result is a Number:
2641 1 exists
2642 0 does not exist
2643 -1 not implemented on this system
2644 |exepath()| can be used to get the full path of an executable.
2645
2646 Can also be used as a |method|: >
2647 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002648<
2649 Return type: |Number|
2650
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002651
2652execute({command} [, {silent}]) *execute()*
2653 Execute an Ex command or commands and return the output as a
2654 string.
2655 {command} can be a string or a List. In case of a List the
2656 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002657 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002658 redir => var
2659 {command}
2660 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002661< Except that line continuation in {command} is not recognized.
2662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002663 The optional {silent} argument can have these values:
2664 "" no `:silent` used
2665 "silent" `:silent` used
2666 "silent!" `:silent!` used
2667 The default is "silent". Note that with "silent!", unlike
2668 `:redir`, error messages are dropped. When using an external
2669 command the screen may be messed up, use `system()` instead.
2670 *E930*
2671 It is not possible to use `:redir` anywhere in {command}.
2672
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002673 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002674 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002675
2676< To execute a command in another window than the current one
2677 use `win_execute()`.
2678
2679 When used recursively the output of the recursive call is not
2680 included in the output of the higher level call.
2681
2682 Can also be used as a |method|: >
2683 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002684<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002685 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002687
2688exepath({expr}) *exepath()*
2689 If {expr} is an executable and is either an absolute path, a
2690 relative path or found in $PATH, return the full path.
2691 Note that the current directory is used when {expr} starts
2692 with "./", which may be a problem for Vim: >
2693 echo exepath(v:progpath)
2694< If {expr} cannot be found in $PATH or is not executable then
2695 an empty string is returned.
2696
2697 Can also be used as a |method|: >
2698 GetCommand()->exepath()
2699<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002700 Return type: |String|
2701
2702
2703exists({expr}) *exists()*
2704 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002705 zero otherwise.
2706
2707 Note: In a compiled |:def| function the evaluation is done at
2708 runtime. Use `exists_compiled()` to evaluate the expression
2709 at compile time.
2710
2711 For checking for a supported feature use |has()|.
2712 For checking if a file exists use |filereadable()|.
2713
2714 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002715 varname internal variable (see
2716 dict.key |internal-variables|). Also works
2717 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002718 import.Func entries, |List| items, class and
2719 class.Func object methods, imported items, etc.
2720 object.Func Does not work for local variables in a
2721 class.varname compiled `:def` function.
2722 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002723 script, since it can be used as a
2724 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002725 Beware that evaluating an index may
2726 cause an error message for an invalid
2727 expression. E.g.: >
2728 :let l = [1, 2, 3]
2729 :echo exists("l[5]")
2730< 0 >
2731 :echo exists("l[xx]")
2732< E121: Undefined variable: xx
2733 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002734 &option-name Vim option (only checks if it exists,
2735 not if it really works)
2736 +option-name Vim option that works.
2737 $ENVNAME environment variable (could also be
2738 done by comparing with an empty
2739 string)
2740 *funcname built-in function (see |functions|)
2741 or user defined function (see
2742 |user-functions|) that is implemented.
2743 Also works for a variable that is a
2744 Funcref.
2745 ?funcname built-in function that could be
2746 implemented; to be used to check if
2747 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002748 :cmdname Ex command: built-in command, user
2749 command or command modifier |:command|.
2750 Returns:
2751 1 for match with start of a command
2752 2 full match with a command
2753 3 matches several user commands
2754 To check for a supported command
2755 always check the return value to be 2.
2756 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002757 :3match The |:3match| command (but you
2758 probably should not use it, it is
2759 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002760 #event autocommand defined for this event
2761 #event#pattern autocommand defined for this event and
2762 pattern (the pattern is taken
2763 literally and compared to the
2764 autocommand patterns character by
2765 character)
2766 #group autocommand group exists
2767 #group#event autocommand defined for this group and
2768 event.
2769 #group#event#pattern
2770 autocommand defined for this group,
2771 event and pattern.
2772 ##event autocommand for this event is
2773 supported.
2774
2775 Examples: >
2776 exists("&shortname")
2777 exists("$HOSTNAME")
2778 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002779 exists("*s:MyFunc") " only for legacy script
2780 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002781 exists("bufcount")
2782 exists(":Make")
2783 exists("#CursorHold")
2784 exists("#BufReadPre#*.gz")
2785 exists("#filetypeindent")
2786 exists("#filetypeindent#FileType")
2787 exists("#filetypeindent#FileType#*")
2788 exists("##ColorScheme")
2789< There must be no space between the symbol (&/$/*/#) and the
2790 name.
2791 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002792 a few cases this is ignored. That may become stricter in the
2793 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002794 Working example: >
2795 exists(":make")
2796< NOT working example: >
2797 exists(":make install")
2798
2799< Note that the argument must be a string, not the name of the
2800 variable itself. For example: >
2801 exists(bufcount)
2802< This doesn't check for existence of the "bufcount" variable,
2803 but gets the value of "bufcount", and checks if that exists.
2804
2805 Can also be used as a |method|: >
2806 Varname()->exists()
2807<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002808 Return type: |String|
2809
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002810
2811exists_compiled({expr}) *exists_compiled()*
2812 Like `exists()` but evaluated at compile time. This is useful
2813 to skip a block where a function is used that would otherwise
2814 give an error: >
2815 if exists_compiled('*ThatFunction')
2816 ThatFunction('works')
2817 endif
2818< If `exists()` were used then a compilation error would be
2819 given if ThatFunction() is not defined.
2820
2821 {expr} must be a literal string. *E1232*
2822 Can only be used in a |:def| function. *E1233*
2823 This does not work to check for arguments or local variables.
2824
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002825 Return type: |String|
2826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002827
2828exp({expr}) *exp()*
2829 Return the exponential of {expr} as a |Float| in the range
2830 [0, inf].
2831 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002832 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002833 Examples: >
2834 :echo exp(2)
2835< 7.389056 >
2836 :echo exp(-1)
2837< 0.367879
2838
2839 Can also be used as a |method|: >
2840 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002841<
2842 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002843
2844
2845expand({string} [, {nosuf} [, {list}]]) *expand()*
2846 Expand wildcards and the following special keywords in
2847 {string}. 'wildignorecase' applies.
2848
2849 If {list} is given and it is |TRUE|, a List will be returned.
2850 Otherwise the result is a String and when there are several
2851 matches, they are separated by <NL> characters. [Note: in
2852 version 5.0 a space was used, which caused problems when a
2853 file name contains a space]
2854
2855 If the expansion fails, the result is an empty string. A name
2856 for a non-existing file is not included, unless {string} does
2857 not start with '%', '#' or '<', see below.
2858
Christian Brabandtec9c3262024-02-21 20:40:05 +01002859 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002860 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002861
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002862 When {string} starts with '%', '#' or '<', the expansion is
2863 done like for the |cmdline-special| variables with their
2864 associated modifiers. Here is a short overview:
2865
2866 % current file name
2867 # alternate file name
2868 #n alternate file name n
2869 <cfile> file name under the cursor
2870 <afile> autocmd file name
2871 <abuf> autocmd buffer number (as a String!)
2872 <amatch> autocmd matched name
2873 <cexpr> C expression under the cursor
2874 <sfile> sourced script file or function name
2875 <slnum> sourced script line number or function
2876 line number
2877 <sflnum> script file line number, also when in
2878 a function
2879 <SID> "<SNR>123_" where "123" is the
2880 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002881 <script> sourced script file, or script file
2882 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002883 <stack> call stack
2884 <cword> word under the cursor
2885 <cWORD> WORD under the cursor
2886 <client> the {clientid} of the last received
2887 message |server2client()|
2888 Modifiers:
2889 :p expand to full path
2890 :h head (last path component removed)
2891 :t tail (last path component only)
2892 :r root (one extension removed)
2893 :e extension only
2894
2895 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002896 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002897< Note that when expanding a string that starts with '%', '#' or
2898 '<', any following text is ignored. This does NOT work: >
2899 :let doesntwork = expand("%:h.bak")
2900< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002901 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002902< Also note that expanding "<cfile>" and others only returns the
2903 referenced file name without further expansion. If "<cfile>"
2904 is "~/.cshrc", you need to do another expand() to have the
2905 "~/" expanded into the path of the home directory: >
2906 :echo expand(expand("<cfile>"))
2907<
2908 There cannot be white space between the variables and the
2909 following modifier. The |fnamemodify()| function can be used
2910 to modify normal file names.
2911
2912 When using '%' or '#', and the current or alternate file name
2913 is not defined, an empty string is used. Using "%:p" in a
2914 buffer with no name, results in the current directory, with a
2915 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002916 When 'verbose' is set then expanding '%', '#' and <> items
2917 will result in an error message if the argument cannot be
2918 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002919
2920 When {string} does not start with '%', '#' or '<', it is
2921 expanded like a file name is expanded on the command line.
2922 'suffixes' and 'wildignore' are used, unless the optional
2923 {nosuf} argument is given and it is |TRUE|.
2924 Names for non-existing files are included. The "**" item can
2925 be used to search in a directory tree. For example, to find
2926 all "README" files in the current directory and below: >
2927 :echo expand("**/README")
2928<
2929 expand() can also be used to expand variables and environment
2930 variables that are only known in a shell. But this can be
2931 slow, because a shell may be used to do the expansion. See
2932 |expr-env-expand|.
2933 The expanded variable is still handled like a list of file
2934 names. When an environment variable cannot be expanded, it is
2935 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2936 "$FOOBAR".
2937
2938 See |glob()| for finding existing files. See |system()| for
2939 getting the raw output of an external command.
2940
2941 Can also be used as a |method|: >
2942 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002943<
2944 Return type: |String| or list<string> depending on {list}
2945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002946
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002947expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002948 Expand special items in String {string} like what is done for
2949 an Ex command such as `:edit`. This expands special keywords,
2950 like with |expand()|, and environment variables, anywhere in
2951 {string}. "~user" and "~/path" are only expanded at the
2952 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002953
2954 The following items are supported in the {options} Dict
2955 argument:
2956 errmsg If set to TRUE, error messages are displayed
2957 if an error is encountered during expansion.
2958 By default, error messages are not displayed.
2959
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002960 Returns the expanded string. If an error is encountered
2961 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002962
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002963 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002964 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002965 make /path/runtime/doc/builtin.o
2966 :echo expandcmd('make %<.o', {'errmsg': v:true})
2967<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002968 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002969 GetCommand()->expandcmd()
2970<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002971 Return type: |String| or list<string> depending on {list}
2972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002973extend({expr1}, {expr2} [, {expr3}]) *extend()*
2974 {expr1} and {expr2} must be both |Lists| or both
2975 |Dictionaries|.
2976
2977 If they are |Lists|: Append {expr2} to {expr1}.
2978 If {expr3} is given insert the items of {expr2} before the
2979 item with index {expr3} in {expr1}. When {expr3} is zero
2980 insert before the first item. When {expr3} is equal to
2981 len({expr1}) then {expr2} is appended.
2982 Examples: >
2983 :echo sort(extend(mylist, [7, 5]))
2984 :call extend(mylist, [2, 3], 1)
2985< When {expr1} is the same List as {expr2} then the number of
2986 items copied is equal to the original length of the List.
2987 E.g., when {expr3} is 1 you get N new copies of the first item
2988 (where N is the original length of the List).
2989 Use |add()| to concatenate one item to a list. To concatenate
2990 two lists into a new list use the + operator: >
2991 :let newlist = [1, 2, 3] + [4, 5]
2992<
2993 If they are |Dictionaries|:
2994 Add all entries from {expr2} to {expr1}.
2995 If a key exists in both {expr1} and {expr2} then {expr3} is
2996 used to decide what to do:
2997 {expr3} = "keep": keep the value of {expr1}
2998 {expr3} = "force": use the value of {expr2}
2999 {expr3} = "error": give an error message *E737*
3000 When {expr3} is omitted then "force" is assumed.
3001
3002 {expr1} is changed when {expr2} is not empty. If necessary
3003 make a copy of {expr1} first.
3004 {expr2} remains unchanged.
3005 When {expr1} is locked and {expr2} is not empty the operation
3006 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003007 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003008
3009 Can also be used as a |method|: >
3010 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003011<
3012 Return type: list<{type}> or dict<{type}> depending on {expr1}
3013 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003014
3015
3016extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3017 Like |extend()| but instead of adding items to {expr1} a new
3018 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003019 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003020
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003021 Return type: list<{type}> or dict<{type}> depending on {expr1}
3022 and {expr2}, in case of error: |Number|
3023
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003024
3025feedkeys({string} [, {mode}]) *feedkeys()*
3026 Characters in {string} are queued for processing as if they
3027 come from a mapping or were typed by the user.
3028
3029 By default the string is added to the end of the typeahead
3030 buffer, thus if a mapping is still being executed the
3031 characters come after them. Use the 'i' flag to insert before
3032 other characters, they will be executed next, before any
3033 characters from a mapping.
3034
3035 The function does not wait for processing of keys contained in
3036 {string}.
3037
3038 To include special keys into {string}, use double-quotes
3039 and "\..." notation |expr-quote|. For example,
3040 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3041 feedkeys('\<CR>') pushes 5 characters.
3042 A special code that might be useful is <Ignore>, it exits the
3043 wait for a character without doing anything. *<Ignore>*
3044
3045 {mode} is a String, which can contain these character flags:
3046 'm' Remap keys. This is default. If {mode} is absent,
3047 keys are remapped.
3048 'n' Do not remap keys.
3049 't' Handle keys as if typed; otherwise they are handled as
3050 if coming from a mapping. This matters for undo,
3051 opening folds, etc.
3052 'L' Lowlevel input. Only works for Unix or when using the
3053 GUI. Keys are used as if they were coming from the
3054 terminal. Other flags are not used. *E980*
3055 When a CTRL-C interrupts and 't' is included it sets
3056 the internal "got_int" flag.
3057 'i' Insert the string instead of appending (see above).
3058 'x' Execute commands until typeahead is empty. This is
3059 similar to using ":normal!". You can call feedkeys()
3060 several times without 'x' and then one time with 'x'
3061 (possibly with an empty {string}) to execute all the
3062 typeahead. Note that when Vim ends in Insert mode it
3063 will behave as if <Esc> is typed, to avoid getting
3064 stuck, waiting for a character to be typed before the
3065 script continues.
3066 Note that if you manage to call feedkeys() while
3067 executing commands, thus calling it recursively, then
3068 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003069 'c' Remove any script context when executing, so that
3070 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003071 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003072 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003073 '!' When used with 'x' will not end Insert mode. Can be
3074 used in a test when a timer is set to exit Insert mode
3075 a little later. Useful for testing CursorHoldI.
3076
3077 Return value is always 0.
3078
3079 Can also be used as a |method|: >
3080 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003081<
3082 Return type: |String| or list<string> depending on {list}
3083
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003084
Shougo Matsushita60c87432024-06-03 22:59:27 +02003085filecopy({from}, {to}) *filecopy()*
3086 Copy the file pointed to by the name {from} to {to}. The
3087 result is a Number, which is |TRUE| if the file was copied
3088 successfully, and |FALSE| when it failed.
3089 If a file with name {to} already exists, it will fail.
3090 Note that it does not handle directories (yet).
3091
3092 This function is not available in the |sandbox|.
3093
3094 Can also be used as a |method|: >
3095 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003096<
3097 Return type: |Number|
3098
Shougo Matsushita60c87432024-06-03 22:59:27 +02003099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003100filereadable({file}) *filereadable()*
3101 The result is a Number, which is |TRUE| when a file with the
3102 name {file} exists, and can be read. If {file} doesn't exist,
3103 or is a directory, the result is |FALSE|. {file} is any
3104 expression, which is used as a String.
3105 If you don't care about the file being readable you can use
3106 |glob()|.
3107 {file} is used as-is, you may want to expand wildcards first: >
3108 echo filereadable('~/.vimrc')
3109 0
3110 echo filereadable(expand('~/.vimrc'))
3111 1
3112
3113< Can also be used as a |method|: >
3114 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003115<
3116 Return type: |Number|
3117
3118 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003119 Obsolete name: file_readable().
3120
3121
3122filewritable({file}) *filewritable()*
3123 The result is a Number, which is 1 when a file with the
3124 name {file} exists, and can be written. If {file} doesn't
3125 exist, or is not writable, the result is 0. If {file} is a
3126 directory, and we can write to it, the result is 2.
3127
3128 Can also be used as a |method|: >
3129 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003130<
3131 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003132
3133
3134filter({expr1}, {expr2}) *filter()*
3135 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3136 For each item in {expr1} evaluate {expr2} and when the result
3137 is zero or false remove the item from the |List| or
3138 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003139 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003140
3141 {expr2} must be a |string| or |Funcref|.
3142
3143 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3144 of the current item. For a |Dictionary| |v:key| has the key
3145 of the current item and for a |List| |v:key| has the index of
3146 the current item. For a |Blob| |v:key| has the index of the
3147 current byte. For a |String| |v:key| has the index of the
3148 current character.
3149 Examples: >
3150 call filter(mylist, 'v:val !~ "OLD"')
3151< Removes the items where "OLD" appears. >
3152 call filter(mydict, 'v:key >= 8')
3153< Removes the items with a key below 8. >
3154 call filter(var, 0)
3155< Removes all the items, thus clears the |List| or |Dictionary|.
3156
3157 Note that {expr2} is the result of expression and is then
3158 used as an expression again. Often it is good to use a
3159 |literal-string| to avoid having to double backslashes.
3160
3161 If {expr2} is a |Funcref| it must take two arguments:
3162 1. the key or the index of the current item.
3163 2. the value of the current item.
3164 The function must return |TRUE| if the item should be kept.
3165 Example that keeps the odd items of a list: >
3166 func Odd(idx, val)
3167 return a:idx % 2 == 1
3168 endfunc
3169 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003170< It is shorter when using a |lambda|. In |Vim9| syntax: >
3171 call filter(myList, (idx, val) => idx * val <= 42)
3172< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003173 call filter(myList, {idx, val -> idx * val <= 42})
3174< If you do not use "val" you can leave it out: >
3175 call filter(myList, {idx -> idx % 2 == 1})
3176<
3177 In |Vim9| script the result must be true, false, zero or one.
3178 Other values will result in a type error.
3179
3180 For a |List| and a |Dictionary| the operation is done
3181 in-place. If you want it to remain unmodified make a copy
3182 first: >
3183 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3184
3185< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003186 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003187 When an error is encountered while evaluating {expr2} no
3188 further items in {expr1} are processed.
3189 When {expr2} is a Funcref errors inside a function are ignored,
3190 unless it was defined with the "abort" flag.
3191
3192 Can also be used as a |method|: >
3193 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003194<
3195 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3196 depending on {expr1}
3197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003198
3199finddir({name} [, {path} [, {count}]]) *finddir()*
3200 Find directory {name} in {path}. Supports both downwards and
3201 upwards recursive directory searches. See |file-searching|
3202 for the syntax of {path}.
3203
3204 Returns the path of the first found match. When the found
3205 directory is below the current directory a relative path is
3206 returned. Otherwise a full path is returned.
3207 If {path} is omitted or empty then 'path' is used.
3208
3209 If the optional {count} is given, find {count}'s occurrence of
3210 {name} in {path} instead of the first one.
3211 When {count} is negative return all the matches in a |List|.
3212
Bram Moolenaar016188f2022-06-06 20:52:59 +01003213 Returns an empty string if the directory is not found.
3214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003215 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216
3217 Can also be used as a |method|: >
3218 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003219<
3220 Return type: |String|
3221
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003222
3223findfile({name} [, {path} [, {count}]]) *findfile()*
3224 Just like |finddir()|, but find a file instead of a directory.
3225 Uses 'suffixesadd'.
3226 Example: >
3227 :echo findfile("tags.vim", ".;")
3228< Searches from the directory of the current file upwards until
3229 it finds the file "tags.vim".
3230
3231 Can also be used as a |method|: >
3232 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003233<
3234 Return type: |String|
3235
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003236
3237flatten({list} [, {maxdepth}]) *flatten()*
3238 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3239 the result is a |List| without nesting, as if {maxdepth} is
3240 a very large number.
3241 The {list} is changed in place, use |flattennew()| if you do
3242 not want that.
3243 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003244 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003245 *E900*
3246 {maxdepth} means how deep in nested lists changes are made.
3247 {list} is not modified when {maxdepth} is 0.
3248 {maxdepth} must be positive number.
3249
3250 If there is an error the number zero is returned.
3251
3252 Example: >
3253 :echo flatten([1, [2, [3, 4]], 5])
3254< [1, 2, 3, 4, 5] >
3255 :echo flatten([1, [2, [3, 4]], 5], 1)
3256< [1, 2, [3, 4], 5]
3257
3258 Can also be used as a |method|: >
3259 mylist->flatten()
3260<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003261 Return type: list<{type}>
3262
3263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003264flattennew({list} [, {maxdepth}]) *flattennew()*
3265 Like |flatten()| but first make a copy of {list}.
3266
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003267 Return type: list<{type}>
3268
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003269
3270float2nr({expr}) *float2nr()*
3271 Convert {expr} to a Number by omitting the part after the
3272 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003273 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003274 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003275 When the value of {expr} is out of range for a |Number| the
3276 result is truncated to 0x7fffffff or -0x7fffffff (or when
3277 64-bit Number support is enabled, 0x7fffffffffffffff or
3278 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3279 64-bit Number support is enabled, -0x8000000000000000).
3280 Examples: >
3281 echo float2nr(3.95)
3282< 3 >
3283 echo float2nr(-23.45)
3284< -23 >
3285 echo float2nr(1.0e100)
3286< 2147483647 (or 9223372036854775807) >
3287 echo float2nr(-1.0e150)
3288< -2147483647 (or -9223372036854775807) >
3289 echo float2nr(1.0e-100)
3290< 0
3291
3292 Can also be used as a |method|: >
3293 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003294<
3295 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003296
3297
3298floor({expr}) *floor()*
3299 Return the largest integral value less than or equal to
3300 {expr} as a |Float| (round down).
3301 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003302 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003303 Examples: >
3304 echo floor(1.856)
3305< 1.0 >
3306 echo floor(-5.456)
3307< -6.0 >
3308 echo floor(4.0)
3309< 4.0
3310
3311 Can also be used as a |method|: >
3312 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003313<
3314 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003315
3316
3317fmod({expr1}, {expr2}) *fmod()*
3318 Return the remainder of {expr1} / {expr2}, even if the
3319 division is not representable. Returns {expr1} - i * {expr2}
3320 for some integer i such that if {expr2} is non-zero, the
3321 result has the same sign as {expr1} and magnitude less than
3322 the magnitude of {expr2}. If {expr2} is zero, the value
3323 returned is zero. The value returned is a |Float|.
3324 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003325 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3326 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003327 Examples: >
3328 :echo fmod(12.33, 1.22)
3329< 0.13 >
3330 :echo fmod(-12.33, 1.22)
3331< -0.13
3332
3333 Can also be used as a |method|: >
3334 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003335<
3336 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003337
3338
3339fnameescape({string}) *fnameescape()*
3340 Escape {string} for use as file name command argument. All
3341 characters that have a special meaning, such as '%' and '|'
3342 are escaped with a backslash.
3343 For most systems the characters escaped are
3344 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3345 appears in a filename, it depends on the value of 'isfname'.
3346 A leading '+' and '>' is also escaped (special after |:edit|
3347 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003348 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003349 Example: >
3350 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003351 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003352< results in executing: >
3353 edit \+some\ str\%nge\|name
3354<
3355 Can also be used as a |method|: >
3356 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003357<
3358 Return type: |String|
3359
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003360
3361fnamemodify({fname}, {mods}) *fnamemodify()*
3362 Modify file name {fname} according to {mods}. {mods} is a
3363 string of characters like it is used for file names on the
3364 command line. See |filename-modifiers|.
3365 Example: >
3366 :echo fnamemodify("main.c", ":p:h")
3367< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003368 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003369< If {mods} is empty or an unsupported modifier is used then
3370 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003371 When {fname} is empty then with {mods} ":h" returns ".", so
3372 that `:cd` can be used with it. This is different from
3373 expand('%:h') without a buffer name, which returns an empty
3374 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003375 Note: Environment variables don't work in {fname}, use
3376 |expand()| first then.
3377
3378 Can also be used as a |method|: >
3379 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003380<
3381 Return type: |String|
3382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003383
3384foldclosed({lnum}) *foldclosed()*
3385 The result is a Number. If the line {lnum} is in a closed
3386 fold, the result is the number of the first line in that fold.
3387 If the line {lnum} is not in a closed fold, -1 is returned.
3388 {lnum} is used like with |getline()|. Thus "." is the current
3389 line, "'m" mark m, etc.
3390
3391 Can also be used as a |method|: >
3392 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003393<
3394 Return type: |Number|
3395
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003396
3397foldclosedend({lnum}) *foldclosedend()*
3398 The result is a Number. If the line {lnum} is in a closed
3399 fold, the result is the number of the last line in that fold.
3400 If the line {lnum} is not in a closed fold, -1 is returned.
3401 {lnum} is used like with |getline()|. Thus "." is the current
3402 line, "'m" mark m, etc.
3403
3404 Can also be used as a |method|: >
3405 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003406<
3407 Return type: |Number|
3408
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003409
3410foldlevel({lnum}) *foldlevel()*
3411 The result is a Number, which is the foldlevel of line {lnum}
3412 in the current buffer. For nested folds the deepest level is
3413 returned. If there is no fold at line {lnum}, zero is
3414 returned. It doesn't matter if the folds are open or closed.
3415 When used while updating folds (from 'foldexpr') -1 is
3416 returned for lines where folds are still to be updated and the
3417 foldlevel is unknown. As a special case the level of the
3418 previous line is usually available.
3419 {lnum} is used like with |getline()|. Thus "." is the current
3420 line, "'m" mark m, etc.
3421
3422 Can also be used as a |method|: >
3423 GetLnum()->foldlevel()
3424<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003425 Return type: |Number|
3426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003427 *foldtext()*
3428foldtext() Returns a String, to be displayed for a closed fold. This is
3429 the default function used for the 'foldtext' option and should
3430 only be called from evaluating 'foldtext'. It uses the
3431 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3432 The returned string looks like this: >
3433 +-- 45 lines: abcdef
3434< The number of leading dashes depends on the foldlevel. The
3435 "45" is the number of lines in the fold. "abcdef" is the text
3436 in the first non-blank line of the fold. Leading white space,
3437 "//" or "/*" and the text from the 'foldmarker' and
3438 'commentstring' options is removed.
3439 When used to draw the actual foldtext, the rest of the line
3440 will be filled with the fold char from the 'fillchars'
3441 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003442 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003443
3444 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003445 {not available when compiled without the |+folding| feature}
3446
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003448foldtextresult({lnum}) *foldtextresult()*
3449 Returns the text that is displayed for the closed fold at line
3450 {lnum}. Evaluates 'foldtext' in the appropriate context.
3451 When there is no closed fold at {lnum} an empty string is
3452 returned.
3453 {lnum} is used like with |getline()|. Thus "." is the current
3454 line, "'m" mark m, etc.
3455 Useful when exporting folded text, e.g., to HTML.
3456 {not available when compiled without the |+folding| feature}
3457
3458
3459 Can also be used as a |method|: >
3460 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003461<
3462 Return type: |String|
3463
Ernie Raele79e2072024-01-13 11:47:33 +01003464
3465foreach({expr1}, {expr2}) *foreach()*
3466 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3467 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003468 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003469 See |map()| and |filter()| to modify {expr1}.
3470
3471 {expr2} must be a |string| or |Funcref|.
3472
3473 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3474 of the current item. For a |Dictionary| |v:key| has the key
3475 of the current item and for a |List| |v:key| has the index of
3476 the current item. For a |Blob| |v:key| has the index of the
3477 current byte. For a |String| |v:key| has the index of the
3478 current character.
3479 Examples: >
3480 call foreach(mylist, 'used[v:val] = true')
3481< This records the items that are in the {expr1} list.
3482
3483 Note that {expr2} is the result of expression and is then used
3484 as a command. Often it is good to use a |literal-string| to
3485 avoid having to double backslashes.
3486
3487 If {expr2} is a |Funcref| it must take two arguments:
3488 1. the key or the index of the current item.
3489 2. the value of the current item.
3490 With a legacy script lambda you don't get an error if it only
3491 accepts one argument, but with a Vim9 lambda you get "E1106:
3492 One argument too many", the number of arguments must match.
3493 If the function returns a value, it is ignored.
3494
3495 Returns {expr1} in all cases.
3496 When an error is encountered while executing {expr2} no
3497 further items in {expr1} are processed.
3498 When {expr2} is a Funcref errors inside a function are ignored,
3499 unless it was defined with the "abort" flag.
3500
3501 Can also be used as a |method|: >
3502 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003503<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003504 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3505 depending on {expr1}
3506
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003507 *foreground()*
3508foreground() Move the Vim window to the foreground. Useful when sent from
3509 a client to a Vim server. |remote_send()|
3510 On Win32 systems this might not work, the OS does not always
3511 allow a window to bring itself to the foreground. Use
3512 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003513
3514 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003515 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003516 Win32 console version}
3517
Bram Moolenaaraa534142022-09-15 21:46:02 +01003518fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003519 Get the full command name from a short abbreviated command
3520 name; see |20.2| for details on command abbreviations.
3521
3522 The string argument {name} may start with a `:` and can
3523 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003524 Returns an empty string if a command doesn't exist, if it's
3525 ambiguous (for user-defined commands) or cannot be shortened
3526 this way. |vim9-no-shorten|
3527
3528 Without the {vim9} argument uses the current script version.
3529 If {vim9} is present and FALSE then legacy script rules are
3530 used. When {vim9} is present and TRUE then Vim9 rules are
3531 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003532
3533 For example `fullcommand('s')`, `fullcommand('sub')`,
3534 `fullcommand(':%substitute')` all return "substitute".
3535
3536 Can also be used as a |method|: >
3537 GetName()->fullcommand()
3538<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003539 Return type: |String|
3540
3541
3542funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003543 Just like |function()|, but the returned Funcref will lookup
3544 the function by reference, not by name. This matters when the
3545 function {name} is redefined later.
3546
3547 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003548 It only works for an autoloaded function if it has already
3549 been loaded (to avoid mistakenly loading the autoload script
3550 when only intending to use the function name, use |function()|
3551 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003552 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003553
3554 Can also be used as a |method|: >
3555 GetFuncname()->funcref([arg])
3556<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003557 Return type: func(...): any or |Number| on error
3558
Dominique Pellee764d1b2023-03-12 21:20:59 +00003559 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003560function({name} [, {arglist}] [, {dict}])
3561 Return a |Funcref| variable that refers to function {name}.
3562 {name} can be the name of a user defined function or an
3563 internal function.
3564
3565 {name} can also be a Funcref or a partial. When it is a
3566 partial the dict stored in it will be used and the {dict}
3567 argument is not allowed. E.g.: >
3568 let FuncWithArg = function(dict.Func, [arg])
3569 let Broken = function(dict.Func, [arg], dict)
3570<
3571 When using the Funcref the function will be found by {name},
3572 also when it was redefined later. Use |funcref()| to keep the
3573 same function.
3574
3575 When {arglist} or {dict} is present this creates a partial.
3576 That means the argument list and/or the dictionary is stored in
3577 the Funcref and will be used when the Funcref is called.
3578
3579 The arguments are passed to the function in front of other
3580 arguments, but after any argument from |method|. Example: >
3581 func Callback(arg1, arg2, name)
3582 ...
3583 let Partial = function('Callback', ['one', 'two'])
3584 ...
3585 call Partial('name')
3586< Invokes the function as with: >
3587 call Callback('one', 'two', 'name')
3588
3589< With a |method|: >
3590 func Callback(one, two, three)
3591 ...
3592 let Partial = function('Callback', ['two'])
3593 ...
3594 eval 'one'->Partial('three')
3595< Invokes the function as with: >
3596 call Callback('one', 'two', 'three')
3597
3598< The function() call can be nested to add more arguments to the
3599 Funcref. The extra arguments are appended to the list of
3600 arguments. Example: >
3601 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003602 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003603 let Func = function('Callback', ['one'])
3604 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003605 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003606 call Func2('name')
3607< Invokes the function as with: >
3608 call Callback('one', 'two', 'name')
3609
3610< The Dictionary is only useful when calling a "dict" function.
3611 In that case the {dict} is passed in as "self". Example: >
3612 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003613 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003614 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003615 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003616 let context = {"name": "example"}
3617 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003618 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003619 call Func() " will echo: called for example
3620< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003621 arguments, these two are equivalent, if Callback() is defined
3622 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003623 let Func = function('Callback', context)
3624 let Func = context.Callback
3625
3626< The argument list and the Dictionary can be combined: >
3627 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003628 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003629 let context = {"name": "example"}
3630 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003631 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003632 call Func(500)
3633< Invokes the function as with: >
3634 call context.Callback('one', 500)
3635<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003636 Returns 0 on error.
3637
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003638 Can also be used as a |method|: >
3639 GetFuncname()->function([arg])
3640
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003641<
3642 Return type: func(...): any or |Number| on error
3643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003644
3645garbagecollect([{atexit}]) *garbagecollect()*
3646 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3647 that have circular references.
3648
3649 There is hardly ever a need to invoke this function, as it is
3650 automatically done when Vim runs out of memory or is waiting
3651 for the user to press a key after 'updatetime'. Items without
3652 circular references are always freed when they become unused.
3653 This is useful if you have deleted a very big |List| and/or
3654 |Dictionary| with circular references in a script that runs
3655 for a long time.
3656
3657 When the optional {atexit} argument is one, garbage
3658 collection will also be done when exiting Vim, if it wasn't
3659 done before. This is useful when checking for memory leaks.
3660
3661 The garbage collection is not done immediately but only when
3662 it's safe to perform. This is when waiting for the user to
3663 type a character. To force garbage collection immediately use
3664 |test_garbagecollect_now()|.
3665
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003666 Return type: |String|
3667
3668
LemonBoy48b7d052024-07-09 18:24:59 +02003669get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003670 Get item {idx} from |List| {list}. When this item is not
3671 available return {default}. Return zero when {default} is
3672 omitted.
3673 Preferably used as a |method|: >
3674 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003675<
3676 Return type: any, depending on {list}
3677
LemonBoy48b7d052024-07-09 18:24:59 +02003678get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003679 Get byte {idx} from |Blob| {blob}. When this byte is not
3680 available return {default}. Return -1 when {default} is
3681 omitted.
3682 Preferably used as a |method|: >
3683 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003684<
3685 Return type: |Number|
3686
LemonBoy48b7d052024-07-09 18:24:59 +02003687get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003688 Get item with key {key} from |Dictionary| {dict}. When this
3689 item is not available return {default}. Return zero when
3690 {default} is omitted. Useful example: >
3691 let val = get(g:, 'var_name', 'default')
3692< This gets the value of g:var_name if it exists, and uses
3693 'default' when it does not exist.
3694 Preferably used as a |method|: >
3695 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003696<
h-east84ac2122024-06-17 18:12:30 +02003697 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003698
LemonBoy48b7d052024-07-09 18:24:59 +02003699get({func}, {what}) *get()-func*
3700 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003701 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003702 "name" The function name
3703 "func" The function
3704 "dict" The dictionary
3705 "args" The list with arguments
3706 "arity" A dictionary with information about the number of
3707 arguments accepted by the function (minus the
3708 {arglist}) with the following fields:
3709 required the number of positional arguments
3710 optional the number of optional arguments,
3711 in addition to the required ones
3712 varargs |TRUE| if the function accepts a
3713 variable number of arguments |...|
3714
3715 Note: There is no error, if the {arglist} of
3716 the Funcref contains more arguments than the
3717 Funcref expects, it's not validated.
3718
Bram Moolenaar016188f2022-06-06 20:52:59 +01003719 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003720
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003721 Preferably used as a |method|: >
3722 myfunc->get(what)
3723<
LemonBoy48b7d052024-07-09 18:24:59 +02003724 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003726 *getbufinfo()*
3727getbufinfo([{buf}])
3728getbufinfo([{dict}])
3729 Get information about buffers as a List of Dictionaries.
3730
3731 Without an argument information about all the buffers is
3732 returned.
3733
3734 When the argument is a |Dictionary| only the buffers matching
3735 the specified criteria are returned. The following keys can
3736 be specified in {dict}:
3737 buflisted include only listed buffers.
3738 bufloaded include only loaded buffers.
3739 bufmodified include only modified buffers.
3740
3741 Otherwise, {buf} specifies a particular buffer to return
3742 information for. For the use of {buf}, see |bufname()|
3743 above. If the buffer is found the returned List has one item.
3744 Otherwise the result is an empty list.
3745
3746 Each returned List item is a dictionary with the following
3747 entries:
3748 bufnr Buffer number.
3749 changed TRUE if the buffer is modified.
3750 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003751 command TRUE if the buffer belongs to the
3752 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003753 hidden TRUE if the buffer is hidden.
3754 lastused Timestamp in seconds, like
3755 |localtime()|, when the buffer was
3756 last used.
3757 {only with the |+viminfo| feature}
3758 listed TRUE if the buffer is listed.
3759 lnum Line number used for the buffer when
3760 opened in the current window.
3761 Only valid if the buffer has been
3762 displayed in the window in the past.
3763 If you want the line number of the
3764 last known cursor position in a given
3765 window, use |line()|: >
3766 :echo line('.', {winid})
3767<
3768 linecount Number of lines in the buffer (only
3769 valid when loaded)
3770 loaded TRUE if the buffer is loaded.
3771 name Full path to the file in the buffer.
3772 signs List of signs placed in the buffer.
3773 Each list item is a dictionary with
3774 the following fields:
3775 id sign identifier
3776 lnum line number
3777 name sign name
3778 variables A reference to the dictionary with
3779 buffer-local variables.
3780 windows List of |window-ID|s that display this
3781 buffer
3782 popups List of popup |window-ID|s that
3783 display this buffer
3784
3785 Examples: >
3786 for buf in getbufinfo()
3787 echo buf.name
3788 endfor
3789 for buf in getbufinfo({'buflisted':1})
3790 if buf.changed
3791 ....
3792 endif
3793 endfor
3794<
3795 To get buffer-local options use: >
3796 getbufvar({bufnr}, '&option_name')
3797<
3798 Can also be used as a |method|: >
3799 GetBufnr()->getbufinfo()
3800<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003801 Return type: list<dict<any>>
3802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003803
3804 *getbufline()*
3805getbufline({buf}, {lnum} [, {end}])
3806 Return a |List| with the lines starting from {lnum} to {end}
3807 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003808 |List| with only the line {lnum} is returned. See
3809 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003810
3811 For the use of {buf}, see |bufname()| above.
3812
3813 For {lnum} and {end} "$" can be used for the last line of the
3814 buffer. Otherwise a number must be used.
3815
3816 When {lnum} is smaller than 1 or bigger than the number of
3817 lines in the buffer, an empty |List| is returned.
3818
3819 When {end} is greater than the number of lines in the buffer,
3820 it is treated as {end} is set to the number of lines in the
3821 buffer. When {end} is before {lnum} an empty |List| is
3822 returned.
3823
3824 This function works only for loaded buffers. For unloaded and
3825 non-existing buffers, an empty |List| is returned.
3826
3827 Example: >
3828 :let lines = getbufline(bufnr("myfile"), 1, "$")
3829
3830< Can also be used as a |method|: >
3831 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003832<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003833 Return type: list<string>
3834
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003835 *getbufoneline()*
3836getbufoneline({buf}, {lnum})
3837 Just like `getbufline()` but only get one line and return it
3838 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003839
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003840 Return type: |String|
3841
3842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003843getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3844 The result is the value of option or local buffer variable
3845 {varname} in buffer {buf}. Note that the name without "b:"
3846 must be used.
3847 The {varname} argument is a string.
3848 When {varname} is empty returns a |Dictionary| with all the
3849 buffer-local variables.
3850 When {varname} is equal to "&" returns a |Dictionary| with all
3851 the buffer-local options.
3852 Otherwise, when {varname} starts with "&" returns the value of
3853 a buffer-local option.
3854 This also works for a global or buffer-local option, but it
3855 doesn't work for a global variable, window-local variable or
3856 window-local option.
3857 For the use of {buf}, see |bufname()| above.
3858 When the buffer or variable doesn't exist {def} or an empty
3859 string is returned, there is no error message.
3860 Examples: >
3861 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003862 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003863
3864< Can also be used as a |method|: >
3865 GetBufnr()->getbufvar(varname)
3866<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003867 Return type: any, depending on {varname}
3868
3869
mikoto20001083cae2024-11-11 21:24:14 +01003870getcellpixels() *getcellpixels()*
3871 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003872 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003873
3874 Only works on Unix (terminal and gVim) and Windows (gVim only).
3875 Returns [] on other systems or on failure.
3876 Note that there could be variations across different terminals.
3877 On macOS, system Terminal.app returns sizes in points (before
3878 Retina scaling), whereas third-party terminals return raw pixel
3879 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003880
mikoto2000de094dc2024-11-14 22:13:48 +01003881 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003882
3883
Kota Kato66bb9ae2023-01-17 18:31:56 +00003884getcellwidths() *getcellwidths()*
3885 Returns a |List| of cell widths of character ranges overridden
3886 by |setcellwidths()|. The format is equal to the argument of
3887 |setcellwidths()|. If no character ranges have their cell
3888 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003889
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003890 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003891
3892
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003893getchangelist([{buf}]) *getchangelist()*
3894 Returns the |changelist| for the buffer {buf}. For the use
3895 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3896 exist, an empty list is returned.
3897
3898 The returned list contains two entries: a list with the change
3899 locations and the current position in the list. Each
3900 entry in the change list is a dictionary with the following
3901 entries:
3902 col column number
3903 coladd column offset for 'virtualedit'
3904 lnum line number
3905 If buffer {buf} is the current buffer, then the current
3906 position refers to the position in the list. For other
3907 buffers, it is set to the length of the list.
3908
3909 Can also be used as a |method|: >
3910 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003911<
3912 Return type: list<any>
3913
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003914
Doug Kearns9cd9e752024-04-07 17:42:17 +02003915getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003916 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003917 If {expr} is omitted, wait until a character is available.
3918 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003919 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003920 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003921 not consumed. Return zero if no character available.
3922 If you prefer always getting a string use |getcharstr()|.
3923
Doug Kearns9cd9e752024-04-07 17:42:17 +02003924 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003925 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003926 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003927 Otherwise a String is returned with the encoded character.
3928 For a special key it's a String with a sequence of bytes
3929 starting with 0x80 (decimal: 128). This is the same value as
3930 the String "\<Key>", e.g., "\<Left>". The returned value is
3931 also a String when a modifier (shift, control, alt) was used
3932 that is not included in the character.
3933
Doug Kearns9cd9e752024-04-07 17:42:17 +02003934 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003935 while Vim waits to see if this is the start of an escape
3936 sequence.
3937
Doug Kearns9cd9e752024-04-07 17:42:17 +02003938 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003939 one-byte character it is the character itself as a number.
3940 Use nr2char() to convert it to a String.
3941
3942 Use getcharmod() to obtain any additional modifiers.
3943
3944 When the user clicks a mouse button, the mouse event will be
3945 returned. The position can then be found in |v:mouse_col|,
3946 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3947 |getmousepos()| can also be used. Mouse move events will be
3948 ignored.
3949 This example positions the mouse as it would normally happen: >
3950 let c = getchar()
3951 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003952 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003953 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003954 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003955 endif
3956<
3957 When using bracketed paste only the first character is
3958 returned, the rest of the pasted text is dropped.
3959 |xterm-bracketed-paste|.
3960
3961 There is no prompt, you will somehow have to make clear to the
3962 user that a character has to be typed. The screen is not
3963 redrawn, e.g. when resizing the window. When using a popup
3964 window it should work better with a |popup-filter|.
3965
3966 There is no mapping for the character.
3967 Key codes are replaced, thus when the user presses the <Del>
3968 key you get the code for the <Del> key, not the raw character
3969 sequence. Examples: >
3970 getchar() == "\<Del>"
3971 getchar() == "\<S-Left>"
3972< This example redefines "f" to ignore case: >
3973 :nmap f :call FindChar()<CR>
3974 :function FindChar()
3975 : let c = nr2char(getchar())
3976 : while col('.') < col('$') - 1
3977 : normal l
3978 : if getline('.')[col('.') - 1] ==? c
3979 : break
3980 : endif
3981 : endwhile
3982 :endfunction
3983<
3984 You may also receive synthetic characters, such as
3985 |<CursorHold>|. Often you will want to ignore this and get
3986 another character: >
3987 :function GetKey()
3988 : let c = getchar()
3989 : while c == "\<CursorHold>"
3990 : let c = getchar()
3991 : endwhile
3992 : return c
3993 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003994<
3995 Return type: |Number| or |String|
3996
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003997
3998getcharmod() *getcharmod()*
3999 The result is a Number which is the state of the modifiers for
4000 the last obtained character with getchar() or in another way.
4001 These values are added together:
4002 2 shift
4003 4 control
4004 8 alt (meta)
4005 16 meta (when it's different from ALT)
4006 32 mouse double click
4007 64 mouse triple click
4008 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004009 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004010 Only the modifiers that have not been included in the
4011 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004012 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004013
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004014 Return type: |Number|
4015
4016
4017getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004018 Get the position for String {expr}. Same as |getpos()| but the
4019 column number in the returned List is a character index
4020 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004021 If |getpos()| returns a very large column number, equal to
4022 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004023 of the last character.
4024
4025 Example:
4026 With the cursor on '세' in line 5 with text "여보세요": >
4027 getcharpos('.') returns [0, 5, 3, 0]
4028 getpos('.') returns [0, 5, 7, 0]
4029<
4030 Can also be used as a |method|: >
4031 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004032<
4033 Return type: list<number>
4034
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004035
4036getcharsearch() *getcharsearch()*
4037 Return the current character search information as a {dict}
4038 with the following entries:
4039
4040 char character previously used for a character
4041 search (|t|, |f|, |T|, or |F|); empty string
4042 if no character search has been performed
4043 forward direction of character search; 1 for forward,
4044 0 for backward
4045 until type of character search; 1 for a |t| or |T|
4046 character search, 0 for an |f| or |F|
4047 character search
4048
4049 This can be useful to always have |;| and |,| search
4050 forward/backward regardless of the direction of the previous
4051 character search: >
4052 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4053 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4054< Also see |setcharsearch()|.
4055
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004056 Return type: dict<any>
4057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004058
Doug Kearns9cd9e752024-04-07 17:42:17 +02004059getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004060 Get a single character from the user or input stream as a
4061 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004062 If {expr} is omitted, wait until a character is available.
4063 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004064 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004065 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004066 available, it is not consumed. Return an empty string
4067 if no character is available.
4068 Otherwise this works like |getchar()|, except that a number
4069 result is converted to a string.
4070
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004071 Return type: |String|
4072
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004073getcmdcomplpat() *getcmdcomplpat()*
4074 Return completion pattern of the current command-line.
4075 Only works when the command line is being edited, thus
4076 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4077 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4078 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4079 Returns an empty string when completion is not defined.
4080
4081 Return type: |String|
4082
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004083
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004084getcmdcompltype() *getcmdcompltype()*
4085 Return the type of the current command-line completion.
4086 Only works when the command line is being edited, thus
4087 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004088 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004089 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004090 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004091 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004092
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004093 Return type: |String|
4094
4095
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004096getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004097 Return the current command-line input. Only works when the
4098 command line is being edited, thus requires use of
4099 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004100 Example: >
4101 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004102< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4103 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004104 Returns an empty string when entering a password or using
4105 |inputsecret()|.
4106
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004107 Return type: |String|
4108
4109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004110getcmdpos() *getcmdpos()*
4111 Return the position of the cursor in the command line as a
4112 byte count. The first column is 1.
4113 Only works when editing the command line, thus requires use of
4114 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4115 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004116 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4117 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004118
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004119 Return type: |Number|
4120
4121
Shougo Matsushita69084282024-09-23 20:34:47 +02004122getcmdprompt() *getcmdprompt()*
4123 Return the current command-line prompt when using functions
4124 like |input()| or |confirm()|.
4125 Only works when the command line is being edited, thus
4126 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4127 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4128 |setcmdpos()| and |setcmdline()|.
4129
4130 Return type: |String|
4131
4132
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004133getcmdscreenpos() *getcmdscreenpos()*
4134 Return the screen position of the cursor in the command line
4135 as a byte count. The first column is 1.
4136 Instead of |getcmdpos()|, it adds the prompt position.
4137 Only works when editing the command line, thus requires use of
4138 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4139 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004140 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4141 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004142
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004143 Return type: |Number|
4144
4145
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004146getcmdtype() *getcmdtype()*
4147 Return the current command-line type. Possible return values
4148 are:
4149 : normal Ex command
4150 > debug mode command |debug-mode|
4151 / forward search command
4152 ? backward search command
4153 @ |input()| command
4154 - |:insert| or |:append| command
4155 = |i_CTRL-R_=|
4156 Only works when editing the command line, thus requires use of
4157 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4158 Returns an empty string otherwise.
4159 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4160
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004161 Return type: |String|
4162
4163
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004164getcmdwintype() *getcmdwintype()*
4165 Return the current |command-line-window| type. Possible return
4166 values are the same as |getcmdtype()|. Returns an empty string
4167 when not in the command-line window.
4168
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004169 Return type: |String|
4170
4171
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004172getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4173 Return a list of command-line completion matches. The String
4174 {type} argument specifies what for. The following completion
4175 types are supported:
4176
4177 arglist file names in argument list
4178 augroup autocmd groups
4179 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004180 behave |:behave| suboptions
4181 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004182 color color schemes
4183 command Ex command
4184 cmdline |cmdline-completion| result
4185 compiler compilers
4186 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004187 custom,{func} custom completion, defined via {func}
4188 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004189 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004190 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004191 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004192 environment environment variable names
4193 event autocommand events
4194 expression Vim expression
4195 file file and directory names
4196 file_in_path file and directory names in |'path'|
4197 filetype filetype names |'filetype'|
4198 function function name
4199 help help subjects
4200 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004201 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004202 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004203 locale locale names (as output of locale -a)
4204 mapclear buffer argument
4205 mapping mapping name
4206 menu menus
4207 messages |:messages| suboptions
4208 option options
4209 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004210 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004211 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004212 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004213 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004214 sign |:sign| suboptions
4215 syntax syntax file names |'syntax'|
4216 syntime |:syntime| suboptions
4217 tag tags
4218 tag_listfiles tags, file names
4219 user user names
4220 var user variables
4221
4222 If {pat} is an empty string, then all the matches are
4223 returned. Otherwise only items matching {pat} are returned.
4224 See |wildcards| for the use of special characters in {pat}.
4225
4226 If the optional {filtered} flag is set to 1, then 'wildignore'
4227 is applied to filter the results. Otherwise all the matches
4228 are returned. The 'wildignorecase' option always applies.
4229
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004230 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4231 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004232 regular expression matching is used. Thus this function
4233 follows the user preference, what happens on the command line.
4234 If you do not want this you can make 'wildoptions' empty
4235 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004237 If {type} is "cmdline", then the |cmdline-completion| result is
4238 returned. For example, to complete the possible values after
4239 a ":call" command: >
4240 echo getcompletion('call ', 'cmdline')
4241<
4242 If there are no matches, an empty list is returned. An
4243 invalid value for {type} produces an error.
4244
4245 Can also be used as a |method|: >
4246 GetPattern()->getcompletion('color')
4247<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004248 Return type: list<string>
4249
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004250 *getcurpos()*
4251getcurpos([{winid}])
4252 Get the position of the cursor. This is like getpos('.'), but
4253 includes an extra "curswant" item in the list:
4254 [0, lnum, col, off, curswant] ~
4255 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004256 cursor vertically. After |$| command it will be a very large
4257 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004258 |getpos()|.
4259 The first "bufnum" item is always zero. The byte position of
4260 the cursor is returned in 'col'. To get the character
4261 position, use |getcursorcharpos()|.
4262
4263 The optional {winid} argument can specify the window. It can
4264 be the window number or the |window-ID|. The last known
4265 cursor position is returned, this may be invalid for the
4266 current value of the buffer if it is not the current window.
4267 If {winid} is invalid a list with zeroes is returned.
4268
4269 This can be used to save and restore the cursor position: >
4270 let save_cursor = getcurpos()
4271 MoveTheCursorAround
4272 call setpos('.', save_cursor)
4273< Note that this only works within the window. See
4274 |winrestview()| for restoring more state.
4275
4276 Can also be used as a |method|: >
4277 GetWinid()->getcurpos()
4278<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004279 Return type: list<number>
4280
4281
4282getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004283 Same as |getcurpos()| but the column number in the returned
4284 List is a character index instead of a byte index.
4285
4286 Example:
4287 With the cursor on '보' in line 3 with text "여보세요": >
4288 getcursorcharpos() returns [0, 3, 2, 0, 3]
4289 getcurpos() returns [0, 3, 4, 0, 3]
4290<
4291 Can also be used as a |method|: >
4292 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004293<
4294 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004295
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004296
4297getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004298 The result is a String, which is the name of the current
4299 working directory. 'autochdir' is ignored.
4300
4301 With {winnr} return the local current directory of this window
4302 in the current tab page. {winnr} can be the window number or
4303 the |window-ID|.
4304 If {winnr} is -1 return the name of the global working
4305 directory. See also |haslocaldir()|.
4306
4307 With {winnr} and {tabnr} return the local current directory of
4308 the window in the specified tab page. If {winnr} is -1 return
4309 the working directory of the tabpage.
4310 If {winnr} is zero use the current window, if {tabnr} is zero
4311 use the current tabpage.
4312 Without any arguments, return the actual working directory of
4313 the current window.
4314 Return an empty string if the arguments are invalid.
4315
4316 Examples: >
4317 " Get the working directory of the current window
4318 :echo getcwd()
4319 :echo getcwd(0)
4320 :echo getcwd(0, 0)
4321 " Get the working directory of window 3 in tabpage 2
4322 :echo getcwd(3, 2)
4323 " Get the global working directory
4324 :echo getcwd(-1)
4325 " Get the working directory of tabpage 3
4326 :echo getcwd(-1, 3)
4327 " Get the working directory of current tabpage
4328 :echo getcwd(-1, 0)
4329
4330< Can also be used as a |method|: >
4331 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004332<
4333 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004334
4335getenv({name}) *getenv()*
4336 Return the value of environment variable {name}. The {name}
4337 argument is a string, without a leading '$'. Example: >
4338 myHome = getenv('HOME')
4339
4340< When the variable does not exist |v:null| is returned. That
4341 is different from a variable set to an empty string, although
4342 some systems interpret the empty value as the variable being
4343 deleted. See also |expr-env|.
4344
4345 Can also be used as a |method|: >
4346 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004347<
4348 Return type: |String| or |Number|
4349
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004350
4351getfontname([{name}]) *getfontname()*
4352 Without an argument returns the name of the normal font being
4353 used. Like what is used for the Normal highlight group
4354 |hl-Normal|.
4355 With an argument a check is done whether String {name} is a
4356 valid font name. If not then an empty string is returned.
4357 Otherwise the actual font name is returned, or {name} if the
4358 GUI does not support obtaining the real name.
4359 Only works when the GUI is running, thus not in your vimrc or
4360 gvimrc file. Use the |GUIEnter| autocommand to use this
4361 function just after the GUI has started.
4362 Note that the GTK GUI accepts any font name, thus checking for
4363 a valid name does not work.
4364
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004365 Return type: |String|
4366
4367
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004368getfperm({fname}) *getfperm()*
4369 The result is a String, which is the read, write, and execute
4370 permissions of the given file {fname}.
4371 If {fname} does not exist or its directory cannot be read, an
4372 empty string is returned.
4373 The result is of the form "rwxrwxrwx", where each group of
4374 "rwx" flags represent, in turn, the permissions of the owner
4375 of the file, the group the file belongs to, and other users.
4376 If a user does not have a given permission the flag for this
4377 is replaced with the string "-". Examples: >
4378 :echo getfperm("/etc/passwd")
4379 :echo getfperm(expand("~/.vimrc"))
4380< This will hopefully (from a security point of view) display
4381 the string "rw-r--r--" or even "rw-------".
4382
4383 Can also be used as a |method|: >
4384 GetFilename()->getfperm()
4385<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004386 Return type: |String|
4387
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004388 For setting permissions use |setfperm()|.
4389
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004390
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004391getfsize({fname}) *getfsize()*
4392 The result is a Number, which is the size in bytes of the
4393 given file {fname}.
4394 If {fname} is a directory, 0 is returned.
4395 If the file {fname} can't be found, -1 is returned.
4396 If the size of {fname} is too big to fit in a Number then -2
4397 is returned.
4398
4399 Can also be used as a |method|: >
4400 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004401<
4402 Return type: |Number|
4403
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004404
4405getftime({fname}) *getftime()*
4406 The result is a Number, which is the last modification time of
4407 the given file {fname}. The value is measured as seconds
4408 since 1st Jan 1970, and may be passed to strftime(). See also
4409 |localtime()| and |strftime()|.
4410 If the file {fname} can't be found -1 is returned.
4411
4412 Can also be used as a |method|: >
4413 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004414<
4415 Return type: |Number|
4416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004417
4418getftype({fname}) *getftype()*
4419 The result is a String, which is a description of the kind of
4420 file of the given file {fname}.
4421 If {fname} does not exist an empty string is returned.
4422 Here is a table over different kinds of files and their
4423 results:
4424 Normal file "file"
4425 Directory "dir"
4426 Symbolic link "link"
4427 Block device "bdev"
4428 Character device "cdev"
4429 Socket "socket"
4430 FIFO "fifo"
4431 All other "other"
4432 Example: >
4433 getftype("/home")
4434< Note that a type such as "link" will only be returned on
4435 systems that support it. On some systems only "dir" and
4436 "file" are returned. On MS-Windows a symbolic link to a
4437 directory returns "dir" instead of "link".
4438
4439 Can also be used as a |method|: >
4440 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004441<
4442 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004443
4444getimstatus() *getimstatus()*
4445 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004446 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004447 See 'imstatusfunc'.
4448
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004449 Return type: |Number|
4450
4451
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004452getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4453 Returns the |jumplist| for the specified window.
4454
4455 Without arguments use the current window.
4456 With {winnr} only use this window in the current tab page.
4457 {winnr} can also be a |window-ID|.
4458 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004459 page. If {winnr} or {tabnr} is invalid, an empty list is
4460 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004461
4462 The returned list contains two entries: a list with the jump
4463 locations and the last used jump position number in the list.
4464 Each entry in the jump location list is a dictionary with
4465 the following entries:
4466 bufnr buffer number
4467 col column number
4468 coladd column offset for 'virtualedit'
4469 filename filename if available
4470 lnum line number
4471
4472 Can also be used as a |method|: >
4473 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004474<
4475 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004476
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004477 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004478getline({lnum} [, {end}])
4479 Without {end} the result is a String, which is line {lnum}
4480 from the current buffer. Example: >
4481 getline(1)
4482< When {lnum} is a String that doesn't start with a
4483 digit, |line()| is called to translate the String into a Number.
4484 To get the line under the cursor: >
4485 getline(".")
4486< When {lnum} is a number smaller than 1 or bigger than the
4487 number of lines in the buffer, an empty string is returned.
4488
4489 When {end} is given the result is a |List| where each item is
4490 a line from the current buffer in the range {lnum} to {end},
4491 including line {end}.
4492 {end} is used in the same way as {lnum}.
4493 Non-existing lines are silently omitted.
4494 When {end} is before {lnum} an empty |List| is returned.
4495 Example: >
4496 :let start = line('.')
4497 :let end = search("^$") - 1
4498 :let lines = getline(start, end)
4499
4500< Can also be used as a |method|: >
4501 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004502<
4503 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004504
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004505 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004506 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004507
4508getloclist({nr} [, {what}]) *getloclist()*
4509 Returns a |List| with all the entries in the location list for
4510 window {nr}. {nr} can be the window number or the |window-ID|.
4511 When {nr} is zero the current window is used.
4512
4513 For a location list window, the displayed location list is
4514 returned. For an invalid window number {nr}, an empty list is
4515 returned. Otherwise, same as |getqflist()|.
4516
4517 If the optional {what} dictionary argument is supplied, then
4518 returns the items listed in {what} as a dictionary. Refer to
4519 |getqflist()| for the supported items in {what}.
4520
4521 In addition to the items supported by |getqflist()| in {what},
4522 the following item is supported by |getloclist()|:
4523
4524 filewinid id of the window used to display files
4525 from the location list. This field is
4526 applicable only when called from a
4527 location list window. See
4528 |location-list-file-window| for more
4529 details.
4530
4531 Returns a |Dictionary| with default values if there is no
4532 location list for the window {nr}.
4533 Returns an empty Dictionary if window {nr} does not exist.
4534
4535 Examples (See also |getqflist-examples|): >
4536 :echo getloclist(3, {'all': 0})
4537 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004538<
4539 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004540
4541
4542getmarklist([{buf}]) *getmarklist()*
4543 Without the {buf} argument returns a |List| with information
4544 about all the global marks. |mark|
4545
4546 If the optional {buf} argument is specified, returns the
4547 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004548 see |bufname()|. If {buf} is invalid, an empty list is
4549 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004550
4551 Each item in the returned List is a |Dict| with the following:
4552 mark name of the mark prefixed by "'"
4553 pos a |List| with the position of the mark:
4554 [bufnum, lnum, col, off]
4555 Refer to |getpos()| for more information.
4556 file file name
4557
4558 Refer to |getpos()| for getting information about a specific
4559 mark.
4560
4561 Can also be used as a |method|: >
4562 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004563<
4564 Return type: list<dict<any>> or list<any>
4565
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004566
4567getmatches([{win}]) *getmatches()*
4568 Returns a |List| with all matches previously defined for the
4569 current window by |matchadd()| and the |:match| commands.
4570 |getmatches()| is useful in combination with |setmatches()|,
4571 as |setmatches()| can restore a list of matches saved by
4572 |getmatches()|.
4573 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004574 window ID instead of the current window. If {win} is invalid,
4575 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004576 Example: >
4577 :echo getmatches()
4578< [{'group': 'MyGroup1', 'pattern': 'TODO',
4579 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4580 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4581 :let m = getmatches()
4582 :call clearmatches()
4583 :echo getmatches()
4584< [] >
4585 :call setmatches(m)
4586 :echo getmatches()
4587< [{'group': 'MyGroup1', 'pattern': 'TODO',
4588 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4589 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4590 :unlet m
4591<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004592 Return type: list<dict<any>> or list<any>
4593
4594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004595getmousepos() *getmousepos()*
4596 Returns a |Dictionary| with the last known position of the
4597 mouse. This can be used in a mapping for a mouse click or in
4598 a filter of a popup window. The items are:
4599 screenrow screen row
4600 screencol screen column
4601 winid Window ID of the click
4602 winrow row inside "winid"
4603 wincol column inside "winid"
4604 line text line inside "winid"
4605 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004606 coladd offset (in screen columns) from the
4607 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004608 All numbers are 1-based.
4609
4610 If not over a window, e.g. when in the command line, then only
4611 "screenrow" and "screencol" are valid, the others are zero.
4612
4613 When on the status line below a window or the vertical
4614 separator right of a window, the "line" and "column" values
4615 are zero.
4616
4617 When the position is after the text then "column" is the
4618 length of the text in bytes plus one.
4619
4620 If the mouse is over a popup window then that window is used.
4621
4622 When using |getchar()| the Vim variables |v:mouse_lnum|,
4623 |v:mouse_col| and |v:mouse_winid| also provide these values.
4624
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004625 Return type: dict<number>
4626
4627
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004628getmouseshape() *getmouseshape()*
4629 Returns the name of the currently showing mouse pointer.
4630 When the |+mouseshape| feature is not supported or the shape
4631 is unknown an empty string is returned.
4632 This function is mainly intended for testing.
4633
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004634 Return type: |String|
4635
4636
4637getpid() *getpid()*
4638 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004639 On Unix and MS-Windows this is a unique number, until Vim
4640 exits.
4641
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004642 Return type: |Number|
4643
4644
4645getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004646 Get the position for String {expr}.
4647 The accepted values for {expr} are: *E1209*
4648 . The cursor position.
4649 $ The last line in the current buffer.
4650 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004651 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004652 w0 First line visible in current window (one if the
4653 display isn't updated, e.g. in silent Ex mode).
4654 w$ Last line visible in current window (this is one
4655 less than "w0" if no lines are visible).
4656 v When not in Visual mode, returns the cursor
4657 position. In Visual mode, returns the other end
4658 of the Visual area. A good way to think about
4659 this is that in Visual mode "v" and "." complement
4660 each other. While "." refers to the cursor
4661 position, "v" refers to where |v_o| would move the
4662 cursor. As a result, you can use "v" and "."
4663 together to work on all of a selection in
4664 characterwise Visual mode. If the cursor is at
4665 the end of a characterwise Visual area, "v" refers
4666 to the start of the same Visual area. And if the
4667 cursor is at the start of a characterwise Visual
4668 area, "v" refers to the end of the same Visual
4669 area. "v" differs from |'<| and |'>| in that it's
4670 updated right away.
4671 Note that a mark in another file can be used. The line number
4672 then applies to another buffer.
4673
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004674 The result is a |List| with four numbers:
4675 [bufnum, lnum, col, off]
4676 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4677 is the buffer number of the mark.
4678 "lnum" and "col" are the position in the buffer. The first
4679 column is 1.
4680 The "off" number is zero, unless 'virtualedit' is used. Then
4681 it is the offset in screen columns from the start of the
4682 character. E.g., a position within a <Tab> or after the last
4683 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004684
4685 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004686 The column number in the returned List is the byte position
4687 within the line. To get the character position in the line,
4688 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004689
4690 Note that for '< and '> Visual mode matters: when it is "V"
4691 (visual line mode) the column of '< is zero and the column of
4692 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004693 A very large column number equal to |v:maxcol| can be returned,
4694 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004695 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004696
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004697 This can be used to save and restore the position of a mark: >
4698 let save_a_mark = getpos("'a")
4699 ...
4700 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004701<
4702 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004703
4704 Can also be used as a |method|: >
4705 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004706<
4707 Return type: list<number>
4708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004709
4710getqflist([{what}]) *getqflist()*
4711 Returns a |List| with all the current quickfix errors. Each
4712 list item is a dictionary with these entries:
4713 bufnr number of buffer that has the file name, use
4714 bufname() to get the name
4715 module module name
4716 lnum line number in the buffer (first line is 1)
4717 end_lnum
4718 end of line number if the item is multiline
4719 col column number (first column is 1)
4720 end_col end of column number if the item has range
4721 vcol |TRUE|: "col" is visual column
4722 |FALSE|: "col" is byte index
4723 nr error number
h-east84ac2122024-06-17 18:12:30 +02004724 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004725 text description of the error
4726 type type of the error, 'E', '1', etc.
4727 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004728 user_data
4729 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004730 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004731
4732 When there is no error list or it's empty, an empty list is
4733 returned. Quickfix list entries with a non-existing buffer
4734 number are returned with "bufnr" set to zero (Note: some
4735 functions accept buffer number zero for the alternate buffer,
4736 you may need to explicitly check for zero).
4737
4738 Useful application: Find pattern matches in multiple files and
4739 do something with them: >
4740 :vimgrep /theword/jg *.c
4741 :for d in getqflist()
4742 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4743 :endfor
4744<
4745 If the optional {what} dictionary argument is supplied, then
4746 returns only the items listed in {what} as a dictionary. The
4747 following string items are supported in {what}:
4748 changedtick get the total number of changes made
4749 to the list |quickfix-changedtick|
4750 context get the |quickfix-context|
4751 efm errorformat to use when parsing "lines". If
4752 not present, then the 'errorformat' option
4753 value is used.
4754 id get information for the quickfix list with
4755 |quickfix-ID|; zero means the id for the
4756 current list or the list specified by "nr"
4757 idx get information for the quickfix entry at this
4758 index in the list specified by 'id' or 'nr'.
4759 If set to zero, then uses the current entry.
4760 See |quickfix-index|
4761 items quickfix list entries
4762 lines parse a list of lines using 'efm' and return
4763 the resulting entries. Only a |List| type is
4764 accepted. The current quickfix list is not
4765 modified. See |quickfix-parse|.
4766 nr get information for this quickfix list; zero
4767 means the current quickfix list and "$" means
4768 the last quickfix list
4769 qfbufnr number of the buffer displayed in the quickfix
4770 window. Returns 0 if the quickfix buffer is
4771 not present. See |quickfix-buffer|.
4772 size number of entries in the quickfix list
4773 title get the list title |quickfix-title|
4774 winid get the quickfix |window-ID|
4775 all all of the above quickfix properties
4776 Non-string items in {what} are ignored. To get the value of a
4777 particular item, set it to zero.
4778 If "nr" is not present then the current quickfix list is used.
4779 If both "nr" and a non-zero "id" are specified, then the list
4780 specified by "id" is used.
4781 To get the number of lists in the quickfix stack, set "nr" to
4782 "$" in {what}. The "nr" value in the returned dictionary
4783 contains the quickfix stack size.
4784 When "lines" is specified, all the other items except "efm"
4785 are ignored. The returned dictionary contains the entry
4786 "items" with the list of entries.
4787
4788 The returned dictionary contains the following entries:
4789 changedtick total number of changes made to the
4790 list |quickfix-changedtick|
4791 context quickfix list context. See |quickfix-context|
4792 If not present, set to "".
4793 id quickfix list ID |quickfix-ID|. If not
4794 present, set to 0.
4795 idx index of the quickfix entry in the list. If not
4796 present, set to 0.
4797 items quickfix list entries. If not present, set to
4798 an empty list.
4799 nr quickfix list number. If not present, set to 0
4800 qfbufnr number of the buffer displayed in the quickfix
4801 window. If not present, set to 0.
4802 size number of entries in the quickfix list. If not
4803 present, set to 0.
4804 title quickfix list title text. If not present, set
4805 to "".
4806 winid quickfix |window-ID|. If not present, set to 0
4807
4808 Examples (See also |getqflist-examples|): >
4809 :echo getqflist({'all': 1})
4810 :echo getqflist({'nr': 2, 'title': 1})
4811 :echo getqflist({'lines' : ["F1:10:L10"]})
4812<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004813 Return type: list<dict<any>> or list<any>
4814
4815
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004816getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4817 The result is a String, which is the contents of register
4818 {regname}. Example: >
4819 :let cliptext = getreg('*')
4820< When register {regname} was not set the result is an empty
4821 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004822 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004823
4824 getreg('=') returns the last evaluated value of the expression
4825 register. (For use in maps.)
4826 getreg('=', 1) returns the expression itself, so that it can
4827 be restored with |setreg()|. For other registers the extra
4828 argument is ignored, thus you can always give it.
4829
4830 If {list} is present and |TRUE|, the result type is changed
4831 to |List|. Each list item is one text line. Use it if you care
4832 about zero bytes possibly present inside register: without
4833 third argument both NLs and zero bytes are represented as NLs
4834 (see |NL-used-for-Nul|).
4835 When the register was not set an empty list is returned.
4836
4837 If {regname} is "", the unnamed register '"' is used.
4838 If {regname} is not specified, |v:register| is used.
4839 In |Vim9-script| {regname} must be one character.
4840
4841 Can also be used as a |method|: >
4842 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004843<
4844 Return type: |String|
4845
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004846
4847getreginfo([{regname}]) *getreginfo()*
4848 Returns detailed information about register {regname} as a
4849 Dictionary with the following entries:
4850 regcontents List of lines contained in register
4851 {regname}, like
4852 |getreg|({regname}, 1, 1).
4853 regtype the type of register {regname}, as in
4854 |getregtype()|.
4855 isunnamed Boolean flag, v:true if this register
4856 is currently pointed to by the unnamed
4857 register.
4858 points_to for the unnamed register, gives the
4859 single letter name of the register
4860 currently pointed to (see |quotequote|).
4861 For example, after deleting a line
4862 with `dd`, this field will be "1",
4863 which is the register that got the
4864 deleted text.
4865
4866 The {regname} argument is a string. If {regname} is invalid
4867 or not set, an empty Dictionary will be returned.
4868 If {regname} is "" or "@", the unnamed register '"' is used.
4869 If {regname} is not specified, |v:register| is used.
4870 The returned Dictionary can be passed to |setreg()|.
4871 In |Vim9-script| {regname} must be one character.
4872
4873 Can also be used as a |method|: >
4874 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004875<
4876 Return type: dict<any>
4877
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004878
Shougo Matsushita19b71882024-02-28 22:48:12 +01004879getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004880 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004881 buffer.
4882
4883 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004884 See |getpos()| for the format of the list. It's possible
4885 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004886 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004887
4888 The optional argument {opts} is a Dict and supports the
4889 following items:
4890
zeertzjqafc22952024-05-24 19:07:12 +02004891 type Specify the region's selection type.
4892 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004893 except that the width can be omitted
4894 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004895 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004896
zeertzjq87410ab2024-03-02 06:00:23 +08004897 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004898 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004899 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004900
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004901 You can get the last selection type by |visualmode()|.
4902 If Visual mode is active, use |mode()| to get the Visual mode
4903 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004904 This function is useful to get text starting and ending in
4905 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004906
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004907 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004908 Note that:
4909 - Order of {pos1} and {pos2} doesn't matter, it will always
4910 return content from the upper left position to the lower
4911 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004912 - If 'virtualedit' is enabled and the region is past the end
4913 of the lines, resulting lines are padded with spaces.
4914 - If the region is blockwise and it starts or ends in the
4915 middle of a multi-cell character, it is not included but
4916 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004917 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004918 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004919 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004920 - It is evaluated in current window context, which makes a
4921 difference if the buffer is displayed in a window with
4922 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004923
4924 Examples: >
4925 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004926 \ <Cmd>echow getregion(
4927 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004928<
4929 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004930 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004931<
4932 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004933
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004934
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004935getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4936 Same as |getregion()|, but returns a list of positions
4937 describing the buffer text segments bound by {pos1} and
4938 {pos2}.
4939 The segments are a pair of positions for every line: >
4940 [[{start_pos}, {end_pos}], ...]
4941<
4942 The position is a |List| with four numbers:
4943 [bufnum, lnum, col, off]
4944 "bufnum" is the buffer number.
4945 "lnum" and "col" are the position in the buffer. The first
4946 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004947 If the "off" number of a starting position is non-zero, it is
4948 the offset in screen columns from the start of the character.
4949 E.g., a position within a <Tab> or after the last character.
4950 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004951 the offset of the character's first cell not included in the
4952 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004953
zeertzjq2b09de92024-05-24 07:48:51 +02004954 Apart from the options supported by |getregion()|, {opts} also
4955 supports the following:
4956
4957 eol If |TRUE|, indicate positions beyond
4958 the end of a line with "col" values
4959 one more than the length of the line.
4960 If |FALSE|, positions are limited
4961 within their lines, and if a line is
4962 empty or the selection is entirely
4963 beyond the end of a line, a "col"
4964 value of 0 is used for both positions.
4965 (default: |FALSE|)
4966
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004967 Can also be used as a |method|: >
4968 getpos('.')->getregionpos(getpos("'a"))
4969<
zeertzjqd4d12072024-07-16 20:34:16 +02004970 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004971
4972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004973getregtype([{regname}]) *getregtype()*
4974 The result is a String, which is type of register {regname}.
4975 The value will be one of:
4976 "v" for |characterwise| text
4977 "V" for |linewise| text
4978 "<CTRL-V>{width}" for |blockwise-visual| text
4979 "" for an empty or unknown register
4980 <CTRL-V> is one character with value 0x16.
4981 The {regname} argument is a string. If {regname} is "", the
4982 unnamed register '"' is used. If {regname} is not specified,
4983 |v:register| is used.
4984 In |Vim9-script| {regname} must be one character.
4985
4986 Can also be used as a |method|: >
4987 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004988<
4989 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004990
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004991
Bram Moolenaar71badf92023-04-22 22:40:14 +01004992getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004993 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004994 scripts in the order they were sourced, like what
4995 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004996
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004997 The optional Dict argument {opts} supports the following
4998 optional items:
4999 name Script name match pattern. If specified,
5000 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005001 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005002 "name" are returned.
5003 sid Script ID |<SID>|. If specified, only
5004 information about the script with ID "sid" is
5005 returned and "name" is ignored.
5006
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005007 Each item in the returned List is a |Dict| with the following
5008 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005009 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005010 `import autoload` but was not actually sourced
5011 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005012 functions List of script-local function names defined in
5013 the script. Present only when a particular
5014 script is specified using the "sid" item in
5015 {opts}.
5016 name Vim script file name.
5017 sid Script ID |<SID>|.
5018 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005019 this script name links to, if any, otherwise
5020 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005021 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005022 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005023 specified using the "sid" item in {opts}.
5024 Note that this is a copy, the value of
5025 script-local variables cannot be changed using
5026 this dictionary.
h_east59858792023-10-25 22:47:05 +09005027 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005028
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005029 Examples: >
5030 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005031 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005032<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005033 Return type: list<dict<any>>
5034
5035
ichizok663d18d2025-01-02 18:06:00 +01005036getstacktrace() *getstacktrace()*
5037 Returns the current stack trace of Vim scripts.
5038 Stack trace is a |List|, of which each item is a |Dictionary|
5039 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005040 funcref The funcref if the stack is at a function,
5041 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005042 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005043 stack is at an autocmd event, otherwise this
5044 item is omitted.
5045 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005046 filepath The file path of the script on the stack.
5047
5048 Return type: list<dict<any>>
5049
5050
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005051gettabinfo([{tabnr}]) *gettabinfo()*
5052 If {tabnr} is not specified, then information about all the
5053 tab pages is returned as a |List|. Each List item is a
5054 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5055 number and information about that one is returned. If the tab
5056 page does not exist an empty List is returned.
5057
5058 Each List item is a |Dictionary| with the following entries:
5059 tabnr tab page number.
5060 variables a reference to the dictionary with
5061 tabpage-local variables
5062 windows List of |window-ID|s in the tab page.
5063
5064 Can also be used as a |method|: >
5065 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005066<
5067 Return type: list<dict<any>>
5068
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005069
5070gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5071 Get the value of a tab-local variable {varname} in tab page
5072 {tabnr}. |t:var|
5073 Tabs are numbered starting with one.
5074 The {varname} argument is a string. When {varname} is empty a
5075 dictionary with all tab-local variables is returned.
5076 Note that the name without "t:" must be used.
5077 When the tab or variable doesn't exist {def} or an empty
5078 string is returned, there is no error message.
5079
5080 Can also be used as a |method|: >
5081 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005082<
5083 Return type: any, depending on {varname}
5084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005085
5086gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5087 Get the value of window-local variable {varname} in window
5088 {winnr} in tab page {tabnr}.
5089 The {varname} argument is a string. When {varname} is empty a
5090 dictionary with all window-local variables is returned.
5091 When {varname} is equal to "&" get the values of all
5092 window-local options in a |Dictionary|.
5093 Otherwise, when {varname} starts with "&" get the value of a
5094 window-local option.
5095 Note that {varname} must be the name without "w:".
5096 Tabs are numbered starting with one. For the current tabpage
5097 use |getwinvar()|.
5098 {winnr} can be the window number or the |window-ID|.
5099 When {winnr} is zero the current window is used.
5100 This also works for a global option, buffer-local option and
5101 window-local option, but it doesn't work for a global variable
5102 or buffer-local variable.
5103 When the tab, window or variable doesn't exist {def} or an
5104 empty string is returned, there is no error message.
5105 Examples: >
5106 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005107 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005108<
5109 To obtain all window-local variables use: >
5110 gettabwinvar({tabnr}, {winnr}, '&')
5111
5112< Can also be used as a |method|: >
5113 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005114<
5115 Return type: any, depending on {varname}
5116
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005117
5118gettagstack([{winnr}]) *gettagstack()*
5119 The result is a Dict, which is the tag stack of window {winnr}.
5120 {winnr} can be the window number or the |window-ID|.
5121 When {winnr} is not specified, the current window is used.
5122 When window {winnr} doesn't exist, an empty Dict is returned.
5123
5124 The returned dictionary contains the following entries:
5125 curidx Current index in the stack. When at
5126 top of the stack, set to (length + 1).
5127 Index of bottom of the stack is 1.
5128 items List of items in the stack. Each item
5129 is a dictionary containing the
5130 entries described below.
5131 length Number of entries in the stack.
5132
5133 Each item in the stack is a dictionary with the following
5134 entries:
5135 bufnr buffer number of the current jump
5136 from cursor position before the tag jump.
5137 See |getpos()| for the format of the
5138 returned list.
5139 matchnr current matching tag number. Used when
5140 multiple matching tags are found for a
5141 name.
5142 tagname name of the tag
5143
5144 See |tagstack| for more information about the tag stack.
5145
5146 Can also be used as a |method|: >
5147 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005148<
5149 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005150
5151
Christ van Willegence0ef912024-06-20 23:41:59 +02005152gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005153 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005154 This is intended for use in Vim scripts. When generating
5155 message translations the {text} is extracted by `xgettext`,
5156 the translator can add translated messages into the .po file
5157 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005158 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005159 `xgettext` does not support single quoted escaped text.
5160
Christ van Willegence0ef912024-06-20 23:41:59 +02005161 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005162 for that specific package. This is mainly required for
5163 third-party Vim scripts. You need to specify a path to the
5164 translations with the |bindtextdomain()| function before
5165 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005166
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005167 Return type: |String|
5168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005169
5170getwininfo([{winid}]) *getwininfo()*
5171 Returns information about windows as a |List| with Dictionaries.
5172
5173 If {winid} is given Information about the window with that ID
5174 is returned, as a |List| with one item. If the window does not
5175 exist the result is an empty list.
5176
5177 Without {winid} information about all the windows in all the
5178 tab pages is returned.
5179
5180 Each List item is a |Dictionary| with the following entries:
5181 botline last complete displayed buffer line
5182 bufnr number of buffer in the window
5183 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005184 leftcol first column displayed; only used when
5185 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005186 loclist 1 if showing a location list
5187 {only with the +quickfix feature}
5188 quickfix 1 if quickfix or location list window
5189 {only with the +quickfix feature}
5190 terminal 1 if a terminal window
5191 {only with the +terminal feature}
5192 tabnr tab page number
5193 topline first displayed buffer line
5194 variables a reference to the dictionary with
5195 window-local variables
5196 width window width
5197 winbar 1 if the window has a toolbar, 0
5198 otherwise
5199 wincol leftmost screen column of the window;
5200 "col" from |win_screenpos()|
5201 textoff number of columns occupied by any
5202 'foldcolumn', 'signcolumn' and line
5203 number in front of the text
5204 winid |window-ID|
5205 winnr window number
5206 winrow topmost screen line of the window;
5207 "row" from |win_screenpos()|
5208
5209 Can also be used as a |method|: >
5210 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005211<
5212 Return type: list<dict<any>>
5213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005214
5215getwinpos([{timeout}]) *getwinpos()*
5216 The result is a |List| with two numbers, the result of
5217 |getwinposx()| and |getwinposy()| combined:
5218 [x-pos, y-pos]
5219 {timeout} can be used to specify how long to wait in msec for
5220 a response from the terminal. When omitted 100 msec is used.
5221 Use a longer time for a remote terminal.
5222 When using a value less than 10 and no response is received
5223 within that time, a previously reported position is returned,
5224 if available. This can be used to poll for the position and
5225 do some work in the meantime: >
5226 while 1
5227 let res = getwinpos(1)
5228 if res[0] >= 0
5229 break
5230 endif
5231 " Do some work here
5232 endwhile
5233<
5234
5235 Can also be used as a |method|: >
5236 GetTimeout()->getwinpos()
5237<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005238 Return type: list<number>
5239
5240
5241getwinposx() *getwinposx()*
5242 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005243 the left hand side of the GUI Vim window. Also works for an
5244 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005245 The result will be -1 if the information is not available
5246 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005247 The value can be used with `:winpos`.
5248
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005249 Return type: |Number|
5250
5251
5252getwinposy() *getwinposy()*
5253 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005254 the top of the GUI Vim window. Also works for an xterm (uses
5255 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005256 The result will be -1 if the information is not available
5257 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005258 The value can be used with `:winpos`.
5259
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005260 Return type: |Number|
5261
5262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005263getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5264 Like |gettabwinvar()| for the current tabpage.
5265 Examples: >
5266 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005267 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005268
5269< Can also be used as a |method|: >
5270 GetWinnr()->getwinvar(varname)
5271<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005272 Return type: any, depending on {varname}
5273
5274
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005275glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5276 Expand the file wildcards in {expr}. See |wildcards| for the
5277 use of special characters.
5278
5279 Unless the optional {nosuf} argument is given and is |TRUE|,
5280 the 'suffixes' and 'wildignore' options apply: Names matching
5281 one of the patterns in 'wildignore' will be skipped and
5282 'suffixes' affect the ordering of matches.
5283 'wildignorecase' always applies.
5284
5285 When {list} is present and it is |TRUE| the result is a |List|
5286 with all matching files. The advantage of using a List is,
5287 you also get filenames containing newlines correctly.
5288 Otherwise the result is a String and when there are several
5289 matches, they are separated by <NL> characters.
5290
5291 If the expansion fails, the result is an empty String or List.
5292
5293 You can also use |readdir()| if you need to do complicated
5294 things, such as limiting the number of matches.
5295
5296 A name for a non-existing file is not included. A symbolic
5297 link is only included if it points to an existing file.
5298 However, when the {alllinks} argument is present and it is
5299 |TRUE| then all symbolic links are included.
5300
5301 For most systems backticks can be used to get files names from
5302 any external command. Example: >
5303 :let tagfiles = glob("`find . -name tags -print`")
5304 :let &tags = substitute(tagfiles, "\n", ",", "g")
5305< The result of the program inside the backticks should be one
5306 item per line. Spaces inside an item are allowed.
5307
5308 See |expand()| for expanding special Vim variables. See
5309 |system()| for getting the raw output of an external command.
5310
5311 Can also be used as a |method|: >
5312 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005313<
5314 Return type: |String| or list<string> or list<any> depending
5315 on {list}
5316
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005317
h-east624bb832024-11-09 18:37:32 +01005318glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005319 Convert a file pattern, as used by glob(), into a search
5320 pattern. The result can be used to match with a string that
5321 is a file name. E.g. >
5322 if filename =~ glob2regpat('Make*.mak')
5323< This is equivalent to: >
5324 if filename =~ '^Make.*\.mak$'
5325< When {string} is an empty string the result is "^$", match an
5326 empty string.
5327 Note that the result depends on the system. On MS-Windows
5328 a backslash usually means a path separator.
5329
5330 Can also be used as a |method|: >
5331 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005332<
5333 Return type: |String|
5334
5335 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005336globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5337 Perform glob() for String {expr} on all directories in {path}
5338 and concatenate the results. Example: >
5339 :echo globpath(&rtp, "syntax/c.vim")
5340<
5341 {path} is a comma-separated list of directory names. Each
5342 directory name is prepended to {expr} and expanded like with
5343 |glob()|. A path separator is inserted when needed.
5344 To add a comma inside a directory name escape it with a
5345 backslash. Note that on MS-Windows a directory may have a
5346 trailing backslash, remove it if you put a comma after it.
5347 If the expansion fails for one of the directories, there is no
5348 error message.
5349
5350 Unless the optional {nosuf} argument is given and is |TRUE|,
5351 the 'suffixes' and 'wildignore' options apply: Names matching
5352 one of the patterns in 'wildignore' will be skipped and
5353 'suffixes' affect the ordering of matches.
5354
5355 When {list} is present and it is |TRUE| the result is a |List|
5356 with all matching files. The advantage of using a List is, you
5357 also get filenames containing newlines correctly. Otherwise
5358 the result is a String and when there are several matches,
5359 they are separated by <NL> characters. Example: >
5360 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5361<
5362 {alllinks} is used as with |glob()|.
5363
5364 The "**" item can be used to search in a directory tree.
5365 For example, to find all "README.txt" files in the directories
5366 in 'runtimepath' and below: >
5367 :echo globpath(&rtp, "**/README.txt")
5368< Upwards search and limiting the depth of "**" is not
5369 supported, thus using 'path' will not always work properly.
5370
5371 Can also be used as a |method|, the base is passed as the
5372 second argument: >
5373 GetExpr()->globpath(&rtp)
5374<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005375 Return type: |String| or list<string> or list<any> depending
5376 on {list}
5377
5378
5379has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005380 When {check} is omitted or is zero: The result is a Number,
5381 which is 1 if the feature {feature} is supported, zero
5382 otherwise. The {feature} argument is a string, case is
5383 ignored. See |feature-list| below.
5384
5385 When {check} is present and not zero: The result is a Number,
5386 which is 1 if the feature {feature} could ever be supported,
5387 zero otherwise. This is useful to check for a typo in
5388 {feature} and to detect dead code. Keep in mind that an older
5389 Vim version will not know about a feature added later and
5390 features that have been abandoned will not be known by the
5391 current Vim version.
5392
5393 Also see |exists()| and |exists_compiled()|.
5394
5395 Note that to skip code that has a syntax error when the
5396 feature is not available, Vim may skip the rest of the line
5397 and miss a following `endif`. Therefore put the `endif` on a
5398 separate line: >
5399 if has('feature')
5400 let x = this->breaks->without->the->feature
5401 endif
5402< If the `endif` would be moved to the second line as "| endif" it
5403 would not be found.
5404
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005405 Return type: |Number|
5406
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005407
5408has_key({dict}, {key}) *has_key()*
5409 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005410 has an entry with key {key}. FALSE otherwise.
5411 The {key} argument is a string. In |Vim9| script a number is
5412 also accepted (and converted to a string) but no other types.
5413 In legacy script the usual automatic conversion to string is
5414 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005415
5416 Can also be used as a |method|: >
5417 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005418<
5419 Return type: |Number|
5420
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005421
5422haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5423 The result is a Number:
5424 1 when the window has set a local directory via |:lcd|
5425 2 when the tab-page has set a local directory via |:tcd|
5426 0 otherwise.
5427
5428 Without arguments use the current window.
5429 With {winnr} use this window in the current tab page.
5430 With {winnr} and {tabnr} use the window in the specified tab
5431 page.
5432 {winnr} can be the window number or the |window-ID|.
5433 If {winnr} is -1 it is ignored and only the tabpage is used.
5434 Return 0 if the arguments are invalid.
5435 Examples: >
5436 if haslocaldir() == 1
5437 " window local directory case
5438 elseif haslocaldir() == 2
5439 " tab-local directory case
5440 else
5441 " global directory case
5442 endif
5443
5444 " current window
5445 :echo haslocaldir()
5446 :echo haslocaldir(0)
5447 :echo haslocaldir(0, 0)
5448 " window n in current tab page
5449 :echo haslocaldir(n)
5450 :echo haslocaldir(n, 0)
5451 " window n in tab page m
5452 :echo haslocaldir(n, m)
5453 " tab page m
5454 :echo haslocaldir(-1, m)
5455<
5456 Can also be used as a |method|: >
5457 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005458<
5459 Return type: |Number|
5460
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005461
5462hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5463 The result is a Number, which is TRUE if there is a mapping
5464 that contains {what} in somewhere in the rhs (what it is
5465 mapped to) and this mapping exists in one of the modes
5466 indicated by {mode}.
5467 The arguments {what} and {mode} are strings.
5468 When {abbr} is there and it is |TRUE| use abbreviations
5469 instead of mappings. Don't forget to specify Insert and/or
5470 Command-line mode.
5471 Both the global mappings and the mappings local to the current
5472 buffer are checked for a match.
5473 If no matching mapping is found FALSE is returned.
5474 The following characters are recognized in {mode}:
5475 n Normal mode
5476 v Visual and Select mode
5477 x Visual mode
5478 s Select mode
5479 o Operator-pending mode
5480 i Insert mode
5481 l Language-Argument ("r", "f", "t", etc.)
5482 c Command-line mode
5483 When {mode} is omitted, "nvo" is used.
5484
5485 This function is useful to check if a mapping already exists
5486 to a function in a Vim script. Example: >
5487 :if !hasmapto('\ABCdoit')
5488 : map <Leader>d \ABCdoit
5489 :endif
5490< This installs the mapping to "\ABCdoit" only if there isn't
5491 already a mapping to "\ABCdoit".
5492
5493 Can also be used as a |method|: >
5494 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005495<
5496 Return type: |Number|
5497
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005498
5499histadd({history}, {item}) *histadd()*
5500 Add the String {item} to the history {history} which can be
5501 one of: *hist-names*
5502 "cmd" or ":" command line history
5503 "search" or "/" search pattern history
5504 "expr" or "=" typed expression history
5505 "input" or "@" input line history
5506 "debug" or ">" debug command history
5507 empty the current or last used history
5508 The {history} string does not need to be the whole name, one
5509 character is sufficient.
5510 If {item} does already exist in the history, it will be
5511 shifted to become the newest entry.
5512 The result is a Number: TRUE if the operation was successful,
5513 otherwise FALSE is returned.
5514
5515 Example: >
5516 :call histadd("input", strftime("%Y %b %d"))
5517 :let date=input("Enter date: ")
5518< This function is not available in the |sandbox|.
5519
5520 Can also be used as a |method|, the base is passed as the
5521 second argument: >
5522 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005523<
5524 Return type: |Number|
5525
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005526
5527histdel({history} [, {item}]) *histdel()*
5528 Clear {history}, i.e. delete all its entries. See |hist-names|
5529 for the possible values of {history}.
5530
5531 If the parameter {item} evaluates to a String, it is used as a
5532 regular expression. All entries matching that expression will
5533 be removed from the history (if there are any).
5534 Upper/lowercase must match, unless "\c" is used |/\c|.
5535 If {item} evaluates to a Number, it will be interpreted as
5536 an index, see |:history-indexing|. The respective entry will
5537 be removed if it exists.
5538
5539 The result is TRUE for a successful operation, otherwise FALSE
5540 is returned.
5541
5542 Examples:
5543 Clear expression register history: >
5544 :call histdel("expr")
5545<
5546 Remove all entries starting with "*" from the search history: >
5547 :call histdel("/", '^\*')
5548<
5549 The following three are equivalent: >
5550 :call histdel("search", histnr("search"))
5551 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005552 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005553<
5554 To delete the last search pattern and use the last-but-one for
5555 the "n" command and 'hlsearch': >
5556 :call histdel("search", -1)
5557 :let @/ = histget("search", -1)
5558<
5559 Can also be used as a |method|: >
5560 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005561<
5562 Return type: |Number|
5563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005564
5565histget({history} [, {index}]) *histget()*
5566 The result is a String, the entry with Number {index} from
5567 {history}. See |hist-names| for the possible values of
5568 {history}, and |:history-indexing| for {index}. If there is
5569 no such entry, an empty String is returned. When {index} is
5570 omitted, the most recent item from the history is used.
5571
5572 Examples:
5573 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005574 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005575
5576< Define an Ex command ":H {num}" that supports re-execution of
5577 the {num}th entry from the output of |:history|. >
5578 :command -nargs=1 H execute histget("cmd", 0+<args>)
5579<
5580 Can also be used as a |method|: >
5581 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005582<
5583 Return type: |String|
5584
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005585
5586histnr({history}) *histnr()*
5587 The result is the Number of the current entry in {history}.
5588 See |hist-names| for the possible values of {history}.
5589 If an error occurred, -1 is returned.
5590
5591 Example: >
5592 :let inp_index = histnr("expr")
5593
5594< Can also be used as a |method|: >
5595 GetHistory()->histnr()
5596<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005597 Return type: |Number|
5598
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005599hlexists({name}) *hlexists()*
5600 The result is a Number, which is TRUE if a highlight group
5601 called {name} exists. This is when the group has been
5602 defined in some way. Not necessarily when highlighting has
5603 been defined for it, it may also have been used for a syntax
5604 item.
5605 *highlight_exists()*
5606 Obsolete name: highlight_exists().
5607
5608 Can also be used as a |method|: >
5609 GetName()->hlexists()
5610<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005611 Return type: |Number|
5612
5613
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005614hlget([{name} [, {resolve}]]) *hlget()*
5615 Returns a List of all the highlight group attributes. If the
5616 optional {name} is specified, then returns a List with only
5617 the attributes of the specified highlight group. Returns an
5618 empty List if the highlight group {name} is not present.
5619
5620 If the optional {resolve} argument is set to v:true and the
5621 highlight group {name} is linked to another group, then the
5622 link is resolved recursively and the attributes of the
5623 resolved highlight group are returned.
5624
5625 Each entry in the returned List is a Dictionary with the
5626 following items:
5627 cleared boolean flag, set to v:true if the highlight
5628 group attributes are cleared or not yet
5629 specified. See |highlight-clear|.
5630 cterm cterm attributes. See |highlight-cterm|.
5631 ctermbg cterm background color.
5632 See |highlight-ctermbg|.
5633 ctermfg cterm foreground color.
5634 See |highlight-ctermfg|.
5635 ctermul cterm underline color. See |highlight-ctermul|.
5636 default boolean flag, set to v:true if the highlight
5637 group link is a default link. See
5638 |highlight-default|.
5639 font highlight group font. See |highlight-font|.
5640 gui gui attributes. See |highlight-gui|.
5641 guibg gui background color. See |highlight-guibg|.
5642 guifg gui foreground color. See |highlight-guifg|.
5643 guisp gui special color. See |highlight-guisp|.
5644 id highlight group ID.
5645 linksto linked highlight group name.
5646 See |:highlight-link|.
5647 name highlight group name. See |group-name|.
5648 start start terminal keycode. See |highlight-start|.
5649 stop stop terminal keycode. See |highlight-stop|.
5650 term term attributes. See |highlight-term|.
5651
5652 The 'term', 'cterm' and 'gui' items in the above Dictionary
5653 have a dictionary value with the following optional boolean
5654 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5655 'reverse', 'inverse' and 'strikethrough'.
5656
5657 Example(s): >
5658 :echo hlget()
5659 :echo hlget('ModeMsg')
5660 :echo hlget('Number', v:true)
5661<
5662 Can also be used as a |method|: >
5663 GetName()->hlget()
5664<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005665 Return type: list<dict<any>>
5666
5667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005668hlset({list}) *hlset()*
5669 Creates or modifies the attributes of a List of highlight
5670 groups. Each item in {list} is a dictionary containing the
5671 attributes of a highlight group. See |hlget()| for the list of
5672 supported items in this dictionary.
5673
5674 In addition to the items described in |hlget()|, the following
5675 additional items are supported in the dictionary:
5676
5677 force boolean flag to force the creation of
5678 a link for an existing highlight group
5679 with attributes.
5680
5681 The highlight group is identified using the 'name' item and
5682 the 'id' item (if supplied) is ignored. If a highlight group
5683 with a specified name doesn't exist, then it is created.
5684 Otherwise the attributes of an existing highlight group are
5685 modified.
5686
5687 If an empty dictionary value is used for the 'term' or 'cterm'
5688 or 'gui' entries, then the corresponding attributes are
5689 cleared. If the 'cleared' item is set to v:true, then all the
5690 attributes of the highlight group are cleared.
5691
5692 The 'linksto' item can be used to link a highlight group to
5693 another highlight group. See |:highlight-link|.
5694
5695 Returns zero for success, -1 for failure.
5696
5697 Example(s): >
5698 " add bold attribute to the Visual highlight group
5699 :call hlset([#{name: 'Visual',
5700 \ term: #{reverse: 1 , bold: 1}}])
5701 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5702 :let l = hlget()
5703 :call hlset(l)
5704 " clear the Search highlight group
5705 :call hlset([#{name: 'Search', cleared: v:true}])
5706 " clear the 'term' attributes for a highlight group
5707 :call hlset([#{name: 'Title', term: {}}])
5708 " create the MyHlg group linking it to DiffAdd
5709 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5710 " remove the MyHlg group link
5711 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5712 " clear the attributes and a link
5713 :call hlset([#{name: 'MyHlg', cleared: v:true,
5714 \ linksto: 'NONE'}])
5715<
5716 Can also be used as a |method|: >
5717 GetAttrList()->hlset()
5718<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005719 Return type: |Number|
5720
5721hlID({name}) *hlID()*
5722 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005723 with name {name}. When the highlight group doesn't exist,
5724 zero is returned.
5725 This can be used to retrieve information about the highlight
5726 group. For example, to get the background color of the
5727 "Comment" group: >
5728 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5729< *highlightID()*
5730 Obsolete name: highlightID().
5731
5732 Can also be used as a |method|: >
5733 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005734<
5735 Return type: |Number|
5736
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005737
5738hostname() *hostname()*
5739 The result is a String, which is the name of the machine on
5740 which Vim is currently running. Machine names greater than
5741 256 characters long are truncated.
5742
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005743 Return type: |String|
5744
5745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005746iconv({string}, {from}, {to}) *iconv()*
5747 The result is a String, which is the text {string} converted
5748 from encoding {from} to encoding {to}.
5749 When the conversion completely fails an empty string is
5750 returned. When some characters could not be converted they
5751 are replaced with "?".
5752 The encoding names are whatever the iconv() library function
5753 can accept, see ":!man 3 iconv".
5754 Most conversions require Vim to be compiled with the |+iconv|
5755 feature. Otherwise only UTF-8 to latin1 conversion and back
5756 can be done.
5757 This can be used to display messages with special characters,
5758 no matter what 'encoding' is set to. Write the message in
5759 UTF-8 and use: >
5760 echo iconv(utf8_str, "utf-8", &enc)
5761< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5762 from/to UCS-2 is automatically changed to use UTF-8. You
5763 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5764
5765 Can also be used as a |method|: >
5766 GetText()->iconv('latin1', 'utf-8')
5767<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005768 Return type: |String|
5769
5770
h-east624bb832024-11-09 18:37:32 +01005771id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005772 The result is a unique String associated with the {item} and
5773 not with the {item}'s contents. It is only valid while the
5774 {item} exists and is referenced. It is valid only in the
5775 instance of vim that produces the result. The whole idea is
5776 that `id({item})` does not change if the contents of {item}
5777 changes. This is useful as a `key` for creating an identity
5778 dictionary, rather than one based on equals.
5779
5780 This operation does not reference {item} and there is no
5781 function to convert the `id` to the {item}. It may be useful to
5782 have a map of `id` to {item}. The following >
5783 var referenceMap: dict<any>
5784 var id = item->id()
5785 referenceMap[id] = item
5786< prevents {item} from being garbage collected and provides a
5787 way to get the {item} from the `id`.
5788
5789 {item} may be a List, Dictionary, Object, Job, Channel or
5790 Blob. If the item is not a permitted type, or it is a null
5791 value, then an empty String is returned.
5792
5793 Can also be used as a |method|: >
5794 GetItem()->id()
5795<
5796 Return type: |String|
5797
5798
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005799indent({lnum}) *indent()*
5800 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005801 current buffer. The indent is counted in spaces, the value
5802 of 'tabstop' is relevant. {lnum} is used just like in
5803 |getline()|.
5804 When {lnum} is invalid -1 is returned. In |Vim9| script an
5805 error is given.
5806
5807 Can also be used as a |method|: >
5808 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005809<
5810 Return type: |Number|
5811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005812
5813index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005814 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005815 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005817 If {object} is a |List| return the lowest index where the item
5818 has a value equal to {expr}. There is no automatic
5819 conversion, so the String "4" is different from the Number 4.
5820 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005821 of 'ignorecase' is not used here, case matters as indicated by
5822 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005823
5824 If {object} is |Blob| return the lowest index where the byte
5825 value is equal to {expr}.
5826
5827 If {start} is given then start looking at the item with index
5828 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005829
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005830 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5831 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005832
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005833 -1 is returned when {expr} is not found in {object}.
5834 Example: >
5835 :let idx = index(words, "the")
5836 :if index(numbers, 123) >= 0
5837
5838< Can also be used as a |method|: >
5839 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005840<
5841 Return type: |Number|
5842
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005843
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005844indexof({object}, {expr} [, {opts}]) *indexof()*
5845 Returns the index of an item in {object} where {expr} is
5846 v:true. {object} must be a |List| or a |Blob|.
5847
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005848 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005849 List until the expression is v:true and return the index of
5850 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005851
5852 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005853 Blob until the expression is v:true and return the index of
5854 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005855
5856 {expr} must be a |string| or |Funcref|.
5857
5858 If {expr} is a |string|: If {object} is a |List|, inside
5859 {expr} |v:key| has the index of the current List item and
5860 |v:val| has the value of the item. If {object} is a |Blob|,
5861 inside {expr} |v:key| has the index of the current byte and
5862 |v:val| has the byte value.
5863
5864 If {expr} is a |Funcref| it must take two arguments:
5865 1. the key or the index of the current item.
5866 2. the value of the current item.
5867 The function must return |TRUE| if the item is found and the
5868 search should stop.
5869
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005870 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005871 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005872 startidx start evaluating {expr} at the item with this
5873 index; may be negative for an item relative to
5874 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005875 Returns -1 when {expr} evaluates to v:false for all the items.
5876 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005877 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5878 :echo indexof(l, "v:val.n == 20")
5879 :echo indexof(l, {i, v -> v.n == 30})
5880 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005881
5882< Can also be used as a |method|: >
5883 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005884<
5885 Return type: |Number|
5886
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005888input({prompt} [, {text} [, {completion}]]) *input()*
5889 The result is a String, which is whatever the user typed on
5890 the command-line. The {prompt} argument is either a prompt
5891 string, or a blank string (for no prompt). A '\n' can be used
5892 in the prompt to start a new line.
5893 The highlighting set with |:echohl| is used for the prompt.
5894 The input is entered just like a command-line, with the same
5895 editing commands and mappings. There is a separate history
5896 for lines typed for input().
5897 Example: >
5898 :if input("Coffee or beer? ") == "beer"
5899 : echo "Cheers!"
5900 :endif
5901<
5902 If the optional {text} argument is present and not empty, this
5903 is used for the default reply, as if the user typed this.
5904 Example: >
5905 :let color = input("Color? ", "white")
5906
5907< The optional {completion} argument specifies the type of
5908 completion supported for the input. Without it completion is
5909 not performed. The supported completion types are the same as
5910 that can be supplied to a user-defined command using the
5911 "-complete=" argument. Refer to |:command-completion| for
5912 more information. Example: >
5913 let fname = input("File: ", "", "file")
5914<
5915 NOTE: This function must not be used in a startup file, for
5916 the versions that only run in GUI mode (e.g., the Win32 GUI).
5917 Note: When input() is called from within a mapping it will
5918 consume remaining characters from that mapping, because a
5919 mapping is handled like the characters were typed.
5920 Use |inputsave()| before input() and |inputrestore()|
5921 after input() to avoid that. Another solution is to avoid
5922 that further characters follow in the mapping, e.g., by using
5923 |:execute| or |:normal|.
5924
5925 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005926 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005927 :function GetFoo()
5928 : call inputsave()
5929 : let g:Foo = input("enter search pattern: ")
5930 : call inputrestore()
5931 :endfunction
5932
5933< Can also be used as a |method|: >
5934 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005935<
5936 Return type: |String|
5937
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005938
5939inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5940 Like |input()|, but when the GUI is running and text dialogs
5941 are supported, a dialog window pops up to input the text.
5942 Example: >
5943 :let n = inputdialog("value for shiftwidth", shiftwidth())
5944 :if n != ""
5945 : let &sw = n
5946 :endif
5947< When the dialog is cancelled {cancelreturn} is returned. When
5948 omitted an empty string is returned.
5949 Hitting <Enter> works like pressing the OK button. Hitting
5950 <Esc> works like pressing the Cancel button.
5951 NOTE: Command-line completion is not supported.
5952
5953 Can also be used as a |method|: >
5954 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005955<
5956 Return type: |String|
5957
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005958
5959inputlist({textlist}) *inputlist()*
5960 {textlist} must be a |List| of strings. This |List| is
5961 displayed, one string per line. The user will be prompted to
5962 enter a number, which is returned.
5963 The user can also select an item by clicking on it with the
5964 mouse, if the mouse is enabled in the command line ('mouse' is
5965 "a" or includes "c"). For the first string 0 is returned.
5966 When clicking above the first item a negative number is
5967 returned. When clicking on the prompt one more than the
5968 length of {textlist} is returned.
5969 Make sure {textlist} has less than 'lines' entries, otherwise
5970 it won't work. It's a good idea to put the entry number at
5971 the start of the string. And put a prompt in the first item.
5972 Example: >
5973 let color = inputlist(['Select color:', '1. red',
5974 \ '2. green', '3. blue'])
5975
5976< Can also be used as a |method|: >
5977 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005978<
5979 Return type: |Number|
5980
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005981
5982inputrestore() *inputrestore()*
5983 Restore typeahead that was saved with a previous |inputsave()|.
5984 Should be called the same number of times inputsave() is
5985 called. Calling it more often is harmless though.
5986 Returns TRUE when there is nothing to restore, FALSE otherwise.
5987
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005988 Return type: |Number|
5989
5990
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005991inputsave() *inputsave()*
5992 Preserve typeahead (also from mappings) and clear it, so that
5993 a following prompt gets input from the user. Should be
5994 followed by a matching inputrestore() after the prompt. Can
5995 be used several times, in which case there must be just as
5996 many inputrestore() calls.
5997 Returns TRUE when out of memory, FALSE otherwise.
5998
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005999 Return type: |Number|
6000
6001
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006002inputsecret({prompt} [, {text}]) *inputsecret()*
6003 This function acts much like the |input()| function with but
6004 two exceptions:
6005 a) the user's response will be displayed as a sequence of
6006 asterisks ("*") thereby keeping the entry secret, and
6007 b) the user's response will not be recorded on the input
6008 |history| stack.
6009 The result is a String, which is whatever the user actually
6010 typed on the command-line in response to the issued prompt.
6011 NOTE: Command-line completion is not supported.
6012
6013 Can also be used as a |method|: >
6014 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006015<
6016 Return type: |String|
6017
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006018
6019insert({object}, {item} [, {idx}]) *insert()*
6020 When {object} is a |List| or a |Blob| insert {item} at the start
6021 of it.
6022
6023 If {idx} is specified insert {item} before the item with index
6024 {idx}. If {idx} is zero it goes before the first item, just
6025 like omitting {idx}. A negative {idx} is also possible, see
6026 |list-index|. -1 inserts just before the last item.
6027
6028 Returns the resulting |List| or |Blob|. Examples: >
6029 :let mylist = insert([2, 3, 5], 1)
6030 :call insert(mylist, 4, -1)
6031 :call insert(mylist, 6, len(mylist))
6032< The last example can be done simpler with |add()|.
6033 Note that when {item} is a |List| it is inserted as a single
6034 item. Use |extend()| to concatenate |Lists|.
6035
6036 Can also be used as a |method|: >
6037 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006038<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006039 Return type: |Number|
6040
6041
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006042 *instanceof()* *E614* *E616* *E693*
6043instanceof({object}, {class})
6044 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006045 argument is a direct or indirect instance of a |Class|,
6046 |Interface|, or class |:type| alias specified by {class}.
6047 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006048 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006049 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006050 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006051
6052< Can also be used as a |method|: >
6053 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006054<
6055 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006057interrupt() *interrupt()*
6058 Interrupt script execution. It works more or less like the
6059 user typing CTRL-C, most commands won't execute and control
6060 returns to the user. This is useful to abort execution
6061 from lower down, e.g. in an autocommand. Example: >
6062 :function s:check_typoname(file)
6063 : if fnamemodify(a:file, ':t') == '['
6064 : echomsg 'Maybe typo'
6065 : call interrupt()
6066 : endif
6067 :endfunction
6068 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006069<
6070 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006071
6072invert({expr}) *invert()*
6073 Bitwise invert. The argument is converted to a number. A
6074 List, Dict or Float argument causes an error. Example: >
6075 :let bits = invert(bits)
6076< Can also be used as a |method|: >
6077 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006078<
6079 Return type: |Number|
6080
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006081
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006082isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006083 The result is a Number, which is |TRUE| when {path} is an
6084 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006085 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006086 On MS-Windows, it is considered absolute when it starts with an
6087 optional drive prefix and is followed by a '\' or '/'. UNC paths
6088 are always absolute.
6089 Example: >
6090 echo isabsolutepath('/usr/share/') " 1
6091 echo isabsolutepath('./foobar') " 0
6092 echo isabsolutepath('C:\Windows') " 1
6093 echo isabsolutepath('foobar') " 0
6094 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006095<
LemonBoydca1d402022-04-28 15:26:33 +01006096 Can also be used as a |method|: >
6097 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006098<
6099 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006100
6101
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006102isdirectory({directory}) *isdirectory()*
6103 The result is a Number, which is |TRUE| when a directory
6104 with the name {directory} exists. If {directory} doesn't
6105 exist, or isn't a directory, the result is |FALSE|. {directory}
6106 is any expression, which is used as a String.
6107
6108 Can also be used as a |method|: >
6109 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006110<
6111 Return type: |Number|
6112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006113
6114isinf({expr}) *isinf()*
6115 Return 1 if {expr} is a positive infinity, or -1 a negative
6116 infinity, otherwise 0. >
6117 :echo isinf(1.0 / 0.0)
6118< 1 >
6119 :echo isinf(-1.0 / 0.0)
6120< -1
6121
6122 Can also be used as a |method|: >
6123 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006124<
6125 Return type: |Number|
6126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006127
6128islocked({expr}) *islocked()* *E786*
6129 The result is a Number, which is |TRUE| when {expr} is the
6130 name of a locked variable.
6131 The string argument {expr} must be the name of a variable,
6132 |List| item or |Dictionary| entry, not the variable itself!
6133 Example: >
6134 :let alist = [0, ['a', 'b'], 2, 3]
6135 :lockvar 1 alist
6136 :echo islocked('alist') " 1
6137 :echo islocked('alist[1]') " 0
6138
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006139< When {expr} is a variable that does not exist -1 is returned.
6140 If {expr} uses a range, list or dict index that is out of
6141 range or does not exist you get an error message. Use
6142 |exists()| to check for existence.
6143 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006144
6145 Can also be used as a |method|: >
6146 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006147<
6148 Return type: |Number|
6149
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006150
6151isnan({expr}) *isnan()*
6152 Return |TRUE| if {expr} is a float with value NaN. >
6153 echo isnan(0.0 / 0.0)
6154< 1
6155
6156 Can also be used as a |method|: >
6157 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006158<
6159 Return type: |Number|
6160
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006161
6162items({dict}) *items()*
6163 Return a |List| with all the key-value pairs of {dict}. Each
6164 |List| item is a list with two items: the key of a {dict}
6165 entry and the value of this entry. The |List| is in arbitrary
6166 order. Also see |keys()| and |values()|.
6167 Example: >
6168 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006169 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006170 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006171<
6172 A List or a String argument is also supported. In these
6173 cases, items() returns a List with the index and the value at
6174 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006175
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006176 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006177 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006178<
6179 Return type: list<list<any>> or list<any>
6180
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006181
6182job_ functions are documented here: |job-functions-details|
6183
6184
6185join({list} [, {sep}]) *join()*
6186 Join the items in {list} together into one String.
6187 When {sep} is specified it is put in between the items. If
6188 {sep} is omitted a single space is used.
6189 Note that {sep} is not added at the end. You might want to
6190 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006191 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006192< String items are used as-is. |Lists| and |Dictionaries| are
6193 converted into a string like with |string()|.
6194 The opposite function is |split()|.
6195
6196 Can also be used as a |method|: >
6197 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006198<
6199 Return type: |String|
6200
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006201
6202js_decode({string}) *js_decode()*
6203 This is similar to |json_decode()| with these differences:
6204 - Object key names do not have to be in quotes.
6205 - Strings can be in single quotes.
6206 - Empty items in an array (between two commas) are allowed and
6207 result in v:none items.
6208
6209 Can also be used as a |method|: >
6210 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006211<
6212 Return type: any, depending on {varname}
6213
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006214
6215js_encode({expr}) *js_encode()*
6216 This is similar to |json_encode()| with these differences:
6217 - Object key names are not in quotes.
6218 - v:none items in an array result in an empty item between
6219 commas.
6220 For example, the Vim object:
6221 [1,v:none,{"one":1},v:none] ~
6222 Will be encoded as:
6223 [1,,{one:1},,] ~
6224 While json_encode() would produce:
6225 [1,null,{"one":1},null] ~
6226 This encoding is valid for JavaScript. It is more efficient
6227 than JSON, especially when using an array with optional items.
6228
6229 Can also be used as a |method|: >
6230 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006231<
6232 Return type: |String|
6233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006234
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006235json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006236 This parses a JSON formatted string and returns the equivalent
6237 in Vim values. See |json_encode()| for the relation between
6238 JSON and Vim values.
6239 The decoding is permissive:
6240 - A trailing comma in an array and object is ignored, e.g.
6241 "[1, 2, ]" is the same as "[1, 2]".
6242 - Integer keys are accepted in objects, e.g. {1:2} is the
6243 same as {"1":2}.
6244 - More floating point numbers are recognized, e.g. "1." for
6245 "1.0", or "001.2" for "1.2". Special floating point values
6246 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6247 are accepted.
6248 - Leading zeroes in integer numbers are ignored, e.g. "012"
6249 for "12" or "-012" for "-12".
6250 - Capitalization is ignored in literal names null, true or
6251 false, e.g. "NULL" for "null", "True" for "true".
6252 - Control characters U+0000 through U+001F which are not
6253 escaped in strings are accepted, e.g. " " (tab
6254 character in string) for "\t".
6255 - An empty JSON expression or made of only spaces is accepted
6256 and results in v:none.
6257 - Backslash in an invalid 2-character sequence escape is
6258 ignored, e.g. "\a" is decoded as "a".
6259 - A correct surrogate pair in JSON strings should normally be
6260 a 12 character sequence such as "\uD834\uDD1E", but
6261 json_decode() silently accepts truncated surrogate pairs
6262 such as "\uD834" or "\uD834\u"
6263 *E938*
6264 A duplicate key in an object, valid in rfc7159, is not
6265 accepted by json_decode() as the result must be a valid Vim
6266 type, e.g. this fails: {"a":"b", "a":"c"}
6267
6268 Can also be used as a |method|: >
6269 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006270<
6271 Return type: any, depending on {varname}
6272
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006273
6274json_encode({expr}) *json_encode()*
6275 Encode {expr} as JSON and return this as a string.
6276 The encoding is specified in:
6277 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006278 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006279 |Number| decimal number
6280 |Float| floating point number
6281 Float nan "NaN"
6282 Float inf "Infinity"
6283 Float -inf "-Infinity"
6284 |String| in double quotes (possibly null)
6285 |Funcref| not possible, error
6286 |List| as an array (possibly null); when
6287 used recursively: []
6288 |Dict| as an object (possibly null); when
6289 used recursively: {}
6290 |Blob| as an array of the individual bytes
6291 v:false "false"
6292 v:true "true"
6293 v:none "null"
6294 v:null "null"
6295 Note that NaN and Infinity are passed on as values. This is
6296 missing in the JSON standard, but several implementations do
6297 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006298 If a string contains an illegal character then the replacement
6299 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006300
6301 Can also be used as a |method|: >
6302 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006303<
6304 Return type: |String|
6305
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006306
6307keys({dict}) *keys()*
6308 Return a |List| with all the keys of {dict}. The |List| is in
6309 arbitrary order. Also see |items()| and |values()|.
6310
6311 Can also be used as a |method|: >
6312 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006313<
6314 Return type: list<string>
6315
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006316
zeertzjqcdc83932022-09-12 13:38:41 +01006317keytrans({string}) *keytrans()*
6318 Turn the internal byte representation of keys into a form that
6319 can be used for |:map|. E.g. >
6320 :let xx = "\<C-Home>"
6321 :echo keytrans(xx)
6322< <C-Home>
6323
6324 Can also be used as a |method|: >
6325 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006326<
6327 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006328
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006329
6330len({expr}) *len()* *E701*
6331 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006332 When {expr} is a String or a Number the length in bytes is
6333 used, as with |strlen()|.
6334 When {expr} is a |List| the number of items in the |List| is
6335 returned.
6336 When {expr} is a |Blob| the number of bytes is returned.
6337 When {expr} is a |Dictionary| the number of entries in the
6338 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006339 When {expr} is an |Object|, invokes the len() method in the
6340 object (if present) to get the length (|object-len()|).
6341 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006342
6343 Can also be used as a |method|: >
6344 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006345<
6346 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006347
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006348
6349 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006350libcall({libname}, {funcname}, {argument})
6351 Call function {funcname} in the run-time library {libname}
6352 with single argument {argument}.
6353 This is useful to call functions in a library that you
6354 especially made to be used with Vim. Since only one argument
6355 is possible, calling standard library functions is rather
6356 limited.
6357 The result is the String returned by the function. If the
6358 function returns NULL, this will appear as an empty string ""
6359 to Vim.
6360 If the function returns a number, use libcallnr()!
6361 If {argument} is a number, it is passed to the function as an
6362 int; if {argument} is a string, it is passed as a
6363 null-terminated string.
6364 This function will fail in |restricted-mode|.
6365
6366 libcall() allows you to write your own 'plug-in' extensions to
6367 Vim without having to recompile the program. It is NOT a
6368 means to call system functions! If you try to do so Vim will
6369 very probably crash.
6370
6371 For Win32, the functions you write must be placed in a DLL
6372 and use the normal C calling convention (NOT Pascal which is
6373 used in Windows System DLLs). The function must take exactly
6374 one parameter, either a character pointer or a long integer,
6375 and must return a character pointer or NULL. The character
6376 pointer returned must point to memory that will remain valid
6377 after the function has returned (e.g. in static data in the
6378 DLL). If it points to allocated memory, that memory will
6379 leak away. Using a static buffer in the function should work,
6380 it's then freed when the DLL is unloaded.
6381
6382 WARNING: If the function returns a non-valid pointer, Vim may
6383 crash! This also happens if the function returns a number,
6384 because Vim thinks it's a pointer.
6385 For Win32 systems, {libname} should be the filename of the DLL
6386 without the ".DLL" suffix. A full path is only required if
6387 the DLL is not in the usual places.
6388 For Unix: When compiling your own plugins, remember that the
6389 object code must be compiled as position-independent ('PIC').
6390 {only in Win32 and some Unix versions, when the |+libcall|
6391 feature is present}
6392 Examples: >
6393 :echo libcall("libc.so", "getenv", "HOME")
6394
6395< Can also be used as a |method|, the base is passed as the
6396 third argument: >
6397 GetValue()->libcall("libc.so", "getenv")
6398<
6399 *libcallnr()*
6400libcallnr({libname}, {funcname}, {argument})
6401 Just like |libcall()|, but used for a function that returns an
6402 int instead of a string.
6403 {only in Win32 on some Unix versions, when the |+libcall|
6404 feature is present}
6405 Examples: >
6406 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6407 :call libcallnr("libc.so", "printf", "Hello World!\n")
6408 :call libcallnr("libc.so", "sleep", 10)
6409<
6410 Can also be used as a |method|, the base is passed as the
6411 third argument: >
6412 GetValue()->libcallnr("libc.so", "printf")
6413<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006414 Return type: |String|
6415
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006416
6417line({expr} [, {winid}]) *line()*
6418 The result is a Number, which is the line number of the file
6419 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006420 See |getpos()| for accepted positions.
6421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006422 To get the column number use |col()|. To get both use
6423 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006425 With the optional {winid} argument the values are obtained for
6426 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006427
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006428 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006430 Examples: >
6431 line(".") line number of the cursor
6432 line(".", winid) idem, in window "winid"
6433 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006434 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006435<
6436 To jump to the last known position when opening a file see
6437 |last-position-jump|.
6438
6439 Can also be used as a |method|: >
6440 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006441<
6442 Return type: |Number|
6443
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006444
6445line2byte({lnum}) *line2byte()*
6446 Return the byte count from the start of the buffer for line
6447 {lnum}. This includes the end-of-line character, depending on
6448 the 'fileformat' option for the current buffer. The first
6449 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6450 This can also be used to get the byte count for the line just
6451 below the last line: >
6452 line2byte(line("$") + 1)
6453< This is the buffer size plus one. If 'fileencoding' is empty
6454 it is the file size plus one. {lnum} is used like with
6455 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6456 feature has been disabled at compile time, -1 is returned.
6457 Also see |byte2line()|, |go| and |:goto|.
6458
6459 Can also be used as a |method|: >
6460 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006461<
6462 Return type: |Number|
6463
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006464
6465lispindent({lnum}) *lispindent()*
6466 Get the amount of indent for line {lnum} according the lisp
6467 indenting rules, as with 'lisp'.
6468 The indent is counted in spaces, the value of 'tabstop' is
6469 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006470 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006471 error is given.
6472
6473 Can also be used as a |method|: >
6474 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006475<
6476 Return type: |Number|
6477
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006478
6479list2blob({list}) *list2blob()*
6480 Return a Blob concatenating all the number values in {list}.
6481 Examples: >
6482 list2blob([1, 2, 3, 4]) returns 0z01020304
6483 list2blob([]) returns 0z
6484< Returns an empty Blob on error. If one of the numbers is
6485 negative or more than 255 error *E1239* is given.
6486
6487 |blob2list()| does the opposite.
6488
6489 Can also be used as a |method|: >
6490 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006491<
6492 Return type: |Blob|
6493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006494
6495list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006496 Convert each number in {list} to a character string and
6497 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006498 list2str([32]) returns " "
6499 list2str([65, 66, 67]) returns "ABC"
6500< The same can be done (slowly) with: >
6501 join(map(list, {nr, val -> nr2char(val)}), '')
6502< |str2list()| does the opposite.
6503
6504 When {utf8} is omitted or zero, the current 'encoding' is used.
6505 When {utf8} is TRUE, always return UTF-8 characters.
6506 With UTF-8 composing characters work as expected: >
6507 list2str([97, 769]) returns "á"
6508<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006509 Returns an empty string on error.
6510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006511 Can also be used as a |method|: >
6512 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006513<
6514 Return type: |String|
6515
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006516
6517listener_add({callback} [, {buf}]) *listener_add()*
6518 Add a callback function that will be invoked when changes have
6519 been made to buffer {buf}.
6520 {buf} refers to a buffer name or number. For the accepted
6521 values, see |bufname()|. When {buf} is omitted the current
6522 buffer is used.
6523 Returns a unique ID that can be passed to |listener_remove()|.
6524
6525 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006526 bufnr the buffer that was changed
6527 start first changed line number
6528 end first line number below the change
6529 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006530 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006531 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006532
6533 Example: >
6534 func Listener(bufnr, start, end, added, changes)
6535 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6536 endfunc
6537 call listener_add('Listener', bufnr)
6538
Bram Moolenaar944697a2022-02-20 19:48:20 +00006539< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006540 dictionary with these entries:
6541 lnum the first line number of the change
6542 end the first line below the change
6543 added number of lines added; negative if lines were
6544 deleted
6545 col first column in "lnum" that was affected by
6546 the change; one if unknown or the whole line
6547 was affected; this is a byte index, first
6548 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006549 When lines are inserted (not when a line is split, e.g. by
6550 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006551 lnum line above which the new line is added
6552 end equal to "lnum"
6553 added number of lines inserted
6554 col 1
6555 When lines are deleted the values are:
6556 lnum the first deleted line
6557 end the line below the first deleted line, before
6558 the deletion was done
6559 added negative, number of lines deleted
6560 col 1
6561 When lines are changed:
6562 lnum the first changed line
6563 end the line below the last changed line
6564 added 0
6565 col first column with a change or 1
6566
6567 The entries are in the order the changes were made, thus the
6568 most recent change is at the end. The line numbers are valid
6569 when the callback is invoked, but later changes may make them
6570 invalid, thus keeping a copy for later might not work.
6571
6572 The {callback} is invoked just before the screen is updated,
6573 when |listener_flush()| is called or when a change is being
6574 made that changes the line count in a way it causes a line
6575 number in the list of changes to become invalid.
6576
6577 The {callback} is invoked with the text locked, see
6578 |textlock|. If you do need to make changes to the buffer, use
6579 a timer to do this later |timer_start()|.
6580
6581 The {callback} is not invoked when the buffer is first loaded.
6582 Use the |BufReadPost| autocmd event to handle the initial text
6583 of a buffer.
6584 The {callback} is also not invoked when the buffer is
6585 unloaded, use the |BufUnload| autocmd event for that.
6586
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006587 Returns zero if {callback} or {buf} is invalid.
6588
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006589 Can also be used as a |method|, the base is passed as the
6590 second argument: >
6591 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006592<
6593 Return type: |Number|
6594
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006595
6596listener_flush([{buf}]) *listener_flush()*
6597 Invoke listener callbacks for buffer {buf}. If there are no
6598 pending changes then no callbacks are invoked.
6599
6600 {buf} refers to a buffer name or number. For the accepted
6601 values, see |bufname()|. When {buf} is omitted the current
6602 buffer is used.
6603
6604 Can also be used as a |method|: >
6605 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006606<
6607 Return type: |Number|
6608
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006609
6610listener_remove({id}) *listener_remove()*
6611 Remove a listener previously added with listener_add().
6612 Returns FALSE when {id} could not be found, TRUE when {id} was
6613 removed.
6614
6615 Can also be used as a |method|: >
6616 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006617<
6618 Return type: |Number|
6619
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006620
6621localtime() *localtime()*
6622 Return the current time, measured as seconds since 1st Jan
6623 1970. See also |strftime()|, |strptime()| and |getftime()|.
6624
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006625 Return type: |Number|
6626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006627
6628log({expr}) *log()*
6629 Return the natural logarithm (base e) of {expr} as a |Float|.
6630 {expr} must evaluate to a |Float| or a |Number| in the range
6631 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006632 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006633 Examples: >
6634 :echo log(10)
6635< 2.302585 >
6636 :echo log(exp(5))
6637< 5.0
6638
6639 Can also be used as a |method|: >
6640 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006641<
6642 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006643
6644
6645log10({expr}) *log10()*
6646 Return the logarithm of Float {expr} to base 10 as a |Float|.
6647 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006648 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006649 Examples: >
6650 :echo log10(1000)
6651< 3.0 >
6652 :echo log10(0.01)
6653< -2.0
6654
6655 Can also be used as a |method|: >
6656 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006657<
6658 Return type: |Float|
6659
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006660
6661luaeval({expr} [, {expr}]) *luaeval()*
6662 Evaluate Lua expression {expr} and return its result converted
6663 to Vim data structures. Second {expr} may hold additional
6664 argument accessible as _A inside first {expr}.
6665 Strings are returned as they are.
6666 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006667 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006668 Dictionaries and lists obtained by vim.eval() are returned
6669 as-is.
6670 Other objects are returned as zero without any errors.
6671 See |lua-luaeval| for more details.
6672 Note that in a `:def` function local variables are not visible
6673 to {expr}.
6674
6675 Can also be used as a |method|: >
6676 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006677<
6678 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006679
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006680 {only available when compiled with the |+lua| feature}
6681
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006682
6683map({expr1}, {expr2}) *map()*
6684 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006685 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006686 item in {expr1} with the result of evaluating {expr2}.
6687 For a |Blob| each byte is replaced.
6688 For a |String|, each character, including composing
6689 characters, is replaced.
6690 If the item type changes you may want to use |mapnew()| to
6691 create a new List or Dictionary. This is required when using
6692 Vim9 script.
6693
6694 {expr2} must be a |String| or |Funcref|.
6695
6696 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6697 of the current item. For a |Dictionary| |v:key| has the key
6698 of the current item and for a |List| |v:key| has the index of
6699 the current item. For a |Blob| |v:key| has the index of the
6700 current byte. For a |String| |v:key| has the index of the
6701 current character.
6702 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006703 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006704< This puts "> " before and " <" after each item in "mylist".
6705
6706 Note that {expr2} is the result of an expression and is then
6707 used as an expression again. Often it is good to use a
6708 |literal-string| to avoid having to double backslashes. You
6709 still have to double ' quotes
6710
6711 If {expr2} is a |Funcref| it is called with two arguments:
6712 1. The key or the index of the current item.
6713 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006714 With a legacy script lambda you don't get an error if it only
6715 accepts one argument, but with a Vim9 lambda you get "E1106:
6716 One argument too many", the number of arguments must match.
6717
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006718 The function must return the new value of the item. Example
6719 that changes each value by "key-value": >
6720 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006721 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006722 endfunc
6723 call map(myDict, function('KeyValue'))
6724< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006725 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006726< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006727 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006728< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006729 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006730<
6731 The operation is done in-place for a |List| and |Dictionary|.
6732 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006733 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006734
6735< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6736 or a new |Blob| or |String|.
6737 When an error is encountered while evaluating {expr2} no
6738 further items in {expr1} are processed.
6739 When {expr2} is a Funcref errors inside a function are ignored,
6740 unless it was defined with the "abort" flag.
6741
6742 Can also be used as a |method|: >
6743 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006744<
6745 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6746 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006747
6748
6749maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6750 When {dict} is omitted or zero: Return the rhs of mapping
6751 {name} in mode {mode}. The returned String has special
6752 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006753 listing. When {dict} is TRUE a dictionary is returned, see
6754 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006755
6756 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006757 returned if {dict} is FALSE, otherwise returns an empty Dict.
6758 When the mapping for {name} is empty, then "<Nop>" is
6759 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006760
6761 The {name} can have special key names, like in the ":map"
6762 command.
6763
6764 {mode} can be one of these strings:
6765 "n" Normal
6766 "v" Visual (including Select)
6767 "o" Operator-pending
6768 "i" Insert
6769 "c" Cmd-line
6770 "s" Select
6771 "x" Visual
6772 "l" langmap |language-mapping|
6773 "t" Terminal-Job
6774 "" Normal, Visual and Operator-pending
6775 When {mode} is omitted, the modes for "" are used.
6776
6777 When {abbr} is there and it is |TRUE| use abbreviations
6778 instead of mappings.
6779
6780 When {dict} is there and it is |TRUE| return a dictionary
6781 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006782 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006783 "lhs" The {lhs} of the mapping as it would be typed
6784 "lhsraw" The {lhs} of the mapping as raw bytes
6785 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6786 form, only present when it differs from "lhsraw"
6787 "rhs" The {rhs} of the mapping as typed.
6788 "silent" 1 for a |:map-silent| mapping, else 0.
6789 "noremap" 1 if the {rhs} of the mapping is not remappable.
6790 "script" 1 if mapping was defined with <script>.
6791 "expr" 1 for an expression mapping (|:map-<expr>|).
6792 "buffer" 1 for a buffer local mapping (|:map-local|).
6793 "mode" Modes for which the mapping is defined. In
6794 addition to the modes mentioned above, these
6795 characters will be used:
6796 " " Normal, Visual and Operator-pending
6797 "!" Insert and Commandline mode
6798 (|mapmode-ic|)
6799 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006800 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006801 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006802 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006803 "lnum" The line number in "sid", zero if unknown.
6804 "nowait" Do not wait for other, longer mappings.
6805 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006806 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006807 "mode_bits" Vim's internal binary representation of "mode".
6808 |mapset()| ignores this; only "mode" is used.
6809 See |maplist()| for usage examples. The values
6810 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006811
6812 The dictionary can be used to restore a mapping with
6813 |mapset()|.
6814
6815 The mappings local to the current buffer are checked first,
6816 then the global mappings.
6817 This function can be used to map a key even when it's already
6818 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006819 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006820
6821< Can also be used as a |method|: >
6822 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006823<
6824 Return type: |String| or dict<any> depending on {dict}
6825
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006826
6827mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6828 Check if there is a mapping that matches with {name} in mode
6829 {mode}. See |maparg()| for {mode} and special names in
6830 {name}.
6831 When {abbr} is there and it is |TRUE| use abbreviations
6832 instead of mappings.
6833 A match happens with a mapping that starts with {name} and
6834 with a mapping which is equal to the start of {name}.
6835
6836 matches mapping "a" "ab" "abc" ~
6837 mapcheck("a") yes yes yes
6838 mapcheck("abc") yes yes yes
6839 mapcheck("ax") yes no no
6840 mapcheck("b") no no no
6841
6842 The difference with maparg() is that mapcheck() finds a
6843 mapping that matches with {name}, while maparg() only finds a
6844 mapping for {name} exactly.
6845 When there is no mapping that starts with {name}, an empty
6846 String is returned. If there is one, the RHS of that mapping
6847 is returned. If there are several mappings that start with
6848 {name}, the RHS of one of them is returned. This will be
6849 "<Nop>" if the RHS is empty.
6850 The mappings local to the current buffer are checked first,
6851 then the global mappings.
6852 This function can be used to check if a mapping can be added
6853 without being ambiguous. Example: >
6854 :if mapcheck("_vv") == ""
6855 : map _vv :set guifont=7x13<CR>
6856 :endif
6857< This avoids adding the "_vv" mapping when there already is a
6858 mapping for "_v" or for "_vvv".
6859
6860 Can also be used as a |method|: >
6861 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006862<
6863 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006864
6865
Ernie Rael09661202022-04-25 14:40:44 +01006866maplist([{abbr}]) *maplist()*
6867 Returns a |List| of all mappings. Each List item is a |Dict|,
6868 the same as what is returned by |maparg()|, see
6869 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6870 abbreviations instead of mappings.
6871
6872 Example to show all mappings with 'MultiMatch' in rhs: >
6873 vim9script
6874 echo maplist()->filter(
6875 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006876< It can be tricky to find mappings for particular |:map-modes|.
6877 |mapping-dict|'s "mode_bits" can simplify this. For example,
6878 the mode_bits for Normal, Insert or Command-line modes are
6879 0x19. To find all the mappings available in those modes you
6880 can do: >
6881 vim9script
6882 var saved_maps = []
6883 for m in maplist()
6884 if and(m.mode_bits, 0x19) != 0
6885 saved_maps->add(m)
6886 endif
6887 endfor
6888 echo saved_maps->mapnew((_, m) => m.lhs)
6889< The values of the mode_bits are defined in Vim's src/vim.h
6890 file and they can be discovered at runtime using
6891 |:map-commands| and "maplist()". Example: >
6892 vim9script
6893 omap xyzzy <Nop>
6894 var op_bit = maplist()->filter(
6895 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6896 ounmap xyzzy
6897 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006898<
6899 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006900
6901
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006902mapnew({expr1}, {expr2}) *mapnew()*
6903 Like |map()| but instead of replacing items in {expr1} a new
6904 List or Dictionary is created and returned. {expr1} remains
6905 unchanged. Items can still be changed by {expr2}, if you
6906 don't want that use |deepcopy()| first.
6907
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006908 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6909 depending on {expr1}
6910
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006911
6912mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006913mapset({dict})
6914 Restore a mapping from a dictionary, possibly returned by
6915 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6916 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006917 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006918 feature allows copying mappings from one buffer to another.
6919 The dict.mode value may restore a single mapping that covers
6920 more than one mode, like with mode values of '!', ' ', 'nox',
6921 or 'v'. *E1276*
6922
6923 In the first form, {mode} and {abbr} should be the same as
6924 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006925 {mode} is used to define the mode in which the mapping is set,
6926 not the "mode" entry in {dict}.
6927 Example for saving and restoring a mapping: >
6928 let save_map = maparg('K', 'n', 0, 1)
6929 nnoremap K somethingelse
6930 ...
6931 call mapset('n', 0, save_map)
6932< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006933 e.g. with `:map!`, you need to save/restore the mapping for
6934 all of them, when they might differ.
6935
6936 In the second form, with {dict} as the only argument, mode
6937 and abbr are taken from the dict.
6938 Example: >
6939 vim9script
6940 var save_maps = maplist()->filter(
6941 (_, m) => m.lhs == 'K')
6942 nnoremap K somethingelse
6943 cnoremap K somethingelse2
6944 # ...
6945 unmap K
6946 for d in save_maps
6947 mapset(d)
6948 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006949<
6950 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006951
6952
6953match({expr}, {pat} [, {start} [, {count}]]) *match()*
6954 When {expr} is a |List| then this returns the index of the
6955 first item where {pat} matches. Each item is used as a
6956 String, |Lists| and |Dictionaries| are used as echoed.
6957
6958 Otherwise, {expr} is used as a String. The result is a
6959 Number, which gives the index (byte offset) in {expr} where
6960 {pat} matches.
6961
6962 A match at the first character or |List| item returns zero.
6963 If there is no match -1 is returned.
6964
6965 For getting submatches see |matchlist()|.
6966 Example: >
6967 :echo match("testing", "ing") " results in 4
6968 :echo match([1, 'x'], '\a') " results in 1
6969< See |string-match| for how {pat} is used.
6970 *strpbrk()*
6971 Vim doesn't have a strpbrk() function. But you can do: >
6972 :let sepidx = match(line, '[.,;: \t]')
6973< *strcasestr()*
6974 Vim doesn't have a strcasestr() function. But you can add
6975 "\c" to the pattern to ignore case: >
6976 :let idx = match(haystack, '\cneedle')
6977<
6978 If {start} is given, the search starts from byte index
6979 {start} in a String or item {start} in a |List|.
6980 The result, however, is still the index counted from the
6981 first character/item. Example: >
6982 :echo match("testing", "ing", 2)
6983< result is again "4". >
6984 :echo match("testing", "ing", 4)
6985< result is again "4". >
6986 :echo match("testing", "t", 2)
6987< result is "3".
6988 For a String, if {start} > 0 then it is like the string starts
6989 {start} bytes later, thus "^" will match at {start}. Except
6990 when {count} is given, then it's like matches before the
6991 {start} byte are ignored (this is a bit complicated to keep it
6992 backwards compatible).
6993 For a String, if {start} < 0, it will be set to 0. For a list
6994 the index is counted from the end.
6995 If {start} is out of range ({start} > strlen({expr}) for a
6996 String or {start} > len({expr}) for a |List|) -1 is returned.
6997
6998 When {count} is given use the {count}'th match. When a match
6999 is found in a String the search for the next one starts one
7000 character further. Thus this example results in 1: >
7001 echo match("testing", "..", 0, 2)
7002< In a |List| the search continues in the next item.
7003 Note that when {count} is added the way {start} works changes,
7004 see above.
7005
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007006 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007007 See |pattern| for the patterns that are accepted.
7008 The 'ignorecase' option is used to set the ignore-caseness of
7009 the pattern. 'smartcase' is NOT used. The matching is always
7010 done like 'magic' is set and 'cpoptions' is empty.
7011 Note that a match at the start is preferred, thus when the
7012 pattern is using "*" (any number of matches) it tends to find
7013 zero matches at the start instead of a number of matches
7014 further down in the text.
7015
7016 Can also be used as a |method|: >
7017 GetText()->match('word')
7018 GetList()->match('word')
7019<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007020 Return type: |Number|
7021
7022
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007023 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007024matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7025 Defines a pattern to be highlighted in the current window (a
7026 "match"). It will be highlighted with {group}. Returns an
7027 identification number (ID), which can be used to delete the
7028 match using |matchdelete()|. The ID is bound to the window.
7029 Matching is case sensitive and magic, unless case sensitivity
7030 or magicness are explicitly overridden in {pattern}. The
7031 'magic', 'smartcase' and 'ignorecase' options are not used.
7032 The "Conceal" value is special, it causes the match to be
7033 concealed.
7034
7035 The optional {priority} argument assigns a priority to the
7036 match. A match with a high priority will have its
7037 highlighting overrule that of a match with a lower priority.
7038 A priority is specified as an integer (negative numbers are no
7039 exception). If the {priority} argument is not specified, the
7040 default priority is 10. The priority of 'hlsearch' is zero,
7041 hence all matches with a priority greater than zero will
7042 overrule it. Syntax highlighting (see 'syntax') is a separate
7043 mechanism, and regardless of the chosen priority a match will
7044 always overrule syntax highlighting.
7045
7046 The optional {id} argument allows the request for a specific
7047 match ID. If a specified ID is already taken, an error
7048 message will appear and the match will not be added. An ID
7049 is specified as a positive integer (zero excluded). IDs 1, 2
7050 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007051 respectively. 3 is reserved for use by the |matchparen|
7052 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007053 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007054 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007055
7056 The optional {dict} argument allows for further custom
7057 values. Currently this is used to specify a match specific
7058 conceal character that will be shown for |hl-Conceal|
7059 highlighted matches. The dict can have the following members:
7060
7061 conceal Special character to show instead of the
7062 match (only for |hl-Conceal| highlighted
7063 matches, see |:syn-cchar|)
7064 window Instead of the current window use the
7065 window with this number or window ID.
7066
7067 The number of matches is not limited, as it is the case with
7068 the |:match| commands.
7069
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007070 Returns -1 on error.
7071
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007072 Example: >
7073 :highlight MyGroup ctermbg=green guibg=green
7074 :let m = matchadd("MyGroup", "TODO")
7075< Deletion of the pattern: >
7076 :call matchdelete(m)
7077
7078< A list of matches defined by |matchadd()| and |:match| are
7079 available from |getmatches()|. All matches can be deleted in
7080 one operation by |clearmatches()|.
7081
7082 Can also be used as a |method|: >
7083 GetGroup()->matchadd('TODO')
7084<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007085 Return type: |Number|
7086
7087
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007088 *matchaddpos()*
7089matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7090 Same as |matchadd()|, but requires a list of positions {pos}
7091 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007092 because it does not handle regular expressions and it sets
7093 buffer line boundaries to redraw screen. It is supposed to be
7094 used when fast match additions and deletions are required, for
7095 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007096
7097 {pos} is a list of positions. Each position can be one of
7098 these:
7099 - A number. This whole line will be highlighted. The first
7100 line has number 1.
7101 - A list with one number, e.g., [23]. The whole line with this
7102 number will be highlighted.
7103 - A list with two numbers, e.g., [23, 11]. The first number is
7104 the line number, the second one is the column number (first
7105 column is 1, the value must correspond to the byte index as
7106 |col()| would return). The character at this position will
7107 be highlighted.
7108 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7109 the third number gives the length of the highlight in bytes.
7110
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007111 Returns -1 on error.
7112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007113 Example: >
7114 :highlight MyGroup ctermbg=green guibg=green
7115 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7116< Deletion of the pattern: >
7117 :call matchdelete(m)
7118
7119< Matches added by |matchaddpos()| are returned by
7120 |getmatches()|.
7121
7122 Can also be used as a |method|: >
7123 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007124<
7125 Return type: |Number|
7126
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007127
7128matcharg({nr}) *matcharg()*
7129 Selects the {nr} match item, as set with a |:match|,
7130 |:2match| or |:3match| command.
7131 Return a |List| with two elements:
7132 The name of the highlight group used
7133 The pattern used.
7134 When {nr} is not 1, 2 or 3 returns an empty |List|.
7135 When there is no match item set returns ['', ''].
7136 This is useful to save and restore a |:match|.
7137 Highlighting matches using the |:match| commands are limited
7138 to three matches. |matchadd()| does not have this limitation.
7139
7140 Can also be used as a |method|: >
7141 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007142<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007143 Return type: list<string>
7144
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007145 *matchbufline()*
7146matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7147 Returns the |List| of matches in lines from {lnum} to {end} in
7148 buffer {buf} where {pat} matches.
7149
7150 {lnum} and {end} can either be a line number or the string "$"
7151 to refer to the last line in {buf}.
7152
7153 The {dict} argument supports following items:
7154 submatches include submatch information (|/\(|)
7155
7156 For each match, a |Dict| with the following items is returned:
7157 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007158 lnum line number where there is a match
7159 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007160 Note that there can be multiple matches in a single line.
7161
7162 This function works only for loaded buffers. First call
7163 |bufload()| if needed.
7164
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007165 See |match-pattern| for information about the effect of some
7166 option settings on the pattern.
7167
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007168 When {buf} is not a valid buffer, the buffer is not loaded or
7169 {lnum} or {end} is not valid then an error is given and an
7170 empty |List| is returned.
7171
7172 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007173 " Assuming line 3 in buffer 5 contains "a"
7174 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7175 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7176 " Assuming line 4 in buffer 10 contains "tik tok"
7177 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7178 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007179<
7180 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007181 "\1", "\2", etc. are also returned. Example: >
7182 " Assuming line 2 in buffer 2 contains "acd"
7183 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007184 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007185 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007186< The "submatches" List always contains 9 items. If a submatch
7187 is not found, then an empty string is returned for that
7188 submatch.
7189
7190 Can also be used as a |method|: >
7191 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007192<
7193 Return type: list<dict<any>> or list<any>
7194
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007195
h-east624bb832024-11-09 18:37:32 +01007196matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007197 Deletes a match with ID {id} previously defined by |matchadd()|
7198 or one of the |:match| commands. Returns 0 if successful,
7199 otherwise -1. See example for |matchadd()|. All matches can
7200 be deleted in one operation by |clearmatches()|.
7201 If {win} is specified, use the window with this number or
7202 window ID instead of the current window.
7203
7204 Can also be used as a |method|: >
7205 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007206<
7207 Return type: |Number|
7208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007209
7210matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7211 Same as |match()|, but return the index of first character
7212 after the match. Example: >
7213 :echo matchend("testing", "ing")
7214< results in "7".
7215 *strspn()* *strcspn()*
7216 Vim doesn't have a strspn() or strcspn() function, but you can
7217 do it with matchend(): >
7218 :let span = matchend(line, '[a-zA-Z]')
7219 :let span = matchend(line, '[^a-zA-Z]')
7220< Except that -1 is returned when there are no matches.
7221
7222 The {start}, if given, has the same meaning as for |match()|. >
7223 :echo matchend("testing", "ing", 2)
7224< results in "7". >
7225 :echo matchend("testing", "ing", 5)
7226< result is "-1".
7227 When {expr} is a |List| the result is equal to |match()|.
7228
7229 Can also be used as a |method|: >
7230 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007231<
7232 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007233
7234
7235matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7236 If {list} is a list of strings, then returns a |List| with all
7237 the strings in {list} that fuzzy match {str}. The strings in
7238 the returned list are sorted based on the matching score.
7239
7240 The optional {dict} argument always supports the following
7241 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007242 matchseq When this item is present return only matches
7243 that contain the characters in {str} in the
7244 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007245 limit Maximum number of matches in {list} to be
7246 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007247
7248 If {list} is a list of dictionaries, then the optional {dict}
7249 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007250 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007251 {str}. The value of this item should be a
7252 string.
7253 text_cb |Funcref| that will be called for every item
7254 in {list} to get the text for fuzzy matching.
7255 This should accept a dictionary item as the
7256 argument and return the text for that item to
7257 use for fuzzy matching.
7258
7259 {str} is treated as a literal string and regular expression
7260 matching is NOT supported. The maximum supported {str} length
7261 is 256.
7262
7263 When {str} has multiple words each separated by white space,
7264 then the list of strings that have all the words is returned.
7265
7266 If there are no matching strings or there is an error, then an
7267 empty list is returned. If length of {str} is greater than
7268 256, then returns an empty list.
7269
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007270 When {limit} is given, matchfuzzy() will find up to this
7271 number of matches in {list} and return them in sorted order.
7272
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007273 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007274 matching strings.
7275
7276 Example: >
7277 :echo matchfuzzy(["clay", "crow"], "cay")
7278< results in ["clay"]. >
7279 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7280< results in a list of buffer names fuzzy matching "ndl". >
7281 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7282< results in a list of buffer information dicts with buffer
7283 names fuzzy matching "ndl". >
7284 :echo getbufinfo()->matchfuzzy("spl",
7285 \ {'text_cb' : {v -> v.name}})
7286< results in a list of buffer information dicts with buffer
7287 names fuzzy matching "spl". >
7288 :echo v:oldfiles->matchfuzzy("test")
7289< results in a list of file names fuzzy matching "test". >
7290 :let l = readfile("buffer.c")->matchfuzzy("str")
7291< results in a list of lines in "buffer.c" fuzzy matching "str". >
7292 :echo ['one two', 'two one']->matchfuzzy('two one')
7293< results in ['two one', 'one two']. >
7294 :echo ['one two', 'two one']->matchfuzzy('two one',
7295 \ {'matchseq': 1})
7296< results in ['two one'].
7297
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007298 Return type: list<string> or list<any>
7299
7300
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007301matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7302 Same as |matchfuzzy()|, but returns the list of matched
7303 strings, the list of character positions where characters
7304 in {str} matches and a list of matching scores. You can
7305 use |byteidx()| to convert a character position to a byte
7306 position.
7307
7308 If {str} matches multiple times in a string, then only the
7309 positions for the best match is returned.
7310
7311 If there are no matching strings or there is an error, then a
7312 list with three empty list items is returned.
7313
7314 Example: >
7315 :echo matchfuzzypos(['testing'], 'tsg')
7316< results in [['testing'], [[0, 2, 6]], [99]] >
7317 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7318< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7319 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7320< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7321
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007322 Return type: list<list<any>>
7323
7324
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007325matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7326 Same as |match()|, but return a |List|. The first item in the
7327 list is the matched string, same as what matchstr() would
7328 return. Following items are submatches, like "\1", "\2", etc.
7329 in |:substitute|. When an optional submatch didn't match an
7330 empty string is used. Example: >
7331 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7332< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7333 When there is no match an empty list is returned.
7334
7335 You can pass in a List, but that is not very useful.
7336
7337 Can also be used as a |method|: >
7338 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007339<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007340 Return type: list<string> or list<any>
7341
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007342 *matchstrlist()*
7343matchstrlist({list}, {pat} [, {dict}])
7344 Returns the |List| of matches in {list} where {pat} matches.
7345 {list} is a |List| of strings. {pat} is matched against each
7346 string in {list}.
7347
7348 The {dict} argument supports following items:
7349 submatches include submatch information (|/\(|)
7350
7351 For each match, a |Dict| with the following items is returned:
7352 byteidx starting byte index of the match.
7353 idx index in {list} of the match.
7354 text matched string
7355 submatches a List of submatches. Present only if
7356 "submatches" is set to v:true in {dict}.
7357
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007358 See |match-pattern| for information about the effect of some
7359 option settings on the pattern.
7360
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007361 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007362 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7363 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7364 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7365 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007366<
7367 If "submatches" is present and is v:true, then submatches like
7368 "\1", "\2", etc. are also returned. Example: >
7369 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7370 \ #{submatches: v:true})
7371 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7372< The "submatches" List always contains 9 items. If a submatch
7373 is not found, then an empty string is returned for that
7374 submatch.
7375
7376 Can also be used as a |method|: >
7377 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007378<
7379 Return type: list<dict<any>> or list<any>
7380
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007381
7382matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7383 Same as |match()|, but return the matched string. Example: >
7384 :echo matchstr("testing", "ing")
7385< results in "ing".
7386 When there is no match "" is returned.
7387 The {start}, if given, has the same meaning as for |match()|. >
7388 :echo matchstr("testing", "ing", 2)
7389< results in "ing". >
7390 :echo matchstr("testing", "ing", 5)
7391< result is "".
7392 When {expr} is a |List| then the matching item is returned.
7393 The type isn't changed, it's not necessarily a String.
7394
7395 Can also be used as a |method|: >
7396 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007397<
7398 Return type: |String|
7399
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007400
7401matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7402 Same as |matchstr()|, but return the matched string, the start
7403 position and the end position of the match. Example: >
7404 :echo matchstrpos("testing", "ing")
7405< results in ["ing", 4, 7].
7406 When there is no match ["", -1, -1] is returned.
7407 The {start}, if given, has the same meaning as for |match()|. >
7408 :echo matchstrpos("testing", "ing", 2)
7409< results in ["ing", 4, 7]. >
7410 :echo matchstrpos("testing", "ing", 5)
7411< result is ["", -1, -1].
7412 When {expr} is a |List| then the matching item, the index
7413 of first item where {pat} matches, the start position and the
7414 end position of the match are returned. >
7415 :echo matchstrpos([1, '__x'], '\a')
7416< result is ["x", 1, 2, 3].
7417 The type isn't changed, it's not necessarily a String.
7418
7419 Can also be used as a |method|: >
7420 GetText()->matchstrpos('word')
7421<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007422 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007423
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007424
7425max({expr}) *max()*
7426 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007427 echo max([apples, pears, oranges])
7428
7429< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7430 it returns the maximum of all values in the Dictionary.
7431 If {expr} is neither a List nor a Dictionary, or one of the
7432 items in {expr} cannot be used as a Number this results in
7433 an error. An empty |List| or |Dictionary| results in zero.
7434
7435 Can also be used as a |method|: >
7436 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007437<
7438 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007439
7440
7441menu_info({name} [, {mode}]) *menu_info()*
7442 Return information about the specified menu {name} in
7443 mode {mode}. The menu name should be specified without the
7444 shortcut character ('&'). If {name} is "", then the top-level
7445 menu names are returned.
7446
7447 {mode} can be one of these strings:
7448 "n" Normal
7449 "v" Visual (including Select)
7450 "o" Operator-pending
7451 "i" Insert
7452 "c" Cmd-line
7453 "s" Select
7454 "x" Visual
7455 "t" Terminal-Job
7456 "" Normal, Visual and Operator-pending
7457 "!" Insert and Cmd-line
7458 When {mode} is omitted, the modes for "" are used.
7459
7460 Returns a |Dictionary| containing the following items:
7461 accel menu item accelerator text |menu-text|
7462 display display name (name without '&')
7463 enabled v:true if this menu item is enabled
7464 Refer to |:menu-enable|
7465 icon name of the icon file (for toolbar)
7466 |toolbar-icon|
7467 iconidx index of a built-in icon
7468 modes modes for which the menu is defined. In
7469 addition to the modes mentioned above, these
7470 characters will be used:
7471 " " Normal, Visual and Operator-pending
7472 name menu item name.
7473 noremenu v:true if the {rhs} of the menu item is not
7474 remappable else v:false.
7475 priority menu order priority |menu-priority|
7476 rhs right-hand-side of the menu item. The returned
7477 string has special characters translated like
7478 in the output of the ":menu" command listing.
7479 When the {rhs} of a menu item is empty, then
7480 "<Nop>" is returned.
7481 script v:true if script-local remapping of {rhs} is
7482 allowed else v:false. See |:menu-script|.
7483 shortcut shortcut key (character after '&' in
7484 the menu name) |menu-shortcut|
7485 silent v:true if the menu item is created
7486 with <silent> argument |:menu-silent|
7487 submenus |List| containing the names of
7488 all the submenus. Present only if the menu
7489 item has submenus.
7490
7491 Returns an empty dictionary if the menu item is not found.
7492
7493 Examples: >
7494 :echo menu_info('Edit.Cut')
7495 :echo menu_info('File.Save', 'n')
7496
7497 " Display the entire menu hierarchy in a buffer
7498 func ShowMenu(name, pfx)
7499 let m = menu_info(a:name)
7500 call append(line('$'), a:pfx .. m.display)
7501 for child in m->get('submenus', [])
7502 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7503 \ a:pfx .. ' ')
7504 endfor
7505 endfunc
7506 new
7507 for topmenu in menu_info('').submenus
7508 call ShowMenu(topmenu, '')
7509 endfor
7510<
7511 Can also be used as a |method|: >
7512 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007513<
7514 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007515
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007516min({expr}) *min()*
7517 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007518 echo min([apples, pears, oranges])
7519
7520< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7521 it returns the minimum of all values in the Dictionary.
7522 If {expr} is neither a List nor a Dictionary, or one of the
7523 items in {expr} cannot be used as a Number this results in
7524 an error. An empty |List| or |Dictionary| results in zero.
7525
7526 Can also be used as a |method|: >
7527 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007528<
7529 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007530
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007531
7532mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007533 Create directory {name}.
7534
Bram Moolenaar938ae282023-02-20 20:44:55 +00007535 When {flags} is present it must be a string. An empty string
7536 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007537
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007538 {flags} can contain these character flags:
7539 "p" intermediate directories will be created as necessary
7540 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007541 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007542 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007543 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007544
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007545 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007546 some directories may already exist. Only the first one that
7547 is created and what it contains is scheduled to be deleted.
7548 E.g. when using: >
7549 call mkdir('subdir/tmp/autoload', 'pR')
7550< and "subdir" already exists then "subdir/tmp" will be
7551 scheduled for deletion, like with: >
7552 defer delete('subdir/tmp', 'rf')
7553< Note that if scheduling the defer fails the directory is not
7554 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007555
7556 If {prot} is given it is used to set the protection bits of
7557 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7558 the user, readable for others). Use 0o700 to make it
7559 unreadable for others. This is only used for the last part of
7560 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7561 created with 0o755.
7562 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007563 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007564
7565< This function is not available in the |sandbox|.
7566
7567 There is no error if the directory already exists and the "p"
7568 flag is passed (since patch 8.0.1708). However, without the
7569 "p" option the call will fail.
7570
7571 The function result is a Number, which is TRUE if the call was
7572 successful or FALSE if the directory creation failed or partly
7573 failed.
7574
7575 Not available on all systems. To check use: >
7576 :if exists("*mkdir")
7577
7578< Can also be used as a |method|: >
7579 GetName()->mkdir()
7580<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007581 Return type: |Number|
7582
7583
7584mode([{expr}]) *mode()*
7585 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007586 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007587 a non-empty String (|non-zero-arg|), then the full mode is
7588 returned, otherwise only the first letter is returned.
7589 Also see |state()|.
7590
7591 n Normal
7592 no Operator-pending
7593 nov Operator-pending (forced characterwise |o_v|)
7594 noV Operator-pending (forced linewise |o_V|)
7595 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7596 CTRL-V is one character
7597 niI Normal using |i_CTRL-O| in |Insert-mode|
7598 niR Normal using |i_CTRL-O| in |Replace-mode|
7599 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7600 nt Terminal-Normal (insert goes to Terminal-Job mode)
7601 v Visual by character
7602 vs Visual by character using |v_CTRL-O| in Select mode
7603 V Visual by line
7604 Vs Visual by line using |v_CTRL-O| in Select mode
7605 CTRL-V Visual blockwise
7606 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7607 s Select by character
7608 S Select by line
7609 CTRL-S Select blockwise
7610 i Insert
7611 ic Insert mode completion |compl-generic|
7612 ix Insert mode |i_CTRL-X| completion
7613 R Replace |R|
7614 Rc Replace mode completion |compl-generic|
7615 Rx Replace mode |i_CTRL-X| completion
7616 Rv Virtual Replace |gR|
7617 Rvc Virtual Replace mode completion |compl-generic|
7618 Rvx Virtual Replace mode |i_CTRL-X| completion
7619 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007620 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007621 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007622 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007623 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007624 ce Normal Ex mode |Q|
7625 r Hit-enter prompt
7626 rm The -- more -- prompt
7627 r? A |:confirm| query of some sort
7628 ! Shell or external command is executing
7629 t Terminal-Job mode: keys go to the job
7630
7631 This is useful in the 'statusline' option or when used
7632 with |remote_expr()| In most other places it always returns
7633 "c" or "n".
7634 Note that in the future more modes and more specific modes may
7635 be added. It's better not to compare the whole string but only
7636 the leading character(s).
7637 Also see |visualmode()|.
7638
7639 Can also be used as a |method|: >
7640 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007641<
7642 Return type: |String|
7643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007644
7645mzeval({expr}) *mzeval()*
7646 Evaluate MzScheme expression {expr} and return its result
7647 converted to Vim data structures.
7648 Numbers and strings are returned as they are.
7649 Pairs (including lists and improper lists) and vectors are
7650 returned as Vim |Lists|.
7651 Hash tables are represented as Vim |Dictionary| type with keys
7652 converted to strings.
7653 All other types are converted to string with display function.
7654 Examples: >
7655 :mz (define l (list 1 2 3))
7656 :mz (define h (make-hash)) (hash-set! h "list" l)
7657 :echo mzeval("l")
7658 :echo mzeval("h")
7659<
7660 Note that in a `:def` function local variables are not visible
7661 to {expr}.
7662
7663 Can also be used as a |method|: >
7664 GetExpr()->mzeval()
7665<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007666 Return type: any, depending on {expr}
7667
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007668 {only available when compiled with the |+mzscheme| feature}
7669
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007670
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007671nextnonblank({lnum}) *nextnonblank()*
7672 Return the line number of the first line at or below {lnum}
7673 that is not blank. Example: >
7674 if getline(nextnonblank(1)) =~ "Java"
7675< When {lnum} is invalid or there is no non-blank line at or
7676 below it, zero is returned.
7677 {lnum} is used like with |getline()|.
7678 See also |prevnonblank()|.
7679
7680 Can also be used as a |method|: >
7681 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007682<
7683 Return type: |Number|
7684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007685
7686nr2char({expr} [, {utf8}]) *nr2char()*
7687 Return a string with a single character, which has the number
7688 value {expr}. Examples: >
7689 nr2char(64) returns "@"
7690 nr2char(32) returns " "
7691< When {utf8} is omitted or zero, the current 'encoding' is used.
7692 Example for "utf-8": >
7693 nr2char(300) returns I with bow character
7694< When {utf8} is TRUE, always return UTF-8 characters.
7695 Note that a NUL character in the file is specified with
7696 nr2char(10), because NULs are represented with newline
7697 characters. nr2char(0) is a real NUL and terminates the
7698 string, thus results in an empty string.
7699 To turn a list of character numbers into a string: >
7700 let list = [65, 66, 67]
7701 let str = join(map(list, {_, val -> nr2char(val)}), '')
7702< Result: "ABC"
7703
7704 Can also be used as a |method|: >
7705 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007706<
7707 Return type: |String|
7708
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007709
7710or({expr}, {expr}) *or()*
7711 Bitwise OR on the two arguments. The arguments are converted
7712 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007713 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007714 Example: >
7715 :let bits = or(bits, 0x80)
7716< Can also be used as a |method|: >
7717 :let bits = bits->or(0x80)
7718
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007719< Rationale: The reason this is a function and not using the "|"
7720 character like many languages, is that Vi has always used "|"
7721 to separate commands. In many places it would not be clear if
7722 "|" is an operator or a command separator.
7723
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007724 Return type: |Number|
7725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007726
7727pathshorten({path} [, {len}]) *pathshorten()*
7728 Shorten directory names in the path {path} and return the
7729 result. The tail, the file name, is kept as-is. The other
7730 components in the path are reduced to {len} letters in length.
7731 If {len} is omitted or smaller than 1 then 1 is used (single
7732 letters). Leading '~' and '.' characters are kept. Examples: >
7733 :echo pathshorten('~/.vim/autoload/myfile.vim')
7734< ~/.v/a/myfile.vim ~
7735>
7736 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7737< ~/.vi/au/myfile.vim ~
7738 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007739 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007740
7741 Can also be used as a |method|: >
7742 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007743<
7744 Return type: |String|
7745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007746
7747perleval({expr}) *perleval()*
7748 Evaluate Perl expression {expr} in scalar context and return
7749 its result converted to Vim data structures. If value can't be
7750 converted, it is returned as a string Perl representation.
7751 Note: If you want an array or hash, {expr} must return a
7752 reference to it.
7753 Example: >
7754 :echo perleval('[1 .. 4]')
7755< [1, 2, 3, 4]
7756
7757 Note that in a `:def` function local variables are not visible
7758 to {expr}.
7759
7760 Can also be used as a |method|: >
7761 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007762<
7763 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007764
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007765 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007766
7767
7768popup_ functions are documented here: |popup-functions|
7769
7770
7771pow({x}, {y}) *pow()*
7772 Return the power of {x} to the exponent {y} as a |Float|.
7773 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007774 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007775 Examples: >
7776 :echo pow(3, 3)
7777< 27.0 >
7778 :echo pow(2, 16)
7779< 65536.0 >
7780 :echo pow(32, 0.20)
7781< 2.0
7782
7783 Can also be used as a |method|: >
7784 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007785<
7786 Return type: |Number|
7787
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007788
7789prevnonblank({lnum}) *prevnonblank()*
7790 Return the line number of the first line at or above {lnum}
7791 that is not blank. Example: >
7792 let ind = indent(prevnonblank(v:lnum - 1))
7793< When {lnum} is invalid or there is no non-blank line at or
7794 above it, zero is returned.
7795 {lnum} is used like with |getline()|.
7796 Also see |nextnonblank()|.
7797
7798 Can also be used as a |method|: >
7799 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007800<
7801 Return type: |Number|
7802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007803
7804printf({fmt}, {expr1} ...) *printf()*
7805 Return a String with {fmt}, where "%" items are replaced by
7806 the formatted form of their respective arguments. Example: >
7807 printf("%4d: E%d %.30s", lnum, errno, msg)
7808< May result in:
7809 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7810
7811 When used as a |method| the base is passed as the second
7812 argument: >
7813 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007814<
7815 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007816
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007817 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007818 %s string
7819 %6S string right-aligned in 6 display cells
7820 %6s string right-aligned in 6 bytes
7821 %.9s string truncated to 9 bytes
7822 %c single byte
7823 %d decimal number
7824 %5d decimal number padded with spaces to 5 characters
7825 %x hex number
7826 %04x hex number padded with zeros to at least 4 characters
7827 %X hex number using upper case letters
7828 %o octal number
7829 %08b binary number padded with zeros to at least 8 chars
7830 %f floating point number as 12.23, inf, -inf or nan
7831 %F floating point number as 12.23, INF, -INF or NAN
7832 %e floating point number as 1.23e3, inf, -inf or nan
7833 %E floating point number as 1.23E3, INF, -INF or NAN
7834 %g floating point number, as %f or %e depending on value
7835 %G floating point number, as %F or %E depending on value
7836 %% the % character itself
7837
7838 Conversion specifications start with '%' and end with the
7839 conversion type. All other characters are copied unchanged to
7840 the result.
7841
7842 The "%" starts a conversion specification. The following
7843 arguments appear in sequence:
7844
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007845 % [pos-argument] [flags] [field-width] [.precision] type
7846
7847 pos-argument
7848 At most one positional argument specifier. These
7849 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007850
7851 flags
7852 Zero or more of the following flags:
7853
7854 # The value should be converted to an "alternate
7855 form". For c, d, and s conversions, this option
7856 has no effect. For o conversions, the precision
7857 of the number is increased to force the first
7858 character of the output string to a zero (except
7859 if a zero value is printed with an explicit
7860 precision of zero).
7861 For b and B conversions, a non-zero result has
7862 the string "0b" (or "0B" for B conversions)
7863 prepended to it.
7864 For x and X conversions, a non-zero result has
7865 the string "0x" (or "0X" for X conversions)
7866 prepended to it.
7867
7868 0 (zero) Zero padding. For all conversions the converted
7869 value is padded on the left with zeros rather
7870 than blanks. If a precision is given with a
7871 numeric conversion (d, b, B, o, x, and X), the 0
7872 flag is ignored.
7873
7874 - A negative field width flag; the converted value
7875 is to be left adjusted on the field boundary.
7876 The converted value is padded on the right with
7877 blanks, rather than on the left with blanks or
7878 zeros. A - overrides a 0 if both are given.
7879
7880 ' ' (space) A blank should be left before a positive
7881 number produced by a signed conversion (d).
7882
7883 + A sign must always be placed before a number
7884 produced by a signed conversion. A + overrides
7885 a space if both are used.
7886
7887 field-width
7888 An optional decimal digit string specifying a minimum
7889 field width. If the converted value has fewer bytes
7890 than the field width, it will be padded with spaces on
7891 the left (or right, if the left-adjustment flag has
7892 been given) to fill out the field width. For the S
7893 conversion the count is in cells.
7894
7895 .precision
7896 An optional precision, in the form of a period '.'
7897 followed by an optional digit string. If the digit
7898 string is omitted, the precision is taken as zero.
7899 This gives the minimum number of digits to appear for
7900 d, o, x, and X conversions, the maximum number of
7901 bytes to be printed from a string for s conversions,
7902 or the maximum number of cells to be printed from a
7903 string for S conversions.
7904 For floating point it is the number of digits after
7905 the decimal point.
7906
7907 type
7908 A character that specifies the type of conversion to
7909 be applied, see below.
7910
7911 A field width or precision, or both, may be indicated by an
7912 asterisk '*' instead of a digit string. In this case, a
7913 Number argument supplies the field width or precision. A
7914 negative field width is treated as a left adjustment flag
7915 followed by a positive field width; a negative precision is
7916 treated as though it were missing. Example: >
7917 :echo printf("%d: %.*s", nr, width, line)
7918< This limits the length of the text used from "line" to
7919 "width" bytes.
7920
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007921 If the argument to be formatted is specified using a
7922 positional argument specifier, and a '*' is used to indicate
7923 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007924 precision, the argument(s) to be used must also be specified
7925 using a {n$} positional argument specifier. See |printf-$|.
7926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007927 The conversion specifiers and their meanings are:
7928
7929 *printf-d* *printf-b* *printf-B* *printf-o*
7930 *printf-x* *printf-X*
7931 dbBoxX The Number argument is converted to signed decimal
7932 (d), unsigned binary (b and B), unsigned octal (o), or
7933 unsigned hexadecimal (x and X) notation. The letters
7934 "abcdef" are used for x conversions; the letters
7935 "ABCDEF" are used for X conversions.
7936 The precision, if any, gives the minimum number of
7937 digits that must appear; if the converted value
7938 requires fewer digits, it is padded on the left with
7939 zeros.
7940 In no case does a non-existent or small field width
7941 cause truncation of a numeric field; if the result of
7942 a conversion is wider than the field width, the field
7943 is expanded to contain the conversion result.
7944 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007945 The 'l' modifier indicates the argument is a long
7946 integer. The size will be 32 bits or 64 bits
7947 depending on your platform.
7948 The "ll" modifier indicates the argument is 64 bits.
7949 The b and B conversion specifiers never take a width
7950 modifier and always assume their argument is a 64 bit
7951 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007952 Generally, these modifiers are not useful. They are
7953 ignored when type is known from the argument.
7954
7955 i alias for d
7956 D alias for ld
7957 U alias for lu
7958 O alias for lo
7959
7960 *printf-c*
7961 c The Number argument is converted to a byte, and the
7962 resulting character is written.
7963
7964 *printf-s*
7965 s The text of the String argument is used. If a
7966 precision is specified, no more bytes than the number
7967 specified are used.
7968 If the argument is not a String type, it is
7969 automatically converted to text with the same format
7970 as ":echo".
7971 *printf-S*
7972 S The text of the String argument is used. If a
7973 precision is specified, no more display cells than the
7974 number specified are used.
7975
7976 *printf-f* *E807*
7977 f F The Float argument is converted into a string of the
7978 form 123.456. The precision specifies the number of
7979 digits after the decimal point. When the precision is
7980 zero the decimal point is omitted. When the precision
7981 is not specified 6 is used. A really big number
7982 (out of range or dividing by zero) results in "inf"
7983 or "-inf" with %f (INF or -INF with %F).
7984 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7985 Example: >
7986 echo printf("%.2f", 12.115)
7987< 12.12
7988 Note that roundoff depends on the system libraries.
7989 Use |round()| when in doubt.
7990
7991 *printf-e* *printf-E*
7992 e E The Float argument is converted into a string of the
7993 form 1.234e+03 or 1.234E+03 when using 'E'. The
7994 precision specifies the number of digits after the
7995 decimal point, like with 'f'.
7996
7997 *printf-g* *printf-G*
7998 g G The Float argument is converted like with 'f' if the
7999 value is between 0.001 (inclusive) and 10000000.0
8000 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8001 for 'G'. When no precision is specified superfluous
8002 zeroes and '+' signs are removed, except for the zero
8003 immediately after the decimal point. Thus 10000000.0
8004 results in 1.0e7.
8005
8006 *printf-%*
8007 % A '%' is written. No argument is converted. The
8008 complete conversion specification is "%%".
8009
8010 When a Number argument is expected a String argument is also
8011 accepted and automatically converted.
8012 When a Float or String argument is expected a Number argument
8013 is also accepted and automatically converted.
8014 Any other argument type results in an error message.
8015
8016 *E766* *E767*
8017 The number of {exprN} arguments must exactly match the number
8018 of "%" items. If there are not sufficient or too many
8019 arguments an error is given. Up to 18 arguments can be used.
8020
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008021 *printf-$*
8022 In certain languages, error and informative messages are
8023 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008024 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008025 having a different word order, positional arguments may be
8026 used to indicate this. For instance: >
8027
h_east596a9f22023-11-21 21:24:23 +09008028 #, c-format
8029 msgid "%s returning %s"
8030 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008031<
h_east596a9f22023-11-21 21:24:23 +09008032 In this example, the sentence has its 2 string arguments
8033 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008034
h_east596a9f22023-11-21 21:24:23 +09008035 echo printf(
8036 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8037 "Bram", "Moolenaar")
8038< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008039
h_east596a9f22023-11-21 21:24:23 +09008040 echo printf(
8041 "In Belgium, vim's creator's name is: %2$s %1$s",
8042 "Bram", "Moolenaar")
8043< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008044
8045 Width (and precision) can be specified using the '*' specifier.
8046 In this case, you must specify the field width position in the
8047 argument list. >
8048
h_east596a9f22023-11-21 21:24:23 +09008049 echo printf("%1$*2$.*3$d", 1, 2, 3)
8050< 001 >
8051 echo printf("%2$*3$.*1$d", 1, 2, 3)
8052< 2 >
8053 echo printf("%3$*1$.*2$d", 1, 2, 3)
8054< 03 >
8055 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8056< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008057
8058 You can mix specifying the width and/or precision directly
8059 and via positional arguments: >
8060
h_east596a9f22023-11-21 21:24:23 +09008061 echo printf("%1$4.*2$f", 1.4142135, 6)
8062< 1.414214 >
8063 echo printf("%1$*2$.4f", 1.4142135, 6)
8064< 1.4142 >
8065 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8066< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008067
Christ van Willegenc35fc032024-03-14 18:30:41 +01008068 You will get an overflow error |E1510|, when the field-width
8069 or precision will result in a string longer than 6400 chars.
8070
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008071 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008072 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008073 echo printf("%s%1$s", "One", "Two")
8074< E1500: Cannot mix positional and non-positional arguments:
8075 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008076
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008077 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008078 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008079 echo printf("%3$s%1$s", "One", "Two", "Three")
8080< E1501: format argument 2 unused in $-style format:
8081 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008082
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008083 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008084 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008085 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8086< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008087
8088 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008089 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8090< E1502: Positional argument 2 used as field width reused as
8091 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008092
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008093 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008094 When a positional argument is used, but not the correct number
8095 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008096 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8097< E1503: Positional argument 3 out of bounds: %1$d at width
8098 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008099
8100 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008101 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8102< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8103 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008104
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008105 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008106 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008107 echo printf("%1$s %2$s %1$s", "One", "Two")
8108< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008109
8110 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008111 echo printf("%1$s %2$s %1$d", "One", "Two")
8112< E1504: Positional argument 1 type used inconsistently:
8113 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008114
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008115 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008116 Various other errors that lead to a format string being
8117 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008118 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8119< E1505: Invalid format specifier: %1$d at width %2$d is:
8120 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008121
Christ van Willegenea746f92023-10-05 20:48:36 +02008122 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008123 This internal error indicates that the logic to parse a
8124 positional format argument ran into a problem that couldn't be
8125 otherwise reported. Please file a bug against Vim if you run
8126 into this, copying the exact format string and parameters that
8127 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008128
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008129 Return type: |String|
8130
Christ van Willegenea746f92023-10-05 20:48:36 +02008131
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008132prompt_getprompt({buf}) *prompt_getprompt()*
8133 Returns the effective prompt text for buffer {buf}. {buf} can
8134 be a buffer name or number. See |prompt-buffer|.
8135
8136 If the buffer doesn't exist or isn't a prompt buffer, an empty
8137 string is returned.
8138
8139 Can also be used as a |method|: >
8140 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008141<
8142 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008143
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008144 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008145
8146
8147prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8148 Set prompt callback for buffer {buf} to {expr}. When {expr}
8149 is an empty string the callback is removed. This has only
8150 effect if {buf} has 'buftype' set to "prompt".
8151
8152 The callback is invoked when pressing Enter. The current
8153 buffer will always be the prompt buffer. A new line for a
8154 prompt is added before invoking the callback, thus the prompt
8155 for which the callback was invoked will be in the last but one
8156 line.
8157 If the callback wants to add text to the buffer, it must
8158 insert it above the last line, since that is where the current
8159 prompt is. This can also be done asynchronously.
8160 The callback is invoked with one argument, which is the text
8161 that was entered at the prompt. This can be an empty string
8162 if the user only typed Enter.
8163 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008164 func s:TextEntered(text)
8165 if a:text == 'exit' || a:text == 'quit'
8166 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008167 " Reset 'modified' to allow the buffer to be closed.
8168 " We assume there is nothing useful to be saved.
8169 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008170 close
8171 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008172 " Do something useful with "a:text". In this example
8173 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008174 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008175 endif
8176 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008177 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008178
8179< Can also be used as a |method|: >
8180 GetBuffer()->prompt_setcallback(callback)
8181
8182< {only available when compiled with the |+channel| feature}
8183
8184prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8185 Set a callback for buffer {buf} to {expr}. When {expr} is an
8186 empty string the callback is removed. This has only effect if
8187 {buf} has 'buftype' set to "prompt".
8188
8189 This callback will be invoked when pressing CTRL-C in Insert
8190 mode. Without setting a callback Vim will exit Insert mode,
8191 as in any buffer.
8192
8193 Can also be used as a |method|: >
8194 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008195<
8196 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008197
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008198 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008199
8200prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8201 Set prompt for buffer {buf} to {text}. You most likely want
8202 {text} to end in a space.
8203 The result is only visible if {buf} has 'buftype' set to
8204 "prompt". Example: >
8205 call prompt_setprompt(bufnr(), 'command: ')
8206<
8207 Can also be used as a |method|: >
8208 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008209<
8210 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008211
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008212 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008213
8214prop_ functions are documented here: |text-prop-functions|
8215
8216pum_getpos() *pum_getpos()*
8217 If the popup menu (see |ins-completion-menu|) is not visible,
8218 returns an empty |Dictionary|, otherwise, returns a
8219 |Dictionary| with the following keys:
8220 height nr of items visible
8221 width screen cells
8222 row top screen row (0 first row)
8223 col leftmost screen column (0 first col)
8224 size total nr of items
8225 scrollbar |TRUE| if scrollbar is visible
8226
8227 The values are the same as in |v:event| during
8228 |CompleteChanged|.
8229
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008230 Return type: dict<any>
8231
8232
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008233pumvisible() *pumvisible()*
8234 Returns non-zero when the popup menu is visible, zero
8235 otherwise. See |ins-completion-menu|.
8236 This can be used to avoid some things that would remove the
8237 popup menu.
8238
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008239 Return type: |Number|
8240
8241
zeertzjq7c515282024-11-10 20:26:12 +01008242py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008243 Evaluate Python expression {expr} and return its result
8244 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008245 If a {locals} |Dictionary| is given, it defines set of local
8246 variables available in the expression. The keys are variable
8247 names and the values are the variable values. |Dictionary| and
8248 |List| values are referenced, and may be updated by the
8249 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008250 Numbers and strings are returned as they are (strings are
8251 copied though, Unicode strings are additionally converted to
8252 'encoding').
8253 Lists are represented as Vim |List| type.
8254 Dictionaries are represented as Vim |Dictionary| type with
8255 keys converted to strings.
8256 Note that in a `:def` function local variables are not visible
8257 to {expr}.
8258
8259 Can also be used as a |method|: >
8260 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008261 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008262<
8263 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008264
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008265 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008266
8267 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008268pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008269 Evaluate Python expression {expr} and return its result
8270 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008271 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008272 Numbers and strings are returned as they are (strings are
8273 copied though).
8274 Lists are represented as Vim |List| type.
8275 Dictionaries are represented as Vim |Dictionary| type,
8276 non-string keys result in error.
8277 Note that in a `:def` function local variables are not visible
8278 to {expr}.
8279
8280 Can also be used as a |method|: >
8281 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008282<
8283 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008284
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008285 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008286
zeertzjq7c515282024-11-10 20:26:12 +01008287pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008288 Evaluate Python expression {expr} and return its result
8289 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008290 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008291 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8292 See also: |pyeval()|, |py3eval()|
8293
8294 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008295 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008296<
8297 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008298
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008299 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008300 |+python3| feature}
8301
8302rand([{expr}]) *rand()* *random*
8303 Return a pseudo-random Number generated with an xoshiro128**
8304 algorithm using seed {expr}. The returned number is 32 bits,
8305 also on 64 bits systems, for consistency.
8306 {expr} can be initialized by |srand()| and will be updated by
8307 rand(). If {expr} is omitted, an internal seed value is used
8308 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008309 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008310
8311 Examples: >
8312 :echo rand()
8313 :let seed = srand()
8314 :echo rand(seed)
8315 :echo rand(seed) % 16 " random number 0 - 15
8316<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008317 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008318
8319 *E726* *E727*
8320range({expr} [, {max} [, {stride}]]) *range()*
8321 Returns a |List| with Numbers:
8322 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8323 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8324 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8325 {max}] (increasing {expr} with {stride} each time, not
8326 producing a value past {max}).
8327 When the maximum is one before the start the result is an
8328 empty list. When the maximum is more than one before the
8329 start this is an error.
8330 Examples: >
8331 range(4) " [0, 1, 2, 3]
8332 range(2, 4) " [2, 3, 4]
8333 range(2, 9, 3) " [2, 5, 8]
8334 range(2, -2, -1) " [2, 1, 0, -1, -2]
8335 range(0) " []
8336 range(2, 0) " error!
8337<
8338 Can also be used as a |method|: >
8339 GetExpr()->range()
8340<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008341 Return type: list<number>
8342
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008343
K.Takata11df3ae2022-10-19 14:02:40 +01008344readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008345 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008346 If {offset} is specified, read the file from the specified
8347 offset. If it is a negative value, it is used as an offset
8348 from the end of the file. E.g., to read the last 12 bytes: >
8349 readblob('file.bin', -12)
8350< If {size} is specified, only the specified size will be read.
8351 E.g. to read the first 100 bytes of a file: >
8352 readblob('file.bin', 0, 100)
8353< If {size} is -1 or omitted, the whole data starting from
8354 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008355 This can be also used to read the data from a character device
8356 on Unix when {size} is explicitly set. Only if the device
8357 supports seeking {offset} can be used. Otherwise it should be
8358 zero. E.g. to read 10 bytes from a serial console: >
8359 readblob('/dev/ttyS0', 0, 10)
8360< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008361 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008362 When the offset is beyond the end of the file the result is an
8363 empty blob.
8364 When trying to read more bytes than are available the result
8365 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008366 Also see |readfile()| and |writefile()|.
8367
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008368 Return type: |Blob|
8369
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008370
8371readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8372 Return a list with file and directory names in {directory}.
8373 You can also use |glob()| if you don't need to do complicated
8374 things, such as limiting the number of matches.
8375 The list will be sorted (case sensitive), see the {dict}
8376 argument below for changing the sort order.
8377
8378 When {expr} is omitted all entries are included.
8379 When {expr} is given, it is evaluated to check what to do:
8380 If {expr} results in -1 then no further entries will
8381 be handled.
8382 If {expr} results in 0 then this entry will not be
8383 added to the list.
8384 If {expr} results in 1 then this entry will be added
8385 to the list.
8386 The entries "." and ".." are always excluded.
8387 Each time {expr} is evaluated |v:val| is set to the entry name.
8388 When {expr} is a function the name is passed as the argument.
8389 For example, to get a list of files ending in ".txt": >
8390 readdir(dirname, {n -> n =~ '.txt$'})
8391< To skip hidden and backup files: >
8392 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008393< *E857*
8394 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008395 values. Currently this is used to specify if and how sorting
8396 should be performed. The dict can have the following members:
8397
8398 sort How to sort the result returned from the system.
8399 Valid values are:
8400 "none" do not sort (fastest method)
8401 "case" sort case sensitive (byte value of
8402 each character, technically, using
8403 strcmp()) (default)
8404 "icase" sort case insensitive (technically
8405 using strcasecmp())
8406 "collate" sort using the collation order
8407 of the "POSIX" or "C" |locale|
8408 (technically using strcoll())
8409 Other values are silently ignored.
8410
8411 For example, to get a list of all files in the current
8412 directory without sorting the individual entries: >
8413 readdir('.', '1', #{sort: 'none'})
8414< If you want to get a directory tree: >
8415 function! s:tree(dir)
8416 return {a:dir : map(readdir(a:dir),
8417 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008418 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008419 endfunction
8420 echo s:tree(".")
8421<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008422 Returns an empty List on error.
8423
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008424 Can also be used as a |method|: >
8425 GetDirName()->readdir()
8426<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008427 Return type: list<string> or list<any>
8428
8429
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008430readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8431 Extended version of |readdir()|.
8432 Return a list of Dictionaries with file and directory
8433 information in {directory}.
8434 This is useful if you want to get the attributes of file and
8435 directory at the same time as getting a list of a directory.
8436 This is much faster than calling |readdir()| then calling
8437 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8438 each file and directory especially on MS-Windows.
8439 The list will by default be sorted by name (case sensitive),
8440 the sorting can be changed by using the optional {dict}
8441 argument, see |readdir()|.
8442
8443 The Dictionary for file and directory information has the
8444 following items:
8445 group Group name of the entry. (Only on Unix)
8446 name Name of the entry.
8447 perm Permissions of the entry. See |getfperm()|.
8448 size Size of the entry. See |getfsize()|.
8449 time Timestamp of the entry. See |getftime()|.
8450 type Type of the entry.
8451 On Unix, almost same as |getftype()| except:
8452 Symlink to a dir "linkd"
8453 Other symlink "link"
8454 On MS-Windows:
8455 Normal file "file"
8456 Directory "dir"
8457 Junction "junction"
8458 Symlink to a dir "linkd"
8459 Other symlink "link"
8460 Other reparse point "reparse"
8461 user User name of the entry's owner. (Only on Unix)
8462 On Unix, if the entry is a symlink, the Dictionary includes
8463 the information of the target (except the "type" item).
8464 On MS-Windows, it includes the information of the symlink
8465 itself because of performance reasons.
8466
8467 When {expr} is omitted all entries are included.
8468 When {expr} is given, it is evaluated to check what to do:
8469 If {expr} results in -1 then no further entries will
8470 be handled.
8471 If {expr} results in 0 then this entry will not be
8472 added to the list.
8473 If {expr} results in 1 then this entry will be added
8474 to the list.
8475 The entries "." and ".." are always excluded.
8476 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8477 of the entry.
8478 When {expr} is a function the entry is passed as the argument.
8479 For example, to get a list of files ending in ".txt": >
8480 readdirex(dirname, {e -> e.name =~ '.txt$'})
8481<
8482 For example, to get a list of all files in the current
8483 directory without sorting the individual entries: >
8484 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008485<
8486 Can also be used as a |method|: >
8487 GetDirName()->readdirex()
8488<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008489 Return type: list<dict<any>> or list<any>
8490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008491
8492 *readfile()*
8493readfile({fname} [, {type} [, {max}]])
8494 Read file {fname} and return a |List|, each line of the file
8495 as an item. Lines are broken at NL characters. Macintosh
8496 files separated with CR will result in a single long line
8497 (unless a NL appears somewhere).
8498 All NUL characters are replaced with a NL character.
8499 When {type} contains "b" binary mode is used:
8500 - When the last line ends in a NL an extra empty list item is
8501 added.
8502 - No CR characters are removed.
8503 Otherwise:
8504 - CR characters that appear before a NL are removed.
8505 - Whether the last line ends in a NL or not does not matter.
8506 - When 'encoding' is Unicode any UTF-8 byte order mark is
8507 removed from the text.
8508 When {max} is given this specifies the maximum number of lines
8509 to be read. Useful if you only want to check the first ten
8510 lines of a file: >
8511 :for line in readfile(fname, '', 10)
8512 : if line =~ 'Date' | echo line | endif
8513 :endfor
8514< When {max} is negative -{max} lines from the end of the file
8515 are returned, or as many as there are.
8516 When {max} is zero the result is an empty list.
8517 Note that without {max} the whole file is read into memory.
8518 Also note that there is no recognition of encoding. Read a
8519 file into a buffer if you need to.
8520 Deprecated (use |readblob()| instead): When {type} contains
8521 "B" a |Blob| is returned with the binary data of the file
8522 unmodified.
8523 When the file can't be opened an error message is given and
8524 the result is an empty list.
8525 Also see |writefile()|.
8526
8527 Can also be used as a |method|: >
8528 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008529<
8530 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008531
8532reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8533 {func} is called for every item in {object}, which can be a
8534 |String|, |List| or a |Blob|. {func} is called with two
8535 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008536 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008537
8538 {initial} is the initial result. When omitted, the first item
8539 in {object} is used and {func} is first called for the second
8540 item. If {initial} is not given and {object} is empty no
8541 result can be computed, an E998 error is given.
8542
8543 Examples: >
8544 echo reduce([1, 3, 5], { acc, val -> acc + val })
8545 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8546 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8547 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8548<
8549 Can also be used as a |method|: >
8550 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008551<
8552 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8553 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008554
8555
8556reg_executing() *reg_executing()*
8557 Returns the single letter name of the register being executed.
8558 Returns an empty string when no register is being executed.
8559 See |@|.
8560
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008561 Return type: |String|
8562
8563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008564reg_recording() *reg_recording()*
8565 Returns the single letter name of the register being recorded.
8566 Returns an empty string when not recording. See |q|.
8567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008568 Return type: |String|
8569
8570
8571reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008572reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008573reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008574 Return an item that represents a time value. The item is a
8575 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008576 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008577 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008578 string or |reltimefloat()| to convert to a Float. For
8579 example, to see the time spent in function Work(): >
8580 var startTime = reltime()
8581 Work()
8582 echo startTime->reltime()->reltimestr()
8583<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008584 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008585 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008586 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008587 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008588 specified in the argument.
8589 With two arguments it returns the time passed between {start}
8590 and {end}.
8591
8592 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008593 reltime(). If there is an error an empty List is returned in
8594 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008595
8596 Can also be used as a |method|: >
8597 GetStart()->reltime()
8598<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008599 Return type: list<number>
8600
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008601 {only available when compiled with the |+reltime| feature}
8602
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008604reltimefloat({time}) *reltimefloat()*
8605 Return a Float that represents the time value of {time}.
8606 Example: >
8607 let start = reltime()
8608 call MyFunction()
8609 let seconds = reltimefloat(reltime(start))
8610< See the note of reltimestr() about overhead.
8611 Also see |profiling|.
8612 If there is an error 0.0 is returned in legacy script, in Vim9
8613 script an error is given.
8614
8615 Can also be used as a |method|: >
8616 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008617<
8618 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008619
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008620 {only available when compiled with the |+reltime| feature}
8621
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008622
8623reltimestr({time}) *reltimestr()*
8624 Return a String that represents the time value of {time}.
8625 This is the number of seconds, a dot and the number of
8626 microseconds. Example: >
8627 let start = reltime()
8628 call MyFunction()
8629 echo reltimestr(reltime(start))
8630< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008631 The accuracy depends on the system. Use reltimefloat() for the
8632 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008633 Leading spaces are used to make the string align nicely. You
8634 can use split() to remove it. >
8635 echo split(reltimestr(reltime(start)))[0]
8636< Also see |profiling|.
8637 If there is an error an empty string is returned in legacy
8638 script, in Vim9 script an error is given.
8639
8640 Can also be used as a |method|: >
8641 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008642<
8643 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008644
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008645 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008646
8647 *remote_expr()* *E449*
8648remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008649 Send the {string} to {server}. The {server} argument is a
8650 string, also see |{server}|.
8651
8652 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008653 after evaluation. The result must be a String or a |List|
8654 other types will be converted to String. A |List| is turned
8655 into a String by joining the items with a line break in
8656 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008657
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008658 If {idvar} is present and not empty, it is taken as the name
8659 of a variable and a {serverid} for later use with
8660 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008661
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008662 If {timeout} is given the read times out after this many
8663 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008664
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008665 See also |clientserver| |RemoteReply|.
8666 This function is not available in the |sandbox|.
8667 {only available when compiled with the |+clientserver| feature}
8668 Note: Any errors will cause a local error message to be issued
8669 and the result will be the empty string.
8670
8671 Variables will be evaluated in the global namespace,
8672 independent of a function currently being active. Except
8673 when in debug mode, then local function variables and
8674 arguments can be evaluated.
8675
8676 Examples: >
8677 :echo remote_expr("gvim", "2+2")
8678 :echo remote_expr("gvim1", "b:current_syntax")
8679<
8680 Can also be used as a |method|: >
8681 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008682<
8683 Return type: |String| or list<{type}>
8684
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008685
8686remote_foreground({server}) *remote_foreground()*
8687 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008688 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008689 This works like: >
8690 remote_expr({server}, "foreground()")
8691< Except that on Win32 systems the client does the work, to work
8692 around the problem that the OS doesn't always allow the server
8693 to bring itself to the foreground.
8694 Note: This does not restore the window if it was minimized,
8695 like foreground() does.
8696 This function is not available in the |sandbox|.
8697
8698 Can also be used as a |method|: >
8699 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008700<
8701 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008702
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008703 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008704 Win32 console version}
8705
8706
8707remote_peek({serverid} [, {retvar}]) *remote_peek()*
8708 Returns a positive number if there are available strings
8709 from {serverid}. Copies any reply string into the variable
8710 {retvar} if specified. {retvar} must be a string with the
8711 name of a variable.
8712 Returns zero if none are available.
8713 Returns -1 if something is wrong.
8714 See also |clientserver|.
8715 This function is not available in the |sandbox|.
8716 {only available when compiled with the |+clientserver| feature}
8717 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008718 :let repl = ""
8719 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008720
8721< Can also be used as a |method|: >
8722 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008723<
8724 Return type: |Number|
8725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008726
8727remote_read({serverid}, [{timeout}]) *remote_read()*
8728 Return the oldest available reply from {serverid} and consume
8729 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008730 reply is available. Returns an empty string, if a reply is
8731 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008732 See also |clientserver|.
8733 This function is not available in the |sandbox|.
8734 {only available when compiled with the |+clientserver| feature}
8735 Example: >
8736 :echo remote_read(id)
8737
8738< Can also be used as a |method|: >
8739 ServerId()->remote_read()
8740<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008741 Return type: |String|
8742
8743
8744remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008745 Send the {string} to {server}. The {server} argument is a
8746 string, also see |{server}|.
8747
8748 The string is sent as input keys and the function returns
8749 immediately. At the Vim server the keys are not mapped
8750 |:map|.
8751
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008752 If {idvar} is present, it is taken as the name of a variable
8753 and a {serverid} for later use with remote_read() is stored
8754 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008755
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008756 See also |clientserver| |RemoteReply|.
8757 This function is not available in the |sandbox|.
8758 {only available when compiled with the |+clientserver| feature}
8759
8760 Note: Any errors will be reported in the server and may mess
8761 up the display.
8762 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008763 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008764 \ remote_read(serverid)
8765
8766 :autocmd NONE RemoteReply *
8767 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008768 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008769 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8770<
8771 Can also be used as a |method|: >
8772 ServerName()->remote_send(keys)
8773<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008774 Return type: |String|
8775
8776
8777remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008778 Become the server {name}. {name} must be a non-empty string.
8779 This fails if already running as a server, when |v:servername|
8780 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008781
8782 Can also be used as a |method|: >
8783 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008784<
8785 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008786
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008787 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008788
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008789
8790remove({list}, {idx}) *remove()*
8791remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008792 Without {end}: Remove the item at {idx} from |List| {list} and
8793 return the item.
8794 With {end}: Remove items from {idx} to {end} (inclusive) and
8795 return a |List| with these items. When {idx} points to the same
8796 item as {end} a list with one item is returned. When {end}
8797 points to an item before {idx} this is an error.
8798 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008799 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008800 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008801 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008802 :call remove(mylist, 0, 9)
8803<
8804 Use |delete()| to remove a file.
8805
8806 Can also be used as a |method|: >
8807 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008808<
8809 Return type: any, depending on {list}
8810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008811
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008812remove({blob}, {idx})
8813remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008814 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8815 return the byte.
8816 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8817 return a |Blob| with these bytes. When {idx} points to the same
8818 byte as {end} a |Blob| with one byte is returned. When {end}
8819 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008820 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008821 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008822 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008823 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008824<
8825 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008826
8827remove({dict}, {key})
8828 Remove the entry from {dict} with key {key} and return it.
8829 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008830 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008831< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008832 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008833
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008834 Return type: any, depending on {dict}
8835
8836
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008837rename({from}, {to}) *rename()*
8838 Rename the file by the name {from} to the name {to}. This
8839 should also work to move files across file systems. The
8840 result is a Number, which is 0 if the file was renamed
8841 successfully, and non-zero when the renaming failed.
8842 NOTE: If {to} exists it is overwritten without warning.
8843 This function is not available in the |sandbox|.
8844
8845 Can also be used as a |method|: >
8846 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008847<
8848 Return type: |Number|
8849
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008850
8851repeat({expr}, {count}) *repeat()*
8852 Repeat {expr} {count} times and return the concatenated
8853 result. Example: >
8854 :let separator = repeat('-', 80)
8855< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008856 When {expr} is a |List| or a |Blob| the result is {expr}
8857 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008858 :let longlist = repeat(['a', 'b'], 3)
8859< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8860
8861 Can also be used as a |method|: >
8862 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008863<
8864 Return type: |String|, |Blob| or list<{type}> depending on
8865 {expr}
8866
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008867
8868resolve({filename}) *resolve()* *E655*
8869 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8870 returns the path the shortcut points to in a simplified form.
8871 When {filename} is a symbolic link or junction point, return
8872 the full path to the target. If the target of junction is
8873 removed, return {filename}.
8874 On Unix, repeat resolving symbolic links in all path
8875 components of {filename} and return the simplified result.
8876 To cope with link cycles, resolving of symbolic links is
8877 stopped after 100 iterations.
8878 On other systems, return the simplified {filename}.
8879 The simplification step is done as by |simplify()|.
8880 resolve() keeps a leading path component specifying the
8881 current directory (provided the result is still a relative
8882 path name) and also keeps a trailing path separator.
8883
8884 Can also be used as a |method|: >
8885 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008886<
8887 Return type: |String|
8888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008889
8890reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008891 Reverse the order of items in {object}. {object} can be a
8892 |List|, a |Blob| or a |String|. For a List and a Blob the
8893 items are reversed in-place and {object} is returned.
8894 For a String a new String is returned.
8895 Returns zero if {object} is not a List, Blob or a String.
8896 If you want a List or Blob to remain unmodified make a copy
8897 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008898 :let revlist = reverse(copy(mylist))
8899< Can also be used as a |method|: >
8900 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008901<
8902 Return type: |String|, |Blob| or list<{type}> depending on
8903 {object}
8904
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008905
8906round({expr}) *round()*
8907 Round off {expr} to the nearest integral value and return it
8908 as a |Float|. If {expr} lies halfway between two integral
8909 values, then use the larger one (away from zero).
8910 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008911 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008912 Examples: >
8913 echo round(0.456)
8914< 0.0 >
8915 echo round(4.5)
8916< 5.0 >
8917 echo round(-4.5)
8918< -5.0
8919
8920 Can also be used as a |method|: >
8921 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008922<
8923 Return type: |Float|
8924
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008925
8926rubyeval({expr}) *rubyeval()*
8927 Evaluate Ruby expression {expr} and return its result
8928 converted to Vim data structures.
8929 Numbers, floats and strings are returned as they are (strings
8930 are copied though).
8931 Arrays are represented as Vim |List| type.
8932 Hashes are represented as Vim |Dictionary| type.
8933 Other objects are represented as strings resulted from their
8934 "Object#to_s" method.
8935 Note that in a `:def` function local variables are not visible
8936 to {expr}.
8937
8938 Can also be used as a |method|: >
8939 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008940<
8941 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008942
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008943 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008944
8945screenattr({row}, {col}) *screenattr()*
8946 Like |screenchar()|, but return the attribute. This is a rather
8947 arbitrary number that can only be used to compare to the
8948 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008949 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008950
8951 Can also be used as a |method|: >
8952 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008953<
8954 Return type: |Number|
8955
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008956
8957screenchar({row}, {col}) *screenchar()*
8958 The result is a Number, which is the character at position
8959 [row, col] on the screen. This works for every possible
8960 screen position, also status lines, window separators and the
8961 command line. The top left position is row one, column one
8962 The character excludes composing characters. For double-byte
8963 encodings it may only be the first byte.
8964 This is mainly to be used for testing.
8965 Returns -1 when row or col is out of range.
8966
8967 Can also be used as a |method|: >
8968 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008969<
8970 Return type: |Number|
8971
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008972
8973screenchars({row}, {col}) *screenchars()*
8974 The result is a |List| of Numbers. The first number is the same
8975 as what |screenchar()| returns. Further numbers are
8976 composing characters on top of the base character.
8977 This is mainly to be used for testing.
8978 Returns an empty List when row or col is out of range.
8979
8980 Can also be used as a |method|: >
8981 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008982<
8983 Return type: list<number> or list<any>
8984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008985
8986screencol() *screencol()*
8987 The result is a Number, which is the current screen column of
8988 the cursor. The leftmost column has number 1.
8989 This function is mainly used for testing.
8990
8991 Note: Always returns the current screen column, thus if used
8992 in a command (e.g. ":echo screencol()") it will return the
8993 column inside the command line, which is 1 when the command is
8994 executed. To get the cursor position in the file use one of
8995 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008996 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008997 nnoremap <silent> GG :echom screencol()<CR>
8998 nnoremap GG <Cmd>echom screencol()<CR>
8999<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009000 Return type: |Number|
9001
9002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009003screenpos({winid}, {lnum}, {col}) *screenpos()*
9004 The result is a Dict with the screen position of the text
9005 character in window {winid} at buffer line {lnum} and column
9006 {col}. {col} is a one-based byte index.
9007 The Dict has these members:
9008 row screen row
9009 col first screen column
9010 endcol last screen column
9011 curscol cursor screen column
9012 If the specified position is not visible, all values are zero.
9013 The "endcol" value differs from "col" when the character
9014 occupies more than one screen cell. E.g. for a Tab "col" can
9015 be 1 and "endcol" can be 8.
9016 The "curscol" value is where the cursor would be placed. For
9017 a Tab it would be the same as "endcol", while for a double
9018 width character it would be the same as "col".
9019 The |conceal| feature is ignored here, the column numbers are
9020 as if 'conceallevel' is zero. You can set the cursor to the
9021 right position and use |screencol()| to get the value with
9022 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009023 If the position is in a closed fold the screen position of the
9024 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009025 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009026
9027 Can also be used as a |method|: >
9028 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009029<
9030 Return type: dict<number> or dict<any>
9031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009032
9033screenrow() *screenrow()*
9034 The result is a Number, which is the current screen row of the
9035 cursor. The top line has number one.
9036 This function is mainly used for testing.
9037 Alternatively you can use |winline()|.
9038
9039 Note: Same restrictions as with |screencol()|.
9040
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009041 Return type: |Number|
9042
9043
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009044screenstring({row}, {col}) *screenstring()*
9045 The result is a String that contains the base character and
9046 any composing characters at position [row, col] on the screen.
9047 This is like |screenchars()| but returning a String with the
9048 characters.
9049 This is mainly to be used for testing.
9050 Returns an empty String when row or col is out of range.
9051
9052 Can also be used as a |method|: >
9053 GetRow()->screenstring(col)
9054<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009055 Return type: |String|
9056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009057 *search()*
9058search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9059 Search for regexp pattern {pattern}. The search starts at the
9060 cursor position (you can use |cursor()| to set it).
9061
9062 When a match has been found its line number is returned.
9063 If there is no match a 0 is returned and the cursor doesn't
9064 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009065 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009066
9067 {flags} is a String, which can contain these character flags:
9068 'b' search Backward instead of forward
9069 'c' accept a match at the Cursor position
9070 'e' move to the End of the match
9071 'n' do Not move the cursor
9072 'p' return number of matching sub-Pattern (see below)
9073 's' Set the ' mark at the previous location of the cursor
9074 'w' Wrap around the end of the file
9075 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009076 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009077 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9078
9079 If the 's' flag is supplied, the ' mark is set, only if the
9080 cursor is moved. The 's' flag cannot be combined with the 'n'
9081 flag.
9082
9083 'ignorecase', 'smartcase' and 'magic' are used.
9084
9085 When the 'z' flag is not given, forward searching always
9086 starts in column zero and then matches before the cursor are
9087 skipped. When the 'c' flag is present in 'cpo' the next
9088 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009089 search starts one column after the start of the match. This
9090 matters for overlapping matches. See |cpo-c|. You can also
9091 insert "\ze" to change where the match ends, see |/\ze|.
9092
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009093 When searching backwards and the 'z' flag is given then the
9094 search starts in column zero, thus no match in the current
9095 line will be found (unless wrapping around the end of the
9096 file).
9097
9098 When the {stopline} argument is given then the search stops
9099 after searching this line. This is useful to restrict the
9100 search to a range of lines. Examples: >
9101 let match = search('(', 'b', line("w0"))
9102 let end = search('END', '', line("w$"))
9103< When {stopline} is used and it is not zero this also implies
9104 that the search does not wrap around the end of the file.
9105 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009106 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009107 When the {timeout} argument is given the search stops when
9108 more than this many milliseconds have passed. Thus when
9109 {timeout} is 500 the search stops after half a second.
9110 The value must not be negative. A zero value is like not
9111 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009112
9113 Note: the timeout is only considered when searching, not
9114 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009115 {only available when compiled with the |+reltime| feature}
9116
9117 If the {skip} expression is given it is evaluated with the
9118 cursor positioned on the start of a match. If it evaluates to
9119 non-zero this match is skipped. This can be used, for
9120 example, to skip a match in a comment or a string.
9121 {skip} can be a string, which is evaluated as an expression, a
9122 function reference or a lambda.
9123 When {skip} is omitted or empty, every match is accepted.
9124 When evaluating {skip} causes an error the search is aborted
9125 and -1 returned.
9126 *search()-sub-match*
9127 With the 'p' flag the returned value is one more than the
9128 first sub-match in \(\). One if none of them matched but the
9129 whole pattern did match.
9130 To get the column number too use |searchpos()|.
9131
9132 The cursor will be positioned at the match, unless the 'n'
9133 flag is used.
9134
9135 Example (goes over all files in the argument list): >
9136 :let n = 1
9137 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009138 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009139 : " start at the last char in the file and wrap for the
9140 : " first search to find match at start of file
9141 : normal G$
9142 : let flags = "w"
9143 : while search("foo", flags) > 0
9144 : s/foo/bar/g
9145 : let flags = "W"
9146 : endwhile
9147 : update " write the file if modified
9148 : let n = n + 1
9149 :endwhile
9150<
9151 Example for using some flags: >
9152 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9153< This will search for the keywords "if", "else", and "endif"
9154 under or after the cursor. Because of the 'p' flag, it
9155 returns 1, 2, or 3 depending on which keyword is found, or 0
9156 if the search fails. With the cursor on the first word of the
9157 line:
9158 if (foo == 0) | let foo = foo + 1 | endif ~
9159 the function returns 1. Without the 'c' flag, the function
9160 finds the "endif" and returns 3. The same thing happens
9161 without the 'e' flag if the cursor is on the "f" of "if".
9162 The 'n' flag tells the function not to move the cursor.
9163
9164 Can also be used as a |method|: >
9165 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009166<
9167 Return type: |Number|
9168
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009169
9170searchcount([{options}]) *searchcount()*
9171 Get or update the last search count, like what is displayed
9172 without the "S" flag in 'shortmess'. This works even if
9173 'shortmess' does contain the "S" flag.
9174
9175 This returns a |Dictionary|. The dictionary is empty if the
9176 previous pattern was not set and "pattern" was not specified.
9177
9178 key type meaning ~
9179 current |Number| current position of match;
9180 0 if the cursor position is
9181 before the first match
9182 exact_match |Boolean| 1 if "current" is matched on
9183 "pos", otherwise 0
9184 total |Number| total count of matches found
9185 incomplete |Number| 0: search was fully completed
9186 1: recomputing was timed out
9187 2: max count exceeded
9188
9189 For {options} see further down.
9190
9191 To get the last search count when |n| or |N| was pressed, call
9192 this function with `recompute: 0` . This sometimes returns
9193 wrong information because |n| and |N|'s maximum count is 99.
9194 If it exceeded 99 the result must be max count + 1 (100). If
9195 you want to get correct information, specify `recompute: 1`: >
9196
9197 " result == maxcount + 1 (100) when many matches
9198 let result = searchcount(#{recompute: 0})
9199
9200 " Below returns correct result (recompute defaults
9201 " to 1)
9202 let result = searchcount()
9203<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009204 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009205 function! LastSearchCount() abort
9206 let result = searchcount(#{recompute: 0})
9207 if empty(result)
9208 return ''
9209 endif
9210 if result.incomplete ==# 1 " timed out
9211 return printf(' /%s [?/??]', @/)
9212 elseif result.incomplete ==# 2 " max count exceeded
9213 if result.total > result.maxcount &&
9214 \ result.current > result.maxcount
9215 return printf(' /%s [>%d/>%d]', @/,
9216 \ result.current, result.total)
9217 elseif result.total > result.maxcount
9218 return printf(' /%s [%d/>%d]', @/,
9219 \ result.current, result.total)
9220 endif
9221 endif
9222 return printf(' /%s [%d/%d]', @/,
9223 \ result.current, result.total)
9224 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009225 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009226
9227 " Or if you want to show the count only when
9228 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009229 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009230 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9231<
9232 You can also update the search count, which can be useful in a
9233 |CursorMoved| or |CursorMovedI| autocommand: >
9234
9235 autocmd CursorMoved,CursorMovedI *
9236 \ let s:searchcount_timer = timer_start(
9237 \ 200, function('s:update_searchcount'))
9238 function! s:update_searchcount(timer) abort
9239 if a:timer ==# s:searchcount_timer
9240 call searchcount(#{
9241 \ recompute: 1, maxcount: 0, timeout: 100})
9242 redrawstatus
9243 endif
9244 endfunction
9245<
9246 This can also be used to count matched texts with specified
9247 pattern in the current buffer using "pattern": >
9248
9249 " Count '\<foo\>' in this buffer
9250 " (Note that it also updates search count)
9251 let result = searchcount(#{pattern: '\<foo\>'})
9252
9253 " To restore old search count by old pattern,
9254 " search again
9255 call searchcount()
9256<
9257 {options} must be a |Dictionary|. It can contain:
9258 key type meaning ~
9259 recompute |Boolean| if |TRUE|, recompute the count
9260 like |n| or |N| was executed.
9261 otherwise returns the last
9262 computed result (when |n| or
9263 |N| was used when "S" is not
9264 in 'shortmess', or this
9265 function was called).
9266 (default: |TRUE|)
9267 pattern |String| recompute if this was given
9268 and different with |@/|.
9269 this works as same as the
9270 below command is executed
9271 before calling this function >
9272 let @/ = pattern
9273< (default: |@/|)
9274 timeout |Number| 0 or negative number is no
9275 timeout. timeout milliseconds
9276 for recomputing the result
9277 (default: 0)
9278 maxcount |Number| 0 or negative number is no
9279 limit. max count of matched
9280 text while recomputing the
9281 result. if search exceeded
9282 total count, "total" value
9283 becomes `maxcount + 1`
9284 (default: 99)
9285 pos |List| `[lnum, col, off]` value
9286 when recomputing the result.
9287 this changes "current" result
9288 value. see |cursor()|,
9289 |getpos()|
9290 (default: cursor's position)
9291
9292 Can also be used as a |method|: >
9293 GetSearchOpts()->searchcount()
9294<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009295 Return type: dict<number>
9296
9297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009298searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9299 Search for the declaration of {name}.
9300
9301 With a non-zero {global} argument it works like |gD|, find
9302 first match in the file. Otherwise it works like |gd|, find
9303 first match in the function.
9304
9305 With a non-zero {thisblock} argument matches in a {} block
9306 that ends before the cursor position are ignored. Avoids
9307 finding variable declarations only valid in another scope.
9308
9309 Moves the cursor to the found match.
9310 Returns zero for success, non-zero for failure.
9311 Example: >
9312 if searchdecl('myvar') == 0
9313 echo getline('.')
9314 endif
9315<
9316 Can also be used as a |method|: >
9317 GetName()->searchdecl()
9318<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009319 Return type: |Number|
9320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009321 *searchpair()*
9322searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9323 [, {stopline} [, {timeout}]]]])
9324 Search for the match of a nested start-end pair. This can be
9325 used to find the "endif" that matches an "if", while other
9326 if/endif pairs in between are ignored.
9327 The search starts at the cursor. The default is to search
9328 forward, include 'b' in {flags} to search backward.
9329 If a match is found, the cursor is positioned at it and the
9330 line number is returned. If no match is found 0 or -1 is
9331 returned and the cursor doesn't move. No error message is
9332 given.
9333
9334 {start}, {middle} and {end} are patterns, see |pattern|. They
9335 must not contain \( \) pairs. Use of \%( \) is allowed. When
9336 {middle} is not empty, it is found when searching from either
9337 direction, but only when not in a nested start-end pair. A
9338 typical use is: >
9339 searchpair('\<if\>', '\<else\>', '\<endif\>')
9340< By leaving {middle} empty the "else" is skipped.
9341
9342 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9343 |search()|. Additionally:
9344 'r' Repeat until no more matches found; will find the
9345 outer pair. Implies the 'W' flag.
9346 'm' Return number of matches instead of line number with
9347 the match; will be > 1 when 'r' is used.
9348 Note: it's nearly always a good idea to use the 'W' flag, to
9349 avoid wrapping around the end of the file.
9350
9351 When a match for {start}, {middle} or {end} is found, the
9352 {skip} expression is evaluated with the cursor positioned on
9353 the start of the match. It should return non-zero if this
9354 match is to be skipped. E.g., because it is inside a comment
9355 or a string.
9356 When {skip} is omitted or empty, every match is accepted.
9357 When evaluating {skip} causes an error the search is aborted
9358 and -1 returned.
9359 {skip} can be a string, a lambda, a funcref or a partial.
9360 Anything else makes the function fail.
9361 In a `:def` function when the {skip} argument is a string
9362 constant it is compiled into instructions.
9363
9364 For {stopline} and {timeout} see |search()|.
9365
9366 The value of 'ignorecase' is used. 'magic' is ignored, the
9367 patterns are used like it's on.
9368
9369 The search starts exactly at the cursor. A match with
9370 {start}, {middle} or {end} at the next character, in the
9371 direction of searching, is the first one found. Example: >
9372 if 1
9373 if 2
9374 endif 2
9375 endif 1
9376< When starting at the "if 2", with the cursor on the "i", and
9377 searching forwards, the "endif 2" is found. When starting on
9378 the character just before the "if 2", the "endif 1" will be
9379 found. That's because the "if 2" will be found first, and
9380 then this is considered to be a nested if/endif from "if 2" to
9381 "endif 2".
9382 When searching backwards and {end} is more than one character,
9383 it may be useful to put "\zs" at the end of the pattern, so
9384 that when the cursor is inside a match with the end it finds
9385 the matching start.
9386
9387 Example, to find the "endif" command in a Vim script: >
9388
9389 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9390 \ 'getline(".") =~ "^\\s*\""')
9391
9392< The cursor must be at or after the "if" for which a match is
9393 to be found. Note that single-quote strings are used to avoid
9394 having to double the backslashes. The skip expression only
9395 catches comments at the start of a line, not after a command.
9396 Also, a word "en" or "if" halfway a line is considered a
9397 match.
9398 Another example, to search for the matching "{" of a "}": >
9399
9400 :echo searchpair('{', '', '}', 'bW')
9401
9402< This works when the cursor is at or before the "}" for which a
9403 match is to be found. To reject matches that syntax
9404 highlighting recognized as strings: >
9405
9406 :echo searchpair('{', '', '}', 'bW',
9407 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9408<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009409 Return type: |Number|
9410
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009411 *searchpairpos()*
9412searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9413 [, {stopline} [, {timeout}]]]])
9414 Same as |searchpair()|, but returns a |List| with the line and
9415 column position of the match. The first element of the |List|
9416 is the line number and the second element is the byte index of
9417 the column position of the match. If no match is found,
9418 returns [0, 0]. >
9419
9420 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9421<
9422 See |match-parens| for a bigger and more useful example.
9423
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009424 Return type: list<number>
9425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009426 *searchpos()*
9427searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9428 Same as |search()|, but returns a |List| with the line and
9429 column position of the match. The first element of the |List|
9430 is the line number and the second element is the byte index of
9431 the column position of the match. If no match is found,
9432 returns [0, 0].
9433 Example: >
9434 :let [lnum, col] = searchpos('mypattern', 'n')
9435
9436< When the 'p' flag is given then there is an extra item with
9437 the sub-pattern match number |search()-sub-match|. Example: >
9438 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9439< In this example "submatch" is 2 when a lowercase letter is
9440 found |/\l|, 3 when an uppercase letter is found |/\u|.
9441
9442 Can also be used as a |method|: >
9443 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009444<
9445 Return type: list<number>
9446
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009447
9448server2client({clientid}, {string}) *server2client()*
9449 Send a reply string to {clientid}. The most recent {clientid}
9450 that sent a string can be retrieved with expand("<client>").
9451 {only available when compiled with the |+clientserver| feature}
9452 Returns zero for success, -1 for failure.
9453 Note:
9454 This id has to be stored before the next command can be
9455 received. I.e. before returning from the received command and
9456 before calling any commands that waits for input.
9457 See also |clientserver|.
9458 Example: >
9459 :echo server2client(expand("<client>"), "HELLO")
9460
9461< Can also be used as a |method|: >
9462 GetClientId()->server2client(string)
9463<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009464 Return type: |Number|
9465
9466
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009467serverlist() *serverlist()*
9468 Return a list of available server names, one per line.
9469 When there are no servers or the information is not available
9470 an empty string is returned. See also |clientserver|.
9471 {only available when compiled with the |+clientserver| feature}
9472 Example: >
9473 :echo serverlist()
9474<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009475 Return type: |String|
9476
9477
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009478setbufline({buf}, {lnum}, {text}) *setbufline()*
9479 Set line {lnum} to {text} in buffer {buf}. This works like
9480 |setline()| for the specified buffer.
9481
9482 This function works only for loaded buffers. First call
9483 |bufload()| if needed.
9484
9485 To insert lines use |appendbufline()|.
9486 Any text properties in {lnum} are cleared.
9487
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009488 {text} can be a string to set one line, or a List of strings
9489 to set multiple lines. If the List extends below the last
9490 line then those lines are added. If the List is empty then
9491 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009492
9493 For the use of {buf}, see |bufname()| above.
9494
9495 {lnum} is used like with |setline()|.
9496 Use "$" to refer to the last line in buffer {buf}.
9497 When {lnum} is just below the last line the {text} will be
9498 added below the last line.
9499
9500 When {buf} is not a valid buffer, the buffer is not loaded or
9501 {lnum} is not valid then 1 is returned. In |Vim9| script an
9502 error is given.
9503 On success 0 is returned.
9504
9505 Can also be used as a |method|, the base is passed as the
9506 third argument: >
9507 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009508<
9509 Return type: |Number|
9510
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009511
9512setbufvar({buf}, {varname}, {val}) *setbufvar()*
9513 Set option or local variable {varname} in buffer {buf} to
9514 {val}.
9515 This also works for a global or local window option, but it
9516 doesn't work for a global or local window variable.
9517 For a local window option the global value is unchanged.
9518 For the use of {buf}, see |bufname()| above.
9519 The {varname} argument is a string.
9520 Note that the variable name without "b:" must be used.
9521 Examples: >
9522 :call setbufvar(1, "&mod", 1)
9523 :call setbufvar("todo", "myvar", "foobar")
9524< This function is not available in the |sandbox|.
9525
9526 Can also be used as a |method|, the base is passed as the
9527 third argument: >
9528 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009529<
9530 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009531
9532
9533setcellwidths({list}) *setcellwidths()*
9534 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009535 tells Vim how wide characters are when displayed in the
9536 terminal, counted in screen cells. The values override
9537 'ambiwidth'. Example: >
9538 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009539 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009540 \ [0x2194, 0x2199, 2],
9541 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009542
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009543< The {list} argument is a List of Lists with each three
9544 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9545 {low} and {high} can be the same, in which case this refers to
9546 one character. Otherwise it is the range of characters from
9547 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009548 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009549
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009550 {width} must be either 1 or 2, indicating the character width
9551 in screen cells. *E1112*
9552 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009553 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009555 If the new value causes 'fillchars' or 'listchars' to become
9556 invalid it is rejected and an error is given.
9557
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009558 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009559 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009560
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009561< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009562 the effect for known emoji characters. Move the cursor
9563 through the text to check if the cell widths of your terminal
9564 match with what Vim knows about each emoji. If it doesn't
9565 look right you need to adjust the {list} argument.
9566
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009567 Return type: |Number|
9568
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009569
9570setcharpos({expr}, {list}) *setcharpos()*
9571 Same as |setpos()| but uses the specified column number as the
9572 character index instead of the byte index in the line.
9573
9574 Example:
9575 With the text "여보세요" in line 8: >
9576 call setcharpos('.', [0, 8, 4, 0])
9577< positions the cursor on the fourth character '요'. >
9578 call setpos('.', [0, 8, 4, 0])
9579< positions the cursor on the second character '보'.
9580
9581 Can also be used as a |method|: >
9582 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009583<
9584 Return type: |Number|
9585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009586
9587setcharsearch({dict}) *setcharsearch()*
9588 Set the current character search information to {dict},
9589 which contains one or more of the following entries:
9590
9591 char character which will be used for a subsequent
9592 |,| or |;| command; an empty string clears the
9593 character search
9594 forward direction of character search; 1 for forward,
9595 0 for backward
9596 until type of character search; 1 for a |t| or |T|
9597 character search, 0 for an |f| or |F|
9598 character search
9599
9600 This can be useful to save/restore a user's character search
9601 from a script: >
9602 :let prevsearch = getcharsearch()
9603 :" Perform a command which clobbers user's search
9604 :call setcharsearch(prevsearch)
9605< Also see |getcharsearch()|.
9606
9607 Can also be used as a |method|: >
9608 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009609<
9610 Return type: dict<any>
9611
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009612
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009613setcmdline({str} [, {pos}]) *setcmdline()*
9614 Set the command line to {str} and set the cursor position to
9615 {pos}.
9616 If {pos} is omitted, the cursor is positioned after the text.
9617 Returns 0 when successful, 1 when not editing the command
9618 line.
9619
9620 Can also be used as a |method|: >
9621 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009622<
9623 Return type: |Number|
9624
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009625
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009626setcmdpos({pos}) *setcmdpos()*
9627 Set the cursor position in the command line to byte position
9628 {pos}. The first position is 1.
9629 Use |getcmdpos()| to obtain the current position.
9630 Only works while editing the command line, thus you must use
9631 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9632 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9633 set after the command line is set to the expression. For
9634 |c_CTRL-R_=| it is set after evaluating the expression but
9635 before inserting the resulting text.
9636 When the number is too big the cursor is put at the end of the
9637 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009638 Returns 0 when successful, 1 when not editing the command
9639 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009640
9641 Can also be used as a |method|: >
9642 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009643<
9644 Return type: |Number|
9645
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009646
9647setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9648setcursorcharpos({list})
9649 Same as |cursor()| but uses the specified column number as the
9650 character index instead of the byte index in the line.
9651
9652 Example:
9653 With the text "여보세요" in line 4: >
9654 call setcursorcharpos(4, 3)
9655< positions the cursor on the third character '세'. >
9656 call cursor(4, 3)
9657< positions the cursor on the first character '여'.
9658
9659 Can also be used as a |method|: >
9660 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009661<
9662 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009663
9664
9665setenv({name}, {val}) *setenv()*
9666 Set environment variable {name} to {val}. Example: >
9667 call setenv('HOME', '/home/myhome')
9668
9669< When {val} is |v:null| the environment variable is deleted.
9670 See also |expr-env|.
9671
9672 Can also be used as a |method|, the base is passed as the
9673 second argument: >
9674 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009675<
9676 Return type: |Number|
9677
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009678
9679setfperm({fname}, {mode}) *setfperm()* *chmod*
9680 Set the file permissions for {fname} to {mode}.
9681 {mode} must be a string with 9 characters. It is of the form
9682 "rwxrwxrwx", where each group of "rwx" flags represent, in
9683 turn, the permissions of the owner of the file, the group the
9684 file belongs to, and other users. A '-' character means the
9685 permission is off, any other character means on. Multi-byte
9686 characters are not supported.
9687
9688 For example "rw-r-----" means read-write for the user,
9689 readable by the group, not accessible by others. "xx-x-----"
9690 would do the same thing.
9691
9692 Returns non-zero for success, zero for failure.
9693
9694 Can also be used as a |method|: >
9695 GetFilename()->setfperm(mode)
9696<
9697 To read permissions see |getfperm()|.
9698
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009699 Return type: |Number|
9700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009701
9702setline({lnum}, {text}) *setline()*
9703 Set line {lnum} of the current buffer to {text}. To insert
9704 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009705 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009706 Any text properties in {lnum} are cleared. See
9707 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009708
9709 {lnum} is used like with |getline()|.
9710 When {lnum} is just below the last line the {text} will be
9711 added below the last line.
9712 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009713 converted to a String. When {text} is an empty List then
9714 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009715
9716 If this succeeds, FALSE is returned. If this fails (most likely
9717 because {lnum} is invalid) TRUE is returned.
9718 In |Vim9| script an error is given if {lnum} is invalid.
9719
9720 Example: >
9721 :call setline(5, strftime("%c"))
9722
9723< When {text} is a |List| then line {lnum} and following lines
9724 will be set to the items in the list. Example: >
9725 :call setline(5, ['aaa', 'bbb', 'ccc'])
9726< This is equivalent to: >
9727 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9728 : call setline(n, l)
9729 :endfor
9730
9731< Note: The '[ and '] marks are not set.
9732
9733 Can also be used as a |method|, the base is passed as the
9734 second argument: >
9735 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009736<
9737 Return type: |Number|
9738
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009739
9740setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9741 Create or replace or add to the location list for window {nr}.
9742 {nr} can be the window number or the |window-ID|.
9743 When {nr} is zero the current window is used.
9744
9745 For a location list window, the displayed location list is
9746 modified. For an invalid window number {nr}, -1 is returned.
9747 Otherwise, same as |setqflist()|.
9748 Also see |location-list|.
9749
9750 For {action} see |setqflist-action|.
9751
9752 If the optional {what} dictionary argument is supplied, then
9753 only the items listed in {what} are set. Refer to |setqflist()|
9754 for the list of supported keys in {what}.
9755
9756 Can also be used as a |method|, the base is passed as the
9757 second argument: >
9758 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009759<
9760 Return type: |Number|
9761
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009762
9763setmatches({list} [, {win}]) *setmatches()*
9764 Restores a list of matches saved by |getmatches()| for the
9765 current window. Returns 0 if successful, otherwise -1. All
9766 current matches are cleared before the list is restored. See
9767 example for |getmatches()|.
9768 If {win} is specified, use the window with this number or
9769 window ID instead of the current window.
9770
9771 Can also be used as a |method|: >
9772 GetMatches()->setmatches()
9773<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009774 Return type: |Number|
9775
9776
9777setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009778 Set the position for String {expr}. Possible values:
9779 . the cursor
9780 'x mark x
9781
9782 {list} must be a |List| with four or five numbers:
9783 [bufnum, lnum, col, off]
9784 [bufnum, lnum, col, off, curswant]
9785
9786 "bufnum" is the buffer number. Zero can be used for the
9787 current buffer. When setting an uppercase mark "bufnum" is
9788 used for the mark position. For other marks it specifies the
9789 buffer to set the mark in. You can use the |bufnr()| function
9790 to turn a file name into a buffer number.
9791 For setting the cursor and the ' mark "bufnum" is ignored,
9792 since these are associated with a window, not a buffer.
9793 Does not change the jumplist.
9794
9795 "lnum" and "col" are the position in the buffer. The first
9796 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9797 smaller than 1 then 1 is used. To use the character count
9798 instead of the byte count, use |setcharpos()|.
9799
9800 The "off" number is only used when 'virtualedit' is set. Then
9801 it is the offset in screen columns from the start of the
9802 character. E.g., a position within a <Tab> or after the last
9803 character.
9804
9805 The "curswant" number is only used when setting the cursor
9806 position. It sets the preferred column for when moving the
9807 cursor vertically. When the "curswant" number is missing the
9808 preferred column is not set. When it is present and setting a
9809 mark position it is not used.
9810
9811 Note that for '< and '> changing the line number may result in
9812 the marks to be effectively be swapped, so that '< is always
9813 before '>.
9814
9815 Returns 0 when the position could be set, -1 otherwise.
9816 An error message is given if {expr} is invalid.
9817
9818 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9819
9820 This does not restore the preferred column for moving
9821 vertically; if you set the cursor position with this, |j| and
9822 |k| motions will jump to previous columns! Use |cursor()| to
9823 also set the preferred column. Also see the "curswant" key in
9824 |winrestview()|.
9825
9826 Can also be used as a |method|: >
9827 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009828<
9829 Return type: |Number|
9830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009831
9832setqflist({list} [, {action} [, {what}]]) *setqflist()*
9833 Create or replace or add to the quickfix list.
9834
9835 If the optional {what} dictionary argument is supplied, then
9836 only the items listed in {what} are set. The first {list}
9837 argument is ignored. See below for the supported items in
9838 {what}.
9839 *setqflist-what*
9840 When {what} is not present, the items in {list} are used. Each
9841 item must be a dictionary. Non-dictionary items in {list} are
9842 ignored. Each dictionary item can contain the following
9843 entries:
9844
9845 bufnr buffer number; must be the number of a valid
9846 buffer
9847 filename name of a file; only used when "bufnr" is not
9848 present or it is invalid.
9849 module name of a module; if given it will be used in
9850 quickfix error window instead of the filename.
9851 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009852 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009853 pattern search pattern used to locate the error
9854 col column number
9855 vcol when non-zero: "col" is visual column
9856 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009857 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009858 nr error number
9859 text description of the error
9860 type single-character error type, 'E', 'W', etc.
9861 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009862 user_data custom data associated with the item, can be
9863 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009864
9865 The "col", "vcol", "nr", "type" and "text" entries are
9866 optional. Either "lnum" or "pattern" entry can be used to
9867 locate a matching error line.
9868 If the "filename" and "bufnr" entries are not present or
9869 neither the "lnum" or "pattern" entries are present, then the
9870 item will not be handled as an error line.
9871 If both "pattern" and "lnum" are present then "pattern" will
9872 be used.
9873 If the "valid" entry is not supplied, then the valid flag is
9874 set when "bufnr" is a valid buffer or "filename" exists.
9875 If you supply an empty {list}, the quickfix list will be
9876 cleared.
9877 Note that the list is not exactly the same as what
9878 |getqflist()| returns.
9879
9880 {action} values: *setqflist-action* *E927*
9881 'a' The items from {list} are added to the existing
9882 quickfix list. If there is no existing list, then a
9883 new list is created.
9884
9885 'r' The items from the current quickfix list are replaced
9886 with the items from {list}. This can also be used to
9887 clear the list: >
9888 :call setqflist([], 'r')
9889<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009890 'u' Like 'r', but tries to preserve the current selection
9891 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009892 'f' All the quickfix lists in the quickfix stack are
9893 freed.
9894
9895 If {action} is not present or is set to ' ', then a new list
9896 is created. The new quickfix list is added after the current
9897 quickfix list in the stack and all the following lists are
9898 freed. To add a new quickfix list at the end of the stack,
9899 set "nr" in {what} to "$".
9900
9901 The following items can be specified in dictionary {what}:
9902 context quickfix list context. See |quickfix-context|
9903 efm errorformat to use when parsing text from
9904 "lines". If this is not present, then the
9905 'errorformat' option value is used.
9906 See |quickfix-parse|
9907 id quickfix list identifier |quickfix-ID|
9908 idx index of the current entry in the quickfix
9909 list specified by 'id' or 'nr'. If set to '$',
9910 then the last entry in the list is set as the
9911 current entry. See |quickfix-index|
9912 items list of quickfix entries. Same as the {list}
9913 argument.
9914 lines use 'errorformat' to parse a list of lines and
9915 add the resulting entries to the quickfix list
9916 {nr} or {id}. Only a |List| value is supported.
9917 See |quickfix-parse|
9918 nr list number in the quickfix stack; zero
9919 means the current quickfix list and "$" means
9920 the last quickfix list.
9921 quickfixtextfunc
9922 function to get the text to display in the
9923 quickfix window. The value can be the name of
9924 a function or a funcref or a lambda. Refer to
9925 |quickfix-window-function| for an explanation
9926 of how to write the function and an example.
9927 title quickfix list title text. See |quickfix-title|
9928 Unsupported keys in {what} are ignored.
9929 If the "nr" item is not present, then the current quickfix list
9930 is modified. When creating a new quickfix list, "nr" can be
9931 set to a value one greater than the quickfix stack size.
9932 When modifying a quickfix list, to guarantee that the correct
9933 list is modified, "id" should be used instead of "nr" to
9934 specify the list.
9935
9936 Examples (See also |setqflist-examples|): >
9937 :call setqflist([], 'r', {'title': 'My search'})
9938 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9939 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9940<
9941 Returns zero for success, -1 for failure.
9942
9943 This function can be used to create a quickfix list
9944 independent of the 'errorformat' setting. Use a command like
9945 `:cc 1` to jump to the first position.
9946
9947 Can also be used as a |method|, the base is passed as the
9948 second argument: >
9949 GetErrorlist()->setqflist()
9950<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009951 Return type: |Number|
9952
9953
9954setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009955 Set the register {regname} to {value}.
9956 If {regname} is "" or "@", the unnamed register '"' is used.
9957 The {regname} argument is a string. In |Vim9-script|
9958 {regname} must be one character.
9959
9960 {value} may be any value returned by |getreg()| or
9961 |getreginfo()|, including a |List| or |Dict|.
9962 If {options} contains "a" or {regname} is upper case,
9963 then the value is appended.
9964
9965 {options} can also contain a register type specification:
9966 "c" or "v" |characterwise| mode
9967 "l" or "V" |linewise| mode
9968 "b" or "<CTRL-V>" |blockwise-visual| mode
9969 If a number immediately follows "b" or "<CTRL-V>" then this is
9970 used as the width of the selection - if it is not specified
9971 then the width of the block is set to the number of characters
9972 in the longest line (counting a <Tab> as 1 character).
9973
9974 If {options} contains no register settings, then the default
9975 is to use character mode unless {value} ends in a <NL> for
9976 string {value} and linewise mode for list {value}. Blockwise
9977 mode is never selected automatically.
9978 Returns zero for success, non-zero for failure.
9979
9980 *E883*
9981 Note: you may not use |List| containing more than one item to
9982 set search and expression registers. Lists containing no
9983 items act like empty strings.
9984
9985 Examples: >
9986 :call setreg(v:register, @*)
9987 :call setreg('*', @%, 'ac')
9988 :call setreg('a', "1\n2\n3", 'b5')
9989 :call setreg('"', { 'points_to': 'a'})
9990
9991< This example shows using the functions to save and restore a
9992 register: >
9993 :let var_a = getreginfo()
9994 :call setreg('a', var_a)
9995< or: >
9996 :let var_a = getreg('a', 1, 1)
9997 :let var_amode = getregtype('a')
9998 ....
9999 :call setreg('a', var_a, var_amode)
10000< Note: you may not reliably restore register value
10001 without using the third argument to |getreg()| as without it
10002 newlines are represented as newlines AND Nul bytes are
10003 represented as newlines as well, see |NL-used-for-Nul|.
10004
10005 You can also change the type of a register by appending
10006 nothing: >
10007 :call setreg('a', '', 'al')
10008
10009< Can also be used as a |method|, the base is passed as the
10010 second argument: >
10011 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010012<
10013 Return type: |Number|
10014
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010015
10016settabvar({tabnr}, {varname}, {val}) *settabvar()*
10017 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10018 |t:var|
10019 The {varname} argument is a string.
10020 Note that autocommands are blocked, side effects may not be
10021 triggered, e.g. when setting 'filetype'.
10022 Note that the variable name without "t:" must be used.
10023 Tabs are numbered starting with one.
10024 This function is not available in the |sandbox|.
10025
10026 Can also be used as a |method|, the base is passed as the
10027 third argument: >
10028 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010029<
10030 Return type: |Number|
10031
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010032
10033settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10034 Set option or local variable {varname} in window {winnr} to
10035 {val}.
10036 Tabs are numbered starting with one. For the current tabpage
10037 use |setwinvar()|.
10038 {winnr} can be the window number or the |window-ID|.
10039 When {winnr} is zero the current window is used.
10040 Note that autocommands are blocked, side effects may not be
10041 triggered, e.g. when setting 'filetype' or 'syntax'.
10042 This also works for a global or local buffer option, but it
10043 doesn't work for a global or local buffer variable.
10044 For a local buffer option the global value is unchanged.
10045 Note that the variable name without "w:" must be used.
10046 Examples: >
10047 :call settabwinvar(1, 1, "&list", 0)
10048 :call settabwinvar(3, 2, "myvar", "foobar")
10049< This function is not available in the |sandbox|.
10050
10051 Can also be used as a |method|, the base is passed as the
10052 fourth argument: >
10053 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010054<
10055 Return type: |Number|
10056
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010057
10058settagstack({nr}, {dict} [, {action}]) *settagstack()*
10059 Modify the tag stack of the window {nr} using {dict}.
10060 {nr} can be the window number or the |window-ID|.
10061
10062 For a list of supported items in {dict}, refer to
10063 |gettagstack()|. "curidx" takes effect before changing the tag
10064 stack.
10065 *E962*
10066 How the tag stack is modified depends on the {action}
10067 argument:
10068 - If {action} is not present or is set to 'r', then the tag
10069 stack is replaced.
10070 - If {action} is set to 'a', then new entries from {dict} are
10071 pushed (added) onto the tag stack.
10072 - If {action} is set to 't', then all the entries from the
10073 current entry in the tag stack or "curidx" in {dict} are
10074 removed and then new entries are pushed to the stack.
10075
10076 The current index is set to one after the length of the tag
10077 stack after the modification.
10078
10079 Returns zero for success, -1 for failure.
10080
10081 Examples (for more examples see |tagstack-examples|):
10082 Empty the tag stack of window 3: >
10083 call settagstack(3, {'items' : []})
10084
10085< Save and restore the tag stack: >
10086 let stack = gettagstack(1003)
10087 " do something else
10088 call settagstack(1003, stack)
10089 unlet stack
10090<
10091 Can also be used as a |method|, the base is passed as the
10092 second argument: >
10093 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010094<
10095 Return type: |Number|
10096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010097
10098setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10099 Like |settabwinvar()| for the current tab page.
10100 Examples: >
10101 :call setwinvar(1, "&list", 0)
10102 :call setwinvar(2, "myvar", "foobar")
10103
10104< Can also be used as a |method|, the base is passed as the
10105 third argument: >
10106 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010107<
10108 Return type: |Number|
10109
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010110
10111sha256({string}) *sha256()*
10112 Returns a String with 64 hex characters, which is the SHA256
10113 checksum of {string}.
10114
10115 Can also be used as a |method|: >
10116 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010117<
10118 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010119
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010120 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010121
10122shellescape({string} [, {special}]) *shellescape()*
10123 Escape {string} for use as a shell command argument.
10124 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010125 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010126 in single quotes and will double up all internal single
10127 quotes.
10128 On MS-Windows, when 'shellslash' is not set, it will enclose
10129 {string} in double quotes and double all double quotes within
10130 {string}.
10131 Otherwise it will enclose {string} in single quotes and
10132 replace all "'" with "'\''".
10133
Enno5faeb602024-05-15 21:54:19 +020010134 The {special} argument adds additional escaping of keywords
10135 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010136 number or a non-empty String (|non-zero-arg|), then special
10137 items such as "!", "%", "#" and "<cword>" (as listed in
10138 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010139 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010140
10141 The "!" character will be escaped (again with a |non-zero-arg|
10142 {special}) when 'shell' contains "csh" in the tail. That is
10143 because for csh and tcsh "!" is used for history replacement
10144 even when inside single quotes.
10145
10146 With a |non-zero-arg| {special} the <NL> character is also
10147 escaped. When 'shell' containing "csh" in the tail it's
10148 escaped a second time.
10149
10150 The "\" character will be escaped when 'shell' contains "fish"
10151 in the tail. That is because for fish "\" is used as an escape
10152 character inside single quotes.
10153
10154 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010155 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010156< This results in a directory listing for the file under the
10157 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010158 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010159< See also |::S|.
10160
10161 Can also be used as a |method|: >
10162 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010163<
10164 Return type: |String|
10165
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010166
10167shiftwidth([{col}]) *shiftwidth()*
10168 Returns the effective value of 'shiftwidth'. This is the
10169 'shiftwidth' value unless it is zero, in which case it is the
10170 'tabstop' value. This function was introduced with patch
10171 7.3.694 in 2012, everybody should have it by now (however it
10172 did not allow for the optional {col} argument until 8.1.542).
10173
10174 When there is one argument {col} this is used as column number
10175 for which to return the 'shiftwidth' value. This matters for the
10176 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10177 no {col} argument is given, column 1 will be assumed.
10178
10179 Can also be used as a |method|: >
10180 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010181<
10182 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010183
10184sign_ functions are documented here: |sign-functions-details|
10185
10186
10187simplify({filename}) *simplify()*
10188 Simplify the file name as much as possible without changing
10189 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10190 Unix) are not resolved. If the first path component in
10191 {filename} designates the current directory, this will be
10192 valid for the result as well. A trailing path separator is
10193 not removed either. On Unix "//path" is unchanged, but
10194 "///path" is simplified to "/path" (this follows the Posix
10195 standard).
10196 Example: >
10197 simplify("./dir/.././/file/") == "./file/"
10198< Note: The combination "dir/.." is only removed if "dir" is
10199 a searchable directory or does not exist. On Unix, it is also
10200 removed when "dir" is a symbolic link within the same
10201 directory. In order to resolve all the involved symbolic
10202 links before simplifying the path name, use |resolve()|.
10203
10204 Can also be used as a |method|: >
10205 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010206<
10207 Return type: |String|
10208
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010209
10210sin({expr}) *sin()*
10211 Return the sine of {expr}, measured in radians, as a |Float|.
10212 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010213 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010214 Examples: >
10215 :echo sin(100)
10216< -0.506366 >
10217 :echo sin(-4.01)
10218< 0.763301
10219
10220 Can also be used as a |method|: >
10221 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010222<
10223 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010224
10225
10226sinh({expr}) *sinh()*
10227 Return the hyperbolic sine of {expr} as a |Float| in the range
10228 [-inf, inf].
10229 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010230 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010231 Examples: >
10232 :echo sinh(0.5)
10233< 0.521095 >
10234 :echo sinh(-0.9)
10235< -1.026517
10236
10237 Can also be used as a |method|: >
10238 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010239<
10240 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010241
10242
10243slice({expr}, {start} [, {end}]) *slice()*
10244 Similar to using a |slice| "expr[start : end]", but "end" is
10245 used exclusive. And for a string the indexes are used as
10246 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010247 |vim9script|. Also, composing characters are treated as a
10248 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010249 When {end} is omitted the slice continues to the last item.
10250 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010251 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010252
10253 Can also be used as a |method|: >
10254 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010255<
10256 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010257
10258
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010259sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010260 Sort the items in {list} in-place. Returns {list}.
10261
10262 If you want a list to remain unmodified make a copy first: >
10263 :let sortedlist = sort(copy(mylist))
10264
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010265< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010266 string representation of each item to sort on. Numbers sort
10267 after Strings, |Lists| after Numbers. For sorting text in the
10268 current buffer use |:sort|.
10269
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010270 When {how} is given and it is 'i' then case is ignored.
10271 In legacy script, for backwards compatibility, the value one
10272 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010273
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010274 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010275 locale is used for ordering. Implementation details: strcoll()
10276 is used to compare strings. See |:language| check or set the
10277 collation locale. |v:collate| can also be used to check the
10278 current locale. Sorting using the locale typically ignores
10279 case. Example: >
10280 " ö is sorted similarly to o with English locale.
10281 :language collate en_US.UTF8
10282 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10283< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10284>
10285 " ö is sorted after z with Swedish locale.
10286 :language collate sv_SE.UTF8
10287 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10288< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10289 This does not work properly on Mac.
10290
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010291 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010292 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010293 strtod() function to parse numbers. Strings, Lists, Dicts and
10294 Funcrefs will be considered as being 0). Note that this won't
10295 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010296
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010297 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010298 sorted numerical. This is like 'n' but a string containing
10299 digits will be used as the number they represent.
10300
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010301 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010302 sorted numerical. All values must be a Number or a Float.
10303
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010304 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010305 is called to compare items. The function is invoked with two
10306 items as argument and must return zero if they are equal, 1 or
10307 bigger if the first one sorts after the second one, -1 or
10308 smaller if the first one sorts before the second one.
10309
10310 {dict} is for functions with the "dict" attribute. It will be
10311 used to set the local variable "self". |Dictionary-function|
10312
10313 The sort is stable, items which compare equal (as number or as
10314 string) will keep their relative position. E.g., when sorting
10315 on numbers, text strings will sort next to each other, in the
10316 same order as they were originally.
10317
10318 Can also be used as a |method|: >
10319 mylist->sort()
10320
10321< Also see |uniq()|.
10322
10323 Example: >
10324 func MyCompare(i1, i2)
10325 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10326 endfunc
10327 eval mylist->sort("MyCompare")
10328< A shorter compare version for this specific simple case, which
10329 ignores overflow: >
10330 func MyCompare(i1, i2)
10331 return a:i1 - a:i2
10332 endfunc
10333< For a simple expression you can use a lambda: >
10334 eval mylist->sort({i1, i2 -> i1 - i2})
10335<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010336 Return type: list<{type}>
10337
10338
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010339sound_clear() *sound_clear()*
10340 Stop playing all sounds.
10341
10342 On some Linux systems you may need the libcanberra-pulse
10343 package, otherwise sound may not stop.
10344
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010345 Return type: |Number|
10346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010347 {only available when compiled with the |+sound| feature}
10348
10349 *sound_playevent()*
10350sound_playevent({name} [, {callback}])
10351 Play a sound identified by {name}. Which event names are
10352 supported depends on the system. Often the XDG sound names
10353 are used. On Ubuntu they may be found in
10354 /usr/share/sounds/freedesktop/stereo. Example: >
10355 call sound_playevent('bell')
10356< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10357 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10358 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010359 On macOS, {name} refers to files located in
10360 /System/Library/Sounds (e.g. "Tink"). It will also work for
10361 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010362
10363 When {callback} is specified it is invoked when the sound is
10364 finished. The first argument is the sound ID, the second
10365 argument is the status:
10366 0 sound was played to the end
10367 1 sound was interrupted
10368 2 error occurred after sound started
10369 Example: >
10370 func Callback(id, status)
10371 echomsg "sound " .. a:id .. " finished with " .. a:status
10372 endfunc
10373 call sound_playevent('bell', 'Callback')
10374
10375< MS-Windows: {callback} doesn't work for this function.
10376
10377 Returns the sound ID, which can be passed to `sound_stop()`.
10378 Returns zero if the sound could not be played.
10379
10380 Can also be used as a |method|: >
10381 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010382<
10383 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010384
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010385 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010386
10387 *sound_playfile()*
10388sound_playfile({path} [, {callback}])
10389 Like `sound_playevent()` but play sound file {path}. {path}
10390 must be a full path. On Ubuntu you may find files to play
10391 with this command: >
10392 :!find /usr/share/sounds -type f | grep -v index.theme
10393
10394< Can also be used as a |method|: >
10395 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010396<
10397 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010398
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010399 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010400
10401
10402sound_stop({id}) *sound_stop()*
10403 Stop playing sound {id}. {id} must be previously returned by
10404 `sound_playevent()` or `sound_playfile()`.
10405
10406 On some Linux systems you may need the libcanberra-pulse
10407 package, otherwise sound may not stop.
10408
10409 On MS-Windows, this does not work for event sound started by
10410 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10411
10412 Can also be used as a |method|: >
10413 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010414<
10415 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010416
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010417 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010418
10419 *soundfold()*
10420soundfold({word})
10421 Return the sound-folded equivalent of {word}. Uses the first
10422 language in 'spelllang' for the current window that supports
10423 soundfolding. 'spell' must be set. When no sound folding is
10424 possible the {word} is returned unmodified.
10425 This can be used for making spelling suggestions. Note that
10426 the method can be quite slow.
10427
10428 Can also be used as a |method|: >
10429 GetWord()->soundfold()
10430<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010431 Return type: |String|
10432
10433
10434spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010435 Without argument: The result is the badly spelled word under
10436 or after the cursor. The cursor is moved to the start of the
10437 bad word. When no bad word is found in the cursor line the
10438 result is an empty string and the cursor doesn't move.
10439
10440 With argument: The result is the first word in {sentence} that
10441 is badly spelled. If there are no spelling mistakes the
10442 result is an empty string.
10443
10444 The return value is a list with two items:
10445 - The badly spelled word or an empty string.
10446 - The type of the spelling error:
10447 "bad" spelling mistake
10448 "rare" rare word
10449 "local" word only valid in another region
10450 "caps" word should start with Capital
10451 Example: >
10452 echo spellbadword("the quik brown fox")
10453< ['quik', 'bad'] ~
10454
10455 The spelling information for the current window and the value
10456 of 'spelllang' are used.
10457
10458 Can also be used as a |method|: >
10459 GetText()->spellbadword()
10460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010461 Return type: list<string>
10462
10463
10464spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010465 Return a |List| with spelling suggestions to replace {word}.
10466 When {max} is given up to this number of suggestions are
10467 returned. Otherwise up to 25 suggestions are returned.
10468
10469 When the {capital} argument is given and it's non-zero only
10470 suggestions with a leading capital will be given. Use this
10471 after a match with 'spellcapcheck'.
10472
10473 {word} can be a badly spelled word followed by other text.
10474 This allows for joining two words that were split. The
10475 suggestions also include the following text, thus you can
10476 replace a line.
10477
10478 {word} may also be a good word. Similar words will then be
10479 returned. {word} itself is not included in the suggestions,
10480 although it may appear capitalized.
10481
10482 The spelling information for the current window is used. The
10483 values of 'spelllang' and 'spellsuggest' are used.
10484
10485 Can also be used as a |method|: >
10486 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010487<
10488 Return type: list<string> or list<any>
10489
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010490
10491split({string} [, {pattern} [, {keepempty}]]) *split()*
10492 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010493 empty each white space separated sequence of characters
10494 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010495 Otherwise the string is split where {pattern} matches,
10496 removing the matched characters. 'ignorecase' is not used
10497 here, add \c to ignore case. |/\c|
10498 When the first or last item is empty it is omitted, unless the
10499 {keepempty} argument is given and it's non-zero.
10500 Other empty items are kept when {pattern} matches at least one
10501 character or when {keepempty} is non-zero.
10502 Example: >
10503 :let words = split(getline('.'), '\W\+')
10504< To split a string in individual characters: >
10505 :for c in split(mystring, '\zs')
10506< If you want to keep the separator you can also use '\zs' at
10507 the end of the pattern: >
10508 :echo split('abc:def:ghi', ':\zs')
10509< ['abc:', 'def:', 'ghi'] ~
10510 Splitting a table where the first element can be empty: >
10511 :let items = split(line, ':', 1)
10512< The opposite function is |join()|.
10513
10514 Can also be used as a |method|: >
10515 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010516<
10517 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010518
10519sqrt({expr}) *sqrt()*
10520 Return the non-negative square root of Float {expr} as a
10521 |Float|.
10522 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010523 is negative the result is NaN (Not a Number). Returns 0.0 if
10524 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010525 Examples: >
10526 :echo sqrt(100)
10527< 10.0 >
10528 :echo sqrt(-4.01)
10529< nan
10530 "nan" may be different, it depends on system libraries.
10531
10532 Can also be used as a |method|: >
10533 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010534<
10535 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010536
10537
10538srand([{expr}]) *srand()*
10539 Initialize seed used by |rand()|:
10540 - If {expr} is not given, seed values are initialized by
10541 reading from /dev/urandom, if possible, or using time(NULL)
10542 a.k.a. epoch time otherwise; this only has second accuracy.
10543 - If {expr} is given it must be a Number. It is used to
10544 initialize the seed values. This is useful for testing or
10545 when a predictable sequence is intended.
10546
10547 Examples: >
10548 :let seed = srand()
10549 :let seed = srand(userinput)
10550 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010551<
10552 Return type: list<number>
10553
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010554
10555state([{what}]) *state()*
10556 Return a string which contains characters indicating the
10557 current state. Mostly useful in callbacks that want to do
10558 work that may not always be safe. Roughly this works like:
10559 - callback uses state() to check if work is safe to do.
10560 Yes: then do it right away.
10561 No: add to work queue and add a |SafeState| and/or
10562 |SafeStateAgain| autocommand (|SafeState| triggers at
10563 toplevel, |SafeStateAgain| triggers after handling
10564 messages and callbacks).
10565 - When SafeState or SafeStateAgain is triggered and executes
10566 your autocommand, check with `state()` if the work can be
10567 done now, and if yes remove it from the queue and execute.
10568 Remove the autocommand if the queue is now empty.
10569 Also see |mode()|.
10570
10571 When {what} is given only characters in this string will be
10572 added. E.g, this checks if the screen has scrolled: >
10573 if state('s') == ''
10574 " screen has not scrolled
10575<
10576 These characters indicate the state, generally indicating that
10577 something is busy:
10578 m halfway a mapping, :normal command, feedkeys() or
10579 stuffed command
10580 o operator pending, e.g. after |d|
10581 a Insert mode autocomplete active
10582 x executing an autocommand
10583 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10584 ch_readraw() when reading json
10585 S not triggering SafeState or SafeStateAgain, e.g. after
10586 |f| or a count
10587 c callback invoked, including timer (repeats for
10588 recursiveness up to "ccc")
10589 s screen has scrolled for messages
10590
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010591 Return type: |String|
10592
10593
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010594str2blob({string} [, {options}]) *str2blob()*
10595 Return a Blob by converting the characters in {string} into
10596 bytes.
10597
10598 If {options} is not supplied, the current 'encoding' value is
10599 used to convert the characters in {string} into bytes.
10600
10601 The argument {options} is a |Dict| and supports the following
10602 items:
10603 encoding Encode the characters in {string} using this
10604 encoding. The value is a |String|. See
10605 |encoding-names| for the supported values.
10606
10607 An error is given and an empty blob is returned if the
10608 character encoding fails.
10609
10610 Returns an empty Blob if {string} is empty.
10611
10612 See also |blob2str()|
10613
10614 Examples: >
10615 str2blob("ab") returns 0z6162
10616 str2blob("«»") returns 0zC2ABC2BB
10617 str2blob("«»", {'encoding': 'latin1'}) returns 0zABBB
10618<
10619 Can also be used as a |method|: >
10620 GetStr()->str2blob()
10621<
10622 Return type: |Blob|
10623
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010624str2float({string} [, {quoted}]) *str2float()*
10625 Convert String {string} to a Float. This mostly works the
10626 same as when using a floating point number in an expression,
10627 see |floating-point-format|. But it's a bit more permissive.
10628 E.g., "1e40" is accepted, while in an expression you need to
10629 write "1.0e40". The hexadecimal form "0x123" is also
10630 accepted, but not others, like binary or octal.
10631 When {quoted} is present and non-zero then embedded single
10632 quotes before the dot are ignored, thus "1'000.0" is a
10633 thousand.
10634 Text after the number is silently ignored.
10635 The decimal point is always '.', no matter what the locale is
10636 set to. A comma ends the number: "12,345.67" is converted to
10637 12.0. You can strip out thousands separators with
10638 |substitute()|: >
10639 let f = str2float(substitute(text, ',', '', 'g'))
10640<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010641 Returns 0.0 if the conversion fails.
10642
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010643 Can also be used as a |method|: >
10644 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010645<
10646 Return type: |Float|
10647
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010648
10649str2list({string} [, {utf8}]) *str2list()*
10650 Return a list containing the number values which represent
10651 each character in String {string}. Examples: >
10652 str2list(" ") returns [32]
10653 str2list("ABC") returns [65, 66, 67]
10654< |list2str()| does the opposite.
10655
10656 When {utf8} is omitted or zero, the current 'encoding' is used.
10657 When {utf8} is TRUE, always treat the String as UTF-8
10658 characters. With UTF-8 composing characters are handled
10659 properly: >
10660 str2list("á") returns [97, 769]
10661
10662< Can also be used as a |method|: >
10663 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010664<
10665 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010666
10667
10668str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10669 Convert string {string} to a number.
10670 {base} is the conversion base, it can be 2, 8, 10 or 16.
10671 When {quoted} is present and non-zero then embedded single
10672 quotes are ignored, thus "1'000'000" is a million.
10673
10674 When {base} is omitted base 10 is used. This also means that
10675 a leading zero doesn't cause octal conversion to be used, as
10676 with the default String to Number conversion. Example: >
10677 let nr = str2nr('0123')
10678<
10679 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10680 different base the result will be zero. Similarly, when
10681 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10682 {base} is 2 a leading "0b" or "0B" is ignored.
10683 Text after the number is silently ignored.
10684
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010685 Returns 0 if {string} is empty or on error.
10686
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010687 Can also be used as a |method|: >
10688 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010689<
10690 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010691
10692
10693strcharlen({string}) *strcharlen()*
10694 The result is a Number, which is the number of characters
10695 in String {string}. Composing characters are ignored.
10696 |strchars()| can count the number of characters, counting
10697 composing characters separately.
10698
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010699 Returns 0 if {string} is empty or on error.
10700
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010701 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10702
10703 Can also be used as a |method|: >
10704 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010705<
10706 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010707
10708
10709strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10710 Like |strpart()| but using character index and length instead
10711 of byte index and length.
10712 When {skipcc} is omitted or zero, composing characters are
10713 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010714 When {skipcc} set to 1, composing characters are treated as a
10715 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010716 When a character index is used where a character does not
10717 exist it is omitted and counted as one character. For
10718 example: >
10719 strcharpart('abc', -1, 2)
10720< results in 'a'.
10721
Bram Moolenaard592deb2022-06-17 15:42:40 +010010722 Returns an empty string on error.
10723
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010724 Can also be used as a |method|: >
10725 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010726<
10727 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010728
10729
10730strchars({string} [, {skipcc}]) *strchars()*
10731 The result is a Number, which is the number of characters
10732 in String {string}.
10733 When {skipcc} is omitted or zero, composing characters are
10734 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010735 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010736 |strcharlen()| always does this.
10737
Bram Moolenaard592deb2022-06-17 15:42:40 +010010738 Returns zero on error.
10739
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010740 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10741
10742 {skipcc} is only available after 7.4.755. For backward
10743 compatibility, you can define a wrapper function: >
10744 if has("patch-7.4.755")
10745 function s:strchars(str, skipcc)
10746 return strchars(a:str, a:skipcc)
10747 endfunction
10748 else
10749 function s:strchars(str, skipcc)
10750 if a:skipcc
10751 return strlen(substitute(a:str, ".", "x", "g"))
10752 else
10753 return strchars(a:str)
10754 endif
10755 endfunction
10756 endif
10757<
10758 Can also be used as a |method|: >
10759 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010760<
10761 Return type: |Number|
10762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010763
10764strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10765 The result is a Number, which is the number of display cells
10766 String {string} occupies on the screen when it starts at {col}
10767 (first column is zero). When {col} is omitted zero is used.
10768 Otherwise it is the screen column where to start. This
10769 matters for Tab characters.
10770 The option settings of the current window are used. This
10771 matters for anything that's displayed differently, such as
10772 'tabstop' and 'display'.
10773 When {string} contains characters with East Asian Width Class
10774 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010775 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010776 Also see |strlen()|, |strwidth()| and |strchars()|.
10777
10778 Can also be used as a |method|: >
10779 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010780<
10781 Return type: |Number|
10782
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010783
10784strftime({format} [, {time}]) *strftime()*
10785 The result is a String, which is a formatted date and time, as
10786 specified by the {format} string. The given {time} is used,
10787 or the current time if no time is given. The accepted
10788 {format} depends on your system, thus this is not portable!
10789 See the manual page of the C function strftime() for the
10790 format. The maximum length of the result is 80 characters.
10791 See also |localtime()|, |getftime()| and |strptime()|.
10792 The language can be changed with the |:language| command.
10793 Examples: >
10794 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10795 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10796 :echo strftime("%y%m%d %T") 970427 11:53:55
10797 :echo strftime("%H:%M") 11:55
10798 :echo strftime("%c", getftime("file.c"))
10799 Show mod time of file.c.
10800< Not available on all systems. To check use: >
10801 :if exists("*strftime")
10802
10803< Can also be used as a |method|: >
10804 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010805<
10806 Return type: |String|
10807
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010808
10809strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010810 Get a Number corresponding to the character at {index} in
10811 {str}. This uses a zero-based character index, not a byte
10812 index. Composing characters are considered separate
10813 characters here. Use |nr2char()| to convert the Number to a
10814 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010815 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010816 Also see |strcharpart()| and |strchars()|.
10817
10818 Can also be used as a |method|: >
10819 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010820<
10821 Return type: |Number|
10822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010823
10824stridx({haystack}, {needle} [, {start}]) *stridx()*
10825 The result is a Number, which gives the byte index in
10826 {haystack} of the first occurrence of the String {needle}.
10827 If {start} is specified, the search starts at index {start}.
10828 This can be used to find a second match: >
10829 :let colon1 = stridx(line, ":")
10830 :let colon2 = stridx(line, ":", colon1 + 1)
10831< The search is done case-sensitive.
10832 For pattern searches use |match()|.
10833 -1 is returned if the {needle} does not occur in {haystack}.
10834 See also |strridx()|.
10835 Examples: >
10836 :echo stridx("An Example", "Example") 3
10837 :echo stridx("Starting point", "Start") 0
10838 :echo stridx("Starting point", "start") -1
10839< *strstr()* *strchr()*
10840 stridx() works similar to the C function strstr(). When used
10841 with a single character it works similar to strchr().
10842
10843 Can also be used as a |method|: >
10844 GetHaystack()->stridx(needle)
10845<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010846 Return type: |Number|
10847
10848
10849string({expr}) *string()*
10850 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010851 Float, String, Blob or a composition of them, then the result
10852 can be parsed back with |eval()|.
10853 {expr} type result ~
10854 String 'string' (single quotes are doubled)
10855 Number 123
10856 Float 123.123456 or 1.123456e8
10857 Funcref function('name')
10858 Blob 0z00112233.44556677.8899
10859 List [item, item]
10860 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010861 Class class SomeName
10862 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010863 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010864 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010865
10866 When a |List| or |Dictionary| has a recursive reference it is
10867 replaced by "[...]" or "{...}". Using eval() on the result
10868 will then fail.
10869
mityu7f0bba22024-03-29 10:14:41 +010010870 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010871 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010872 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010873
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010874 Can also be used as a |method|: >
10875 mylist->string()
10876
10877< Also see |strtrans()|.
10878
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010879 Return type: |String|
10880
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010881
10882strlen({string}) *strlen()*
10883 The result is a Number, which is the length of the String
10884 {string} in bytes.
10885 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010886 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010887 If you want to count the number of multibyte characters use
10888 |strchars()|.
10889 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10890
10891 Can also be used as a |method|: >
10892 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010893<
10894 Return type: |Number|
10895
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010896
10897strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10898 The result is a String, which is part of {src}, starting from
10899 byte {start}, with the byte length {len}.
10900 When {chars} is present and TRUE then {len} is the number of
10901 characters positions (composing characters are not counted
10902 separately, thus "1" means one base character and any
10903 following composing characters).
10904 To count {start} as characters instead of bytes use
10905 |strcharpart()|.
10906
10907 When bytes are selected which do not exist, this doesn't
10908 result in an error, the bytes are simply omitted.
10909 If {len} is missing, the copy continues from {start} till the
10910 end of the {src}. >
10911 strpart("abcdefg", 3, 2) == "de"
10912 strpart("abcdefg", -2, 4) == "ab"
10913 strpart("abcdefg", 5, 4) == "fg"
10914 strpart("abcdefg", 3) == "defg"
10915
10916< Note: To get the first character, {start} must be 0. For
10917 example, to get the character under the cursor: >
10918 strpart(getline("."), col(".") - 1, 1, v:true)
10919<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010920 Returns an empty string on error.
10921
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010922 Can also be used as a |method|: >
10923 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010924<
10925 Return type: |String|
10926
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010927
10928strptime({format}, {timestring}) *strptime()*
10929 The result is a Number, which is a unix timestamp representing
10930 the date and time in {timestring}, which is expected to match
10931 the format specified in {format}.
10932
10933 The accepted {format} depends on your system, thus this is not
10934 portable! See the manual page of the C function strptime()
10935 for the format. Especially avoid "%c". The value of $TZ also
10936 matters.
10937
10938 If the {timestring} cannot be parsed with {format} zero is
10939 returned. If you do not know the format of {timestring} you
10940 can try different {format} values until you get a non-zero
10941 result.
10942
10943 See also |strftime()|.
10944 Examples: >
10945 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10946< 862156163 >
10947 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10948< Sun Apr 27 11:53:55 1997 >
10949 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10950< Sun Apr 27 12:53:55 1997
10951
10952 Can also be used as a |method|: >
10953 GetFormat()->strptime(timestring)
10954<
10955 Not available on all systems. To check use: >
10956 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010957<
10958 Return type: |Number|
10959
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010960
10961strridx({haystack}, {needle} [, {start}]) *strridx()*
10962 The result is a Number, which gives the byte index in
10963 {haystack} of the last occurrence of the String {needle}.
10964 When {start} is specified, matches beyond this index are
10965 ignored. This can be used to find a match before a previous
10966 match: >
10967 :let lastcomma = strridx(line, ",")
10968 :let comma2 = strridx(line, ",", lastcomma - 1)
10969< The search is done case-sensitive.
10970 For pattern searches use |match()|.
10971 -1 is returned if the {needle} does not occur in {haystack}.
10972 If the {needle} is empty the length of {haystack} is returned.
10973 See also |stridx()|. Examples: >
10974 :echo strridx("an angry armadillo", "an") 3
10975< *strrchr()*
10976 When used with a single character it works similar to the C
10977 function strrchr().
10978
10979 Can also be used as a |method|: >
10980 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010981<
10982 Return type: |Number|
10983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010984
10985strtrans({string}) *strtrans()*
10986 The result is a String, which is {string} with all unprintable
10987 characters translated into printable characters |'isprint'|.
10988 Like they are shown in a window. Example: >
10989 echo strtrans(@a)
10990< This displays a newline in register a as "^@" instead of
10991 starting a new line.
10992
Bram Moolenaard592deb2022-06-17 15:42:40 +010010993 Returns an empty string on error.
10994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010995 Can also be used as a |method|: >
10996 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010997<
10998 Return type: |String|
10999
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011000
Christian Brabandt67672ef2023-04-24 21:09:54 +010011001strutf16len({string} [, {countcc}]) *strutf16len()*
11002 The result is a Number, which is the number of UTF-16 code
11003 units in String {string} (after converting it to UTF-16).
11004
11005 When {countcc} is TRUE, composing characters are counted
11006 separately.
11007 When {countcc} is omitted or FALSE, composing characters are
11008 ignored.
11009
11010 Returns zero on error.
11011
11012 Also see |strlen()| and |strcharlen()|.
11013 Examples: >
11014 echo strutf16len('a') returns 1
11015 echo strutf16len('©') returns 1
11016 echo strutf16len('😊') returns 2
11017 echo strutf16len('ą́') returns 1
11018 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011019<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011020 Can also be used as a |method|: >
11021 GetText()->strutf16len()
11022<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011023 Return type: |Number|
11024
11025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011026strwidth({string}) *strwidth()*
11027 The result is a Number, which is the number of display cells
11028 String {string} occupies. A Tab character is counted as one
11029 cell, alternatively use |strdisplaywidth()|.
11030 When {string} contains characters with East Asian Width Class
11031 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011032 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011033 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11034
11035 Can also be used as a |method|: >
11036 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011037<
11038 Return type: |Number|
11039
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011040
11041submatch({nr} [, {list}]) *submatch()* *E935*
11042 Only for an expression in a |:substitute| command or
11043 substitute() function.
11044 Returns the {nr}'th submatch of the matched text. When {nr}
11045 is 0 the whole matched text is returned.
11046 Note that a NL in the string can stand for a line break of a
11047 multi-line match or a NUL character in the text.
11048 Also see |sub-replace-expression|.
11049
11050 If {list} is present and non-zero then submatch() returns
11051 a list of strings, similar to |getline()| with two arguments.
11052 NL characters in the text represent NUL characters in the
11053 text.
11054 Only returns more than one item for |:substitute|, inside
11055 |substitute()| this list will always contain one or zero
11056 items, since there are no real line breaks.
11057
11058 When substitute() is used recursively only the submatches in
11059 the current (deepest) call can be obtained.
11060
Bram Moolenaard592deb2022-06-17 15:42:40 +010011061 Returns an empty string or list on error.
11062
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011063 Examples: >
11064 :s/\d\+/\=submatch(0) + 1/
11065 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11066< This finds the first number in the line and adds one to it.
11067 A line break is included as a newline character.
11068
11069 Can also be used as a |method|: >
11070 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011071<
11072 Return type: |String| or list<string> depending on {list}
11073
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011074
11075substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11076 The result is a String, which is a copy of {string}, in which
11077 the first match of {pat} is replaced with {sub}.
11078 When {flags} is "g", all matches of {pat} in {string} are
11079 replaced. Otherwise {flags} should be "".
11080
11081 This works like the ":substitute" command (without any flags).
11082 But the matching with {pat} is always done like the 'magic'
11083 option is set and 'cpoptions' is empty (to make scripts
11084 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11085 if you want to ignore or match case and ignore 'ignorecase'.
11086 'smartcase' is not used. See |string-match| for how {pat} is
11087 used.
11088
11089 A "~" in {sub} is not replaced with the previous {sub}.
11090 Note that some codes in {sub} have a special meaning
11091 |sub-replace-special|. For example, to replace something with
11092 "\n" (two characters), use "\\\\n" or '\\n'.
11093
11094 When {pat} does not match in {string}, {string} is returned
11095 unmodified.
11096
11097 Example: >
11098 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11099< This removes the last component of the 'path' option. >
11100 :echo substitute("testing", ".*", "\\U\\0", "")
11101< results in "TESTING".
11102
11103 When {sub} starts with "\=", the remainder is interpreted as
11104 an expression. See |sub-replace-expression|. Example: >
11105 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011106 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011107
11108< When {sub} is a Funcref that function is called, with one
11109 optional argument. Example: >
11110 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11111< The optional argument is a list which contains the whole
11112 matched string and up to nine submatches, like what
11113 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011114 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011115
Bram Moolenaard592deb2022-06-17 15:42:40 +010011116< Returns an empty string on error.
11117
11118 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011119 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011120<
11121 Return type: |String|
11122
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011123
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011124swapfilelist() *swapfilelist()*
11125 Returns a list of swap file names, like what "vim -r" shows.
11126 See the |-r| command argument. The 'directory' option is used
11127 for the directories to inspect. If you only want to get a
11128 list of swap files in the current directory then temporarily
11129 set 'directory' to a dot: >
11130 let save_dir = &directory
11131 let &directory = '.'
11132 let swapfiles = swapfilelist()
11133 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011134<
11135 Return type: list<string>
11136
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011137
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011138swapinfo({fname}) *swapinfo()*
11139 The result is a dictionary, which holds information about the
11140 swapfile {fname}. The available fields are:
11141 version Vim version
11142 user user name
11143 host host name
11144 fname original file name
11145 pid PID of the Vim process that created the swap
11146 file
11147 mtime last modification time in seconds
11148 inode Optional: INODE number of the file
11149 dirty 1 if file was modified, 0 if not
11150 Note that "user" and "host" are truncated to at most 39 bytes.
11151 In case of failure an "error" item is added with the reason:
11152 Cannot open file: file not found or in accessible
11153 Cannot read file: cannot read first block
11154 Not a swap file: does not contain correct block ID
11155 Magic number mismatch: Info in first block is invalid
11156
11157 Can also be used as a |method|: >
11158 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011159<
11160 Return type: dict<any> or dict<string>
11161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011162
11163swapname({buf}) *swapname()*
11164 The result is the swap file path of the buffer {expr}.
11165 For the use of {buf}, see |bufname()| above.
11166 If buffer {buf} is the current buffer, the result is equal to
11167 |:swapname| (unless there is no swap file).
11168 If buffer {buf} has no swap file, returns an empty string.
11169
11170 Can also be used as a |method|: >
11171 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011172<
11173 Return type: |String|
11174
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011175
11176synID({lnum}, {col}, {trans}) *synID()*
11177 The result is a Number, which is the syntax ID at the position
11178 {lnum} and {col} in the current window.
11179 The syntax ID can be used with |synIDattr()| and
11180 |synIDtrans()| to obtain syntax information about text.
11181
11182 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11183 line. 'synmaxcol' applies, in a longer line zero is returned.
11184 Note that when the position is after the last character,
11185 that's where the cursor can be in Insert mode, synID() returns
11186 zero. {lnum} is used like with |getline()|.
11187
11188 When {trans} is |TRUE|, transparent items are reduced to the
11189 item that they reveal. This is useful when wanting to know
11190 the effective color. When {trans} is |FALSE|, the transparent
11191 item is returned. This is useful when wanting to know which
11192 syntax item is effective (e.g. inside parens).
11193 Warning: This function can be very slow. Best speed is
11194 obtained by going through the file in forward direction.
11195
Bram Moolenaard592deb2022-06-17 15:42:40 +010011196 Returns zero on error.
11197
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011198 Example (echoes the name of the syntax item under the cursor): >
11199 :echo synIDattr(synID(line("."), col("."), 1), "name")
11200<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011201 Return type: |Number|
11202
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011203
11204synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11205 The result is a String, which is the {what} attribute of
11206 syntax ID {synID}. This can be used to obtain information
11207 about a syntax item.
11208 {mode} can be "gui", "cterm" or "term", to get the attributes
11209 for that mode. When {mode} is omitted, or an invalid value is
11210 used, the attributes for the currently active highlighting are
11211 used (GUI, cterm or term).
11212 Use synIDtrans() to follow linked highlight groups.
11213 {what} result
11214 "name" the name of the syntax item
11215 "fg" foreground color (GUI: color name used to set
11216 the color, cterm: color number as a string,
11217 term: empty string)
11218 "bg" background color (as with "fg")
11219 "font" font name (only available in the GUI)
11220 |highlight-font|
11221 "sp" special color for the GUI (as with "fg")
11222 |highlight-guisp|
11223 "ul" underline color for cterm: number as a string
11224 "fg#" like "fg", but for the GUI and the GUI is
11225 running the name in "#RRGGBB" form
11226 "bg#" like "fg#" for "bg"
11227 "sp#" like "fg#" for "sp"
11228 "bold" "1" if bold
11229 "italic" "1" if italic
11230 "reverse" "1" if reverse
11231 "inverse" "1" if inverse (= reverse)
11232 "standout" "1" if standout
11233 "underline" "1" if underlined
11234 "undercurl" "1" if undercurled
11235 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011236 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011237
Bram Moolenaard592deb2022-06-17 15:42:40 +010011238 Returns an empty string on error.
11239
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011240 Example (echoes the color of the syntax item under the
11241 cursor): >
11242 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11243<
11244 Can also be used as a |method|: >
11245 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011246<
11247 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011248
11249
11250synIDtrans({synID}) *synIDtrans()*
11251 The result is a Number, which is the translated syntax ID of
11252 {synID}. This is the syntax group ID of what is being used to
11253 highlight the character. Highlight links given with
11254 ":highlight link" are followed.
11255
Bram Moolenaard592deb2022-06-17 15:42:40 +010011256 Returns zero on error.
11257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011258 Can also be used as a |method|: >
11259 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011260<
11261 Return type: |Number|
11262
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011263
11264synconcealed({lnum}, {col}) *synconcealed()*
11265 The result is a |List| with currently three items:
11266 1. The first item in the list is 0 if the character at the
11267 position {lnum} and {col} is not part of a concealable
11268 region, 1 if it is. {lnum} is used like with |getline()|.
11269 2. The second item in the list is a string. If the first item
11270 is 1, the second item contains the text which will be
11271 displayed in place of the concealed text, depending on the
11272 current setting of 'conceallevel' and 'listchars'.
11273 3. The third and final item in the list is a number
11274 representing the specific syntax region matched in the
11275 line. When the character is not concealed the value is
11276 zero. This allows detection of the beginning of a new
11277 concealable region if there are two consecutive regions
11278 with the same replacement character. For an example, if
11279 the text is "123456" and both "23" and "45" are concealed
11280 and replaced by the character "X", then:
11281 call returns ~
11282 synconcealed(lnum, 1) [0, '', 0]
11283 synconcealed(lnum, 2) [1, 'X', 1]
11284 synconcealed(lnum, 3) [1, 'X', 1]
11285 synconcealed(lnum, 4) [1, 'X', 2]
11286 synconcealed(lnum, 5) [1, 'X', 2]
11287 synconcealed(lnum, 6) [0, '', 0]
11288
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011289 Note: Doesn't consider |matchadd()| highlighting items,
11290 since syntax and matching highlighting are two different
11291 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011292
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011293 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011294
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011295
11296synstack({lnum}, {col}) *synstack()*
11297 Return a |List|, which is the stack of syntax items at the
11298 position {lnum} and {col} in the current window. {lnum} is
11299 used like with |getline()|. Each item in the List is an ID
11300 like what |synID()| returns.
11301 The first item in the List is the outer region, following are
11302 items contained in that one. The last one is what |synID()|
11303 returns, unless not the whole item is highlighted or it is a
11304 transparent item.
11305 This function is useful for debugging a syntax file.
11306 Example that shows the syntax stack under the cursor: >
11307 for id in synstack(line("."), col("."))
11308 echo synIDattr(id, "name")
11309 endfor
11310< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011311 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011312 character in a line and the first column in an empty line are
11313 valid positions.
11314
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011315 Return type: list<number> or list<any>
11316
11317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011318system({expr} [, {input}]) *system()* *E677*
11319 Get the output of the shell command {expr} as a |String|. See
11320 |systemlist()| to get the output as a |List|.
11321
11322 When {input} is given and is a |String| this string is written
11323 to a file and passed as stdin to the command. The string is
11324 written as-is, you need to take care of using the correct line
11325 separators yourself.
11326 If {input} is given and is a |List| it is written to the file
11327 in a way |writefile()| does with {binary} set to "b" (i.e.
11328 with a newline between each list item with newlines inside
11329 list items converted to NULs).
11330 When {input} is given and is a number that is a valid id for
11331 an existing buffer then the content of the buffer is written
11332 to the file line by line, each line terminated by a NL and
11333 NULs characters where the text has a NL.
11334
11335 Pipes are not used, the 'shelltemp' option is not used.
11336
11337 When prepended by |:silent| the terminal will not be set to
11338 cooked mode. This is meant to be used for commands that do
11339 not need the user to type. It avoids stray characters showing
11340 up on the screen which require |CTRL-L| to remove. >
11341 :silent let f = system('ls *.vim')
11342<
11343 Note: Use |shellescape()| or |::S| with |expand()| or
11344 |fnamemodify()| to escape special characters in a command
11345 argument. Newlines in {expr} may cause the command to fail.
11346 The characters in 'shellquote' and 'shellxquote' may also
11347 cause trouble.
11348 This is not to be used for interactive commands.
11349
11350 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011351 :let files = system('ls ' .. shellescape(expand('%:h')))
11352 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011353
11354< To make the result more system-independent, the shell output
11355 is filtered to replace <CR> with <NL> for Macintosh, and
11356 <CR><NL> with <NL> for DOS-like systems.
11357 To avoid the string being truncated at a NUL, all NUL
11358 characters are replaced with SOH (0x01).
11359
11360 The command executed is constructed using several options:
11361 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11362 ({tmp} is an automatically generated file name).
11363 For Unix, braces are put around {expr} to allow for
11364 concatenated commands.
11365
11366 The command will be executed in "cooked" mode, so that a
11367 CTRL-C will interrupt the command (on Unix at least).
11368
11369 The resulting error code can be found in |v:shell_error|.
11370 This function will fail in |restricted-mode|.
11371
11372 Note that any wrong value in the options mentioned above may
11373 make the function fail. It has also been reported to fail
11374 when using a security agent application.
11375 Unlike ":!cmd" there is no automatic check for changed files.
11376 Use |:checktime| to force a check.
11377
11378 Can also be used as a |method|: >
11379 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011380<
11381 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011382
11383
11384systemlist({expr} [, {input}]) *systemlist()*
11385 Same as |system()|, but returns a |List| with lines (parts of
11386 output separated by NL) with NULs transformed into NLs. Output
11387 is the same as |readfile()| will output with {binary} argument
11388 set to "b", except that there is no extra empty item when the
11389 result ends in a NL.
11390 Note that on MS-Windows you may get trailing CR characters.
11391
11392 To see the difference between "echo hello" and "echo -n hello"
11393 use |system()| and |split()|: >
11394 echo system('echo hello')->split('\n', 1)
11395<
11396 Returns an empty string on error.
11397
11398 Can also be used as a |method|: >
11399 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011400<
11401 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011402
11403
11404tabpagebuflist([{arg}]) *tabpagebuflist()*
11405 The result is a |List|, where each item is the number of the
11406 buffer associated with each window in the current tab page.
11407 {arg} specifies the number of the tab page to be used. When
11408 omitted the current tab page is used.
11409 When {arg} is invalid the number zero is returned.
11410 To get a list of all buffers in all tabs use this: >
11411 let buflist = []
11412 for i in range(tabpagenr('$'))
11413 call extend(buflist, tabpagebuflist(i + 1))
11414 endfor
11415< Note that a buffer may appear in more than one window.
11416
11417 Can also be used as a |method|: >
11418 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011419<
11420 Return type: list<number>
11421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011422
11423tabpagenr([{arg}]) *tabpagenr()*
11424 The result is a Number, which is the number of the current
11425 tab page. The first tab page has number 1.
11426
11427 The optional argument {arg} supports the following values:
11428 $ the number of the last tab page (the tab page
11429 count).
11430 # the number of the last accessed tab page
11431 (where |g<Tab>| goes to). if there is no
11432 previous tab page 0 is returned.
11433 The number can be used with the |:tab| command.
11434
Bram Moolenaard592deb2022-06-17 15:42:40 +010011435 Returns zero on error.
11436
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011437 Return type: |Number|
11438
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011439
11440tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11441 Like |winnr()| but for tab page {tabarg}.
11442 {tabarg} specifies the number of tab page to be used.
11443 {arg} is used like with |winnr()|:
11444 - When omitted the current window number is returned. This is
11445 the window which will be used when going to this tab page.
11446 - When "$" the number of windows is returned.
11447 - When "#" the previous window nr is returned.
11448 Useful examples: >
11449 tabpagewinnr(1) " current window of tab page 1
11450 tabpagewinnr(4, '$') " number of windows in tab page 4
11451< When {tabarg} is invalid zero is returned.
11452
11453 Can also be used as a |method|: >
11454 GetTabpage()->tabpagewinnr()
11455<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011456 Return type: |Number|
11457
11458
11459tagfiles() *tagfiles()*
11460 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011461 for the current buffer. This is the 'tags' option expanded.
11462
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011463 Return type: list<string> or list<any>
11464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011465
11466taglist({expr} [, {filename}]) *taglist()*
11467 Returns a |List| of tags matching the regular expression {expr}.
11468
11469 If {filename} is passed it is used to prioritize the results
11470 in the same way that |:tselect| does. See |tag-priority|.
11471 {filename} should be the full path of the file.
11472
11473 Each list item is a dictionary with at least the following
11474 entries:
11475 name Name of the tag.
11476 filename Name of the file where the tag is
11477 defined. It is either relative to the
11478 current directory or a full path.
11479 cmd Ex command used to locate the tag in
11480 the file.
11481 kind Type of the tag. The value for this
11482 entry depends on the language specific
11483 kind values. Only available when
11484 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011485 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011486 static A file specific tag. Refer to
11487 |static-tag| for more information.
11488 More entries may be present, depending on the content of the
11489 tags file: access, implementation, inherits and signature.
11490 Refer to the ctags documentation for information about these
11491 fields. For C code the fields "struct", "class" and "enum"
11492 may appear, they give the name of the entity the tag is
11493 contained in.
11494
11495 The ex-command "cmd" can be either an ex search pattern, a
11496 line number or a line number followed by a byte number.
11497
11498 If there are no matching tags, then an empty list is returned.
11499
11500 To get an exact tag match, the anchors '^' and '$' should be
11501 used in {expr}. This also make the function work faster.
11502 Refer to |tag-regexp| for more information about the tag
11503 search regular expression pattern.
11504
11505 Refer to |'tags'| for information about how the tags file is
11506 located by Vim. Refer to |tags-file-format| for the format of
11507 the tags file generated by the different ctags tools.
11508
11509 Can also be used as a |method|: >
11510 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011511<
11512 Return type: list<dict<any>> or list<any>
11513
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011514
11515tan({expr}) *tan()*
11516 Return the tangent of {expr}, measured in radians, as a |Float|
11517 in the range [-inf, inf].
11518 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011519 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011520 Examples: >
11521 :echo tan(10)
11522< 0.648361 >
11523 :echo tan(-4.01)
11524< -1.181502
11525
11526 Can also be used as a |method|: >
11527 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011528<
11529 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011530
11531
11532tanh({expr}) *tanh()*
11533 Return the hyperbolic tangent of {expr} as a |Float| in the
11534 range [-1, 1].
11535 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011536 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011537 Examples: >
11538 :echo tanh(0.5)
11539< 0.462117 >
11540 :echo tanh(-1)
11541< -0.761594
11542
11543 Can also be used as a |method|: >
11544 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011545<
11546 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011547
11548
11549tempname() *tempname()* *temp-file-name*
11550 The result is a String, which is the name of a file that
11551 doesn't exist. It can be used for a temporary file. The name
11552 is different for at least 26 consecutive calls. Example: >
11553 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011554 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011555< For Unix, the file will be in a private directory |tempfile|
11556 that is recursively deleted when Vim exits, on other systems
11557 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011558 For MS-Windows forward slashes are used when the 'shellslash'
11559 option is set, or when 'shellcmdflag' starts with '-' and
11560 'shell' does not contain powershell or pwsh.
11561
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011562 Return type: |String|
11563
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011564
11565term_ functions are documented here: |terminal-function-details|
11566
11567
11568terminalprops() *terminalprops()*
11569 Returns a |Dictionary| with properties of the terminal that Vim
11570 detected from the response to |t_RV| request. See
11571 |v:termresponse| for the response itself. If |v:termresponse|
11572 is empty most values here will be 'u' for unknown.
11573 cursor_style whether sending |t_RS| works **
11574 cursor_blink_mode whether sending |t_RC| works **
11575 underline_rgb whether |t_8u| works **
11576 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011577 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011578
11579 ** value 'u' for unknown, 'y' for yes, 'n' for no
11580
11581 If the |+termresponse| feature is missing then the result is
11582 an empty dictionary.
11583
11584 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11585 current cursor style.
11586 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11587 request the cursor blink status.
11588 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11589 is not empty, Vim will detect the working of sending |t_RS|
11590 and |t_RC| on startup.
11591
11592 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11593 This avoids sending it to xterm, which would clear the colors.
11594
11595 For "mouse" the value 'u' is unknown
11596
11597 Also see:
11598 - 'ambiwidth' - detected by using |t_u7|.
11599 - |v:termstyleresp| and |v:termblinkresp| for the response to
11600 |t_RS| and |t_RC|.
11601
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011602 Return type: dict<string>
11603
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011604
11605test_ functions are documented here: |test-functions-details|
11606
11607
11608 *timer_info()*
11609timer_info([{id}])
11610 Return a list with information about timers.
11611 When {id} is given only information about this timer is
11612 returned. When timer {id} does not exist an empty list is
11613 returned.
11614 When {id} is omitted information about all timers is returned.
11615
11616 For each timer the information is stored in a |Dictionary| with
11617 these items:
11618 "id" the timer ID
11619 "time" time the timer was started with
11620 "remaining" time until the timer fires
11621 "repeat" number of times the timer will still fire;
11622 -1 means forever
11623 "callback" the callback
11624 "paused" 1 if the timer is paused, 0 otherwise
11625
11626 Can also be used as a |method|: >
11627 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011628<
11629 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011630
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011631 {only available when compiled with the |+timers| feature}
11632
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011633
11634timer_pause({timer}, {paused}) *timer_pause()*
11635 Pause or unpause a timer. A paused timer does not invoke its
11636 callback when its time expires. Unpausing a timer may cause
11637 the callback to be invoked almost immediately if enough time
11638 has passed.
11639
11640 Pausing a timer is useful to avoid the callback to be called
11641 for a short time.
11642
11643 If {paused} evaluates to a non-zero Number or a non-empty
11644 String, then the timer is paused, otherwise it is unpaused.
11645 See |non-zero-arg|.
11646
11647 Can also be used as a |method|: >
11648 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011649<
11650 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011651
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011652 {only available when compiled with the |+timers| feature}
11653
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011654
11655 *timer_start()* *timer* *timers*
11656timer_start({time}, {callback} [, {options}])
11657 Create a timer and return the timer ID.
11658
11659 {time} is the waiting time in milliseconds. This is the
11660 minimum time before invoking the callback. When the system is
11661 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011662 Zero can be used to execute the callback when Vim is back in
11663 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011664
11665 {callback} is the function to call. It can be the name of a
11666 function or a |Funcref|. It is called with one argument, which
11667 is the timer ID. The callback is only invoked when Vim is
11668 waiting for input.
11669 If you want to show a message look at |popup_notification()|
11670 to avoid interfering with what the user is doing.
11671
11672 {options} is a dictionary. Supported entries:
11673 "repeat" Number of times to repeat calling the
11674 callback. -1 means forever. When not present
11675 the callback will be called once.
11676 If the timer causes an error three times in a
11677 row the repeat is cancelled. This avoids that
11678 Vim becomes unusable because of all the error
11679 messages.
11680
Bram Moolenaard592deb2022-06-17 15:42:40 +010011681 Returns -1 on error.
11682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011683 Example: >
11684 func MyHandler(timer)
11685 echo 'Handler called'
11686 endfunc
11687 let timer = timer_start(500, 'MyHandler',
11688 \ {'repeat': 3})
11689< This will invoke MyHandler() three times at 500 msec
11690 intervals.
11691
11692 Can also be used as a |method|: >
11693 GetMsec()->timer_start(callback)
11694
11695< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011696
11697 Return type: |Number|
11698
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011699 {only available when compiled with the |+timers| feature}
11700
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011702timer_stop({timer}) *timer_stop()*
11703 Stop a timer. The timer callback will no longer be invoked.
11704 {timer} is an ID returned by timer_start(), thus it must be a
11705 Number. If {timer} does not exist there is no error.
11706
11707 Can also be used as a |method|: >
11708 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011709<
11710 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011711
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011712 {only available when compiled with the |+timers| feature}
11713
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011714
11715timer_stopall() *timer_stopall()*
11716 Stop all timers. The timer callbacks will no longer be
11717 invoked. Useful if a timer is misbehaving. If there are no
11718 timers there is no error.
11719
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011720 Return type: |Number|
11721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011722 {only available when compiled with the |+timers| feature}
11723
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011725tolower({expr}) *tolower()*
11726 The result is a copy of the String given, with all uppercase
11727 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011728 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011729
11730 Can also be used as a |method|: >
11731 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011732<
11733 Return type: |String|
11734
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011735
11736toupper({expr}) *toupper()*
11737 The result is a copy of the String given, with all lowercase
11738 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011739 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011740
11741 Can also be used as a |method|: >
11742 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011743<
11744 Return type: |String|
11745
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011746
11747tr({src}, {fromstr}, {tostr}) *tr()*
11748 The result is a copy of the {src} string with all characters
11749 which appear in {fromstr} replaced by the character in that
11750 position in the {tostr} string. Thus the first character in
11751 {fromstr} is translated into the first character in {tostr}
11752 and so on. Exactly like the unix "tr" command.
11753 This code also deals with multibyte characters properly.
11754
Bram Moolenaard592deb2022-06-17 15:42:40 +010011755 Returns an empty string on error.
11756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011757 Examples: >
11758 echo tr("hello there", "ht", "HT")
11759< returns "Hello THere" >
11760 echo tr("<blob>", "<>", "{}")
11761< returns "{blob}"
11762
11763 Can also be used as a |method|: >
11764 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011765<
11766 Return type: |String|
11767
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011768
11769trim({text} [, {mask} [, {dir}]]) *trim()*
11770 Return {text} as a String where any character in {mask} is
11771 removed from the beginning and/or end of {text}.
11772
Illia Bobyr80799172023-10-17 18:00:50 +020011773 If {mask} is not given, or is an empty string, {mask} is all
11774 characters up to 0x20, which includes Tab, space, NL and CR,
11775 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011776
11777 The optional {dir} argument specifies where to remove the
11778 characters:
11779 0 remove from the beginning and end of {text}
11780 1 remove only at the beginning of {text}
11781 2 remove only at the end of {text}
11782 When omitted both ends are trimmed.
11783
11784 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011785 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011786
11787 Examples: >
11788 echo trim(" some text ")
11789< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011790 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011791< returns "RESERVE_TAIL" >
11792 echo trim("rm<Xrm<>X>rrm", "rm<>")
11793< returns "Xrm<>X" (characters in the middle are not removed) >
11794 echo trim(" vim ", " ", 2)
11795< returns " vim"
11796
11797 Can also be used as a |method|: >
11798 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011799<
11800 Return type: |String|
11801
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011802
11803trunc({expr}) *trunc()*
11804 Return the largest integral value with magnitude less than or
11805 equal to {expr} as a |Float| (truncate towards zero).
11806 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011807 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011808 Examples: >
11809 echo trunc(1.456)
11810< 1.0 >
11811 echo trunc(-5.456)
11812< -5.0 >
11813 echo trunc(4.0)
11814< 4.0
11815
11816 Can also be used as a |method|: >
11817 Compute()->trunc()
11818<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011819 Return type: |Float|
11820
11821
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011822 *type()*
11823type({expr}) The result is a Number representing the type of {expr}.
11824 Instead of using the number directly, it is better to use the
11825 v:t_ variable that has the value:
11826 Number: 0 |v:t_number|
11827 String: 1 |v:t_string|
11828 Funcref: 2 |v:t_func|
11829 List: 3 |v:t_list|
11830 Dictionary: 4 |v:t_dict|
11831 Float: 5 |v:t_float|
11832 Boolean: 6 |v:t_bool| (v:false and v:true)
11833 None: 7 |v:t_none| (v:null and v:none)
11834 Job: 8 |v:t_job|
11835 Channel: 9 |v:t_channel|
11836 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011837 Class: 12 |v:t_class|
11838 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011839 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011840 Enum: 15 |v:t_enum|
11841 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011842 For backward compatibility, this method can be used: >
11843 :if type(myvar) == type(0)
11844 :if type(myvar) == type("")
11845 :if type(myvar) == type(function("tr"))
11846 :if type(myvar) == type([])
11847 :if type(myvar) == type({})
11848 :if type(myvar) == type(0.0)
11849 :if type(myvar) == type(v:false)
11850 :if type(myvar) == type(v:none)
11851< To check if the v:t_ variables exist use this: >
11852 :if exists('v:t_number')
11853
11854< Can also be used as a |method|: >
11855 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011856<
11857 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011858
11859
11860typename({expr}) *typename()*
11861 Return a string representation of the type of {expr}.
11862 Example: >
11863 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011864< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011865
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011866 Return type: |String|
11867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011868
11869undofile({name}) *undofile()*
11870 Return the name of the undo file that would be used for a file
11871 with name {name} when writing. This uses the 'undodir'
11872 option, finding directories that exist. It does not check if
11873 the undo file exists.
11874 {name} is always expanded to the full path, since that is what
11875 is used internally.
11876 If {name} is empty undofile() returns an empty string, since a
11877 buffer without a file name will not write an undo file.
11878 Useful in combination with |:wundo| and |:rundo|.
11879 When compiled without the |+persistent_undo| option this always
11880 returns an empty string.
11881
11882 Can also be used as a |method|: >
11883 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011884<
11885 Return type: |String|
11886
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011887
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011888undotree([{buf}]) *undotree()*
11889 Return the current state of the undo tree for the current
11890 buffer, or for a specific buffer if {buf} is given. The
11891 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011892 "seq_last" The highest undo sequence number used.
11893 "seq_cur" The sequence number of the current position in
11894 the undo tree. This differs from "seq_last"
11895 when some changes were undone.
11896 "time_cur" Time last used for |:earlier| and related
11897 commands. Use |strftime()| to convert to
11898 something readable.
11899 "save_last" Number of the last file write. Zero when no
11900 write yet.
11901 "save_cur" Number of the current position in the undo
11902 tree.
11903 "synced" Non-zero when the last undo block was synced.
11904 This happens when waiting from input from the
11905 user. See |undo-blocks|.
11906 "entries" A list of dictionaries with information about
11907 undo blocks.
11908
11909 The first item in the "entries" list is the oldest undo item.
11910 Each List item is a |Dictionary| with these items:
11911 "seq" Undo sequence number. Same as what appears in
11912 |:undolist|.
11913 "time" Timestamp when the change happened. Use
11914 |strftime()| to convert to something readable.
11915 "newhead" Only appears in the item that is the last one
11916 that was added. This marks the last change
11917 and where further changes will be added.
11918 "curhead" Only appears in the item that is the last one
11919 that was undone. This marks the current
11920 position in the undo tree, the block that will
11921 be used by a redo command. When nothing was
11922 undone after the last change this item will
11923 not appear anywhere.
11924 "save" Only appears on the last block before a file
11925 write. The number is the write count. The
11926 first write has number 1, the last one the
11927 "save_last" mentioned above.
11928 "alt" Alternate entry. This is again a List of undo
11929 blocks. Each item may again have an "alt"
11930 item.
11931
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011932 Return type: dict<any>
11933
11934
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011935uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11936 Remove second and succeeding copies of repeated adjacent
11937 {list} items in-place. Returns {list}. If you want a list
11938 to remain unmodified make a copy first: >
11939 :let newlist = uniq(copy(mylist))
11940< The default compare function uses the string representation of
11941 each item. For the use of {func} and {dict} see |sort()|.
11942
Bram Moolenaard592deb2022-06-17 15:42:40 +010011943 Returns zero if {list} is not a |List|.
11944
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011945 Can also be used as a |method|: >
11946 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011947<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011948 Return type: list<{type}>
11949
11950
Christian Brabandt67672ef2023-04-24 21:09:54 +010011951 *utf16idx()*
11952utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011953 Same as |charidx()| but returns the UTF-16 code unit index of
11954 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011955
11956 When {charidx} is present and TRUE, {idx} is used as the
11957 character index in the String {string} instead of as the byte
11958 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011959 An {idx} in the middle of a UTF-8 sequence is rounded
11960 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011961
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011962 Returns -1 if the arguments are invalid or if there are less
11963 than {idx} bytes in {string}. If there are exactly {idx} bytes
11964 the length of the string in UTF-16 code units is returned.
11965
Christian Brabandt67672ef2023-04-24 21:09:54 +010011966 See |byteidx()| and |byteidxcomp()| for getting the byte index
11967 from the UTF-16 index and |charidx()| for getting the
11968 character index from the UTF-16 index.
11969 Refer to |string-offset-encoding| for more information.
11970 Examples: >
11971 echo utf16idx('a😊😊', 3) returns 2
11972 echo utf16idx('a😊😊', 7) returns 4
11973 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11974 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11975 echo utf16idx('aą́c', 6) returns 2
11976 echo utf16idx('aą́c', 6, 1) returns 4
11977 echo utf16idx('a😊😊', 9) returns -1
11978<
11979 Can also be used as a |method|: >
11980 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011981<
11982 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011983
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011984
11985values({dict}) *values()*
11986 Return a |List| with all the values of {dict}. The |List| is
11987 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011988 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011989
11990 Can also be used as a |method|: >
11991 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011992<
11993 Return type: list<any>
11994
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011995
zeertzjq825cf812023-08-17 22:55:25 +020011996virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011997 The result is a Number, which is the screen column of the file
11998 position given with {expr}. That is, the last screen position
11999 occupied by the character at that position, when the screen
12000 would be of unlimited width. When there is a <Tab> at the
12001 position, the returned Number will be the column at the end of
12002 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12003 set to 8, it returns 8. |conceal| is ignored.
12004 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012005
zeertzjq02f3eba2024-06-12 20:45:24 +020012006 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012007 When {expr} is "$", it means the end of the cursor line, so
12008 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012009
12010 When 'virtualedit' is used {expr} can be [lnum, col, off],
12011 where "off" is the offset in screen columns from the start of
12012 the character. E.g., a position within a <Tab> or after the
12013 last character. When "off" is omitted zero is used. When
12014 Virtual editing is active in the current mode, a position
12015 beyond the end of the line can be returned. Also see
12016 |'virtualedit'|
12017
zeertzjq825cf812023-08-17 22:55:25 +020012018 If {list} is present and non-zero then virtcol() returns a
12019 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012020 character.
12021
zeertzjq825cf812023-08-17 22:55:25 +020012022 With the optional {winid} argument the values are obtained for
12023 that window instead of the current window.
12024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012025 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012027 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012028 " With text "foo^Lbar" and cursor on the "^L":
12029
12030 virtcol(".") " returns 5
12031 virtcol(".", 1) " returns [4, 5]
12032 virtcol("$") " returns 9
12033
12034 " With text " there", with 't at 'h':
12035
12036 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012037<
12038 The first column is 1. 0 or [0, 0] is returned for an error.
12039
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012040 A more advanced example that echoes the maximum length of
12041 all lines: >
12042 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12043
12044< Can also be used as a |method|: >
12045 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012046<
12047 Return type: |Number|
12048
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012049
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012050virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12051 The result is a Number, which is the byte index of the
12052 character in window {winid} at buffer line {lnum} and virtual
12053 column {col}.
12054
zeertzjqb583eda2023-10-14 11:32:28 +020012055 If buffer line {lnum} is an empty line, 0 is returned.
12056
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012057 If {col} is greater than the last virtual column in line
12058 {lnum}, then the byte index of the character at the last
12059 virtual column is returned.
12060
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012061 For a multi-byte character, the column number of the first
12062 byte in the character is returned.
12063
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012064 The {winid} argument can be the window number or the
12065 |window-ID|. If this is zero, then the current window is used.
12066
12067 Returns -1 if the window {winid} doesn't exist or the buffer
12068 line {lnum} or virtual column {col} is invalid.
12069
12070 See also |screenpos()|, |virtcol()| and |col()|.
12071
12072 Can also be used as a |method|: >
12073 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012074<
12075 Return type: |Number|
12076
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012077
12078visualmode([{expr}]) *visualmode()*
12079 The result is a String, which describes the last Visual mode
12080 used in the current buffer. Initially it returns an empty
12081 string, but once Visual mode has been used, it returns "v",
12082 "V", or "<CTRL-V>" (a single CTRL-V character) for
12083 character-wise, line-wise, or block-wise Visual mode
12084 respectively.
12085 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012086 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012087< This enters the same Visual mode as before. It is also useful
12088 in scripts if you wish to act differently depending on the
12089 Visual mode that was used.
12090 If Visual mode is active, use |mode()| to get the Visual mode
12091 (e.g., in a |:vmap|).
12092 If {expr} is supplied and it evaluates to a non-zero Number or
12093 a non-empty String, then the Visual mode will be cleared and
12094 the old value is returned. See |non-zero-arg|.
12095
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012096 Return type: |String|
12097
12098
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012099wildmenumode() *wildmenumode()*
12100 Returns |TRUE| when the wildmenu is active and |FALSE|
12101 otherwise. See 'wildmenu' and 'wildmode'.
12102 This can be used in mappings to handle the 'wildcharm' option
12103 gracefully. (Makes only sense with |mapmode-c| mappings).
12104
12105 For example to make <c-j> work like <down> in wildmode, use: >
12106 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12107<
Milly6c2fc372024-10-16 22:11:17 +020012108 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012109
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012110 Return type: |Number|
12111
12112
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012113win_execute({id}, {command} [, {silent}]) *win_execute()*
12114 Like `execute()` but in the context of window {id}.
12115 The window will temporarily be made the current window,
12116 without triggering autocommands or changing directory. When
12117 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012118 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012119 Example: >
12120 call win_execute(winid, 'set syntax=python')
12121< Doing the same with `setwinvar()` would not trigger
12122 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012123 *E994*
12124 Not all commands are allowed in popup windows.
12125 When window {id} does not exist then no error is given and
12126 an empty string is returned.
12127
12128 Can also be used as a |method|, the base is passed as the
12129 second argument: >
12130 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012131<
12132 Return type: |String|
12133
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012134
12135win_findbuf({bufnr}) *win_findbuf()*
12136 Returns a |List| with |window-ID|s for windows that contain
12137 buffer {bufnr}. When there is none the list is empty.
12138
12139 Can also be used as a |method|: >
12140 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012141<
12142 Return type: list<number> or list<any>
12143
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012144
12145win_getid([{win} [, {tab}]]) *win_getid()*
12146 Get the |window-ID| for the specified window.
12147 When {win} is missing use the current window.
12148 With {win} this is the window number. The top window has
12149 number 1.
12150 Without {tab} use the current tab, otherwise the tab with
12151 number {tab}. The first tab has number one.
12152 Return zero if the window cannot be found.
12153
12154 Can also be used as a |method|: >
12155 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012156<
12157 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012158
12159
12160win_gettype([{nr}]) *win_gettype()*
12161 Return the type of the window:
12162 "autocmd" autocommand window. Temporary window
12163 used to execute autocommands.
12164 "command" command-line window |cmdwin|
12165 (empty) normal window
12166 "loclist" |location-list-window|
12167 "popup" popup window |popup|
12168 "preview" preview window |preview-window|
12169 "quickfix" |quickfix-window|
12170 "unknown" window {nr} not found
12171
12172 When {nr} is omitted return the type of the current window.
12173 When {nr} is given return the type of this window by number or
12174 |window-ID|.
12175
12176 Also see the 'buftype' option. When running a terminal in a
12177 popup window then 'buftype' is "terminal" and win_gettype()
12178 returns "popup".
12179
12180 Can also be used as a |method|: >
12181 GetWinid()->win_gettype()
12182<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012183 Return type: |String|
12184
12185
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012186win_gotoid({expr}) *win_gotoid()*
12187 Go to window with ID {expr}. This may also change the current
12188 tabpage.
12189 Return TRUE if successful, FALSE if the window cannot be found.
12190
12191 Can also be used as a |method|: >
12192 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012193<
12194 Return type: |Number|
12195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012196
12197win_id2tabwin({expr}) *win_id2tabwin()*
12198 Return a list with the tab number and window number of window
12199 with ID {expr}: [tabnr, winnr].
12200 Return [0, 0] if the window cannot be found.
12201
12202 Can also be used as a |method|: >
12203 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012204<
12205 Return type: list<number>
12206
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012207
12208win_id2win({expr}) *win_id2win()*
12209 Return the window number of window with ID {expr}.
12210 Return 0 if the window cannot be found in the current tabpage.
12211
12212 Can also be used as a |method|: >
12213 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012214<
12215 Return type: |Number|
12216
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012217
Daniel Steinbergee630312022-01-10 13:36:34 +000012218win_move_separator({nr}, {offset}) *win_move_separator()*
12219 Move window {nr}'s vertical separator (i.e., the right border)
12220 by {offset} columns, as if being dragged by the mouse. {nr}
12221 can be a window number or |window-ID|. A positive {offset}
12222 moves right and a negative {offset} moves left. Moving a
12223 window's vertical separator will change the width of the
12224 window and the width of other windows adjacent to the vertical
12225 separator. The magnitude of movement may be smaller than
12226 specified (e.g., as a consequence of maintaining
12227 'winminwidth'). Returns TRUE if the window can be found and
12228 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012229 This will fail for the rightmost window and a full-width
12230 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012231 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012232
12233 Can also be used as a |method|: >
12234 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012235<
12236 Return type: |Number|
12237
Daniel Steinbergee630312022-01-10 13:36:34 +000012238
12239win_move_statusline({nr}, {offset}) *win_move_statusline()*
12240 Move window {nr}'s status line (i.e., the bottom border) by
12241 {offset} rows, as if being dragged by the mouse. {nr} can be a
12242 window number or |window-ID|. A positive {offset} moves down
12243 and a negative {offset} moves up. Moving a window's status
12244 line will change the height of the window and the height of
12245 other windows adjacent to the status line. The magnitude of
12246 movement may be smaller than specified (e.g., as a consequence
12247 of maintaining 'winminheight'). Returns TRUE if the window can
12248 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012249 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012250
12251 Can also be used as a |method|: >
12252 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012253<
12254 Return type: |Number|
12255
Daniel Steinbergee630312022-01-10 13:36:34 +000012256
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012257win_screenpos({nr}) *win_screenpos()*
12258 Return the screen position of window {nr} as a list with two
12259 numbers: [row, col]. The first window always has position
12260 [1, 1], unless there is a tabline, then it is [2, 1].
12261 {nr} can be the window number or the |window-ID|. Use zero
12262 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012263 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012264
12265 Can also be used as a |method|: >
12266 GetWinid()->win_screenpos()
12267<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012268 Return type: list<number>
12269
12270
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012271win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012272 Temporarily switch to window {target}, then move window {nr}
12273 to a new split adjacent to {target}.
12274 Unlike commands such as |:split|, no new windows are created
12275 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012276
12277 Both {nr} and {target} can be window numbers or |window-ID|s.
12278 Both must be in the current tab page.
12279
12280 Returns zero for success, non-zero for failure.
12281
12282 {options} is a |Dictionary| with the following optional entries:
12283 "vertical" When TRUE, the split is created vertically,
12284 like with |:vsplit|.
12285 "rightbelow" When TRUE, the split is made below or to the
12286 right (if vertical). When FALSE, it is done
12287 above or to the left (if vertical). When not
12288 present, the values of 'splitbelow' and
12289 'splitright' are used.
12290
12291 Can also be used as a |method|: >
12292 GetWinid()->win_splitmove(target)
12293<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012294 Return type: |Number|
12295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012296
12297 *winbufnr()*
12298winbufnr({nr}) The result is a Number, which is the number of the buffer
12299 associated with window {nr}. {nr} can be the window number or
12300 the |window-ID|.
12301 When {nr} is zero, the number of the buffer in the current
12302 window is returned.
12303 When window {nr} doesn't exist, -1 is returned.
12304 Example: >
12305 :echo "The file in the current window is " . bufname(winbufnr(0))
12306<
12307 Can also be used as a |method|: >
12308 FindWindow()->winbufnr()->bufname()
12309<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012310 Return type: |Number|
12311
12312
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012313 *wincol()*
12314wincol() The result is a Number, which is the virtual column of the
12315 cursor in the window. This is counting screen cells from the
12316 left side of the window. The leftmost column is one.
12317
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012318 Return type: |Number|
12319
12320
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012321 *windowsversion()*
12322windowsversion()
12323 The result is a String. For MS-Windows it indicates the OS
12324 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12325 Windows XP is "5.1". For non-MS-Windows systems the result is
12326 an empty string.
12327
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012328 Return type: |String|
12329
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012330winheight({nr}) *winheight()*
12331 The result is a Number, which is the height of window {nr}.
12332 {nr} can be the window number or the |window-ID|.
12333 When {nr} is zero, the height of the current window is
12334 returned. When window {nr} doesn't exist, -1 is returned.
12335 An existing window always has a height of zero or more.
12336 This excludes any window toolbar line.
12337 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012338 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012339
12340< Can also be used as a |method|: >
12341 GetWinid()->winheight()
12342<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012343 Return type: |Number|
12344
12345
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012346winlayout([{tabnr}]) *winlayout()*
12347 The result is a nested List containing the layout of windows
12348 in a tabpage.
12349
12350 Without {tabnr} use the current tabpage, otherwise the tabpage
12351 with number {tabnr}. If the tabpage {tabnr} is not found,
12352 returns an empty list.
12353
12354 For a leaf window, it returns:
12355 ['leaf', {winid}]
12356 For horizontally split windows, which form a column, it
12357 returns:
12358 ['col', [{nested list of windows}]]
12359 For vertically split windows, which form a row, it returns:
12360 ['row', [{nested list of windows}]]
12361
12362 Example: >
12363 " Only one window in the tab page
12364 :echo winlayout()
12365 ['leaf', 1000]
12366 " Two horizontally split windows
12367 :echo winlayout()
12368 ['col', [['leaf', 1000], ['leaf', 1001]]]
12369 " The second tab page, with three horizontally split
12370 " windows, with two vertically split windows in the
12371 " middle window
12372 :echo winlayout(2)
12373 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12374 ['leaf', 1001]]], ['leaf', 1000]]]
12375<
12376 Can also be used as a |method|: >
12377 GetTabnr()->winlayout()
12378<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012379 Return type: list<any>
12380
12381
12382winline() *winline()*
12383 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012384 in the window. This is counting screen lines from the top of
12385 the window. The first line is one.
12386 If the cursor was moved the view on the file will be updated
12387 first, this may cause a scroll.
12388
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012389 Return type: |Number|
12390
12391
12392winnr([{arg}]) *winnr()*
12393 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012394 window. The top window has number 1.
12395 Returns zero for a popup window.
12396
12397 The optional argument {arg} supports the following values:
12398 $ the number of the last window (the window
12399 count).
12400 # the number of the last accessed window (where
12401 |CTRL-W_p| goes to). If there is no previous
12402 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012403 returned. May refer to the current window in
12404 some cases (e.g. when evaluating 'statusline'
12405 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012406 {N}j the number of the Nth window below the
12407 current window (where |CTRL-W_j| goes to).
12408 {N}k the number of the Nth window above the current
12409 window (where |CTRL-W_k| goes to).
12410 {N}h the number of the Nth window left of the
12411 current window (where |CTRL-W_h| goes to).
12412 {N}l the number of the Nth window right of the
12413 current window (where |CTRL-W_l| goes to).
12414 The number can be used with |CTRL-W_w| and ":wincmd w"
12415 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012416 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012417 Also see |tabpagewinnr()| and |win_getid()|.
12418 Examples: >
12419 let window_count = winnr('$')
12420 let prev_window = winnr('#')
12421 let wnum = winnr('3k')
12422
12423< Can also be used as a |method|: >
12424 GetWinval()->winnr()
12425<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012426 Return type: |Number|
12427
12428
12429winrestcmd() *winrestcmd()*
12430 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012431 the current window sizes. Only works properly when no windows
12432 are opened or closed and the current window and tab page is
12433 unchanged.
12434 Example: >
12435 :let cmd = winrestcmd()
12436 :call MessWithWindowSizes()
12437 :exe cmd
12438<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012439 Return type: |String|
12440
12441
12442winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012443 Uses the |Dictionary| returned by |winsaveview()| to restore
12444 the view of the current window.
12445 Note: The {dict} does not have to contain all values, that are
12446 returned by |winsaveview()|. If values are missing, those
12447 settings won't be restored. So you can use: >
12448 :call winrestview({'curswant': 4})
12449<
12450 This will only set the curswant value (the column the cursor
12451 wants to move on vertical movements) of the cursor to column 5
12452 (yes, that is 5), while all other settings will remain the
12453 same. This is useful, if you set the cursor position manually.
12454
12455 If you have changed the values the result is unpredictable.
12456 If the window size changed the result won't be the same.
12457
12458 Can also be used as a |method|: >
12459 GetView()->winrestview()
12460<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012461 Return type: |Number|
12462
12463
12464winsaveview() *winsaveview()*
12465 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012466 the view of the current window. Use |winrestview()| to
12467 restore the view.
12468 This is useful if you have a mapping that jumps around in the
12469 buffer and you want to go back to the original view.
12470 This does not save fold information. Use the 'foldenable'
12471 option to temporarily switch off folding, so that folds are
12472 not opened when moving around. This may have side effects.
12473 The return value includes:
12474 lnum cursor line number
12475 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012476 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012477 returns)
12478 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012479 curswant column for vertical movement (Note:
12480 the first column is zero, as opposed
12481 to what |getcurpos()| returns). After
12482 |$| command it will be a very large
12483 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012484 topline first line in the window
12485 topfill filler lines, only in diff mode
12486 leftcol first column displayed; only used when
12487 'wrap' is off
12488 skipcol columns skipped
12489 Note that no option values are saved.
12490
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012491 Return type: dict<number>
12492
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012493
12494winwidth({nr}) *winwidth()*
12495 The result is a Number, which is the width of window {nr}.
12496 {nr} can be the window number or the |window-ID|.
12497 When {nr} is zero, the width of the current window is
12498 returned. When window {nr} doesn't exist, -1 is returned.
12499 An existing window always has a width of zero or more.
12500 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012501 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012502 :if winwidth(0) <= 50
12503 : 50 wincmd |
12504 :endif
12505< For getting the terminal or screen size, see the 'columns'
12506 option.
12507
12508 Can also be used as a |method|: >
12509 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012510<
12511 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012512
12513
12514wordcount() *wordcount()*
12515 The result is a dictionary of byte/chars/word statistics for
12516 the current buffer. This is the same info as provided by
12517 |g_CTRL-G|
12518 The return value includes:
12519 bytes Number of bytes in the buffer
12520 chars Number of chars in the buffer
12521 words Number of words in the buffer
12522 cursor_bytes Number of bytes before cursor position
12523 (not in Visual mode)
12524 cursor_chars Number of chars before cursor position
12525 (not in Visual mode)
12526 cursor_words Number of words before cursor position
12527 (not in Visual mode)
12528 visual_bytes Number of bytes visually selected
12529 (only in Visual mode)
12530 visual_chars Number of chars visually selected
12531 (only in Visual mode)
12532 visual_words Number of words visually selected
12533 (only in Visual mode)
12534
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012535 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012536
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012537
12538writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012539 When {object} is a |List| write it to file {fname}. Each list
12540 item is separated with a NL. Each list item must be a String
12541 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012542 All NL characters are replaced with a NUL character.
12543 Inserting CR characters needs to be done before passing {list}
12544 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012545
12546 When {object} is a |Blob| write the bytes to file {fname}
12547 unmodified, also when binary mode is not specified.
12548
12549 {flags} must be a String. These characters are recognized:
12550
12551 'b' Binary mode is used: There will not be a NL after the
12552 last list item. An empty item at the end does cause the
12553 last line in the file to end in a NL.
12554
12555 'a' Append mode is used, lines are appended to the file: >
12556 :call writefile(["foo"], "event.log", "a")
12557 :call writefile(["bar"], "event.log", "a")
12558<
12559 'D' Delete the file when the current function ends. This
12560 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012561 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012562< Fails when not in a function. Also see |:defer|.
12563
12564 's' fsync() is called after writing the file. This flushes
12565 the file to disk, if possible. This takes more time but
12566 avoids losing the file if the system crashes.
12567
12568 'S' fsync() is not called, even when 'fsync' is set.
12569
12570 When {flags} does not contain "S" or "s" then fsync() is
12571 called if the 'fsync' option is set.
12572
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012573 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012574
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012575 When the write fails -1 is returned, otherwise 0. There is an
12576 error message if the file can't be created or when writing
12577 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012578
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012579 Also see |readfile()|.
12580 To copy a file byte for byte: >
12581 :let fl = readfile("foo", "b")
12582 :call writefile(fl, "foocopy", "b")
12583
12584< Can also be used as a |method|: >
12585 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012586<
12587 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012588
12589
12590xor({expr}, {expr}) *xor()*
12591 Bitwise XOR on the two arguments. The arguments are converted
12592 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012593 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012594 Example: >
12595 :let bits = xor(bits, 0x80)
12596<
12597 Can also be used as a |method|: >
12598 :let bits = bits->xor(0x80)
12599<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012600 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012601
12602==============================================================================
126033. Feature list *feature-list*
12604
12605There are three types of features:
126061. Features that are only supported when they have been enabled when Vim
12607 was compiled |+feature-list|. Example: >
12608 :if has("cindent")
12609< *gui_running*
126102. Features that are only supported when certain conditions have been met.
12611 Example: >
12612 :if has("gui_running")
12613< *has-patch*
126143. Beyond a certain version or at a certain version and including a specific
12615 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12616 later, or it is version 7.4 and patch 248 was included. Example: >
12617 :if has("patch-7.4.248")
12618< Note that it's possible for patch 248 to be omitted even though 249 is
12619 included. Only happens when cherry-picking patches.
12620 Note that this form only works for patch 7.4.237 and later, before that
12621 you need to check for the patch and the v:version. Example (checking
12622 version 6.2.148 or later): >
12623 :if v:version > 602 || (v:version == 602 && has("patch148"))
12624
12625Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12626use: `if exists('+shellslash')`
12627
12628
12629acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012630all_builtin_terms Compiled with all builtin terminals enabled. (always
12631 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012632amiga Amiga version of Vim.
12633arabic Compiled with Arabic support |Arabic|.
12634arp Compiled with ARP support (Amiga).
12635autocmd Compiled with autocommand support. (always true)
12636autochdir Compiled with support for 'autochdir'
12637autoservername Automatically enable |clientserver|
12638balloon_eval Compiled with |balloon-eval| support.
12639balloon_multiline GUI supports multiline balloons.
12640beos BeOS version of Vim.
12641browse Compiled with |:browse| support, and browse() will
12642 work.
12643browsefilter Compiled with support for |browsefilter|.
12644bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012645builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012646byte_offset Compiled with support for 'o' in 'statusline'
12647channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012648cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012649clientserver Compiled with remote invocation support |clientserver|.
12650clipboard Compiled with 'clipboard' support.
12651clipboard_working Compiled with 'clipboard' support and it can be used.
12652cmdline_compl Compiled with |cmdline-completion| support.
12653cmdline_hist Compiled with |cmdline-history| support.
12654cmdline_info Compiled with 'showcmd' and 'ruler' support.
12655comments Compiled with |'comments'| support.
12656compatible Compiled to be very Vi compatible.
12657conpty Platform where |ConPTY| can be used.
12658cryptv Compiled with encryption support |encryption|.
12659cscope Compiled with |cscope| support.
12660cursorbind Compiled with |'cursorbind'| (always true)
12661debug Compiled with "DEBUG" defined.
12662dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012663dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012664dialog_gui Compiled with GUI dialog support.
12665diff Compiled with |vimdiff| and 'diff' support.
12666digraphs Compiled with support for digraphs.
12667directx Compiled with support for DirectX and 'renderoptions'.
12668dnd Compiled with support for the "~ register |quote_~|.
12669drop_file Compiled with |drop_file| support.
12670ebcdic Compiled on a machine with ebcdic character set.
12671emacs_tags Compiled with support for Emacs tags.
12672eval Compiled with expression evaluation support. Always
12673 true, of course!
12674ex_extra |+ex_extra| (always true)
12675extra_search Compiled with support for |'incsearch'| and
12676 |'hlsearch'|
12677farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012678file_in_path Compiled with support for |gf| and |<cfile>| (always
12679 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012680filterpipe When 'shelltemp' is off pipes are used for shell
12681 read/write/filter commands
12682find_in_path Compiled with support for include file searches
12683 |+find_in_path|.
12684float Compiled with support for |Float|.
12685fname_case Case in file names matters (for Amiga and MS-Windows
12686 this is not present).
12687folding Compiled with |folding| support.
12688footer Compiled with GUI footer support. |gui-footer|
12689fork Compiled to use fork()/exec() instead of system().
12690gettext Compiled with message translation |multi-lang|
12691gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012692gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012693gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12694gui_gtk Compiled with GTK+ GUI (any version).
12695gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12696gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12697gui_haiku Compiled with Haiku GUI.
12698gui_mac Compiled with Macintosh GUI.
12699gui_motif Compiled with Motif GUI.
12700gui_photon Compiled with Photon GUI.
12701gui_running Vim is running in the GUI, or it will start soon.
12702gui_win32 Compiled with MS-Windows Win32 GUI.
12703gui_win32s idem, and Win32s system being used (Windows 3.1)
12704haiku Haiku version of Vim.
12705hangul_input Compiled with Hangul input support. |hangul|
12706hpux HP-UX version of Vim.
12707iconv Can use iconv() for conversion.
12708insert_expand Compiled with support for CTRL-X expansion commands in
12709 Insert mode. (always true)
12710job Compiled with support for |channel| and |job|
12711ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012712jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012713keymap Compiled with 'keymap' support.
12714lambda Compiled with |lambda| support.
12715langmap Compiled with 'langmap' support.
12716libcall Compiled with |libcall()| support.
12717linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12718 'breakindent' support.
12719linux Linux version of Vim.
12720lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012721 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012722listcmds Compiled with commands for the buffer list |:files|
12723 and the argument list |arglist|.
12724localmap Compiled with local mappings and abbr. |:map-local|
12725lua Compiled with Lua interface |Lua|.
12726mac Any Macintosh version of Vim cf. osx
12727macunix Synonym for osxdarwin
12728menu Compiled with support for |:menu|.
12729mksession Compiled with support for |:mksession|.
12730modify_fname Compiled with file name modifiers. |filename-modifiers|
12731 (always true)
12732mouse Compiled with support for mouse.
12733mouse_dec Compiled with support for Dec terminal mouse.
12734mouse_gpm Compiled with support for gpm (Linux console mouse)
12735mouse_gpm_enabled GPM mouse is working
12736mouse_netterm Compiled with support for netterm mouse.
12737mouse_pterm Compiled with support for qnx pterm mouse.
12738mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12739mouse_sgr Compiled with support for sgr mouse.
12740mouse_urxvt Compiled with support for urxvt mouse.
12741mouse_xterm Compiled with support for xterm mouse.
12742mouseshape Compiled with support for 'mouseshape'.
12743multi_byte Compiled with support for 'encoding' (always true)
12744multi_byte_encoding 'encoding' is set to a multibyte encoding.
12745multi_byte_ime Compiled with support for IME input method.
12746multi_lang Compiled with support for multiple languages.
12747mzscheme Compiled with MzScheme interface |mzscheme|.
12748nanotime Compiled with sub-second time stamp checks.
12749netbeans_enabled Compiled with support for |netbeans| and connected.
12750netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012751num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012752ole Compiled with OLE automation support for Win32.
12753osx Compiled for macOS cf. mac
12754osxdarwin Compiled for macOS, with |mac-darwin-feature|
12755packages Compiled with |packages| support.
12756path_extra Compiled with up/downwards search in 'path' and 'tags'
12757perl Compiled with Perl interface.
12758persistent_undo Compiled with support for persistent undo history.
12759postscript Compiled with PostScript file printing.
12760printer Compiled with |:hardcopy| support.
12761profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012762prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012763python Python 2.x interface available. |has-python|
12764python_compiled Compiled with Python 2.x interface. |has-python|
12765python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12766python3 Python 3.x interface available. |has-python|
12767python3_compiled Compiled with Python 3.x interface. |has-python|
12768python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012769python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012770pythonx Python 2.x and/or 3.x interface available. |python_x|
12771qnx QNX version of Vim.
12772quickfix Compiled with |quickfix| support.
12773reltime Compiled with |reltime()| support.
12774rightleft Compiled with 'rightleft' support.
12775ruby Compiled with Ruby interface |ruby|.
12776scrollbind Compiled with 'scrollbind' support. (always true)
12777showcmd Compiled with 'showcmd' support.
12778signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012779smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012780sodium Compiled with libsodium for better crypt support
12781sound Compiled with sound support, e.g. `sound_playevent()`
12782spell Compiled with spell checking support |spell|.
12783startuptime Compiled with |--startuptime| support.
12784statusline Compiled with support for 'statusline', 'rulerformat'
12785 and special formats of 'titlestring' and 'iconstring'.
12786sun SunOS version of Vim.
12787sun_workshop Support for Sun |workshop| has been removed.
12788syntax Compiled with syntax highlighting support |syntax|.
12789syntax_items There are active syntax highlighting items for the
12790 current buffer.
12791system Compiled to use system() instead of fork()/exec().
12792tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012793 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012794tag_old_static Support for old static tags was removed, see
12795 |tag-old-static|.
12796tcl Compiled with Tcl interface.
12797termguicolors Compiled with true color in terminal support.
12798terminal Compiled with |terminal| support.
12799terminfo Compiled with terminfo instead of termcap.
12800termresponse Compiled with support for |t_RV| and |v:termresponse|.
12801textobjects Compiled with support for |text-objects|.
12802textprop Compiled with support for |text-properties|.
12803tgetent Compiled with tgetent support, able to use a termcap
12804 or terminfo file.
12805timers Compiled with |timer_start()| support.
12806title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012807 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012808toolbar Compiled with support for |gui-toolbar|.
12809ttyin input is a terminal (tty)
12810ttyout output is a terminal (tty)
12811unix Unix version of Vim. *+unix*
12812unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12813user_commands User-defined commands. (always true)
12814vartabs Compiled with variable tabstop support |'vartabstop'|.
12815vcon Win32: Virtual console support is working, can use
12816 'termguicolors'. Also see |+vtp|.
12817vertsplit Compiled with vertically split windows |:vsplit|.
12818 (always true)
12819vim_starting True while initial source'ing takes place. |startup|
12820 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012821vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012822viminfo Compiled with viminfo support.
12823vimscript-1 Compiled Vim script version 1 support
12824vimscript-2 Compiled Vim script version 2 support
12825vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012826vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012827virtualedit Compiled with 'virtualedit' option. (always true)
12828visual Compiled with Visual mode. (always true)
12829visualextra Compiled with extra Visual mode commands. (always
12830 true) |blockwise-operators|.
12831vms VMS version of Vim.
12832vreplace Compiled with |gR| and |gr| commands. (always true)
12833vtp Compiled for vcon support |+vtp| (check vcon to find
12834 out if it works in the current console).
12835wildignore Compiled with 'wildignore' option.
12836wildmenu Compiled with 'wildmenu' option.
12837win16 old version for MS-Windows 3.1 (always false)
12838win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12839 64 bits)
12840win32unix Win32 version of Vim, using Unix files (Cygwin)
12841win64 Win64 version of Vim (MS-Windows 64 bit).
12842win95 Win32 version for MS-Windows 95/98/ME (always false)
12843winaltkeys Compiled with 'winaltkeys' option.
12844windows Compiled with support for more than one window.
12845 (always true)
12846writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012847xattr Compiled with extended attributes support |xattr|
12848 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012849xfontset Compiled with X fontset support |xfontset|.
12850xim Compiled with X input method support |xim|.
12851xpm Compiled with pixmap support.
12852xpm_w32 Compiled with pixmap support for Win32. (Only for
12853 backward compatibility. Use "xpm" instead.)
12854xsmp Compiled with X session management support.
12855xsmp_interact Compiled with interactive X session management support.
12856xterm_clipboard Compiled with support for xterm clipboard.
12857xterm_save Compiled with support for saving and restoring the
12858 xterm screen.
12859x11 Compiled with X11 support.
12860
12861
12862==============================================================================
128634. Matching a pattern in a String *string-match*
12864
12865This is common between several functions. A regexp pattern as explained at
12866|pattern| is normally used to find a match in the buffer lines. When a
12867pattern is used to find a match in a String, almost everything works in the
12868same way. The difference is that a String is handled like it is one line.
12869When it contains a "\n" character, this is not seen as a line break for the
12870pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12871>
12872 :let a = "aaaa\nxxxx"
12873 :echo matchstr(a, "..\n..")
12874 aa
12875 xx
12876 :echo matchstr(a, "a.x")
12877 a
12878 x
12879
12880Don't forget that "^" will only match at the first character of the String and
12881"$" at the last character of the string. They don't match after or before a
12882"\n".
12883
12884 vim:tw=78:ts=8:noet:ft=help:norl: