blob: 9d56f5082231519b0da95e95dc26f6dce6418bed [file] [log] [blame]
glepnir037b0282025-01-16 14:37:44 +01001*builtin.txt* For Vim version 9.1. Last change: 2025 Jan 16
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Builtin functions *builtin-functions*
8
Bram Moolenaarf269eab2022-10-03 18:04:35 +01009Note: Expression evaluation can be disabled at compile time, the builtin
10functions are not available then. See |+eval| and |no-eval-feature|.
11
12For functions grouped by what they are used for see |function-list|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000013
141. Overview |builtin-function-list|
152. Details |builtin-function-details|
163. Feature list |feature-list|
174. Matching a pattern in a String |string-match|
18
19==============================================================================
201. Overview *builtin-function-list*
21
22Use CTRL-] on the function name to jump to the full explanation.
23
24USAGE RESULT DESCRIPTION ~
25
26abs({expr}) Float or Number absolute value of {expr}
27acos({expr}) Float arc cosine of {expr}
28add({object}, {item}) List/Blob append {item} to {object}
29and({expr}, {expr}) Number bitwise AND
30append({lnum}, {text}) Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070031appendbufline({buf}, {lnum}, {text})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000032 Number append {text} below line {lnum}
erraelf0837ba2024-06-24 12:27:01 -070033 in buffer {buf}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000034argc([{winid}]) Number number of files in the argument list
35argidx() Number current index in the argument list
36arglistid([{winnr} [, {tabnr}]]) Number argument list id
37argv({nr} [, {winid}]) String {nr} entry of the argument list
38argv([-1, {winid}]) List the argument list
39asin({expr}) Float arc sine of {expr}
40assert_beeps({cmd}) Number assert {cmd} causes a beep
41assert_equal({exp}, {act} [, {msg}])
42 Number assert {exp} is equal to {act}
43assert_equalfile({fname-one}, {fname-two} [, {msg}])
44 Number assert file contents are equal
45assert_exception({error} [, {msg}])
46 Number assert {error} is in v:exception
47assert_fails({cmd} [, {error} [, {msg} [, {lnum} [, {context}]]]])
48 Number assert {cmd} fails
49assert_false({actual} [, {msg}])
50 Number assert {actual} is false
51assert_inrange({lower}, {upper}, {actual} [, {msg}])
52 Number assert {actual} is inside the range
53assert_match({pat}, {text} [, {msg}])
54 Number assert {pat} matches {text}
55assert_nobeep({cmd}) Number assert {cmd} does not cause a beep
56assert_notequal({exp}, {act} [, {msg}])
57 Number assert {exp} is not equal {act}
58assert_notmatch({pat}, {text} [, {msg}])
59 Number assert {pat} not matches {text}
60assert_report({msg}) Number report a test failure
61assert_true({actual} [, {msg}]) Number assert {actual} is true
62atan({expr}) Float arc tangent of {expr}
63atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
Yegappan Lakshmanan1755a912022-05-19 10:31:47 +010064autocmd_add({acmds}) Bool add a list of autocmds and groups
65autocmd_delete({acmds}) Bool delete a list of autocmds and groups
66autocmd_get([{opts}]) List return a list of autocmds
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000067balloon_gettext() String current text in the balloon
68balloon_show({expr}) none show {expr} inside the balloon
69balloon_split({msg}) List split {msg} as used for a balloon
h-easte80f3452025-01-02 10:40:29 +010070base64_decode({string}) Blob base64 decode {string} characters
71base64_encode({blob}) String base64 encode the bytes in {blob}
Christ van Willegence0ef912024-06-20 23:41:59 +020072bindtextdomain({package}, {path})
Christ van Willegen8252ef12024-07-11 21:36:21 +020073 Bool bind text domain to specified path
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000074blob2list({blob}) List convert {blob} into a list of numbers
Yegappan 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
Maxim Kim6472e582025-01-15 18:31:05 +01001247 echo blob2str(base64_decode(encodedstr))
h-easte80f3452025-01-02 10:40:29 +01001248<
1249 Can also be used as a |method|: >
1250 GetEncodedString()->base64_decode()
1251<
1252 Return type: |Blob|
1253
1254
1255base64_encode({blob}) *base64_encode()*
1256 Return a base64-encoded String representing the bytes in
1257 {blob}. The base64 alphabet defined in RFC 4648 is used.
1258
1259 Examples: >
1260 " Encode the contents of a binary file
1261 echo base64_encode(readblob('somefile.bin'))
1262 " Encode a string
Maxim Kim6472e582025-01-15 18:31:05 +01001263 echo base64_encode(str2blob(somestr))
h-easte80f3452025-01-02 10:40:29 +01001264<
1265 Can also be used as a |method|: >
1266 GetBinaryData()->base64_encode()
1267<
1268 Return type: |String|
1269
1270
Christ van Willegence0ef912024-06-20 23:41:59 +02001271bindtextdomain({package}, {path}) *bindtextdomain()*
1272 Bind a specific {package} to a {path} so that the
1273 |gettext()| function can be used to get language-specific
1274 translations for a package. {path} is the directory name
h-east52e7cc22024-07-28 17:03:29 +02001275 for the translations. See |package-translation|.
Christ van Willegence0ef912024-06-20 23:41:59 +02001276
Christ van Willegen8252ef12024-07-11 21:36:21 +02001277 Returns v:true on success and v:false on failure (out of
1278 memory).
1279
1280 Return type: |vim9-boolean|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001281
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001282blob2list({blob}) *blob2list()*
1283 Return a List containing the number value of each byte in Blob
1284 {blob}. Examples: >
1285 blob2list(0z0102.0304) returns [1, 2, 3, 4]
1286 blob2list(0z) returns []
1287< Returns an empty List on error. |list2blob()| does the
1288 opposite.
1289
1290 Can also be used as a |method|: >
1291 GetBlob()->blob2list()
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01001292<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001293 Return type: list<any> or list<number>
1294
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +01001295
1296blob2str({blob} [, {options}]) *blob2str()*
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)
glepnir037b0282025-01-16 14:37:44 +01001949 completed Return a dictionary containing the entries of
1950 the currently selected index item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001951
1952 *complete_info_mode*
1953 mode values are:
1954 "" Not in completion mode
1955 "keyword" Keyword completion |i_CTRL-X_CTRL-N|
1956 "ctrl_x" Just pressed CTRL-X |i_CTRL-X|
1957 "scroll" Scrolling with |i_CTRL-X_CTRL-E| or
1958 |i_CTRL-X_CTRL-Y|
1959 "whole_line" Whole lines |i_CTRL-X_CTRL-L|
1960 "files" File names |i_CTRL-X_CTRL-F|
1961 "tags" Tags |i_CTRL-X_CTRL-]|
1962 "path_defines" Definition completion |i_CTRL-X_CTRL-D|
1963 "path_patterns" Include completion |i_CTRL-X_CTRL-I|
1964 "dictionary" Dictionary |i_CTRL-X_CTRL-K|
1965 "thesaurus" Thesaurus |i_CTRL-X_CTRL-T|
1966 "cmdline" Vim Command line |i_CTRL-X_CTRL-V|
1967 "function" User defined completion |i_CTRL-X_CTRL-U|
1968 "omni" Omni completion |i_CTRL-X_CTRL-O|
1969 "spell" Spelling suggestions |i_CTRL-X_s|
1970 "eval" |complete()| completion
1971 "unknown" Other internal modes
1972
1973 If the optional {what} list argument is supplied, then only
1974 the items listed in {what} are returned. Unsupported items in
1975 {what} are silently ignored.
1976
1977 To get the position and size of the popup menu, see
1978 |pum_getpos()|. It's also available in |v:event| during the
1979 |CompleteChanged| event.
1980
Bram Moolenaar016188f2022-06-06 20:52:59 +01001981 Returns an empty |Dictionary| on error.
1982
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001983 Examples: >
1984 " Get all items
1985 call complete_info()
1986 " Get only 'mode'
1987 call complete_info(['mode'])
1988 " Get only 'mode' and 'pum_visible'
1989 call complete_info(['mode', 'pum_visible'])
1990
1991< Can also be used as a |method|: >
1992 GetItems()->complete_info()
1993<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02001994 Return type: dict<any>
1995
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00001996 *confirm()*
1997confirm({msg} [, {choices} [, {default} [, {type}]]])
1998 confirm() offers the user a dialog, from which a choice can be
1999 made. It returns the number of the choice. For the first
2000 choice this is 1.
2001 Note: confirm() is only supported when compiled with dialog
glepnirdf461152024-04-04 22:23:29 +02002002 support, see |+dialog_con| |+dialog_con_gui| and |+dialog_gui|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002003
2004 {msg} is displayed in a |dialog| with {choices} as the
2005 alternatives. When {choices} is missing or empty, "&OK" is
2006 used (and translated).
2007 {msg} is a String, use '\n' to include a newline. Only on
2008 some systems the string is wrapped when it doesn't fit.
2009
2010 {choices} is a String, with the individual choices separated
2011 by '\n', e.g. >
2012 confirm("Save changes?", "&Yes\n&No\n&Cancel")
2013< The letter after the '&' is the shortcut key for that choice.
2014 Thus you can type 'c' to select "Cancel". The shortcut does
2015 not need to be the first letter: >
2016 confirm("file has been modified", "&Save\nSave &All")
2017< For the console, the first letter of each choice is used as
2018 the default shortcut key. Case is ignored.
2019
2020 The optional {default} argument is the number of the choice
2021 that is made if the user hits <CR>. Use 1 to make the first
2022 choice the default one. Use 0 to not set a default. If
2023 {default} is omitted, 1 is used.
2024
2025 The optional {type} String argument gives the type of dialog.
2026 This is only used for the icon of the GTK, Mac, Motif and
2027 Win32 GUI. It can be one of these values: "Error",
2028 "Question", "Info", "Warning" or "Generic". Only the first
2029 character is relevant. When {type} is omitted, "Generic" is
2030 used.
2031
2032 If the user aborts the dialog by pressing <Esc>, CTRL-C,
2033 or another valid interrupt key, confirm() returns 0.
2034
2035 An example: >
Bram Moolenaar46eea442022-03-30 10:51:39 +01002036 let choice = confirm("What do you want?",
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002037 \ "&Apples\n&Oranges\n&Bananas", 2)
Bram Moolenaar46eea442022-03-30 10:51:39 +01002038 if choice == 0
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002039 echo "make up your mind!"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002040 elseif choice == 3
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002041 echo "tasteful"
Bram Moolenaar46eea442022-03-30 10:51:39 +01002042 else
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002043 echo "I prefer bananas myself."
Bram Moolenaar46eea442022-03-30 10:51:39 +01002044 endif
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002045< In a GUI dialog, buttons are used. The layout of the buttons
2046 depends on the 'v' flag in 'guioptions'. If it is included,
2047 the buttons are always put vertically. Otherwise, confirm()
2048 tries to put the buttons in one horizontal line. If they
2049 don't fit, a vertical layout is used anyway. For some systems
2050 the horizontal layout is always used.
2051
2052 Can also be used as a |method|in: >
2053 BuildMessage()->confirm("&Yes\n&No")
2054<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002055 Return type: |Number|
2056
2057
2058copy({expr}) *copy()*
2059 Make a copy of {expr}. For Numbers and Strings this isn't
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002060 different from using {expr} directly.
2061 When {expr} is a |List| a shallow copy is created. This means
2062 that the original |List| can be changed without changing the
2063 copy, and vice versa. But the items are identical, thus
2064 changing an item changes the contents of both |Lists|.
2065 A |Dictionary| is copied in a similar way as a |List|.
2066 Also see |deepcopy()|.
2067 Can also be used as a |method|: >
2068 mylist->copy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002069<
2070 Return type: any, depending on {expr}
2071
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002072
2073cos({expr}) *cos()*
2074 Return the cosine of {expr}, measured in radians, as a |Float|.
2075 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002076 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002077 Examples: >
2078 :echo cos(100)
2079< 0.862319 >
2080 :echo cos(-4.01)
2081< -0.646043
2082
2083 Can also be used as a |method|: >
2084 Compute()->cos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002085<
2086 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002087
2088
2089cosh({expr}) *cosh()*
2090 Return the hyperbolic cosine of {expr} as a |Float| in the range
2091 [1, inf].
2092 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002093 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002094 Examples: >
2095 :echo cosh(0.5)
2096< 1.127626 >
2097 :echo cosh(-0.5)
2098< -1.127626
2099
2100 Can also be used as a |method|: >
2101 Compute()->cosh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002102<
2103 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002104
2105
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07002106count({comp}, {expr} [, {ic} [, {start}]]) *count()* *E706*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002107 Return the number of times an item with value {expr} appears
2108 in |String|, |List| or |Dictionary| {comp}.
2109
2110 If {start} is given then start with the item with this index.
2111 {start} can only be used with a |List|.
2112
2113 When {ic} is given and it's |TRUE| then case is ignored.
2114
2115 When {comp} is a string then the number of not overlapping
2116 occurrences of {expr} is returned. Zero is returned when
2117 {expr} is an empty string.
2118
2119 Can also be used as a |method|: >
2120 mylist->count(val)
2121<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002122 Return type: |Number|
2123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002124 *cscope_connection()*
2125cscope_connection([{num} , {dbpath} [, {prepend}]])
2126 Checks for the existence of a |cscope| connection. If no
2127 parameters are specified, then the function returns:
2128 0, if cscope was not available (not compiled in), or
2129 if there are no cscope connections;
2130 1, if there is at least one cscope connection.
2131
2132 If parameters are specified, then the value of {num}
2133 determines how existence of a cscope connection is checked:
2134
2135 {num} Description of existence check
2136 ----- ------------------------------
2137 0 Same as no parameters (e.g., "cscope_connection()").
2138 1 Ignore {prepend}, and use partial string matches for
2139 {dbpath}.
2140 2 Ignore {prepend}, and use exact string matches for
2141 {dbpath}.
2142 3 Use {prepend}, use partial string matches for both
2143 {dbpath} and {prepend}.
2144 4 Use {prepend}, use exact string matches for both
2145 {dbpath} and {prepend}.
2146
2147 Note: All string comparisons are case sensitive!
2148
2149 Examples. Suppose we had the following (from ":cs show"): >
2150
2151 # pid database name prepend path
2152 0 27664 cscope.out /usr/local
2153<
2154 Invocation Return Val ~
2155 ---------- ---------- >
2156 cscope_connection() 1
2157 cscope_connection(1, "out") 1
2158 cscope_connection(2, "out") 0
2159 cscope_connection(3, "out") 0
2160 cscope_connection(3, "out", "local") 1
2161 cscope_connection(4, "out") 0
2162 cscope_connection(4, "out", "local") 0
2163 cscope_connection(4, "cscope.out", "/usr/local") 1
2164<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002165 Return type: |Number|
2166
2167
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002168cursor({lnum}, {col} [, {off}]) *cursor()*
2169cursor({list})
2170 Positions the cursor at the column (byte count) {col} in the
2171 line {lnum}. The first column is one.
2172
2173 When there is one argument {list} this is used as a |List|
2174 with two, three or four item:
2175 [{lnum}, {col}]
2176 [{lnum}, {col}, {off}]
2177 [{lnum}, {col}, {off}, {curswant}]
2178 This is like the return value of |getpos()| or |getcurpos()|,
2179 but without the first item.
2180
Bram Moolenaar10e8ff92023-06-10 21:40:39 +01002181 To position the cursor using {col} as the character count, use
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002182 |setcursorcharpos()|.
2183
2184 Does not change the jumplist.
Bram Moolenaar7c6cd442022-10-11 21:54:04 +01002185 {lnum} is used like with |getline()|, except that if {lnum} is
2186 zero, the cursor will stay in the current line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002187 If {lnum} is greater than the number of lines in the buffer,
2188 the cursor will be positioned at the last line in the buffer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002189 If {col} is greater than the number of bytes in the line,
2190 the cursor will be positioned at the last character in the
2191 line.
2192 If {col} is zero, the cursor will stay in the current column.
2193 If {curswant} is given it is used to set the preferred column
2194 for vertical movement. Otherwise {col} is used.
2195
2196 When 'virtualedit' is used {off} specifies the offset in
2197 screen columns from the start of the character. E.g., a
2198 position within a <Tab> or after the last character.
2199 Returns 0 when the position could be set, -1 otherwise.
2200
2201 Can also be used as a |method|: >
2202 GetCursorPos()->cursor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002203<
2204 Return type: |Number|
2205
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002206
2207debugbreak({pid}) *debugbreak()*
2208 Specifically used to interrupt a program being debugged. It
2209 will cause process {pid} to get a SIGTRAP. Behavior for other
2210 processes is undefined. See |terminal-debugger|.
2211 {only available on MS-Windows}
2212
Bram Moolenaar016188f2022-06-06 20:52:59 +01002213 Returns |TRUE| if successfully interrupted the program.
2214 Otherwise returns |FALSE|.
2215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002216 Can also be used as a |method|: >
2217 GetPid()->debugbreak()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002218<
2219 Return type: |Number|
2220
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002221
2222deepcopy({expr} [, {noref}]) *deepcopy()* *E698*
2223 Make a copy of {expr}. For Numbers and Strings this isn't
2224 different from using {expr} directly.
2225 When {expr} is a |List| a full copy is created. This means
2226 that the original |List| can be changed without changing the
2227 copy, and vice versa. When an item is a |List| or
2228 |Dictionary|, a copy for it is made, recursively. Thus
2229 changing an item in the copy does not change the contents of
2230 the original |List|.
2231 A |Dictionary| is copied in a similar way as a |List|.
2232
2233 When {noref} is omitted or zero a contained |List| or
2234 |Dictionary| is only copied once. All references point to
2235 this single copy. With {noref} set to 1 every occurrence of a
2236 |List| or |Dictionary| results in a new copy. This also means
2237 that a cyclic reference causes deepcopy() to fail.
2238 *E724*
2239 Nesting is possible up to 100 levels. When there is an item
2240 that refers back to a higher level making a deep copy with
2241 {noref} set to 1 will fail.
2242 Also see |copy()|.
2243
2244 Can also be used as a |method|: >
2245 GetObject()->deepcopy()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002246<
2247 Return type: any, depending on {expr}
2248
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002249
2250delete({fname} [, {flags}]) *delete()*
2251 Without {flags} or with {flags} empty: Deletes the file by the
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01002252 name {fname}.
2253
2254 This also works when {fname} is a symbolic link. The symbolic
2255 link itself is deleted, not what it points to.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002256
2257 When {flags} is "d": Deletes the directory by the name
2258 {fname}. This fails when directory {fname} is not empty.
2259
2260 When {flags} is "rf": Deletes the directory by the name
2261 {fname} and everything in it, recursively. BE CAREFUL!
2262 Note: on MS-Windows it is not possible to delete a directory
2263 that is being used.
2264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002265 The result is a Number, which is 0/false if the delete
2266 operation was successful and -1/true when the deletion failed
2267 or partly failed.
2268
2269 Use |remove()| to delete an item from a |List|.
2270 To delete a line from the buffer use |:delete| or
2271 |deletebufline()|.
2272
2273 Can also be used as a |method|: >
2274 GetName()->delete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002275<
2276 Return type: |Number|
2277
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002278
2279deletebufline({buf}, {first} [, {last}]) *deletebufline()*
2280 Delete lines {first} to {last} (inclusive) from buffer {buf}.
2281 If {last} is omitted then delete line {first} only.
2282 On success 0 is returned, on failure 1 is returned.
2283
2284 This function works only for loaded buffers. First call
2285 |bufload()| if needed.
2286
2287 For the use of {buf}, see |bufname()| above.
2288
2289 {first} and {last} are used like with |getline()|. Note that
2290 when using |line()| this refers to the current buffer. Use "$"
2291 to refer to the last line in buffer {buf}.
2292
2293 Can also be used as a |method|: >
2294 GetBuffer()->deletebufline(1)
2295<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002296 Return type: |Number|
2297
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002298 *did_filetype()*
2299did_filetype() Returns |TRUE| when autocommands are being executed and the
2300 FileType event has been triggered at least once. Can be used
2301 to avoid triggering the FileType event again in the scripts
2302 that detect the file type. |FileType|
2303 Returns |FALSE| when `:setf FALLBACK` was used.
2304 When editing another file, the counter is reset, thus this
2305 really checks if the FileType event has been triggered for the
2306 current buffer. This allows an autocommand that starts
2307 editing another buffer to set 'filetype' and load a syntax
2308 file.
2309
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002310 Return type: |Number|
2311
2312
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002313diff({fromlist}, {tolist} [, {options}]) *diff()*
2314 Returns a String or a List containing the diff between the
2315 strings in {fromlist} and {tolist}. Uses the Vim internal
2316 diff library to compute the diff.
2317
2318 *E106*
2319 The optional "output" item in {options} specifies the returned
2320 diff format. The following values are supported:
2321 indices Return a List of the starting and ending
2322 indices and a count of the strings in each
2323 diff hunk.
2324 unified Return the unified diff output as a String.
2325 This is the default.
2326
2327 If the "output" item in {options} is "indices", then a List is
2328 returned. Each List item contains a Dict with the following
2329 items for each diff hunk:
2330 from_idx start index in {fromlist} for this diff hunk.
2331 from_count number of strings in {fromlist} that are
2332 added/removed/modified in this diff hunk.
2333 to_idx start index in {tolist} for this diff hunk.
2334 to_count number of strings in {tolist} that are
2335 added/removed/modified in this diff hunk.
2336
2337 The {options} Dict argument also specifies diff options
2338 (similar to 'diffopt') and supports the following items:
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002339 algorithm Dict specifying the diff algorithm to
2340 use. Supported boolean items are
2341 "myers", "minimal", "patience" and
2342 "histogram".
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002343 context diff context length. Default is 0.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002344 iblank ignore changes where lines are all
2345 blank.
2346 icase ignore changes in case of text.
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01002347 indent-heuristic use the indent heuristic for the
2348 internal diff library.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002349 iwhite ignore changes in amount of white
2350 space.
2351 iwhiteall ignore all white space changes.
2352 iwhiteeol ignore white space changes at end of
2353 line.
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002354 For more information about these options, refer to 'diffopt'.
2355
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01002356 To compute the unified diff, all the items in {fromlist} are
2357 concatenated into a string using a newline separator and the
2358 same for {tolist}. The unified diff output uses line numbers.
2359
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002360 Returns an empty List or String if {fromlist} and {tolist} are
2361 identical.
2362
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002363 Examples: >
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002364 :echo diff(['abc'], ['xxx'])
2365 @@ -1 +1 @@
2366 -abc
2367 +xxx
2368
2369 :echo diff(['abc'], ['xxx'], {'output': 'indices'})
2370 [{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}]
2371 :echo diff(readfile('oldfile'), readfile('newfile'))
2372 :echo diff(getbufline(5, 1, '$'), getbufline(6, 1, '$'))
Yegappan Lakshmanan1af35632024-02-06 11:03:36 +01002373<
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01002374 For more examples, refer to |diff-func-examples|
2375
2376 Can also be used as a |method|: >
2377 GetFromList->diff(to_list)
2378<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002379 Return type: |String| or list<dict<number>> or list<any>
2380 depending on {options}
2381
2382
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002383diff_filler({lnum}) *diff_filler()*
2384 Returns the number of filler lines above line {lnum}.
2385 These are the lines that were inserted at this point in
2386 another diff'ed window. These filler lines are shown in the
2387 display but don't exist in the buffer.
2388 {lnum} is used like with |getline()|. Thus "." is the current
2389 line, "'m" mark m, etc.
2390 Returns 0 if the current window is not in diff mode.
2391
2392 Can also be used as a |method|: >
2393 GetLnum()->diff_filler()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002394<
2395 Return type: |Number|
2396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002397
2398diff_hlID({lnum}, {col}) *diff_hlID()*
2399 Returns the highlight ID for diff mode at line {lnum} column
2400 {col} (byte index). When the current line does not have a
2401 diff change zero is returned.
2402 {lnum} is used like with |getline()|. Thus "." is the current
2403 line, "'m" mark m, etc.
2404 {col} is 1 for the leftmost column, {lnum} is 1 for the first
2405 line.
2406 The highlight ID can be used with |synIDattr()| to obtain
2407 syntax information about the highlighting.
2408
2409 Can also be used as a |method|: >
2410 GetLnum()->diff_hlID(col)
2411<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002412 Return type: |Number|
2413
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002414
2415digraph_get({chars}) *digraph_get()* *E1214*
2416 Return the digraph of {chars}. This should be a string with
2417 exactly two characters. If {chars} are not just two
2418 characters, or the digraph of {chars} does not exist, an error
2419 is given and an empty string is returned.
2420
2421 The character will be converted from Unicode to 'encoding'
2422 when needed. This does require the conversion to be
2423 available, it might fail.
2424
2425 Also see |digraph_getlist()|.
2426
2427 Examples: >
2428 " Get a built-in digraph
2429 :echo digraph_get('00') " Returns '∞'
2430
2431 " Get a user-defined digraph
2432 :call digraph_set('aa', 'あ')
2433 :echo digraph_get('aa') " Returns 'あ'
2434<
2435 Can also be used as a |method|: >
2436 GetChars()->digraph_get()
2437<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002438 Return type: |String|
2439
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002440 This function works only when compiled with the |+digraphs|
2441 feature. If this feature is disabled, this function will
2442 display an error message.
2443
2444
2445digraph_getlist([{listall}]) *digraph_getlist()*
2446 Return a list of digraphs. If the {listall} argument is given
2447 and it is TRUE, return all digraphs, including the default
2448 digraphs. Otherwise, return only user-defined digraphs.
2449
2450 The characters will be converted from Unicode to 'encoding'
2451 when needed. This does require the conservation to be
2452 available, it might fail.
2453
2454 Also see |digraph_get()|.
2455
2456 Examples: >
2457 " Get user-defined digraphs
2458 :echo digraph_getlist()
2459
2460 " Get all the digraphs, including default digraphs
2461 :echo digraph_getlist(1)
2462<
2463 Can also be used as a |method|: >
2464 GetNumber()->digraph_getlist()
2465<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002466 Return type: list<list<string>>
2467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002468 This function works only when compiled with the |+digraphs|
2469 feature. If this feature is disabled, this function will
2470 display an error message.
2471
2472
Bram Moolenaara2baa732022-02-04 16:09:54 +00002473digraph_set({chars}, {digraph}) *digraph_set()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002474 Add digraph {chars} to the list. {chars} must be a string
2475 with two characters. {digraph} is a string with one UTF-8
Bram Moolenaara2baa732022-02-04 16:09:54 +00002476 encoded character. *E1215*
2477 Be careful, composing characters are NOT ignored. This
2478 function is similar to |:digraphs| command, but useful to add
2479 digraphs start with a white space.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002480
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002481 The function returns v:true if |digraph| is registered. If
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002482 this fails an error message is given and v:false is returned.
2483
2484 If you want to define multiple digraphs at once, you can use
2485 |digraph_setlist()|.
2486
2487 Example: >
2488 call digraph_set(' ', 'あ')
2489<
2490 Can be used as a |method|: >
2491 GetString()->digraph_set('あ')
2492<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002493 Return type: |vim9-boolean|
2494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002495 This function works only when compiled with the |+digraphs|
2496 feature. If this feature is disabled, this function will
2497 display an error message.
2498
2499
2500digraph_setlist({digraphlist}) *digraph_setlist()*
2501 Similar to |digraph_set()| but this function can add multiple
2502 digraphs at once. {digraphlist} is a list composed of lists,
2503 where each list contains two strings with {chars} and
Bram Moolenaara2baa732022-02-04 16:09:54 +00002504 {digraph} as in |digraph_set()|. *E1216*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002505 Example: >
2506 call digraph_setlist([['aa', 'あ'], ['ii', 'い']])
2507<
2508 It is similar to the following: >
2509 for [chars, digraph] in [['aa', 'あ'], ['ii', 'い']]
2510 call digraph_set(chars, digraph)
2511 endfor
2512< Except that the function returns after the first error,
2513 following digraphs will not be added.
2514
2515 Can be used as a |method|: >
2516 GetList()->digraph_setlist()
2517<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002518 Return type: |vim9-boolean|
2519
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002520 This function works only when compiled with the |+digraphs|
2521 feature. If this feature is disabled, this function will
2522 display an error message.
2523
2524
2525echoraw({string}) *echoraw()*
2526 Output {string} as-is, including unprintable characters.
2527 This can be used to output a terminal code. For example, to
2528 disable modifyOtherKeys: >
2529 call echoraw(&t_TE)
2530< and to enable it again: >
2531 call echoraw(&t_TI)
2532< Use with care, you can mess up the terminal this way.
2533
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002534 Return type: |Number|
2535
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002536
2537empty({expr}) *empty()*
2538 Return the Number 1 if {expr} is empty, zero otherwise.
2539 - A |List| or |Dictionary| is empty when it does not have any
2540 items.
2541 - A |String| is empty when its length is zero.
2542 - A |Number| and |Float| are empty when their value is zero.
2543 - |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2544 - A |Job| is empty when it failed to start.
2545 - A |Channel| is empty when it is closed.
2546 - A |Blob| is empty when its length is zero.
mityu7f0bba22024-03-29 10:14:41 +01002547 - An |Object| is empty, when the empty() method in the object
2548 (if present) returns true. |object-empty()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002549
2550 For a long |List| this is much faster than comparing the
2551 length with zero.
2552
2553 Can also be used as a |method|: >
2554 mylist->empty()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002555<
2556 Return type: |Number|
2557
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002558
2559environ() *environ()*
2560 Return all of environment variables as dictionary. You can
2561 check if an environment variable exists like this: >
2562 :echo has_key(environ(), 'HOME')
2563< Note that the variable name may be CamelCase; to ignore case
2564 use this: >
2565 :echo index(keys(environ()), 'HOME', 0, 1) != -1
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002566<
2567 Return type: dict<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002568
Bram Moolenaar416bd912023-07-07 23:19:18 +01002569
2570err_teapot([{expr}]) *err_teapot()*
2571 Produce an error with number 418, needed for implementation of
Christian Brabandtee17b6f2023-09-09 11:23:50 +02002572 RFC 2324.
Bram Moolenaar416bd912023-07-07 23:19:18 +01002573 If {expr} is present and it is TRUE error 503 is given,
2574 indicating that coffee is temporarily not available.
2575 If {expr} is present it must be a String.
2576
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002577 Return type: |Number|
2578
Bram Moolenaar416bd912023-07-07 23:19:18 +01002579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002580escape({string}, {chars}) *escape()*
2581 Escape the characters in {chars} that occur in {string} with a
2582 backslash. Example: >
2583 :echo escape('c:\program files\vim', ' \')
2584< results in: >
2585 c:\\program\ files\\vim
2586< Also see |shellescape()| and |fnameescape()|.
2587
2588 Can also be used as a |method|: >
2589 GetText()->escape(' \')
2590<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002591 Return type: |String|
2592
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002593 *eval()*
2594eval({string}) Evaluate {string} and return the result. Especially useful to
2595 turn the result of |string()| back into the original value.
2596 This works for Numbers, Floats, Strings, Blobs and composites
2597 of them. Also works for |Funcref|s that refer to existing
Aliaksei Budavei95740222024-04-04 23:05:33 +03002598 functions. In |Vim9| script, it can be used to obtain |enum|
2599 values from their fully qualified names.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002600
2601 Can also be used as a |method|: >
2602 argv->join()->eval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002603<
2604 Return type: any, depending on {string}
2605
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002606
2607eventhandler() *eventhandler()*
2608 Returns 1 when inside an event handler. That is that Vim got
2609 interrupted while waiting for the user to type a character,
2610 e.g., when dropping a file on Vim. This means interactive
2611 commands cannot be used. Otherwise zero is returned.
2612
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002613 Return type: |Number|
2614
2615
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002616executable({expr}) *executable()*
2617 This function checks if an executable with the name {expr}
2618 exists. {expr} must be the name of the program without any
2619 arguments.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002621 executable() uses the value of $PATH and/or the normal
zeertzjq0cc5dce2024-08-08 21:12:15 +02002622 searchpath for programs.
2623 *PATHEXT*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002624 On MS-Windows the ".exe", ".bat", etc. can optionally be
2625 included. Then the extensions in $PATHEXT are tried. Thus if
2626 "foo.exe" does not exist, "foo.exe.bat" can be found. If
2627 $PATHEXT is not set then ".com;.exe;.bat;.cmd" is used. A dot
2628 by itself can be used in $PATHEXT to try using the name
2629 without an extension. When 'shell' looks like a Unix shell,
2630 then the name is also tried without adding an extension.
2631 On MS-Windows it only checks if the file exists and is not a
2632 directory, not if it's really executable.
zeertzjq0cc5dce2024-08-08 21:12:15 +02002633 On MS-Windows an executable in the same directory as the Vim
2634 executable is always found. Since this directory is added to
2635 $PATH it should also work to execute it |win32-PATH|.
2636 *NoDefaultCurrentDirectoryInExePath*
2637 On MS-Windows an executable in Vim's current working directory
2638 is also normally found, but this can be disabled by setting
2639 the $NoDefaultCurrentDirectoryInExePath environment variable.
2640
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002641 The result is a Number:
2642 1 exists
2643 0 does not exist
2644 -1 not implemented on this system
2645 |exepath()| can be used to get the full path of an executable.
2646
2647 Can also be used as a |method|: >
2648 GetCommand()->executable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002649<
2650 Return type: |Number|
2651
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002652
2653execute({command} [, {silent}]) *execute()*
2654 Execute an Ex command or commands and return the output as a
2655 string.
2656 {command} can be a string or a List. In case of a List the
2657 lines are executed one by one.
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002658 This is more or less equivalent to: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002659 redir => var
2660 {command}
2661 redir END
Bram Moolenaar71badf92023-04-22 22:40:14 +01002662< Except that line continuation in {command} is not recognized.
2663
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002664 The optional {silent} argument can have these values:
2665 "" no `:silent` used
2666 "silent" `:silent` used
2667 "silent!" `:silent!` used
2668 The default is "silent". Note that with "silent!", unlike
2669 `:redir`, error messages are dropped. When using an external
2670 command the screen may be messed up, use `system()` instead.
2671 *E930*
2672 It is not possible to use `:redir` anywhere in {command}.
2673
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01002674 To get a list of lines use `split()` on the result: >
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002675 execute('args')->split("\n")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002676
2677< To execute a command in another window than the current one
2678 use `win_execute()`.
2679
2680 When used recursively the output of the recursive call is not
2681 included in the output of the higher level call.
2682
2683 Can also be used as a |method|: >
2684 GetCommand()->execute()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002685<
Marius Gedminasc98bfb92024-06-19 19:59:23 +02002686 Return type: |String|
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002688
2689exepath({expr}) *exepath()*
2690 If {expr} is an executable and is either an absolute path, a
2691 relative path or found in $PATH, return the full path.
2692 Note that the current directory is used when {expr} starts
2693 with "./", which may be a problem for Vim: >
2694 echo exepath(v:progpath)
2695< If {expr} cannot be found in $PATH or is not executable then
2696 an empty string is returned.
2697
2698 Can also be used as a |method|: >
2699 GetCommand()->exepath()
2700<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002701 Return type: |String|
2702
2703
2704exists({expr}) *exists()*
2705 The result is a Number, which is |TRUE| if {expr} is defined,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002706 zero otherwise.
2707
2708 Note: In a compiled |:def| function the evaluation is done at
2709 runtime. Use `exists_compiled()` to evaluate the expression
2710 at compile time.
2711
2712 For checking for a supported feature use |has()|.
2713 For checking if a file exists use |filereadable()|.
2714
2715 The {expr} argument is a string, which contains one of these:
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002716 varname internal variable (see
2717 dict.key |internal-variables|). Also works
2718 list[i] for |curly-braces-names|, |Dictionary|
Yegappan Lakshmanana2ebb6e2024-02-25 08:40:10 +01002719 import.Func entries, |List| items, class and
2720 class.Func object methods, imported items, etc.
2721 object.Func Does not work for local variables in a
2722 class.varname compiled `:def` function.
2723 object.varname Also works for a function in |Vim9|
Bram Moolenaar944697a2022-02-20 19:48:20 +00002724 script, since it can be used as a
2725 function reference.
Bram Moolenaarf10911e2022-01-29 22:20:48 +00002726 Beware that evaluating an index may
2727 cause an error message for an invalid
2728 expression. E.g.: >
2729 :let l = [1, 2, 3]
2730 :echo exists("l[5]")
2731< 0 >
2732 :echo exists("l[xx]")
2733< E121: Undefined variable: xx
2734 0
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002735 &option-name Vim option (only checks if it exists,
2736 not if it really works)
2737 +option-name Vim option that works.
2738 $ENVNAME environment variable (could also be
2739 done by comparing with an empty
2740 string)
2741 *funcname built-in function (see |functions|)
2742 or user defined function (see
2743 |user-functions|) that is implemented.
2744 Also works for a variable that is a
2745 Funcref.
2746 ?funcname built-in function that could be
2747 implemented; to be used to check if
2748 "funcname" is valid
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002749 :cmdname Ex command: built-in command, user
2750 command or command modifier |:command|.
2751 Returns:
2752 1 for match with start of a command
2753 2 full match with a command
2754 3 matches several user commands
2755 To check for a supported command
2756 always check the return value to be 2.
2757 :2match The |:2match| command.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01002758 :3match The |:3match| command (but you
2759 probably should not use it, it is
2760 reserved for internal usage)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002761 #event autocommand defined for this event
2762 #event#pattern autocommand defined for this event and
2763 pattern (the pattern is taken
2764 literally and compared to the
2765 autocommand patterns character by
2766 character)
2767 #group autocommand group exists
2768 #group#event autocommand defined for this group and
2769 event.
2770 #group#event#pattern
2771 autocommand defined for this group,
2772 event and pattern.
2773 ##event autocommand for this event is
2774 supported.
2775
2776 Examples: >
2777 exists("&shortname")
2778 exists("$HOSTNAME")
2779 exists("*strftime")
Bram Moolenaar944697a2022-02-20 19:48:20 +00002780 exists("*s:MyFunc") " only for legacy script
2781 exists("*MyFunc")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002782 exists("bufcount")
2783 exists(":Make")
2784 exists("#CursorHold")
2785 exists("#BufReadPre#*.gz")
2786 exists("#filetypeindent")
2787 exists("#filetypeindent#FileType")
2788 exists("#filetypeindent#FileType#*")
2789 exists("##ColorScheme")
2790< There must be no space between the symbol (&/$/*/#) and the
2791 name.
2792 There must be no extra characters after the name, although in
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01002793 a few cases this is ignored. That may become stricter in the
2794 future, thus don't count on it!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002795 Working example: >
2796 exists(":make")
2797< NOT working example: >
2798 exists(":make install")
2799
2800< Note that the argument must be a string, not the name of the
2801 variable itself. For example: >
2802 exists(bufcount)
2803< This doesn't check for existence of the "bufcount" variable,
2804 but gets the value of "bufcount", and checks if that exists.
2805
2806 Can also be used as a |method|: >
2807 Varname()->exists()
2808<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002809 Return type: |String|
2810
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002811
2812exists_compiled({expr}) *exists_compiled()*
2813 Like `exists()` but evaluated at compile time. This is useful
2814 to skip a block where a function is used that would otherwise
2815 give an error: >
2816 if exists_compiled('*ThatFunction')
2817 ThatFunction('works')
2818 endif
2819< If `exists()` were used then a compilation error would be
2820 given if ThatFunction() is not defined.
2821
2822 {expr} must be a literal string. *E1232*
2823 Can only be used in a |:def| function. *E1233*
2824 This does not work to check for arguments or local variables.
2825
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002826 Return type: |String|
2827
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002828
2829exp({expr}) *exp()*
2830 Return the exponential of {expr} as a |Float| in the range
2831 [0, inf].
2832 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01002833 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002834 Examples: >
2835 :echo exp(2)
2836< 7.389056 >
2837 :echo exp(-1)
2838< 0.367879
2839
2840 Can also be used as a |method|: >
2841 Compute()->exp()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002842<
2843 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002844
2845
2846expand({string} [, {nosuf} [, {list}]]) *expand()*
2847 Expand wildcards and the following special keywords in
2848 {string}. 'wildignorecase' applies.
2849
2850 If {list} is given and it is |TRUE|, a List will be returned.
2851 Otherwise the result is a String and when there are several
2852 matches, they are separated by <NL> characters. [Note: in
2853 version 5.0 a space was used, which caused problems when a
2854 file name contains a space]
2855
2856 If the expansion fails, the result is an empty string. A name
2857 for a non-existing file is not included, unless {string} does
2858 not start with '%', '#' or '<', see below.
2859
Christian Brabandtec9c3262024-02-21 20:40:05 +01002860 For a |:terminal| window '%' expands to a '!' followed by
h-east53753f62024-05-05 18:42:31 +02002861 the command or shell that is run. |terminal-bufname|
Christian Brabandtec9c3262024-02-21 20:40:05 +01002862
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002863 When {string} starts with '%', '#' or '<', the expansion is
2864 done like for the |cmdline-special| variables with their
2865 associated modifiers. Here is a short overview:
2866
2867 % current file name
2868 # alternate file name
2869 #n alternate file name n
2870 <cfile> file name under the cursor
2871 <afile> autocmd file name
2872 <abuf> autocmd buffer number (as a String!)
2873 <amatch> autocmd matched name
2874 <cexpr> C expression under the cursor
2875 <sfile> sourced script file or function name
2876 <slnum> sourced script line number or function
2877 line number
2878 <sflnum> script file line number, also when in
2879 a function
2880 <SID> "<SNR>123_" where "123" is the
2881 current script ID |<SID>|
Bram Moolenaar75ab5902022-04-18 15:36:40 +01002882 <script> sourced script file, or script file
2883 where the current function was defined
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002884 <stack> call stack
2885 <cword> word under the cursor
2886 <cWORD> WORD under the cursor
2887 <client> the {clientid} of the last received
2888 message |server2client()|
2889 Modifiers:
2890 :p expand to full path
2891 :h head (last path component removed)
2892 :t tail (last path component only)
2893 :r root (one extension removed)
2894 :e extension only
2895
2896 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002897 :let &tags = expand("%:p:h") .. "/tags"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002898< Note that when expanding a string that starts with '%', '#' or
2899 '<', any following text is ignored. This does NOT work: >
2900 :let doesntwork = expand("%:h.bak")
2901< Use this: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00002902 :let doeswork = expand("%:h") .. ".bak"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002903< Also note that expanding "<cfile>" and others only returns the
2904 referenced file name without further expansion. If "<cfile>"
2905 is "~/.cshrc", you need to do another expand() to have the
2906 "~/" expanded into the path of the home directory: >
2907 :echo expand(expand("<cfile>"))
2908<
2909 There cannot be white space between the variables and the
2910 following modifier. The |fnamemodify()| function can be used
2911 to modify normal file names.
2912
2913 When using '%' or '#', and the current or alternate file name
2914 is not defined, an empty string is used. Using "%:p" in a
2915 buffer with no name, results in the current directory, with a
2916 '/' added.
Bram Moolenaar57544522022-04-12 12:54:11 +01002917 When 'verbose' is set then expanding '%', '#' and <> items
2918 will result in an error message if the argument cannot be
2919 expanded.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002920
2921 When {string} does not start with '%', '#' or '<', it is
2922 expanded like a file name is expanded on the command line.
2923 'suffixes' and 'wildignore' are used, unless the optional
2924 {nosuf} argument is given and it is |TRUE|.
2925 Names for non-existing files are included. The "**" item can
2926 be used to search in a directory tree. For example, to find
2927 all "README" files in the current directory and below: >
2928 :echo expand("**/README")
2929<
2930 expand() can also be used to expand variables and environment
2931 variables that are only known in a shell. But this can be
2932 slow, because a shell may be used to do the expansion. See
2933 |expr-env-expand|.
2934 The expanded variable is still handled like a list of file
2935 names. When an environment variable cannot be expanded, it is
2936 left unchanged. Thus ":echo expand('$FOOBAR')" results in
2937 "$FOOBAR".
2938
2939 See |glob()| for finding existing files. See |system()| for
2940 getting the raw output of an external command.
2941
2942 Can also be used as a |method|: >
2943 Getpattern()->expand()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002944<
2945 Return type: |String| or list<string> depending on {list}
2946
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002947
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002948expandcmd({string} [, {options}]) *expandcmd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002949 Expand special items in String {string} like what is done for
2950 an Ex command such as `:edit`. This expands special keywords,
2951 like with |expand()|, and environment variables, anywhere in
2952 {string}. "~user" and "~/path" are only expanded at the
2953 start.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002954
2955 The following items are supported in the {options} Dict
2956 argument:
2957 errmsg If set to TRUE, error messages are displayed
2958 if an error is encountered during expansion.
2959 By default, error messages are not displayed.
2960
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002961 Returns the expanded string. If an error is encountered
2962 during expansion, the unmodified {string} is returned.
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002963
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002964 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002965 :echo expandcmd('make %<.o')
Yegappan Lakshmanan2b74b682022-04-03 21:30:32 +01002966 make /path/runtime/doc/builtin.o
2967 :echo expandcmd('make %<.o', {'errmsg': v:true})
2968<
Yegappan Lakshmanan5018a832022-04-02 21:12:21 +01002969 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002970 GetCommand()->expandcmd()
2971<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02002972 Return type: |String| or list<string> depending on {list}
2973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00002974extend({expr1}, {expr2} [, {expr3}]) *extend()*
2975 {expr1} and {expr2} must be both |Lists| or both
2976 |Dictionaries|.
2977
2978 If they are |Lists|: Append {expr2} to {expr1}.
2979 If {expr3} is given insert the items of {expr2} before the
2980 item with index {expr3} in {expr1}. When {expr3} is zero
2981 insert before the first item. When {expr3} is equal to
2982 len({expr1}) then {expr2} is appended.
2983 Examples: >
2984 :echo sort(extend(mylist, [7, 5]))
2985 :call extend(mylist, [2, 3], 1)
2986< When {expr1} is the same List as {expr2} then the number of
2987 items copied is equal to the original length of the List.
2988 E.g., when {expr3} is 1 you get N new copies of the first item
2989 (where N is the original length of the List).
2990 Use |add()| to concatenate one item to a list. To concatenate
2991 two lists into a new list use the + operator: >
2992 :let newlist = [1, 2, 3] + [4, 5]
2993<
2994 If they are |Dictionaries|:
2995 Add all entries from {expr2} to {expr1}.
2996 If a key exists in both {expr1} and {expr2} then {expr3} is
2997 used to decide what to do:
2998 {expr3} = "keep": keep the value of {expr1}
2999 {expr3} = "force": use the value of {expr2}
3000 {expr3} = "error": give an error message *E737*
3001 When {expr3} is omitted then "force" is assumed.
3002
3003 {expr1} is changed when {expr2} is not empty. If necessary
3004 make a copy of {expr1} first.
3005 {expr2} remains unchanged.
3006 When {expr1} is locked and {expr2} is not empty the operation
3007 fails.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003008 Returns {expr1}. Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003009
3010 Can also be used as a |method|: >
3011 mylist->extend(otherlist)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003012<
3013 Return type: list<{type}> or dict<{type}> depending on {expr1}
3014 and {expr2}, in case of error: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003015
3016
3017extendnew({expr1}, {expr2} [, {expr3}]) *extendnew()*
3018 Like |extend()| but instead of adding items to {expr1} a new
3019 List or Dictionary is created and returned. {expr1} remains
Bram Moolenaardd60c362023-02-27 15:49:53 +00003020 unchanged.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003021
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003022 Return type: list<{type}> or dict<{type}> depending on {expr1}
3023 and {expr2}, in case of error: |Number|
3024
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003025
3026feedkeys({string} [, {mode}]) *feedkeys()*
3027 Characters in {string} are queued for processing as if they
3028 come from a mapping or were typed by the user.
3029
3030 By default the string is added to the end of the typeahead
3031 buffer, thus if a mapping is still being executed the
3032 characters come after them. Use the 'i' flag to insert before
3033 other characters, they will be executed next, before any
3034 characters from a mapping.
3035
3036 The function does not wait for processing of keys contained in
3037 {string}.
3038
3039 To include special keys into {string}, use double-quotes
3040 and "\..." notation |expr-quote|. For example,
3041 feedkeys("\<CR>") simulates pressing of the <Enter> key. But
3042 feedkeys('\<CR>') pushes 5 characters.
3043 A special code that might be useful is <Ignore>, it exits the
3044 wait for a character without doing anything. *<Ignore>*
3045
3046 {mode} is a String, which can contain these character flags:
3047 'm' Remap keys. This is default. If {mode} is absent,
3048 keys are remapped.
3049 'n' Do not remap keys.
3050 't' Handle keys as if typed; otherwise they are handled as
3051 if coming from a mapping. This matters for undo,
3052 opening folds, etc.
3053 'L' Lowlevel input. Only works for Unix or when using the
3054 GUI. Keys are used as if they were coming from the
3055 terminal. Other flags are not used. *E980*
3056 When a CTRL-C interrupts and 't' is included it sets
3057 the internal "got_int" flag.
3058 'i' Insert the string instead of appending (see above).
3059 'x' Execute commands until typeahead is empty. This is
3060 similar to using ":normal!". You can call feedkeys()
3061 several times without 'x' and then one time with 'x'
3062 (possibly with an empty {string}) to execute all the
3063 typeahead. Note that when Vim ends in Insert mode it
3064 will behave as if <Esc> is typed, to avoid getting
3065 stuck, waiting for a character to be typed before the
3066 script continues.
3067 Note that if you manage to call feedkeys() while
3068 executing commands, thus calling it recursively, then
3069 all typeahead will be consumed by the last call.
Bram Moolenaara9725222022-01-16 13:30:33 +00003070 'c' Remove any script context when executing, so that
3071 legacy script syntax applies, "s:var" does not work,
Bram Moolenaard899e512022-05-07 21:54:03 +01003072 etc. Note that if the string being fed sets a script
Bram Moolenaarce001a32022-04-27 15:25:03 +01003073 context this still applies.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003074 '!' When used with 'x' will not end Insert mode. Can be
3075 used in a test when a timer is set to exit Insert mode
3076 a little later. Useful for testing CursorHoldI.
3077
3078 Return value is always 0.
3079
3080 Can also be used as a |method|: >
3081 GetInput()->feedkeys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003082<
3083 Return type: |String| or list<string> depending on {list}
3084
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003085
Shougo Matsushita60c87432024-06-03 22:59:27 +02003086filecopy({from}, {to}) *filecopy()*
3087 Copy the file pointed to by the name {from} to {to}. The
3088 result is a Number, which is |TRUE| if the file was copied
3089 successfully, and |FALSE| when it failed.
3090 If a file with name {to} already exists, it will fail.
3091 Note that it does not handle directories (yet).
3092
3093 This function is not available in the |sandbox|.
3094
3095 Can also be used as a |method|: >
3096 GetOldName()->filecopy(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003097<
3098 Return type: |Number|
3099
Shougo Matsushita60c87432024-06-03 22:59:27 +02003100
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003101filereadable({file}) *filereadable()*
3102 The result is a Number, which is |TRUE| when a file with the
3103 name {file} exists, and can be read. If {file} doesn't exist,
3104 or is a directory, the result is |FALSE|. {file} is any
3105 expression, which is used as a String.
3106 If you don't care about the file being readable you can use
3107 |glob()|.
3108 {file} is used as-is, you may want to expand wildcards first: >
3109 echo filereadable('~/.vimrc')
3110 0
3111 echo filereadable(expand('~/.vimrc'))
3112 1
3113
3114< Can also be used as a |method|: >
3115 GetName()->filereadable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003116<
3117 Return type: |Number|
3118
3119 *file_readable()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003120 Obsolete name: file_readable().
3121
3122
3123filewritable({file}) *filewritable()*
3124 The result is a Number, which is 1 when a file with the
3125 name {file} exists, and can be written. If {file} doesn't
3126 exist, or is not writable, the result is 0. If {file} is a
3127 directory, and we can write to it, the result is 2.
3128
3129 Can also be used as a |method|: >
3130 GetName()->filewritable()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003131<
3132 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003133
3134
3135filter({expr1}, {expr2}) *filter()*
3136 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3137 For each item in {expr1} evaluate {expr2} and when the result
3138 is zero or false remove the item from the |List| or
3139 |Dictionary|. Similarly for each byte in a |Blob| and each
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003140 character in a |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003141
3142 {expr2} must be a |string| or |Funcref|.
3143
3144 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3145 of the current item. For a |Dictionary| |v:key| has the key
3146 of the current item and for a |List| |v:key| has the index of
3147 the current item. For a |Blob| |v:key| has the index of the
3148 current byte. For a |String| |v:key| has the index of the
3149 current character.
3150 Examples: >
3151 call filter(mylist, 'v:val !~ "OLD"')
3152< Removes the items where "OLD" appears. >
3153 call filter(mydict, 'v:key >= 8')
3154< Removes the items with a key below 8. >
3155 call filter(var, 0)
3156< Removes all the items, thus clears the |List| or |Dictionary|.
3157
3158 Note that {expr2} is the result of expression and is then
3159 used as an expression again. Often it is good to use a
3160 |literal-string| to avoid having to double backslashes.
3161
3162 If {expr2} is a |Funcref| it must take two arguments:
3163 1. the key or the index of the current item.
3164 2. the value of the current item.
3165 The function must return |TRUE| if the item should be kept.
3166 Example that keeps the odd items of a list: >
3167 func Odd(idx, val)
3168 return a:idx % 2 == 1
3169 endfunc
3170 call filter(mylist, function('Odd'))
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003171< It is shorter when using a |lambda|. In |Vim9| syntax: >
3172 call filter(myList, (idx, val) => idx * val <= 42)
3173< In legacy script syntax: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003174 call filter(myList, {idx, val -> idx * val <= 42})
3175< If you do not use "val" you can leave it out: >
3176 call filter(myList, {idx -> idx % 2 == 1})
3177<
3178 In |Vim9| script the result must be true, false, zero or one.
3179 Other values will result in a type error.
3180
3181 For a |List| and a |Dictionary| the operation is done
3182 in-place. If you want it to remain unmodified make a copy
3183 first: >
3184 :let l = filter(copy(mylist), 'v:val =~ "KEEP"')
3185
3186< Returns {expr1}, the |List| or |Dictionary| that was filtered,
naohiro ono56200ee2022-01-01 14:59:44 +00003187 or a new |Blob| or |String|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003188 When an error is encountered while evaluating {expr2} no
3189 further items in {expr1} are processed.
3190 When {expr2} is a Funcref errors inside a function are ignored,
3191 unless it was defined with the "abort" flag.
3192
3193 Can also be used as a |method|: >
3194 mylist->filter(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003195<
3196 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
3197 depending on {expr1}
3198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003199
3200finddir({name} [, {path} [, {count}]]) *finddir()*
3201 Find directory {name} in {path}. Supports both downwards and
3202 upwards recursive directory searches. See |file-searching|
3203 for the syntax of {path}.
3204
3205 Returns the path of the first found match. When the found
3206 directory is below the current directory a relative path is
3207 returned. Otherwise a full path is returned.
3208 If {path} is omitted or empty then 'path' is used.
3209
3210 If the optional {count} is given, find {count}'s occurrence of
3211 {name} in {path} instead of the first one.
3212 When {count} is negative return all the matches in a |List|.
3213
Bram Moolenaar016188f2022-06-06 20:52:59 +01003214 Returns an empty string if the directory is not found.
3215
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003216 This is quite similar to the ex-command `:find`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003217
3218 Can also be used as a |method|: >
3219 GetName()->finddir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003220<
3221 Return type: |String|
3222
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003223
3224findfile({name} [, {path} [, {count}]]) *findfile()*
3225 Just like |finddir()|, but find a file instead of a directory.
3226 Uses 'suffixesadd'.
3227 Example: >
3228 :echo findfile("tags.vim", ".;")
3229< Searches from the directory of the current file upwards until
3230 it finds the file "tags.vim".
3231
3232 Can also be used as a |method|: >
3233 GetName()->findfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003234<
3235 Return type: |String|
3236
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003237
3238flatten({list} [, {maxdepth}]) *flatten()*
3239 Flatten {list} up to {maxdepth} levels. Without {maxdepth}
3240 the result is a |List| without nesting, as if {maxdepth} is
3241 a very large number.
3242 The {list} is changed in place, use |flattennew()| if you do
3243 not want that.
3244 In Vim9 script flatten() cannot be used, you must always use
Bram Moolenaara2baa732022-02-04 16:09:54 +00003245 |flattennew()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003246 *E900*
3247 {maxdepth} means how deep in nested lists changes are made.
3248 {list} is not modified when {maxdepth} is 0.
3249 {maxdepth} must be positive number.
3250
3251 If there is an error the number zero is returned.
3252
3253 Example: >
3254 :echo flatten([1, [2, [3, 4]], 5])
3255< [1, 2, 3, 4, 5] >
3256 :echo flatten([1, [2, [3, 4]], 5], 1)
3257< [1, 2, [3, 4], 5]
3258
3259 Can also be used as a |method|: >
3260 mylist->flatten()
3261<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003262 Return type: list<{type}>
3263
3264
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003265flattennew({list} [, {maxdepth}]) *flattennew()*
3266 Like |flatten()| but first make a copy of {list}.
3267
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003268 Return type: list<{type}>
3269
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003270
3271float2nr({expr}) *float2nr()*
3272 Convert {expr} to a Number by omitting the part after the
3273 decimal point.
Bram Moolenaar76db9e02022-11-09 21:21:04 +00003274 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003275 Returns 0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003276 When the value of {expr} is out of range for a |Number| the
3277 result is truncated to 0x7fffffff or -0x7fffffff (or when
3278 64-bit Number support is enabled, 0x7fffffffffffffff or
3279 -0x7fffffffffffffff). NaN results in -0x80000000 (or when
3280 64-bit Number support is enabled, -0x8000000000000000).
3281 Examples: >
3282 echo float2nr(3.95)
3283< 3 >
3284 echo float2nr(-23.45)
3285< -23 >
3286 echo float2nr(1.0e100)
3287< 2147483647 (or 9223372036854775807) >
3288 echo float2nr(-1.0e150)
3289< -2147483647 (or -9223372036854775807) >
3290 echo float2nr(1.0e-100)
3291< 0
3292
3293 Can also be used as a |method|: >
3294 Compute()->float2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003295<
3296 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003297
3298
3299floor({expr}) *floor()*
3300 Return the largest integral value less than or equal to
3301 {expr} as a |Float| (round down).
3302 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003303 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003304 Examples: >
3305 echo floor(1.856)
3306< 1.0 >
3307 echo floor(-5.456)
3308< -6.0 >
3309 echo floor(4.0)
3310< 4.0
3311
3312 Can also be used as a |method|: >
3313 Compute()->floor()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003314<
3315 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003316
3317
3318fmod({expr1}, {expr2}) *fmod()*
3319 Return the remainder of {expr1} / {expr2}, even if the
3320 division is not representable. Returns {expr1} - i * {expr2}
3321 for some integer i such that if {expr2} is non-zero, the
3322 result has the same sign as {expr1} and magnitude less than
3323 the magnitude of {expr2}. If {expr2} is zero, the value
3324 returned is zero. The value returned is a |Float|.
3325 {expr1} and {expr2} must evaluate to a |Float| or a |Number|.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003326 Returns 0.0 if {expr1} or {expr2} is not a |Float| or a
3327 |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003328 Examples: >
3329 :echo fmod(12.33, 1.22)
3330< 0.13 >
3331 :echo fmod(-12.33, 1.22)
3332< -0.13
3333
3334 Can also be used as a |method|: >
3335 Compute()->fmod(1.22)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003336<
3337 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003338
3339
3340fnameescape({string}) *fnameescape()*
3341 Escape {string} for use as file name command argument. All
3342 characters that have a special meaning, such as '%' and '|'
3343 are escaped with a backslash.
3344 For most systems the characters escaped are
3345 " \t\n*?[{`$\\%#'\"|!<". For systems where a backslash
3346 appears in a filename, it depends on the value of 'isfname'.
3347 A leading '+' and '>' is also escaped (special after |:edit|
3348 and |:write|). And a "-" by itself (special after |:cd|).
Bram Moolenaar016188f2022-06-06 20:52:59 +01003349 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003350 Example: >
3351 :let fname = '+some str%nge|name'
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003352 :exe "edit " .. fnameescape(fname)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003353< results in executing: >
3354 edit \+some\ str\%nge\|name
3355<
3356 Can also be used as a |method|: >
3357 GetName()->fnameescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003358<
3359 Return type: |String|
3360
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003361
3362fnamemodify({fname}, {mods}) *fnamemodify()*
3363 Modify file name {fname} according to {mods}. {mods} is a
3364 string of characters like it is used for file names on the
3365 command line. See |filename-modifiers|.
3366 Example: >
3367 :echo fnamemodify("main.c", ":p:h")
3368< results in: >
Bram Moolenaard799daa2022-06-20 11:17:32 +01003369 /home/user/vim/vim/src
Bram Moolenaar016188f2022-06-06 20:52:59 +01003370< If {mods} is empty or an unsupported modifier is used then
3371 {fname} is returned.
Bram Moolenaar5ed11532022-07-06 13:18:11 +01003372 When {fname} is empty then with {mods} ":h" returns ".", so
3373 that `:cd` can be used with it. This is different from
3374 expand('%:h') without a buffer name, which returns an empty
3375 string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003376 Note: Environment variables don't work in {fname}, use
3377 |expand()| first then.
3378
3379 Can also be used as a |method|: >
3380 GetName()->fnamemodify(':p:h')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003381<
3382 Return type: |String|
3383
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003384
3385foldclosed({lnum}) *foldclosed()*
3386 The result is a Number. If the line {lnum} is in a closed
3387 fold, the result is the number of the first line in that fold.
3388 If the line {lnum} is not in a closed fold, -1 is returned.
3389 {lnum} is used like with |getline()|. Thus "." is the current
3390 line, "'m" mark m, etc.
3391
3392 Can also be used as a |method|: >
3393 GetLnum()->foldclosed()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003394<
3395 Return type: |Number|
3396
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003397
3398foldclosedend({lnum}) *foldclosedend()*
3399 The result is a Number. If the line {lnum} is in a closed
3400 fold, the result is the number of the last line in that fold.
3401 If the line {lnum} is not in a closed fold, -1 is returned.
3402 {lnum} is used like with |getline()|. Thus "." is the current
3403 line, "'m" mark m, etc.
3404
3405 Can also be used as a |method|: >
3406 GetLnum()->foldclosedend()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003407<
3408 Return type: |Number|
3409
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003410
3411foldlevel({lnum}) *foldlevel()*
3412 The result is a Number, which is the foldlevel of line {lnum}
3413 in the current buffer. For nested folds the deepest level is
3414 returned. If there is no fold at line {lnum}, zero is
3415 returned. It doesn't matter if the folds are open or closed.
3416 When used while updating folds (from 'foldexpr') -1 is
3417 returned for lines where folds are still to be updated and the
3418 foldlevel is unknown. As a special case the level of the
3419 previous line is usually available.
3420 {lnum} is used like with |getline()|. Thus "." is the current
3421 line, "'m" mark m, etc.
3422
3423 Can also be used as a |method|: >
3424 GetLnum()->foldlevel()
3425<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003426 Return type: |Number|
3427
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003428 *foldtext()*
3429foldtext() Returns a String, to be displayed for a closed fold. This is
3430 the default function used for the 'foldtext' option and should
3431 only be called from evaluating 'foldtext'. It uses the
3432 |v:foldstart|, |v:foldend| and |v:folddashes| variables.
3433 The returned string looks like this: >
3434 +-- 45 lines: abcdef
3435< The number of leading dashes depends on the foldlevel. The
3436 "45" is the number of lines in the fold. "abcdef" is the text
3437 in the first non-blank line of the fold. Leading white space,
3438 "//" or "/*" and the text from the 'foldmarker' and
3439 'commentstring' options is removed.
3440 When used to draw the actual foldtext, the rest of the line
3441 will be filled with the fold char from the 'fillchars'
3442 setting.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003443 Returns an empty string when there is no fold.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003444
3445 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003446 {not available when compiled without the |+folding| feature}
3447
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003448
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003449foldtextresult({lnum}) *foldtextresult()*
3450 Returns the text that is displayed for the closed fold at line
3451 {lnum}. Evaluates 'foldtext' in the appropriate context.
3452 When there is no closed fold at {lnum} an empty string is
3453 returned.
3454 {lnum} is used like with |getline()|. Thus "." is the current
3455 line, "'m" mark m, etc.
3456 Useful when exporting folded text, e.g., to HTML.
3457 {not available when compiled without the |+folding| feature}
3458
3459
3460 Can also be used as a |method|: >
3461 GetLnum()->foldtextresult()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003462<
3463 Return type: |String|
3464
Ernie Raele79e2072024-01-13 11:47:33 +01003465
3466foreach({expr1}, {expr2}) *foreach()*
3467 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
3468 For each item in {expr1} execute {expr2}. {expr1} is not
erraelc92b8be2024-01-14 10:11:07 -08003469 modified; its values may be, as with |:lockvar| 1. |E741|
Ernie Raele79e2072024-01-13 11:47:33 +01003470 See |map()| and |filter()| to modify {expr1}.
3471
3472 {expr2} must be a |string| or |Funcref|.
3473
3474 If {expr2} is a |string|, inside {expr2} |v:val| has the value
3475 of the current item. For a |Dictionary| |v:key| has the key
3476 of the current item and for a |List| |v:key| has the index of
3477 the current item. For a |Blob| |v:key| has the index of the
3478 current byte. For a |String| |v:key| has the index of the
3479 current character.
3480 Examples: >
3481 call foreach(mylist, 'used[v:val] = true')
3482< This records the items that are in the {expr1} list.
3483
3484 Note that {expr2} is the result of expression and is then used
3485 as a command. Often it is good to use a |literal-string| to
3486 avoid having to double backslashes.
3487
3488 If {expr2} is a |Funcref| it must take two arguments:
3489 1. the key or the index of the current item.
3490 2. the value of the current item.
3491 With a legacy script lambda you don't get an error if it only
3492 accepts one argument, but with a Vim9 lambda you get "E1106:
3493 One argument too many", the number of arguments must match.
3494 If the function returns a value, it is ignored.
3495
3496 Returns {expr1} in all cases.
3497 When an error is encountered while executing {expr2} no
3498 further items in {expr1} are processed.
3499 When {expr2} is a Funcref errors inside a function are ignored,
3500 unless it was defined with the "abort" flag.
3501
3502 Can also be used as a |method|: >
3503 mylist->foreach(expr2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003504<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003505 Return type: |String|, |Blob| list<{type}> or dict<{type}>
3506 depending on {expr1}
3507
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003508 *foreground()*
3509foreground() Move the Vim window to the foreground. Useful when sent from
3510 a client to a Vim server. |remote_send()|
3511 On Win32 systems this might not work, the OS does not always
3512 allow a window to bring itself to the foreground. Use
3513 |remote_foreground()| instead.
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003514
3515 Return type: |Number|
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01003516 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003517 Win32 console version}
3518
Bram Moolenaaraa534142022-09-15 21:46:02 +01003519fullcommand({name} [, {vim9}]) *fullcommand()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003520 Get the full command name from a short abbreviated command
3521 name; see |20.2| for details on command abbreviations.
3522
3523 The string argument {name} may start with a `:` and can
3524 include a [range], these are skipped and not returned.
Bram Moolenaaraa534142022-09-15 21:46:02 +01003525 Returns an empty string if a command doesn't exist, if it's
3526 ambiguous (for user-defined commands) or cannot be shortened
3527 this way. |vim9-no-shorten|
3528
3529 Without the {vim9} argument uses the current script version.
3530 If {vim9} is present and FALSE then legacy script rules are
3531 used. When {vim9} is present and TRUE then Vim9 rules are
3532 used, e.g. "en" is not a short form of "endif".
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003533
3534 For example `fullcommand('s')`, `fullcommand('sub')`,
3535 `fullcommand(':%substitute')` all return "substitute".
3536
3537 Can also be used as a |method|: >
3538 GetName()->fullcommand()
3539<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003540 Return type: |String|
3541
3542
3543funcref({name} [, {arglist}] [, {dict}]) *funcref()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003544 Just like |function()|, but the returned Funcref will lookup
3545 the function by reference, not by name. This matters when the
3546 function {name} is redefined later.
3547
3548 Unlike |function()|, {name} must be an existing user function.
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00003549 It only works for an autoloaded function if it has already
3550 been loaded (to avoid mistakenly loading the autoload script
3551 when only intending to use the function name, use |function()|
3552 instead). {name} cannot be a builtin function.
Bram Moolenaar016188f2022-06-06 20:52:59 +01003553 Returns 0 on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003554
3555 Can also be used as a |method|: >
3556 GetFuncname()->funcref([arg])
3557<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003558 Return type: func(...): any or |Number| on error
3559
Dominique Pellee764d1b2023-03-12 21:20:59 +00003560 *function()* *partial* *E700* *E923*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003561function({name} [, {arglist}] [, {dict}])
3562 Return a |Funcref| variable that refers to function {name}.
3563 {name} can be the name of a user defined function or an
3564 internal function.
3565
3566 {name} can also be a Funcref or a partial. When it is a
3567 partial the dict stored in it will be used and the {dict}
3568 argument is not allowed. E.g.: >
3569 let FuncWithArg = function(dict.Func, [arg])
3570 let Broken = function(dict.Func, [arg], dict)
3571<
3572 When using the Funcref the function will be found by {name},
3573 also when it was redefined later. Use |funcref()| to keep the
3574 same function.
3575
3576 When {arglist} or {dict} is present this creates a partial.
3577 That means the argument list and/or the dictionary is stored in
3578 the Funcref and will be used when the Funcref is called.
3579
3580 The arguments are passed to the function in front of other
3581 arguments, but after any argument from |method|. Example: >
3582 func Callback(arg1, arg2, name)
3583 ...
3584 let Partial = function('Callback', ['one', 'two'])
3585 ...
3586 call Partial('name')
3587< Invokes the function as with: >
3588 call Callback('one', 'two', 'name')
3589
3590< With a |method|: >
3591 func Callback(one, two, three)
3592 ...
3593 let Partial = function('Callback', ['two'])
3594 ...
3595 eval 'one'->Partial('three')
3596< Invokes the function as with: >
3597 call Callback('one', 'two', 'three')
3598
3599< The function() call can be nested to add more arguments to the
3600 Funcref. The extra arguments are appended to the list of
3601 arguments. Example: >
3602 func Callback(arg1, arg2, name)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003603 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003604 let Func = function('Callback', ['one'])
3605 let Func2 = function(Func, ['two'])
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003606 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003607 call Func2('name')
3608< Invokes the function as with: >
3609 call Callback('one', 'two', 'name')
3610
3611< The Dictionary is only useful when calling a "dict" function.
3612 In that case the {dict} is passed in as "self". Example: >
3613 function Callback() dict
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003614 echo "called for " .. self.name
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003615 endfunction
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003616 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003617 let context = {"name": "example"}
3618 let Func = function('Callback', context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003619 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003620 call Func() " will echo: called for example
3621< The use of function() is not needed when there are no extra
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003622 arguments, these two are equivalent, if Callback() is defined
3623 as context.Callback(): >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003624 let Func = function('Callback', context)
3625 let Func = context.Callback
3626
3627< The argument list and the Dictionary can be combined: >
3628 function Callback(arg1, count) dict
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003629 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003630 let context = {"name": "example"}
3631 let Func = function('Callback', ['one'], context)
Bram Moolenaar0daafaa2022-09-04 17:45:43 +01003632 "...
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003633 call Func(500)
3634< Invokes the function as with: >
3635 call context.Callback('one', 500)
3636<
Bram Moolenaar016188f2022-06-06 20:52:59 +01003637 Returns 0 on error.
3638
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003639 Can also be used as a |method|: >
3640 GetFuncname()->function([arg])
3641
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003642<
3643 Return type: func(...): any or |Number| on error
3644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003645
3646garbagecollect([{atexit}]) *garbagecollect()*
3647 Cleanup unused |Lists|, |Dictionaries|, |Channels| and |Jobs|
3648 that have circular references.
3649
3650 There is hardly ever a need to invoke this function, as it is
3651 automatically done when Vim runs out of memory or is waiting
3652 for the user to press a key after 'updatetime'. Items without
3653 circular references are always freed when they become unused.
3654 This is useful if you have deleted a very big |List| and/or
3655 |Dictionary| with circular references in a script that runs
3656 for a long time.
3657
3658 When the optional {atexit} argument is one, garbage
3659 collection will also be done when exiting Vim, if it wasn't
3660 done before. This is useful when checking for memory leaks.
3661
3662 The garbage collection is not done immediately but only when
3663 it's safe to perform. This is when waiting for the user to
3664 type a character. To force garbage collection immediately use
3665 |test_garbagecollect_now()|.
3666
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003667 Return type: |String|
3668
3669
LemonBoy48b7d052024-07-09 18:24:59 +02003670get({list}, {idx} [, {default}]) *get()* *get()-list*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003671 Get item {idx} from |List| {list}. When this item is not
3672 available return {default}. Return zero when {default} is
3673 omitted.
3674 Preferably used as a |method|: >
3675 mylist->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003676<
3677 Return type: any, depending on {list}
3678
LemonBoy48b7d052024-07-09 18:24:59 +02003679get({blob}, {idx} [, {default}]) *get()-blob*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003680 Get byte {idx} from |Blob| {blob}. When this byte is not
3681 available return {default}. Return -1 when {default} is
3682 omitted.
3683 Preferably used as a |method|: >
3684 myblob->get(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003685<
3686 Return type: |Number|
3687
LemonBoy48b7d052024-07-09 18:24:59 +02003688get({dict}, {key} [, {default}]) *get()-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003689 Get item with key {key} from |Dictionary| {dict}. When this
3690 item is not available return {default}. Return zero when
3691 {default} is omitted. Useful example: >
3692 let val = get(g:, 'var_name', 'default')
3693< This gets the value of g:var_name if it exists, and uses
3694 'default' when it does not exist.
3695 Preferably used as a |method|: >
3696 mydict->get(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003697<
h-east84ac2122024-06-17 18:12:30 +02003698 Return type: any, depending on {dict}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003699
LemonBoy48b7d052024-07-09 18:24:59 +02003700get({func}, {what}) *get()-func*
3701 Get item {what} from |Funcref| {func}. Possible values for
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003702 {what} are:
LemonBoy48b7d052024-07-09 18:24:59 +02003703 "name" The function name
3704 "func" The function
3705 "dict" The dictionary
3706 "args" The list with arguments
3707 "arity" A dictionary with information about the number of
3708 arguments accepted by the function (minus the
3709 {arglist}) with the following fields:
3710 required the number of positional arguments
3711 optional the number of optional arguments,
3712 in addition to the required ones
3713 varargs |TRUE| if the function accepts a
3714 variable number of arguments |...|
3715
3716 Note: There is no error, if the {arglist} of
3717 the Funcref contains more arguments than the
3718 Funcref expects, it's not validated.
3719
Bram Moolenaar016188f2022-06-06 20:52:59 +01003720 Returns zero on error.
LemonBoy48b7d052024-07-09 18:24:59 +02003721
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003722 Preferably used as a |method|: >
3723 myfunc->get(what)
3724<
LemonBoy48b7d052024-07-09 18:24:59 +02003725 Return type: any, depending on {func} and {what}
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003727 *getbufinfo()*
3728getbufinfo([{buf}])
3729getbufinfo([{dict}])
3730 Get information about buffers as a List of Dictionaries.
3731
3732 Without an argument information about all the buffers is
3733 returned.
3734
3735 When the argument is a |Dictionary| only the buffers matching
3736 the specified criteria are returned. The following keys can
3737 be specified in {dict}:
3738 buflisted include only listed buffers.
3739 bufloaded include only loaded buffers.
3740 bufmodified include only modified buffers.
3741
3742 Otherwise, {buf} specifies a particular buffer to return
3743 information for. For the use of {buf}, see |bufname()|
3744 above. If the buffer is found the returned List has one item.
3745 Otherwise the result is an empty list.
3746
3747 Each returned List item is a dictionary with the following
3748 entries:
3749 bufnr Buffer number.
3750 changed TRUE if the buffer is modified.
3751 changedtick Number of changes made to the buffer.
Sean Dewar1fb41032023-08-16 17:15:05 +01003752 command TRUE if the buffer belongs to the
3753 command-line window |cmdwin|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003754 hidden TRUE if the buffer is hidden.
3755 lastused Timestamp in seconds, like
3756 |localtime()|, when the buffer was
3757 last used.
3758 {only with the |+viminfo| feature}
3759 listed TRUE if the buffer is listed.
3760 lnum Line number used for the buffer when
3761 opened in the current window.
3762 Only valid if the buffer has been
3763 displayed in the window in the past.
3764 If you want the line number of the
3765 last known cursor position in a given
3766 window, use |line()|: >
3767 :echo line('.', {winid})
3768<
3769 linecount Number of lines in the buffer (only
3770 valid when loaded)
3771 loaded TRUE if the buffer is loaded.
3772 name Full path to the file in the buffer.
3773 signs List of signs placed in the buffer.
3774 Each list item is a dictionary with
3775 the following fields:
3776 id sign identifier
3777 lnum line number
3778 name sign name
3779 variables A reference to the dictionary with
3780 buffer-local variables.
3781 windows List of |window-ID|s that display this
3782 buffer
3783 popups List of popup |window-ID|s that
3784 display this buffer
3785
3786 Examples: >
3787 for buf in getbufinfo()
3788 echo buf.name
3789 endfor
3790 for buf in getbufinfo({'buflisted':1})
3791 if buf.changed
3792 ....
3793 endif
3794 endfor
3795<
3796 To get buffer-local options use: >
3797 getbufvar({bufnr}, '&option_name')
3798<
3799 Can also be used as a |method|: >
3800 GetBufnr()->getbufinfo()
3801<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003802 Return type: list<dict<any>>
3803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003804
3805 *getbufline()*
3806getbufline({buf}, {lnum} [, {end}])
3807 Return a |List| with the lines starting from {lnum} to {end}
3808 (inclusive) in the buffer {buf}. If {end} is omitted, a
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003809 |List| with only the line {lnum} is returned. See
3810 `getbufoneline()` for only getting the line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003811
3812 For the use of {buf}, see |bufname()| above.
3813
3814 For {lnum} and {end} "$" can be used for the last line of the
3815 buffer. Otherwise a number must be used.
3816
3817 When {lnum} is smaller than 1 or bigger than the number of
3818 lines in the buffer, an empty |List| is returned.
3819
3820 When {end} is greater than the number of lines in the buffer,
3821 it is treated as {end} is set to the number of lines in the
3822 buffer. When {end} is before {lnum} an empty |List| is
3823 returned.
3824
3825 This function works only for loaded buffers. For unloaded and
3826 non-existing buffers, an empty |List| is returned.
3827
3828 Example: >
3829 :let lines = getbufline(bufnr("myfile"), 1, "$")
3830
3831< Can also be used as a |method|: >
3832 GetBufnr()->getbufline(lnum)
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003833<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003834 Return type: list<string>
3835
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00003836 *getbufoneline()*
3837getbufoneline({buf}, {lnum})
3838 Just like `getbufline()` but only get one line and return it
3839 as a string.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003840
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003841 Return type: |String|
3842
3843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003844getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
3845 The result is the value of option or local buffer variable
3846 {varname} in buffer {buf}. Note that the name without "b:"
3847 must be used.
3848 The {varname} argument is a string.
3849 When {varname} is empty returns a |Dictionary| with all the
3850 buffer-local variables.
3851 When {varname} is equal to "&" returns a |Dictionary| with all
3852 the buffer-local options.
3853 Otherwise, when {varname} starts with "&" returns the value of
3854 a buffer-local option.
3855 This also works for a global or buffer-local option, but it
3856 doesn't work for a global variable, window-local variable or
3857 window-local option.
3858 For the use of {buf}, see |bufname()| above.
3859 When the buffer or variable doesn't exist {def} or an empty
3860 string is returned, there is no error message.
3861 Examples: >
3862 :let bufmodified = getbufvar(1, "&mod")
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003863 :echo "todo myvar = " .. getbufvar("todo", "myvar")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003864
3865< Can also be used as a |method|: >
3866 GetBufnr()->getbufvar(varname)
3867<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003868 Return type: any, depending on {varname}
3869
3870
mikoto20001083cae2024-11-11 21:24:14 +01003871getcellpixels() *getcellpixels()*
3872 Returns a |List| of terminal cell pixel size.
h-eastb534e802024-12-03 20:37:52 +01003873 List format is [xpixel, ypixel].
mikoto2000a73dfc22024-11-18 21:12:21 +01003874
3875 Only works on Unix (terminal and gVim) and Windows (gVim only).
3876 Returns [] on other systems or on failure.
3877 Note that there could be variations across different terminals.
3878 On macOS, system Terminal.app returns sizes in points (before
3879 Retina scaling), whereas third-party terminals return raw pixel
3880 sizes (post Retina scaling).
mikoto20001083cae2024-11-11 21:24:14 +01003881
mikoto2000de094dc2024-11-14 22:13:48 +01003882 Return type: list<any>
mikoto20001083cae2024-11-11 21:24:14 +01003883
3884
Kota Kato66bb9ae2023-01-17 18:31:56 +00003885getcellwidths() *getcellwidths()*
3886 Returns a |List| of cell widths of character ranges overridden
3887 by |setcellwidths()|. The format is equal to the argument of
3888 |setcellwidths()|. If no character ranges have their cell
3889 widths overridden, an empty List is returned.
h-east84ac2122024-06-17 18:12:30 +02003890
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003891 Return type: list<any>
Kota Kato66bb9ae2023-01-17 18:31:56 +00003892
3893
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003894getchangelist([{buf}]) *getchangelist()*
3895 Returns the |changelist| for the buffer {buf}. For the use
3896 of {buf}, see |bufname()| above. If buffer {buf} doesn't
3897 exist, an empty list is returned.
3898
3899 The returned list contains two entries: a list with the change
3900 locations and the current position in the list. Each
3901 entry in the change list is a dictionary with the following
3902 entries:
3903 col column number
3904 coladd column offset for 'virtualedit'
3905 lnum line number
3906 If buffer {buf} is the current buffer, then the current
3907 position refers to the position in the list. For other
3908 buffers, it is set to the length of the list.
3909
3910 Can also be used as a |method|: >
3911 GetBufnr()->getchangelist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003912<
3913 Return type: list<any>
3914
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003915
Doug Kearns9cd9e752024-04-07 17:42:17 +02003916getchar([{expr}]) *getchar()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003917 Get a single character from the user or input stream.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003918 If {expr} is omitted, wait until a character is available.
3919 If {expr} is 0, only get a character when one is available.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003920 Return zero otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02003921 If {expr} is 1, only check if a character is available, it is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003922 not consumed. Return zero if no character available.
3923 If you prefer always getting a string use |getcharstr()|.
3924
Doug Kearns9cd9e752024-04-07 17:42:17 +02003925 Without {expr} and when {expr} is 0 a whole character or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003926 special key is returned. If it is a single character, the
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01003927 result is a Number. Use |nr2char()| to convert it to a String.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003928 Otherwise a String is returned with the encoded character.
3929 For a special key it's a String with a sequence of bytes
3930 starting with 0x80 (decimal: 128). This is the same value as
3931 the String "\<Key>", e.g., "\<Left>". The returned value is
3932 also a String when a modifier (shift, control, alt) was used
3933 that is not included in the character.
3934
Doug Kearns9cd9e752024-04-07 17:42:17 +02003935 When {expr} is 0 and Esc is typed, there will be a short delay
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003936 while Vim waits to see if this is the start of an escape
3937 sequence.
3938
Doug Kearns9cd9e752024-04-07 17:42:17 +02003939 When {expr} is 1 only the first byte is returned. For a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003940 one-byte character it is the character itself as a number.
3941 Use nr2char() to convert it to a String.
3942
3943 Use getcharmod() to obtain any additional modifiers.
3944
3945 When the user clicks a mouse button, the mouse event will be
3946 returned. The position can then be found in |v:mouse_col|,
3947 |v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
3948 |getmousepos()| can also be used. Mouse move events will be
3949 ignored.
3950 This example positions the mouse as it would normally happen: >
3951 let c = getchar()
3952 if c == "\<LeftMouse>" && v:mouse_win > 0
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003953 exe v:mouse_win .. "wincmd w"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003954 exe v:mouse_lnum
Bram Moolenaarc51cf032022-02-26 12:25:45 +00003955 exe "normal " .. v:mouse_col .. "|"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003956 endif
3957<
3958 When using bracketed paste only the first character is
3959 returned, the rest of the pasted text is dropped.
3960 |xterm-bracketed-paste|.
3961
3962 There is no prompt, you will somehow have to make clear to the
3963 user that a character has to be typed. The screen is not
3964 redrawn, e.g. when resizing the window. When using a popup
3965 window it should work better with a |popup-filter|.
3966
3967 There is no mapping for the character.
3968 Key codes are replaced, thus when the user presses the <Del>
3969 key you get the code for the <Del> key, not the raw character
3970 sequence. Examples: >
3971 getchar() == "\<Del>"
3972 getchar() == "\<S-Left>"
3973< This example redefines "f" to ignore case: >
3974 :nmap f :call FindChar()<CR>
3975 :function FindChar()
3976 : let c = nr2char(getchar())
3977 : while col('.') < col('$') - 1
3978 : normal l
3979 : if getline('.')[col('.') - 1] ==? c
3980 : break
3981 : endif
3982 : endwhile
3983 :endfunction
3984<
3985 You may also receive synthetic characters, such as
3986 |<CursorHold>|. Often you will want to ignore this and get
3987 another character: >
3988 :function GetKey()
3989 : let c = getchar()
3990 : while c == "\<CursorHold>"
3991 : let c = getchar()
3992 : endwhile
3993 : return c
3994 :endfunction
Christian Brabandt5674c9a2024-06-09 00:13:43 +02003995<
3996 Return type: |Number| or |String|
3997
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00003998
3999getcharmod() *getcharmod()*
4000 The result is a Number which is the state of the modifiers for
4001 the last obtained character with getchar() or in another way.
4002 These values are added together:
4003 2 shift
4004 4 control
4005 8 alt (meta)
4006 16 meta (when it's different from ALT)
4007 32 mouse double click
4008 64 mouse triple click
4009 96 mouse quadruple click (== 32 + 64)
Casey Tucker92e90a12024-01-25 22:44:00 +01004010 128 command (Mac) or super (GTK)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004011 Only the modifiers that have not been included in the
4012 character itself are obtained. Thus Shift-a results in "A"
Bram Moolenaar016188f2022-06-06 20:52:59 +01004013 without a modifier. Returns 0 if no modifiers are used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004014
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004015 Return type: |Number|
4016
4017
4018getcharpos({expr}) *getcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004019 Get the position for String {expr}. Same as |getpos()| but the
4020 column number in the returned List is a character index
4021 instead of a byte index.
naohiro ono56200ee2022-01-01 14:59:44 +00004022 If |getpos()| returns a very large column number, equal to
4023 |v:maxcol|, then getcharpos() will return the character index
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004024 of the last character.
4025
4026 Example:
4027 With the cursor on '세' in line 5 with text "여보세요": >
4028 getcharpos('.') returns [0, 5, 3, 0]
4029 getpos('.') returns [0, 5, 7, 0]
4030<
4031 Can also be used as a |method|: >
4032 GetMark()->getcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004033<
4034 Return type: list<number>
4035
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004036
4037getcharsearch() *getcharsearch()*
4038 Return the current character search information as a {dict}
4039 with the following entries:
4040
4041 char character previously used for a character
4042 search (|t|, |f|, |T|, or |F|); empty string
4043 if no character search has been performed
4044 forward direction of character search; 1 for forward,
4045 0 for backward
4046 until type of character search; 1 for a |t| or |T|
4047 character search, 0 for an |f| or |F|
4048 character search
4049
4050 This can be useful to always have |;| and |,| search
4051 forward/backward regardless of the direction of the previous
4052 character search: >
4053 :nnoremap <expr> ; getcharsearch().forward ? ';' : ','
4054 :nnoremap <expr> , getcharsearch().forward ? ',' : ';'
4055< Also see |setcharsearch()|.
4056
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004057 Return type: dict<any>
4058
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004059
Doug Kearns9cd9e752024-04-07 17:42:17 +02004060getcharstr([{expr}]) *getcharstr()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004061 Get a single character from the user or input stream as a
4062 string.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004063 If {expr} is omitted, wait until a character is available.
4064 If {expr} is 0 or false, only get a character when one is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004065 available. Return an empty string otherwise.
Doug Kearns9cd9e752024-04-07 17:42:17 +02004066 If {expr} is 1 or true, only check if a character is
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004067 available, it is not consumed. Return an empty string
4068 if no character is available.
4069 Otherwise this works like |getchar()|, except that a number
4070 result is converted to a string.
4071
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004072 Return type: |String|
4073
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004074getcmdcomplpat() *getcmdcomplpat()*
4075 Return completion pattern of the current command-line.
4076 Only works when the command line is being edited, thus
4077 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4078 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4079 |getcmdprompt()|, |getcmdcompltype()| and |setcmdline()|.
4080 Returns an empty string when completion is not defined.
4081
4082 Return type: |String|
4083
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004084
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004085getcmdcompltype() *getcmdcompltype()*
4086 Return the type of the current command-line completion.
4087 Only works when the command line is being edited, thus
4088 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar921bde82022-05-09 19:50:35 +01004089 See |:command-completion| for the return string.
Shougo Matsushita69084282024-09-23 20:34:47 +02004090 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
Ruslan Russkikh0407d622024-10-08 22:21:05 +02004091 |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004092 Returns an empty string when completion is not defined.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004093
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004094 Return type: |String|
4095
4096
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004097getcmdline() *getcmdline()*
Shougo Matsushita69084282024-09-23 20:34:47 +02004098 Return the current command-line input. Only works when the
4099 command line is being edited, thus requires use of
4100 |c_CTRL-\_e| or |c_CTRL-R_=|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004101 Example: >
4102 :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
Shougo Matsushita69084282024-09-23 20:34:47 +02004103< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
4104 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004105 Returns an empty string when entering a password or using
4106 |inputsecret()|.
4107
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004108 Return type: |String|
4109
4110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004111getcmdpos() *getcmdpos()*
4112 Return the position of the cursor in the command line as a
4113 byte count. The first column is 1.
4114 Only works when editing the command line, thus requires use of
4115 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4116 Returns 0 otherwise.
Shougo Matsushita69084282024-09-23 20:34:47 +02004117 Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
4118 |getcmdprompt()| and |setcmdline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004119
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004120 Return type: |Number|
4121
4122
Shougo Matsushita69084282024-09-23 20:34:47 +02004123getcmdprompt() *getcmdprompt()*
4124 Return the current command-line prompt when using functions
4125 like |input()| or |confirm()|.
4126 Only works when the command line is being edited, thus
4127 requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
4128 Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|,
4129 |setcmdpos()| and |setcmdline()|.
4130
4131 Return type: |String|
4132
4133
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004134getcmdscreenpos() *getcmdscreenpos()*
4135 Return the screen position of the cursor in the command line
4136 as a byte count. The first column is 1.
4137 Instead of |getcmdpos()|, it adds the prompt position.
4138 Only works when editing the command line, thus requires use of
4139 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4140 Returns 0 otherwise.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01004141 Also see |getcmdpos()|, |setcmdpos()|, |getcmdline()| and
4142 |setcmdline()|.
Shougo Matsushita79d599b2022-05-07 12:48:29 +01004143
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004144 Return type: |Number|
4145
4146
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004147getcmdtype() *getcmdtype()*
4148 Return the current command-line type. Possible return values
4149 are:
4150 : normal Ex command
4151 > debug mode command |debug-mode|
4152 / forward search command
4153 ? backward search command
4154 @ |input()| command
4155 - |:insert| or |:append| command
4156 = |i_CTRL-R_=|
4157 Only works when editing the command line, thus requires use of
4158 |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
4159 Returns an empty string otherwise.
4160 Also see |getcmdpos()|, |setcmdpos()| and |getcmdline()|.
4161
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004162 Return type: |String|
4163
4164
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004165getcmdwintype() *getcmdwintype()*
4166 Return the current |command-line-window| type. Possible return
4167 values are the same as |getcmdtype()|. Returns an empty string
4168 when not in the command-line window.
4169
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004170 Return type: |String|
4171
4172
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004173getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
4174 Return a list of command-line completion matches. The String
4175 {type} argument specifies what for. The following completion
4176 types are supported:
4177
4178 arglist file names in argument list
4179 augroup autocmd groups
4180 buffer buffer names
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004181 behave |:behave| suboptions
4182 breakpoint |:breakadd| and |:breakdel| suboptions
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004183 color color schemes
4184 command Ex command
4185 cmdline |cmdline-completion| result
4186 compiler compilers
4187 cscope |:cscope| suboptions
Shougo Matsushita92997dd2023-08-20 20:55:55 +02004188 custom,{func} custom completion, defined via {func}
4189 customlist,{func} custom completion, defined via {func}
zeertzjq85f36d62024-10-10 19:14:13 +02004190 diff_buffer |:diffget| and |:diffput| completion
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004191 dir directory names
LemonBoya20bf692024-07-11 22:35:53 +02004192 dir_in_path directory names in |'cdpath'|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004193 environment environment variable names
4194 event autocommand events
4195 expression Vim expression
4196 file file and directory names
4197 file_in_path file and directory names in |'path'|
4198 filetype filetype names |'filetype'|
4199 function function name
4200 help help subjects
4201 highlight highlight groups
Bram Moolenaar6e2e2cc2022-03-14 19:24:46 +00004202 history |:history| suboptions
Doug Kearns81642d92024-01-04 22:37:44 +01004203 keymap keyboard mappings
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004204 locale locale names (as output of locale -a)
4205 mapclear buffer argument
4206 mapping mapping name
4207 menu menus
4208 messages |:messages| suboptions
4209 option options
4210 packadd optional package |pack-add| names
zeertzjq5c8771b2023-01-24 12:34:03 +00004211 runtime |:runtime| completion
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004212 scriptnames sourced script names |:scriptnames|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004213 shellcmd Shell command
zeertzjq85f36d62024-10-10 19:14:13 +02004214 shellcmdline Shell command line with filename arguments
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004215 sign |:sign| suboptions
4216 syntax syntax file names |'syntax'|
4217 syntime |:syntime| suboptions
4218 tag tags
4219 tag_listfiles tags, file names
4220 user user names
4221 var user variables
4222
4223 If {pat} is an empty string, then all the matches are
4224 returned. Otherwise only items matching {pat} are returned.
4225 See |wildcards| for the use of special characters in {pat}.
4226
4227 If the optional {filtered} flag is set to 1, then 'wildignore'
4228 is applied to filter the results. Otherwise all the matches
4229 are returned. The 'wildignorecase' option always applies.
4230
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004231 If the 'wildoptions' option contains 'fuzzy', then fuzzy
4232 matching is used to get the completion matches. Otherwise
Yegappan Lakshmanan454ce672022-03-24 11:22:13 +00004233 regular expression matching is used. Thus this function
4234 follows the user preference, what happens on the command line.
4235 If you do not want this you can make 'wildoptions' empty
4236 before calling getcompletion() and restore it afterwards.
Yegappan Lakshmanane7dd0fa2022-03-22 16:06:31 +00004237
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004238 If {type} is "cmdline", then the |cmdline-completion| result is
4239 returned. For example, to complete the possible values after
4240 a ":call" command: >
4241 echo getcompletion('call ', 'cmdline')
4242<
4243 If there are no matches, an empty list is returned. An
4244 invalid value for {type} produces an error.
4245
4246 Can also be used as a |method|: >
4247 GetPattern()->getcompletion('color')
4248<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004249 Return type: list<string>
4250
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004251 *getcurpos()*
4252getcurpos([{winid}])
4253 Get the position of the cursor. This is like getpos('.'), but
4254 includes an extra "curswant" item in the list:
4255 [0, lnum, col, off, curswant] ~
4256 The "curswant" number is the preferred column when moving the
naohiro ono56200ee2022-01-01 14:59:44 +00004257 cursor vertically. After |$| command it will be a very large
4258 number equal to |v:maxcol|. Also see |getcursorcharpos()| and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004259 |getpos()|.
4260 The first "bufnum" item is always zero. The byte position of
4261 the cursor is returned in 'col'. To get the character
4262 position, use |getcursorcharpos()|.
4263
4264 The optional {winid} argument can specify the window. It can
4265 be the window number or the |window-ID|. The last known
4266 cursor position is returned, this may be invalid for the
4267 current value of the buffer if it is not the current window.
4268 If {winid} is invalid a list with zeroes is returned.
4269
4270 This can be used to save and restore the cursor position: >
4271 let save_cursor = getcurpos()
4272 MoveTheCursorAround
4273 call setpos('.', save_cursor)
4274< Note that this only works within the window. See
4275 |winrestview()| for restoring more state.
4276
4277 Can also be used as a |method|: >
4278 GetWinid()->getcurpos()
4279<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004280 Return type: list<number>
4281
4282
4283getcursorcharpos([{winid}]) *getcursorcharpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004284 Same as |getcurpos()| but the column number in the returned
4285 List is a character index instead of a byte index.
4286
4287 Example:
4288 With the cursor on '보' in line 3 with text "여보세요": >
4289 getcursorcharpos() returns [0, 3, 2, 0, 3]
4290 getcurpos() returns [0, 3, 4, 0, 3]
4291<
4292 Can also be used as a |method|: >
4293 GetWinid()->getcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004294<
4295 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004296
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004297
4298getcwd([{winnr} [, {tabnr}]]) *getcwd()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004299 The result is a String, which is the name of the current
4300 working directory. 'autochdir' is ignored.
4301
4302 With {winnr} return the local current directory of this window
4303 in the current tab page. {winnr} can be the window number or
4304 the |window-ID|.
4305 If {winnr} is -1 return the name of the global working
4306 directory. See also |haslocaldir()|.
4307
4308 With {winnr} and {tabnr} return the local current directory of
4309 the window in the specified tab page. If {winnr} is -1 return
4310 the working directory of the tabpage.
4311 If {winnr} is zero use the current window, if {tabnr} is zero
4312 use the current tabpage.
4313 Without any arguments, return the actual working directory of
4314 the current window.
4315 Return an empty string if the arguments are invalid.
4316
4317 Examples: >
4318 " Get the working directory of the current window
4319 :echo getcwd()
4320 :echo getcwd(0)
4321 :echo getcwd(0, 0)
4322 " Get the working directory of window 3 in tabpage 2
4323 :echo getcwd(3, 2)
4324 " Get the global working directory
4325 :echo getcwd(-1)
4326 " Get the working directory of tabpage 3
4327 :echo getcwd(-1, 3)
4328 " Get the working directory of current tabpage
4329 :echo getcwd(-1, 0)
4330
4331< Can also be used as a |method|: >
4332 GetWinnr()->getcwd()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004333<
4334 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004335
4336getenv({name}) *getenv()*
4337 Return the value of environment variable {name}. The {name}
4338 argument is a string, without a leading '$'. Example: >
4339 myHome = getenv('HOME')
4340
4341< When the variable does not exist |v:null| is returned. That
4342 is different from a variable set to an empty string, although
4343 some systems interpret the empty value as the variable being
4344 deleted. See also |expr-env|.
4345
4346 Can also be used as a |method|: >
4347 GetVarname()->getenv()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004348<
4349 Return type: |String| or |Number|
4350
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004351
4352getfontname([{name}]) *getfontname()*
4353 Without an argument returns the name of the normal font being
4354 used. Like what is used for the Normal highlight group
4355 |hl-Normal|.
4356 With an argument a check is done whether String {name} is a
4357 valid font name. If not then an empty string is returned.
4358 Otherwise the actual font name is returned, or {name} if the
4359 GUI does not support obtaining the real name.
4360 Only works when the GUI is running, thus not in your vimrc or
4361 gvimrc file. Use the |GUIEnter| autocommand to use this
4362 function just after the GUI has started.
4363 Note that the GTK GUI accepts any font name, thus checking for
4364 a valid name does not work.
4365
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004366 Return type: |String|
4367
4368
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004369getfperm({fname}) *getfperm()*
4370 The result is a String, which is the read, write, and execute
4371 permissions of the given file {fname}.
4372 If {fname} does not exist or its directory cannot be read, an
4373 empty string is returned.
4374 The result is of the form "rwxrwxrwx", where each group of
4375 "rwx" flags represent, in turn, the permissions of the owner
4376 of the file, the group the file belongs to, and other users.
4377 If a user does not have a given permission the flag for this
4378 is replaced with the string "-". Examples: >
4379 :echo getfperm("/etc/passwd")
4380 :echo getfperm(expand("~/.vimrc"))
4381< This will hopefully (from a security point of view) display
4382 the string "rw-r--r--" or even "rw-------".
4383
4384 Can also be used as a |method|: >
4385 GetFilename()->getfperm()
4386<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004387 Return type: |String|
4388
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004389 For setting permissions use |setfperm()|.
4390
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004391
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004392getfsize({fname}) *getfsize()*
4393 The result is a Number, which is the size in bytes of the
4394 given file {fname}.
4395 If {fname} is a directory, 0 is returned.
4396 If the file {fname} can't be found, -1 is returned.
4397 If the size of {fname} is too big to fit in a Number then -2
4398 is returned.
4399
4400 Can also be used as a |method|: >
4401 GetFilename()->getfsize()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004402<
4403 Return type: |Number|
4404
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004405
4406getftime({fname}) *getftime()*
4407 The result is a Number, which is the last modification time of
4408 the given file {fname}. The value is measured as seconds
4409 since 1st Jan 1970, and may be passed to strftime(). See also
4410 |localtime()| and |strftime()|.
4411 If the file {fname} can't be found -1 is returned.
4412
4413 Can also be used as a |method|: >
4414 GetFilename()->getftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004415<
4416 Return type: |Number|
4417
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004418
4419getftype({fname}) *getftype()*
4420 The result is a String, which is a description of the kind of
4421 file of the given file {fname}.
4422 If {fname} does not exist an empty string is returned.
4423 Here is a table over different kinds of files and their
4424 results:
4425 Normal file "file"
4426 Directory "dir"
4427 Symbolic link "link"
4428 Block device "bdev"
4429 Character device "cdev"
4430 Socket "socket"
4431 FIFO "fifo"
4432 All other "other"
4433 Example: >
4434 getftype("/home")
4435< Note that a type such as "link" will only be returned on
4436 systems that support it. On some systems only "dir" and
4437 "file" are returned. On MS-Windows a symbolic link to a
4438 directory returns "dir" instead of "link".
4439
4440 Can also be used as a |method|: >
4441 GetFilename()->getftype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004442<
4443 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004444
4445getimstatus() *getimstatus()*
4446 The result is a Number, which is |TRUE| when the IME status is
Bram Moolenaar016188f2022-06-06 20:52:59 +01004447 active and |FALSE| otherwise.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004448 See 'imstatusfunc'.
4449
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004450 Return type: |Number|
4451
4452
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004453getjumplist([{winnr} [, {tabnr}]]) *getjumplist()*
4454 Returns the |jumplist| for the specified window.
4455
4456 Without arguments use the current window.
4457 With {winnr} only use this window in the current tab page.
4458 {winnr} can also be a |window-ID|.
4459 With {winnr} and {tabnr} use the window in the specified tab
Bram Moolenaar016188f2022-06-06 20:52:59 +01004460 page. If {winnr} or {tabnr} is invalid, an empty list is
4461 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004462
4463 The returned list contains two entries: a list with the jump
4464 locations and the last used jump position number in the list.
4465 Each entry in the jump location list is a dictionary with
4466 the following entries:
4467 bufnr buffer number
4468 col column number
4469 coladd column offset for 'virtualedit'
4470 filename filename if available
4471 lnum line number
4472
4473 Can also be used as a |method|: >
4474 GetWinnr()->getjumplist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004475<
4476 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004477
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004478 *getline()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004479getline({lnum} [, {end}])
4480 Without {end} the result is a String, which is line {lnum}
4481 from the current buffer. Example: >
4482 getline(1)
4483< When {lnum} is a String that doesn't start with a
4484 digit, |line()| is called to translate the String into a Number.
4485 To get the line under the cursor: >
4486 getline(".")
4487< When {lnum} is a number smaller than 1 or bigger than the
4488 number of lines in the buffer, an empty string is returned.
4489
4490 When {end} is given the result is a |List| where each item is
4491 a line from the current buffer in the range {lnum} to {end},
4492 including line {end}.
4493 {end} is used in the same way as {lnum}.
4494 Non-existing lines are silently omitted.
4495 When {end} is before {lnum} an empty |List| is returned.
4496 Example: >
4497 :let start = line('.')
4498 :let end = search("^$") - 1
4499 :let lines = getline(start, end)
4500
4501< Can also be used as a |method|: >
4502 ComputeLnum()->getline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004503<
4504 Return type: list<string> or |String| depending on {end}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004505
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004506 To get lines from another buffer see |getbufline()| and
Bram Moolenaarce30ccc2022-11-21 19:57:04 +00004507 |getbufoneline()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004508
4509getloclist({nr} [, {what}]) *getloclist()*
4510 Returns a |List| with all the entries in the location list for
4511 window {nr}. {nr} can be the window number or the |window-ID|.
4512 When {nr} is zero the current window is used.
4513
4514 For a location list window, the displayed location list is
4515 returned. For an invalid window number {nr}, an empty list is
4516 returned. Otherwise, same as |getqflist()|.
4517
4518 If the optional {what} dictionary argument is supplied, then
4519 returns the items listed in {what} as a dictionary. Refer to
4520 |getqflist()| for the supported items in {what}.
4521
4522 In addition to the items supported by |getqflist()| in {what},
4523 the following item is supported by |getloclist()|:
4524
4525 filewinid id of the window used to display files
4526 from the location list. This field is
4527 applicable only when called from a
4528 location list window. See
4529 |location-list-file-window| for more
4530 details.
4531
4532 Returns a |Dictionary| with default values if there is no
4533 location list for the window {nr}.
4534 Returns an empty Dictionary if window {nr} does not exist.
4535
4536 Examples (See also |getqflist-examples|): >
4537 :echo getloclist(3, {'all': 0})
4538 :echo getloclist(5, {'filewinid': 0})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004539<
4540 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004541
4542
4543getmarklist([{buf}]) *getmarklist()*
4544 Without the {buf} argument returns a |List| with information
4545 about all the global marks. |mark|
4546
4547 If the optional {buf} argument is specified, returns the
4548 local marks defined in buffer {buf}. For the use of {buf},
Bram Moolenaar016188f2022-06-06 20:52:59 +01004549 see |bufname()|. If {buf} is invalid, an empty list is
4550 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004551
4552 Each item in the returned List is a |Dict| with the following:
4553 mark name of the mark prefixed by "'"
4554 pos a |List| with the position of the mark:
4555 [bufnum, lnum, col, off]
4556 Refer to |getpos()| for more information.
4557 file file name
4558
4559 Refer to |getpos()| for getting information about a specific
4560 mark.
4561
4562 Can also be used as a |method|: >
4563 GetBufnr()->getmarklist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004564<
4565 Return type: list<dict<any>> or list<any>
4566
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004567
4568getmatches([{win}]) *getmatches()*
4569 Returns a |List| with all matches previously defined for the
4570 current window by |matchadd()| and the |:match| commands.
4571 |getmatches()| is useful in combination with |setmatches()|,
4572 as |setmatches()| can restore a list of matches saved by
4573 |getmatches()|.
4574 If {win} is specified, use the window with this number or
Bram Moolenaar016188f2022-06-06 20:52:59 +01004575 window ID instead of the current window. If {win} is invalid,
4576 an empty list is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004577 Example: >
4578 :echo getmatches()
4579< [{'group': 'MyGroup1', 'pattern': 'TODO',
4580 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4581 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4582 :let m = getmatches()
4583 :call clearmatches()
4584 :echo getmatches()
4585< [] >
4586 :call setmatches(m)
4587 :echo getmatches()
4588< [{'group': 'MyGroup1', 'pattern': 'TODO',
4589 'priority': 10, 'id': 1}, {'group': 'MyGroup2',
4590 'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
4591 :unlet m
4592<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004593 Return type: list<dict<any>> or list<any>
4594
4595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004596getmousepos() *getmousepos()*
4597 Returns a |Dictionary| with the last known position of the
4598 mouse. This can be used in a mapping for a mouse click or in
4599 a filter of a popup window. The items are:
4600 screenrow screen row
4601 screencol screen column
4602 winid Window ID of the click
4603 winrow row inside "winid"
4604 wincol column inside "winid"
4605 line text line inside "winid"
4606 column text column inside "winid"
zeertzjqf5a94d52023-10-15 10:03:30 +02004607 coladd offset (in screen columns) from the
4608 start of the clicked char
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004609 All numbers are 1-based.
4610
4611 If not over a window, e.g. when in the command line, then only
4612 "screenrow" and "screencol" are valid, the others are zero.
4613
4614 When on the status line below a window or the vertical
4615 separator right of a window, the "line" and "column" values
4616 are zero.
4617
4618 When the position is after the text then "column" is the
4619 length of the text in bytes plus one.
4620
4621 If the mouse is over a popup window then that window is used.
4622
4623 When using |getchar()| the Vim variables |v:mouse_lnum|,
4624 |v:mouse_col| and |v:mouse_winid| also provide these values.
4625
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004626 Return type: dict<number>
4627
4628
Bram Moolenaar24dc19c2022-11-14 19:49:15 +00004629getmouseshape() *getmouseshape()*
4630 Returns the name of the currently showing mouse pointer.
4631 When the |+mouseshape| feature is not supported or the shape
4632 is unknown an empty string is returned.
4633 This function is mainly intended for testing.
4634
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004635 Return type: |String|
4636
4637
4638getpid() *getpid()*
4639 Return a Number which is the process ID of the Vim process.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004640 On Unix and MS-Windows this is a unique number, until Vim
4641 exits.
4642
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004643 Return type: |Number|
4644
4645
4646getpos({expr}) *getpos()*
zeertzjq02f3eba2024-06-12 20:45:24 +02004647 Get the position for String {expr}.
4648 The accepted values for {expr} are: *E1209*
4649 . The cursor position.
4650 $ The last line in the current buffer.
4651 'x Position of mark x (if the mark is not set, 0 is
zeertzjqd353d272024-06-13 23:00:25 +08004652 returned for all values).
zeertzjq02f3eba2024-06-12 20:45:24 +02004653 w0 First line visible in current window (one if the
4654 display isn't updated, e.g. in silent Ex mode).
4655 w$ Last line visible in current window (this is one
4656 less than "w0" if no lines are visible).
4657 v When not in Visual mode, returns the cursor
4658 position. In Visual mode, returns the other end
4659 of the Visual area. A good way to think about
4660 this is that in Visual mode "v" and "." complement
4661 each other. While "." refers to the cursor
4662 position, "v" refers to where |v_o| would move the
4663 cursor. As a result, you can use "v" and "."
4664 together to work on all of a selection in
4665 characterwise Visual mode. If the cursor is at
4666 the end of a characterwise Visual area, "v" refers
4667 to the start of the same Visual area. And if the
4668 cursor is at the start of a characterwise Visual
4669 area, "v" refers to the end of the same Visual
4670 area. "v" differs from |'<| and |'>| in that it's
4671 updated right away.
4672 Note that a mark in another file can be used. The line number
4673 then applies to another buffer.
4674
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004675 The result is a |List| with four numbers:
4676 [bufnum, lnum, col, off]
4677 "bufnum" is zero, unless a mark like '0 or 'A is used, then it
4678 is the buffer number of the mark.
4679 "lnum" and "col" are the position in the buffer. The first
4680 column is 1.
4681 The "off" number is zero, unless 'virtualedit' is used. Then
4682 it is the offset in screen columns from the start of the
4683 character. E.g., a position within a <Tab> or after the last
4684 character.
zeertzjq02f3eba2024-06-12 20:45:24 +02004685
4686 For getting the cursor position see |getcurpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004687 The column number in the returned List is the byte position
4688 within the line. To get the character position in the line,
4689 use |getcharpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02004690
4691 Note that for '< and '> Visual mode matters: when it is "V"
4692 (visual line mode) the column of '< is zero and the column of
4693 '> is a large number equal to |v:maxcol|.
naohiro ono56200ee2022-01-01 14:59:44 +00004694 A very large column number equal to |v:maxcol| can be returned,
4695 in which case it means "after the end of the line".
Bram Moolenaar016188f2022-06-06 20:52:59 +01004696 If {expr} is invalid, returns a list with all zeros.
zeertzjq02f3eba2024-06-12 20:45:24 +02004697
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004698 This can be used to save and restore the position of a mark: >
4699 let save_a_mark = getpos("'a")
4700 ...
4701 call setpos("'a", save_a_mark)
zeertzjqd353d272024-06-13 23:00:25 +08004702<
4703 Also see |getcharpos()|, |getcurpos()| and |setpos()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004704
4705 Can also be used as a |method|: >
4706 GetMark()->getpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004707<
4708 Return type: list<number>
4709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004710
4711getqflist([{what}]) *getqflist()*
4712 Returns a |List| with all the current quickfix errors. Each
4713 list item is a dictionary with these entries:
4714 bufnr number of buffer that has the file name, use
4715 bufname() to get the name
4716 module module name
4717 lnum line number in the buffer (first line is 1)
4718 end_lnum
4719 end of line number if the item is multiline
4720 col column number (first column is 1)
4721 end_col end of column number if the item has range
4722 vcol |TRUE|: "col" is visual column
4723 |FALSE|: "col" is byte index
4724 nr error number
h-east84ac2122024-06-17 18:12:30 +02004725 pattern search pattern used to locate the error
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004726 text description of the error
4727 type type of the error, 'E', '1', etc.
4728 valid |TRUE|: recognized error message
h_east596a9f22023-11-21 21:24:23 +09004729 user_data
4730 custom data associated with the item, can be
Tom Praschanca6ac992023-08-11 23:26:12 +02004731 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004732
4733 When there is no error list or it's empty, an empty list is
4734 returned. Quickfix list entries with a non-existing buffer
4735 number are returned with "bufnr" set to zero (Note: some
4736 functions accept buffer number zero for the alternate buffer,
4737 you may need to explicitly check for zero).
4738
4739 Useful application: Find pattern matches in multiple files and
4740 do something with them: >
4741 :vimgrep /theword/jg *.c
4742 :for d in getqflist()
4743 : echo bufname(d.bufnr) ':' d.lnum '=' d.text
4744 :endfor
4745<
4746 If the optional {what} dictionary argument is supplied, then
4747 returns only the items listed in {what} as a dictionary. The
4748 following string items are supported in {what}:
4749 changedtick get the total number of changes made
4750 to the list |quickfix-changedtick|
4751 context get the |quickfix-context|
4752 efm errorformat to use when parsing "lines". If
4753 not present, then the 'errorformat' option
4754 value is used.
4755 id get information for the quickfix list with
4756 |quickfix-ID|; zero means the id for the
4757 current list or the list specified by "nr"
4758 idx get information for the quickfix entry at this
4759 index in the list specified by 'id' or 'nr'.
4760 If set to zero, then uses the current entry.
4761 See |quickfix-index|
4762 items quickfix list entries
4763 lines parse a list of lines using 'efm' and return
4764 the resulting entries. Only a |List| type is
4765 accepted. The current quickfix list is not
4766 modified. See |quickfix-parse|.
4767 nr get information for this quickfix list; zero
4768 means the current quickfix list and "$" means
4769 the last quickfix list
4770 qfbufnr number of the buffer displayed in the quickfix
4771 window. Returns 0 if the quickfix buffer is
4772 not present. See |quickfix-buffer|.
4773 size number of entries in the quickfix list
4774 title get the list title |quickfix-title|
4775 winid get the quickfix |window-ID|
4776 all all of the above quickfix properties
4777 Non-string items in {what} are ignored. To get the value of a
4778 particular item, set it to zero.
4779 If "nr" is not present then the current quickfix list is used.
4780 If both "nr" and a non-zero "id" are specified, then the list
4781 specified by "id" is used.
4782 To get the number of lists in the quickfix stack, set "nr" to
4783 "$" in {what}. The "nr" value in the returned dictionary
4784 contains the quickfix stack size.
4785 When "lines" is specified, all the other items except "efm"
4786 are ignored. The returned dictionary contains the entry
4787 "items" with the list of entries.
4788
4789 The returned dictionary contains the following entries:
4790 changedtick total number of changes made to the
4791 list |quickfix-changedtick|
4792 context quickfix list context. See |quickfix-context|
4793 If not present, set to "".
4794 id quickfix list ID |quickfix-ID|. If not
4795 present, set to 0.
4796 idx index of the quickfix entry in the list. If not
4797 present, set to 0.
4798 items quickfix list entries. If not present, set to
4799 an empty list.
4800 nr quickfix list number. If not present, set to 0
4801 qfbufnr number of the buffer displayed in the quickfix
4802 window. If not present, set to 0.
4803 size number of entries in the quickfix list. If not
4804 present, set to 0.
4805 title quickfix list title text. If not present, set
4806 to "".
4807 winid quickfix |window-ID|. If not present, set to 0
4808
4809 Examples (See also |getqflist-examples|): >
4810 :echo getqflist({'all': 1})
4811 :echo getqflist({'nr': 2, 'title': 1})
4812 :echo getqflist({'lines' : ["F1:10:L10"]})
4813<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004814 Return type: list<dict<any>> or list<any>
4815
4816
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004817getreg([{regname} [, 1 [, {list}]]]) *getreg()*
4818 The result is a String, which is the contents of register
4819 {regname}. Example: >
4820 :let cliptext = getreg('*')
4821< When register {regname} was not set the result is an empty
4822 string.
Bram Moolenaara2baa732022-02-04 16:09:54 +00004823 The {regname} argument must be a string. *E1162*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004824
4825 getreg('=') returns the last evaluated value of the expression
4826 register. (For use in maps.)
4827 getreg('=', 1) returns the expression itself, so that it can
4828 be restored with |setreg()|. For other registers the extra
4829 argument is ignored, thus you can always give it.
4830
4831 If {list} is present and |TRUE|, the result type is changed
4832 to |List|. Each list item is one text line. Use it if you care
4833 about zero bytes possibly present inside register: without
4834 third argument both NLs and zero bytes are represented as NLs
4835 (see |NL-used-for-Nul|).
4836 When the register was not set an empty list is returned.
4837
4838 If {regname} is "", the unnamed register '"' is used.
4839 If {regname} is not specified, |v:register| is used.
4840 In |Vim9-script| {regname} must be one character.
4841
4842 Can also be used as a |method|: >
4843 GetRegname()->getreg()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004844<
4845 Return type: |String|
4846
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004847
4848getreginfo([{regname}]) *getreginfo()*
4849 Returns detailed information about register {regname} as a
4850 Dictionary with the following entries:
4851 regcontents List of lines contained in register
4852 {regname}, like
4853 |getreg|({regname}, 1, 1).
4854 regtype the type of register {regname}, as in
4855 |getregtype()|.
4856 isunnamed Boolean flag, v:true if this register
4857 is currently pointed to by the unnamed
4858 register.
4859 points_to for the unnamed register, gives the
4860 single letter name of the register
4861 currently pointed to (see |quotequote|).
4862 For example, after deleting a line
4863 with `dd`, this field will be "1",
4864 which is the register that got the
4865 deleted text.
4866
4867 The {regname} argument is a string. If {regname} is invalid
4868 or not set, an empty Dictionary will be returned.
4869 If {regname} is "" or "@", the unnamed register '"' is used.
4870 If {regname} is not specified, |v:register| is used.
4871 The returned Dictionary can be passed to |setreg()|.
4872 In |Vim9-script| {regname} must be one character.
4873
4874 Can also be used as a |method|: >
4875 GetRegname()->getreginfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004876<
4877 Return type: dict<any>
4878
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004879
Shougo Matsushita19b71882024-02-28 22:48:12 +01004880getregion({pos1}, {pos2} [, {opts}]) *getregion()*
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004881 Returns the list of strings from {pos1} to {pos2} from a
Shougo Matsushita19b71882024-02-28 22:48:12 +01004882 buffer.
4883
4884 {pos1} and {pos2} must both be |List|s with four numbers.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004885 See |getpos()| for the format of the list. It's possible
4886 to specify positions from a different buffer, but please
zeertzjq0df8f932024-03-07 21:40:53 +01004887 note the limitations at |getregion-notes|.
Shougo Matsushita19b71882024-02-28 22:48:12 +01004888
4889 The optional argument {opts} is a Dict and supports the
4890 following items:
4891
zeertzjqafc22952024-05-24 19:07:12 +02004892 type Specify the region's selection type.
4893 See |getregtype()| for possible values,
zeertzjqdff55a32024-05-25 10:25:36 +02004894 except that the width can be omitted
4895 and an empty string cannot be used.
zeertzjqafc22952024-05-24 19:07:12 +02004896 (default: "v")
Shougo Matsushita19b71882024-02-28 22:48:12 +01004897
zeertzjq87410ab2024-03-02 06:00:23 +08004898 exclusive If |TRUE|, use exclusive selection
zeertzjqafc22952024-05-24 19:07:12 +02004899 for the end position.
zeertzjq87410ab2024-03-02 06:00:23 +08004900 (default: follow 'selection')
Shougo Matsushita19b71882024-02-28 22:48:12 +01004901
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004902 You can get the last selection type by |visualmode()|.
4903 If Visual mode is active, use |mode()| to get the Visual mode
4904 (e.g., in a |:vmap|).
zeertzjq87410ab2024-03-02 06:00:23 +08004905 This function is useful to get text starting and ending in
4906 different columns, such as a |characterwise-visual| selection.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004907
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004908 *getregion-notes*
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004909 Note that:
4910 - Order of {pos1} and {pos2} doesn't matter, it will always
4911 return content from the upper left position to the lower
4912 right position.
zeertzjq87410ab2024-03-02 06:00:23 +08004913 - If 'virtualedit' is enabled and the region is past the end
4914 of the lines, resulting lines are padded with spaces.
4915 - If the region is blockwise and it starts or ends in the
4916 middle of a multi-cell character, it is not included but
4917 its selected part is substituted with spaces.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004918 - If {pos1} and {pos2} are not in the same buffer, an empty
zeertzjq421b5972024-02-22 19:48:06 +01004919 list is returned.
Shougo Matsushita84bf6e62024-03-06 21:10:18 +01004920 - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
zeertzjq0df8f932024-03-07 21:40:53 +01004921 - It is evaluated in current window context, which makes a
4922 difference if the buffer is displayed in a window with
4923 different 'virtualedit' or 'list' values.
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004924
4925 Examples: >
4926 :xnoremap <CR>
Shougo Matsushita19b71882024-02-28 22:48:12 +01004927 \ <Cmd>echow getregion(
4928 \ getpos('v'), getpos('.'), #{ type: mode() })<CR>
Shougo Matsushita3f905ab2024-02-21 00:02:45 +01004929<
4930 Can also be used as a |method|: >
Shougo Matsushita19b71882024-02-28 22:48:12 +01004931 getpos('.')->getregion(getpos("'a"))
zeertzjqd4d12072024-07-16 20:34:16 +02004932<
4933 Return type: list<string>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004934
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004935
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004936getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()*
4937 Same as |getregion()|, but returns a list of positions
4938 describing the buffer text segments bound by {pos1} and
4939 {pos2}.
4940 The segments are a pair of positions for every line: >
4941 [[{start_pos}, {end_pos}], ...]
4942<
4943 The position is a |List| with four numbers:
4944 [bufnum, lnum, col, off]
4945 "bufnum" is the buffer number.
4946 "lnum" and "col" are the position in the buffer. The first
4947 column is 1.
zeertzjqc95e64f2024-05-20 14:00:31 +02004948 If the "off" number of a starting position is non-zero, it is
4949 the offset in screen columns from the start of the character.
4950 E.g., a position within a <Tab> or after the last character.
4951 If the "off" number of an ending position is non-zero, it is
zeertzjq52a6f342024-05-22 16:42:44 +02004952 the offset of the character's first cell not included in the
4953 selection, otherwise all its cells are included.
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004954
zeertzjq2b09de92024-05-24 07:48:51 +02004955 Apart from the options supported by |getregion()|, {opts} also
4956 supports the following:
4957
4958 eol If |TRUE|, indicate positions beyond
4959 the end of a line with "col" values
4960 one more than the length of the line.
4961 If |FALSE|, positions are limited
4962 within their lines, and if a line is
4963 empty or the selection is entirely
4964 beyond the end of a line, a "col"
4965 value of 0 is used for both positions.
4966 (default: |FALSE|)
4967
Shougo Matsushitab4757e62024-05-07 20:49:24 +02004968 Can also be used as a |method|: >
4969 getpos('.')->getregionpos(getpos("'a"))
4970<
zeertzjqd4d12072024-07-16 20:34:16 +02004971 Return type: list<list<list<number>>>
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004972
4973
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004974getregtype([{regname}]) *getregtype()*
4975 The result is a String, which is type of register {regname}.
4976 The value will be one of:
4977 "v" for |characterwise| text
4978 "V" for |linewise| text
4979 "<CTRL-V>{width}" for |blockwise-visual| text
4980 "" for an empty or unknown register
4981 <CTRL-V> is one character with value 0x16.
4982 The {regname} argument is a string. If {regname} is "", the
4983 unnamed register '"' is used. If {regname} is not specified,
4984 |v:register| is used.
4985 In |Vim9-script| {regname} must be one character.
4986
4987 Can also be used as a |method|: >
4988 GetRegname()->getregtype()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02004989<
4990 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00004991
Yee Cheng Chind52fb2f2024-10-31 09:25:09 +01004992
Bram Moolenaar71badf92023-04-22 22:40:14 +01004993getscriptinfo([{opts}]) *getscriptinfo()*
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004994 Returns a |List| with information about all the sourced Vim
Bram Moolenaar753885b2022-08-24 16:30:36 +01004995 scripts in the order they were sourced, like what
4996 `:scriptnames` shows.
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01004997
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01004998 The optional Dict argument {opts} supports the following
4999 optional items:
5000 name Script name match pattern. If specified,
5001 and "sid" is not specified, information about
Bram Moolenaar71badf92023-04-22 22:40:14 +01005002 scripts with a name that match the pattern
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005003 "name" are returned.
5004 sid Script ID |<SID>|. If specified, only
5005 information about the script with ID "sid" is
5006 returned and "name" is ignored.
5007
Yegappan Lakshmananf768c3d2022-08-22 13:15:13 +01005008 Each item in the returned List is a |Dict| with the following
5009 items:
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005010 autoload Set to TRUE for a script that was used with
Bram Moolenaar753885b2022-08-24 16:30:36 +01005011 `import autoload` but was not actually sourced
5012 yet (see |import-autoload|).
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005013 functions List of script-local function names defined in
5014 the script. Present only when a particular
5015 script is specified using the "sid" item in
5016 {opts}.
5017 name Vim script file name.
5018 sid Script ID |<SID>|.
5019 sourced Script ID of the actually sourced script that
Bram Moolenaarfd999452022-08-24 18:30:14 +01005020 this script name links to, if any, otherwise
5021 zero
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005022 variables A dictionary with the script-local variables.
Bram Moolenaarf1dcd142022-12-31 15:30:45 +00005023 Present only when a particular script is
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005024 specified using the "sid" item in {opts}.
5025 Note that this is a copy, the value of
5026 script-local variables cannot be changed using
5027 this dictionary.
h_east59858792023-10-25 22:47:05 +09005028 version Vim script version (|scriptversion|)
Yegappan Lakshmanan520f6ef2022-08-25 17:40:40 +01005029
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005030 Examples: >
5031 :echo getscriptinfo({'name': 'myscript'})
zeertzjqad4881c2024-05-04 15:35:30 +08005032 :echo getscriptinfo({'sid': 15})[0].variables
Yegappan Lakshmanan2f892d82022-08-28 18:52:10 +01005033<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005034 Return type: list<dict<any>>
5035
5036
ichizok663d18d2025-01-02 18:06:00 +01005037getstacktrace() *getstacktrace()*
5038 Returns the current stack trace of Vim scripts.
5039 Stack trace is a |List|, of which each item is a |Dictionary|
5040 with the following items:
zeertzjq6655bef2025-01-06 18:32:13 +01005041 funcref The funcref if the stack is at a function,
5042 otherwise this item is omitted.
ichizok663d18d2025-01-02 18:06:00 +01005043 event The string of the event description if the
zeertzjq6655bef2025-01-06 18:32:13 +01005044 stack is at an autocmd event, otherwise this
5045 item is omitted.
5046 lnum The line number in the script on the stack.
ichizok663d18d2025-01-02 18:06:00 +01005047 filepath The file path of the script on the stack.
5048
5049 Return type: list<dict<any>>
5050
5051
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005052gettabinfo([{tabnr}]) *gettabinfo()*
5053 If {tabnr} is not specified, then information about all the
5054 tab pages is returned as a |List|. Each List item is a
5055 |Dictionary|. Otherwise, {tabnr} specifies the tab page
5056 number and information about that one is returned. If the tab
5057 page does not exist an empty List is returned.
5058
5059 Each List item is a |Dictionary| with the following entries:
5060 tabnr tab page number.
5061 variables a reference to the dictionary with
5062 tabpage-local variables
5063 windows List of |window-ID|s in the tab page.
5064
5065 Can also be used as a |method|: >
5066 GetTabnr()->gettabinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005067<
5068 Return type: list<dict<any>>
5069
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005070
5071gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
5072 Get the value of a tab-local variable {varname} in tab page
5073 {tabnr}. |t:var|
5074 Tabs are numbered starting with one.
5075 The {varname} argument is a string. When {varname} is empty a
5076 dictionary with all tab-local variables is returned.
5077 Note that the name without "t:" must be used.
5078 When the tab or variable doesn't exist {def} or an empty
5079 string is returned, there is no error message.
5080
5081 Can also be used as a |method|: >
5082 GetTabnr()->gettabvar(varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005083<
5084 Return type: any, depending on {varname}
5085
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005086
5087gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
5088 Get the value of window-local variable {varname} in window
5089 {winnr} in tab page {tabnr}.
5090 The {varname} argument is a string. When {varname} is empty a
5091 dictionary with all window-local variables is returned.
5092 When {varname} is equal to "&" get the values of all
5093 window-local options in a |Dictionary|.
5094 Otherwise, when {varname} starts with "&" get the value of a
5095 window-local option.
5096 Note that {varname} must be the name without "w:".
5097 Tabs are numbered starting with one. For the current tabpage
5098 use |getwinvar()|.
5099 {winnr} can be the window number or the |window-ID|.
5100 When {winnr} is zero the current window is used.
5101 This also works for a global option, buffer-local option and
5102 window-local option, but it doesn't work for a global variable
5103 or buffer-local variable.
5104 When the tab, window or variable doesn't exist {def} or an
5105 empty string is returned, there is no error message.
5106 Examples: >
5107 :let list_is_on = gettabwinvar(1, 2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005108 :echo "myvar = " .. gettabwinvar(3, 1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005109<
5110 To obtain all window-local variables use: >
5111 gettabwinvar({tabnr}, {winnr}, '&')
5112
5113< Can also be used as a |method|: >
5114 GetTabnr()->gettabwinvar(winnr, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005115<
5116 Return type: any, depending on {varname}
5117
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005118
5119gettagstack([{winnr}]) *gettagstack()*
5120 The result is a Dict, which is the tag stack of window {winnr}.
5121 {winnr} can be the window number or the |window-ID|.
5122 When {winnr} is not specified, the current window is used.
5123 When window {winnr} doesn't exist, an empty Dict is returned.
5124
5125 The returned dictionary contains the following entries:
5126 curidx Current index in the stack. When at
5127 top of the stack, set to (length + 1).
5128 Index of bottom of the stack is 1.
5129 items List of items in the stack. Each item
5130 is a dictionary containing the
5131 entries described below.
5132 length Number of entries in the stack.
5133
5134 Each item in the stack is a dictionary with the following
5135 entries:
5136 bufnr buffer number of the current jump
5137 from cursor position before the tag jump.
5138 See |getpos()| for the format of the
5139 returned list.
5140 matchnr current matching tag number. Used when
5141 multiple matching tags are found for a
5142 name.
5143 tagname name of the tag
5144
5145 See |tagstack| for more information about the tag stack.
5146
5147 Can also be used as a |method|: >
5148 GetWinnr()->gettagstack()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005149<
5150 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005151
5152
Christ van Willegence0ef912024-06-20 23:41:59 +02005153gettext({text} [, {package}]) *gettext()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005154 Translate String {text} if possible.
RestorerZ96509102024-07-11 21:14:15 +02005155 This is intended for use in Vim scripts. When generating
5156 message translations the {text} is extracted by `xgettext`,
5157 the translator can add translated messages into the .po file
5158 and Vim will lookup the translation when gettext() is called.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005159 For {text} double quoted strings are preferred, because
RestorerZ96509102024-07-11 21:14:15 +02005160 `xgettext` does not support single quoted escaped text.
5161
Christ van Willegence0ef912024-06-20 23:41:59 +02005162 When the {package} is specified, the translation is looked up
RestorerZ96509102024-07-11 21:14:15 +02005163 for that specific package. This is mainly required for
5164 third-party Vim scripts. You need to specify a path to the
5165 translations with the |bindtextdomain()| function before
5166 using the gettext() function.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005167
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005168 Return type: |String|
5169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005170
5171getwininfo([{winid}]) *getwininfo()*
5172 Returns information about windows as a |List| with Dictionaries.
5173
5174 If {winid} is given Information about the window with that ID
5175 is returned, as a |List| with one item. If the window does not
5176 exist the result is an empty list.
5177
5178 Without {winid} information about all the windows in all the
5179 tab pages is returned.
5180
5181 Each List item is a |Dictionary| with the following entries:
5182 botline last complete displayed buffer line
5183 bufnr number of buffer in the window
5184 height window height (excluding winbar)
glepnir0a850672024-11-25 19:39:04 +01005185 leftcol first column displayed; only used when
5186 'wrap' is off
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005187 loclist 1 if showing a location list
5188 {only with the +quickfix feature}
5189 quickfix 1 if quickfix or location list window
5190 {only with the +quickfix feature}
5191 terminal 1 if a terminal window
5192 {only with the +terminal feature}
5193 tabnr tab page number
5194 topline first displayed buffer line
5195 variables a reference to the dictionary with
5196 window-local variables
5197 width window width
5198 winbar 1 if the window has a toolbar, 0
5199 otherwise
5200 wincol leftmost screen column of the window;
5201 "col" from |win_screenpos()|
5202 textoff number of columns occupied by any
5203 'foldcolumn', 'signcolumn' and line
5204 number in front of the text
5205 winid |window-ID|
5206 winnr window number
5207 winrow topmost screen line of the window;
5208 "row" from |win_screenpos()|
5209
5210 Can also be used as a |method|: >
5211 GetWinnr()->getwininfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005212<
5213 Return type: list<dict<any>>
5214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005215
5216getwinpos([{timeout}]) *getwinpos()*
5217 The result is a |List| with two numbers, the result of
5218 |getwinposx()| and |getwinposy()| combined:
5219 [x-pos, y-pos]
5220 {timeout} can be used to specify how long to wait in msec for
5221 a response from the terminal. When omitted 100 msec is used.
5222 Use a longer time for a remote terminal.
5223 When using a value less than 10 and no response is received
5224 within that time, a previously reported position is returned,
5225 if available. This can be used to poll for the position and
5226 do some work in the meantime: >
5227 while 1
5228 let res = getwinpos(1)
5229 if res[0] >= 0
5230 break
5231 endif
5232 " Do some work here
5233 endwhile
5234<
5235
5236 Can also be used as a |method|: >
5237 GetTimeout()->getwinpos()
5238<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005239 Return type: list<number>
5240
5241
5242getwinposx() *getwinposx()*
5243 The result is a Number, which is the X coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005244 the left hand side of the GUI Vim window. Also works for an
5245 xterm (uses a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005246 The result will be -1 if the information is not available
5247 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005248 The value can be used with `:winpos`.
5249
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005250 Return type: |Number|
5251
5252
5253getwinposy() *getwinposy()*
5254 The result is a Number, which is the Y coordinate in pixels of
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005255 the top of the GUI Vim window. Also works for an xterm (uses
5256 a timeout of 100 msec).
lilydjwg6e0a18f2024-01-29 20:54:28 +01005257 The result will be -1 if the information is not available
5258 (e.g. on the Wayland backend).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005259 The value can be used with `:winpos`.
5260
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005261 Return type: |Number|
5262
5263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005264getwinvar({winnr}, {varname} [, {def}]) *getwinvar()*
5265 Like |gettabwinvar()| for the current tabpage.
5266 Examples: >
5267 :let list_is_on = getwinvar(2, '&list')
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005268 :echo "myvar = " .. getwinvar(1, 'myvar')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005269
5270< Can also be used as a |method|: >
5271 GetWinnr()->getwinvar(varname)
5272<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005273 Return type: any, depending on {varname}
5274
5275
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005276glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
5277 Expand the file wildcards in {expr}. See |wildcards| for the
5278 use of special characters.
5279
5280 Unless the optional {nosuf} argument is given and is |TRUE|,
5281 the 'suffixes' and 'wildignore' options apply: Names matching
5282 one of the patterns in 'wildignore' will be skipped and
5283 'suffixes' affect the ordering of matches.
5284 'wildignorecase' always applies.
5285
5286 When {list} is present and it is |TRUE| the result is a |List|
5287 with all matching files. The advantage of using a List is,
5288 you also get filenames containing newlines correctly.
5289 Otherwise the result is a String and when there are several
5290 matches, they are separated by <NL> characters.
5291
5292 If the expansion fails, the result is an empty String or List.
5293
5294 You can also use |readdir()| if you need to do complicated
5295 things, such as limiting the number of matches.
5296
5297 A name for a non-existing file is not included. A symbolic
5298 link is only included if it points to an existing file.
5299 However, when the {alllinks} argument is present and it is
5300 |TRUE| then all symbolic links are included.
5301
5302 For most systems backticks can be used to get files names from
5303 any external command. Example: >
5304 :let tagfiles = glob("`find . -name tags -print`")
5305 :let &tags = substitute(tagfiles, "\n", ",", "g")
5306< The result of the program inside the backticks should be one
5307 item per line. Spaces inside an item are allowed.
5308
5309 See |expand()| for expanding special Vim variables. See
5310 |system()| for getting the raw output of an external command.
5311
5312 Can also be used as a |method|: >
5313 GetExpr()->glob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005314<
5315 Return type: |String| or list<string> or list<any> depending
5316 on {list}
5317
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005318
h-east624bb832024-11-09 18:37:32 +01005319glob2regpat({string}) *glob2regpat()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005320 Convert a file pattern, as used by glob(), into a search
5321 pattern. The result can be used to match with a string that
5322 is a file name. E.g. >
5323 if filename =~ glob2regpat('Make*.mak')
5324< This is equivalent to: >
5325 if filename =~ '^Make.*\.mak$'
5326< When {string} is an empty string the result is "^$", match an
5327 empty string.
5328 Note that the result depends on the system. On MS-Windows
5329 a backslash usually means a path separator.
5330
5331 Can also be used as a |method|: >
5332 GetExpr()->glob2regpat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005333<
5334 Return type: |String|
5335
5336 *globpath()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005337globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
5338 Perform glob() for String {expr} on all directories in {path}
5339 and concatenate the results. Example: >
5340 :echo globpath(&rtp, "syntax/c.vim")
5341<
5342 {path} is a comma-separated list of directory names. Each
5343 directory name is prepended to {expr} and expanded like with
5344 |glob()|. A path separator is inserted when needed.
5345 To add a comma inside a directory name escape it with a
5346 backslash. Note that on MS-Windows a directory may have a
5347 trailing backslash, remove it if you put a comma after it.
5348 If the expansion fails for one of the directories, there is no
5349 error message.
5350
5351 Unless the optional {nosuf} argument is given and is |TRUE|,
5352 the 'suffixes' and 'wildignore' options apply: Names matching
5353 one of the patterns in 'wildignore' will be skipped and
5354 'suffixes' affect the ordering of matches.
5355
5356 When {list} is present and it is |TRUE| the result is a |List|
5357 with all matching files. The advantage of using a List is, you
5358 also get filenames containing newlines correctly. Otherwise
5359 the result is a String and when there are several matches,
5360 they are separated by <NL> characters. Example: >
5361 :echo globpath(&rtp, "syntax/c.vim", 0, 1)
5362<
5363 {alllinks} is used as with |glob()|.
5364
5365 The "**" item can be used to search in a directory tree.
5366 For example, to find all "README.txt" files in the directories
5367 in 'runtimepath' and below: >
5368 :echo globpath(&rtp, "**/README.txt")
5369< Upwards search and limiting the depth of "**" is not
5370 supported, thus using 'path' will not always work properly.
5371
5372 Can also be used as a |method|, the base is passed as the
5373 second argument: >
5374 GetExpr()->globpath(&rtp)
5375<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005376 Return type: |String| or list<string> or list<any> depending
5377 on {list}
5378
5379
5380has({feature} [, {check}]) *has()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005381 When {check} is omitted or is zero: The result is a Number,
5382 which is 1 if the feature {feature} is supported, zero
5383 otherwise. The {feature} argument is a string, case is
5384 ignored. See |feature-list| below.
5385
5386 When {check} is present and not zero: The result is a Number,
5387 which is 1 if the feature {feature} could ever be supported,
5388 zero otherwise. This is useful to check for a typo in
5389 {feature} and to detect dead code. Keep in mind that an older
5390 Vim version will not know about a feature added later and
5391 features that have been abandoned will not be known by the
5392 current Vim version.
5393
5394 Also see |exists()| and |exists_compiled()|.
5395
5396 Note that to skip code that has a syntax error when the
5397 feature is not available, Vim may skip the rest of the line
5398 and miss a following `endif`. Therefore put the `endif` on a
5399 separate line: >
5400 if has('feature')
5401 let x = this->breaks->without->the->feature
5402 endif
5403< If the `endif` would be moved to the second line as "| endif" it
5404 would not be found.
5405
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005406 Return type: |Number|
5407
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005408
5409has_key({dict}, {key}) *has_key()*
5410 The result is a Number, which is TRUE if |Dictionary| {dict}
Bram Moolenaare8008642022-08-19 17:15:35 +01005411 has an entry with key {key}. FALSE otherwise.
5412 The {key} argument is a string. In |Vim9| script a number is
5413 also accepted (and converted to a string) but no other types.
5414 In legacy script the usual automatic conversion to string is
5415 done.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005416
5417 Can also be used as a |method|: >
5418 mydict->has_key(key)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005419<
5420 Return type: |Number|
5421
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005422
5423haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()*
5424 The result is a Number:
5425 1 when the window has set a local directory via |:lcd|
5426 2 when the tab-page has set a local directory via |:tcd|
5427 0 otherwise.
5428
5429 Without arguments use the current window.
5430 With {winnr} use this window in the current tab page.
5431 With {winnr} and {tabnr} use the window in the specified tab
5432 page.
5433 {winnr} can be the window number or the |window-ID|.
5434 If {winnr} is -1 it is ignored and only the tabpage is used.
5435 Return 0 if the arguments are invalid.
5436 Examples: >
5437 if haslocaldir() == 1
5438 " window local directory case
5439 elseif haslocaldir() == 2
5440 " tab-local directory case
5441 else
5442 " global directory case
5443 endif
5444
5445 " current window
5446 :echo haslocaldir()
5447 :echo haslocaldir(0)
5448 :echo haslocaldir(0, 0)
5449 " window n in current tab page
5450 :echo haslocaldir(n)
5451 :echo haslocaldir(n, 0)
5452 " window n in tab page m
5453 :echo haslocaldir(n, m)
5454 " tab page m
5455 :echo haslocaldir(-1, m)
5456<
5457 Can also be used as a |method|: >
5458 GetWinnr()->haslocaldir()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005459<
5460 Return type: |Number|
5461
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005462
5463hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
5464 The result is a Number, which is TRUE if there is a mapping
5465 that contains {what} in somewhere in the rhs (what it is
5466 mapped to) and this mapping exists in one of the modes
5467 indicated by {mode}.
5468 The arguments {what} and {mode} are strings.
5469 When {abbr} is there and it is |TRUE| use abbreviations
5470 instead of mappings. Don't forget to specify Insert and/or
5471 Command-line mode.
5472 Both the global mappings and the mappings local to the current
5473 buffer are checked for a match.
5474 If no matching mapping is found FALSE is returned.
5475 The following characters are recognized in {mode}:
5476 n Normal mode
5477 v Visual and Select mode
5478 x Visual mode
5479 s Select mode
5480 o Operator-pending mode
5481 i Insert mode
5482 l Language-Argument ("r", "f", "t", etc.)
5483 c Command-line mode
5484 When {mode} is omitted, "nvo" is used.
5485
5486 This function is useful to check if a mapping already exists
5487 to a function in a Vim script. Example: >
5488 :if !hasmapto('\ABCdoit')
5489 : map <Leader>d \ABCdoit
5490 :endif
5491< This installs the mapping to "\ABCdoit" only if there isn't
5492 already a mapping to "\ABCdoit".
5493
5494 Can also be used as a |method|: >
5495 GetRHS()->hasmapto()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005496<
5497 Return type: |Number|
5498
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005499
5500histadd({history}, {item}) *histadd()*
5501 Add the String {item} to the history {history} which can be
5502 one of: *hist-names*
5503 "cmd" or ":" command line history
5504 "search" or "/" search pattern history
5505 "expr" or "=" typed expression history
5506 "input" or "@" input line history
5507 "debug" or ">" debug command history
5508 empty the current or last used history
5509 The {history} string does not need to be the whole name, one
5510 character is sufficient.
5511 If {item} does already exist in the history, it will be
5512 shifted to become the newest entry.
5513 The result is a Number: TRUE if the operation was successful,
5514 otherwise FALSE is returned.
5515
5516 Example: >
5517 :call histadd("input", strftime("%Y %b %d"))
5518 :let date=input("Enter date: ")
5519< This function is not available in the |sandbox|.
5520
5521 Can also be used as a |method|, the base is passed as the
5522 second argument: >
5523 GetHistory()->histadd('search')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005524<
5525 Return type: |Number|
5526
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005527
5528histdel({history} [, {item}]) *histdel()*
5529 Clear {history}, i.e. delete all its entries. See |hist-names|
5530 for the possible values of {history}.
5531
5532 If the parameter {item} evaluates to a String, it is used as a
5533 regular expression. All entries matching that expression will
5534 be removed from the history (if there are any).
5535 Upper/lowercase must match, unless "\c" is used |/\c|.
5536 If {item} evaluates to a Number, it will be interpreted as
5537 an index, see |:history-indexing|. The respective entry will
5538 be removed if it exists.
5539
5540 The result is TRUE for a successful operation, otherwise FALSE
5541 is returned.
5542
5543 Examples:
5544 Clear expression register history: >
5545 :call histdel("expr")
5546<
5547 Remove all entries starting with "*" from the search history: >
5548 :call histdel("/", '^\*')
5549<
5550 The following three are equivalent: >
5551 :call histdel("search", histnr("search"))
5552 :call histdel("search", -1)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005553 :call histdel("search", '^' .. histget("search", -1) .. '$')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005554<
5555 To delete the last search pattern and use the last-but-one for
5556 the "n" command and 'hlsearch': >
5557 :call histdel("search", -1)
5558 :let @/ = histget("search", -1)
5559<
5560 Can also be used as a |method|: >
5561 GetHistory()->histdel()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005562<
5563 Return type: |Number|
5564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005565
5566histget({history} [, {index}]) *histget()*
5567 The result is a String, the entry with Number {index} from
5568 {history}. See |hist-names| for the possible values of
5569 {history}, and |:history-indexing| for {index}. If there is
5570 no such entry, an empty String is returned. When {index} is
5571 omitted, the most recent item from the history is used.
5572
5573 Examples:
5574 Redo the second last search from history. >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005575 :execute '/' .. histget("search", -2)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005576
5577< Define an Ex command ":H {num}" that supports re-execution of
5578 the {num}th entry from the output of |:history|. >
5579 :command -nargs=1 H execute histget("cmd", 0+<args>)
5580<
5581 Can also be used as a |method|: >
5582 GetHistory()->histget()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005583<
5584 Return type: |String|
5585
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005586
5587histnr({history}) *histnr()*
5588 The result is the Number of the current entry in {history}.
5589 See |hist-names| for the possible values of {history}.
5590 If an error occurred, -1 is returned.
5591
5592 Example: >
5593 :let inp_index = histnr("expr")
5594
5595< Can also be used as a |method|: >
5596 GetHistory()->histnr()
5597<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005598 Return type: |Number|
5599
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005600hlexists({name}) *hlexists()*
5601 The result is a Number, which is TRUE if a highlight group
5602 called {name} exists. This is when the group has been
5603 defined in some way. Not necessarily when highlighting has
5604 been defined for it, it may also have been used for a syntax
5605 item.
5606 *highlight_exists()*
5607 Obsolete name: highlight_exists().
5608
5609 Can also be used as a |method|: >
5610 GetName()->hlexists()
5611<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005612 Return type: |Number|
5613
5614
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005615hlget([{name} [, {resolve}]]) *hlget()*
5616 Returns a List of all the highlight group attributes. If the
5617 optional {name} is specified, then returns a List with only
5618 the attributes of the specified highlight group. Returns an
5619 empty List if the highlight group {name} is not present.
5620
5621 If the optional {resolve} argument is set to v:true and the
5622 highlight group {name} is linked to another group, then the
5623 link is resolved recursively and the attributes of the
5624 resolved highlight group are returned.
5625
5626 Each entry in the returned List is a Dictionary with the
5627 following items:
5628 cleared boolean flag, set to v:true if the highlight
5629 group attributes are cleared or not yet
5630 specified. See |highlight-clear|.
5631 cterm cterm attributes. See |highlight-cterm|.
5632 ctermbg cterm background color.
5633 See |highlight-ctermbg|.
5634 ctermfg cterm foreground color.
5635 See |highlight-ctermfg|.
5636 ctermul cterm underline color. See |highlight-ctermul|.
5637 default boolean flag, set to v:true if the highlight
5638 group link is a default link. See
5639 |highlight-default|.
5640 font highlight group font. See |highlight-font|.
5641 gui gui attributes. See |highlight-gui|.
5642 guibg gui background color. See |highlight-guibg|.
5643 guifg gui foreground color. See |highlight-guifg|.
5644 guisp gui special color. See |highlight-guisp|.
5645 id highlight group ID.
5646 linksto linked highlight group name.
5647 See |:highlight-link|.
5648 name highlight group name. See |group-name|.
5649 start start terminal keycode. See |highlight-start|.
5650 stop stop terminal keycode. See |highlight-stop|.
5651 term term attributes. See |highlight-term|.
5652
5653 The 'term', 'cterm' and 'gui' items in the above Dictionary
5654 have a dictionary value with the following optional boolean
5655 items: 'bold', 'standout', 'underline', 'undercurl', 'italic',
5656 'reverse', 'inverse' and 'strikethrough'.
5657
5658 Example(s): >
5659 :echo hlget()
5660 :echo hlget('ModeMsg')
5661 :echo hlget('Number', v:true)
5662<
5663 Can also be used as a |method|: >
5664 GetName()->hlget()
5665<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005666 Return type: list<dict<any>>
5667
5668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005669hlset({list}) *hlset()*
5670 Creates or modifies the attributes of a List of highlight
5671 groups. Each item in {list} is a dictionary containing the
5672 attributes of a highlight group. See |hlget()| for the list of
5673 supported items in this dictionary.
5674
5675 In addition to the items described in |hlget()|, the following
5676 additional items are supported in the dictionary:
5677
5678 force boolean flag to force the creation of
5679 a link for an existing highlight group
5680 with attributes.
5681
5682 The highlight group is identified using the 'name' item and
5683 the 'id' item (if supplied) is ignored. If a highlight group
5684 with a specified name doesn't exist, then it is created.
5685 Otherwise the attributes of an existing highlight group are
5686 modified.
5687
5688 If an empty dictionary value is used for the 'term' or 'cterm'
5689 or 'gui' entries, then the corresponding attributes are
5690 cleared. If the 'cleared' item is set to v:true, then all the
5691 attributes of the highlight group are cleared.
5692
5693 The 'linksto' item can be used to link a highlight group to
5694 another highlight group. See |:highlight-link|.
5695
5696 Returns zero for success, -1 for failure.
5697
5698 Example(s): >
5699 " add bold attribute to the Visual highlight group
5700 :call hlset([#{name: 'Visual',
5701 \ term: #{reverse: 1 , bold: 1}}])
5702 :call hlset([#{name: 'Type', guifg: 'DarkGreen'}])
5703 :let l = hlget()
5704 :call hlset(l)
5705 " clear the Search highlight group
5706 :call hlset([#{name: 'Search', cleared: v:true}])
5707 " clear the 'term' attributes for a highlight group
5708 :call hlset([#{name: 'Title', term: {}}])
5709 " create the MyHlg group linking it to DiffAdd
5710 :call hlset([#{name: 'MyHlg', linksto: 'DiffAdd'}])
5711 " remove the MyHlg group link
5712 :call hlset([#{name: 'MyHlg', linksto: 'NONE'}])
5713 " clear the attributes and a link
5714 :call hlset([#{name: 'MyHlg', cleared: v:true,
5715 \ linksto: 'NONE'}])
5716<
5717 Can also be used as a |method|: >
5718 GetAttrList()->hlset()
5719<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005720 Return type: |Number|
5721
5722hlID({name}) *hlID()*
5723 The result is a Number, which is the ID of the highlight group
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005724 with name {name}. When the highlight group doesn't exist,
5725 zero is returned.
5726 This can be used to retrieve information about the highlight
5727 group. For example, to get the background color of the
5728 "Comment" group: >
5729 :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
5730< *highlightID()*
5731 Obsolete name: highlightID().
5732
5733 Can also be used as a |method|: >
5734 GetName()->hlID()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005735<
5736 Return type: |Number|
5737
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005738
5739hostname() *hostname()*
5740 The result is a String, which is the name of the machine on
5741 which Vim is currently running. Machine names greater than
5742 256 characters long are truncated.
5743
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005744 Return type: |String|
5745
5746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005747iconv({string}, {from}, {to}) *iconv()*
5748 The result is a String, which is the text {string} converted
5749 from encoding {from} to encoding {to}.
5750 When the conversion completely fails an empty string is
5751 returned. When some characters could not be converted they
5752 are replaced with "?".
5753 The encoding names are whatever the iconv() library function
5754 can accept, see ":!man 3 iconv".
5755 Most conversions require Vim to be compiled with the |+iconv|
5756 feature. Otherwise only UTF-8 to latin1 conversion and back
5757 can be done.
5758 This can be used to display messages with special characters,
5759 no matter what 'encoding' is set to. Write the message in
5760 UTF-8 and use: >
5761 echo iconv(utf8_str, "utf-8", &enc)
5762< Note that Vim uses UTF-8 for all Unicode encodings, conversion
5763 from/to UCS-2 is automatically changed to use UTF-8. You
5764 cannot use UCS-2 in a string anyway, because of the NUL bytes.
5765
5766 Can also be used as a |method|: >
5767 GetText()->iconv('latin1', 'utf-8')
5768<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005769 Return type: |String|
5770
5771
h-east624bb832024-11-09 18:37:32 +01005772id({item}) *id()*
Ernie Raelc8e158b2024-07-09 18:39:52 +02005773 The result is a unique String associated with the {item} and
5774 not with the {item}'s contents. It is only valid while the
5775 {item} exists and is referenced. It is valid only in the
5776 instance of vim that produces the result. The whole idea is
5777 that `id({item})` does not change if the contents of {item}
5778 changes. This is useful as a `key` for creating an identity
5779 dictionary, rather than one based on equals.
5780
5781 This operation does not reference {item} and there is no
5782 function to convert the `id` to the {item}. It may be useful to
5783 have a map of `id` to {item}. The following >
5784 var referenceMap: dict<any>
5785 var id = item->id()
5786 referenceMap[id] = item
5787< prevents {item} from being garbage collected and provides a
5788 way to get the {item} from the `id`.
5789
5790 {item} may be a List, Dictionary, Object, Job, Channel or
5791 Blob. If the item is not a permitted type, or it is a null
5792 value, then an empty String is returned.
5793
5794 Can also be used as a |method|: >
5795 GetItem()->id()
5796<
5797 Return type: |String|
5798
5799
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005800indent({lnum}) *indent()*
5801 The result is a Number, which is indent of line {lnum} in the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005802 current buffer. The indent is counted in spaces, the value
5803 of 'tabstop' is relevant. {lnum} is used just like in
5804 |getline()|.
5805 When {lnum} is invalid -1 is returned. In |Vim9| script an
5806 error is given.
5807
5808 Can also be used as a |method|: >
5809 GetLnum()->indent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005810<
5811 Return type: |Number|
5812
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005813
5814index({object}, {expr} [, {start} [, {ic}]]) *index()*
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005815 Find {expr} in {object} and return its index. See
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005816 |indexof()| for using a lambda to select the item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005817
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005818 If {object} is a |List| return the lowest index where the item
5819 has a value equal to {expr}. There is no automatic
5820 conversion, so the String "4" is different from the Number 4.
5821 And the number 4 is different from the Float 4.0. The value
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005822 of 'ignorecase' is not used here, case matters as indicated by
5823 the {ic} argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005824
5825 If {object} is |Blob| return the lowest index where the byte
5826 value is equal to {expr}.
5827
5828 If {start} is given then start looking at the item with index
5829 {start} (may be negative for an item relative to the end).
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005830
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005831 When {ic} is given and it is |TRUE|, ignore case. Otherwise
5832 case must match.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005833
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005834 -1 is returned when {expr} is not found in {object}.
5835 Example: >
5836 :let idx = index(words, "the")
5837 :if index(numbers, 123) >= 0
5838
5839< Can also be used as a |method|: >
5840 GetObject()->index(what)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005841<
5842 Return type: |Number|
5843
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005844
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005845indexof({object}, {expr} [, {opts}]) *indexof()*
5846 Returns the index of an item in {object} where {expr} is
5847 v:true. {object} must be a |List| or a |Blob|.
5848
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005849 If {object} is a |List|, evaluate {expr} for each item in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005850 List until the expression is v:true and return the index of
5851 this item.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005852
5853 If {object} is a |Blob| evaluate {expr} for each byte in the
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005854 Blob until the expression is v:true and return the index of
5855 this byte.
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005856
5857 {expr} must be a |string| or |Funcref|.
5858
5859 If {expr} is a |string|: If {object} is a |List|, inside
5860 {expr} |v:key| has the index of the current List item and
5861 |v:val| has the value of the item. If {object} is a |Blob|,
5862 inside {expr} |v:key| has the index of the current byte and
5863 |v:val| has the byte value.
5864
5865 If {expr} is a |Funcref| it must take two arguments:
5866 1. the key or the index of the current item.
5867 2. the value of the current item.
5868 The function must return |TRUE| if the item is found and the
5869 search should stop.
5870
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005871 The optional argument {opts} is a Dict and supports the
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005872 following items:
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005873 startidx start evaluating {expr} at the item with this
5874 index; may be negative for an item relative to
5875 the end
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005876 Returns -1 when {expr} evaluates to v:false for all the items.
5877 Example: >
Yegappan Lakshmanan3fbf6cd2022-08-13 21:35:13 +01005878 :let l = [#{n: 10}, #{n: 20}, #{n: 30}]
5879 :echo indexof(l, "v:val.n == 20")
5880 :echo indexof(l, {i, v -> v.n == 30})
5881 :echo indexof(l, "v:val.n == 20", #{startidx: 1})
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005882
5883< Can also be used as a |method|: >
5884 mylist->indexof(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005885<
5886 Return type: |Number|
5887
Yegappan Lakshmananb2186552022-08-13 13:09:20 +01005888
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005889input({prompt} [, {text} [, {completion}]]) *input()*
5890 The result is a String, which is whatever the user typed on
5891 the command-line. The {prompt} argument is either a prompt
5892 string, or a blank string (for no prompt). A '\n' can be used
5893 in the prompt to start a new line.
5894 The highlighting set with |:echohl| is used for the prompt.
5895 The input is entered just like a command-line, with the same
5896 editing commands and mappings. There is a separate history
5897 for lines typed for input().
5898 Example: >
5899 :if input("Coffee or beer? ") == "beer"
5900 : echo "Cheers!"
5901 :endif
5902<
5903 If the optional {text} argument is present and not empty, this
5904 is used for the default reply, as if the user typed this.
5905 Example: >
5906 :let color = input("Color? ", "white")
5907
5908< The optional {completion} argument specifies the type of
5909 completion supported for the input. Without it completion is
5910 not performed. The supported completion types are the same as
5911 that can be supplied to a user-defined command using the
5912 "-complete=" argument. Refer to |:command-completion| for
5913 more information. Example: >
5914 let fname = input("File: ", "", "file")
5915<
5916 NOTE: This function must not be used in a startup file, for
5917 the versions that only run in GUI mode (e.g., the Win32 GUI).
5918 Note: When input() is called from within a mapping it will
5919 consume remaining characters from that mapping, because a
5920 mapping is handled like the characters were typed.
5921 Use |inputsave()| before input() and |inputrestore()|
5922 after input() to avoid that. Another solution is to avoid
5923 that further characters follow in the mapping, e.g., by using
5924 |:execute| or |:normal|.
5925
5926 Example with a mapping: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00005927 :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005928 :function GetFoo()
5929 : call inputsave()
5930 : let g:Foo = input("enter search pattern: ")
5931 : call inputrestore()
5932 :endfunction
5933
5934< Can also be used as a |method|: >
5935 GetPrompt()->input()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005936<
5937 Return type: |String|
5938
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005939
5940inputdialog({prompt} [, {text} [, {cancelreturn}]]) *inputdialog()*
5941 Like |input()|, but when the GUI is running and text dialogs
5942 are supported, a dialog window pops up to input the text.
5943 Example: >
5944 :let n = inputdialog("value for shiftwidth", shiftwidth())
5945 :if n != ""
5946 : let &sw = n
5947 :endif
5948< When the dialog is cancelled {cancelreturn} is returned. When
5949 omitted an empty string is returned.
5950 Hitting <Enter> works like pressing the OK button. Hitting
5951 <Esc> works like pressing the Cancel button.
5952 NOTE: Command-line completion is not supported.
5953
5954 Can also be used as a |method|: >
5955 GetPrompt()->inputdialog()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005956<
5957 Return type: |String|
5958
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005959
5960inputlist({textlist}) *inputlist()*
5961 {textlist} must be a |List| of strings. This |List| is
5962 displayed, one string per line. The user will be prompted to
5963 enter a number, which is returned.
5964 The user can also select an item by clicking on it with the
5965 mouse, if the mouse is enabled in the command line ('mouse' is
5966 "a" or includes "c"). For the first string 0 is returned.
5967 When clicking above the first item a negative number is
5968 returned. When clicking on the prompt one more than the
5969 length of {textlist} is returned.
5970 Make sure {textlist} has less than 'lines' entries, otherwise
5971 it won't work. It's a good idea to put the entry number at
5972 the start of the string. And put a prompt in the first item.
5973 Example: >
5974 let color = inputlist(['Select color:', '1. red',
5975 \ '2. green', '3. blue'])
5976
5977< Can also be used as a |method|: >
5978 GetChoices()->inputlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005979<
5980 Return type: |Number|
5981
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005982
5983inputrestore() *inputrestore()*
5984 Restore typeahead that was saved with a previous |inputsave()|.
5985 Should be called the same number of times inputsave() is
5986 called. Calling it more often is harmless though.
5987 Returns TRUE when there is nothing to restore, FALSE otherwise.
5988
Christian Brabandt5674c9a2024-06-09 00:13:43 +02005989 Return type: |Number|
5990
5991
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00005992inputsave() *inputsave()*
5993 Preserve typeahead (also from mappings) and clear it, so that
5994 a following prompt gets input from the user. Should be
5995 followed by a matching inputrestore() after the prompt. Can
5996 be used several times, in which case there must be just as
5997 many inputrestore() calls.
5998 Returns TRUE when out of memory, FALSE otherwise.
5999
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006000 Return type: |Number|
6001
6002
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006003inputsecret({prompt} [, {text}]) *inputsecret()*
6004 This function acts much like the |input()| function with but
6005 two exceptions:
6006 a) the user's response will be displayed as a sequence of
6007 asterisks ("*") thereby keeping the entry secret, and
6008 b) the user's response will not be recorded on the input
6009 |history| stack.
6010 The result is a String, which is whatever the user actually
6011 typed on the command-line in response to the issued prompt.
6012 NOTE: Command-line completion is not supported.
6013
6014 Can also be used as a |method|: >
6015 GetPrompt()->inputsecret()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006016<
6017 Return type: |String|
6018
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006019
6020insert({object}, {item} [, {idx}]) *insert()*
6021 When {object} is a |List| or a |Blob| insert {item} at the start
6022 of it.
6023
6024 If {idx} is specified insert {item} before the item with index
6025 {idx}. If {idx} is zero it goes before the first item, just
6026 like omitting {idx}. A negative {idx} is also possible, see
6027 |list-index|. -1 inserts just before the last item.
6028
6029 Returns the resulting |List| or |Blob|. Examples: >
6030 :let mylist = insert([2, 3, 5], 1)
6031 :call insert(mylist, 4, -1)
6032 :call insert(mylist, 6, len(mylist))
6033< The last example can be done simpler with |add()|.
6034 Note that when {item} is a |List| it is inserted as a single
6035 item. Use |extend()| to concatenate |Lists|.
6036
6037 Can also be used as a |method|: >
6038 mylist->insert(item)
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006039<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006040 Return type: |Number|
6041
6042
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006043 *instanceof()* *E614* *E616* *E693*
6044instanceof({object}, {class})
6045 The result is a Number, which is |TRUE| when the {object}
Ernie Rael2025af12023-12-12 16:58:00 +01006046 argument is a direct or indirect instance of a |Class|,
6047 |Interface|, or class |:type| alias specified by {class}.
6048 If {class} is varargs, the function returns |TRUE| when
Yegappan Lakshmanancd39b692023-10-02 12:50:45 -07006049 {object} is an instance of any of the specified classes.
LemonBoyafe04662023-08-23 21:08:11 +02006050 Example: >
Ernie Rael2025af12023-12-12 16:58:00 +01006051 instanceof(animal, Dog, Cat)
LemonBoyafe04662023-08-23 21:08:11 +02006052
6053< Can also be used as a |method|: >
6054 myobj->instanceof(mytype)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006055<
6056 Return type: |Number|
LemonBoyafe04662023-08-23 21:08:11 +02006057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006058interrupt() *interrupt()*
6059 Interrupt script execution. It works more or less like the
6060 user typing CTRL-C, most commands won't execute and control
6061 returns to the user. This is useful to abort execution
6062 from lower down, e.g. in an autocommand. Example: >
6063 :function s:check_typoname(file)
6064 : if fnamemodify(a:file, ':t') == '['
6065 : echomsg 'Maybe typo'
6066 : call interrupt()
6067 : endif
6068 :endfunction
6069 :au BufWritePre * call s:check_typoname(expand('<amatch>'))
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006070<
6071 Return type: void
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006072
6073invert({expr}) *invert()*
6074 Bitwise invert. The argument is converted to a number. A
6075 List, Dict or Float argument causes an error. Example: >
6076 :let bits = invert(bits)
6077< Can also be used as a |method|: >
6078 :let bits = bits->invert()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006079<
6080 Return type: |Number|
6081
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006082
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006083isabsolutepath({path}) *isabsolutepath()*
LemonBoydca1d402022-04-28 15:26:33 +01006084 The result is a Number, which is |TRUE| when {path} is an
6085 absolute path.
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006086 On Unix, a path is considered absolute when it starts with '/'.
LemonBoydca1d402022-04-28 15:26:33 +01006087 On MS-Windows, it is considered absolute when it starts with an
6088 optional drive prefix and is followed by a '\' or '/'. UNC paths
6089 are always absolute.
6090 Example: >
6091 echo isabsolutepath('/usr/share/') " 1
6092 echo isabsolutepath('./foobar') " 0
6093 echo isabsolutepath('C:\Windows') " 1
6094 echo isabsolutepath('foobar') " 0
6095 echo isabsolutepath('\\remote\file') " 1
Bram Moolenaar8a3b8052022-06-26 12:21:15 +01006096<
LemonBoydca1d402022-04-28 15:26:33 +01006097 Can also be used as a |method|: >
6098 GetName()->isabsolutepath()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006099<
6100 Return type: |Number|
LemonBoydca1d402022-04-28 15:26:33 +01006101
6102
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006103isdirectory({directory}) *isdirectory()*
6104 The result is a Number, which is |TRUE| when a directory
6105 with the name {directory} exists. If {directory} doesn't
6106 exist, or isn't a directory, the result is |FALSE|. {directory}
6107 is any expression, which is used as a String.
6108
6109 Can also be used as a |method|: >
6110 GetName()->isdirectory()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006111<
6112 Return type: |Number|
6113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006114
6115isinf({expr}) *isinf()*
6116 Return 1 if {expr} is a positive infinity, or -1 a negative
6117 infinity, otherwise 0. >
6118 :echo isinf(1.0 / 0.0)
6119< 1 >
6120 :echo isinf(-1.0 / 0.0)
6121< -1
6122
6123 Can also be used as a |method|: >
6124 Compute()->isinf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006125<
6126 Return type: |Number|
6127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006128
6129islocked({expr}) *islocked()* *E786*
6130 The result is a Number, which is |TRUE| when {expr} is the
6131 name of a locked variable.
6132 The string argument {expr} must be the name of a variable,
6133 |List| item or |Dictionary| entry, not the variable itself!
6134 Example: >
6135 :let alist = [0, ['a', 'b'], 2, 3]
6136 :lockvar 1 alist
6137 :echo islocked('alist') " 1
6138 :echo islocked('alist[1]') " 0
6139
Bram Moolenaar9da17d72022-02-09 21:50:44 +00006140< When {expr} is a variable that does not exist -1 is returned.
6141 If {expr} uses a range, list or dict index that is out of
6142 range or does not exist you get an error message. Use
6143 |exists()| to check for existence.
6144 In Vim9 script it does not work for local function variables.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006145
6146 Can also be used as a |method|: >
6147 GetName()->islocked()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006148<
6149 Return type: |Number|
6150
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006151
6152isnan({expr}) *isnan()*
6153 Return |TRUE| if {expr} is a float with value NaN. >
6154 echo isnan(0.0 / 0.0)
6155< 1
6156
6157 Can also be used as a |method|: >
6158 Compute()->isnan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006159<
6160 Return type: |Number|
6161
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006162
6163items({dict}) *items()*
6164 Return a |List| with all the key-value pairs of {dict}. Each
6165 |List| item is a list with two items: the key of a {dict}
6166 entry and the value of this entry. The |List| is in arbitrary
6167 order. Also see |keys()| and |values()|.
6168 Example: >
6169 for [key, value] in items(mydict)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006170 echo key .. ': ' .. value
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006171 endfor
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006172<
6173 A List or a String argument is also supported. In these
6174 cases, items() returns a List with the index and the value at
6175 the index.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006176
Yegappan Lakshmanan49cdd622023-12-24 11:01:23 +01006177 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006178 mydict->items()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006179<
6180 Return type: list<list<any>> or list<any>
6181
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006182
6183job_ functions are documented here: |job-functions-details|
6184
6185
6186join({list} [, {sep}]) *join()*
6187 Join the items in {list} together into one String.
6188 When {sep} is specified it is put in between the items. If
6189 {sep} is omitted a single space is used.
6190 Note that {sep} is not added at the end. You might want to
6191 add it there too: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006192 let lines = join(mylist, "\n") .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006193< String items are used as-is. |Lists| and |Dictionaries| are
6194 converted into a string like with |string()|.
6195 The opposite function is |split()|.
6196
6197 Can also be used as a |method|: >
6198 mylist->join()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006199<
6200 Return type: |String|
6201
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006202
6203js_decode({string}) *js_decode()*
6204 This is similar to |json_decode()| with these differences:
6205 - Object key names do not have to be in quotes.
6206 - Strings can be in single quotes.
6207 - Empty items in an array (between two commas) are allowed and
6208 result in v:none items.
6209
6210 Can also be used as a |method|: >
6211 ReadObject()->js_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006212<
6213 Return type: any, depending on {varname}
6214
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006215
6216js_encode({expr}) *js_encode()*
6217 This is similar to |json_encode()| with these differences:
6218 - Object key names are not in quotes.
6219 - v:none items in an array result in an empty item between
6220 commas.
6221 For example, the Vim object:
6222 [1,v:none,{"one":1},v:none] ~
6223 Will be encoded as:
6224 [1,,{one:1},,] ~
6225 While json_encode() would produce:
6226 [1,null,{"one":1},null] ~
6227 This encoding is valid for JavaScript. It is more efficient
6228 than JSON, especially when using an array with optional items.
6229
6230 Can also be used as a |method|: >
6231 GetObject()->js_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006232<
6233 Return type: |String|
6234
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006235
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00006236json_decode({string}) *json_decode()* *E491*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006237 This parses a JSON formatted string and returns the equivalent
6238 in Vim values. See |json_encode()| for the relation between
6239 JSON and Vim values.
6240 The decoding is permissive:
6241 - A trailing comma in an array and object is ignored, e.g.
6242 "[1, 2, ]" is the same as "[1, 2]".
6243 - Integer keys are accepted in objects, e.g. {1:2} is the
6244 same as {"1":2}.
6245 - More floating point numbers are recognized, e.g. "1." for
6246 "1.0", or "001.2" for "1.2". Special floating point values
6247 "Infinity", "-Infinity" and "NaN" (capitalization ignored)
6248 are accepted.
6249 - Leading zeroes in integer numbers are ignored, e.g. "012"
6250 for "12" or "-012" for "-12".
6251 - Capitalization is ignored in literal names null, true or
6252 false, e.g. "NULL" for "null", "True" for "true".
6253 - Control characters U+0000 through U+001F which are not
6254 escaped in strings are accepted, e.g. " " (tab
6255 character in string) for "\t".
6256 - An empty JSON expression or made of only spaces is accepted
6257 and results in v:none.
6258 - Backslash in an invalid 2-character sequence escape is
6259 ignored, e.g. "\a" is decoded as "a".
6260 - A correct surrogate pair in JSON strings should normally be
6261 a 12 character sequence such as "\uD834\uDD1E", but
6262 json_decode() silently accepts truncated surrogate pairs
6263 such as "\uD834" or "\uD834\u"
6264 *E938*
6265 A duplicate key in an object, valid in rfc7159, is not
6266 accepted by json_decode() as the result must be a valid Vim
6267 type, e.g. this fails: {"a":"b", "a":"c"}
6268
6269 Can also be used as a |method|: >
6270 ReadObject()->json_decode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006271<
6272 Return type: any, depending on {varname}
6273
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006274
6275json_encode({expr}) *json_encode()*
6276 Encode {expr} as JSON and return this as a string.
6277 The encoding is specified in:
6278 https://tools.ietf.org/html/rfc7159.html
Bram Moolenaara2baa732022-02-04 16:09:54 +00006279 Vim values are converted as follows: *E1161*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006280 |Number| decimal number
6281 |Float| floating point number
6282 Float nan "NaN"
6283 Float inf "Infinity"
6284 Float -inf "-Infinity"
6285 |String| in double quotes (possibly null)
6286 |Funcref| not possible, error
6287 |List| as an array (possibly null); when
6288 used recursively: []
6289 |Dict| as an object (possibly null); when
6290 used recursively: {}
6291 |Blob| as an array of the individual bytes
6292 v:false "false"
6293 v:true "true"
6294 v:none "null"
6295 v:null "null"
6296 Note that NaN and Infinity are passed on as values. This is
6297 missing in the JSON standard, but several implementations do
6298 allow it. If not then you will get an error.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01006299 If a string contains an illegal character then the replacement
6300 character 0xfffd is used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006301
6302 Can also be used as a |method|: >
6303 GetObject()->json_encode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006304<
6305 Return type: |String|
6306
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006307
6308keys({dict}) *keys()*
6309 Return a |List| with all the keys of {dict}. The |List| is in
6310 arbitrary order. Also see |items()| and |values()|.
6311
6312 Can also be used as a |method|: >
6313 mydict->keys()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006314<
6315 Return type: list<string>
6316
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006317
zeertzjqcdc83932022-09-12 13:38:41 +01006318keytrans({string}) *keytrans()*
6319 Turn the internal byte representation of keys into a form that
6320 can be used for |:map|. E.g. >
6321 :let xx = "\<C-Home>"
6322 :echo keytrans(xx)
6323< <C-Home>
6324
6325 Can also be used as a |method|: >
6326 "\<C-Home>"->keytrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006327<
6328 Return type: |String|
zeertzjqcdc83932022-09-12 13:38:41 +01006329
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006330
6331len({expr}) *len()* *E701*
6332 The result is a Number, which is the length of the argument.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006333 When {expr} is a String or a Number the length in bytes is
6334 used, as with |strlen()|.
6335 When {expr} is a |List| the number of items in the |List| is
6336 returned.
6337 When {expr} is a |Blob| the number of bytes is returned.
6338 When {expr} is a |Dictionary| the number of entries in the
6339 |Dictionary| is returned.
mityu7f0bba22024-03-29 10:14:41 +01006340 When {expr} is an |Object|, invokes the len() method in the
6341 object (if present) to get the length (|object-len()|).
6342 Otherwise returns zero.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006343
6344 Can also be used as a |method|: >
6345 mylist->len()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006346<
6347 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006348
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006349
6350 *libcall()* *E364* *E368*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006351libcall({libname}, {funcname}, {argument})
6352 Call function {funcname} in the run-time library {libname}
6353 with single argument {argument}.
6354 This is useful to call functions in a library that you
6355 especially made to be used with Vim. Since only one argument
6356 is possible, calling standard library functions is rather
6357 limited.
6358 The result is the String returned by the function. If the
6359 function returns NULL, this will appear as an empty string ""
6360 to Vim.
6361 If the function returns a number, use libcallnr()!
6362 If {argument} is a number, it is passed to the function as an
6363 int; if {argument} is a string, it is passed as a
6364 null-terminated string.
6365 This function will fail in |restricted-mode|.
6366
6367 libcall() allows you to write your own 'plug-in' extensions to
6368 Vim without having to recompile the program. It is NOT a
6369 means to call system functions! If you try to do so Vim will
6370 very probably crash.
6371
6372 For Win32, the functions you write must be placed in a DLL
6373 and use the normal C calling convention (NOT Pascal which is
6374 used in Windows System DLLs). The function must take exactly
6375 one parameter, either a character pointer or a long integer,
6376 and must return a character pointer or NULL. The character
6377 pointer returned must point to memory that will remain valid
6378 after the function has returned (e.g. in static data in the
6379 DLL). If it points to allocated memory, that memory will
6380 leak away. Using a static buffer in the function should work,
6381 it's then freed when the DLL is unloaded.
6382
6383 WARNING: If the function returns a non-valid pointer, Vim may
6384 crash! This also happens if the function returns a number,
6385 because Vim thinks it's a pointer.
6386 For Win32 systems, {libname} should be the filename of the DLL
6387 without the ".DLL" suffix. A full path is only required if
6388 the DLL is not in the usual places.
6389 For Unix: When compiling your own plugins, remember that the
6390 object code must be compiled as position-independent ('PIC').
6391 {only in Win32 and some Unix versions, when the |+libcall|
6392 feature is present}
6393 Examples: >
6394 :echo libcall("libc.so", "getenv", "HOME")
6395
6396< Can also be used as a |method|, the base is passed as the
6397 third argument: >
6398 GetValue()->libcall("libc.so", "getenv")
6399<
6400 *libcallnr()*
6401libcallnr({libname}, {funcname}, {argument})
6402 Just like |libcall()|, but used for a function that returns an
6403 int instead of a string.
6404 {only in Win32 on some Unix versions, when the |+libcall|
6405 feature is present}
6406 Examples: >
6407 :echo libcallnr("/usr/lib/libc.so", "getpid", "")
6408 :call libcallnr("libc.so", "printf", "Hello World!\n")
6409 :call libcallnr("libc.so", "sleep", 10)
6410<
6411 Can also be used as a |method|, the base is passed as the
6412 third argument: >
6413 GetValue()->libcallnr("libc.so", "printf")
6414<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006415 Return type: |String|
6416
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006417
6418line({expr} [, {winid}]) *line()*
6419 The result is a Number, which is the line number of the file
6420 position given with {expr}. The {expr} argument is a string.
zeertzjq02f3eba2024-06-12 20:45:24 +02006421 See |getpos()| for accepted positions.
6422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006423 To get the column number use |col()|. To get both use
6424 |getpos()|.
zeertzjq02f3eba2024-06-12 20:45:24 +02006425
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006426 With the optional {winid} argument the values are obtained for
6427 that window instead of the current window.
zeertzjq02f3eba2024-06-12 20:45:24 +02006428
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006429 Returns 0 for invalid values of {expr} and {winid}.
zeertzjq02f3eba2024-06-12 20:45:24 +02006430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006431 Examples: >
6432 line(".") line number of the cursor
6433 line(".", winid) idem, in window "winid"
6434 line("'t") line number of mark t
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006435 line("'" .. marker) line number of mark marker
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006436<
6437 To jump to the last known position when opening a file see
6438 |last-position-jump|.
6439
6440 Can also be used as a |method|: >
6441 GetValue()->line()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006442<
6443 Return type: |Number|
6444
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006445
6446line2byte({lnum}) *line2byte()*
6447 Return the byte count from the start of the buffer for line
6448 {lnum}. This includes the end-of-line character, depending on
6449 the 'fileformat' option for the current buffer. The first
6450 line returns 1. 'encoding' matters, 'fileencoding' is ignored.
6451 This can also be used to get the byte count for the line just
6452 below the last line: >
6453 line2byte(line("$") + 1)
6454< This is the buffer size plus one. If 'fileencoding' is empty
6455 it is the file size plus one. {lnum} is used like with
6456 |getline()|. When {lnum} is invalid, or the |+byte_offset|
6457 feature has been disabled at compile time, -1 is returned.
6458 Also see |byte2line()|, |go| and |:goto|.
6459
6460 Can also be used as a |method|: >
6461 GetLnum()->line2byte()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006462<
6463 Return type: |Number|
6464
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006465
6466lispindent({lnum}) *lispindent()*
6467 Get the amount of indent for line {lnum} according the lisp
6468 indenting rules, as with 'lisp'.
6469 The indent is counted in spaces, the value of 'tabstop' is
6470 relevant. {lnum} is used just like in |getline()|.
Bram Moolenaar8e145b82022-05-21 20:17:31 +01006471 When {lnum} is invalid -1 is returned. In |Vim9| script an
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006472 error is given.
6473
6474 Can also be used as a |method|: >
6475 GetLnum()->lispindent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006476<
6477 Return type: |Number|
6478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006479
6480list2blob({list}) *list2blob()*
6481 Return a Blob concatenating all the number values in {list}.
6482 Examples: >
6483 list2blob([1, 2, 3, 4]) returns 0z01020304
6484 list2blob([]) returns 0z
6485< Returns an empty Blob on error. If one of the numbers is
6486 negative or more than 255 error *E1239* is given.
6487
6488 |blob2list()| does the opposite.
6489
6490 Can also be used as a |method|: >
6491 GetList()->list2blob()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006492<
6493 Return type: |Blob|
6494
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006495
6496list2str({list} [, {utf8}]) *list2str()*
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006497 Convert each number in {list} to a character string and
6498 concatenates them all. Examples: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006499 list2str([32]) returns " "
6500 list2str([65, 66, 67]) returns "ABC"
6501< The same can be done (slowly) with: >
6502 join(map(list, {nr, val -> nr2char(val)}), '')
6503< |str2list()| does the opposite.
6504
6505 When {utf8} is omitted or zero, the current 'encoding' is used.
6506 When {utf8} is TRUE, always return UTF-8 characters.
6507 With UTF-8 composing characters work as expected: >
6508 list2str([97, 769]) returns "á"
6509<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006510 Returns an empty string on error.
6511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006512 Can also be used as a |method|: >
6513 GetList()->list2str()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006514<
6515 Return type: |String|
6516
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006517
6518listener_add({callback} [, {buf}]) *listener_add()*
6519 Add a callback function that will be invoked when changes have
6520 been made to buffer {buf}.
6521 {buf} refers to a buffer name or number. For the accepted
6522 values, see |bufname()|. When {buf} is omitted the current
6523 buffer is used.
6524 Returns a unique ID that can be passed to |listener_remove()|.
6525
6526 The {callback} is invoked with five arguments:
Bram Moolenaar944697a2022-02-20 19:48:20 +00006527 bufnr the buffer that was changed
6528 start first changed line number
6529 end first line number below the change
6530 added number of lines added, negative if lines were
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006531 deleted
Bram Moolenaar944697a2022-02-20 19:48:20 +00006532 changes a List of items with details about the changes
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006533
6534 Example: >
6535 func Listener(bufnr, start, end, added, changes)
6536 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed'
6537 endfunc
6538 call listener_add('Listener', bufnr)
6539
Bram Moolenaar944697a2022-02-20 19:48:20 +00006540< The List cannot be changed. Each item in "changes" is a
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006541 dictionary with these entries:
6542 lnum the first line number of the change
6543 end the first line below the change
6544 added number of lines added; negative if lines were
6545 deleted
6546 col first column in "lnum" that was affected by
6547 the change; one if unknown or the whole line
6548 was affected; this is a byte index, first
6549 character has a value of one.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01006550 When lines are inserted (not when a line is split, e.g. by
6551 typing CR in Insert mode) the values are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006552 lnum line above which the new line is added
6553 end equal to "lnum"
6554 added number of lines inserted
6555 col 1
6556 When lines are deleted the values are:
6557 lnum the first deleted line
6558 end the line below the first deleted line, before
6559 the deletion was done
6560 added negative, number of lines deleted
6561 col 1
6562 When lines are changed:
6563 lnum the first changed line
6564 end the line below the last changed line
6565 added 0
6566 col first column with a change or 1
6567
6568 The entries are in the order the changes were made, thus the
6569 most recent change is at the end. The line numbers are valid
6570 when the callback is invoked, but later changes may make them
6571 invalid, thus keeping a copy for later might not work.
6572
6573 The {callback} is invoked just before the screen is updated,
6574 when |listener_flush()| is called or when a change is being
6575 made that changes the line count in a way it causes a line
6576 number in the list of changes to become invalid.
6577
6578 The {callback} is invoked with the text locked, see
6579 |textlock|. If you do need to make changes to the buffer, use
6580 a timer to do this later |timer_start()|.
6581
6582 The {callback} is not invoked when the buffer is first loaded.
6583 Use the |BufReadPost| autocmd event to handle the initial text
6584 of a buffer.
6585 The {callback} is also not invoked when the buffer is
6586 unloaded, use the |BufUnload| autocmd event for that.
6587
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006588 Returns zero if {callback} or {buf} is invalid.
6589
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006590 Can also be used as a |method|, the base is passed as the
6591 second argument: >
6592 GetBuffer()->listener_add(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006593<
6594 Return type: |Number|
6595
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006596
6597listener_flush([{buf}]) *listener_flush()*
6598 Invoke listener callbacks for buffer {buf}. If there are no
6599 pending changes then no callbacks are invoked.
6600
6601 {buf} refers to a buffer name or number. For the accepted
6602 values, see |bufname()|. When {buf} is omitted the current
6603 buffer is used.
6604
6605 Can also be used as a |method|: >
6606 GetBuffer()->listener_flush()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006607<
6608 Return type: |Number|
6609
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006610
6611listener_remove({id}) *listener_remove()*
6612 Remove a listener previously added with listener_add().
6613 Returns FALSE when {id} could not be found, TRUE when {id} was
6614 removed.
6615
6616 Can also be used as a |method|: >
6617 GetListenerId()->listener_remove()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006618<
6619 Return type: |Number|
6620
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006621
6622localtime() *localtime()*
6623 Return the current time, measured as seconds since 1st Jan
6624 1970. See also |strftime()|, |strptime()| and |getftime()|.
6625
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006626 Return type: |Number|
6627
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006628
6629log({expr}) *log()*
6630 Return the natural logarithm (base e) of {expr} as a |Float|.
6631 {expr} must evaluate to a |Float| or a |Number| in the range
6632 (0, inf].
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006633 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006634 Examples: >
6635 :echo log(10)
6636< 2.302585 >
6637 :echo log(exp(5))
6638< 5.0
6639
6640 Can also be used as a |method|: >
6641 Compute()->log()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006642<
6643 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006644
6645
6646log10({expr}) *log10()*
6647 Return the logarithm of Float {expr} to base 10 as a |Float|.
6648 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006649 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006650 Examples: >
6651 :echo log10(1000)
6652< 3.0 >
6653 :echo log10(0.01)
6654< -2.0
6655
6656 Can also be used as a |method|: >
6657 Compute()->log10()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006658<
6659 Return type: |Float|
6660
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006661
6662luaeval({expr} [, {expr}]) *luaeval()*
6663 Evaluate Lua expression {expr} and return its result converted
6664 to Vim data structures. Second {expr} may hold additional
6665 argument accessible as _A inside first {expr}.
6666 Strings are returned as they are.
6667 Boolean objects are converted to numbers.
Bram Moolenaar73e28dc2022-09-17 21:08:33 +01006668 Numbers are converted to |Float| values.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006669 Dictionaries and lists obtained by vim.eval() are returned
6670 as-is.
6671 Other objects are returned as zero without any errors.
6672 See |lua-luaeval| for more details.
6673 Note that in a `:def` function local variables are not visible
6674 to {expr}.
6675
6676 Can also be used as a |method|: >
6677 GetExpr()->luaeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006678<
6679 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006680
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006681 {only available when compiled with the |+lua| feature}
6682
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006683
6684map({expr1}, {expr2}) *map()*
6685 {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
Bram Moolenaar944697a2022-02-20 19:48:20 +00006686 When {expr1} is a |List| or |Dictionary|, replace each
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006687 item in {expr1} with the result of evaluating {expr2}.
6688 For a |Blob| each byte is replaced.
6689 For a |String|, each character, including composing
6690 characters, is replaced.
6691 If the item type changes you may want to use |mapnew()| to
6692 create a new List or Dictionary. This is required when using
6693 Vim9 script.
6694
6695 {expr2} must be a |String| or |Funcref|.
6696
6697 If {expr2} is a |String|, inside {expr2} |v:val| has the value
6698 of the current item. For a |Dictionary| |v:key| has the key
6699 of the current item and for a |List| |v:key| has the index of
6700 the current item. For a |Blob| |v:key| has the index of the
6701 current byte. For a |String| |v:key| has the index of the
6702 current character.
6703 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006704 :call map(mylist, '"> " .. v:val .. " <"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006705< This puts "> " before and " <" after each item in "mylist".
6706
6707 Note that {expr2} is the result of an expression and is then
6708 used as an expression again. Often it is good to use a
6709 |literal-string| to avoid having to double backslashes. You
6710 still have to double ' quotes
6711
6712 If {expr2} is a |Funcref| it is called with two arguments:
6713 1. The key or the index of the current item.
6714 2. the value of the current item.
Bram Moolenaarb59ae592022-11-23 23:46:31 +00006715 With a legacy script lambda you don't get an error if it only
6716 accepts one argument, but with a Vim9 lambda you get "E1106:
6717 One argument too many", the number of arguments must match.
6718
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006719 The function must return the new value of the item. Example
6720 that changes each value by "key-value": >
6721 func KeyValue(key, val)
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006722 return a:key .. '-' .. a:val
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006723 endfunc
6724 call map(myDict, function('KeyValue'))
6725< It is shorter when using a |lambda|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006726 call map(myDict, {key, val -> key .. '-' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006727< If you do not use "val" you can leave it out: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006728 call map(myDict, {key -> 'item: ' .. key})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006729< If you do not use "key" you can use a short name: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006730 call map(myDict, {_, val -> 'item: ' .. val})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006731<
6732 The operation is done in-place for a |List| and |Dictionary|.
6733 If you want it to remain unmodified make a copy first: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006734 :let tlist = map(copy(mylist), ' v:val .. "\t"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006735
6736< Returns {expr1}, the |List| or |Dictionary| that was filtered,
6737 or a new |Blob| or |String|.
6738 When an error is encountered while evaluating {expr2} no
6739 further items in {expr1} are processed.
6740 When {expr2} is a Funcref errors inside a function are ignored,
6741 unless it was defined with the "abort" flag.
6742
6743 Can also be used as a |method|: >
6744 mylist->map(expr2)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006745<
6746 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6747 depending on {expr1}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006748
6749
6750maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6751 When {dict} is omitted or zero: Return the rhs of mapping
6752 {name} in mode {mode}. The returned String has special
6753 characters translated like in the output of the ":map" command
Ernie Rael09661202022-04-25 14:40:44 +01006754 listing. When {dict} is TRUE a dictionary is returned, see
6755 below. To get a list of all mappings see |maplist()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006756
6757 When there is no mapping for {name}, an empty String is
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01006758 returned if {dict} is FALSE, otherwise returns an empty Dict.
6759 When the mapping for {name} is empty, then "<Nop>" is
6760 returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006761
6762 The {name} can have special key names, like in the ":map"
6763 command.
6764
6765 {mode} can be one of these strings:
6766 "n" Normal
6767 "v" Visual (including Select)
6768 "o" Operator-pending
6769 "i" Insert
6770 "c" Cmd-line
6771 "s" Select
6772 "x" Visual
6773 "l" langmap |language-mapping|
6774 "t" Terminal-Job
6775 "" Normal, Visual and Operator-pending
6776 When {mode} is omitted, the modes for "" are used.
6777
6778 When {abbr} is there and it is |TRUE| use abbreviations
6779 instead of mappings.
6780
6781 When {dict} is there and it is |TRUE| return a dictionary
6782 containing all the information of the mapping with the
Ernie Rael659c2402022-04-24 18:40:28 +01006783 following items: *mapping-dict*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006784 "lhs" The {lhs} of the mapping as it would be typed
6785 "lhsraw" The {lhs} of the mapping as raw bytes
6786 "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate
6787 form, only present when it differs from "lhsraw"
6788 "rhs" The {rhs} of the mapping as typed.
6789 "silent" 1 for a |:map-silent| mapping, else 0.
6790 "noremap" 1 if the {rhs} of the mapping is not remappable.
6791 "script" 1 if mapping was defined with <script>.
6792 "expr" 1 for an expression mapping (|:map-<expr>|).
6793 "buffer" 1 for a buffer local mapping (|:map-local|).
6794 "mode" Modes for which the mapping is defined. In
6795 addition to the modes mentioned above, these
6796 characters will be used:
6797 " " Normal, Visual and Operator-pending
6798 "!" Insert and Commandline mode
6799 (|mapmode-ic|)
6800 "sid" The script local ID, used for <sid> mappings
Bram Moolenaar71badf92023-04-22 22:40:14 +01006801 (|<SID>|). Negative for special contexts.
Bram Moolenaara9528b32022-01-18 20:51:35 +00006802 "scriptversion" The version of the script. 999999 for
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006803 |Vim9| script.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006804 "lnum" The line number in "sid", zero if unknown.
6805 "nowait" Do not wait for other, longer mappings.
6806 (|:map-<nowait>|).
Bram Moolenaar921bde82022-05-09 19:50:35 +01006807 "abbr" True if this is an abbreviation |abbreviations|.
Ernie Raeld8f5f762022-05-10 17:50:39 +01006808 "mode_bits" Vim's internal binary representation of "mode".
6809 |mapset()| ignores this; only "mode" is used.
6810 See |maplist()| for usage examples. The values
6811 are from src/vim.h and may change in the future.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006812
6813 The dictionary can be used to restore a mapping with
6814 |mapset()|.
6815
6816 The mappings local to the current buffer are checked first,
6817 then the global mappings.
6818 This function can be used to map a key even when it's already
6819 mapped, and have it do the original mapping too. Sketch: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00006820 exe 'nnoremap <Tab> ==' .. maparg('<Tab>', 'n')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006821
6822< Can also be used as a |method|: >
6823 GetKey()->maparg('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006824<
6825 Return type: |String| or dict<any> depending on {dict}
6826
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006827
6828mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
6829 Check if there is a mapping that matches with {name} in mode
6830 {mode}. See |maparg()| for {mode} and special names in
6831 {name}.
6832 When {abbr} is there and it is |TRUE| use abbreviations
6833 instead of mappings.
6834 A match happens with a mapping that starts with {name} and
6835 with a mapping which is equal to the start of {name}.
6836
6837 matches mapping "a" "ab" "abc" ~
6838 mapcheck("a") yes yes yes
6839 mapcheck("abc") yes yes yes
6840 mapcheck("ax") yes no no
6841 mapcheck("b") no no no
6842
6843 The difference with maparg() is that mapcheck() finds a
6844 mapping that matches with {name}, while maparg() only finds a
6845 mapping for {name} exactly.
6846 When there is no mapping that starts with {name}, an empty
6847 String is returned. If there is one, the RHS of that mapping
6848 is returned. If there are several mappings that start with
6849 {name}, the RHS of one of them is returned. This will be
6850 "<Nop>" if the RHS is empty.
6851 The mappings local to the current buffer are checked first,
6852 then the global mappings.
6853 This function can be used to check if a mapping can be added
6854 without being ambiguous. Example: >
6855 :if mapcheck("_vv") == ""
6856 : map _vv :set guifont=7x13<CR>
6857 :endif
6858< This avoids adding the "_vv" mapping when there already is a
6859 mapping for "_v" or for "_vvv".
6860
6861 Can also be used as a |method|: >
6862 GetKey()->mapcheck('n')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006863<
6864 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006865
6866
Ernie Rael09661202022-04-25 14:40:44 +01006867maplist([{abbr}]) *maplist()*
6868 Returns a |List| of all mappings. Each List item is a |Dict|,
6869 the same as what is returned by |maparg()|, see
6870 |mapping-dict|. When {abbr} is there and it is |TRUE| use
6871 abbreviations instead of mappings.
6872
6873 Example to show all mappings with 'MultiMatch' in rhs: >
6874 vim9script
6875 echo maplist()->filter(
6876 (_, m) => match(m.rhs, 'MultiMatch') >= 0)
Ernie Raeld8f5f762022-05-10 17:50:39 +01006877< It can be tricky to find mappings for particular |:map-modes|.
6878 |mapping-dict|'s "mode_bits" can simplify this. For example,
6879 the mode_bits for Normal, Insert or Command-line modes are
6880 0x19. To find all the mappings available in those modes you
6881 can do: >
6882 vim9script
6883 var saved_maps = []
6884 for m in maplist()
6885 if and(m.mode_bits, 0x19) != 0
6886 saved_maps->add(m)
6887 endif
6888 endfor
6889 echo saved_maps->mapnew((_, m) => m.lhs)
6890< The values of the mode_bits are defined in Vim's src/vim.h
6891 file and they can be discovered at runtime using
6892 |:map-commands| and "maplist()". Example: >
6893 vim9script
6894 omap xyzzy <Nop>
6895 var op_bit = maplist()->filter(
6896 (_, m) => m.lhs == 'xyzzy')[0].mode_bits
6897 ounmap xyzzy
6898 echo printf("Operator-pending mode bit: 0x%x", op_bit)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006899<
6900 Return type: list<dict<any>>
Ernie Rael09661202022-04-25 14:40:44 +01006901
6902
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006903mapnew({expr1}, {expr2}) *mapnew()*
6904 Like |map()| but instead of replacing items in {expr1} a new
6905 List or Dictionary is created and returned. {expr1} remains
6906 unchanged. Items can still be changed by {expr2}, if you
6907 don't want that use |deepcopy()| first.
6908
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006909 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
6910 depending on {expr1}
6911
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006912
6913mapset({mode}, {abbr}, {dict}) *mapset()*
Ernie Rael51d04d12022-05-04 15:40:22 +01006914mapset({dict})
6915 Restore a mapping from a dictionary, possibly returned by
6916 |maparg()| or |maplist()|. A buffer mapping, when dict.buffer
6917 is true, is set on the current buffer; it is up to the caller
Bram Moolenaar2d8ed022022-05-21 13:08:16 +01006918 to ensure that the intended buffer is the current buffer. This
Ernie Rael51d04d12022-05-04 15:40:22 +01006919 feature allows copying mappings from one buffer to another.
6920 The dict.mode value may restore a single mapping that covers
6921 more than one mode, like with mode values of '!', ' ', 'nox',
6922 or 'v'. *E1276*
6923
6924 In the first form, {mode} and {abbr} should be the same as
6925 for the call to |maparg()|. *E460*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006926 {mode} is used to define the mode in which the mapping is set,
6927 not the "mode" entry in {dict}.
6928 Example for saving and restoring a mapping: >
6929 let save_map = maparg('K', 'n', 0, 1)
6930 nnoremap K somethingelse
6931 ...
6932 call mapset('n', 0, save_map)
6933< Note that if you are going to replace a map in several modes,
Ernie Rael51d04d12022-05-04 15:40:22 +01006934 e.g. with `:map!`, you need to save/restore the mapping for
6935 all of them, when they might differ.
6936
6937 In the second form, with {dict} as the only argument, mode
6938 and abbr are taken from the dict.
6939 Example: >
6940 vim9script
6941 var save_maps = maplist()->filter(
6942 (_, m) => m.lhs == 'K')
6943 nnoremap K somethingelse
6944 cnoremap K somethingelse2
6945 # ...
6946 unmap K
6947 for d in save_maps
6948 mapset(d)
6949 endfor
Christian Brabandt5674c9a2024-06-09 00:13:43 +02006950<
6951 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00006952
6953
6954match({expr}, {pat} [, {start} [, {count}]]) *match()*
6955 When {expr} is a |List| then this returns the index of the
6956 first item where {pat} matches. Each item is used as a
6957 String, |Lists| and |Dictionaries| are used as echoed.
6958
6959 Otherwise, {expr} is used as a String. The result is a
6960 Number, which gives the index (byte offset) in {expr} where
6961 {pat} matches.
6962
6963 A match at the first character or |List| item returns zero.
6964 If there is no match -1 is returned.
6965
6966 For getting submatches see |matchlist()|.
6967 Example: >
6968 :echo match("testing", "ing") " results in 4
6969 :echo match([1, 'x'], '\a') " results in 1
6970< See |string-match| for how {pat} is used.
6971 *strpbrk()*
6972 Vim doesn't have a strpbrk() function. But you can do: >
6973 :let sepidx = match(line, '[.,;: \t]')
6974< *strcasestr()*
6975 Vim doesn't have a strcasestr() function. But you can add
6976 "\c" to the pattern to ignore case: >
6977 :let idx = match(haystack, '\cneedle')
6978<
6979 If {start} is given, the search starts from byte index
6980 {start} in a String or item {start} in a |List|.
6981 The result, however, is still the index counted from the
6982 first character/item. Example: >
6983 :echo match("testing", "ing", 2)
6984< result is again "4". >
6985 :echo match("testing", "ing", 4)
6986< result is again "4". >
6987 :echo match("testing", "t", 2)
6988< result is "3".
6989 For a String, if {start} > 0 then it is like the string starts
6990 {start} bytes later, thus "^" will match at {start}. Except
6991 when {count} is given, then it's like matches before the
6992 {start} byte are ignored (this is a bit complicated to keep it
6993 backwards compatible).
6994 For a String, if {start} < 0, it will be set to 0. For a list
6995 the index is counted from the end.
6996 If {start} is out of range ({start} > strlen({expr}) for a
6997 String or {start} > len({expr}) for a |List|) -1 is returned.
6998
6999 When {count} is given use the {count}'th match. When a match
7000 is found in a String the search for the next one starts one
7001 character further. Thus this example results in 1: >
7002 echo match("testing", "..", 0, 2)
7003< In a |List| the search continues in the next item.
7004 Note that when {count} is added the way {start} works changes,
7005 see above.
7006
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007007 *match-pattern*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007008 See |pattern| for the patterns that are accepted.
7009 The 'ignorecase' option is used to set the ignore-caseness of
7010 the pattern. 'smartcase' is NOT used. The matching is always
7011 done like 'magic' is set and 'cpoptions' is empty.
7012 Note that a match at the start is preferred, thus when the
7013 pattern is using "*" (any number of matches) it tends to find
7014 zero matches at the start instead of a number of matches
7015 further down in the text.
7016
7017 Can also be used as a |method|: >
7018 GetText()->match('word')
7019 GetList()->match('word')
7020<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007021 Return type: |Number|
7022
7023
Bram Moolenaar2f0936c2022-01-08 21:51:59 +00007024 *matchadd()* *E290* *E798* *E799* *E801* *E957*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007025matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
7026 Defines a pattern to be highlighted in the current window (a
7027 "match"). It will be highlighted with {group}. Returns an
7028 identification number (ID), which can be used to delete the
7029 match using |matchdelete()|. The ID is bound to the window.
7030 Matching is case sensitive and magic, unless case sensitivity
7031 or magicness are explicitly overridden in {pattern}. The
7032 'magic', 'smartcase' and 'ignorecase' options are not used.
7033 The "Conceal" value is special, it causes the match to be
7034 concealed.
7035
7036 The optional {priority} argument assigns a priority to the
7037 match. A match with a high priority will have its
7038 highlighting overrule that of a match with a lower priority.
7039 A priority is specified as an integer (negative numbers are no
7040 exception). If the {priority} argument is not specified, the
7041 default priority is 10. The priority of 'hlsearch' is zero,
7042 hence all matches with a priority greater than zero will
7043 overrule it. Syntax highlighting (see 'syntax') is a separate
7044 mechanism, and regardless of the chosen priority a match will
7045 always overrule syntax highlighting.
7046
7047 The optional {id} argument allows the request for a specific
7048 match ID. If a specified ID is already taken, an error
7049 message will appear and the match will not be added. An ID
7050 is specified as a positive integer (zero excluded). IDs 1, 2
7051 and 3 are reserved for |:match|, |:2match| and |:3match|,
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01007052 respectively. 3 is reserved for use by the |matchparen|
7053 plugin.
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01007054 If the {id} argument is not specified or -1, |matchadd()|
Bram Moolenaar9f573a82022-09-29 13:50:08 +01007055 automatically chooses a free ID, which is at least 1000.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007056
7057 The optional {dict} argument allows for further custom
7058 values. Currently this is used to specify a match specific
7059 conceal character that will be shown for |hl-Conceal|
7060 highlighted matches. The dict can have the following members:
7061
7062 conceal Special character to show instead of the
7063 match (only for |hl-Conceal| highlighted
7064 matches, see |:syn-cchar|)
7065 window Instead of the current window use the
7066 window with this number or window ID.
7067
7068 The number of matches is not limited, as it is the case with
7069 the |:match| commands.
7070
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007071 Returns -1 on error.
7072
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007073 Example: >
7074 :highlight MyGroup ctermbg=green guibg=green
7075 :let m = matchadd("MyGroup", "TODO")
7076< Deletion of the pattern: >
7077 :call matchdelete(m)
7078
7079< A list of matches defined by |matchadd()| and |:match| are
7080 available from |getmatches()|. All matches can be deleted in
7081 one operation by |clearmatches()|.
7082
7083 Can also be used as a |method|: >
7084 GetGroup()->matchadd('TODO')
7085<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007086 Return type: |Number|
7087
7088
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007089 *matchaddpos()*
7090matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
7091 Same as |matchadd()|, but requires a list of positions {pos}
7092 instead of a pattern. This command is faster than |matchadd()|
Shane Harperc1b39842024-07-17 19:40:40 +02007093 because it does not handle regular expressions and it sets
7094 buffer line boundaries to redraw screen. It is supposed to be
7095 used when fast match additions and deletions are required, for
7096 example to highlight matching parentheses.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007097
7098 {pos} is a list of positions. Each position can be one of
7099 these:
7100 - A number. This whole line will be highlighted. The first
7101 line has number 1.
7102 - A list with one number, e.g., [23]. The whole line with this
7103 number will be highlighted.
7104 - A list with two numbers, e.g., [23, 11]. The first number is
7105 the line number, the second one is the column number (first
7106 column is 1, the value must correspond to the byte index as
7107 |col()| would return). The character at this position will
7108 be highlighted.
7109 - A list with three numbers, e.g., [23, 11, 3]. As above, but
7110 the third number gives the length of the highlight in bytes.
7111
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007112 Returns -1 on error.
7113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007114 Example: >
7115 :highlight MyGroup ctermbg=green guibg=green
7116 :let m = matchaddpos("MyGroup", [[23, 24], 34])
7117< Deletion of the pattern: >
7118 :call matchdelete(m)
7119
7120< Matches added by |matchaddpos()| are returned by
7121 |getmatches()|.
7122
7123 Can also be used as a |method|: >
7124 GetGroup()->matchaddpos([23, 11])
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007125<
7126 Return type: |Number|
7127
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007128
7129matcharg({nr}) *matcharg()*
7130 Selects the {nr} match item, as set with a |:match|,
7131 |:2match| or |:3match| command.
7132 Return a |List| with two elements:
7133 The name of the highlight group used
7134 The pattern used.
7135 When {nr} is not 1, 2 or 3 returns an empty |List|.
7136 When there is no match item set returns ['', ''].
7137 This is useful to save and restore a |:match|.
7138 Highlighting matches using the |:match| commands are limited
7139 to three matches. |matchadd()| does not have this limitation.
7140
7141 Can also be used as a |method|: >
7142 GetMatch()->matcharg()
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007143<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007144 Return type: list<string>
7145
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007146 *matchbufline()*
7147matchbufline({buf}, {pat}, {lnum}, {end}, [, {dict}])
7148 Returns the |List| of matches in lines from {lnum} to {end} in
7149 buffer {buf} where {pat} matches.
7150
7151 {lnum} and {end} can either be a line number or the string "$"
7152 to refer to the last line in {buf}.
7153
7154 The {dict} argument supports following items:
7155 submatches include submatch information (|/\(|)
7156
7157 For each match, a |Dict| with the following items is returned:
7158 byteidx starting byte index of the match
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007159 lnum line number where there is a match
7160 text matched string
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007161 Note that there can be multiple matches in a single line.
7162
7163 This function works only for loaded buffers. First call
7164 |bufload()| if needed.
7165
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007166 See |match-pattern| for information about the effect of some
7167 option settings on the pattern.
7168
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007169 When {buf} is not a valid buffer, the buffer is not loaded or
7170 {lnum} or {end} is not valid then an error is given and an
7171 empty |List| is returned.
7172
7173 Examples: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007174 " Assuming line 3 in buffer 5 contains "a"
7175 :echo matchbufline(5, '\<\k\+\>', 3, 3)
7176 [{'lnum': 3, 'byteidx': 0, 'text': 'a'}]
7177 " Assuming line 4 in buffer 10 contains "tik tok"
7178 :echo matchbufline(10, '\<\k\+\>', 1, 4)
7179 [{'lnum': 4, 'byteidx': 0, 'text': 'tik'}, {'lnum': 4, 'byteidx': 4, 'text': 'tok'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007180<
7181 If {submatch} is present and is v:true, then submatches like
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007182 "\1", "\2", etc. are also returned. Example: >
7183 " Assuming line 2 in buffer 2 contains "acd"
7184 :echo matchbufline(2, '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2, 2
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007185 \ {'submatches': v:true})
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007186 [{'lnum': 2, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007187< The "submatches" List always contains 9 items. If a submatch
7188 is not found, then an empty string is returned for that
7189 submatch.
7190
7191 Can also be used as a |method|: >
7192 GetBuffer()->matchbufline('mypat', 1, '$')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007193<
7194 Return type: list<dict<any>> or list<any>
7195
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007196
h-east624bb832024-11-09 18:37:32 +01007197matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007198 Deletes a match with ID {id} previously defined by |matchadd()|
7199 or one of the |:match| commands. Returns 0 if successful,
7200 otherwise -1. See example for |matchadd()|. All matches can
7201 be deleted in one operation by |clearmatches()|.
7202 If {win} is specified, use the window with this number or
7203 window ID instead of the current window.
7204
7205 Can also be used as a |method|: >
7206 GetMatch()->matchdelete()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007207<
7208 Return type: |Number|
7209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007210
7211matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
7212 Same as |match()|, but return the index of first character
7213 after the match. Example: >
7214 :echo matchend("testing", "ing")
7215< results in "7".
7216 *strspn()* *strcspn()*
7217 Vim doesn't have a strspn() or strcspn() function, but you can
7218 do it with matchend(): >
7219 :let span = matchend(line, '[a-zA-Z]')
7220 :let span = matchend(line, '[^a-zA-Z]')
7221< Except that -1 is returned when there are no matches.
7222
7223 The {start}, if given, has the same meaning as for |match()|. >
7224 :echo matchend("testing", "ing", 2)
7225< results in "7". >
7226 :echo matchend("testing", "ing", 5)
7227< result is "-1".
7228 When {expr} is a |List| the result is equal to |match()|.
7229
7230 Can also be used as a |method|: >
7231 GetText()->matchend('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007232<
7233 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007234
7235
7236matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()*
7237 If {list} is a list of strings, then returns a |List| with all
7238 the strings in {list} that fuzzy match {str}. The strings in
7239 the returned list are sorted based on the matching score.
7240
7241 The optional {dict} argument always supports the following
7242 items:
zeertzjq9af2bc02022-05-11 14:15:37 +01007243 matchseq When this item is present return only matches
7244 that contain the characters in {str} in the
7245 given sequence.
Kazuyuki Miyagi47f1a552022-06-17 18:30:03 +01007246 limit Maximum number of matches in {list} to be
7247 returned. Zero means no limit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007248
7249 If {list} is a list of dictionaries, then the optional {dict}
7250 argument supports the following additional items:
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007251 key Key of the item which is fuzzy matched against
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007252 {str}. The value of this item should be a
7253 string.
7254 text_cb |Funcref| that will be called for every item
7255 in {list} to get the text for fuzzy matching.
7256 This should accept a dictionary item as the
7257 argument and return the text for that item to
7258 use for fuzzy matching.
7259
7260 {str} is treated as a literal string and regular expression
7261 matching is NOT supported. The maximum supported {str} length
7262 is 256.
7263
7264 When {str} has multiple words each separated by white space,
7265 then the list of strings that have all the words is returned.
7266
7267 If there are no matching strings or there is an error, then an
7268 empty list is returned. If length of {str} is greater than
7269 256, then returns an empty list.
7270
Yasuhiro Matsumoto9029a6e2022-04-16 12:35:35 +01007271 When {limit} is given, matchfuzzy() will find up to this
7272 number of matches in {list} and return them in sorted order.
7273
Bram Moolenaar1588bc82022-03-08 21:35:07 +00007274 Refer to |fuzzy-matching| for more information about fuzzy
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007275 matching strings.
7276
7277 Example: >
7278 :echo matchfuzzy(["clay", "crow"], "cay")
7279< results in ["clay"]. >
7280 :echo getbufinfo()->map({_, v -> v.name})->matchfuzzy("ndl")
7281< results in a list of buffer names fuzzy matching "ndl". >
7282 :echo getbufinfo()->matchfuzzy("ndl", {'key' : 'name'})
7283< results in a list of buffer information dicts with buffer
7284 names fuzzy matching "ndl". >
7285 :echo getbufinfo()->matchfuzzy("spl",
7286 \ {'text_cb' : {v -> v.name}})
7287< results in a list of buffer information dicts with buffer
7288 names fuzzy matching "spl". >
7289 :echo v:oldfiles->matchfuzzy("test")
7290< results in a list of file names fuzzy matching "test". >
7291 :let l = readfile("buffer.c")->matchfuzzy("str")
7292< results in a list of lines in "buffer.c" fuzzy matching "str". >
7293 :echo ['one two', 'two one']->matchfuzzy('two one')
7294< results in ['two one', 'one two']. >
7295 :echo ['one two', 'two one']->matchfuzzy('two one',
7296 \ {'matchseq': 1})
7297< results in ['two one'].
7298
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007299 Return type: list<string> or list<any>
7300
7301
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007302matchfuzzypos({list}, {str} [, {dict}]) *matchfuzzypos()*
7303 Same as |matchfuzzy()|, but returns the list of matched
7304 strings, the list of character positions where characters
7305 in {str} matches and a list of matching scores. You can
7306 use |byteidx()| to convert a character position to a byte
7307 position.
7308
7309 If {str} matches multiple times in a string, then only the
7310 positions for the best match is returned.
7311
7312 If there are no matching strings or there is an error, then a
7313 list with three empty list items is returned.
7314
7315 Example: >
7316 :echo matchfuzzypos(['testing'], 'tsg')
7317< results in [['testing'], [[0, 2, 6]], [99]] >
7318 :echo matchfuzzypos(['clay', 'lacy'], 'la')
7319< results in [['lacy', 'clay'], [[0, 1], [1, 2]], [153, 133]] >
7320 :echo [{'text': 'hello', 'id' : 10}]->matchfuzzypos('ll', {'key' : 'text'})
7321< results in [[{'id': 10, 'text': 'hello'}], [[2, 3]], [127]]
7322
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007323 Return type: list<list<any>>
7324
7325
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007326matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
7327 Same as |match()|, but return a |List|. The first item in the
7328 list is the matched string, same as what matchstr() would
7329 return. Following items are submatches, like "\1", "\2", etc.
7330 in |:substitute|. When an optional submatch didn't match an
7331 empty string is used. Example: >
7332 echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
7333< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
7334 When there is no match an empty list is returned.
7335
7336 You can pass in a List, but that is not very useful.
7337
7338 Can also be used as a |method|: >
7339 GetText()->matchlist('word')
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007340<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007341 Return type: list<string> or list<any>
7342
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007343 *matchstrlist()*
7344matchstrlist({list}, {pat} [, {dict}])
7345 Returns the |List| of matches in {list} where {pat} matches.
7346 {list} is a |List| of strings. {pat} is matched against each
7347 string in {list}.
7348
7349 The {dict} argument supports following items:
7350 submatches include submatch information (|/\(|)
7351
7352 For each match, a |Dict| with the following items is returned:
7353 byteidx starting byte index of the match.
7354 idx index in {list} of the match.
7355 text matched string
7356 submatches a List of submatches. Present only if
7357 "submatches" is set to v:true in {dict}.
7358
Yegappan Lakshmanana35235e2024-02-24 10:09:43 +01007359 See |match-pattern| for information about the effect of some
7360 option settings on the pattern.
7361
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007362 Example: >
Yegappan Lakshmananeb3475d2024-01-15 11:08:25 -08007363 :echo matchstrlist(['tik tok'], '\<\k\+\>')
7364 [{'idx': 0, 'byteidx': 0, 'text': 'tik'}, {'idx': 0, 'byteidx': 4, 'text': 'tok'}]
7365 :echo matchstrlist(['a', 'b'], '\<\k\+\>')
7366 [{'idx': 0, 'byteidx': 0, 'text': 'a'}, {'idx': 1, 'byteidx': 0, 'text': 'b'}]
Yegappan Lakshmananf93b1c82024-01-04 22:28:46 +01007367<
7368 If "submatches" is present and is v:true, then submatches like
7369 "\1", "\2", etc. are also returned. Example: >
7370 :echo matchstrlist(['acd'], '\(a\)\?\(b\)\?\(c\)\?\(.*\)',
7371 \ #{submatches: v:true})
7372 [{'idx': 0, 'byteidx': 0, 'text': 'acd', 'submatches': ['a', '', 'c', 'd', '', '', '', '', '']}]
7373< The "submatches" List always contains 9 items. If a submatch
7374 is not found, then an empty string is returned for that
7375 submatch.
7376
7377 Can also be used as a |method|: >
7378 GetListOfStrings()->matchstrlist('mypat')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007379<
7380 Return type: list<dict<any>> or list<any>
7381
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007382
7383matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
7384 Same as |match()|, but return the matched string. Example: >
7385 :echo matchstr("testing", "ing")
7386< results in "ing".
7387 When there is no match "" is returned.
7388 The {start}, if given, has the same meaning as for |match()|. >
7389 :echo matchstr("testing", "ing", 2)
7390< results in "ing". >
7391 :echo matchstr("testing", "ing", 5)
7392< result is "".
7393 When {expr} is a |List| then the matching item is returned.
7394 The type isn't changed, it's not necessarily a String.
7395
7396 Can also be used as a |method|: >
7397 GetText()->matchstr('word')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007398<
7399 Return type: |String|
7400
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007401
7402matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
7403 Same as |matchstr()|, but return the matched string, the start
7404 position and the end position of the match. Example: >
7405 :echo matchstrpos("testing", "ing")
7406< results in ["ing", 4, 7].
7407 When there is no match ["", -1, -1] is returned.
7408 The {start}, if given, has the same meaning as for |match()|. >
7409 :echo matchstrpos("testing", "ing", 2)
7410< results in ["ing", 4, 7]. >
7411 :echo matchstrpos("testing", "ing", 5)
7412< result is ["", -1, -1].
7413 When {expr} is a |List| then the matching item, the index
7414 of first item where {pat} matches, the start position and the
7415 end position of the match are returned. >
7416 :echo matchstrpos([1, '__x'], '\a')
7417< result is ["x", 1, 2, 3].
7418 The type isn't changed, it's not necessarily a String.
7419
7420 Can also be used as a |method|: >
7421 GetText()->matchstrpos('word')
7422<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007423 Return type: list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007424
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007425
7426max({expr}) *max()*
7427 Return the maximum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007428 echo max([apples, pears, oranges])
7429
7430< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7431 it returns the maximum of all values in the Dictionary.
7432 If {expr} is neither a List nor a Dictionary, or one of the
7433 items in {expr} cannot be used as a Number this results in
7434 an error. An empty |List| or |Dictionary| results in zero.
7435
7436 Can also be used as a |method|: >
7437 mylist->max()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007438<
7439 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007440
7441
7442menu_info({name} [, {mode}]) *menu_info()*
7443 Return information about the specified menu {name} in
7444 mode {mode}. The menu name should be specified without the
7445 shortcut character ('&'). If {name} is "", then the top-level
7446 menu names are returned.
7447
7448 {mode} can be one of these strings:
7449 "n" Normal
7450 "v" Visual (including Select)
7451 "o" Operator-pending
7452 "i" Insert
7453 "c" Cmd-line
7454 "s" Select
7455 "x" Visual
7456 "t" Terminal-Job
7457 "" Normal, Visual and Operator-pending
7458 "!" Insert and Cmd-line
7459 When {mode} is omitted, the modes for "" are used.
7460
7461 Returns a |Dictionary| containing the following items:
7462 accel menu item accelerator text |menu-text|
7463 display display name (name without '&')
7464 enabled v:true if this menu item is enabled
7465 Refer to |:menu-enable|
7466 icon name of the icon file (for toolbar)
7467 |toolbar-icon|
7468 iconidx index of a built-in icon
7469 modes modes for which the menu is defined. In
7470 addition to the modes mentioned above, these
7471 characters will be used:
7472 " " Normal, Visual and Operator-pending
7473 name menu item name.
7474 noremenu v:true if the {rhs} of the menu item is not
7475 remappable else v:false.
7476 priority menu order priority |menu-priority|
7477 rhs right-hand-side of the menu item. The returned
7478 string has special characters translated like
7479 in the output of the ":menu" command listing.
7480 When the {rhs} of a menu item is empty, then
7481 "<Nop>" is returned.
7482 script v:true if script-local remapping of {rhs} is
7483 allowed else v:false. See |:menu-script|.
7484 shortcut shortcut key (character after '&' in
7485 the menu name) |menu-shortcut|
7486 silent v:true if the menu item is created
7487 with <silent> argument |:menu-silent|
7488 submenus |List| containing the names of
7489 all the submenus. Present only if the menu
7490 item has submenus.
7491
7492 Returns an empty dictionary if the menu item is not found.
7493
7494 Examples: >
7495 :echo menu_info('Edit.Cut')
7496 :echo menu_info('File.Save', 'n')
7497
7498 " Display the entire menu hierarchy in a buffer
7499 func ShowMenu(name, pfx)
7500 let m = menu_info(a:name)
7501 call append(line('$'), a:pfx .. m.display)
7502 for child in m->get('submenus', [])
7503 call ShowMenu(a:name .. '.' .. escape(child, '.'),
7504 \ a:pfx .. ' ')
7505 endfor
7506 endfunc
7507 new
7508 for topmenu in menu_info('').submenus
7509 call ShowMenu(topmenu, '')
7510 endfor
7511<
7512 Can also be used as a |method|: >
7513 GetMenuName()->menu_info('v')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007514<
7515 Return type: dict<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007516
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007517min({expr}) *min()*
7518 Return the minimum value of all items in {expr}. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007519 echo min([apples, pears, oranges])
7520
7521< {expr} can be a |List| or a |Dictionary|. For a Dictionary,
7522 it returns the minimum of all values in the Dictionary.
7523 If {expr} is neither a List nor a Dictionary, or one of the
7524 items in {expr} cannot be used as a Number this results in
7525 an error. An empty |List| or |Dictionary| results in zero.
7526
7527 Can also be used as a |method|: >
7528 mylist->min()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007529<
7530 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007531
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007532
7533mkdir({name} [, {flags} [, {prot}]]) *mkdir()* *E739*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007534 Create directory {name}.
7535
Bram Moolenaar938ae282023-02-20 20:44:55 +00007536 When {flags} is present it must be a string. An empty string
7537 has no effect.
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007538
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007539 {flags} can contain these character flags:
7540 "p" intermediate directories will be created as necessary
7541 "D" {name} will be deleted at the end of the current
Christian Brabandtc509c002024-06-14 20:22:05 +02007542 function, but not recursively |:defer|
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007543 "R" {name} will be deleted recursively at the end of the
Christian Brabandtc509c002024-06-14 20:22:05 +02007544 current function |:defer|
Bram Moolenaar938ae282023-02-20 20:44:55 +00007545
Christian Brabandtd6d4e132024-06-13 21:21:41 +02007546 Note that when {name} has more than one part and "p" is used
Bram Moolenaar6f14da12022-09-07 21:30:44 +01007547 some directories may already exist. Only the first one that
7548 is created and what it contains is scheduled to be deleted.
7549 E.g. when using: >
7550 call mkdir('subdir/tmp/autoload', 'pR')
7551< and "subdir" already exists then "subdir/tmp" will be
7552 scheduled for deletion, like with: >
7553 defer delete('subdir/tmp', 'rf')
7554< Note that if scheduling the defer fails the directory is not
7555 deleted. This should only happen when out of memory.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007556
7557 If {prot} is given it is used to set the protection bits of
7558 the new directory. The default is 0o755 (rwxr-xr-x: r/w for
7559 the user, readable for others). Use 0o700 to make it
7560 unreadable for others. This is only used for the last part of
7561 {name}. Thus if you create /tmp/foo/bar then /tmp/foo will be
7562 created with 0o755.
7563 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00007564 :call mkdir($HOME .. "/tmp/foo/bar", "p", 0o700)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007565
7566< This function is not available in the |sandbox|.
7567
7568 There is no error if the directory already exists and the "p"
7569 flag is passed (since patch 8.0.1708). However, without the
7570 "p" option the call will fail.
7571
7572 The function result is a Number, which is TRUE if the call was
7573 successful or FALSE if the directory creation failed or partly
7574 failed.
7575
7576 Not available on all systems. To check use: >
7577 :if exists("*mkdir")
7578
7579< Can also be used as a |method|: >
7580 GetName()->mkdir()
7581<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007582 Return type: |Number|
7583
7584
7585mode([{expr}]) *mode()*
7586 Return a string that indicates the current mode.
Doug Kearns9cd9e752024-04-07 17:42:17 +02007587 If {expr} is supplied and it evaluates to a non-zero Number or
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007588 a non-empty String (|non-zero-arg|), then the full mode is
7589 returned, otherwise only the first letter is returned.
7590 Also see |state()|.
7591
7592 n Normal
7593 no Operator-pending
7594 nov Operator-pending (forced characterwise |o_v|)
7595 noV Operator-pending (forced linewise |o_V|)
7596 noCTRL-V Operator-pending (forced blockwise |o_CTRL-V|);
7597 CTRL-V is one character
7598 niI Normal using |i_CTRL-O| in |Insert-mode|
7599 niR Normal using |i_CTRL-O| in |Replace-mode|
7600 niV Normal using |i_CTRL-O| in |Virtual-Replace-mode|
7601 nt Terminal-Normal (insert goes to Terminal-Job mode)
7602 v Visual by character
7603 vs Visual by character using |v_CTRL-O| in Select mode
7604 V Visual by line
7605 Vs Visual by line using |v_CTRL-O| in Select mode
7606 CTRL-V Visual blockwise
7607 CTRL-Vs Visual blockwise using |v_CTRL-O| in Select mode
7608 s Select by character
7609 S Select by line
7610 CTRL-S Select blockwise
7611 i Insert
7612 ic Insert mode completion |compl-generic|
7613 ix Insert mode |i_CTRL-X| completion
7614 R Replace |R|
7615 Rc Replace mode completion |compl-generic|
7616 Rx Replace mode |i_CTRL-X| completion
7617 Rv Virtual Replace |gR|
7618 Rvc Virtual Replace mode completion |compl-generic|
7619 Rvx Virtual Replace mode |i_CTRL-X| completion
7620 c Command-line editing
h-east71ebf3b2023-09-03 17:12:55 +02007621 ct Command-line editing via Terminal-Job mode
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007622 cr Command-line editing overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007623 cv Vim Ex mode |gQ|
zeertzjqfcaeb3d2023-11-28 20:46:29 +01007624 cvr Vim Ex mode while in overstrike mode |c_<Insert>|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007625 ce Normal Ex mode |Q|
7626 r Hit-enter prompt
7627 rm The -- more -- prompt
7628 r? A |:confirm| query of some sort
7629 ! Shell or external command is executing
7630 t Terminal-Job mode: keys go to the job
7631
7632 This is useful in the 'statusline' option or when used
7633 with |remote_expr()| In most other places it always returns
7634 "c" or "n".
7635 Note that in the future more modes and more specific modes may
7636 be added. It's better not to compare the whole string but only
7637 the leading character(s).
7638 Also see |visualmode()|.
7639
7640 Can also be used as a |method|: >
7641 DoFull()->mode()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007642<
7643 Return type: |String|
7644
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007645
7646mzeval({expr}) *mzeval()*
7647 Evaluate MzScheme expression {expr} and return its result
7648 converted to Vim data structures.
7649 Numbers and strings are returned as they are.
7650 Pairs (including lists and improper lists) and vectors are
7651 returned as Vim |Lists|.
7652 Hash tables are represented as Vim |Dictionary| type with keys
7653 converted to strings.
7654 All other types are converted to string with display function.
7655 Examples: >
7656 :mz (define l (list 1 2 3))
7657 :mz (define h (make-hash)) (hash-set! h "list" l)
7658 :echo mzeval("l")
7659 :echo mzeval("h")
7660<
7661 Note that in a `:def` function local variables are not visible
7662 to {expr}.
7663
7664 Can also be used as a |method|: >
7665 GetExpr()->mzeval()
7666<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007667 Return type: any, depending on {expr}
7668
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007669 {only available when compiled with the |+mzscheme| feature}
7670
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007671
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007672nextnonblank({lnum}) *nextnonblank()*
7673 Return the line number of the first line at or below {lnum}
7674 that is not blank. Example: >
7675 if getline(nextnonblank(1)) =~ "Java"
7676< When {lnum} is invalid or there is no non-blank line at or
7677 below it, zero is returned.
7678 {lnum} is used like with |getline()|.
7679 See also |prevnonblank()|.
7680
7681 Can also be used as a |method|: >
7682 GetLnum()->nextnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007683<
7684 Return type: |Number|
7685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007686
7687nr2char({expr} [, {utf8}]) *nr2char()*
7688 Return a string with a single character, which has the number
7689 value {expr}. Examples: >
7690 nr2char(64) returns "@"
7691 nr2char(32) returns " "
7692< When {utf8} is omitted or zero, the current 'encoding' is used.
7693 Example for "utf-8": >
7694 nr2char(300) returns I with bow character
7695< When {utf8} is TRUE, always return UTF-8 characters.
7696 Note that a NUL character in the file is specified with
7697 nr2char(10), because NULs are represented with newline
7698 characters. nr2char(0) is a real NUL and terminates the
7699 string, thus results in an empty string.
7700 To turn a list of character numbers into a string: >
7701 let list = [65, 66, 67]
7702 let str = join(map(list, {_, val -> nr2char(val)}), '')
7703< Result: "ABC"
7704
7705 Can also be used as a |method|: >
7706 GetNumber()->nr2char()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007707<
7708 Return type: |String|
7709
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007710
7711or({expr}, {expr}) *or()*
7712 Bitwise OR on the two arguments. The arguments are converted
7713 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007714 Also see `and()` and `xor()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007715 Example: >
7716 :let bits = or(bits, 0x80)
7717< Can also be used as a |method|: >
7718 :let bits = bits->or(0x80)
7719
Bram Moolenaar5a6ec102022-05-27 21:58:00 +01007720< Rationale: The reason this is a function and not using the "|"
7721 character like many languages, is that Vi has always used "|"
7722 to separate commands. In many places it would not be clear if
7723 "|" is an operator or a command separator.
7724
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007725 Return type: |Number|
7726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007727
7728pathshorten({path} [, {len}]) *pathshorten()*
7729 Shorten directory names in the path {path} and return the
7730 result. The tail, the file name, is kept as-is. The other
7731 components in the path are reduced to {len} letters in length.
7732 If {len} is omitted or smaller than 1 then 1 is used (single
7733 letters). Leading '~' and '.' characters are kept. Examples: >
7734 :echo pathshorten('~/.vim/autoload/myfile.vim')
7735< ~/.v/a/myfile.vim ~
7736>
7737 :echo pathshorten('~/.vim/autoload/myfile.vim', 2)
7738< ~/.vi/au/myfile.vim ~
7739 It doesn't matter if the path exists or not.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007740 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007741
7742 Can also be used as a |method|: >
7743 GetDirectories()->pathshorten()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007744<
7745 Return type: |String|
7746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007747
7748perleval({expr}) *perleval()*
7749 Evaluate Perl expression {expr} in scalar context and return
7750 its result converted to Vim data structures. If value can't be
7751 converted, it is returned as a string Perl representation.
7752 Note: If you want an array or hash, {expr} must return a
7753 reference to it.
7754 Example: >
7755 :echo perleval('[1 .. 4]')
7756< [1, 2, 3, 4]
7757
7758 Note that in a `:def` function local variables are not visible
7759 to {expr}.
7760
7761 Can also be used as a |method|: >
7762 GetExpr()->perleval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007763<
7764 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007765
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007766 {only available when compiled with the |+perl| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007767
7768
7769popup_ functions are documented here: |popup-functions|
7770
7771
7772pow({x}, {y}) *pow()*
7773 Return the power of {x} to the exponent {y} as a |Float|.
7774 {x} and {y} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01007775 Returns 0.0 if {x} or {y} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007776 Examples: >
7777 :echo pow(3, 3)
7778< 27.0 >
7779 :echo pow(2, 16)
7780< 65536.0 >
7781 :echo pow(32, 0.20)
7782< 2.0
7783
7784 Can also be used as a |method|: >
7785 Compute()->pow(3)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007786<
7787 Return type: |Number|
7788
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007789
7790prevnonblank({lnum}) *prevnonblank()*
7791 Return the line number of the first line at or above {lnum}
7792 that is not blank. Example: >
7793 let ind = indent(prevnonblank(v:lnum - 1))
7794< When {lnum} is invalid or there is no non-blank line at or
7795 above it, zero is returned.
7796 {lnum} is used like with |getline()|.
7797 Also see |nextnonblank()|.
7798
7799 Can also be used as a |method|: >
7800 GetLnum()->prevnonblank()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02007801<
7802 Return type: |Number|
7803
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007804
7805printf({fmt}, {expr1} ...) *printf()*
7806 Return a String with {fmt}, where "%" items are replaced by
7807 the formatted form of their respective arguments. Example: >
7808 printf("%4d: E%d %.30s", lnum, errno, msg)
7809< May result in:
7810 " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
7811
7812 When used as a |method| the base is passed as the second
7813 argument: >
7814 Compute()->printf("result: %d")
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007815<
7816 You can use `call()` to pass the items as a list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007817
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +01007818 Often used items are:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007819 %s string
7820 %6S string right-aligned in 6 display cells
7821 %6s string right-aligned in 6 bytes
7822 %.9s string truncated to 9 bytes
7823 %c single byte
7824 %d decimal number
7825 %5d decimal number padded with spaces to 5 characters
7826 %x hex number
7827 %04x hex number padded with zeros to at least 4 characters
7828 %X hex number using upper case letters
7829 %o octal number
7830 %08b binary number padded with zeros to at least 8 chars
7831 %f floating point number as 12.23, inf, -inf or nan
7832 %F floating point number as 12.23, INF, -INF or NAN
7833 %e floating point number as 1.23e3, inf, -inf or nan
7834 %E floating point number as 1.23E3, INF, -INF or NAN
7835 %g floating point number, as %f or %e depending on value
7836 %G floating point number, as %F or %E depending on value
7837 %% the % character itself
7838
7839 Conversion specifications start with '%' and end with the
7840 conversion type. All other characters are copied unchanged to
7841 the result.
7842
7843 The "%" starts a conversion specification. The following
7844 arguments appear in sequence:
7845
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007846 % [pos-argument] [flags] [field-width] [.precision] type
7847
7848 pos-argument
7849 At most one positional argument specifier. These
7850 take the form {n$}, where n is >= 1.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007851
7852 flags
7853 Zero or more of the following flags:
7854
7855 # The value should be converted to an "alternate
7856 form". For c, d, and s conversions, this option
7857 has no effect. For o conversions, the precision
7858 of the number is increased to force the first
7859 character of the output string to a zero (except
7860 if a zero value is printed with an explicit
7861 precision of zero).
7862 For b and B conversions, a non-zero result has
7863 the string "0b" (or "0B" for B conversions)
7864 prepended to it.
7865 For x and X conversions, a non-zero result has
7866 the string "0x" (or "0X" for X conversions)
7867 prepended to it.
7868
7869 0 (zero) Zero padding. For all conversions the converted
7870 value is padded on the left with zeros rather
7871 than blanks. If a precision is given with a
7872 numeric conversion (d, b, B, o, x, and X), the 0
7873 flag is ignored.
7874
7875 - A negative field width flag; the converted value
7876 is to be left adjusted on the field boundary.
7877 The converted value is padded on the right with
7878 blanks, rather than on the left with blanks or
7879 zeros. A - overrides a 0 if both are given.
7880
7881 ' ' (space) A blank should be left before a positive
7882 number produced by a signed conversion (d).
7883
7884 + A sign must always be placed before a number
7885 produced by a signed conversion. A + overrides
7886 a space if both are used.
7887
7888 field-width
7889 An optional decimal digit string specifying a minimum
7890 field width. If the converted value has fewer bytes
7891 than the field width, it will be padded with spaces on
7892 the left (or right, if the left-adjustment flag has
7893 been given) to fill out the field width. For the S
7894 conversion the count is in cells.
7895
7896 .precision
7897 An optional precision, in the form of a period '.'
7898 followed by an optional digit string. If the digit
7899 string is omitted, the precision is taken as zero.
7900 This gives the minimum number of digits to appear for
7901 d, o, x, and X conversions, the maximum number of
7902 bytes to be printed from a string for s conversions,
7903 or the maximum number of cells to be printed from a
7904 string for S conversions.
7905 For floating point it is the number of digits after
7906 the decimal point.
7907
7908 type
7909 A character that specifies the type of conversion to
7910 be applied, see below.
7911
7912 A field width or precision, or both, may be indicated by an
7913 asterisk '*' instead of a digit string. In this case, a
7914 Number argument supplies the field width or precision. A
7915 negative field width is treated as a left adjustment flag
7916 followed by a positive field width; a negative precision is
7917 treated as though it were missing. Example: >
7918 :echo printf("%d: %.*s", nr, width, line)
7919< This limits the length of the text used from "line" to
7920 "width" bytes.
7921
Dominique Pellé17dca3c2023-12-14 20:36:32 +01007922 If the argument to be formatted is specified using a
7923 positional argument specifier, and a '*' is used to indicate
7924 that a number argument is to be used to specify the width or
Christ van Willegen0c6181f2023-08-13 18:03:14 +02007925 precision, the argument(s) to be used must also be specified
7926 using a {n$} positional argument specifier. See |printf-$|.
7927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007928 The conversion specifiers and their meanings are:
7929
7930 *printf-d* *printf-b* *printf-B* *printf-o*
7931 *printf-x* *printf-X*
7932 dbBoxX The Number argument is converted to signed decimal
7933 (d), unsigned binary (b and B), unsigned octal (o), or
7934 unsigned hexadecimal (x and X) notation. The letters
7935 "abcdef" are used for x conversions; the letters
7936 "ABCDEF" are used for X conversions.
7937 The precision, if any, gives the minimum number of
7938 digits that must appear; if the converted value
7939 requires fewer digits, it is padded on the left with
7940 zeros.
7941 In no case does a non-existent or small field width
7942 cause truncation of a numeric field; if the result of
7943 a conversion is wider than the field width, the field
7944 is expanded to contain the conversion result.
7945 The 'h' modifier indicates the argument is 16 bits.
Christ van Willegenaa90d4f2023-09-03 17:22:37 +02007946 The 'l' modifier indicates the argument is a long
7947 integer. The size will be 32 bits or 64 bits
7948 depending on your platform.
7949 The "ll" modifier indicates the argument is 64 bits.
7950 The b and B conversion specifiers never take a width
7951 modifier and always assume their argument is a 64 bit
7952 integer.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00007953 Generally, these modifiers are not useful. They are
7954 ignored when type is known from the argument.
7955
7956 i alias for d
7957 D alias for ld
7958 U alias for lu
7959 O alias for lo
7960
7961 *printf-c*
7962 c The Number argument is converted to a byte, and the
7963 resulting character is written.
7964
7965 *printf-s*
7966 s The text of the String argument is used. If a
7967 precision is specified, no more bytes than the number
7968 specified are used.
7969 If the argument is not a String type, it is
7970 automatically converted to text with the same format
7971 as ":echo".
7972 *printf-S*
7973 S The text of the String argument is used. If a
7974 precision is specified, no more display cells than the
7975 number specified are used.
7976
7977 *printf-f* *E807*
7978 f F The Float argument is converted into a string of the
7979 form 123.456. The precision specifies the number of
7980 digits after the decimal point. When the precision is
7981 zero the decimal point is omitted. When the precision
7982 is not specified 6 is used. A really big number
7983 (out of range or dividing by zero) results in "inf"
7984 or "-inf" with %f (INF or -INF with %F).
7985 "0.0 / 0.0" results in "nan" with %f (NAN with %F).
7986 Example: >
7987 echo printf("%.2f", 12.115)
7988< 12.12
7989 Note that roundoff depends on the system libraries.
7990 Use |round()| when in doubt.
7991
7992 *printf-e* *printf-E*
7993 e E The Float argument is converted into a string of the
7994 form 1.234e+03 or 1.234E+03 when using 'E'. The
7995 precision specifies the number of digits after the
7996 decimal point, like with 'f'.
7997
7998 *printf-g* *printf-G*
7999 g G The Float argument is converted like with 'f' if the
8000 value is between 0.001 (inclusive) and 10000000.0
8001 (exclusive). Otherwise 'e' is used for 'g' and 'E'
8002 for 'G'. When no precision is specified superfluous
8003 zeroes and '+' signs are removed, except for the zero
8004 immediately after the decimal point. Thus 10000000.0
8005 results in 1.0e7.
8006
8007 *printf-%*
8008 % A '%' is written. No argument is converted. The
8009 complete conversion specification is "%%".
8010
8011 When a Number argument is expected a String argument is also
8012 accepted and automatically converted.
8013 When a Float or String argument is expected a Number argument
8014 is also accepted and automatically converted.
8015 Any other argument type results in an error message.
8016
8017 *E766* *E767*
8018 The number of {exprN} arguments must exactly match the number
8019 of "%" items. If there are not sufficient or too many
8020 arguments an error is given. Up to 18 arguments can be used.
8021
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008022 *printf-$*
8023 In certain languages, error and informative messages are
8024 more readable when the order of words is different from the
Christian Brabandtee17b6f2023-09-09 11:23:50 +02008025 corresponding message in English. To accommodate translations
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008026 having a different word order, positional arguments may be
8027 used to indicate this. For instance: >
8028
h_east596a9f22023-11-21 21:24:23 +09008029 #, c-format
8030 msgid "%s returning %s"
8031 msgstr "waarde %2$s komt terug van %1$s"
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008032<
h_east596a9f22023-11-21 21:24:23 +09008033 In this example, the sentence has its 2 string arguments
8034 reversed in the output. >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008035
h_east596a9f22023-11-21 21:24:23 +09008036 echo printf(
8037 "In The Netherlands, vim's creator's name is: %1$s %2$s",
8038 "Bram", "Moolenaar")
8039< In The Netherlands, vim's creator's name is: Bram Moolenaar >
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008040
h_east596a9f22023-11-21 21:24:23 +09008041 echo printf(
8042 "In Belgium, vim's creator's name is: %2$s %1$s",
8043 "Bram", "Moolenaar")
8044< In Belgium, vim's creator's name is: Moolenaar Bram
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008045
8046 Width (and precision) can be specified using the '*' specifier.
8047 In this case, you must specify the field width position in the
8048 argument list. >
8049
h_east596a9f22023-11-21 21:24:23 +09008050 echo printf("%1$*2$.*3$d", 1, 2, 3)
8051< 001 >
8052 echo printf("%2$*3$.*1$d", 1, 2, 3)
8053< 2 >
8054 echo printf("%3$*1$.*2$d", 1, 2, 3)
8055< 03 >
8056 echo printf("%1$*2$.*3$g", 1.4142, 2, 3)
8057< 1.414
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008058
8059 You can mix specifying the width and/or precision directly
8060 and via positional arguments: >
8061
h_east596a9f22023-11-21 21:24:23 +09008062 echo printf("%1$4.*2$f", 1.4142135, 6)
8063< 1.414214 >
8064 echo printf("%1$*2$.4f", 1.4142135, 6)
8065< 1.4142 >
8066 echo printf("%1$*2$.*3$f", 1.4142135, 6, 2)
8067< 1.41
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008068
Christ van Willegenc35fc032024-03-14 18:30:41 +01008069 You will get an overflow error |E1510|, when the field-width
8070 or precision will result in a string longer than 6400 chars.
8071
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008072 *E1500*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008073 You cannot mix positional and non-positional arguments: >
h_east596a9f22023-11-21 21:24:23 +09008074 echo printf("%s%1$s", "One", "Two")
8075< E1500: Cannot mix positional and non-positional arguments:
8076 %s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008077
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008078 *E1501*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008079 You cannot skip a positional argument in a format string: >
h_east596a9f22023-11-21 21:24:23 +09008080 echo printf("%3$s%1$s", "One", "Two", "Three")
8081< E1501: format argument 2 unused in $-style format:
8082 %3$s%1$s
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008083
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008084 *E1502*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008085 You can re-use a [field-width] (or [precision]) argument: >
h_east596a9f22023-11-21 21:24:23 +09008086 echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
8087< 1 at width 2 is: 01
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008088
8089 However, you can't use it as a different type: >
h_east596a9f22023-11-21 21:24:23 +09008090 echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
8091< E1502: Positional argument 2 used as field width reused as
8092 different type: long int/int
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008093
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008094 *E1503*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008095 When a positional argument is used, but not the correct number
8096 or arguments is given, an error is raised: >
h_east596a9f22023-11-21 21:24:23 +09008097 echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
8098< E1503: Positional argument 3 out of bounds: %1$d at width
8099 %2$d is: %01$*2$.*3$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008100
8101 Only the first error is reported: >
h_east596a9f22023-11-21 21:24:23 +09008102 echo printf("%01$*2$.*3$d %4$d", 1, 2)
8103< E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
8104 %4$d
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008105
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008106 *E1504*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008107 A positional argument can be used more than once: >
h_east596a9f22023-11-21 21:24:23 +09008108 echo printf("%1$s %2$s %1$s", "One", "Two")
8109< One Two One
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008110
8111 However, you can't use a different type the second time: >
h_east596a9f22023-11-21 21:24:23 +09008112 echo printf("%1$s %2$s %1$d", "One", "Two")
8113< E1504: Positional argument 1 type used inconsistently:
8114 int/string
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008115
Yegappan Lakshmanan413f8392023-09-28 22:46:37 +02008116 *E1505*
Christ van Willegen0c6181f2023-08-13 18:03:14 +02008117 Various other errors that lead to a format string being
8118 wrongly formatted lead to: >
h_east596a9f22023-11-21 21:24:23 +09008119 echo printf("%1$d at width %2$d is: %01$*2$.3$d", 1, 2)
8120< E1505: Invalid format specifier: %1$d at width %2$d is:
8121 %01$*2$.3$d
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008122
Christ van Willegenea746f92023-10-05 20:48:36 +02008123 *E1507*
zeertzjq27e12c72023-10-07 01:34:04 +08008124 This internal error indicates that the logic to parse a
8125 positional format argument ran into a problem that couldn't be
8126 otherwise reported. Please file a bug against Vim if you run
8127 into this, copying the exact format string and parameters that
8128 were used.
Christ van Willegenea746f92023-10-05 20:48:36 +02008129
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008130 Return type: |String|
8131
Christ van Willegenea746f92023-10-05 20:48:36 +02008132
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008133prompt_getprompt({buf}) *prompt_getprompt()*
8134 Returns the effective prompt text for buffer {buf}. {buf} can
8135 be a buffer name or number. See |prompt-buffer|.
8136
8137 If the buffer doesn't exist or isn't a prompt buffer, an empty
8138 string is returned.
8139
8140 Can also be used as a |method|: >
8141 GetBuffer()->prompt_getprompt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008142<
8143 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008144
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008145 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008146
8147
8148prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
8149 Set prompt callback for buffer {buf} to {expr}. When {expr}
8150 is an empty string the callback is removed. This has only
8151 effect if {buf} has 'buftype' set to "prompt".
8152
8153 The callback is invoked when pressing Enter. The current
8154 buffer will always be the prompt buffer. A new line for a
8155 prompt is added before invoking the callback, thus the prompt
8156 for which the callback was invoked will be in the last but one
8157 line.
8158 If the callback wants to add text to the buffer, it must
8159 insert it above the last line, since that is where the current
8160 prompt is. This can also be done asynchronously.
8161 The callback is invoked with one argument, which is the text
8162 that was entered at the prompt. This can be an empty string
8163 if the user only typed Enter.
8164 Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008165 func s:TextEntered(text)
8166 if a:text == 'exit' || a:text == 'quit'
8167 stopinsert
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008168 " Reset 'modified' to allow the buffer to be closed.
8169 " We assume there is nothing useful to be saved.
8170 set nomodified
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008171 close
8172 else
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008173 " Do something useful with "a:text". In this example
8174 " we just repeat it.
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008175 call append(line('$') - 1, 'Entered: "' .. a:text .. '"')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008176 endif
8177 endfunc
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01008178 call prompt_setcallback(bufnr(), function('s:TextEntered'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008179
8180< Can also be used as a |method|: >
8181 GetBuffer()->prompt_setcallback(callback)
8182
8183< {only available when compiled with the |+channel| feature}
8184
8185prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
8186 Set a callback for buffer {buf} to {expr}. When {expr} is an
8187 empty string the callback is removed. This has only effect if
8188 {buf} has 'buftype' set to "prompt".
8189
8190 This callback will be invoked when pressing CTRL-C in Insert
8191 mode. Without setting a callback Vim will exit Insert mode,
8192 as in any buffer.
8193
8194 Can also be used as a |method|: >
8195 GetBuffer()->prompt_setinterrupt(callback)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008196<
8197 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008198
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008199 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008200
8201prompt_setprompt({buf}, {text}) *prompt_setprompt()*
8202 Set prompt for buffer {buf} to {text}. You most likely want
8203 {text} to end in a space.
8204 The result is only visible if {buf} has 'buftype' set to
8205 "prompt". Example: >
8206 call prompt_setprompt(bufnr(), 'command: ')
8207<
8208 Can also be used as a |method|: >
8209 GetBuffer()->prompt_setprompt('command: ')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008210<
8211 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008212
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008213 {only available when compiled with the |+channel| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008214
8215prop_ functions are documented here: |text-prop-functions|
8216
8217pum_getpos() *pum_getpos()*
8218 If the popup menu (see |ins-completion-menu|) is not visible,
8219 returns an empty |Dictionary|, otherwise, returns a
8220 |Dictionary| with the following keys:
8221 height nr of items visible
8222 width screen cells
8223 row top screen row (0 first row)
8224 col leftmost screen column (0 first col)
8225 size total nr of items
8226 scrollbar |TRUE| if scrollbar is visible
8227
8228 The values are the same as in |v:event| during
8229 |CompleteChanged|.
8230
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008231 Return type: dict<any>
8232
8233
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008234pumvisible() *pumvisible()*
8235 Returns non-zero when the popup menu is visible, zero
8236 otherwise. See |ins-completion-menu|.
8237 This can be used to avoid some things that would remove the
8238 popup menu.
8239
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008240 Return type: |Number|
8241
8242
zeertzjq7c515282024-11-10 20:26:12 +01008243py3eval({expr} [, {locals}]) *py3eval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008244 Evaluate Python expression {expr} and return its result
8245 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008246 If a {locals} |Dictionary| is given, it defines set of local
8247 variables available in the expression. The keys are variable
8248 names and the values are the variable values. |Dictionary| and
8249 |List| values are referenced, and may be updated by the
8250 expression (as if |python-bindeval| was used).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008251 Numbers and strings are returned as they are (strings are
8252 copied though, Unicode strings are additionally converted to
8253 'encoding').
8254 Lists are represented as Vim |List| type.
8255 Dictionaries are represented as Vim |Dictionary| type with
8256 keys converted to strings.
8257 Note that in a `:def` function local variables are not visible
8258 to {expr}.
8259
8260 Can also be used as a |method|: >
8261 GetExpr()->py3eval()
Ben Jacksonea19e782024-11-06 21:50:05 +01008262 'b",".join(l)'->py3eval({'l': ['a', 'b', 'c']})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008263<
8264 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008265
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008266 {only available when compiled with the |+python3| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008267
8268 *E858* *E859*
zeertzjq7c515282024-11-10 20:26:12 +01008269pyeval({expr} [, {locals}]) *pyeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008270 Evaluate Python expression {expr} and return its result
8271 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008272 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008273 Numbers and strings are returned as they are (strings are
8274 copied though).
8275 Lists are represented as Vim |List| type.
8276 Dictionaries are represented as Vim |Dictionary| type,
8277 non-string keys result in error.
8278 Note that in a `:def` function local variables are not visible
8279 to {expr}.
8280
8281 Can also be used as a |method|: >
8282 GetExpr()->pyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008283<
8284 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008285
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008286 {only available when compiled with the |+python| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008287
zeertzjq7c515282024-11-10 20:26:12 +01008288pyxeval({expr} [, {locals}]) *pyxeval()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008289 Evaluate Python expression {expr} and return its result
8290 converted to Vim data structures.
Ben Jacksonea19e782024-11-06 21:50:05 +01008291 For {locals} see |py3eval()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008292 Uses Python 2 or 3, see |python_x| and 'pyxversion'.
8293 See also: |pyeval()|, |py3eval()|
8294
8295 Can also be used as a |method|: >
h-east52e7cc22024-07-28 17:03:29 +02008296 GetExpr()->pyxeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008297<
8298 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008299
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008300 {only available when compiled with the |+python| or the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008301 |+python3| feature}
8302
8303rand([{expr}]) *rand()* *random*
8304 Return a pseudo-random Number generated with an xoshiro128**
8305 algorithm using seed {expr}. The returned number is 32 bits,
8306 also on 64 bits systems, for consistency.
8307 {expr} can be initialized by |srand()| and will be updated by
8308 rand(). If {expr} is omitted, an internal seed value is used
8309 and updated.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008310 Returns -1 if {expr} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008311
8312 Examples: >
8313 :echo rand()
8314 :let seed = srand()
8315 :echo rand(seed)
8316 :echo rand(seed) % 16 " random number 0 - 15
8317<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008318 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008319
8320 *E726* *E727*
8321range({expr} [, {max} [, {stride}]]) *range()*
8322 Returns a |List| with Numbers:
8323 - If only {expr} is specified: [0, 1, ..., {expr} - 1]
8324 - If {max} is specified: [{expr}, {expr} + 1, ..., {max}]
8325 - If {stride} is specified: [{expr}, {expr} + {stride}, ...,
8326 {max}] (increasing {expr} with {stride} each time, not
8327 producing a value past {max}).
8328 When the maximum is one before the start the result is an
8329 empty list. When the maximum is more than one before the
8330 start this is an error.
8331 Examples: >
8332 range(4) " [0, 1, 2, 3]
8333 range(2, 4) " [2, 3, 4]
8334 range(2, 9, 3) " [2, 5, 8]
8335 range(2, -2, -1) " [2, 1, 0, -1, -2]
8336 range(0) " []
8337 range(2, 0) " error!
8338<
8339 Can also be used as a |method|: >
8340 GetExpr()->range()
8341<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008342 Return type: list<number>
8343
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008344
K.Takata11df3ae2022-10-19 14:02:40 +01008345readblob({fname} [, {offset} [, {size}]]) *readblob()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008346 Read file {fname} in binary mode and return a |Blob|.
K.Takata11df3ae2022-10-19 14:02:40 +01008347 If {offset} is specified, read the file from the specified
8348 offset. If it is a negative value, it is used as an offset
8349 from the end of the file. E.g., to read the last 12 bytes: >
8350 readblob('file.bin', -12)
8351< If {size} is specified, only the specified size will be read.
8352 E.g. to read the first 100 bytes of a file: >
8353 readblob('file.bin', 0, 100)
8354< If {size} is -1 or omitted, the whole data starting from
8355 {offset} will be read.
K.Takata43625762022-10-20 13:28:51 +01008356 This can be also used to read the data from a character device
8357 on Unix when {size} is explicitly set. Only if the device
8358 supports seeking {offset} can be used. Otherwise it should be
8359 zero. E.g. to read 10 bytes from a serial console: >
8360 readblob('/dev/ttyS0', 0, 10)
8361< When the file can't be opened an error message is given and
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008362 the result is an empty |Blob|.
Bram Moolenaar5b2a3d72022-10-21 11:25:30 +01008363 When the offset is beyond the end of the file the result is an
8364 empty blob.
8365 When trying to read more bytes than are available the result
8366 is truncated.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008367 Also see |readfile()| and |writefile()|.
8368
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008369 Return type: |Blob|
8370
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008371
8372readdir({directory} [, {expr} [, {dict}]]) *readdir()*
8373 Return a list with file and directory names in {directory}.
8374 You can also use |glob()| if you don't need to do complicated
8375 things, such as limiting the number of matches.
8376 The list will be sorted (case sensitive), see the {dict}
8377 argument below for changing the sort order.
8378
8379 When {expr} is omitted all entries are included.
8380 When {expr} is given, it is evaluated to check what to do:
8381 If {expr} results in -1 then no further entries will
8382 be handled.
8383 If {expr} results in 0 then this entry will not be
8384 added to the list.
8385 If {expr} results in 1 then this entry will be added
8386 to the list.
8387 The entries "." and ".." are always excluded.
8388 Each time {expr} is evaluated |v:val| is set to the entry name.
8389 When {expr} is a function the name is passed as the argument.
8390 For example, to get a list of files ending in ".txt": >
8391 readdir(dirname, {n -> n =~ '.txt$'})
8392< To skip hidden and backup files: >
8393 readdir(dirname, {n -> n !~ '^\.\|\~$'})
Bram Moolenaar6f4754b2022-01-23 12:07:04 +00008394< *E857*
8395 The optional {dict} argument allows for further custom
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008396 values. Currently this is used to specify if and how sorting
8397 should be performed. The dict can have the following members:
8398
8399 sort How to sort the result returned from the system.
8400 Valid values are:
8401 "none" do not sort (fastest method)
8402 "case" sort case sensitive (byte value of
8403 each character, technically, using
8404 strcmp()) (default)
8405 "icase" sort case insensitive (technically
8406 using strcasecmp())
8407 "collate" sort using the collation order
8408 of the "POSIX" or "C" |locale|
8409 (technically using strcoll())
8410 Other values are silently ignored.
8411
8412 For example, to get a list of all files in the current
8413 directory without sorting the individual entries: >
8414 readdir('.', '1', #{sort: 'none'})
8415< If you want to get a directory tree: >
8416 function! s:tree(dir)
8417 return {a:dir : map(readdir(a:dir),
8418 \ {_, x -> isdirectory(x) ?
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008419 \ {x : s:tree(a:dir .. '/' .. x)} : x})}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008420 endfunction
8421 echo s:tree(".")
8422<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008423 Returns an empty List on error.
8424
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008425 Can also be used as a |method|: >
8426 GetDirName()->readdir()
8427<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008428 Return type: list<string> or list<any>
8429
8430
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008431readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
8432 Extended version of |readdir()|.
8433 Return a list of Dictionaries with file and directory
8434 information in {directory}.
8435 This is useful if you want to get the attributes of file and
8436 directory at the same time as getting a list of a directory.
8437 This is much faster than calling |readdir()| then calling
8438 |getfperm()|, |getfsize()|, |getftime()| and |getftype()| for
8439 each file and directory especially on MS-Windows.
8440 The list will by default be sorted by name (case sensitive),
8441 the sorting can be changed by using the optional {dict}
8442 argument, see |readdir()|.
8443
8444 The Dictionary for file and directory information has the
8445 following items:
8446 group Group name of the entry. (Only on Unix)
8447 name Name of the entry.
8448 perm Permissions of the entry. See |getfperm()|.
8449 size Size of the entry. See |getfsize()|.
8450 time Timestamp of the entry. See |getftime()|.
8451 type Type of the entry.
8452 On Unix, almost same as |getftype()| except:
8453 Symlink to a dir "linkd"
8454 Other symlink "link"
8455 On MS-Windows:
8456 Normal file "file"
8457 Directory "dir"
8458 Junction "junction"
8459 Symlink to a dir "linkd"
8460 Other symlink "link"
8461 Other reparse point "reparse"
8462 user User name of the entry's owner. (Only on Unix)
8463 On Unix, if the entry is a symlink, the Dictionary includes
8464 the information of the target (except the "type" item).
8465 On MS-Windows, it includes the information of the symlink
8466 itself because of performance reasons.
8467
8468 When {expr} is omitted all entries are included.
8469 When {expr} is given, it is evaluated to check what to do:
8470 If {expr} results in -1 then no further entries will
8471 be handled.
8472 If {expr} results in 0 then this entry will not be
8473 added to the list.
8474 If {expr} results in 1 then this entry will be added
8475 to the list.
8476 The entries "." and ".." are always excluded.
8477 Each time {expr} is evaluated |v:val| is set to a |Dictionary|
8478 of the entry.
8479 When {expr} is a function the entry is passed as the argument.
8480 For example, to get a list of files ending in ".txt": >
8481 readdirex(dirname, {e -> e.name =~ '.txt$'})
8482<
8483 For example, to get a list of all files in the current
8484 directory without sorting the individual entries: >
8485 readdirex(dirname, '1', #{sort: 'none'})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008486<
8487 Can also be used as a |method|: >
8488 GetDirName()->readdirex()
8489<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008490 Return type: list<dict<any>> or list<any>
8491
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008492
8493 *readfile()*
8494readfile({fname} [, {type} [, {max}]])
8495 Read file {fname} and return a |List|, each line of the file
8496 as an item. Lines are broken at NL characters. Macintosh
8497 files separated with CR will result in a single long line
8498 (unless a NL appears somewhere).
8499 All NUL characters are replaced with a NL character.
8500 When {type} contains "b" binary mode is used:
8501 - When the last line ends in a NL an extra empty list item is
8502 added.
8503 - No CR characters are removed.
8504 Otherwise:
8505 - CR characters that appear before a NL are removed.
8506 - Whether the last line ends in a NL or not does not matter.
8507 - When 'encoding' is Unicode any UTF-8 byte order mark is
8508 removed from the text.
8509 When {max} is given this specifies the maximum number of lines
8510 to be read. Useful if you only want to check the first ten
8511 lines of a file: >
8512 :for line in readfile(fname, '', 10)
8513 : if line =~ 'Date' | echo line | endif
8514 :endfor
8515< When {max} is negative -{max} lines from the end of the file
8516 are returned, or as many as there are.
8517 When {max} is zero the result is an empty list.
8518 Note that without {max} the whole file is read into memory.
8519 Also note that there is no recognition of encoding. Read a
8520 file into a buffer if you need to.
8521 Deprecated (use |readblob()| instead): When {type} contains
8522 "B" a |Blob| is returned with the binary data of the file
8523 unmodified.
8524 When the file can't be opened an error message is given and
8525 the result is an empty list.
8526 Also see |writefile()|.
8527
8528 Can also be used as a |method|: >
8529 GetFileName()->readfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008530<
8531 Return type: list<string> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008532
8533reduce({object}, {func} [, {initial}]) *reduce()* *E998*
8534 {func} is called for every item in {object}, which can be a
8535 |String|, |List| or a |Blob|. {func} is called with two
8536 arguments: the result so far and current item. After
Bram Moolenaarf10911e2022-01-29 22:20:48 +00008537 processing all items the result is returned. *E1132*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008538
8539 {initial} is the initial result. When omitted, the first item
8540 in {object} is used and {func} is first called for the second
8541 item. If {initial} is not given and {object} is empty no
8542 result can be computed, an E998 error is given.
8543
8544 Examples: >
8545 echo reduce([1, 3, 5], { acc, val -> acc + val })
8546 echo reduce(['x', 'y'], { acc, val -> acc .. val }, 'a')
8547 echo reduce(0z1122, { acc, val -> 2 * acc + val })
8548 echo reduce('xyz', { acc, val -> acc .. ',' .. val })
8549<
8550 Can also be used as a |method|: >
8551 echo mylist->reduce({ acc, val -> acc + val }, 0)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008552<
8553 Return type: |String|, |Blob|, list<{type}> or dict<{type}>
8554 depending on {object} and {func}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008555
8556
8557reg_executing() *reg_executing()*
8558 Returns the single letter name of the register being executed.
8559 Returns an empty string when no register is being executed.
8560 See |@|.
8561
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008562 Return type: |String|
8563
8564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008565reg_recording() *reg_recording()*
8566 Returns the single letter name of the register being recorded.
8567 Returns an empty string when not recording. See |q|.
8568
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008569 Return type: |String|
8570
8571
8572reltime() *reltime()*
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008573reltime({start})
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008574reltime({start}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008575 Return an item that represents a time value. The item is a
8576 list with items that depend on the system. In Vim 9 script
Bram Moolenaar71badf92023-04-22 22:40:14 +01008577 the type list<any> can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008578 The item can be passed to |reltimestr()| to convert it to a
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008579 string or |reltimefloat()| to convert to a Float. For
8580 example, to see the time spent in function Work(): >
8581 var startTime = reltime()
8582 Work()
8583 echo startTime->reltime()->reltimestr()
8584<
Bram Moolenaar016188f2022-06-06 20:52:59 +01008585 Without an argument reltime() returns the current time (the
Lifepillar963fd7d2024-01-05 17:44:57 +01008586 representation is system-dependent, it cannot be used as the
Bram Moolenaar016188f2022-06-06 20:52:59 +01008587 wall-clock time, see |localtime()| for that).
Lifepillar963fd7d2024-01-05 17:44:57 +01008588 With one argument it returns the time passed since the time
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008589 specified in the argument.
8590 With two arguments it returns the time passed between {start}
8591 and {end}.
8592
8593 The {start} and {end} arguments must be values returned by
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008594 reltime(). If there is an error an empty List is returned in
8595 legacy script, in Vim9 script an error is given.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008596
8597 Can also be used as a |method|: >
8598 GetStart()->reltime()
8599<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008600 Return type: list<number>
8601
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008602 {only available when compiled with the |+reltime| feature}
8603
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008605reltimefloat({time}) *reltimefloat()*
8606 Return a Float that represents the time value of {time}.
8607 Example: >
8608 let start = reltime()
8609 call MyFunction()
8610 let seconds = reltimefloat(reltime(start))
8611< See the note of reltimestr() about overhead.
8612 Also see |profiling|.
8613 If there is an error 0.0 is returned in legacy script, in Vim9
8614 script an error is given.
8615
8616 Can also be used as a |method|: >
8617 reltime(start)->reltimefloat()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008618<
8619 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008620
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008621 {only available when compiled with the |+reltime| feature}
8622
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008623
8624reltimestr({time}) *reltimestr()*
8625 Return a String that represents the time value of {time}.
8626 This is the number of seconds, a dot and the number of
8627 microseconds. Example: >
8628 let start = reltime()
8629 call MyFunction()
8630 echo reltimestr(reltime(start))
8631< Note that overhead for the commands will be added to the time.
Ernie Rael076de792023-03-16 21:43:15 +00008632 The accuracy depends on the system. Use reltimefloat() for the
8633 greatest accuracy which is nanoseconds on some systems.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008634 Leading spaces are used to make the string align nicely. You
8635 can use split() to remove it. >
8636 echo split(reltimestr(reltime(start)))[0]
8637< Also see |profiling|.
8638 If there is an error an empty string is returned in legacy
8639 script, in Vim9 script an error is given.
8640
8641 Can also be used as a |method|: >
8642 reltime(start)->reltimestr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008643<
8644 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008645
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008646 {only available when compiled with the |+reltime| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008647
8648 *remote_expr()* *E449*
8649remote_expr({server}, {string} [, {idvar} [, {timeout}]])
Bram Moolenaar944697a2022-02-20 19:48:20 +00008650 Send the {string} to {server}. The {server} argument is a
8651 string, also see |{server}|.
8652
8653 The string is sent as an expression and the result is returned
Christian Brabandt1961caf2024-10-12 11:57:12 +02008654 after evaluation. The result must be a String or a |List|
8655 other types will be converted to String. A |List| is turned
8656 into a String by joining the items with a line break in
8657 between (not at the end), like with join(expr, "\n").
Bram Moolenaar944697a2022-02-20 19:48:20 +00008658
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008659 If {idvar} is present and not empty, it is taken as the name
8660 of a variable and a {serverid} for later use with
8661 |remote_read()| is stored there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008662
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008663 If {timeout} is given the read times out after this many
8664 seconds. Otherwise a timeout of 600 seconds is used.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008665
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008666 See also |clientserver| |RemoteReply|.
8667 This function is not available in the |sandbox|.
8668 {only available when compiled with the |+clientserver| feature}
8669 Note: Any errors will cause a local error message to be issued
8670 and the result will be the empty string.
8671
8672 Variables will be evaluated in the global namespace,
8673 independent of a function currently being active. Except
8674 when in debug mode, then local function variables and
8675 arguments can be evaluated.
8676
8677 Examples: >
8678 :echo remote_expr("gvim", "2+2")
8679 :echo remote_expr("gvim1", "b:current_syntax")
8680<
8681 Can also be used as a |method|: >
8682 ServerName()->remote_expr(expr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008683<
8684 Return type: |String| or list<{type}>
8685
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008686
8687remote_foreground({server}) *remote_foreground()*
8688 Move the Vim server with the name {server} to the foreground.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008689 The {server} argument is a string, also see |{server}|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008690 This works like: >
8691 remote_expr({server}, "foreground()")
8692< Except that on Win32 systems the client does the work, to work
8693 around the problem that the OS doesn't always allow the server
8694 to bring itself to the foreground.
8695 Note: This does not restore the window if it was minimized,
8696 like foreground() does.
8697 This function is not available in the |sandbox|.
8698
8699 Can also be used as a |method|: >
8700 ServerName()->remote_foreground()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008701<
8702 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008703
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008704 {only in the Win32, Motif and GTK GUI versions and the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008705 Win32 console version}
8706
8707
8708remote_peek({serverid} [, {retvar}]) *remote_peek()*
8709 Returns a positive number if there are available strings
8710 from {serverid}. Copies any reply string into the variable
8711 {retvar} if specified. {retvar} must be a string with the
8712 name of a variable.
8713 Returns zero if none are available.
8714 Returns -1 if something is wrong.
8715 See also |clientserver|.
8716 This function is not available in the |sandbox|.
8717 {only available when compiled with the |+clientserver| feature}
8718 Examples: >
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008719 :let repl = ""
8720 :echo "PEEK: " .. remote_peek(id, "repl") .. ": " .. repl
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008721
8722< Can also be used as a |method|: >
8723 ServerId()->remote_peek()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008724<
8725 Return type: |Number|
8726
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008727
8728remote_read({serverid}, [{timeout}]) *remote_read()*
8729 Return the oldest available reply from {serverid} and consume
8730 it. Unless a {timeout} in seconds is given, it blocks until a
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008731 reply is available. Returns an empty string, if a reply is
8732 not available or on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008733 See also |clientserver|.
8734 This function is not available in the |sandbox|.
8735 {only available when compiled with the |+clientserver| feature}
8736 Example: >
8737 :echo remote_read(id)
8738
8739< Can also be used as a |method|: >
8740 ServerId()->remote_read()
8741<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008742 Return type: |String|
8743
8744
8745remote_send({server}, {string} [, {idvar}]) *remote_send()* *E241*
Bram Moolenaar944697a2022-02-20 19:48:20 +00008746 Send the {string} to {server}. The {server} argument is a
8747 string, also see |{server}|.
8748
8749 The string is sent as input keys and the function returns
8750 immediately. At the Vim server the keys are not mapped
8751 |:map|.
8752
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008753 If {idvar} is present, it is taken as the name of a variable
8754 and a {serverid} for later use with remote_read() is stored
8755 there.
Bram Moolenaar944697a2022-02-20 19:48:20 +00008756
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008757 See also |clientserver| |RemoteReply|.
8758 This function is not available in the |sandbox|.
8759 {only available when compiled with the |+clientserver| feature}
8760
8761 Note: Any errors will be reported in the server and may mess
8762 up the display.
8763 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008764 :echo remote_send("gvim", ":DropAndReply " .. file, "serverid") ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008765 \ remote_read(serverid)
8766
8767 :autocmd NONE RemoteReply *
8768 \ echo remote_read(expand("<amatch>"))
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008769 :echo remote_send("gvim", ":sleep 10 | echo " ..
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008770 \ 'server2client(expand("<client>"), "HELLO")<CR>')
8771<
8772 Can also be used as a |method|: >
8773 ServerName()->remote_send(keys)
8774<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008775 Return type: |String|
8776
8777
8778remote_startserver({name}) *remote_startserver()* *E941* *E942*
h-east17b69512023-05-01 22:36:56 +01008779 Become the server {name}. {name} must be a non-empty string.
8780 This fails if already running as a server, when |v:servername|
8781 is not empty.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008782
8783 Can also be used as a |method|: >
8784 ServerName()->remote_startserver()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008785<
8786 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008787
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008788 {only available when compiled with the |+clientserver| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008789
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008790
8791remove({list}, {idx}) *remove()*
8792remove({list}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008793 Without {end}: Remove the item at {idx} from |List| {list} and
8794 return the item.
8795 With {end}: Remove items from {idx} to {end} (inclusive) and
8796 return a |List| with these items. When {idx} points to the same
8797 item as {end} a list with one item is returned. When {end}
8798 points to an item before {idx} this is an error.
8799 See |list-index| for possible values of {idx} and {end}.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008800 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008801 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008802 :echo "last item: " .. remove(mylist, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008803 :call remove(mylist, 0, 9)
8804<
8805 Use |delete()| to remove a file.
8806
8807 Can also be used as a |method|: >
8808 mylist->remove(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008809<
8810 Return type: any, depending on {list}
8811
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008812
Bram Moolenaarf269eab2022-10-03 18:04:35 +01008813remove({blob}, {idx})
8814remove({blob}, {idx}, {end})
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008815 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
8816 return the byte.
8817 With {end}: Remove bytes from {idx} to {end} (inclusive) and
8818 return a |Blob| with these bytes. When {idx} points to the same
8819 byte as {end} a |Blob| with one byte is returned. When {end}
8820 points to a byte before {idx} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008821 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008822 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008823 :echo "last byte: " .. remove(myblob, -1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008824 :call remove(mylist, 0, 9)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008825<
8826 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008827
8828remove({dict}, {key})
8829 Remove the entry from {dict} with key {key} and return it.
8830 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008831 :echo "removed " .. remove(dict, "one")
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008832< If there is no {key} in {dict} this is an error.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008833 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008834
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008835 Return type: any, depending on {dict}
8836
8837
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008838rename({from}, {to}) *rename()*
8839 Rename the file by the name {from} to the name {to}. This
8840 should also work to move files across file systems. The
8841 result is a Number, which is 0 if the file was renamed
8842 successfully, and non-zero when the renaming failed.
8843 NOTE: If {to} exists it is overwritten without warning.
8844 This function is not available in the |sandbox|.
8845
8846 Can also be used as a |method|: >
8847 GetOldName()->rename(newname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008848<
8849 Return type: |Number|
8850
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008851
8852repeat({expr}, {count}) *repeat()*
8853 Repeat {expr} {count} times and return the concatenated
8854 result. Example: >
8855 :let separator = repeat('-', 80)
8856< When {count} is zero or negative the result is empty.
Bakudankun375141e2022-09-09 18:46:47 +01008857 When {expr} is a |List| or a |Blob| the result is {expr}
8858 concatenated {count} times. Example: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008859 :let longlist = repeat(['a', 'b'], 3)
8860< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
8861
8862 Can also be used as a |method|: >
8863 mylist->repeat(count)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008864<
8865 Return type: |String|, |Blob| or list<{type}> depending on
8866 {expr}
8867
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008868
8869resolve({filename}) *resolve()* *E655*
8870 On MS-Windows, when {filename} is a shortcut (a .lnk file),
8871 returns the path the shortcut points to in a simplified form.
8872 When {filename} is a symbolic link or junction point, return
8873 the full path to the target. If the target of junction is
8874 removed, return {filename}.
8875 On Unix, repeat resolving symbolic links in all path
8876 components of {filename} and return the simplified result.
8877 To cope with link cycles, resolving of symbolic links is
8878 stopped after 100 iterations.
8879 On other systems, return the simplified {filename}.
8880 The simplification step is done as by |simplify()|.
8881 resolve() keeps a leading path component specifying the
8882 current directory (provided the result is still a relative
8883 path name) and also keeps a trailing path separator.
8884
8885 Can also be used as a |method|: >
8886 GetName()->resolve()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008887<
8888 Return type: |String|
8889
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008890
8891reverse({object}) *reverse()*
Yegappan Lakshmanan03ff1c22023-05-06 14:08:21 +01008892 Reverse the order of items in {object}. {object} can be a
8893 |List|, a |Blob| or a |String|. For a List and a Blob the
8894 items are reversed in-place and {object} is returned.
8895 For a String a new String is returned.
8896 Returns zero if {object} is not a List, Blob or a String.
8897 If you want a List or Blob to remain unmodified make a copy
8898 first: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008899 :let revlist = reverse(copy(mylist))
8900< Can also be used as a |method|: >
8901 mylist->reverse()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008902<
8903 Return type: |String|, |Blob| or list<{type}> depending on
8904 {object}
8905
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008906
8907round({expr}) *round()*
8908 Round off {expr} to the nearest integral value and return it
8909 as a |Float|. If {expr} lies halfway between two integral
8910 values, then use the larger one (away from zero).
8911 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008912 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008913 Examples: >
8914 echo round(0.456)
8915< 0.0 >
8916 echo round(4.5)
8917< 5.0 >
8918 echo round(-4.5)
8919< -5.0
8920
8921 Can also be used as a |method|: >
8922 Compute()->round()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008923<
8924 Return type: |Float|
8925
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008926
8927rubyeval({expr}) *rubyeval()*
8928 Evaluate Ruby expression {expr} and return its result
8929 converted to Vim data structures.
8930 Numbers, floats and strings are returned as they are (strings
8931 are copied though).
8932 Arrays are represented as Vim |List| type.
8933 Hashes are represented as Vim |Dictionary| type.
8934 Other objects are represented as strings resulted from their
8935 "Object#to_s" method.
8936 Note that in a `:def` function local variables are not visible
8937 to {expr}.
8938
8939 Can also be used as a |method|: >
8940 GetRubyExpr()->rubyeval()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008941<
8942 Return type: any, depending on {expr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008943
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008944 {only available when compiled with the |+ruby| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008945
8946screenattr({row}, {col}) *screenattr()*
8947 Like |screenchar()|, but return the attribute. This is a rather
8948 arbitrary number that can only be used to compare to the
8949 attribute at other positions.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01008950 Returns -1 when row or col is out of range.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008951
8952 Can also be used as a |method|: >
8953 GetRow()->screenattr(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008954<
8955 Return type: |Number|
8956
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008957
8958screenchar({row}, {col}) *screenchar()*
8959 The result is a Number, which is the character at position
8960 [row, col] on the screen. This works for every possible
8961 screen position, also status lines, window separators and the
8962 command line. The top left position is row one, column one
8963 The character excludes composing characters. For double-byte
8964 encodings it may only be the first byte.
8965 This is mainly to be used for testing.
8966 Returns -1 when row or col is out of range.
8967
8968 Can also be used as a |method|: >
8969 GetRow()->screenchar(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008970<
8971 Return type: |Number|
8972
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008973
8974screenchars({row}, {col}) *screenchars()*
8975 The result is a |List| of Numbers. The first number is the same
8976 as what |screenchar()| returns. Further numbers are
8977 composing characters on top of the base character.
8978 This is mainly to be used for testing.
8979 Returns an empty List when row or col is out of range.
8980
8981 Can also be used as a |method|: >
8982 GetRow()->screenchars(col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02008983<
8984 Return type: list<number> or list<any>
8985
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008986
8987screencol() *screencol()*
8988 The result is a Number, which is the current screen column of
8989 the cursor. The leftmost column has number 1.
8990 This function is mainly used for testing.
8991
8992 Note: Always returns the current screen column, thus if used
8993 in a command (e.g. ":echo screencol()") it will return the
8994 column inside the command line, which is 1 when the command is
8995 executed. To get the cursor position in the file use one of
8996 the following mappings: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +00008997 nnoremap <expr> GG ":echom " .. screencol() .. "\n"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00008998 nnoremap <silent> GG :echom screencol()<CR>
8999 nnoremap GG <Cmd>echom screencol()<CR>
9000<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009001 Return type: |Number|
9002
9003
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009004screenpos({winid}, {lnum}, {col}) *screenpos()*
9005 The result is a Dict with the screen position of the text
9006 character in window {winid} at buffer line {lnum} and column
9007 {col}. {col} is a one-based byte index.
9008 The Dict has these members:
9009 row screen row
9010 col first screen column
9011 endcol last screen column
9012 curscol cursor screen column
9013 If the specified position is not visible, all values are zero.
9014 The "endcol" value differs from "col" when the character
9015 occupies more than one screen cell. E.g. for a Tab "col" can
9016 be 1 and "endcol" can be 8.
9017 The "curscol" value is where the cursor would be placed. For
9018 a Tab it would be the same as "endcol", while for a double
9019 width character it would be the same as "col".
9020 The |conceal| feature is ignored here, the column numbers are
9021 as if 'conceallevel' is zero. You can set the cursor to the
9022 right position and use |screencol()| to get the value with
9023 |conceal| taken into account.
Bram Moolenaar944697a2022-02-20 19:48:20 +00009024 If the position is in a closed fold the screen position of the
9025 first character is returned, {col} is not used.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +01009026 Returns an empty Dict if {winid} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009027
9028 Can also be used as a |method|: >
9029 GetWinid()->screenpos(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009030<
9031 Return type: dict<number> or dict<any>
9032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009033
9034screenrow() *screenrow()*
9035 The result is a Number, which is the current screen row of the
9036 cursor. The top line has number one.
9037 This function is mainly used for testing.
9038 Alternatively you can use |winline()|.
9039
9040 Note: Same restrictions as with |screencol()|.
9041
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009042 Return type: |Number|
9043
9044
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009045screenstring({row}, {col}) *screenstring()*
9046 The result is a String that contains the base character and
9047 any composing characters at position [row, col] on the screen.
9048 This is like |screenchars()| but returning a String with the
9049 characters.
9050 This is mainly to be used for testing.
9051 Returns an empty String when row or col is out of range.
9052
9053 Can also be used as a |method|: >
9054 GetRow()->screenstring(col)
9055<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009056 Return type: |String|
9057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009058 *search()*
9059search({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9060 Search for regexp pattern {pattern}. The search starts at the
9061 cursor position (you can use |cursor()| to set it).
9062
9063 When a match has been found its line number is returned.
9064 If there is no match a 0 is returned and the cursor doesn't
9065 move. No error message is given.
Christian Brabandt9a660d22024-03-12 22:03:09 +01009066 To get the matched string, use |matchbufline()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009067
9068 {flags} is a String, which can contain these character flags:
9069 'b' search Backward instead of forward
9070 'c' accept a match at the Cursor position
9071 'e' move to the End of the match
9072 'n' do Not move the cursor
9073 'p' return number of matching sub-Pattern (see below)
9074 's' Set the ' mark at the previous location of the cursor
9075 'w' Wrap around the end of the file
9076 'W' don't Wrap around the end of the file
Doug Kearns8a27d972025-01-05 15:56:57 +01009077 'z' start searching at the cursor column instead of Zero
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009078 If neither 'w' or 'W' is given, the 'wrapscan' option applies.
9079
9080 If the 's' flag is supplied, the ' mark is set, only if the
9081 cursor is moved. The 's' flag cannot be combined with the 'n'
9082 flag.
9083
9084 'ignorecase', 'smartcase' and 'magic' are used.
9085
9086 When the 'z' flag is not given, forward searching always
9087 starts in column zero and then matches before the cursor are
9088 skipped. When the 'c' flag is present in 'cpo' the next
9089 search starts after the match. Without the 'c' flag the next
Bram Moolenaarfd999452022-08-24 18:30:14 +01009090 search starts one column after the start of the match. This
9091 matters for overlapping matches. See |cpo-c|. You can also
9092 insert "\ze" to change where the match ends, see |/\ze|.
9093
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009094 When searching backwards and the 'z' flag is given then the
9095 search starts in column zero, thus no match in the current
9096 line will be found (unless wrapping around the end of the
9097 file).
9098
9099 When the {stopline} argument is given then the search stops
9100 after searching this line. This is useful to restrict the
9101 search to a range of lines. Examples: >
9102 let match = search('(', 'b', line("w0"))
9103 let end = search('END', '', line("w$"))
9104< When {stopline} is used and it is not zero this also implies
9105 that the search does not wrap around the end of the file.
9106 A zero value is equal to not giving the argument.
Bram Moolenaar2ecbe532022-07-29 21:36:21 +01009107 *E1285* *E1286* *E1287* *E1288* *E1289*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009108 When the {timeout} argument is given the search stops when
9109 more than this many milliseconds have passed. Thus when
9110 {timeout} is 500 the search stops after half a second.
9111 The value must not be negative. A zero value is like not
9112 giving the argument.
Christian Brabandtd657d3d2024-09-10 21:55:49 +02009113
9114 Note: the timeout is only considered when searching, not
9115 while evaluating the {skip} expression.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009116 {only available when compiled with the |+reltime| feature}
9117
9118 If the {skip} expression is given it is evaluated with the
9119 cursor positioned on the start of a match. If it evaluates to
9120 non-zero this match is skipped. This can be used, for
9121 example, to skip a match in a comment or a string.
9122 {skip} can be a string, which is evaluated as an expression, a
9123 function reference or a lambda.
9124 When {skip} is omitted or empty, every match is accepted.
9125 When evaluating {skip} causes an error the search is aborted
9126 and -1 returned.
9127 *search()-sub-match*
9128 With the 'p' flag the returned value is one more than the
9129 first sub-match in \(\). One if none of them matched but the
9130 whole pattern did match.
9131 To get the column number too use |searchpos()|.
9132
9133 The cursor will be positioned at the match, unless the 'n'
9134 flag is used.
9135
9136 Example (goes over all files in the argument list): >
9137 :let n = 1
9138 :while n <= argc() " loop over all files in arglist
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009139 : exe "argument " .. n
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009140 : " start at the last char in the file and wrap for the
9141 : " first search to find match at start of file
9142 : normal G$
9143 : let flags = "w"
9144 : while search("foo", flags) > 0
9145 : s/foo/bar/g
9146 : let flags = "W"
9147 : endwhile
9148 : update " write the file if modified
9149 : let n = n + 1
9150 :endwhile
9151<
9152 Example for using some flags: >
9153 :echo search('\<if\|\(else\)\|\(endif\)', 'ncpe')
9154< This will search for the keywords "if", "else", and "endif"
9155 under or after the cursor. Because of the 'p' flag, it
9156 returns 1, 2, or 3 depending on which keyword is found, or 0
9157 if the search fails. With the cursor on the first word of the
9158 line:
9159 if (foo == 0) | let foo = foo + 1 | endif ~
9160 the function returns 1. Without the 'c' flag, the function
9161 finds the "endif" and returns 3. The same thing happens
9162 without the 'e' flag if the cursor is on the "f" of "if".
9163 The 'n' flag tells the function not to move the cursor.
9164
9165 Can also be used as a |method|: >
9166 GetPattern()->search()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009167<
9168 Return type: |Number|
9169
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009170
9171searchcount([{options}]) *searchcount()*
9172 Get or update the last search count, like what is displayed
9173 without the "S" flag in 'shortmess'. This works even if
9174 'shortmess' does contain the "S" flag.
9175
9176 This returns a |Dictionary|. The dictionary is empty if the
9177 previous pattern was not set and "pattern" was not specified.
9178
9179 key type meaning ~
9180 current |Number| current position of match;
9181 0 if the cursor position is
9182 before the first match
9183 exact_match |Boolean| 1 if "current" is matched on
9184 "pos", otherwise 0
9185 total |Number| total count of matches found
9186 incomplete |Number| 0: search was fully completed
9187 1: recomputing was timed out
9188 2: max count exceeded
9189
9190 For {options} see further down.
9191
9192 To get the last search count when |n| or |N| was pressed, call
9193 this function with `recompute: 0` . This sometimes returns
9194 wrong information because |n| and |N|'s maximum count is 99.
9195 If it exceeded 99 the result must be max count + 1 (100). If
9196 you want to get correct information, specify `recompute: 1`: >
9197
9198 " result == maxcount + 1 (100) when many matches
9199 let result = searchcount(#{recompute: 0})
9200
9201 " Below returns correct result (recompute defaults
9202 " to 1)
9203 let result = searchcount()
9204<
Bram Moolenaarb529cfb2022-07-25 15:42:07 +01009205 The function is useful to add the count to 'statusline': >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009206 function! LastSearchCount() abort
9207 let result = searchcount(#{recompute: 0})
9208 if empty(result)
9209 return ''
9210 endif
9211 if result.incomplete ==# 1 " timed out
9212 return printf(' /%s [?/??]', @/)
9213 elseif result.incomplete ==# 2 " max count exceeded
9214 if result.total > result.maxcount &&
9215 \ result.current > result.maxcount
9216 return printf(' /%s [>%d/>%d]', @/,
9217 \ result.current, result.total)
9218 elseif result.total > result.maxcount
9219 return printf(' /%s [%d/>%d]', @/,
9220 \ result.current, result.total)
9221 endif
9222 endif
9223 return printf(' /%s [%d/%d]', @/,
9224 \ result.current, result.total)
9225 endfunction
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009226 let &statusline ..= '%{LastSearchCount()}'
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009227
9228 " Or if you want to show the count only when
9229 " 'hlsearch' was on
Bram Moolenaarc51cf032022-02-26 12:25:45 +00009230 " let &statusline ..=
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009231 " \ '%{v:hlsearch ? LastSearchCount() : ""}'
9232<
9233 You can also update the search count, which can be useful in a
9234 |CursorMoved| or |CursorMovedI| autocommand: >
9235
9236 autocmd CursorMoved,CursorMovedI *
9237 \ let s:searchcount_timer = timer_start(
9238 \ 200, function('s:update_searchcount'))
9239 function! s:update_searchcount(timer) abort
9240 if a:timer ==# s:searchcount_timer
9241 call searchcount(#{
9242 \ recompute: 1, maxcount: 0, timeout: 100})
9243 redrawstatus
9244 endif
9245 endfunction
9246<
9247 This can also be used to count matched texts with specified
9248 pattern in the current buffer using "pattern": >
9249
9250 " Count '\<foo\>' in this buffer
9251 " (Note that it also updates search count)
9252 let result = searchcount(#{pattern: '\<foo\>'})
9253
9254 " To restore old search count by old pattern,
9255 " search again
9256 call searchcount()
9257<
9258 {options} must be a |Dictionary|. It can contain:
9259 key type meaning ~
9260 recompute |Boolean| if |TRUE|, recompute the count
9261 like |n| or |N| was executed.
9262 otherwise returns the last
9263 computed result (when |n| or
9264 |N| was used when "S" is not
9265 in 'shortmess', or this
9266 function was called).
9267 (default: |TRUE|)
9268 pattern |String| recompute if this was given
9269 and different with |@/|.
9270 this works as same as the
9271 below command is executed
9272 before calling this function >
9273 let @/ = pattern
9274< (default: |@/|)
9275 timeout |Number| 0 or negative number is no
9276 timeout. timeout milliseconds
9277 for recomputing the result
9278 (default: 0)
9279 maxcount |Number| 0 or negative number is no
9280 limit. max count of matched
9281 text while recomputing the
9282 result. if search exceeded
9283 total count, "total" value
9284 becomes `maxcount + 1`
9285 (default: 99)
9286 pos |List| `[lnum, col, off]` value
9287 when recomputing the result.
9288 this changes "current" result
9289 value. see |cursor()|,
9290 |getpos()|
9291 (default: cursor's position)
9292
9293 Can also be used as a |method|: >
9294 GetSearchOpts()->searchcount()
9295<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009296 Return type: dict<number>
9297
9298
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009299searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()*
9300 Search for the declaration of {name}.
9301
9302 With a non-zero {global} argument it works like |gD|, find
9303 first match in the file. Otherwise it works like |gd|, find
9304 first match in the function.
9305
9306 With a non-zero {thisblock} argument matches in a {} block
9307 that ends before the cursor position are ignored. Avoids
9308 finding variable declarations only valid in another scope.
9309
9310 Moves the cursor to the found match.
9311 Returns zero for success, non-zero for failure.
9312 Example: >
9313 if searchdecl('myvar') == 0
9314 echo getline('.')
9315 endif
9316<
9317 Can also be used as a |method|: >
9318 GetName()->searchdecl()
9319<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009320 Return type: |Number|
9321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009322 *searchpair()*
9323searchpair({start}, {middle}, {end} [, {flags} [, {skip}
9324 [, {stopline} [, {timeout}]]]])
9325 Search for the match of a nested start-end pair. This can be
9326 used to find the "endif" that matches an "if", while other
9327 if/endif pairs in between are ignored.
9328 The search starts at the cursor. The default is to search
9329 forward, include 'b' in {flags} to search backward.
9330 If a match is found, the cursor is positioned at it and the
9331 line number is returned. If no match is found 0 or -1 is
9332 returned and the cursor doesn't move. No error message is
9333 given.
9334
9335 {start}, {middle} and {end} are patterns, see |pattern|. They
9336 must not contain \( \) pairs. Use of \%( \) is allowed. When
9337 {middle} is not empty, it is found when searching from either
9338 direction, but only when not in a nested start-end pair. A
9339 typical use is: >
9340 searchpair('\<if\>', '\<else\>', '\<endif\>')
9341< By leaving {middle} empty the "else" is skipped.
9342
9343 {flags} 'b', 'c', 'n', 's', 'w' and 'W' are used like with
9344 |search()|. Additionally:
9345 'r' Repeat until no more matches found; will find the
9346 outer pair. Implies the 'W' flag.
9347 'm' Return number of matches instead of line number with
9348 the match; will be > 1 when 'r' is used.
9349 Note: it's nearly always a good idea to use the 'W' flag, to
9350 avoid wrapping around the end of the file.
9351
9352 When a match for {start}, {middle} or {end} is found, the
9353 {skip} expression is evaluated with the cursor positioned on
9354 the start of the match. It should return non-zero if this
9355 match is to be skipped. E.g., because it is inside a comment
9356 or a string.
9357 When {skip} is omitted or empty, every match is accepted.
9358 When evaluating {skip} causes an error the search is aborted
9359 and -1 returned.
9360 {skip} can be a string, a lambda, a funcref or a partial.
9361 Anything else makes the function fail.
9362 In a `:def` function when the {skip} argument is a string
9363 constant it is compiled into instructions.
9364
9365 For {stopline} and {timeout} see |search()|.
9366
9367 The value of 'ignorecase' is used. 'magic' is ignored, the
9368 patterns are used like it's on.
9369
9370 The search starts exactly at the cursor. A match with
9371 {start}, {middle} or {end} at the next character, in the
9372 direction of searching, is the first one found. Example: >
9373 if 1
9374 if 2
9375 endif 2
9376 endif 1
9377< When starting at the "if 2", with the cursor on the "i", and
9378 searching forwards, the "endif 2" is found. When starting on
9379 the character just before the "if 2", the "endif 1" will be
9380 found. That's because the "if 2" will be found first, and
9381 then this is considered to be a nested if/endif from "if 2" to
9382 "endif 2".
9383 When searching backwards and {end} is more than one character,
9384 it may be useful to put "\zs" at the end of the pattern, so
9385 that when the cursor is inside a match with the end it finds
9386 the matching start.
9387
9388 Example, to find the "endif" command in a Vim script: >
9389
9390 :echo searchpair('\<if\>', '\<el\%[seif]\>', '\<en\%[dif]\>', 'W',
9391 \ 'getline(".") =~ "^\\s*\""')
9392
9393< The cursor must be at or after the "if" for which a match is
9394 to be found. Note that single-quote strings are used to avoid
9395 having to double the backslashes. The skip expression only
9396 catches comments at the start of a line, not after a command.
9397 Also, a word "en" or "if" halfway a line is considered a
9398 match.
9399 Another example, to search for the matching "{" of a "}": >
9400
9401 :echo searchpair('{', '', '}', 'bW')
9402
9403< This works when the cursor is at or before the "}" for which a
9404 match is to be found. To reject matches that syntax
9405 highlighting recognized as strings: >
9406
9407 :echo searchpair('{', '', '}', 'bW',
9408 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')
9409<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009410 Return type: |Number|
9411
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009412 *searchpairpos()*
9413searchpairpos({start}, {middle}, {end} [, {flags} [, {skip}
9414 [, {stopline} [, {timeout}]]]])
9415 Same as |searchpair()|, but returns a |List| with the line and
9416 column position of the match. The first element of the |List|
9417 is the line number and the second element is the byte index of
9418 the column position of the match. If no match is found,
9419 returns [0, 0]. >
9420
9421 :let [lnum,col] = searchpairpos('{', '', '}', 'n')
9422<
9423 See |match-parens| for a bigger and more useful example.
9424
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009425 Return type: list<number>
9426
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009427 *searchpos()*
9428searchpos({pattern} [, {flags} [, {stopline} [, {timeout} [, {skip}]]]])
9429 Same as |search()|, but returns a |List| with the line and
9430 column position of the match. The first element of the |List|
9431 is the line number and the second element is the byte index of
9432 the column position of the match. If no match is found,
9433 returns [0, 0].
9434 Example: >
9435 :let [lnum, col] = searchpos('mypattern', 'n')
9436
9437< When the 'p' flag is given then there is an extra item with
9438 the sub-pattern match number |search()-sub-match|. Example: >
9439 :let [lnum, col, submatch] = searchpos('\(\l\)\|\(\u\)', 'np')
9440< In this example "submatch" is 2 when a lowercase letter is
9441 found |/\l|, 3 when an uppercase letter is found |/\u|.
9442
9443 Can also be used as a |method|: >
9444 GetPattern()->searchpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009445<
9446 Return type: list<number>
9447
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009448
9449server2client({clientid}, {string}) *server2client()*
9450 Send a reply string to {clientid}. The most recent {clientid}
9451 that sent a string can be retrieved with expand("<client>").
9452 {only available when compiled with the |+clientserver| feature}
9453 Returns zero for success, -1 for failure.
9454 Note:
9455 This id has to be stored before the next command can be
9456 received. I.e. before returning from the received command and
9457 before calling any commands that waits for input.
9458 See also |clientserver|.
9459 Example: >
9460 :echo server2client(expand("<client>"), "HELLO")
9461
9462< Can also be used as a |method|: >
9463 GetClientId()->server2client(string)
9464<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009465 Return type: |Number|
9466
9467
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009468serverlist() *serverlist()*
9469 Return a list of available server names, one per line.
9470 When there are no servers or the information is not available
9471 an empty string is returned. See also |clientserver|.
9472 {only available when compiled with the |+clientserver| feature}
9473 Example: >
9474 :echo serverlist()
9475<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009476 Return type: |String|
9477
9478
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009479setbufline({buf}, {lnum}, {text}) *setbufline()*
9480 Set line {lnum} to {text} in buffer {buf}. This works like
9481 |setline()| for the specified buffer.
9482
9483 This function works only for loaded buffers. First call
9484 |bufload()| if needed.
9485
9486 To insert lines use |appendbufline()|.
9487 Any text properties in {lnum} are cleared.
9488
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009489 {text} can be a string to set one line, or a List of strings
9490 to set multiple lines. If the List extends below the last
9491 line then those lines are added. If the List is empty then
9492 nothing is changed and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009493
9494 For the use of {buf}, see |bufname()| above.
9495
9496 {lnum} is used like with |setline()|.
9497 Use "$" to refer to the last line in buffer {buf}.
9498 When {lnum} is just below the last line the {text} will be
9499 added below the last line.
9500
9501 When {buf} is not a valid buffer, the buffer is not loaded or
9502 {lnum} is not valid then 1 is returned. In |Vim9| script an
9503 error is given.
9504 On success 0 is returned.
9505
9506 Can also be used as a |method|, the base is passed as the
9507 third argument: >
9508 GetText()->setbufline(buf, lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009509<
9510 Return type: |Number|
9511
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009512
9513setbufvar({buf}, {varname}, {val}) *setbufvar()*
9514 Set option or local variable {varname} in buffer {buf} to
9515 {val}.
9516 This also works for a global or local window option, but it
9517 doesn't work for a global or local window variable.
9518 For a local window option the global value is unchanged.
9519 For the use of {buf}, see |bufname()| above.
9520 The {varname} argument is a string.
9521 Note that the variable name without "b:" must be used.
9522 Examples: >
9523 :call setbufvar(1, "&mod", 1)
9524 :call setbufvar("todo", "myvar", "foobar")
9525< This function is not available in the |sandbox|.
9526
9527 Can also be used as a |method|, the base is passed as the
9528 third argument: >
9529 GetValue()->setbufvar(buf, varname)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009530<
9531 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009532
9533
9534setcellwidths({list}) *setcellwidths()*
9535 Specify overrides for cell widths of character ranges. This
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009536 tells Vim how wide characters are when displayed in the
9537 terminal, counted in screen cells. The values override
9538 'ambiwidth'. Example: >
9539 call setcellwidths([
Bram Moolenaar938ae282023-02-20 20:44:55 +00009540 \ [0x111, 0x111, 1],
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009541 \ [0x2194, 0x2199, 2],
9542 \ ])
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009543
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009544< The {list} argument is a List of Lists with each three
9545 numbers: [{low}, {high}, {width}]. *E1109* *E1110*
9546 {low} and {high} can be the same, in which case this refers to
9547 one character. Otherwise it is the range of characters from
9548 {low} to {high} (inclusive). *E1111* *E1114*
K.Takata71933232023-01-20 16:00:55 +00009549 Only characters with value 0x80 and higher can be used.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009550
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009551 {width} must be either 1 or 2, indicating the character width
9552 in screen cells. *E1112*
9553 An error is given if the argument is invalid, also when a
Bram Moolenaar938ae282023-02-20 20:44:55 +00009554 range overlaps with another. *E1113*
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009555
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009556 If the new value causes 'fillchars' or 'listchars' to become
9557 invalid it is rejected and an error is given.
9558
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009559 To clear the overrides pass an empty {list}: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009560 setcellwidths([]);
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009561
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009562< You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
Bram Moolenaarb59ae592022-11-23 23:46:31 +00009563 the effect for known emoji characters. Move the cursor
9564 through the text to check if the cell widths of your terminal
9565 match with what Vim knows about each emoji. If it doesn't
9566 look right you need to adjust the {list} argument.
9567
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009568 Return type: |Number|
9569
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009570
9571setcharpos({expr}, {list}) *setcharpos()*
9572 Same as |setpos()| but uses the specified column number as the
9573 character index instead of the byte index in the line.
9574
9575 Example:
9576 With the text "여보세요" in line 8: >
9577 call setcharpos('.', [0, 8, 4, 0])
9578< positions the cursor on the fourth character '요'. >
9579 call setpos('.', [0, 8, 4, 0])
9580< positions the cursor on the second character '보'.
9581
9582 Can also be used as a |method|: >
9583 GetPosition()->setcharpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009584<
9585 Return type: |Number|
9586
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009587
9588setcharsearch({dict}) *setcharsearch()*
9589 Set the current character search information to {dict},
9590 which contains one or more of the following entries:
9591
9592 char character which will be used for a subsequent
9593 |,| or |;| command; an empty string clears the
9594 character search
9595 forward direction of character search; 1 for forward,
9596 0 for backward
9597 until type of character search; 1 for a |t| or |T|
9598 character search, 0 for an |f| or |F|
9599 character search
9600
9601 This can be useful to save/restore a user's character search
9602 from a script: >
9603 :let prevsearch = getcharsearch()
9604 :" Perform a command which clobbers user's search
9605 :call setcharsearch(prevsearch)
9606< Also see |getcharsearch()|.
9607
9608 Can also be used as a |method|: >
9609 SavedSearch()->setcharsearch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009610<
9611 Return type: dict<any>
9612
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009613
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009614setcmdline({str} [, {pos}]) *setcmdline()*
9615 Set the command line to {str} and set the cursor position to
9616 {pos}.
9617 If {pos} is omitted, the cursor is positioned after the text.
9618 Returns 0 when successful, 1 when not editing the command
9619 line.
9620
9621 Can also be used as a |method|: >
9622 GetText()->setcmdline()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009623<
9624 Return type: |Number|
9625
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009626
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009627setcmdpos({pos}) *setcmdpos()*
9628 Set the cursor position in the command line to byte position
9629 {pos}. The first position is 1.
9630 Use |getcmdpos()| to obtain the current position.
9631 Only works while editing the command line, thus you must use
9632 |c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='. For
9633 |c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
9634 set after the command line is set to the expression. For
9635 |c_CTRL-R_=| it is set after evaluating the expression but
9636 before inserting the resulting text.
9637 When the number is too big the cursor is put at the end of the
9638 line. A number smaller than one has undefined results.
Shougo Matsushita07ea5f12022-08-27 12:22:25 +01009639 Returns 0 when successful, 1 when not editing the command
9640 line.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009641
9642 Can also be used as a |method|: >
9643 GetPos()->setcmdpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009644<
9645 Return type: |Number|
9646
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009647
9648setcursorcharpos({lnum}, {col} [, {off}]) *setcursorcharpos()*
9649setcursorcharpos({list})
9650 Same as |cursor()| but uses the specified column number as the
9651 character index instead of the byte index in the line.
9652
9653 Example:
9654 With the text "여보세요" in line 4: >
9655 call setcursorcharpos(4, 3)
9656< positions the cursor on the third character '세'. >
9657 call cursor(4, 3)
9658< positions the cursor on the first character '여'.
9659
9660 Can also be used as a |method|: >
9661 GetCursorPos()->setcursorcharpos()
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009662<
9663 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009664
9665
9666setenv({name}, {val}) *setenv()*
9667 Set environment variable {name} to {val}. Example: >
9668 call setenv('HOME', '/home/myhome')
9669
9670< When {val} is |v:null| the environment variable is deleted.
9671 See also |expr-env|.
9672
9673 Can also be used as a |method|, the base is passed as the
9674 second argument: >
9675 GetPath()->setenv('PATH')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009676<
9677 Return type: |Number|
9678
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009679
9680setfperm({fname}, {mode}) *setfperm()* *chmod*
9681 Set the file permissions for {fname} to {mode}.
9682 {mode} must be a string with 9 characters. It is of the form
9683 "rwxrwxrwx", where each group of "rwx" flags represent, in
9684 turn, the permissions of the owner of the file, the group the
9685 file belongs to, and other users. A '-' character means the
9686 permission is off, any other character means on. Multi-byte
9687 characters are not supported.
9688
9689 For example "rw-r-----" means read-write for the user,
9690 readable by the group, not accessible by others. "xx-x-----"
9691 would do the same thing.
9692
9693 Returns non-zero for success, zero for failure.
9694
9695 Can also be used as a |method|: >
9696 GetFilename()->setfperm(mode)
9697<
9698 To read permissions see |getfperm()|.
9699
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009700 Return type: |Number|
9701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009702
9703setline({lnum}, {text}) *setline()*
9704 Set line {lnum} of the current buffer to {text}. To insert
9705 lines use |append()|. To set lines in another buffer use
Christian Brabandt946f61c2024-06-17 13:17:58 +02009706 |setbufline()|.
h-east52e7cc22024-07-28 17:03:29 +02009707 Any text properties in {lnum} are cleared. See
9708 |text-prop-cleared|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009709
9710 {lnum} is used like with |getline()|.
9711 When {lnum} is just below the last line the {text} will be
9712 added below the last line.
9713 {text} can be any type or a List of any type, each item is
Bram Moolenaarcd9c8d42022-11-05 23:46:43 +00009714 converted to a String. When {text} is an empty List then
9715 nothing is changed and FALSE is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009716
9717 If this succeeds, FALSE is returned. If this fails (most likely
9718 because {lnum} is invalid) TRUE is returned.
9719 In |Vim9| script an error is given if {lnum} is invalid.
9720
9721 Example: >
9722 :call setline(5, strftime("%c"))
9723
9724< When {text} is a |List| then line {lnum} and following lines
9725 will be set to the items in the list. Example: >
9726 :call setline(5, ['aaa', 'bbb', 'ccc'])
9727< This is equivalent to: >
9728 :for [n, l] in [[5, 'aaa'], [6, 'bbb'], [7, 'ccc']]
9729 : call setline(n, l)
9730 :endfor
9731
9732< Note: The '[ and '] marks are not set.
9733
9734 Can also be used as a |method|, the base is passed as the
9735 second argument: >
9736 GetText()->setline(lnum)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009737<
9738 Return type: |Number|
9739
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009740
9741setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()*
9742 Create or replace or add to the location list for window {nr}.
9743 {nr} can be the window number or the |window-ID|.
9744 When {nr} is zero the current window is used.
9745
9746 For a location list window, the displayed location list is
9747 modified. For an invalid window number {nr}, -1 is returned.
9748 Otherwise, same as |setqflist()|.
9749 Also see |location-list|.
9750
9751 For {action} see |setqflist-action|.
9752
9753 If the optional {what} dictionary argument is supplied, then
9754 only the items listed in {what} are set. Refer to |setqflist()|
9755 for the list of supported keys in {what}.
9756
9757 Can also be used as a |method|, the base is passed as the
9758 second argument: >
9759 GetLoclist()->setloclist(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009760<
9761 Return type: |Number|
9762
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009763
9764setmatches({list} [, {win}]) *setmatches()*
9765 Restores a list of matches saved by |getmatches()| for the
9766 current window. Returns 0 if successful, otherwise -1. All
9767 current matches are cleared before the list is restored. See
9768 example for |getmatches()|.
9769 If {win} is specified, use the window with this number or
9770 window ID instead of the current window.
9771
9772 Can also be used as a |method|: >
9773 GetMatches()->setmatches()
9774<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009775 Return type: |Number|
9776
9777
9778setpos({expr}, {list}) *setpos()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009779 Set the position for String {expr}. Possible values:
9780 . the cursor
9781 'x mark x
9782
9783 {list} must be a |List| with four or five numbers:
9784 [bufnum, lnum, col, off]
9785 [bufnum, lnum, col, off, curswant]
9786
9787 "bufnum" is the buffer number. Zero can be used for the
9788 current buffer. When setting an uppercase mark "bufnum" is
9789 used for the mark position. For other marks it specifies the
9790 buffer to set the mark in. You can use the |bufnr()| function
9791 to turn a file name into a buffer number.
9792 For setting the cursor and the ' mark "bufnum" is ignored,
9793 since these are associated with a window, not a buffer.
9794 Does not change the jumplist.
9795
9796 "lnum" and "col" are the position in the buffer. The first
9797 column is 1. Use a zero "lnum" to delete a mark. If "col" is
9798 smaller than 1 then 1 is used. To use the character count
9799 instead of the byte count, use |setcharpos()|.
9800
9801 The "off" number is only used when 'virtualedit' is set. Then
9802 it is the offset in screen columns from the start of the
9803 character. E.g., a position within a <Tab> or after the last
9804 character.
9805
9806 The "curswant" number is only used when setting the cursor
9807 position. It sets the preferred column for when moving the
9808 cursor vertically. When the "curswant" number is missing the
9809 preferred column is not set. When it is present and setting a
9810 mark position it is not used.
9811
9812 Note that for '< and '> changing the line number may result in
9813 the marks to be effectively be swapped, so that '< is always
9814 before '>.
9815
9816 Returns 0 when the position could be set, -1 otherwise.
9817 An error message is given if {expr} is invalid.
9818
9819 Also see |setcharpos()|, |getpos()| and |getcurpos()|.
9820
9821 This does not restore the preferred column for moving
9822 vertically; if you set the cursor position with this, |j| and
9823 |k| motions will jump to previous columns! Use |cursor()| to
9824 also set the preferred column. Also see the "curswant" key in
9825 |winrestview()|.
9826
9827 Can also be used as a |method|: >
9828 GetPosition()->setpos('.')
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009829<
9830 Return type: |Number|
9831
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009832
9833setqflist({list} [, {action} [, {what}]]) *setqflist()*
9834 Create or replace or add to the quickfix list.
9835
9836 If the optional {what} dictionary argument is supplied, then
9837 only the items listed in {what} are set. The first {list}
9838 argument is ignored. See below for the supported items in
9839 {what}.
9840 *setqflist-what*
9841 When {what} is not present, the items in {list} are used. Each
9842 item must be a dictionary. Non-dictionary items in {list} are
9843 ignored. Each dictionary item can contain the following
9844 entries:
9845
9846 bufnr buffer number; must be the number of a valid
9847 buffer
9848 filename name of a file; only used when "bufnr" is not
9849 present or it is invalid.
9850 module name of a module; if given it will be used in
9851 quickfix error window instead of the filename.
9852 lnum line number in the file
Bram Moolenaara2baa732022-02-04 16:09:54 +00009853 end_lnum end of lines, if the item spans multiple lines
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009854 pattern search pattern used to locate the error
9855 col column number
9856 vcol when non-zero: "col" is visual column
9857 when zero: "col" is byte index
Bram Moolenaara2baa732022-02-04 16:09:54 +00009858 end_col end column, if the item spans multiple columns
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009859 nr error number
9860 text description of the error
9861 type single-character error type, 'E', 'W', etc.
9862 valid recognized error message
Tom Praschanca6ac992023-08-11 23:26:12 +02009863 user_data custom data associated with the item, can be
9864 any type.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009865
9866 The "col", "vcol", "nr", "type" and "text" entries are
9867 optional. Either "lnum" or "pattern" entry can be used to
9868 locate a matching error line.
9869 If the "filename" and "bufnr" entries are not present or
9870 neither the "lnum" or "pattern" entries are present, then the
9871 item will not be handled as an error line.
9872 If both "pattern" and "lnum" are present then "pattern" will
9873 be used.
9874 If the "valid" entry is not supplied, then the valid flag is
9875 set when "bufnr" is a valid buffer or "filename" exists.
9876 If you supply an empty {list}, the quickfix list will be
9877 cleared.
9878 Note that the list is not exactly the same as what
9879 |getqflist()| returns.
9880
9881 {action} values: *setqflist-action* *E927*
9882 'a' The items from {list} are added to the existing
9883 quickfix list. If there is no existing list, then a
9884 new list is created.
9885
9886 'r' The items from the current quickfix list are replaced
9887 with the items from {list}. This can also be used to
9888 clear the list: >
9889 :call setqflist([], 'r')
9890<
Jeremy Fleischman27fbf6e2024-10-14 20:46:27 +02009891 'u' Like 'r', but tries to preserve the current selection
9892 in the quickfix list.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009893 'f' All the quickfix lists in the quickfix stack are
9894 freed.
9895
9896 If {action} is not present or is set to ' ', then a new list
9897 is created. The new quickfix list is added after the current
9898 quickfix list in the stack and all the following lists are
9899 freed. To add a new quickfix list at the end of the stack,
9900 set "nr" in {what} to "$".
9901
9902 The following items can be specified in dictionary {what}:
9903 context quickfix list context. See |quickfix-context|
9904 efm errorformat to use when parsing text from
9905 "lines". If this is not present, then the
9906 'errorformat' option value is used.
9907 See |quickfix-parse|
9908 id quickfix list identifier |quickfix-ID|
9909 idx index of the current entry in the quickfix
9910 list specified by 'id' or 'nr'. If set to '$',
9911 then the last entry in the list is set as the
9912 current entry. See |quickfix-index|
9913 items list of quickfix entries. Same as the {list}
9914 argument.
9915 lines use 'errorformat' to parse a list of lines and
9916 add the resulting entries to the quickfix list
9917 {nr} or {id}. Only a |List| value is supported.
9918 See |quickfix-parse|
9919 nr list number in the quickfix stack; zero
9920 means the current quickfix list and "$" means
9921 the last quickfix list.
9922 quickfixtextfunc
9923 function to get the text to display in the
9924 quickfix window. The value can be the name of
9925 a function or a funcref or a lambda. Refer to
9926 |quickfix-window-function| for an explanation
9927 of how to write the function and an example.
9928 title quickfix list title text. See |quickfix-title|
9929 Unsupported keys in {what} are ignored.
9930 If the "nr" item is not present, then the current quickfix list
9931 is modified. When creating a new quickfix list, "nr" can be
9932 set to a value one greater than the quickfix stack size.
9933 When modifying a quickfix list, to guarantee that the correct
9934 list is modified, "id" should be used instead of "nr" to
9935 specify the list.
9936
9937 Examples (See also |setqflist-examples|): >
9938 :call setqflist([], 'r', {'title': 'My search'})
9939 :call setqflist([], 'r', {'nr': 2, 'title': 'Errors'})
9940 :call setqflist([], 'a', {'id':qfid, 'lines':["F1:10:L10"]})
9941<
9942 Returns zero for success, -1 for failure.
9943
9944 This function can be used to create a quickfix list
9945 independent of the 'errorformat' setting. Use a command like
9946 `:cc 1` to jump to the first position.
9947
9948 Can also be used as a |method|, the base is passed as the
9949 second argument: >
9950 GetErrorlist()->setqflist()
9951<
Christian Brabandt5674c9a2024-06-09 00:13:43 +02009952 Return type: |Number|
9953
9954
9955setreg({regname}, {value} [, {options}]) *setreg()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +00009956 Set the register {regname} to {value}.
9957 If {regname} is "" or "@", the unnamed register '"' is used.
9958 The {regname} argument is a string. In |Vim9-script|
9959 {regname} must be one character.
9960
9961 {value} may be any value returned by |getreg()| or
9962 |getreginfo()|, including a |List| or |Dict|.
9963 If {options} contains "a" or {regname} is upper case,
9964 then the value is appended.
9965
9966 {options} can also contain a register type specification:
9967 "c" or "v" |characterwise| mode
9968 "l" or "V" |linewise| mode
9969 "b" or "<CTRL-V>" |blockwise-visual| mode
9970 If a number immediately follows "b" or "<CTRL-V>" then this is
9971 used as the width of the selection - if it is not specified
9972 then the width of the block is set to the number of characters
9973 in the longest line (counting a <Tab> as 1 character).
9974
9975 If {options} contains no register settings, then the default
9976 is to use character mode unless {value} ends in a <NL> for
9977 string {value} and linewise mode for list {value}. Blockwise
9978 mode is never selected automatically.
9979 Returns zero for success, non-zero for failure.
9980
9981 *E883*
9982 Note: you may not use |List| containing more than one item to
9983 set search and expression registers. Lists containing no
9984 items act like empty strings.
9985
9986 Examples: >
9987 :call setreg(v:register, @*)
9988 :call setreg('*', @%, 'ac')
9989 :call setreg('a', "1\n2\n3", 'b5')
9990 :call setreg('"', { 'points_to': 'a'})
9991
9992< This example shows using the functions to save and restore a
9993 register: >
9994 :let var_a = getreginfo()
9995 :call setreg('a', var_a)
9996< or: >
9997 :let var_a = getreg('a', 1, 1)
9998 :let var_amode = getregtype('a')
9999 ....
10000 :call setreg('a', var_a, var_amode)
10001< Note: you may not reliably restore register value
10002 without using the third argument to |getreg()| as without it
10003 newlines are represented as newlines AND Nul bytes are
10004 represented as newlines as well, see |NL-used-for-Nul|.
10005
10006 You can also change the type of a register by appending
10007 nothing: >
10008 :call setreg('a', '', 'al')
10009
10010< Can also be used as a |method|, the base is passed as the
10011 second argument: >
10012 GetText()->setreg('a')
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010013<
10014 Return type: |Number|
10015
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010016
10017settabvar({tabnr}, {varname}, {val}) *settabvar()*
10018 Set tab-local variable {varname} to {val} in tab page {tabnr}.
10019 |t:var|
10020 The {varname} argument is a string.
10021 Note that autocommands are blocked, side effects may not be
10022 triggered, e.g. when setting 'filetype'.
10023 Note that the variable name without "t:" must be used.
10024 Tabs are numbered starting with one.
10025 This function is not available in the |sandbox|.
10026
10027 Can also be used as a |method|, the base is passed as the
10028 third argument: >
10029 GetValue()->settabvar(tab, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010030<
10031 Return type: |Number|
10032
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010033
10034settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
10035 Set option or local variable {varname} in window {winnr} to
10036 {val}.
10037 Tabs are numbered starting with one. For the current tabpage
10038 use |setwinvar()|.
10039 {winnr} can be the window number or the |window-ID|.
10040 When {winnr} is zero the current window is used.
10041 Note that autocommands are blocked, side effects may not be
10042 triggered, e.g. when setting 'filetype' or 'syntax'.
10043 This also works for a global or local buffer option, but it
10044 doesn't work for a global or local buffer variable.
10045 For a local buffer option the global value is unchanged.
10046 Note that the variable name without "w:" must be used.
10047 Examples: >
10048 :call settabwinvar(1, 1, "&list", 0)
10049 :call settabwinvar(3, 2, "myvar", "foobar")
10050< This function is not available in the |sandbox|.
10051
10052 Can also be used as a |method|, the base is passed as the
10053 fourth argument: >
10054 GetValue()->settabwinvar(tab, winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010055<
10056 Return type: |Number|
10057
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010058
10059settagstack({nr}, {dict} [, {action}]) *settagstack()*
10060 Modify the tag stack of the window {nr} using {dict}.
10061 {nr} can be the window number or the |window-ID|.
10062
10063 For a list of supported items in {dict}, refer to
10064 |gettagstack()|. "curidx" takes effect before changing the tag
10065 stack.
10066 *E962*
10067 How the tag stack is modified depends on the {action}
10068 argument:
10069 - If {action} is not present or is set to 'r', then the tag
10070 stack is replaced.
10071 - If {action} is set to 'a', then new entries from {dict} are
10072 pushed (added) onto the tag stack.
10073 - If {action} is set to 't', then all the entries from the
10074 current entry in the tag stack or "curidx" in {dict} are
10075 removed and then new entries are pushed to the stack.
10076
10077 The current index is set to one after the length of the tag
10078 stack after the modification.
10079
10080 Returns zero for success, -1 for failure.
10081
10082 Examples (for more examples see |tagstack-examples|):
10083 Empty the tag stack of window 3: >
10084 call settagstack(3, {'items' : []})
10085
10086< Save and restore the tag stack: >
10087 let stack = gettagstack(1003)
10088 " do something else
10089 call settagstack(1003, stack)
10090 unlet stack
10091<
10092 Can also be used as a |method|, the base is passed as the
10093 second argument: >
10094 GetStack()->settagstack(winnr)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010095<
10096 Return type: |Number|
10097
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010098
10099setwinvar({winnr}, {varname}, {val}) *setwinvar()*
10100 Like |settabwinvar()| for the current tab page.
10101 Examples: >
10102 :call setwinvar(1, "&list", 0)
10103 :call setwinvar(2, "myvar", "foobar")
10104
10105< Can also be used as a |method|, the base is passed as the
10106 third argument: >
10107 GetValue()->setwinvar(winnr, name)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010108<
10109 Return type: |Number|
10110
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010111
10112sha256({string}) *sha256()*
10113 Returns a String with 64 hex characters, which is the SHA256
10114 checksum of {string}.
10115
10116 Can also be used as a |method|: >
10117 GetText()->sha256()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010118<
10119 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010120
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010121 {only available when compiled with the |+cryptv| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010122
10123shellescape({string} [, {special}]) *shellescape()*
10124 Escape {string} for use as a shell command argument.
10125 When the 'shell' contains powershell (MS-Windows) or pwsh
Bram Moolenaar944697a2022-02-20 19:48:20 +000010126 (MS-Windows, Linux, and macOS) then it will enclose {string}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010127 in single quotes and will double up all internal single
10128 quotes.
10129 On MS-Windows, when 'shellslash' is not set, it will enclose
10130 {string} in double quotes and double all double quotes within
10131 {string}.
10132 Otherwise it will enclose {string} in single quotes and
10133 replace all "'" with "'\''".
10134
Enno5faeb602024-05-15 21:54:19 +020010135 The {special} argument adds additional escaping of keywords
10136 used in Vim commands. When it is not omitted and a non-zero
K.Takatac0e038b2024-05-16 12:39:01 +090010137 number or a non-empty String (|non-zero-arg|), then special
10138 items such as "!", "%", "#" and "<cword>" (as listed in
10139 |expand()|) will be preceded by a backslash.
Enno5faeb602024-05-15 21:54:19 +020010140 This backslash will be removed again by the |:!| command.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010141
10142 The "!" character will be escaped (again with a |non-zero-arg|
10143 {special}) when 'shell' contains "csh" in the tail. That is
10144 because for csh and tcsh "!" is used for history replacement
10145 even when inside single quotes.
10146
10147 With a |non-zero-arg| {special} the <NL> character is also
10148 escaped. When 'shell' containing "csh" in the tail it's
10149 escaped a second time.
10150
10151 The "\" character will be escaped when 'shell' contains "fish"
10152 in the tail. That is because for fish "\" is used as an escape
10153 character inside single quotes.
10154
10155 Example of use with a |:!| command: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010156 :exe '!dir ' .. shellescape(expand('<cfile>'), 1)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010157< This results in a directory listing for the file under the
10158 cursor. Example of use with |system()|: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000010159 :call system("chmod +w -- " .. shellescape(expand("%")))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010160< See also |::S|.
10161
10162 Can also be used as a |method|: >
10163 GetCommand()->shellescape()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010164<
10165 Return type: |String|
10166
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010167
10168shiftwidth([{col}]) *shiftwidth()*
10169 Returns the effective value of 'shiftwidth'. This is the
10170 'shiftwidth' value unless it is zero, in which case it is the
10171 'tabstop' value. This function was introduced with patch
10172 7.3.694 in 2012, everybody should have it by now (however it
10173 did not allow for the optional {col} argument until 8.1.542).
10174
10175 When there is one argument {col} this is used as column number
10176 for which to return the 'shiftwidth' value. This matters for the
10177 'vartabstop' feature. If the 'vartabstop' setting is enabled and
10178 no {col} argument is given, column 1 will be assumed.
10179
10180 Can also be used as a |method|: >
10181 GetColumn()->shiftwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010182<
10183 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010184
10185sign_ functions are documented here: |sign-functions-details|
10186
10187
10188simplify({filename}) *simplify()*
10189 Simplify the file name as much as possible without changing
10190 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
10191 Unix) are not resolved. If the first path component in
10192 {filename} designates the current directory, this will be
10193 valid for the result as well. A trailing path separator is
10194 not removed either. On Unix "//path" is unchanged, but
10195 "///path" is simplified to "/path" (this follows the Posix
10196 standard).
10197 Example: >
10198 simplify("./dir/.././/file/") == "./file/"
10199< Note: The combination "dir/.." is only removed if "dir" is
10200 a searchable directory or does not exist. On Unix, it is also
10201 removed when "dir" is a symbolic link within the same
10202 directory. In order to resolve all the involved symbolic
10203 links before simplifying the path name, use |resolve()|.
10204
10205 Can also be used as a |method|: >
10206 GetName()->simplify()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010207<
10208 Return type: |String|
10209
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010210
10211sin({expr}) *sin()*
10212 Return the sine of {expr}, measured in radians, as a |Float|.
10213 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010214 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010215 Examples: >
10216 :echo sin(100)
10217< -0.506366 >
10218 :echo sin(-4.01)
10219< 0.763301
10220
10221 Can also be used as a |method|: >
10222 Compute()->sin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010223<
10224 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010225
10226
10227sinh({expr}) *sinh()*
10228 Return the hyperbolic sine of {expr} as a |Float| in the range
10229 [-inf, inf].
10230 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010231 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010232 Examples: >
10233 :echo sinh(0.5)
10234< 0.521095 >
10235 :echo sinh(-0.9)
10236< -1.026517
10237
10238 Can also be used as a |method|: >
10239 Compute()->sinh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010240<
10241 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010242
10243
10244slice({expr}, {start} [, {end}]) *slice()*
10245 Similar to using a |slice| "expr[start : end]", but "end" is
10246 used exclusive. And for a string the indexes are used as
10247 character indexes instead of byte indexes, like in
zeertzjqad387692024-03-23 08:23:48 +010010248 |vim9script|. Also, composing characters are treated as a
10249 part of the preceding base character.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010250 When {end} is omitted the slice continues to the last item.
10251 When {end} is -1 the last item is omitted.
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010252 Returns an empty value if {start} or {end} are invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010253
10254 Can also be used as a |method|: >
10255 GetList()->slice(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010256<
10257 Return type: list<{type}>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010258
10259
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010260sort({list} [, {how} [, {dict}]]) *sort()* *E702*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010261 Sort the items in {list} in-place. Returns {list}.
10262
10263 If you want a list to remain unmodified make a copy first: >
10264 :let sortedlist = sort(copy(mylist))
10265
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010266< When {how} is omitted or is a string, then sort() uses the
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010267 string representation of each item to sort on. Numbers sort
10268 after Strings, |Lists| after Numbers. For sorting text in the
10269 current buffer use |:sort|.
10270
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010271 When {how} is given and it is 'i' then case is ignored.
10272 In legacy script, for backwards compatibility, the value one
10273 can be used to ignore case. Zero means to not ignore case.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010274
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010275 When {how} is given and it is 'l' then the current collation
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010276 locale is used for ordering. Implementation details: strcoll()
10277 is used to compare strings. See |:language| check or set the
10278 collation locale. |v:collate| can also be used to check the
10279 current locale. Sorting using the locale typically ignores
10280 case. Example: >
10281 " ö is sorted similarly to o with English locale.
10282 :language collate en_US.UTF8
10283 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10284< ['n', 'o', 'O', 'ö', 'p', 'z'] ~
10285>
10286 " ö is sorted after z with Swedish locale.
10287 :language collate sv_SE.UTF8
10288 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l')
10289< ['n', 'o', 'O', 'p', 'z', 'ö'] ~
10290 This does not work properly on Mac.
10291
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010292 When {how} is given and it is 'n' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010293 sorted numerical (Implementation detail: this uses the
Bram Moolenaarbe19d782023-03-09 22:06:49 +000010294 strtod() function to parse numbers. Strings, Lists, Dicts and
10295 Funcrefs will be considered as being 0). Note that this won't
10296 sort a list of strings with numbers!
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010297
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010298 When {how} is given and it is 'N' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010299 sorted numerical. This is like 'n' but a string containing
10300 digits will be used as the number they represent.
10301
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010302 When {how} is given and it is 'f' then all items will be
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010303 sorted numerical. All values must be a Number or a Float.
10304
Bram Moolenaar2007dd42022-02-23 13:17:47 +000010305 When {how} is a |Funcref| or a function name, this function
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010306 is called to compare items. The function is invoked with two
10307 items as argument and must return zero if they are equal, 1 or
10308 bigger if the first one sorts after the second one, -1 or
10309 smaller if the first one sorts before the second one.
10310
10311 {dict} is for functions with the "dict" attribute. It will be
10312 used to set the local variable "self". |Dictionary-function|
10313
10314 The sort is stable, items which compare equal (as number or as
10315 string) will keep their relative position. E.g., when sorting
10316 on numbers, text strings will sort next to each other, in the
10317 same order as they were originally.
10318
10319 Can also be used as a |method|: >
10320 mylist->sort()
10321
10322< Also see |uniq()|.
10323
10324 Example: >
10325 func MyCompare(i1, i2)
10326 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
10327 endfunc
10328 eval mylist->sort("MyCompare")
10329< A shorter compare version for this specific simple case, which
10330 ignores overflow: >
10331 func MyCompare(i1, i2)
10332 return a:i1 - a:i2
10333 endfunc
10334< For a simple expression you can use a lambda: >
10335 eval mylist->sort({i1, i2 -> i1 - i2})
10336<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010337 Return type: list<{type}>
10338
10339
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010340sound_clear() *sound_clear()*
10341 Stop playing all sounds.
10342
10343 On some Linux systems you may need the libcanberra-pulse
10344 package, otherwise sound may not stop.
10345
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010346 Return type: |Number|
10347
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010348 {only available when compiled with the |+sound| feature}
10349
10350 *sound_playevent()*
10351sound_playevent({name} [, {callback}])
10352 Play a sound identified by {name}. Which event names are
10353 supported depends on the system. Often the XDG sound names
10354 are used. On Ubuntu they may be found in
10355 /usr/share/sounds/freedesktop/stereo. Example: >
10356 call sound_playevent('bell')
10357< On MS-Windows, {name} can be SystemAsterisk, SystemDefault,
10358 SystemExclamation, SystemExit, SystemHand, SystemQuestion,
10359 SystemStart, SystemWelcome, etc.
Yee Cheng Chin4314e4f2022-10-08 13:50:05 +010010360 On macOS, {name} refers to files located in
10361 /System/Library/Sounds (e.g. "Tink"). It will also work for
10362 custom installed sounds in folders like ~/Library/Sounds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010363
10364 When {callback} is specified it is invoked when the sound is
10365 finished. The first argument is the sound ID, the second
10366 argument is the status:
10367 0 sound was played to the end
10368 1 sound was interrupted
10369 2 error occurred after sound started
10370 Example: >
10371 func Callback(id, status)
10372 echomsg "sound " .. a:id .. " finished with " .. a:status
10373 endfunc
10374 call sound_playevent('bell', 'Callback')
10375
10376< MS-Windows: {callback} doesn't work for this function.
10377
10378 Returns the sound ID, which can be passed to `sound_stop()`.
10379 Returns zero if the sound could not be played.
10380
10381 Can also be used as a |method|: >
10382 GetSoundName()->sound_playevent()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010383<
10384 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010385
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010386 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010387
10388 *sound_playfile()*
10389sound_playfile({path} [, {callback}])
10390 Like `sound_playevent()` but play sound file {path}. {path}
10391 must be a full path. On Ubuntu you may find files to play
10392 with this command: >
10393 :!find /usr/share/sounds -type f | grep -v index.theme
10394
10395< Can also be used as a |method|: >
10396 GetSoundPath()->sound_playfile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010397<
10398 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010399
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010400 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010401
10402
10403sound_stop({id}) *sound_stop()*
10404 Stop playing sound {id}. {id} must be previously returned by
10405 `sound_playevent()` or `sound_playfile()`.
10406
10407 On some Linux systems you may need the libcanberra-pulse
10408 package, otherwise sound may not stop.
10409
10410 On MS-Windows, this does not work for event sound started by
10411 `sound_playevent()`. To stop event sounds, use `sound_clear()`.
10412
10413 Can also be used as a |method|: >
10414 soundid->sound_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010415<
10416 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010417
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010418 {only available when compiled with the |+sound| feature}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010419
10420 *soundfold()*
10421soundfold({word})
10422 Return the sound-folded equivalent of {word}. Uses the first
10423 language in 'spelllang' for the current window that supports
10424 soundfolding. 'spell' must be set. When no sound folding is
10425 possible the {word} is returned unmodified.
10426 This can be used for making spelling suggestions. Note that
10427 the method can be quite slow.
10428
10429 Can also be used as a |method|: >
10430 GetWord()->soundfold()
10431<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010432 Return type: |String|
10433
10434
10435spellbadword([{sentence}]) *spellbadword()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010436 Without argument: The result is the badly spelled word under
10437 or after the cursor. The cursor is moved to the start of the
10438 bad word. When no bad word is found in the cursor line the
10439 result is an empty string and the cursor doesn't move.
10440
10441 With argument: The result is the first word in {sentence} that
10442 is badly spelled. If there are no spelling mistakes the
10443 result is an empty string.
10444
10445 The return value is a list with two items:
10446 - The badly spelled word or an empty string.
10447 - The type of the spelling error:
10448 "bad" spelling mistake
10449 "rare" rare word
10450 "local" word only valid in another region
10451 "caps" word should start with Capital
10452 Example: >
10453 echo spellbadword("the quik brown fox")
10454< ['quik', 'bad'] ~
10455
10456 The spelling information for the current window and the value
10457 of 'spelllang' are used.
10458
10459 Can also be used as a |method|: >
10460 GetText()->spellbadword()
10461<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010462 Return type: list<string>
10463
10464
10465spellsuggest({word} [, {max} [, {capital}]]) *spellsuggest()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010466 Return a |List| with spelling suggestions to replace {word}.
10467 When {max} is given up to this number of suggestions are
10468 returned. Otherwise up to 25 suggestions are returned.
10469
10470 When the {capital} argument is given and it's non-zero only
10471 suggestions with a leading capital will be given. Use this
10472 after a match with 'spellcapcheck'.
10473
10474 {word} can be a badly spelled word followed by other text.
10475 This allows for joining two words that were split. The
10476 suggestions also include the following text, thus you can
10477 replace a line.
10478
10479 {word} may also be a good word. Similar words will then be
10480 returned. {word} itself is not included in the suggestions,
10481 although it may appear capitalized.
10482
10483 The spelling information for the current window is used. The
10484 values of 'spelllang' and 'spellsuggest' are used.
10485
10486 Can also be used as a |method|: >
10487 GetWord()->spellsuggest()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010488<
10489 Return type: list<string> or list<any>
10490
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010491
10492split({string} [, {pattern} [, {keepempty}]]) *split()*
10493 Make a |List| out of {string}. When {pattern} is omitted or
Shane Harperc1b39842024-07-17 19:40:40 +020010494 empty each white space separated sequence of characters
10495 becomes an item.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010496 Otherwise the string is split where {pattern} matches,
10497 removing the matched characters. 'ignorecase' is not used
10498 here, add \c to ignore case. |/\c|
10499 When the first or last item is empty it is omitted, unless the
10500 {keepempty} argument is given and it's non-zero.
10501 Other empty items are kept when {pattern} matches at least one
10502 character or when {keepempty} is non-zero.
10503 Example: >
10504 :let words = split(getline('.'), '\W\+')
10505< To split a string in individual characters: >
10506 :for c in split(mystring, '\zs')
10507< If you want to keep the separator you can also use '\zs' at
10508 the end of the pattern: >
10509 :echo split('abc:def:ghi', ':\zs')
10510< ['abc:', 'def:', 'ghi'] ~
10511 Splitting a table where the first element can be empty: >
10512 :let items = split(line, ':', 1)
10513< The opposite function is |join()|.
10514
10515 Can also be used as a |method|: >
10516 GetString()->split()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010517<
10518 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010519
10520sqrt({expr}) *sqrt()*
10521 Return the non-negative square root of Float {expr} as a
10522 |Float|.
10523 {expr} must evaluate to a |Float| or a |Number|. When {expr}
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010524 is negative the result is NaN (Not a Number). Returns 0.0 if
10525 {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010526 Examples: >
10527 :echo sqrt(100)
10528< 10.0 >
10529 :echo sqrt(-4.01)
10530< nan
10531 "nan" may be different, it depends on system libraries.
10532
10533 Can also be used as a |method|: >
10534 Compute()->sqrt()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010535<
10536 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010537
10538
10539srand([{expr}]) *srand()*
10540 Initialize seed used by |rand()|:
10541 - If {expr} is not given, seed values are initialized by
10542 reading from /dev/urandom, if possible, or using time(NULL)
10543 a.k.a. epoch time otherwise; this only has second accuracy.
10544 - If {expr} is given it must be a Number. It is used to
10545 initialize the seed values. This is useful for testing or
10546 when a predictable sequence is intended.
10547
10548 Examples: >
10549 :let seed = srand()
10550 :let seed = srand(userinput)
10551 :echo rand(seed)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010552<
10553 Return type: list<number>
10554
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010555
10556state([{what}]) *state()*
10557 Return a string which contains characters indicating the
10558 current state. Mostly useful in callbacks that want to do
10559 work that may not always be safe. Roughly this works like:
10560 - callback uses state() to check if work is safe to do.
10561 Yes: then do it right away.
10562 No: add to work queue and add a |SafeState| and/or
10563 |SafeStateAgain| autocommand (|SafeState| triggers at
10564 toplevel, |SafeStateAgain| triggers after handling
10565 messages and callbacks).
10566 - When SafeState or SafeStateAgain is triggered and executes
10567 your autocommand, check with `state()` if the work can be
10568 done now, and if yes remove it from the queue and execute.
10569 Remove the autocommand if the queue is now empty.
10570 Also see |mode()|.
10571
10572 When {what} is given only characters in this string will be
10573 added. E.g, this checks if the screen has scrolled: >
10574 if state('s') == ''
10575 " screen has not scrolled
10576<
10577 These characters indicate the state, generally indicating that
10578 something is busy:
10579 m halfway a mapping, :normal command, feedkeys() or
10580 stuffed command
10581 o operator pending, e.g. after |d|
10582 a Insert mode autocomplete active
10583 x executing an autocommand
10584 w blocked on waiting, e.g. ch_evalexpr(), ch_read() and
10585 ch_readraw() when reading json
10586 S not triggering SafeState or SafeStateAgain, e.g. after
10587 |f| or a count
10588 c callback invoked, including timer (repeats for
10589 recursiveness up to "ccc")
10590 s screen has scrolled for messages
10591
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010592 Return type: |String|
10593
10594
Yegappan Lakshmanan1aefe1d2025-01-14 17:29:42 +010010595str2blob({string} [, {options}]) *str2blob()*
10596 Return a Blob by converting the characters in {string} into
10597 bytes.
10598
10599 If {options} is not supplied, the current 'encoding' value is
10600 used to convert the characters in {string} into bytes.
10601
10602 The argument {options} is a |Dict| and supports the following
10603 items:
10604 encoding Encode the characters in {string} using this
10605 encoding. The value is a |String|. See
10606 |encoding-names| for the supported values.
10607
10608 An error is given and an empty blob is returned if the
10609 character encoding fails.
10610
10611 Returns an empty Blob if {string} is empty.
10612
10613 See also |blob2str()|
10614
10615 Examples: >
10616 str2blob("ab") returns 0z6162
10617 str2blob("«»") returns 0zC2ABC2BB
10618 str2blob("«»", {'encoding': 'latin1'}) returns 0zABBB
10619<
10620 Can also be used as a |method|: >
10621 GetStr()->str2blob()
10622<
10623 Return type: |Blob|
10624
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010625str2float({string} [, {quoted}]) *str2float()*
10626 Convert String {string} to a Float. This mostly works the
10627 same as when using a floating point number in an expression,
10628 see |floating-point-format|. But it's a bit more permissive.
10629 E.g., "1e40" is accepted, while in an expression you need to
10630 write "1.0e40". The hexadecimal form "0x123" is also
10631 accepted, but not others, like binary or octal.
10632 When {quoted} is present and non-zero then embedded single
10633 quotes before the dot are ignored, thus "1'000.0" is a
10634 thousand.
10635 Text after the number is silently ignored.
10636 The decimal point is always '.', no matter what the locale is
10637 set to. A comma ends the number: "12,345.67" is converted to
10638 12.0. You can strip out thousands separators with
10639 |substitute()|: >
10640 let f = str2float(substitute(text, ',', '', 'g'))
10641<
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010642 Returns 0.0 if the conversion fails.
10643
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010644 Can also be used as a |method|: >
10645 let f = text->substitute(',', '', 'g')->str2float()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010646<
10647 Return type: |Float|
10648
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010649
10650str2list({string} [, {utf8}]) *str2list()*
10651 Return a list containing the number values which represent
10652 each character in String {string}. Examples: >
10653 str2list(" ") returns [32]
10654 str2list("ABC") returns [65, 66, 67]
10655< |list2str()| does the opposite.
10656
10657 When {utf8} is omitted or zero, the current 'encoding' is used.
10658 When {utf8} is TRUE, always treat the String as UTF-8
10659 characters. With UTF-8 composing characters are handled
10660 properly: >
10661 str2list("á") returns [97, 769]
10662
10663< Can also be used as a |method|: >
10664 GetString()->str2list()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010665<
10666 Return type: list<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010667
10668
10669str2nr({string} [, {base} [, {quoted}]]) *str2nr()*
10670 Convert string {string} to a number.
10671 {base} is the conversion base, it can be 2, 8, 10 or 16.
10672 When {quoted} is present and non-zero then embedded single
10673 quotes are ignored, thus "1'000'000" is a million.
10674
10675 When {base} is omitted base 10 is used. This also means that
10676 a leading zero doesn't cause octal conversion to be used, as
10677 with the default String to Number conversion. Example: >
10678 let nr = str2nr('0123')
10679<
10680 When {base} is 16 a leading "0x" or "0X" is ignored. With a
10681 different base the result will be zero. Similarly, when
10682 {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
10683 {base} is 2 a leading "0b" or "0B" is ignored.
10684 Text after the number is silently ignored.
10685
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010686 Returns 0 if {string} is empty or on error.
10687
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010688 Can also be used as a |method|: >
10689 GetText()->str2nr()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010690<
10691 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010692
10693
10694strcharlen({string}) *strcharlen()*
10695 The result is a Number, which is the number of characters
10696 in String {string}. Composing characters are ignored.
10697 |strchars()| can count the number of characters, counting
10698 composing characters separately.
10699
Bram Moolenaar6ba83ba2022-06-12 22:15:57 +010010700 Returns 0 if {string} is empty or on error.
10701
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010702 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10703
10704 Can also be used as a |method|: >
10705 GetText()->strcharlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010706<
10707 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010708
10709
10710strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()*
10711 Like |strpart()| but using character index and length instead
10712 of byte index and length.
10713 When {skipcc} is omitted or zero, composing characters are
10714 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010715 When {skipcc} set to 1, composing characters are treated as a
10716 part of the preceding base character, similar to |slice()|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010717 When a character index is used where a character does not
10718 exist it is omitted and counted as one character. For
10719 example: >
10720 strcharpart('abc', -1, 2)
10721< results in 'a'.
10722
Bram Moolenaard592deb2022-06-17 15:42:40 +010010723 Returns an empty string on error.
10724
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010725 Can also be used as a |method|: >
10726 GetText()->strcharpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010727<
10728 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010729
10730
10731strchars({string} [, {skipcc}]) *strchars()*
10732 The result is a Number, which is the number of characters
10733 in String {string}.
10734 When {skipcc} is omitted or zero, composing characters are
10735 counted separately.
zeertzjqad387692024-03-23 08:23:48 +010010736 When {skipcc} set to 1, composing characters are ignored.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010737 |strcharlen()| always does this.
10738
Bram Moolenaard592deb2022-06-17 15:42:40 +010010739 Returns zero on error.
10740
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010741 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|.
10742
10743 {skipcc} is only available after 7.4.755. For backward
10744 compatibility, you can define a wrapper function: >
10745 if has("patch-7.4.755")
10746 function s:strchars(str, skipcc)
10747 return strchars(a:str, a:skipcc)
10748 endfunction
10749 else
10750 function s:strchars(str, skipcc)
10751 if a:skipcc
10752 return strlen(substitute(a:str, ".", "x", "g"))
10753 else
10754 return strchars(a:str)
10755 endif
10756 endfunction
10757 endif
10758<
10759 Can also be used as a |method|: >
10760 GetText()->strchars()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010761<
10762 Return type: |Number|
10763
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010764
10765strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
10766 The result is a Number, which is the number of display cells
10767 String {string} occupies on the screen when it starts at {col}
10768 (first column is zero). When {col} is omitted zero is used.
10769 Otherwise it is the screen column where to start. This
10770 matters for Tab characters.
10771 The option settings of the current window are used. This
10772 matters for anything that's displayed differently, such as
10773 'tabstop' and 'display'.
10774 When {string} contains characters with East Asian Width Class
10775 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010776 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010777 Also see |strlen()|, |strwidth()| and |strchars()|.
10778
10779 Can also be used as a |method|: >
10780 GetText()->strdisplaywidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010781<
10782 Return type: |Number|
10783
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010784
10785strftime({format} [, {time}]) *strftime()*
10786 The result is a String, which is a formatted date and time, as
10787 specified by the {format} string. The given {time} is used,
10788 or the current time if no time is given. The accepted
10789 {format} depends on your system, thus this is not portable!
10790 See the manual page of the C function strftime() for the
10791 format. The maximum length of the result is 80 characters.
10792 See also |localtime()|, |getftime()| and |strptime()|.
10793 The language can be changed with the |:language| command.
10794 Examples: >
10795 :echo strftime("%c") Sun Apr 27 11:49:23 1997
10796 :echo strftime("%Y %b %d %X") 1997 Apr 27 11:53:25
10797 :echo strftime("%y%m%d %T") 970427 11:53:55
10798 :echo strftime("%H:%M") 11:55
10799 :echo strftime("%c", getftime("file.c"))
10800 Show mod time of file.c.
10801< Not available on all systems. To check use: >
10802 :if exists("*strftime")
10803
10804< Can also be used as a |method|: >
10805 GetFormat()->strftime()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010806<
10807 Return type: |String|
10808
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010809
10810strgetchar({str}, {index}) *strgetchar()*
Bram Moolenaar2d8ed022022-05-21 13:08:16 +010010811 Get a Number corresponding to the character at {index} in
10812 {str}. This uses a zero-based character index, not a byte
10813 index. Composing characters are considered separate
10814 characters here. Use |nr2char()| to convert the Number to a
10815 String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010816 Returns -1 if {index} is invalid.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010817 Also see |strcharpart()| and |strchars()|.
10818
10819 Can also be used as a |method|: >
10820 GetText()->strgetchar(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010821<
10822 Return type: |Number|
10823
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010824
10825stridx({haystack}, {needle} [, {start}]) *stridx()*
10826 The result is a Number, which gives the byte index in
10827 {haystack} of the first occurrence of the String {needle}.
10828 If {start} is specified, the search starts at index {start}.
10829 This can be used to find a second match: >
10830 :let colon1 = stridx(line, ":")
10831 :let colon2 = stridx(line, ":", colon1 + 1)
10832< The search is done case-sensitive.
10833 For pattern searches use |match()|.
10834 -1 is returned if the {needle} does not occur in {haystack}.
10835 See also |strridx()|.
10836 Examples: >
10837 :echo stridx("An Example", "Example") 3
10838 :echo stridx("Starting point", "Start") 0
10839 :echo stridx("Starting point", "start") -1
10840< *strstr()* *strchr()*
10841 stridx() works similar to the C function strstr(). When used
10842 with a single character it works similar to strchr().
10843
10844 Can also be used as a |method|: >
10845 GetHaystack()->stridx(needle)
10846<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010847 Return type: |Number|
10848
10849
10850string({expr}) *string()*
10851 Return {expr} converted to a String. If {expr} is a Number,
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010852 Float, String, Blob or a composition of them, then the result
10853 can be parsed back with |eval()|.
10854 {expr} type result ~
10855 String 'string' (single quotes are doubled)
10856 Number 123
10857 Float 123.123456 or 1.123456e8
10858 Funcref function('name')
10859 Blob 0z00112233.44556677.8899
10860 List [item, item]
10861 Dictionary {key: value, key: value}
Bram Moolenaarf1dcd142022-12-31 15:30:45 +000010862 Class class SomeName
10863 Object object of SomeName {lnum: 1, col: 3}
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010010864 Enum enum EnumName
Yegappan Lakshmanan3cf121e2024-03-31 18:45:35 +020010865 EnumValue enum name.value {name: str, ordinal: nr}
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010866
10867 When a |List| or |Dictionary| has a recursive reference it is
10868 replaced by "[...]" or "{...}". Using eval() on the result
10869 will then fail.
10870
mityu7f0bba22024-03-29 10:14:41 +010010871 For an object, invokes the string() method to get a textual
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010872 representation of the object. If the method is not present,
mityu7f0bba22024-03-29 10:14:41 +010010873 then the default representation is used. |object-string()|
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +010010874
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010875 Can also be used as a |method|: >
10876 mylist->string()
10877
10878< Also see |strtrans()|.
10879
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010880 Return type: |String|
10881
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010882
10883strlen({string}) *strlen()*
10884 The result is a Number, which is the length of the String
10885 {string} in bytes.
10886 If the argument is a Number it is first converted to a String.
Bram Moolenaard592deb2022-06-17 15:42:40 +010010887 For other types an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010888 If you want to count the number of multibyte characters use
10889 |strchars()|.
10890 Also see |len()|, |strdisplaywidth()| and |strwidth()|.
10891
10892 Can also be used as a |method|: >
10893 GetString()->strlen()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010894<
10895 Return type: |Number|
10896
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010897
10898strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
10899 The result is a String, which is part of {src}, starting from
10900 byte {start}, with the byte length {len}.
10901 When {chars} is present and TRUE then {len} is the number of
10902 characters positions (composing characters are not counted
10903 separately, thus "1" means one base character and any
10904 following composing characters).
10905 To count {start} as characters instead of bytes use
10906 |strcharpart()|.
10907
10908 When bytes are selected which do not exist, this doesn't
10909 result in an error, the bytes are simply omitted.
10910 If {len} is missing, the copy continues from {start} till the
10911 end of the {src}. >
10912 strpart("abcdefg", 3, 2) == "de"
10913 strpart("abcdefg", -2, 4) == "ab"
10914 strpart("abcdefg", 5, 4) == "fg"
10915 strpart("abcdefg", 3) == "defg"
10916
10917< Note: To get the first character, {start} must be 0. For
10918 example, to get the character under the cursor: >
10919 strpart(getline("."), col(".") - 1, 1, v:true)
10920<
Bram Moolenaard592deb2022-06-17 15:42:40 +010010921 Returns an empty string on error.
10922
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010923 Can also be used as a |method|: >
10924 GetText()->strpart(5)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010925<
10926 Return type: |String|
10927
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010928
10929strptime({format}, {timestring}) *strptime()*
10930 The result is a Number, which is a unix timestamp representing
10931 the date and time in {timestring}, which is expected to match
10932 the format specified in {format}.
10933
10934 The accepted {format} depends on your system, thus this is not
10935 portable! See the manual page of the C function strptime()
10936 for the format. Especially avoid "%c". The value of $TZ also
10937 matters.
10938
10939 If the {timestring} cannot be parsed with {format} zero is
10940 returned. If you do not know the format of {timestring} you
10941 can try different {format} values until you get a non-zero
10942 result.
10943
10944 See also |strftime()|.
10945 Examples: >
10946 :echo strptime("%Y %b %d %X", "1997 Apr 27 11:49:23")
10947< 862156163 >
10948 :echo strftime("%c", strptime("%y%m%d %T", "970427 11:53:55"))
10949< Sun Apr 27 11:53:55 1997 >
10950 :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600)
10951< Sun Apr 27 12:53:55 1997
10952
10953 Can also be used as a |method|: >
10954 GetFormat()->strptime(timestring)
10955<
10956 Not available on all systems. To check use: >
10957 :if exists("*strptime")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010958<
10959 Return type: |Number|
10960
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010961
10962strridx({haystack}, {needle} [, {start}]) *strridx()*
10963 The result is a Number, which gives the byte index in
10964 {haystack} of the last occurrence of the String {needle}.
10965 When {start} is specified, matches beyond this index are
10966 ignored. This can be used to find a match before a previous
10967 match: >
10968 :let lastcomma = strridx(line, ",")
10969 :let comma2 = strridx(line, ",", lastcomma - 1)
10970< The search is done case-sensitive.
10971 For pattern searches use |match()|.
10972 -1 is returned if the {needle} does not occur in {haystack}.
10973 If the {needle} is empty the length of {haystack} is returned.
10974 See also |stridx()|. Examples: >
10975 :echo strridx("an angry armadillo", "an") 3
10976< *strrchr()*
10977 When used with a single character it works similar to the C
10978 function strrchr().
10979
10980 Can also be used as a |method|: >
10981 GetHaystack()->strridx(needle)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010982<
10983 Return type: |Number|
10984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010985
10986strtrans({string}) *strtrans()*
10987 The result is a String, which is {string} with all unprintable
10988 characters translated into printable characters |'isprint'|.
10989 Like they are shown in a window. Example: >
10990 echo strtrans(@a)
10991< This displays a newline in register a as "^@" instead of
10992 starting a new line.
10993
Bram Moolenaard592deb2022-06-17 15:42:40 +010010994 Returns an empty string on error.
10995
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000010996 Can also be used as a |method|: >
10997 GetString()->strtrans()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020010998<
10999 Return type: |String|
11000
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011001
Christian Brabandt67672ef2023-04-24 21:09:54 +010011002strutf16len({string} [, {countcc}]) *strutf16len()*
11003 The result is a Number, which is the number of UTF-16 code
11004 units in String {string} (after converting it to UTF-16).
11005
11006 When {countcc} is TRUE, composing characters are counted
11007 separately.
11008 When {countcc} is omitted or FALSE, composing characters are
11009 ignored.
11010
11011 Returns zero on error.
11012
11013 Also see |strlen()| and |strcharlen()|.
11014 Examples: >
11015 echo strutf16len('a') returns 1
11016 echo strutf16len('©') returns 1
11017 echo strutf16len('😊') returns 2
11018 echo strutf16len('ą́') returns 1
11019 echo strutf16len('ą́', v:true) returns 3
a5ob7r790f9a82023-09-25 06:05:47 +090011020<
Christian Brabandt67672ef2023-04-24 21:09:54 +010011021 Can also be used as a |method|: >
11022 GetText()->strutf16len()
11023<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011024 Return type: |Number|
11025
11026
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011027strwidth({string}) *strwidth()*
11028 The result is a Number, which is the number of display cells
11029 String {string} occupies. A Tab character is counted as one
11030 cell, alternatively use |strdisplaywidth()|.
11031 When {string} contains characters with East Asian Width Class
11032 Ambiguous, this function's return value depends on 'ambiwidth'.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011033 Returns zero on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011034 Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
11035
11036 Can also be used as a |method|: >
11037 GetString()->strwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011038<
11039 Return type: |Number|
11040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011041
11042submatch({nr} [, {list}]) *submatch()* *E935*
11043 Only for an expression in a |:substitute| command or
11044 substitute() function.
11045 Returns the {nr}'th submatch of the matched text. When {nr}
11046 is 0 the whole matched text is returned.
11047 Note that a NL in the string can stand for a line break of a
11048 multi-line match or a NUL character in the text.
11049 Also see |sub-replace-expression|.
11050
11051 If {list} is present and non-zero then submatch() returns
11052 a list of strings, similar to |getline()| with two arguments.
11053 NL characters in the text represent NUL characters in the
11054 text.
11055 Only returns more than one item for |:substitute|, inside
11056 |substitute()| this list will always contain one or zero
11057 items, since there are no real line breaks.
11058
11059 When substitute() is used recursively only the submatches in
11060 the current (deepest) call can be obtained.
11061
Bram Moolenaard592deb2022-06-17 15:42:40 +010011062 Returns an empty string or list on error.
11063
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011064 Examples: >
11065 :s/\d\+/\=submatch(0) + 1/
11066 :echo substitute(text, '\d\+', '\=submatch(0) + 1', '')
11067< This finds the first number in the line and adds one to it.
11068 A line break is included as a newline character.
11069
11070 Can also be used as a |method|: >
11071 GetNr()->submatch()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011072<
11073 Return type: |String| or list<string> depending on {list}
11074
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011075
11076substitute({string}, {pat}, {sub}, {flags}) *substitute()*
11077 The result is a String, which is a copy of {string}, in which
11078 the first match of {pat} is replaced with {sub}.
11079 When {flags} is "g", all matches of {pat} in {string} are
11080 replaced. Otherwise {flags} should be "".
11081
11082 This works like the ":substitute" command (without any flags).
11083 But the matching with {pat} is always done like the 'magic'
11084 option is set and 'cpoptions' is empty (to make scripts
11085 portable). 'ignorecase' is still relevant, use |/\c| or |/\C|
11086 if you want to ignore or match case and ignore 'ignorecase'.
11087 'smartcase' is not used. See |string-match| for how {pat} is
11088 used.
11089
11090 A "~" in {sub} is not replaced with the previous {sub}.
11091 Note that some codes in {sub} have a special meaning
11092 |sub-replace-special|. For example, to replace something with
11093 "\n" (two characters), use "\\\\n" or '\\n'.
11094
11095 When {pat} does not match in {string}, {string} is returned
11096 unmodified.
11097
11098 Example: >
11099 :let &path = substitute(&path, ",\\=[^,]*$", "", "")
11100< This removes the last component of the 'path' option. >
11101 :echo substitute("testing", ".*", "\\U\\0", "")
11102< results in "TESTING".
11103
11104 When {sub} starts with "\=", the remainder is interpreted as
11105 an expression. See |sub-replace-expression|. Example: >
11106 :echo substitute(s, '%\(\x\x\)',
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011107 \ '\=nr2char("0x" .. submatch(1))', 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011108
11109< When {sub} is a Funcref that function is called, with one
11110 optional argument. Example: >
11111 :echo substitute(s, '%\(\x\x\)', SubNr, 'g')
11112< The optional argument is a list which contains the whole
11113 matched string and up to nine submatches, like what
11114 |submatch()| returns. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011115 :echo substitute(s, '%\(\x\x\)', {m -> '0x' .. m[1]}, 'g')
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011116
Bram Moolenaard592deb2022-06-17 15:42:40 +010011117< Returns an empty string on error.
11118
11119 Can also be used as a |method|: >
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011120 GetString()->substitute(pat, sub, flags)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011121<
11122 Return type: |String|
11123
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011124
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011125swapfilelist() *swapfilelist()*
11126 Returns a list of swap file names, like what "vim -r" shows.
11127 See the |-r| command argument. The 'directory' option is used
11128 for the directories to inspect. If you only want to get a
11129 list of swap files in the current directory then temporarily
11130 set 'directory' to a dot: >
11131 let save_dir = &directory
11132 let &directory = '.'
11133 let swapfiles = swapfilelist()
11134 let &directory = save_dir
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011135<
11136 Return type: list<string>
11137
Bram Moolenaarc216a7a2022-12-05 13:50:55 +000011138
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011139swapinfo({fname}) *swapinfo()*
11140 The result is a dictionary, which holds information about the
11141 swapfile {fname}. The available fields are:
11142 version Vim version
11143 user user name
11144 host host name
11145 fname original file name
11146 pid PID of the Vim process that created the swap
11147 file
11148 mtime last modification time in seconds
11149 inode Optional: INODE number of the file
11150 dirty 1 if file was modified, 0 if not
11151 Note that "user" and "host" are truncated to at most 39 bytes.
11152 In case of failure an "error" item is added with the reason:
11153 Cannot open file: file not found or in accessible
11154 Cannot read file: cannot read first block
11155 Not a swap file: does not contain correct block ID
11156 Magic number mismatch: Info in first block is invalid
11157
11158 Can also be used as a |method|: >
11159 GetFilename()->swapinfo()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011160<
11161 Return type: dict<any> or dict<string>
11162
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011163
11164swapname({buf}) *swapname()*
11165 The result is the swap file path of the buffer {expr}.
11166 For the use of {buf}, see |bufname()| above.
11167 If buffer {buf} is the current buffer, the result is equal to
11168 |:swapname| (unless there is no swap file).
11169 If buffer {buf} has no swap file, returns an empty string.
11170
11171 Can also be used as a |method|: >
11172 GetBufname()->swapname()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011173<
11174 Return type: |String|
11175
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011176
11177synID({lnum}, {col}, {trans}) *synID()*
11178 The result is a Number, which is the syntax ID at the position
11179 {lnum} and {col} in the current window.
11180 The syntax ID can be used with |synIDattr()| and
11181 |synIDtrans()| to obtain syntax information about text.
11182
11183 {col} is 1 for the leftmost column, {lnum} is 1 for the first
11184 line. 'synmaxcol' applies, in a longer line zero is returned.
11185 Note that when the position is after the last character,
11186 that's where the cursor can be in Insert mode, synID() returns
11187 zero. {lnum} is used like with |getline()|.
11188
11189 When {trans} is |TRUE|, transparent items are reduced to the
11190 item that they reveal. This is useful when wanting to know
11191 the effective color. When {trans} is |FALSE|, the transparent
11192 item is returned. This is useful when wanting to know which
11193 syntax item is effective (e.g. inside parens).
11194 Warning: This function can be very slow. Best speed is
11195 obtained by going through the file in forward direction.
11196
Bram Moolenaard592deb2022-06-17 15:42:40 +010011197 Returns zero on error.
11198
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011199 Example (echoes the name of the syntax item under the cursor): >
11200 :echo synIDattr(synID(line("."), col("."), 1), "name")
11201<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011202 Return type: |Number|
11203
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011204
11205synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
11206 The result is a String, which is the {what} attribute of
11207 syntax ID {synID}. This can be used to obtain information
11208 about a syntax item.
11209 {mode} can be "gui", "cterm" or "term", to get the attributes
11210 for that mode. When {mode} is omitted, or an invalid value is
11211 used, the attributes for the currently active highlighting are
11212 used (GUI, cterm or term).
11213 Use synIDtrans() to follow linked highlight groups.
11214 {what} result
11215 "name" the name of the syntax item
11216 "fg" foreground color (GUI: color name used to set
11217 the color, cterm: color number as a string,
11218 term: empty string)
11219 "bg" background color (as with "fg")
11220 "font" font name (only available in the GUI)
11221 |highlight-font|
11222 "sp" special color for the GUI (as with "fg")
11223 |highlight-guisp|
11224 "ul" underline color for cterm: number as a string
11225 "fg#" like "fg", but for the GUI and the GUI is
11226 running the name in "#RRGGBB" form
11227 "bg#" like "fg#" for "bg"
11228 "sp#" like "fg#" for "sp"
11229 "bold" "1" if bold
11230 "italic" "1" if italic
11231 "reverse" "1" if reverse
11232 "inverse" "1" if inverse (= reverse)
11233 "standout" "1" if standout
11234 "underline" "1" if underlined
11235 "undercurl" "1" if undercurled
11236 "strike" "1" if strikethrough
Bram Moolenaarde786322022-07-30 14:56:17 +010011237 "nocombine" "1" if nocombine
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011238
Bram Moolenaard592deb2022-06-17 15:42:40 +010011239 Returns an empty string on error.
11240
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011241 Example (echoes the color of the syntax item under the
11242 cursor): >
11243 :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
11244<
11245 Can also be used as a |method|: >
11246 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011247<
11248 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011249
11250
11251synIDtrans({synID}) *synIDtrans()*
11252 The result is a Number, which is the translated syntax ID of
11253 {synID}. This is the syntax group ID of what is being used to
11254 highlight the character. Highlight links given with
11255 ":highlight link" are followed.
11256
Bram Moolenaard592deb2022-06-17 15:42:40 +010011257 Returns zero on error.
11258
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011259 Can also be used as a |method|: >
11260 :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011261<
11262 Return type: |Number|
11263
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011264
11265synconcealed({lnum}, {col}) *synconcealed()*
11266 The result is a |List| with currently three items:
11267 1. The first item in the list is 0 if the character at the
11268 position {lnum} and {col} is not part of a concealable
11269 region, 1 if it is. {lnum} is used like with |getline()|.
11270 2. The second item in the list is a string. If the first item
11271 is 1, the second item contains the text which will be
11272 displayed in place of the concealed text, depending on the
11273 current setting of 'conceallevel' and 'listchars'.
11274 3. The third and final item in the list is a number
11275 representing the specific syntax region matched in the
11276 line. When the character is not concealed the value is
11277 zero. This allows detection of the beginning of a new
11278 concealable region if there are two consecutive regions
11279 with the same replacement character. For an example, if
11280 the text is "123456" and both "23" and "45" are concealed
11281 and replaced by the character "X", then:
11282 call returns ~
11283 synconcealed(lnum, 1) [0, '', 0]
11284 synconcealed(lnum, 2) [1, 'X', 1]
11285 synconcealed(lnum, 3) [1, 'X', 1]
11286 synconcealed(lnum, 4) [1, 'X', 2]
11287 synconcealed(lnum, 5) [1, 'X', 2]
11288 synconcealed(lnum, 6) [0, '', 0]
11289
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011290 Note: Doesn't consider |matchadd()| highlighting items,
11291 since syntax and matching highlighting are two different
11292 mechanisms |syntax-vs-match|.
h-east52e7cc22024-07-28 17:03:29 +020011293
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011294 Return type: list<any>
Christian Brabandtfe1e2b52024-04-26 18:42:59 +020011295
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011296
11297synstack({lnum}, {col}) *synstack()*
11298 Return a |List|, which is the stack of syntax items at the
11299 position {lnum} and {col} in the current window. {lnum} is
11300 used like with |getline()|. Each item in the List is an ID
11301 like what |synID()| returns.
11302 The first item in the List is the outer region, following are
11303 items contained in that one. The last one is what |synID()|
11304 returns, unless not the whole item is highlighted or it is a
11305 transparent item.
11306 This function is useful for debugging a syntax file.
11307 Example that shows the syntax stack under the cursor: >
11308 for id in synstack(line("."), col("."))
11309 echo synIDattr(id, "name")
11310 endfor
11311< When the position specified with {lnum} and {col} is invalid
Bram Moolenaard592deb2022-06-17 15:42:40 +010011312 an empty List is returned. The position just after the last
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011313 character in a line and the first column in an empty line are
11314 valid positions.
11315
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011316 Return type: list<number> or list<any>
11317
11318
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011319system({expr} [, {input}]) *system()* *E677*
11320 Get the output of the shell command {expr} as a |String|. See
11321 |systemlist()| to get the output as a |List|.
11322
11323 When {input} is given and is a |String| this string is written
11324 to a file and passed as stdin to the command. The string is
11325 written as-is, you need to take care of using the correct line
11326 separators yourself.
11327 If {input} is given and is a |List| it is written to the file
11328 in a way |writefile()| does with {binary} set to "b" (i.e.
11329 with a newline between each list item with newlines inside
11330 list items converted to NULs).
11331 When {input} is given and is a number that is a valid id for
11332 an existing buffer then the content of the buffer is written
11333 to the file line by line, each line terminated by a NL and
11334 NULs characters where the text has a NL.
11335
11336 Pipes are not used, the 'shelltemp' option is not used.
11337
11338 When prepended by |:silent| the terminal will not be set to
11339 cooked mode. This is meant to be used for commands that do
11340 not need the user to type. It avoids stray characters showing
11341 up on the screen which require |CTRL-L| to remove. >
11342 :silent let f = system('ls *.vim')
11343<
11344 Note: Use |shellescape()| or |::S| with |expand()| or
11345 |fnamemodify()| to escape special characters in a command
11346 argument. Newlines in {expr} may cause the command to fail.
11347 The characters in 'shellquote' and 'shellxquote' may also
11348 cause trouble.
11349 This is not to be used for interactive commands.
11350
11351 The result is a String. Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011352 :let files = system('ls ' .. shellescape(expand('%:h')))
11353 :let files = system('ls ' .. expand('%:h:S'))
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011354
11355< To make the result more system-independent, the shell output
11356 is filtered to replace <CR> with <NL> for Macintosh, and
11357 <CR><NL> with <NL> for DOS-like systems.
11358 To avoid the string being truncated at a NUL, all NUL
11359 characters are replaced with SOH (0x01).
11360
11361 The command executed is constructed using several options:
11362 'shell' 'shellcmdflag' 'shellxquote' {expr} 'shellredir' {tmp} 'shellxquote'
11363 ({tmp} is an automatically generated file name).
11364 For Unix, braces are put around {expr} to allow for
11365 concatenated commands.
11366
11367 The command will be executed in "cooked" mode, so that a
11368 CTRL-C will interrupt the command (on Unix at least).
11369
11370 The resulting error code can be found in |v:shell_error|.
11371 This function will fail in |restricted-mode|.
11372
11373 Note that any wrong value in the options mentioned above may
11374 make the function fail. It has also been reported to fail
11375 when using a security agent application.
11376 Unlike ":!cmd" there is no automatic check for changed files.
11377 Use |:checktime| to force a check.
11378
11379 Can also be used as a |method|: >
11380 :echo GetCmd()->system()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011381<
11382 Return type: |String|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011383
11384
11385systemlist({expr} [, {input}]) *systemlist()*
11386 Same as |system()|, but returns a |List| with lines (parts of
11387 output separated by NL) with NULs transformed into NLs. Output
11388 is the same as |readfile()| will output with {binary} argument
11389 set to "b", except that there is no extra empty item when the
11390 result ends in a NL.
11391 Note that on MS-Windows you may get trailing CR characters.
11392
11393 To see the difference between "echo hello" and "echo -n hello"
11394 use |system()| and |split()|: >
11395 echo system('echo hello')->split('\n', 1)
11396<
11397 Returns an empty string on error.
11398
11399 Can also be used as a |method|: >
11400 :echo GetCmd()->systemlist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011401<
11402 Return type: list<string>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011403
11404
11405tabpagebuflist([{arg}]) *tabpagebuflist()*
11406 The result is a |List|, where each item is the number of the
11407 buffer associated with each window in the current tab page.
11408 {arg} specifies the number of the tab page to be used. When
11409 omitted the current tab page is used.
11410 When {arg} is invalid the number zero is returned.
11411 To get a list of all buffers in all tabs use this: >
11412 let buflist = []
11413 for i in range(tabpagenr('$'))
11414 call extend(buflist, tabpagebuflist(i + 1))
11415 endfor
11416< Note that a buffer may appear in more than one window.
11417
11418 Can also be used as a |method|: >
11419 GetTabpage()->tabpagebuflist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011420<
11421 Return type: list<number>
11422
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011423
11424tabpagenr([{arg}]) *tabpagenr()*
11425 The result is a Number, which is the number of the current
11426 tab page. The first tab page has number 1.
11427
11428 The optional argument {arg} supports the following values:
11429 $ the number of the last tab page (the tab page
11430 count).
11431 # the number of the last accessed tab page
11432 (where |g<Tab>| goes to). if there is no
11433 previous tab page 0 is returned.
11434 The number can be used with the |:tab| command.
11435
Bram Moolenaard592deb2022-06-17 15:42:40 +010011436 Returns zero on error.
11437
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011438 Return type: |Number|
11439
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011440
11441tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()*
11442 Like |winnr()| but for tab page {tabarg}.
11443 {tabarg} specifies the number of tab page to be used.
11444 {arg} is used like with |winnr()|:
11445 - When omitted the current window number is returned. This is
11446 the window which will be used when going to this tab page.
11447 - When "$" the number of windows is returned.
11448 - When "#" the previous window nr is returned.
11449 Useful examples: >
11450 tabpagewinnr(1) " current window of tab page 1
11451 tabpagewinnr(4, '$') " number of windows in tab page 4
11452< When {tabarg} is invalid zero is returned.
11453
11454 Can also be used as a |method|: >
11455 GetTabpage()->tabpagewinnr()
11456<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011457 Return type: |Number|
11458
11459
11460tagfiles() *tagfiles()*
11461 Returns a |List| with the file names used to search for tags
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011462 for the current buffer. This is the 'tags' option expanded.
11463
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011464 Return type: list<string> or list<any>
11465
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011466
11467taglist({expr} [, {filename}]) *taglist()*
11468 Returns a |List| of tags matching the regular expression {expr}.
11469
11470 If {filename} is passed it is used to prioritize the results
11471 in the same way that |:tselect| does. See |tag-priority|.
11472 {filename} should be the full path of the file.
11473
11474 Each list item is a dictionary with at least the following
11475 entries:
11476 name Name of the tag.
11477 filename Name of the file where the tag is
11478 defined. It is either relative to the
11479 current directory or a full path.
11480 cmd Ex command used to locate the tag in
11481 the file.
11482 kind Type of the tag. The value for this
11483 entry depends on the language specific
11484 kind values. Only available when
11485 using a tags file generated by
Bram Moolenaar47c532e2022-03-19 15:18:53 +000011486 Universal/Exuberant ctags or hdrtag.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011487 static A file specific tag. Refer to
11488 |static-tag| for more information.
11489 More entries may be present, depending on the content of the
11490 tags file: access, implementation, inherits and signature.
11491 Refer to the ctags documentation for information about these
11492 fields. For C code the fields "struct", "class" and "enum"
11493 may appear, they give the name of the entity the tag is
11494 contained in.
11495
11496 The ex-command "cmd" can be either an ex search pattern, a
11497 line number or a line number followed by a byte number.
11498
11499 If there are no matching tags, then an empty list is returned.
11500
11501 To get an exact tag match, the anchors '^' and '$' should be
11502 used in {expr}. This also make the function work faster.
11503 Refer to |tag-regexp| for more information about the tag
11504 search regular expression pattern.
11505
11506 Refer to |'tags'| for information about how the tags file is
11507 located by Vim. Refer to |tags-file-format| for the format of
11508 the tags file generated by the different ctags tools.
11509
11510 Can also be used as a |method|: >
11511 GetTagpattern()->taglist()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011512<
11513 Return type: list<dict<any>> or list<any>
11514
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011515
11516tan({expr}) *tan()*
11517 Return the tangent of {expr}, measured in radians, as a |Float|
11518 in the range [-inf, inf].
11519 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011520 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011521 Examples: >
11522 :echo tan(10)
11523< 0.648361 >
11524 :echo tan(-4.01)
11525< -1.181502
11526
11527 Can also be used as a |method|: >
11528 Compute()->tan()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011529<
11530 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011531
11532
11533tanh({expr}) *tanh()*
11534 Return the hyperbolic tangent of {expr} as a |Float| in the
11535 range [-1, 1].
11536 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011537 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011538 Examples: >
11539 :echo tanh(0.5)
11540< 0.462117 >
11541 :echo tanh(-1)
11542< -0.761594
11543
11544 Can also be used as a |method|: >
11545 Compute()->tanh()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011546<
11547 Return type: |Float|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011548
11549
11550tempname() *tempname()* *temp-file-name*
11551 The result is a String, which is the name of a file that
11552 doesn't exist. It can be used for a temporary file. The name
11553 is different for at least 26 consecutive calls. Example: >
11554 :let tmpfile = tempname()
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011555 :exe "redir > " .. tmpfile
Christian Brabandt5cf53012024-05-18 10:13:11 +020011556< For Unix, the file will be in a private directory |tempfile|
11557 that is recursively deleted when Vim exits, on other systems
11558 temporary files are not cleaned up automatically on exit.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011559 For MS-Windows forward slashes are used when the 'shellslash'
11560 option is set, or when 'shellcmdflag' starts with '-' and
11561 'shell' does not contain powershell or pwsh.
11562
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011563 Return type: |String|
11564
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011565
11566term_ functions are documented here: |terminal-function-details|
11567
11568
11569terminalprops() *terminalprops()*
11570 Returns a |Dictionary| with properties of the terminal that Vim
11571 detected from the response to |t_RV| request. See
11572 |v:termresponse| for the response itself. If |v:termresponse|
11573 is empty most values here will be 'u' for unknown.
11574 cursor_style whether sending |t_RS| works **
11575 cursor_blink_mode whether sending |t_RC| works **
11576 underline_rgb whether |t_8u| works **
11577 mouse mouse type supported
Bram Moolenaar4bc85f22022-10-21 14:17:24 +010011578 kitty whether Kitty terminal was detected
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011579
11580 ** value 'u' for unknown, 'y' for yes, 'n' for no
11581
11582 If the |+termresponse| feature is missing then the result is
11583 an empty dictionary.
11584
11585 If "cursor_style" is 'y' then |t_RS| will be sent to request the
11586 current cursor style.
11587 If "cursor_blink_mode" is 'y' then |t_RC| will be sent to
11588 request the cursor blink status.
11589 "cursor_style" and "cursor_blink_mode" are also set if |t_u7|
11590 is not empty, Vim will detect the working of sending |t_RS|
11591 and |t_RC| on startup.
11592
11593 When "underline_rgb" is not 'y', then |t_8u| will be made empty.
11594 This avoids sending it to xterm, which would clear the colors.
11595
11596 For "mouse" the value 'u' is unknown
11597
11598 Also see:
11599 - 'ambiwidth' - detected by using |t_u7|.
11600 - |v:termstyleresp| and |v:termblinkresp| for the response to
11601 |t_RS| and |t_RC|.
11602
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011603 Return type: dict<string>
11604
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011605
11606test_ functions are documented here: |test-functions-details|
11607
11608
11609 *timer_info()*
11610timer_info([{id}])
11611 Return a list with information about timers.
11612 When {id} is given only information about this timer is
11613 returned. When timer {id} does not exist an empty list is
11614 returned.
11615 When {id} is omitted information about all timers is returned.
11616
11617 For each timer the information is stored in a |Dictionary| with
11618 these items:
11619 "id" the timer ID
11620 "time" time the timer was started with
11621 "remaining" time until the timer fires
11622 "repeat" number of times the timer will still fire;
11623 -1 means forever
11624 "callback" the callback
11625 "paused" 1 if the timer is paused, 0 otherwise
11626
11627 Can also be used as a |method|: >
11628 GetTimer()->timer_info()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011629<
11630 Return type: list<dict<any>> or list<any>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011631
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011632 {only available when compiled with the |+timers| feature}
11633
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011634
11635timer_pause({timer}, {paused}) *timer_pause()*
11636 Pause or unpause a timer. A paused timer does not invoke its
11637 callback when its time expires. Unpausing a timer may cause
11638 the callback to be invoked almost immediately if enough time
11639 has passed.
11640
11641 Pausing a timer is useful to avoid the callback to be called
11642 for a short time.
11643
11644 If {paused} evaluates to a non-zero Number or a non-empty
11645 String, then the timer is paused, otherwise it is unpaused.
11646 See |non-zero-arg|.
11647
11648 Can also be used as a |method|: >
11649 GetTimer()->timer_pause(1)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011650<
11651 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011652
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011653 {only available when compiled with the |+timers| feature}
11654
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011655
11656 *timer_start()* *timer* *timers*
11657timer_start({time}, {callback} [, {options}])
11658 Create a timer and return the timer ID.
11659
11660 {time} is the waiting time in milliseconds. This is the
11661 minimum time before invoking the callback. When the system is
11662 busy or Vim is not waiting for input the time will be longer.
Bram Moolenaardd60c362023-02-27 15:49:53 +000011663 Zero can be used to execute the callback when Vim is back in
11664 the main loop.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011665
11666 {callback} is the function to call. It can be the name of a
11667 function or a |Funcref|. It is called with one argument, which
11668 is the timer ID. The callback is only invoked when Vim is
11669 waiting for input.
11670 If you want to show a message look at |popup_notification()|
11671 to avoid interfering with what the user is doing.
11672
11673 {options} is a dictionary. Supported entries:
11674 "repeat" Number of times to repeat calling the
11675 callback. -1 means forever. When not present
11676 the callback will be called once.
11677 If the timer causes an error three times in a
11678 row the repeat is cancelled. This avoids that
11679 Vim becomes unusable because of all the error
11680 messages.
11681
Bram Moolenaard592deb2022-06-17 15:42:40 +010011682 Returns -1 on error.
11683
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011684 Example: >
11685 func MyHandler(timer)
11686 echo 'Handler called'
11687 endfunc
11688 let timer = timer_start(500, 'MyHandler',
11689 \ {'repeat': 3})
11690< This will invoke MyHandler() three times at 500 msec
11691 intervals.
11692
11693 Can also be used as a |method|: >
11694 GetMsec()->timer_start(callback)
11695
11696< Not available in the |sandbox|.
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011697
11698 Return type: |Number|
11699
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011700 {only available when compiled with the |+timers| feature}
11701
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011702
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011703timer_stop({timer}) *timer_stop()*
11704 Stop a timer. The timer callback will no longer be invoked.
11705 {timer} is an ID returned by timer_start(), thus it must be a
11706 Number. If {timer} does not exist there is no error.
11707
11708 Can also be used as a |method|: >
11709 GetTimer()->timer_stop()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011710<
11711 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011712
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011713 {only available when compiled with the |+timers| feature}
11714
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011715
11716timer_stopall() *timer_stopall()*
11717 Stop all timers. The timer callbacks will no longer be
11718 invoked. Useful if a timer is misbehaving. If there are no
11719 timers there is no error.
11720
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011721 Return type: |Number|
11722
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011723 {only available when compiled with the |+timers| feature}
11724
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011725
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011726tolower({expr}) *tolower()*
11727 The result is a copy of the String given, with all uppercase
11728 characters turned into lowercase (just like applying |gu| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011729 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011730
11731 Can also be used as a |method|: >
11732 GetText()->tolower()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011733<
11734 Return type: |String|
11735
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011736
11737toupper({expr}) *toupper()*
11738 The result is a copy of the String given, with all lowercase
11739 characters turned into uppercase (just like applying |gU| to
Bram Moolenaard592deb2022-06-17 15:42:40 +010011740 the string). Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011741
11742 Can also be used as a |method|: >
11743 GetText()->toupper()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011744<
11745 Return type: |String|
11746
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011747
11748tr({src}, {fromstr}, {tostr}) *tr()*
11749 The result is a copy of the {src} string with all characters
11750 which appear in {fromstr} replaced by the character in that
11751 position in the {tostr} string. Thus the first character in
11752 {fromstr} is translated into the first character in {tostr}
11753 and so on. Exactly like the unix "tr" command.
11754 This code also deals with multibyte characters properly.
11755
Bram Moolenaard592deb2022-06-17 15:42:40 +010011756 Returns an empty string on error.
11757
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011758 Examples: >
11759 echo tr("hello there", "ht", "HT")
11760< returns "Hello THere" >
11761 echo tr("<blob>", "<>", "{}")
11762< returns "{blob}"
11763
11764 Can also be used as a |method|: >
11765 GetText()->tr(from, to)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011766<
11767 Return type: |String|
11768
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011769
11770trim({text} [, {mask} [, {dir}]]) *trim()*
11771 Return {text} as a String where any character in {mask} is
11772 removed from the beginning and/or end of {text}.
11773
Illia Bobyr80799172023-10-17 18:00:50 +020011774 If {mask} is not given, or is an empty string, {mask} is all
11775 characters up to 0x20, which includes Tab, space, NL and CR,
11776 plus the non-breaking space character 0xa0.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011777
11778 The optional {dir} argument specifies where to remove the
11779 characters:
11780 0 remove from the beginning and end of {text}
11781 1 remove only at the beginning of {text}
11782 2 remove only at the end of {text}
11783 When omitted both ends are trimmed.
11784
11785 This function deals with multibyte characters properly.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011786 Returns an empty string on error.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011787
11788 Examples: >
11789 echo trim(" some text ")
11790< returns "some text" >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000011791 echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") .. "_TAIL"
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011792< returns "RESERVE_TAIL" >
11793 echo trim("rm<Xrm<>X>rrm", "rm<>")
11794< returns "Xrm<>X" (characters in the middle are not removed) >
11795 echo trim(" vim ", " ", 2)
11796< returns " vim"
11797
11798 Can also be used as a |method|: >
11799 GetText()->trim()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011800<
11801 Return type: |String|
11802
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011803
11804trunc({expr}) *trunc()*
11805 Return the largest integral value with magnitude less than or
11806 equal to {expr} as a |Float| (truncate towards zero).
11807 {expr} must evaluate to a |Float| or a |Number|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011808 Returns 0.0 if {expr} is not a |Float| or a |Number|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011809 Examples: >
11810 echo trunc(1.456)
11811< 1.0 >
11812 echo trunc(-5.456)
11813< -5.0 >
11814 echo trunc(4.0)
11815< 4.0
11816
11817 Can also be used as a |method|: >
11818 Compute()->trunc()
11819<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011820 Return type: |Float|
11821
11822
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011823 *type()*
11824type({expr}) The result is a Number representing the type of {expr}.
11825 Instead of using the number directly, it is better to use the
11826 v:t_ variable that has the value:
11827 Number: 0 |v:t_number|
11828 String: 1 |v:t_string|
11829 Funcref: 2 |v:t_func|
11830 List: 3 |v:t_list|
11831 Dictionary: 4 |v:t_dict|
11832 Float: 5 |v:t_float|
11833 Boolean: 6 |v:t_bool| (v:false and v:true)
11834 None: 7 |v:t_none| (v:null and v:none)
11835 Job: 8 |v:t_job|
11836 Channel: 9 |v:t_channel|
11837 Blob: 10 |v:t_blob|
h_east596a9f22023-11-21 21:24:23 +090011838 Class: 12 |v:t_class|
11839 Object: 13 |v:t_object|
Yegappan Lakshmanan2a71b542023-12-14 20:03:03 +010011840 Typealias: 14 |v:t_typealias|
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +010011841 Enum: 15 |v:t_enum|
11842 EnumValue: 16 |v:t_enumvalue|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011843 For backward compatibility, this method can be used: >
11844 :if type(myvar) == type(0)
11845 :if type(myvar) == type("")
11846 :if type(myvar) == type(function("tr"))
11847 :if type(myvar) == type([])
11848 :if type(myvar) == type({})
11849 :if type(myvar) == type(0.0)
11850 :if type(myvar) == type(v:false)
11851 :if type(myvar) == type(v:none)
11852< To check if the v:t_ variables exist use this: >
11853 :if exists('v:t_number')
11854
11855< Can also be used as a |method|: >
11856 mylist->type()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011857<
11858 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011859
11860
11861typename({expr}) *typename()*
11862 Return a string representation of the type of {expr}.
11863 Example: >
11864 echo typename([1, 2, 3])
Kota Kato66bb9ae2023-01-17 18:31:56 +000011865< list<number> ~
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011866
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011867 Return type: |String|
11868
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011869
11870undofile({name}) *undofile()*
11871 Return the name of the undo file that would be used for a file
11872 with name {name} when writing. This uses the 'undodir'
11873 option, finding directories that exist. It does not check if
11874 the undo file exists.
11875 {name} is always expanded to the full path, since that is what
11876 is used internally.
11877 If {name} is empty undofile() returns an empty string, since a
11878 buffer without a file name will not write an undo file.
11879 Useful in combination with |:wundo| and |:rundo|.
11880 When compiled without the |+persistent_undo| option this always
11881 returns an empty string.
11882
11883 Can also be used as a |method|: >
11884 GetFilename()->undofile()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011885<
11886 Return type: |String|
11887
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011888
Devin J. Pohly5fee1112023-04-23 20:26:59 -050011889undotree([{buf}]) *undotree()*
11890 Return the current state of the undo tree for the current
11891 buffer, or for a specific buffer if {buf} is given. The
11892 result is a dictionary with the following items:
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011893 "seq_last" The highest undo sequence number used.
11894 "seq_cur" The sequence number of the current position in
11895 the undo tree. This differs from "seq_last"
11896 when some changes were undone.
11897 "time_cur" Time last used for |:earlier| and related
11898 commands. Use |strftime()| to convert to
11899 something readable.
11900 "save_last" Number of the last file write. Zero when no
11901 write yet.
11902 "save_cur" Number of the current position in the undo
11903 tree.
11904 "synced" Non-zero when the last undo block was synced.
11905 This happens when waiting from input from the
11906 user. See |undo-blocks|.
11907 "entries" A list of dictionaries with information about
11908 undo blocks.
11909
11910 The first item in the "entries" list is the oldest undo item.
11911 Each List item is a |Dictionary| with these items:
11912 "seq" Undo sequence number. Same as what appears in
11913 |:undolist|.
11914 "time" Timestamp when the change happened. Use
11915 |strftime()| to convert to something readable.
11916 "newhead" Only appears in the item that is the last one
11917 that was added. This marks the last change
11918 and where further changes will be added.
11919 "curhead" Only appears in the item that is the last one
11920 that was undone. This marks the current
11921 position in the undo tree, the block that will
11922 be used by a redo command. When nothing was
11923 undone after the last change this item will
11924 not appear anywhere.
11925 "save" Only appears on the last block before a file
11926 write. The number is the write count. The
11927 first write has number 1, the last one the
11928 "save_last" mentioned above.
11929 "alt" Alternate entry. This is again a List of undo
11930 blocks. Each item may again have an "alt"
11931 item.
11932
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011933 Return type: dict<any>
11934
11935
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011936uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
11937 Remove second and succeeding copies of repeated adjacent
11938 {list} items in-place. Returns {list}. If you want a list
11939 to remain unmodified make a copy first: >
11940 :let newlist = uniq(copy(mylist))
11941< The default compare function uses the string representation of
11942 each item. For the use of {func} and {dict} see |sort()|.
11943
Bram Moolenaard592deb2022-06-17 15:42:40 +010011944 Returns zero if {list} is not a |List|.
11945
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011946 Can also be used as a |method|: >
11947 mylist->uniq()
Christian Brabandt67672ef2023-04-24 21:09:54 +010011948<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011949 Return type: list<{type}>
11950
11951
Christian Brabandt67672ef2023-04-24 21:09:54 +010011952 *utf16idx()*
11953utf16idx({string}, {idx} [, {countcc} [, {charidx}]])
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011954 Same as |charidx()| but returns the UTF-16 code unit index of
11955 the byte at {idx} in {string} (after converting it to UTF-16).
Christian Brabandt67672ef2023-04-24 21:09:54 +010011956
11957 When {charidx} is present and TRUE, {idx} is used as the
11958 character index in the String {string} instead of as the byte
11959 index.
Yegappan Lakshmanan95707032023-06-14 13:10:15 +010011960 An {idx} in the middle of a UTF-8 sequence is rounded
11961 downwards to the beginning of that sequence.
Christian Brabandt67672ef2023-04-24 21:09:54 +010011962
Yegappan Lakshmanan577922b2023-06-08 17:09:45 +010011963 Returns -1 if the arguments are invalid or if there are less
11964 than {idx} bytes in {string}. If there are exactly {idx} bytes
11965 the length of the string in UTF-16 code units is returned.
11966
Christian Brabandt67672ef2023-04-24 21:09:54 +010011967 See |byteidx()| and |byteidxcomp()| for getting the byte index
11968 from the UTF-16 index and |charidx()| for getting the
11969 character index from the UTF-16 index.
11970 Refer to |string-offset-encoding| for more information.
11971 Examples: >
11972 echo utf16idx('a😊😊', 3) returns 2
11973 echo utf16idx('a😊😊', 7) returns 4
11974 echo utf16idx('a😊😊', 1, 0, 1) returns 2
11975 echo utf16idx('a😊😊', 2, 0, 1) returns 4
11976 echo utf16idx('aą́c', 6) returns 2
11977 echo utf16idx('aą́c', 6, 1) returns 4
11978 echo utf16idx('a😊😊', 9) returns -1
11979<
11980 Can also be used as a |method|: >
11981 GetName()->utf16idx(idx)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011982<
11983 Return type: |Number|
Christian Brabandt67672ef2023-04-24 21:09:54 +010011984
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011985
11986values({dict}) *values()*
11987 Return a |List| with all the values of {dict}. The |List| is
11988 in arbitrary order. Also see |items()| and |keys()|.
Bram Moolenaard592deb2022-06-17 15:42:40 +010011989 Returns zero if {dict} is not a |Dict|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011990
11991 Can also be used as a |method|: >
11992 mydict->values()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020011993<
11994 Return type: list<any>
11995
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011996
zeertzjq825cf812023-08-17 22:55:25 +020011997virtcol({expr} [, {list} [, {winid}]]) *virtcol()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000011998 The result is a Number, which is the screen column of the file
11999 position given with {expr}. That is, the last screen position
12000 occupied by the character at that position, when the screen
12001 would be of unlimited width. When there is a <Tab> at the
12002 position, the returned Number will be the column at the end of
12003 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
12004 set to 8, it returns 8. |conceal| is ignored.
12005 For the byte position use |col()|.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012006
zeertzjq02f3eba2024-06-12 20:45:24 +020012007 For the use of {expr} see |getpos()| and |col()|.
zeertzjqd353d272024-06-13 23:00:25 +080012008 When {expr} is "$", it means the end of the cursor line, so
12009 the result is the number of cells in the cursor line plus one.
LemonBoy0f7a3e12022-05-26 12:10:37 +010012010
12011 When 'virtualedit' is used {expr} can be [lnum, col, off],
12012 where "off" is the offset in screen columns from the start of
12013 the character. E.g., a position within a <Tab> or after the
12014 last character. When "off" is omitted zero is used. When
12015 Virtual editing is active in the current mode, a position
12016 beyond the end of the line can be returned. Also see
12017 |'virtualedit'|
12018
zeertzjq825cf812023-08-17 22:55:25 +020012019 If {list} is present and non-zero then virtcol() returns a
12020 List with the first and last screen position occupied by the
LemonBoy0f7a3e12022-05-26 12:10:37 +010012021 character.
12022
zeertzjq825cf812023-08-17 22:55:25 +020012023 With the optional {winid} argument the values are obtained for
12024 that window instead of the current window.
12025
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012026 Note that only marks in the current file can be used.
zeertzjq02f3eba2024-06-12 20:45:24 +020012027
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012028 Examples: >
LemonBoy0f7a3e12022-05-26 12:10:37 +010012029 " With text "foo^Lbar" and cursor on the "^L":
12030
12031 virtcol(".") " returns 5
12032 virtcol(".", 1) " returns [4, 5]
12033 virtcol("$") " returns 9
12034
12035 " With text " there", with 't at 'h':
12036
12037 virtcol("'t") " returns 6
zeertzjq02f3eba2024-06-12 20:45:24 +020012038<
12039 The first column is 1. 0 or [0, 0] is returned for an error.
12040
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012041 A more advanced example that echoes the maximum length of
12042 all lines: >
12043 echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
12044
12045< Can also be used as a |method|: >
12046 GetPos()->virtcol()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012047<
12048 Return type: |Number|
12049
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012050
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012051virtcol2col({winid}, {lnum}, {col}) *virtcol2col()*
12052 The result is a Number, which is the byte index of the
12053 character in window {winid} at buffer line {lnum} and virtual
12054 column {col}.
12055
zeertzjqb583eda2023-10-14 11:32:28 +020012056 If buffer line {lnum} is an empty line, 0 is returned.
12057
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012058 If {col} is greater than the last virtual column in line
12059 {lnum}, then the byte index of the character at the last
12060 virtual column is returned.
12061
Yegappan Lakshmananb209b862023-08-15 23:01:44 +020012062 For a multi-byte character, the column number of the first
12063 byte in the character is returned.
12064
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012065 The {winid} argument can be the window number or the
12066 |window-ID|. If this is zero, then the current window is used.
12067
12068 Returns -1 if the window {winid} doesn't exist or the buffer
12069 line {lnum} or virtual column {col} is invalid.
12070
12071 See also |screenpos()|, |virtcol()| and |col()|.
12072
12073 Can also be used as a |method|: >
12074 GetWinid()->virtcol2col(lnum, col)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012075<
12076 Return type: |Number|
12077
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012078
12079visualmode([{expr}]) *visualmode()*
12080 The result is a String, which describes the last Visual mode
12081 used in the current buffer. Initially it returns an empty
12082 string, but once Visual mode has been used, it returns "v",
12083 "V", or "<CTRL-V>" (a single CTRL-V character) for
12084 character-wise, line-wise, or block-wise Visual mode
12085 respectively.
12086 Example: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012087 :exe "normal " .. visualmode()
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012088< This enters the same Visual mode as before. It is also useful
12089 in scripts if you wish to act differently depending on the
12090 Visual mode that was used.
12091 If Visual mode is active, use |mode()| to get the Visual mode
12092 (e.g., in a |:vmap|).
12093 If {expr} is supplied and it evaluates to a non-zero Number or
12094 a non-empty String, then the Visual mode will be cleared and
12095 the old value is returned. See |non-zero-arg|.
12096
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012097 Return type: |String|
12098
12099
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012100wildmenumode() *wildmenumode()*
12101 Returns |TRUE| when the wildmenu is active and |FALSE|
12102 otherwise. See 'wildmenu' and 'wildmode'.
12103 This can be used in mappings to handle the 'wildcharm' option
12104 gracefully. (Makes only sense with |mapmode-c| mappings).
12105
12106 For example to make <c-j> work like <down> in wildmode, use: >
12107 :cnoremap <expr> <C-j> wildmenumode() ? "\<Down>\<Tab>" : "\<c-j>"
12108<
Milly6c2fc372024-10-16 22:11:17 +020012109 (Note: this needs the 'wildcharm' option set appropriately).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012110
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012111 Return type: |Number|
12112
12113
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012114win_execute({id}, {command} [, {silent}]) *win_execute()*
12115 Like `execute()` but in the context of window {id}.
12116 The window will temporarily be made the current window,
12117 without triggering autocommands or changing directory. When
12118 executing {command} autocommands will be triggered, this may
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010012119 have unexpected side effects. Use `:noautocmd` if needed.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012120 Example: >
12121 call win_execute(winid, 'set syntax=python')
12122< Doing the same with `setwinvar()` would not trigger
12123 autocommands and not actually show syntax highlighting.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012124 *E994*
12125 Not all commands are allowed in popup windows.
12126 When window {id} does not exist then no error is given and
12127 an empty string is returned.
12128
12129 Can also be used as a |method|, the base is passed as the
12130 second argument: >
12131 GetCommand()->win_execute(winid)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012132<
12133 Return type: |String|
12134
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012135
12136win_findbuf({bufnr}) *win_findbuf()*
12137 Returns a |List| with |window-ID|s for windows that contain
12138 buffer {bufnr}. When there is none the list is empty.
12139
12140 Can also be used as a |method|: >
12141 GetBufnr()->win_findbuf()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012142<
12143 Return type: list<number> or list<any>
12144
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012145
12146win_getid([{win} [, {tab}]]) *win_getid()*
12147 Get the |window-ID| for the specified window.
12148 When {win} is missing use the current window.
12149 With {win} this is the window number. The top window has
12150 number 1.
12151 Without {tab} use the current tab, otherwise the tab with
12152 number {tab}. The first tab has number one.
12153 Return zero if the window cannot be found.
12154
12155 Can also be used as a |method|: >
12156 GetWinnr()->win_getid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012157<
12158 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012159
12160
12161win_gettype([{nr}]) *win_gettype()*
12162 Return the type of the window:
12163 "autocmd" autocommand window. Temporary window
12164 used to execute autocommands.
12165 "command" command-line window |cmdwin|
12166 (empty) normal window
12167 "loclist" |location-list-window|
12168 "popup" popup window |popup|
12169 "preview" preview window |preview-window|
12170 "quickfix" |quickfix-window|
12171 "unknown" window {nr} not found
12172
12173 When {nr} is omitted return the type of the current window.
12174 When {nr} is given return the type of this window by number or
12175 |window-ID|.
12176
12177 Also see the 'buftype' option. When running a terminal in a
12178 popup window then 'buftype' is "terminal" and win_gettype()
12179 returns "popup".
12180
12181 Can also be used as a |method|: >
12182 GetWinid()->win_gettype()
12183<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012184 Return type: |String|
12185
12186
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012187win_gotoid({expr}) *win_gotoid()*
12188 Go to window with ID {expr}. This may also change the current
12189 tabpage.
12190 Return TRUE if successful, FALSE if the window cannot be found.
12191
12192 Can also be used as a |method|: >
12193 GetWinid()->win_gotoid()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012194<
12195 Return type: |Number|
12196
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012197
12198win_id2tabwin({expr}) *win_id2tabwin()*
12199 Return a list with the tab number and window number of window
12200 with ID {expr}: [tabnr, winnr].
12201 Return [0, 0] if the window cannot be found.
12202
12203 Can also be used as a |method|: >
12204 GetWinid()->win_id2tabwin()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012205<
12206 Return type: list<number>
12207
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012208
12209win_id2win({expr}) *win_id2win()*
12210 Return the window number of window with ID {expr}.
12211 Return 0 if the window cannot be found in the current tabpage.
12212
12213 Can also be used as a |method|: >
12214 GetWinid()->win_id2win()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012215<
12216 Return type: |Number|
12217
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012218
Daniel Steinbergee630312022-01-10 13:36:34 +000012219win_move_separator({nr}, {offset}) *win_move_separator()*
12220 Move window {nr}'s vertical separator (i.e., the right border)
12221 by {offset} columns, as if being dragged by the mouse. {nr}
12222 can be a window number or |window-ID|. A positive {offset}
12223 moves right and a negative {offset} moves left. Moving a
12224 window's vertical separator will change the width of the
12225 window and the width of other windows adjacent to the vertical
12226 separator. The magnitude of movement may be smaller than
12227 specified (e.g., as a consequence of maintaining
12228 'winminwidth'). Returns TRUE if the window can be found and
12229 FALSE otherwise.
Bram Moolenaard592deb2022-06-17 15:42:40 +010012230 This will fail for the rightmost window and a full-width
12231 window, since it has no separator on the right.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012232 Only works for the current tab page. *E1308*
Daniel Steinbergee630312022-01-10 13:36:34 +000012233
12234 Can also be used as a |method|: >
12235 GetWinnr()->win_move_separator(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012236<
12237 Return type: |Number|
12238
Daniel Steinbergee630312022-01-10 13:36:34 +000012239
12240win_move_statusline({nr}, {offset}) *win_move_statusline()*
12241 Move window {nr}'s status line (i.e., the bottom border) by
12242 {offset} rows, as if being dragged by the mouse. {nr} can be a
12243 window number or |window-ID|. A positive {offset} moves down
12244 and a negative {offset} moves up. Moving a window's status
12245 line will change the height of the window and the height of
12246 other windows adjacent to the status line. The magnitude of
12247 movement may be smaller than specified (e.g., as a consequence
12248 of maintaining 'winminheight'). Returns TRUE if the window can
12249 be found and FALSE otherwise.
Bram Moolenaar76db9e02022-11-09 21:21:04 +000012250 Only works for the current tab page.
Daniel Steinbergee630312022-01-10 13:36:34 +000012251
12252 Can also be used as a |method|: >
12253 GetWinnr()->win_move_statusline(offset)
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012254<
12255 Return type: |Number|
12256
Daniel Steinbergee630312022-01-10 13:36:34 +000012257
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012258win_screenpos({nr}) *win_screenpos()*
12259 Return the screen position of window {nr} as a list with two
12260 numbers: [row, col]. The first window always has position
12261 [1, 1], unless there is a tabline, then it is [2, 1].
12262 {nr} can be the window number or the |window-ID|. Use zero
12263 for the current window.
Sean Dewar5866bc32024-03-13 20:17:24 +010012264 Returns [0, 0] if the window cannot be found.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012265
12266 Can also be used as a |method|: >
12267 GetWinid()->win_screenpos()
12268<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012269 Return type: list<number>
12270
12271
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012272win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
Sean Dewar96cc4ae2024-02-20 21:52:31 +010012273 Temporarily switch to window {target}, then move window {nr}
12274 to a new split adjacent to {target}.
12275 Unlike commands such as |:split|, no new windows are created
12276 (the |window-ID| of window {nr} is unchanged after the move).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012277
12278 Both {nr} and {target} can be window numbers or |window-ID|s.
12279 Both must be in the current tab page.
12280
12281 Returns zero for success, non-zero for failure.
12282
12283 {options} is a |Dictionary| with the following optional entries:
12284 "vertical" When TRUE, the split is created vertically,
12285 like with |:vsplit|.
12286 "rightbelow" When TRUE, the split is made below or to the
12287 right (if vertical). When FALSE, it is done
12288 above or to the left (if vertical). When not
12289 present, the values of 'splitbelow' and
12290 'splitright' are used.
12291
12292 Can also be used as a |method|: >
12293 GetWinid()->win_splitmove(target)
12294<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012295 Return type: |Number|
12296
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012297
12298 *winbufnr()*
12299winbufnr({nr}) The result is a Number, which is the number of the buffer
12300 associated with window {nr}. {nr} can be the window number or
12301 the |window-ID|.
12302 When {nr} is zero, the number of the buffer in the current
12303 window is returned.
12304 When window {nr} doesn't exist, -1 is returned.
12305 Example: >
12306 :echo "The file in the current window is " . bufname(winbufnr(0))
12307<
12308 Can also be used as a |method|: >
12309 FindWindow()->winbufnr()->bufname()
12310<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012311 Return type: |Number|
12312
12313
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012314 *wincol()*
12315wincol() The result is a Number, which is the virtual column of the
12316 cursor in the window. This is counting screen cells from the
12317 left side of the window. The leftmost column is one.
12318
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012319 Return type: |Number|
12320
12321
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012322 *windowsversion()*
12323windowsversion()
12324 The result is a String. For MS-Windows it indicates the OS
12325 version. E.g, Windows 10 is "10.0", Windows 8 is "6.2",
12326 Windows XP is "5.1". For non-MS-Windows systems the result is
12327 an empty string.
12328
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012329 Return type: |String|
12330
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012331winheight({nr}) *winheight()*
12332 The result is a Number, which is the height of window {nr}.
12333 {nr} can be the window number or the |window-ID|.
12334 When {nr} is zero, the height of the current window is
12335 returned. When window {nr} doesn't exist, -1 is returned.
12336 An existing window always has a height of zero or more.
12337 This excludes any window toolbar line.
12338 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012339 :echo "The current window has " .. winheight(0) .. " lines."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012340
12341< Can also be used as a |method|: >
12342 GetWinid()->winheight()
12343<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012344 Return type: |Number|
12345
12346
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012347winlayout([{tabnr}]) *winlayout()*
12348 The result is a nested List containing the layout of windows
12349 in a tabpage.
12350
12351 Without {tabnr} use the current tabpage, otherwise the tabpage
12352 with number {tabnr}. If the tabpage {tabnr} is not found,
12353 returns an empty list.
12354
12355 For a leaf window, it returns:
12356 ['leaf', {winid}]
12357 For horizontally split windows, which form a column, it
12358 returns:
12359 ['col', [{nested list of windows}]]
12360 For vertically split windows, which form a row, it returns:
12361 ['row', [{nested list of windows}]]
12362
12363 Example: >
12364 " Only one window in the tab page
12365 :echo winlayout()
12366 ['leaf', 1000]
12367 " Two horizontally split windows
12368 :echo winlayout()
12369 ['col', [['leaf', 1000], ['leaf', 1001]]]
12370 " The second tab page, with three horizontally split
12371 " windows, with two vertically split windows in the
12372 " middle window
12373 :echo winlayout(2)
12374 ['col', [['leaf', 1002], ['row', [['leaf', 1003],
12375 ['leaf', 1001]]], ['leaf', 1000]]]
12376<
12377 Can also be used as a |method|: >
12378 GetTabnr()->winlayout()
12379<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012380 Return type: list<any>
12381
12382
12383winline() *winline()*
12384 The result is a Number, which is the screen line of the cursor
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012385 in the window. This is counting screen lines from the top of
12386 the window. The first line is one.
12387 If the cursor was moved the view on the file will be updated
12388 first, this may cause a scroll.
12389
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012390 Return type: |Number|
12391
12392
12393winnr([{arg}]) *winnr()*
12394 The result is a Number, which is the number of the current
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012395 window. The top window has number 1.
12396 Returns zero for a popup window.
12397
12398 The optional argument {arg} supports the following values:
12399 $ the number of the last window (the window
12400 count).
12401 # the number of the last accessed window (where
12402 |CTRL-W_p| goes to). If there is no previous
12403 window or it is in another tab page 0 is
Sean Deward64801e2024-03-12 20:46:12 +010012404 returned. May refer to the current window in
12405 some cases (e.g. when evaluating 'statusline'
12406 expressions).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012407 {N}j the number of the Nth window below the
12408 current window (where |CTRL-W_j| goes to).
12409 {N}k the number of the Nth window above the current
12410 window (where |CTRL-W_k| goes to).
12411 {N}h the number of the Nth window left of the
12412 current window (where |CTRL-W_h| goes to).
12413 {N}l the number of the Nth window right of the
12414 current window (where |CTRL-W_l| goes to).
12415 The number can be used with |CTRL-W_w| and ":wincmd w"
12416 |:wincmd|.
Bram Moolenaar016188f2022-06-06 20:52:59 +010012417 When {arg} is invalid an error is given and zero is returned.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012418 Also see |tabpagewinnr()| and |win_getid()|.
12419 Examples: >
12420 let window_count = winnr('$')
12421 let prev_window = winnr('#')
12422 let wnum = winnr('3k')
12423
12424< Can also be used as a |method|: >
12425 GetWinval()->winnr()
12426<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012427 Return type: |Number|
12428
12429
12430winrestcmd() *winrestcmd()*
12431 Returns a sequence of |:resize| commands that should restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012432 the current window sizes. Only works properly when no windows
12433 are opened or closed and the current window and tab page is
12434 unchanged.
12435 Example: >
12436 :let cmd = winrestcmd()
12437 :call MessWithWindowSizes()
12438 :exe cmd
12439<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012440 Return type: |String|
12441
12442
12443winrestview({dict}) *winrestview()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012444 Uses the |Dictionary| returned by |winsaveview()| to restore
12445 the view of the current window.
12446 Note: The {dict} does not have to contain all values, that are
12447 returned by |winsaveview()|. If values are missing, those
12448 settings won't be restored. So you can use: >
12449 :call winrestview({'curswant': 4})
12450<
12451 This will only set the curswant value (the column the cursor
12452 wants to move on vertical movements) of the cursor to column 5
12453 (yes, that is 5), while all other settings will remain the
12454 same. This is useful, if you set the cursor position manually.
12455
12456 If you have changed the values the result is unpredictable.
12457 If the window size changed the result won't be the same.
12458
12459 Can also be used as a |method|: >
12460 GetView()->winrestview()
12461<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012462 Return type: |Number|
12463
12464
12465winsaveview() *winsaveview()*
12466 Returns a |Dictionary| that contains information to restore
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012467 the view of the current window. Use |winrestview()| to
12468 restore the view.
12469 This is useful if you have a mapping that jumps around in the
12470 buffer and you want to go back to the original view.
12471 This does not save fold information. Use the 'foldenable'
12472 option to temporarily switch off folding, so that folds are
12473 not opened when moving around. This may have side effects.
12474 The return value includes:
12475 lnum cursor line number
12476 col cursor column (Note: the first column
naohiro ono56200ee2022-01-01 14:59:44 +000012477 zero, as opposed to what |getcurpos()|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012478 returns)
12479 coladd cursor column offset for 'virtualedit'
naohiro ono56200ee2022-01-01 14:59:44 +000012480 curswant column for vertical movement (Note:
12481 the first column is zero, as opposed
12482 to what |getcurpos()| returns). After
12483 |$| command it will be a very large
12484 number equal to |v:maxcol|.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012485 topline first line in the window
12486 topfill filler lines, only in diff mode
12487 leftcol first column displayed; only used when
12488 'wrap' is off
12489 skipcol columns skipped
12490 Note that no option values are saved.
12491
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012492 Return type: dict<number>
12493
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012494
12495winwidth({nr}) *winwidth()*
12496 The result is a Number, which is the width of window {nr}.
12497 {nr} can be the window number or the |window-ID|.
12498 When {nr} is zero, the width of the current window is
12499 returned. When window {nr} doesn't exist, -1 is returned.
12500 An existing window always has a width of zero or more.
12501 Examples: >
Bram Moolenaarc51cf032022-02-26 12:25:45 +000012502 :echo "The current window has " .. winwidth(0) .. " columns."
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012503 :if winwidth(0) <= 50
12504 : 50 wincmd |
12505 :endif
12506< For getting the terminal or screen size, see the 'columns'
12507 option.
12508
12509 Can also be used as a |method|: >
12510 GetWinid()->winwidth()
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012511<
12512 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012513
12514
12515wordcount() *wordcount()*
12516 The result is a dictionary of byte/chars/word statistics for
12517 the current buffer. This is the same info as provided by
12518 |g_CTRL-G|
12519 The return value includes:
12520 bytes Number of bytes in the buffer
12521 chars Number of chars in the buffer
12522 words Number of words in the buffer
12523 cursor_bytes Number of bytes before cursor position
12524 (not in Visual mode)
12525 cursor_chars Number of chars before cursor position
12526 (not in Visual mode)
12527 cursor_words Number of words before cursor position
12528 (not in Visual mode)
12529 visual_bytes Number of bytes visually selected
12530 (only in Visual mode)
12531 visual_chars Number of chars visually selected
12532 (only in Visual mode)
12533 visual_words Number of words visually selected
12534 (only in Visual mode)
12535
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012536 Return type: dict<number>
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012537
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012538
12539writefile({object}, {fname} [, {flags}]) *writefile()*
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012540 When {object} is a |List| write it to file {fname}. Each list
12541 item is separated with a NL. Each list item must be a String
12542 or Number.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012543 All NL characters are replaced with a NUL character.
12544 Inserting CR characters needs to be done before passing {list}
12545 to writefile().
Bram Moolenaar806a2732022-09-04 15:40:36 +010012546
12547 When {object} is a |Blob| write the bytes to file {fname}
12548 unmodified, also when binary mode is not specified.
12549
12550 {flags} must be a String. These characters are recognized:
12551
12552 'b' Binary mode is used: There will not be a NL after the
12553 last list item. An empty item at the end does cause the
12554 last line in the file to end in a NL.
12555
12556 'a' Append mode is used, lines are appended to the file: >
12557 :call writefile(["foo"], "event.log", "a")
12558 :call writefile(["bar"], "event.log", "a")
12559<
12560 'D' Delete the file when the current function ends. This
12561 works like: >
Bram Moolenaar938ae282023-02-20 20:44:55 +000012562 :defer delete({fname})
Bram Moolenaar806a2732022-09-04 15:40:36 +010012563< Fails when not in a function. Also see |:defer|.
12564
12565 's' fsync() is called after writing the file. This flushes
12566 the file to disk, if possible. This takes more time but
12567 avoids losing the file if the system crashes.
12568
12569 'S' fsync() is not called, even when 'fsync' is set.
12570
12571 When {flags} does not contain "S" or "s" then fsync() is
12572 called if the 'fsync' option is set.
12573
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012574 An existing file is overwritten, if possible.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012575
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012576 When the write fails -1 is returned, otherwise 0. There is an
12577 error message if the file can't be created or when writing
12578 fails.
Bram Moolenaar806a2732022-09-04 15:40:36 +010012579
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012580 Also see |readfile()|.
12581 To copy a file byte for byte: >
12582 :let fl = readfile("foo", "b")
12583 :call writefile(fl, "foocopy", "b")
12584
12585< Can also be used as a |method|: >
12586 GetText()->writefile("thefile")
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012587<
12588 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012589
12590
12591xor({expr}, {expr}) *xor()*
12592 Bitwise XOR on the two arguments. The arguments are converted
12593 to a number. A List, Dict or Float argument causes an error.
Bram Moolenaar5a6ec102022-05-27 21:58:00 +010012594 Also see `and()` and `or()`.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012595 Example: >
12596 :let bits = xor(bits, 0x80)
12597<
12598 Can also be used as a |method|: >
12599 :let bits = bits->xor(0x80)
12600<
Christian Brabandt5674c9a2024-06-09 00:13:43 +020012601 Return type: |Number|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012602
12603==============================================================================
126043. Feature list *feature-list*
12605
12606There are three types of features:
126071. Features that are only supported when they have been enabled when Vim
12608 was compiled |+feature-list|. Example: >
12609 :if has("cindent")
12610< *gui_running*
126112. Features that are only supported when certain conditions have been met.
12612 Example: >
12613 :if has("gui_running")
12614< *has-patch*
126153. Beyond a certain version or at a certain version and including a specific
12616 patch. The "patch-7.4.248" feature means that the Vim version is 7.5 or
12617 later, or it is version 7.4 and patch 248 was included. Example: >
12618 :if has("patch-7.4.248")
12619< Note that it's possible for patch 248 to be omitted even though 249 is
12620 included. Only happens when cherry-picking patches.
12621 Note that this form only works for patch 7.4.237 and later, before that
12622 you need to check for the patch and the v:version. Example (checking
12623 version 6.2.148 or later): >
12624 :if v:version > 602 || (v:version == 602 && has("patch148"))
12625
12626Hint: To find out if Vim supports backslashes in a file name (MS-Windows),
12627use: `if exists('+shellslash')`
12628
12629
12630acl Compiled with |ACL| support.
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012631all_builtin_terms Compiled with all builtin terminals enabled. (always
12632 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012633amiga Amiga version of Vim.
12634arabic Compiled with Arabic support |Arabic|.
12635arp Compiled with ARP support (Amiga).
12636autocmd Compiled with autocommand support. (always true)
12637autochdir Compiled with support for 'autochdir'
12638autoservername Automatically enable |clientserver|
12639balloon_eval Compiled with |balloon-eval| support.
12640balloon_multiline GUI supports multiline balloons.
12641beos BeOS version of Vim.
12642browse Compiled with |:browse| support, and browse() will
12643 work.
12644browsefilter Compiled with support for |browsefilter|.
12645bsd Compiled on an OS in the BSD family (excluding macOS).
Bram Moolenaar2ee347f2022-08-26 17:53:44 +010012646builtin_terms Compiled with some builtin terminals. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012647byte_offset Compiled with support for 'o' in 'statusline'
12648channel Compiled with support for |channel| and |job|
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012649cindent Compiled with 'cindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012650clientserver Compiled with remote invocation support |clientserver|.
12651clipboard Compiled with 'clipboard' support.
12652clipboard_working Compiled with 'clipboard' support and it can be used.
12653cmdline_compl Compiled with |cmdline-completion| support.
12654cmdline_hist Compiled with |cmdline-history| support.
12655cmdline_info Compiled with 'showcmd' and 'ruler' support.
12656comments Compiled with |'comments'| support.
12657compatible Compiled to be very Vi compatible.
12658conpty Platform where |ConPTY| can be used.
12659cryptv Compiled with encryption support |encryption|.
12660cscope Compiled with |cscope| support.
12661cursorbind Compiled with |'cursorbind'| (always true)
12662debug Compiled with "DEBUG" defined.
12663dialog_con Compiled with console dialog support.
glepnirdf461152024-04-04 22:23:29 +020012664dialog_con_gui Compiled with console and GUI dialog support.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012665dialog_gui Compiled with GUI dialog support.
12666diff Compiled with |vimdiff| and 'diff' support.
12667digraphs Compiled with support for digraphs.
12668directx Compiled with support for DirectX and 'renderoptions'.
12669dnd Compiled with support for the "~ register |quote_~|.
12670drop_file Compiled with |drop_file| support.
12671ebcdic Compiled on a machine with ebcdic character set.
12672emacs_tags Compiled with support for Emacs tags.
12673eval Compiled with expression evaluation support. Always
12674 true, of course!
12675ex_extra |+ex_extra| (always true)
12676extra_search Compiled with support for |'incsearch'| and
12677 |'hlsearch'|
12678farsi Support for Farsi was removed |farsi|.
Bram Moolenaarf80f40a2022-08-25 16:02:23 +010012679file_in_path Compiled with support for |gf| and |<cfile>| (always
12680 true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012681filterpipe When 'shelltemp' is off pipes are used for shell
12682 read/write/filter commands
12683find_in_path Compiled with support for include file searches
12684 |+find_in_path|.
12685float Compiled with support for |Float|.
12686fname_case Case in file names matters (for Amiga and MS-Windows
12687 this is not present).
12688folding Compiled with |folding| support.
12689footer Compiled with GUI footer support. |gui-footer|
12690fork Compiled to use fork()/exec() instead of system().
12691gettext Compiled with message translation |multi-lang|
12692gui Compiled with GUI enabled.
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +010012693gui_athena Compiled with Athena GUI (always false).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012694gui_gnome Compiled with Gnome support (gui_gtk is also defined).
12695gui_gtk Compiled with GTK+ GUI (any version).
12696gui_gtk2 Compiled with GTK+ 2 GUI (gui_gtk is also defined).
12697gui_gtk3 Compiled with GTK+ 3 GUI (gui_gtk is also defined).
12698gui_haiku Compiled with Haiku GUI.
12699gui_mac Compiled with Macintosh GUI.
12700gui_motif Compiled with Motif GUI.
12701gui_photon Compiled with Photon GUI.
12702gui_running Vim is running in the GUI, or it will start soon.
12703gui_win32 Compiled with MS-Windows Win32 GUI.
12704gui_win32s idem, and Win32s system being used (Windows 3.1)
12705haiku Haiku version of Vim.
12706hangul_input Compiled with Hangul input support. |hangul|
12707hpux HP-UX version of Vim.
12708iconv Can use iconv() for conversion.
12709insert_expand Compiled with support for CTRL-X expansion commands in
12710 Insert mode. (always true)
12711job Compiled with support for |channel| and |job|
12712ipv6 Compiled with support for IPv6 networking in |channel|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012713jumplist Compiled with |jumplist| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012714keymap Compiled with 'keymap' support.
12715lambda Compiled with |lambda| support.
12716langmap Compiled with 'langmap' support.
12717libcall Compiled with |libcall()| support.
12718linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
12719 'breakindent' support.
12720linux Linux version of Vim.
12721lispindent Compiled with support for lisp indenting.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012722 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012723listcmds Compiled with commands for the buffer list |:files|
12724 and the argument list |arglist|.
12725localmap Compiled with local mappings and abbr. |:map-local|
12726lua Compiled with Lua interface |Lua|.
12727mac Any Macintosh version of Vim cf. osx
12728macunix Synonym for osxdarwin
12729menu Compiled with support for |:menu|.
12730mksession Compiled with support for |:mksession|.
12731modify_fname Compiled with file name modifiers. |filename-modifiers|
12732 (always true)
12733mouse Compiled with support for mouse.
12734mouse_dec Compiled with support for Dec terminal mouse.
12735mouse_gpm Compiled with support for gpm (Linux console mouse)
12736mouse_gpm_enabled GPM mouse is working
12737mouse_netterm Compiled with support for netterm mouse.
12738mouse_pterm Compiled with support for qnx pterm mouse.
12739mouse_sysmouse Compiled with support for sysmouse (*BSD console mouse)
12740mouse_sgr Compiled with support for sgr mouse.
12741mouse_urxvt Compiled with support for urxvt mouse.
12742mouse_xterm Compiled with support for xterm mouse.
12743mouseshape Compiled with support for 'mouseshape'.
12744multi_byte Compiled with support for 'encoding' (always true)
12745multi_byte_encoding 'encoding' is set to a multibyte encoding.
12746multi_byte_ime Compiled with support for IME input method.
12747multi_lang Compiled with support for multiple languages.
12748mzscheme Compiled with MzScheme interface |mzscheme|.
12749nanotime Compiled with sub-second time stamp checks.
12750netbeans_enabled Compiled with support for |netbeans| and connected.
12751netbeans_intg Compiled with support for |netbeans|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012752num64 Compiled with 64-bit |Number| support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012753ole Compiled with OLE automation support for Win32.
12754osx Compiled for macOS cf. mac
12755osxdarwin Compiled for macOS, with |mac-darwin-feature|
12756packages Compiled with |packages| support.
12757path_extra Compiled with up/downwards search in 'path' and 'tags'
12758perl Compiled with Perl interface.
12759persistent_undo Compiled with support for persistent undo history.
12760postscript Compiled with PostScript file printing.
12761printer Compiled with |:hardcopy| support.
12762profile Compiled with |:profile| support.
Bram Moolenaar71badf92023-04-22 22:40:14 +010012763prof_nsec Profile results are in nanoseconds.
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012764python Python 2.x interface available. |has-python|
12765python_compiled Compiled with Python 2.x interface. |has-python|
12766python_dynamic Python 2.x interface is dynamically loaded. |has-python|
12767python3 Python 3.x interface available. |has-python|
12768python3_compiled Compiled with Python 3.x interface. |has-python|
12769python3_dynamic Python 3.x interface is dynamically loaded. |has-python|
Yee Cheng Chinc13b3d12023-08-20 21:18:38 +020012770python3_stable Python 3.x interface is using Python Stable ABI. |has-python|
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012771pythonx Python 2.x and/or 3.x interface available. |python_x|
12772qnx QNX version of Vim.
12773quickfix Compiled with |quickfix| support.
12774reltime Compiled with |reltime()| support.
12775rightleft Compiled with 'rightleft' support.
12776ruby Compiled with Ruby interface |ruby|.
12777scrollbind Compiled with 'scrollbind' support. (always true)
12778showcmd Compiled with 'showcmd' support.
12779signs Compiled with |:sign| support.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012780smartindent Compiled with 'smartindent' support. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012781sodium Compiled with libsodium for better crypt support
12782sound Compiled with sound support, e.g. `sound_playevent()`
12783spell Compiled with spell checking support |spell|.
12784startuptime Compiled with |--startuptime| support.
12785statusline Compiled with support for 'statusline', 'rulerformat'
12786 and special formats of 'titlestring' and 'iconstring'.
12787sun SunOS version of Vim.
12788sun_workshop Support for Sun |workshop| has been removed.
12789syntax Compiled with syntax highlighting support |syntax|.
12790syntax_items There are active syntax highlighting items for the
12791 current buffer.
12792system Compiled to use system() instead of fork()/exec().
12793tag_binary Compiled with binary searching in tags files
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012794 |tag-binary-search|. (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012795tag_old_static Support for old static tags was removed, see
12796 |tag-old-static|.
12797tcl Compiled with Tcl interface.
12798termguicolors Compiled with true color in terminal support.
12799terminal Compiled with |terminal| support.
12800terminfo Compiled with terminfo instead of termcap.
12801termresponse Compiled with support for |t_RV| and |v:termresponse|.
12802textobjects Compiled with support for |text-objects|.
12803textprop Compiled with support for |text-properties|.
12804tgetent Compiled with tgetent support, able to use a termcap
12805 or terminfo file.
12806timers Compiled with |timer_start()| support.
12807title Compiled with window title support |'title'|.
Bram Moolenaare1dc76f2022-06-25 18:01:32 +010012808 (always true)
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012809toolbar Compiled with support for |gui-toolbar|.
12810ttyin input is a terminal (tty)
12811ttyout output is a terminal (tty)
12812unix Unix version of Vim. *+unix*
12813unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
12814user_commands User-defined commands. (always true)
12815vartabs Compiled with variable tabstop support |'vartabstop'|.
12816vcon Win32: Virtual console support is working, can use
12817 'termguicolors'. Also see |+vtp|.
12818vertsplit Compiled with vertically split windows |:vsplit|.
12819 (always true)
12820vim_starting True while initial source'ing takes place. |startup|
12821 *vim_starting*
Bram Moolenaara6feb162022-01-02 12:06:33 +000012822vim9script Compiled with |Vim9| script support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012823viminfo Compiled with viminfo support.
12824vimscript-1 Compiled Vim script version 1 support
12825vimscript-2 Compiled Vim script version 2 support
12826vimscript-3 Compiled Vim script version 3 support
Bram Moolenaar8a3b8052022-06-26 12:21:15 +010012827vimscript-4 Compiled Vim script version 4 support
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012828virtualedit Compiled with 'virtualedit' option. (always true)
12829visual Compiled with Visual mode. (always true)
12830visualextra Compiled with extra Visual mode commands. (always
12831 true) |blockwise-operators|.
12832vms VMS version of Vim.
12833vreplace Compiled with |gR| and |gr| commands. (always true)
12834vtp Compiled for vcon support |+vtp| (check vcon to find
12835 out if it works in the current console).
12836wildignore Compiled with 'wildignore' option.
12837wildmenu Compiled with 'wildmenu' option.
12838win16 old version for MS-Windows 3.1 (always false)
12839win32 Win32 version of Vim (MS-Windows 95 and later, 32 or
12840 64 bits)
12841win32unix Win32 version of Vim, using Unix files (Cygwin)
12842win64 Win64 version of Vim (MS-Windows 64 bit).
12843win95 Win32 version for MS-Windows 95/98/ME (always false)
12844winaltkeys Compiled with 'winaltkeys' option.
12845windows Compiled with support for more than one window.
12846 (always true)
12847writebackup Compiled with 'writebackup' default on.
Christian Brabandte085dfd2023-09-30 12:49:18 +020012848xattr Compiled with extended attributes support |xattr|
12849 (currently only supported on Linux).
Bram Moolenaar1cae5a02021-12-27 21:28:34 +000012850xfontset Compiled with X fontset support |xfontset|.
12851xim Compiled with X input method support |xim|.
12852xpm Compiled with pixmap support.
12853xpm_w32 Compiled with pixmap support for Win32. (Only for
12854 backward compatibility. Use "xpm" instead.)
12855xsmp Compiled with X session management support.
12856xsmp_interact Compiled with interactive X session management support.
12857xterm_clipboard Compiled with support for xterm clipboard.
12858xterm_save Compiled with support for saving and restoring the
12859 xterm screen.
12860x11 Compiled with X11 support.
12861
12862
12863==============================================================================
128644. Matching a pattern in a String *string-match*
12865
12866This is common between several functions. A regexp pattern as explained at
12867|pattern| is normally used to find a match in the buffer lines. When a
12868pattern is used to find a match in a String, almost everything works in the
12869same way. The difference is that a String is handled like it is one line.
12870When it contains a "\n" character, this is not seen as a line break for the
12871pattern. It can be matched with a "\n" in the pattern, or with ".". Example:
12872>
12873 :let a = "aaaa\nxxxx"
12874 :echo matchstr(a, "..\n..")
12875 aa
12876 xx
12877 :echo matchstr(a, "a.x")
12878 a
12879 x
12880
12881Don't forget that "^" will only match at the first character of the String and
12882"$" at the last character of the string. They don't match after or before a
12883"\n".
12884
12885 vim:tw=78:ts=8:noet:ft=help:norl: